1 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 26 27 class Initializer extends Member implements IInitializer { 28 29 protected Initializer(JavaElement parent, int count) { 30 super(parent); 31 if (count <= 0) 33 throw new IllegalArgumentException (); 34 this.occurrenceCount = count; 35 } 36 public boolean equals(Object o) { 37 if (!(o instanceof Initializer)) return false; 38 return super.equals(o); 39 } 40 43 public int getElementType() { 44 return INITIALIZER; 45 } 46 49 protected void getHandleMemento(StringBuffer buff) { 50 ((JavaElement)getParent()).getHandleMemento(buff); 51 buff.append(getHandleMementoDelimiter()); 52 buff.append(this.occurrenceCount); 53 } 54 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 65 public String readableName() { 66 67 return ((JavaElement)getDeclaringType()).readableName(); 68 } 69 72 public void rename(String newName, boolean force, IProgressMonitor monitor) throws JavaModelException { 73 throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this)); 74 } 75 78 public ISourceRange getNameRange() { 79 return null; 80 } 81 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 95 protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) { 96 buffer.append(this.tabString(tab)); 97 if (info == null) { 98 buffer.append("<initializer #"); buffer.append(this.occurrenceCount); 100 buffer.append("> (not open)"); } else if (info == NO_INFO) { 102 buffer.append("<initializer #"); buffer.append(this.occurrenceCount); 104 buffer.append(">"); } else { 106 try { 107 buffer.append("<"); if (Flags.isStatic(this.getFlags())) { 109 buffer.append("static "); } 111 buffer.append("initializer #"); buffer.append(this.occurrenceCount); 113 buffer.append(">"); } catch (JavaModelException e) { 115 buffer.append("<JavaModelException in toString of " + getElementName()); } 117 } 118 } 119 } 120 | Popular Tags |