KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > Initializer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.jdt.core.*;
15 import org.eclipse.jdt.core.Flags;
16 import org.eclipse.jdt.core.IInitializer;
17 import org.eclipse.jdt.core.IJavaModelStatusConstants;
18 import org.eclipse.jdt.core.ISourceRange;
19 import org.eclipse.jdt.core.IType;
20 import org.eclipse.jdt.core.JavaModelException;
21 import org.eclipse.jdt.internal.core.util.Util;
22
23 /**
24  * @see IInitializer
25  */

26
27 /* package */ class Initializer extends Member implements IInitializer {
28
29 protected Initializer(JavaElement parent, int count) {
30     super(parent);
31     // 0 is not valid: this first occurrence is occurrence 1.
32
if (count <= 0)
33         throw new IllegalArgumentException JavaDoc();
34     this.occurrenceCount = count;
35 }
36 public boolean equals(Object JavaDoc o) {
37     if (!(o instanceof Initializer)) return false;
38     return super.equals(o);
39 }
40 /**
41  * @see IJavaElement
42  */

43 public int getElementType() {
44     return INITIALIZER;
45 }
46 /**
47  * @see JavaElement#getHandleMemento(StringBuffer)
48  */

49 protected void getHandleMemento(StringBuffer JavaDoc buff) {
50     ((JavaElement)getParent()).getHandleMemento(buff);
51     buff.append(getHandleMementoDelimiter());
52     buff.append(this.occurrenceCount);
53 }
54 /**
55  * @see JavaElement#getHandleMemento()
56  */

57 protected char getHandleMementoDelimiter() {
58     return JavaElement.JEM_INITIALIZER;
59 }
60 public int hashCode() {
61     return Util.combineHashCodes(this.parent.hashCode(), this.occurrenceCount);
62 }
63 /**
64  */

65 public String JavaDoc readableName() {
66
67     return ((JavaElement)getDeclaringType()).readableName();
68 }
69 /**
70  * @see ISourceManipulation
71  */

72 public void rename(String JavaDoc newName, boolean force, IProgressMonitor monitor) throws JavaModelException {
73     throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this));
74 }
75 /**
76  * @see IMember
77  */

78 public ISourceRange getNameRange() {
79     return null;
80 }
81 /*
82  * @see JavaElement#getPrimaryElement(boolean)
83  */

84 public IJavaElement getPrimaryElement(boolean checkOwner) {
85     if (checkOwner) {
86         CompilationUnit cu = (CompilationUnit)getAncestor(COMPILATION_UNIT);
87         if (cu == null || cu.isPrimary()) return this;
88     }
89     IJavaElement primaryParent = this.parent.getPrimaryElement(false);
90     return ((IType)primaryParent).getInitializer(this.occurrenceCount);
91 }
92 /**
93  * @private Debugging purposes
94  */

95 protected void toStringInfo(int tab, StringBuffer JavaDoc buffer, Object JavaDoc info, boolean showResolvedInfo) {
96     buffer.append(this.tabString(tab));
97     if (info == null) {
98         buffer.append("<initializer #"); //$NON-NLS-1$
99
buffer.append(this.occurrenceCount);
100         buffer.append("> (not open)"); //$NON-NLS-1$
101
} else if (info == NO_INFO) {
102         buffer.append("<initializer #"); //$NON-NLS-1$
103
buffer.append(this.occurrenceCount);
104         buffer.append(">"); //$NON-NLS-1$
105
} else {
106         try {
107             buffer.append("<"); //$NON-NLS-1$
108
if (Flags.isStatic(this.getFlags())) {
109                 buffer.append("static "); //$NON-NLS-1$
110
}
111         buffer.append("initializer #"); //$NON-NLS-1$
112
buffer.append(this.occurrenceCount);
113         buffer.append(">"); //$NON-NLS-1$
114
} catch (JavaModelException e) {
115             buffer.append("<JavaModelException in toString of " + getElementName()); //$NON-NLS-1$
116
}
117     }
118 }
119 }
120
Popular Tags