A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / util / ASTNodeFinder.java
index 571ced2..4c10a87 100644 (file)
@@ -38,12 +38,13 @@ public class ASTNodeFinder {
        }
 
        /*
-        * 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();
@@ -58,32 +59,33 @@ public class ASTNodeFinder {
        }
 
        /*
-        * 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();
@@ -111,74 +113,83 @@ public class ASTNodeFinder {
        }
 
        /*
-        * 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;
        }