org.aspectj.org.eclipse.jdt.internal.core.search.matching
Class MatchLocator

java.lang.Object
  extended by org.aspectj.org.eclipse.jdt.internal.core.search.matching.MatchLocator
All Implemented Interfaces:
ITypeRequestor

public class MatchLocator
extends java.lang.Object
implements ITypeRequestor


Nested Class Summary
static class MatchLocator.WorkingCopyDocument
           
static class MatchLocator.WrappedCoreException
           
 
Field Summary
 char[][][] allSuperTypeNames
           
 PossibleMatch currentPossibleMatch
           
 HandleFactory handleFactory
           
 HierarchyResolver hierarchyResolver
           
 LookupEnvironment lookupEnvironment
           
 int matchContainer
           
 PossibleMatch[] matchesToProcess
           
static int MAX_AT_ONCE
           
 INameEnvironment nameEnvironment
           
 NameLookup nameLookup
           
 int numberOfMatches
           
 CompilerOptions options
           
 MatchLocatorParser parser
           
 SearchPattern pattern
           
 PatternLocator patternLocator
           
 IProgressMonitor progressMonitor
           
 SearchRequestor requestor
           
 long resultCollectorTime
           
 IJavaSearchScope scope
           
 ICompilationUnit[] workingCopies
           
 
Constructor Summary
MatchLocator(SearchPattern pattern, SearchRequestor requestor, IJavaSearchScope scope, IProgressMonitor progressMonitor)
           
 
Method Summary
 void accept(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction)
          Add an additional binary type
 void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction)
          Add an additional compilation unit into the loop -> build compilation unit declarations, their bindings and record their results.
 void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction)
          Add additional source types
static SearchDocument[] addWorkingCopies(SearchPattern pattern, SearchDocument[] indexMatches, ICompilationUnit[] copies, SearchParticipant participant)
           
protected  Parser basicParser()
           
protected  BinaryTypeBinding cacheBinaryType(IType type, IBinaryType binaryType)
           
static ClassFileReader classFileReader(IType type)
           
protected  char[][][] computeSuperTypeNames(IType focusType)
           
protected  IJavaElement createHandle(AbstractMethodDeclaration method, IJavaElement parent)
          Creates an IMethod from the given method declaration and type.
protected  IJavaElement createHandle(AbstractVariableDeclaration variableDeclaration, IJavaElement parent)
          Create an handle for a local variable declaration (may be a local variable or type parameter).
protected  IJavaElement createHandle(Annotation annotation, IAnnotatable parent)
          Create an handle for a local variable declaration (may be a local variable or type parameter).
protected  IJavaElement createHandle(FieldDeclaration fieldDeclaration, TypeDeclaration typeDeclaration, IJavaElement parent)
          Creates an IField from the given field declaration and type.
protected  boolean createHierarchyResolver(IType focusType, PossibleMatch[] possibleMatches)
           
protected  IJavaElement createImportHandle(ImportReference importRef)
          Creates an IImportDeclaration from the given import statement
protected  IJavaElement createPackageDeclarationHandle(CompilationUnitDeclaration unit)
          Creates an IImportDeclaration from the given import statement
protected  IType createTypeHandle(java.lang.String simpleTypeName)
          Creates an IType from the given simple top level type name.
protected  boolean encloses(IJavaElement element)
           
static void findIndexMatches(SearchPattern pattern, Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor monitor)
          Query a given index for matching entries.
protected  IBinaryType getBinaryInfo(ClassFile classFile, IResource resource)
           
protected  IType getFocusType()
           
 MethodBinding getMethodBinding(MethodPattern methodPattern)
           
protected  void getMethodBodies(CompilationUnitDeclaration unit, MatchingNodeSet nodeSet)
           
 SearchParticipant getParticipant()
           
static IJavaElement getProjectOrJar(IJavaElement element)
           
protected  TypeBinding getType(java.lang.Object typeKey, char[] typeName)
           
protected  boolean hasAlreadyDefinedType(CompilationUnitDeclaration parsedUnit)
           
 void initialize(JavaProject project, int possibleMatchSize)
          Create a new parser for the given project, as well as a lookup environment.
protected  void locateMatches(JavaProject javaProject, PossibleMatch[] possibleMatches, int start, int length)
           
protected  void locateMatches(JavaProject javaProject, PossibleMatchSet matchSet, int expected)
          Locate the matches amongst the possible matches.
 void locateMatches(SearchDocument[] searchDocuments)
          Locate the matches in the given files and report them using the search requestor.
protected  void locatePackageDeclarations(SearchParticipant participant, IJavaProject[] projects)
          Locates the package declarations corresponding to this locator's pattern.
protected  void locatePackageDeclarations(SearchPattern searchPattern, SearchParticipant participant, IJavaProject[] projects)
          Locates the package declarations corresponding to the search pattern.
protected  IType lookupType(ReferenceBinding typeBinding)
           
 SearchMatch newDeclarationMatch(IJavaElement element, Binding binding, int accuracy, int offset, int length)
           
 SearchMatch newDeclarationMatch(IJavaElement element, Binding binding, int accuracy, int offset, int length, SearchParticipant participant, IResource resource)
           
 FieldReferenceMatch newFieldReferenceMatch(IJavaElement enclosingElement, IJavaElement localElement, Binding enclosingBinding, int accuracy, int offset, int length, ASTNode reference)
           
 SearchMatch newLocalVariableReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, ASTNode reference)
           
 MethodReferenceMatch newMethodReferenceMatch(IJavaElement enclosingElement, Binding enclosingBinding, int accuracy, int offset, int length, boolean isConstructor, boolean isSynthetic, ASTNode reference)
           
 PackageReferenceMatch newPackageReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, ASTNode reference)
           
 SearchMatch newTypeParameterReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, ASTNode reference)
           
 TypeReferenceMatch newTypeReferenceMatch(IJavaElement enclosingElement, Binding enclosingBinding, int accuracy, ASTNode reference)
           
 TypeReferenceMatch newTypeReferenceMatch(IJavaElement enclosingElement, Binding enclosingBinding, int accuracy, int offset, int length, ASTNode reference)
           
protected  boolean parseAndBuildBindings(PossibleMatch possibleMatch, boolean mustResolve)
          Add the possibleMatch to the loop -> build compilation unit declarations, their bindings and record their results.
protected  void process(PossibleMatch possibleMatch, boolean bindingsWereCreated)
           
static IJavaElement projectOrJarFocus(SearchPattern pattern)
           
protected  void purgeMethodStatements(TypeDeclaration type, boolean checkEachMethod)
           
protected  void reduceParseTree(CompilationUnitDeclaration unit)
          Called prior to the unit being resolved.
protected  void report(SearchMatch match)
           
protected  void reportAccurateEnumConstructorReference(SearchMatch match, FieldDeclaration field, AllocationExpression allocation)
          Finds the accurate positions of each valid token in the source and reports a reference to this token to the search requestor.
protected  void reportAccurateFieldReference(SearchMatch[] matches, QualifiedNameReference qNameRef)
          Finds the accurate positions of each valid token in the source and reports a reference to this token to the search requestor.
protected  void reportAccurateParameterizedMethodReference(SearchMatch match, ASTNode statement, TypeReference[] typeArguments)
          Finds the accurate positions of the sequence of tokens given by qualifiedName in the source and reports a reference to this parameterized type name to the search requestor.
protected  void reportAccurateParameterizedTypeReference(SearchMatch match, TypeReference typeRef, int index, TypeReference[] typeArguments)
          Finds the accurate positions of the sequence of tokens given by qualifiedName in the source and reports a reference to this parameterized type name to the search requestor.
protected  void reportAccurateTypeReference(SearchMatch match, ASTNode typeRef, char[] name)
          Finds the accurate positions of the sequence of tokens given by qualifiedName in the source and reports a reference to this this qualified name to the search requestor.
protected  void reportBinaryMemberDeclaration(IResource resource, IMember binaryMember, Binding binaryMemberBinding, IBinaryType info, int accuracy)
           
protected  void reportMatching(AbstractMethodDeclaration method, TypeDeclaration type, IJavaElement parent, int accuracy, boolean typeInHierarchy, MatchingNodeSet nodeSet)
          Visit the given method declaration and report the nodes that match exactly the search pattern (i.e.
protected  void reportMatching(Annotation[] annotations, IJavaElement enclosingElement, IJavaElement[] otherElements, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedContainer, boolean enclosesElement)
          Report matching in annotations.
protected  void reportMatching(CompilationUnitDeclaration unit, boolean mustResolve)
          Visit the given resolved parse tree and report the nodes that match the search pattern.
protected  void reportMatching(FieldDeclaration field, FieldDeclaration[] otherFields, TypeDeclaration type, IJavaElement parent, int accuracy, boolean typeInHierarchy, MatchingNodeSet nodeSet)
          Visit the given field declaration and report the nodes that match exactly the search pattern (i.e.
protected  void reportMatching(TypeDeclaration type, IJavaElement parent, int accuracy, MatchingNodeSet nodeSet, int occurrenceCount)
          Visit the given type declaration and report the nodes that match exactly the search pattern (i.e.
protected  void reportMatching(TypeParameter[] typeParameters, IJavaElement enclosingElement, IJavaElement parent, Binding binding, MatchingNodeSet nodeSet)
          Report matches in type parameters.
protected  void reportMatchingSuper(TypeReference superReference, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedClassContainer)
           
static void setFocus(SearchPattern pattern, IJavaElement focus)
           
protected  boolean typeInHierarchy(ReferenceBinding binding)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_AT_ONCE

public static final int MAX_AT_ONCE

pattern

public SearchPattern pattern

patternLocator

public PatternLocator patternLocator

matchContainer

public int matchContainer

requestor

public SearchRequestor requestor

scope

public IJavaSearchScope scope

progressMonitor

public IProgressMonitor progressMonitor

workingCopies

public ICompilationUnit[] workingCopies

handleFactory

public HandleFactory handleFactory

allSuperTypeNames

public char[][][] allSuperTypeNames

parser

public MatchLocatorParser parser

nameEnvironment

public INameEnvironment nameEnvironment

nameLookup

public NameLookup nameLookup

lookupEnvironment

public LookupEnvironment lookupEnvironment

hierarchyResolver

public HierarchyResolver hierarchyResolver

options

public CompilerOptions options

numberOfMatches

public int numberOfMatches

matchesToProcess

public PossibleMatch[] matchesToProcess

currentPossibleMatch

public PossibleMatch currentPossibleMatch

resultCollectorTime

public long resultCollectorTime
Constructor Detail

MatchLocator

public MatchLocator(SearchPattern pattern,
                    SearchRequestor requestor,
                    IJavaSearchScope scope,
                    IProgressMonitor progressMonitor)
Method Detail

addWorkingCopies

public static SearchDocument[] addWorkingCopies(SearchPattern pattern,
                                                SearchDocument[] indexMatches,
                                                ICompilationUnit[] copies,
                                                SearchParticipant participant)

setFocus

public static void setFocus(SearchPattern pattern,
                            IJavaElement focus)

classFileReader

public static ClassFileReader classFileReader(IType type)

findIndexMatches

public static void findIndexMatches(SearchPattern pattern,
                                    Index index,
                                    IndexQueryRequestor requestor,
                                    SearchParticipant participant,
                                    IJavaSearchScope scope,
                                    IProgressMonitor monitor)
                             throws java.io.IOException
Query a given index for matching entries. Assumes the sender has opened the index and will close when finished.

Throws:
java.io.IOException

getProjectOrJar

public static IJavaElement getProjectOrJar(IJavaElement element)

projectOrJarFocus

public static IJavaElement projectOrJarFocus(SearchPattern pattern)

accept

public void accept(IBinaryType binaryType,
                   PackageBinding packageBinding,
                   AccessRestriction accessRestriction)
Add an additional binary type

Specified by:
accept in interface ITypeRequestor

accept

public void accept(ICompilationUnit sourceUnit,
                   AccessRestriction accessRestriction)
Add an additional compilation unit into the loop -> build compilation unit declarations, their bindings and record their results.

Specified by:
accept in interface ITypeRequestor

accept

public void accept(ISourceType[] sourceTypes,
                   PackageBinding packageBinding,
                   AccessRestriction accessRestriction)
Add additional source types

Specified by:
accept in interface ITypeRequestor

basicParser

protected Parser basicParser()

cacheBinaryType

protected BinaryTypeBinding cacheBinaryType(IType type,
                                            IBinaryType binaryType)
                                     throws JavaModelException
Throws:
JavaModelException

computeSuperTypeNames

protected char[][][] computeSuperTypeNames(IType focusType)

createHandle

protected IJavaElement createHandle(AbstractMethodDeclaration method,
                                    IJavaElement parent)
Creates an IMethod from the given method declaration and type.


createHandle

protected IJavaElement createHandle(FieldDeclaration fieldDeclaration,
                                    TypeDeclaration typeDeclaration,
                                    IJavaElement parent)
Creates an IField from the given field declaration and type.


createHandle

protected IJavaElement createHandle(AbstractVariableDeclaration variableDeclaration,
                                    IJavaElement parent)
Create an handle for a local variable declaration (may be a local variable or type parameter).


createHandle

protected IJavaElement createHandle(Annotation annotation,
                                    IAnnotatable parent)
Create an handle for a local variable declaration (may be a local variable or type parameter).


createHierarchyResolver

protected boolean createHierarchyResolver(IType focusType,
                                          PossibleMatch[] possibleMatches)

createImportHandle

protected IJavaElement createImportHandle(ImportReference importRef)
Creates an IImportDeclaration from the given import statement


createPackageDeclarationHandle

protected IJavaElement createPackageDeclarationHandle(CompilationUnitDeclaration unit)
Creates an IImportDeclaration from the given import statement


createTypeHandle

protected IType createTypeHandle(java.lang.String simpleTypeName)
Creates an IType from the given simple top level type name.


encloses

protected boolean encloses(IJavaElement element)

getBinaryInfo

protected IBinaryType getBinaryInfo(ClassFile classFile,
                                    IResource resource)
                             throws CoreException
Throws:
CoreException

getFocusType

protected IType getFocusType()

getMethodBodies

protected void getMethodBodies(CompilationUnitDeclaration unit,
                               MatchingNodeSet nodeSet)

getType

protected TypeBinding getType(java.lang.Object typeKey,
                              char[] typeName)

getMethodBinding

public MethodBinding getMethodBinding(MethodPattern methodPattern)

hasAlreadyDefinedType

protected boolean hasAlreadyDefinedType(CompilationUnitDeclaration parsedUnit)

initialize

public void initialize(JavaProject project,
                       int possibleMatchSize)
                throws JavaModelException
Create a new parser for the given project, as well as a lookup environment.

Throws:
JavaModelException

locateMatches

protected void locateMatches(JavaProject javaProject,
                             PossibleMatch[] possibleMatches,
                             int start,
                             int length)
                      throws CoreException
Throws:
CoreException

locateMatches

protected void locateMatches(JavaProject javaProject,
                             PossibleMatchSet matchSet,
                             int expected)
                      throws CoreException
Locate the matches amongst the possible matches.

Throws:
CoreException

locateMatches

public void locateMatches(SearchDocument[] searchDocuments)
                   throws CoreException
Locate the matches in the given files and report them using the search requestor.

Throws:
CoreException

locatePackageDeclarations

protected void locatePackageDeclarations(SearchParticipant participant,
                                         IJavaProject[] projects)
                                  throws CoreException
Locates the package declarations corresponding to this locator's pattern.

Throws:
CoreException

locatePackageDeclarations

protected void locatePackageDeclarations(SearchPattern searchPattern,
                                         SearchParticipant participant,
                                         IJavaProject[] projects)
                                  throws CoreException
Locates the package declarations corresponding to the search pattern.

Throws:
CoreException

lookupType

protected IType lookupType(ReferenceBinding typeBinding)

newDeclarationMatch

public SearchMatch newDeclarationMatch(IJavaElement element,
                                       Binding binding,
                                       int accuracy,
                                       int offset,
                                       int length)

newDeclarationMatch

public SearchMatch newDeclarationMatch(IJavaElement element,
                                       Binding binding,
                                       int accuracy,
                                       int offset,
                                       int length,
                                       SearchParticipant participant,
                                       IResource resource)

newFieldReferenceMatch

public FieldReferenceMatch newFieldReferenceMatch(IJavaElement enclosingElement,
                                                  IJavaElement localElement,
                                                  Binding enclosingBinding,
                                                  int accuracy,
                                                  int offset,
                                                  int length,
                                                  ASTNode reference)

newLocalVariableReferenceMatch

public SearchMatch newLocalVariableReferenceMatch(IJavaElement enclosingElement,
                                                  int accuracy,
                                                  int offset,
                                                  int length,
                                                  ASTNode reference)

newMethodReferenceMatch

public MethodReferenceMatch newMethodReferenceMatch(IJavaElement enclosingElement,
                                                    Binding enclosingBinding,
                                                    int accuracy,
                                                    int offset,
                                                    int length,
                                                    boolean isConstructor,
                                                    boolean isSynthetic,
                                                    ASTNode reference)

newPackageReferenceMatch

public PackageReferenceMatch newPackageReferenceMatch(IJavaElement enclosingElement,
                                                      int accuracy,
                                                      int offset,
                                                      int length,
                                                      ASTNode reference)

newTypeParameterReferenceMatch

public SearchMatch newTypeParameterReferenceMatch(IJavaElement enclosingElement,
                                                  int accuracy,
                                                  int offset,
                                                  int length,
                                                  ASTNode reference)

newTypeReferenceMatch

public TypeReferenceMatch newTypeReferenceMatch(IJavaElement enclosingElement,
                                                Binding enclosingBinding,
                                                int accuracy,
                                                int offset,
                                                int length,
                                                ASTNode reference)

newTypeReferenceMatch

public TypeReferenceMatch newTypeReferenceMatch(IJavaElement enclosingElement,
                                                Binding enclosingBinding,
                                                int accuracy,
                                                ASTNode reference)

parseAndBuildBindings

protected boolean parseAndBuildBindings(PossibleMatch possibleMatch,
                                        boolean mustResolve)
                                 throws CoreException
Add the possibleMatch to the loop -> build compilation unit declarations, their bindings and record their results.

Throws:
CoreException

process

protected void process(PossibleMatch possibleMatch,
                       boolean bindingsWereCreated)
                throws CoreException
Throws:
CoreException

purgeMethodStatements

protected void purgeMethodStatements(TypeDeclaration type,
                                     boolean checkEachMethod)

reduceParseTree

protected void reduceParseTree(CompilationUnitDeclaration unit)
Called prior to the unit being resolved. Reduce the parse tree where possible.


getParticipant

public SearchParticipant getParticipant()

report

protected void report(SearchMatch match)
               throws CoreException
Throws:
CoreException

reportAccurateTypeReference

protected void reportAccurateTypeReference(SearchMatch match,
                                           ASTNode typeRef,
                                           char[] name)
                                    throws CoreException
Finds the accurate positions of the sequence of tokens given by qualifiedName in the source and reports a reference to this this qualified name to the search requestor.

Throws:
CoreException

reportAccurateParameterizedMethodReference

protected void reportAccurateParameterizedMethodReference(SearchMatch match,
                                                          ASTNode statement,
                                                          TypeReference[] typeArguments)
                                                   throws CoreException
Finds the accurate positions of the sequence of tokens given by qualifiedName in the source and reports a reference to this parameterized type name to the search requestor.

Throws:
CoreException
Since:
3.1

reportAccurateParameterizedTypeReference

protected void reportAccurateParameterizedTypeReference(SearchMatch match,
                                                        TypeReference typeRef,
                                                        int index,
                                                        TypeReference[] typeArguments)
                                                 throws CoreException
Finds the accurate positions of the sequence of tokens given by qualifiedName in the source and reports a reference to this parameterized type name to the search requestor.

Throws:
CoreException
Since:
3.1

reportAccurateEnumConstructorReference

protected void reportAccurateEnumConstructorReference(SearchMatch match,
                                                      FieldDeclaration field,
                                                      AllocationExpression allocation)
                                               throws CoreException
Finds the accurate positions of each valid token in the source and reports a reference to this token to the search requestor. A token is valid if it has an accuracy which is not -1.

Throws:
CoreException

reportAccurateFieldReference

protected void reportAccurateFieldReference(SearchMatch[] matches,
                                            QualifiedNameReference qNameRef)
                                     throws CoreException
Finds the accurate positions of each valid token in the source and reports a reference to this token to the search requestor. A token is valid if it has an accuracy which is not -1.

Throws:
CoreException

reportBinaryMemberDeclaration

protected void reportBinaryMemberDeclaration(IResource resource,
                                             IMember binaryMember,
                                             Binding binaryMemberBinding,
                                             IBinaryType info,
                                             int accuracy)
                                      throws CoreException
Throws:
CoreException

reportMatching

protected void reportMatching(AbstractMethodDeclaration method,
                              TypeDeclaration type,
                              IJavaElement parent,
                              int accuracy,
                              boolean typeInHierarchy,
                              MatchingNodeSet nodeSet)
                       throws CoreException
Visit the given method declaration and report the nodes that match exactly the search pattern (i.e. the ones in the matching nodes set) Note that the method declaration has already been checked.

Throws:
CoreException

reportMatching

protected void reportMatching(Annotation[] annotations,
                              IJavaElement enclosingElement,
                              IJavaElement[] otherElements,
                              Binding elementBinding,
                              MatchingNodeSet nodeSet,
                              boolean matchedContainer,
                              boolean enclosesElement)
                       throws CoreException
Report matching in annotations.

Parameters:
otherElements - TODO
Throws:
CoreException

reportMatching

protected void reportMatching(CompilationUnitDeclaration unit,
                              boolean mustResolve)
                       throws CoreException
Visit the given resolved parse tree and report the nodes that match the search pattern.

Throws:
CoreException

reportMatching

protected void reportMatching(FieldDeclaration field,
                              FieldDeclaration[] otherFields,
                              TypeDeclaration type,
                              IJavaElement parent,
                              int accuracy,
                              boolean typeInHierarchy,
                              MatchingNodeSet nodeSet)
                       throws CoreException
Visit the given field declaration and report the nodes that match exactly the search pattern (i.e. the ones in the matching nodes set)

Throws:
CoreException

reportMatching

protected void reportMatching(TypeDeclaration type,
                              IJavaElement parent,
                              int accuracy,
                              MatchingNodeSet nodeSet,
                              int occurrenceCount)
                       throws CoreException
Visit the given type declaration and report the nodes that match exactly the search pattern (i.e. the ones in the matching nodes set)

Throws:
CoreException

reportMatching

protected void reportMatching(TypeParameter[] typeParameters,
                              IJavaElement enclosingElement,
                              IJavaElement parent,
                              Binding binding,
                              MatchingNodeSet nodeSet)
                       throws CoreException
Report matches in type parameters.

Throws:
CoreException

reportMatchingSuper

protected void reportMatchingSuper(TypeReference superReference,
                                   IJavaElement enclosingElement,
                                   Binding elementBinding,
                                   MatchingNodeSet nodeSet,
                                   boolean matchedClassContainer)
                            throws CoreException
Throws:
CoreException

typeInHierarchy

protected boolean typeInHierarchy(ReferenceBinding binding)