1 11 package org.eclipse.jdt.core.dom; 12 13 import org.eclipse.jdt.internal.compiler.ASTVisitor; 14 import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; 15 import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; 16 import org.eclipse.jdt.internal.compiler.ast.Initializer; 17 import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; 18 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; 19 import org.eclipse.jdt.internal.compiler.lookup.ClassScope; 20 import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; 21 import org.eclipse.jdt.internal.compiler.lookup.MethodScope; 22 23 class NodeSearcher extends ASTVisitor { 24 public org.eclipse.jdt.internal.compiler.ast.ASTNode found; 25 public TypeDeclaration enclosingType; 26 public int position; 27 28 NodeSearcher(int position) { 29 this.position = position; 30 } 31 32 public boolean visit( 33 ConstructorDeclaration constructorDeclaration, 34 ClassScope scope) { 35 36 if (constructorDeclaration.declarationSourceStart <= position 37 && position <= constructorDeclaration.declarationSourceEnd) { 38 found = constructorDeclaration; 39 return false; 40 } 41 return true; 42 } 43 44 public boolean visit( 45 FieldDeclaration fieldDeclaration, 46 MethodScope scope) { 47 if (fieldDeclaration.declarationSourceStart <= position 48 && position <= fieldDeclaration.declarationSourceEnd) { 49 found = fieldDeclaration; 50 return false; 51 } 52 return true; 53 } 54 55 public boolean visit(Initializer initializer, MethodScope scope) { 56 if (initializer.declarationSourceStart <= position 57 && position <= initializer.declarationSourceEnd) { 58 found = initializer; 59 return false; 60 } 61 return true; 62 } 63 64 public boolean visit( 65 TypeDeclaration memberTypeDeclaration, 66 ClassScope scope) { 67 if (memberTypeDeclaration.declarationSourceStart <= position 68 && position <= memberTypeDeclaration.declarationSourceEnd) { 69 enclosingType = memberTypeDeclaration; 70 return true; 71 72 } 73 return false; 74 } 75 76 public boolean visit( 77 MethodDeclaration methodDeclaration, 78 ClassScope scope) { 79 80 if (methodDeclaration.declarationSourceStart <= position 81 && position <= methodDeclaration.declarationSourceEnd) { 82 found = methodDeclaration; 83 return false; 84 } 85 return true; 86 } 87 88 public boolean visit( 89 TypeDeclaration typeDeclaration, 90 CompilationUnitScope scope) { 91 if (typeDeclaration.declarationSourceStart <= position 92 && position <= typeDeclaration.declarationSourceEnd) { 93 enclosingType = typeDeclaration; 94 return true; 95 } 96 return false; 97 } 98 99 } 100 | Popular Tags |