import net.sourceforge.phpdt.core.IType;
import net.sourceforge.phpdt.core.compiler.CharOperation;
import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
+import net.sourceforge.phpdt.internal.compiler.ast.AbstractMethodDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.Argument;
+import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.FieldDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.TypeDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
import net.sourceforge.phpdt.internal.compiler.lookup.ClassScope;
-import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.Argument;
-import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
-import net.sourceforge.phpeclipse.internal.compiler.ast.TypeReference;
/**
* Finds an ASTNode given an IJavaElement in a CompilationUnitDeclaration
}
/*
- * Finds the FieldDeclaration in the given ast corresponding to the given field handle.
- * Returns null if not found.
+ * Finds the FieldDeclaration in the given ast corresponding to the given
+ * field handle. Returns null if not found.
*/
public FieldDeclaration findField(IField fieldHandle) {
- TypeDeclaration typeDecl = findType((IType)fieldHandle.getParent());
- if (typeDecl == null) return null;
+ TypeDeclaration typeDecl = findType((IType) fieldHandle.getParent());
+ if (typeDecl == null)
+ return null;
FieldDeclaration[] fields = typeDecl.fields;
if (fields != null) {
char[] fieldName = fieldHandle.getElementName().toCharArray();
}
/*
- * Finds the Initializer in the given ast corresponding to the given initializer handle.
- * Returns null if not found.
+ * Finds the Initializer in the given ast corresponding to the given
+ * initializer handle. Returns null if not found.
*/
-// public Initializer findInitializer(IInitializer initializerHandle) {
-// TypeDeclaration typeDecl = findType((IType)initializerHandle.getParent());
-// if (typeDecl == null) return null;
-// FieldDeclaration[] fields = typeDecl.fields;
-// if (fields != null) {
-// int occurenceCount = ((JavaElement)initializerHandle).occurrenceCount;
-// for (int i = 0, length = fields.length; i < length; i++) {
-// FieldDeclaration field = fields[i];
-// if (field instanceof Initializer && --occurenceCount == 0) {
-// return (Initializer)field;
-// }
-// }
-// }
-// return null;
-// }
-
+ // public Initializer findInitializer(IInitializer initializerHandle) {
+ // TypeDeclaration typeDecl =
+ // findType((IType)initializerHandle.getParent());
+ // if (typeDecl == null) return null;
+ // FieldDeclaration[] fields = typeDecl.fields;
+ // if (fields != null) {
+ // int occurenceCount = ((JavaElement)initializerHandle).occurrenceCount;
+ // for (int i = 0, length = fields.length; i < length; i++) {
+ // FieldDeclaration field = fields[i];
+ // if (field instanceof Initializer && --occurenceCount == 0) {
+ // return (Initializer)field;
+ // }
+ // }
+ // }
+ // return null;
+ // }
/*
- * Finds the AbstractMethodDeclaration in the given ast corresponding to the given method handle.
- * Returns null if not found.
+ * Finds the AbstractMethodDeclaration in the given ast corresponding to the
+ * given method handle. Returns null if not found.
*/
public AbstractMethodDeclaration findMethod(IMethod methodHandle) {
- TypeDeclaration typeDecl = findType((IType)methodHandle.getParent());
- if (typeDecl == null) return null;
+ TypeDeclaration typeDecl = findType((IType) methodHandle.getParent());
+ if (typeDecl == null)
+ return null;
AbstractMethodDeclaration[] methods = typeDecl.methods;
if (methods != null) {
char[] selector = methodHandle.getElementName().toCharArray();
}
/*
- * Finds the TypeDeclaration in the given ast corresponding to the given type handle.
- * Returns null if not found.
+ * Finds the TypeDeclaration in the given ast corresponding to the given
+ * type handle. Returns null if not found.
*/
public TypeDeclaration findType(IType typeHandle) {
IJavaElement parent = typeHandle.getParent();
final char[] typeName = typeHandle.getElementName().toCharArray();
-// final int occurenceCount = ((SourceType)typeHandle).occurrenceCount;
+ // final int occurenceCount = ((SourceType)typeHandle).occurrenceCount;
final boolean findAnonymous = typeName.length == 0;
class Visitor extends ASTVisitor {
TypeDeclaration result;
+
int count = 0;
- public boolean visit(TypeDeclaration typeDeclaration, BlockScope scope) {
- if (result != null) return false;
-// if ((typeDeclaration.bits & ASTNode.IsAnonymousTypeMASK) != 0) {
-// if (findAnonymous && ++count == occurenceCount) {
-// result = typeDeclaration;
-// }
-// } else {
- if (!findAnonymous && CharOperation.equals(typeName, typeDeclaration.name)) {
- result = typeDeclaration;
- }
-// }
+
+ public boolean visit(TypeDeclaration typeDeclaration,
+ BlockScope scope) {
+ if (result != null)
+ return false;
+ // if ((typeDeclaration.bits & ASTNode.IsAnonymousTypeMASK) !=
+ // 0) {
+ // if (findAnonymous && ++count == occurenceCount) {
+ // result = typeDeclaration;
+ // }
+ // } else {
+ if (!findAnonymous
+ && CharOperation.equals(typeName, typeDeclaration.name)) {
+ result = typeDeclaration;
+ }
+ // }
return false; // visit only one level
}
}
switch (parent.getElementType()) {
- case IJavaElement.COMPILATION_UNIT:
- ArrayList types = this.unit.types;
- if (types != null) {
- for (int i = 0, length = types.size(); i < length; i++) {
- TypeDeclaration type = (TypeDeclaration)types.get(i);//[i];
- if (CharOperation.equals(typeName, type.name)) {
- return type;
- }
+ case IJavaElement.COMPILATION_UNIT:
+ ArrayList types = this.unit.types;
+ if (types != null) {
+ for (int i = 0, length = types.size(); i < length; i++) {
+ TypeDeclaration type = (TypeDeclaration) types.get(i);// [i];
+ if (CharOperation.equals(typeName, type.name)) {
+ return type;
}
}
- break;
- case IJavaElement.TYPE:
- TypeDeclaration parentDecl = findType((IType)parent);
- if (parentDecl == null) return null;
-// types = parentDecl.memberTypes;
-// if (types != null) {
-// for (int i = 0, length = types.length; i < length; i++) {
-// TypeDeclaration type = types[i];
-// if (CharOperation.equals(typeName, type.name)) {
-// return type;
-// }
-// }
-// }
- break;
- case IJavaElement.FIELD:
- FieldDeclaration fieldDecl = findField((IField)parent);
- if (fieldDecl == null) return null;
- Visitor visitor = new Visitor();
- fieldDecl.traverse(visitor, null);
- return visitor.result;
-// case IJavaElement.INITIALIZER:
-// Initializer initializer = findInitializer((IInitializer)parent);
-// if (initializer == null) return null;
-// visitor = new Visitor();
-// initializer.traverse(visitor, null);
-// return visitor.result;
- case IJavaElement.METHOD:
- AbstractMethodDeclaration methodDecl = findMethod((IMethod)parent);
- if (methodDecl == null) return null;
- visitor = new Visitor();
- methodDecl.traverse(visitor, (ClassScope)null);
- return visitor.result;
+ }
+ break;
+ case IJavaElement.TYPE:
+ TypeDeclaration parentDecl = findType((IType) parent);
+ if (parentDecl == null)
+ return null;
+ // types = parentDecl.memberTypes;
+ // if (types != null) {
+ // for (int i = 0, length = types.length; i < length; i++) {
+ // TypeDeclaration type = types[i];
+ // if (CharOperation.equals(typeName, type.name)) {
+ // return type;
+ // }
+ // }
+ // }
+ break;
+ case IJavaElement.FIELD:
+ FieldDeclaration fieldDecl = findField((IField) parent);
+ if (fieldDecl == null)
+ return null;
+ Visitor visitor = new Visitor();
+ fieldDecl.traverse(visitor, null);
+ return visitor.result;
+ // case IJavaElement.INITIALIZER:
+ // Initializer initializer = findInitializer((IInitializer)parent);
+ // if (initializer == null) return null;
+ // visitor = new Visitor();
+ // initializer.traverse(visitor, null);
+ // return visitor.result;
+ case IJavaElement.METHOD:
+ AbstractMethodDeclaration methodDecl = findMethod((IMethod) parent);
+ if (methodDecl == null)
+ return null;
+ visitor = new Visitor();
+ methodDecl.traverse(visitor, (ClassScope) null);
+ return visitor.result;
}
return null;
}