Example usage for org.eclipse.jdt.internal.core.search.matching FieldPattern getIndexKey

List of usage examples for org.eclipse.jdt.internal.core.search.matching FieldPattern getIndexKey

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.search.matching FieldPattern getIndexKey.

Prototype

@Override
    public char[] getIndexKey() 

Source Link

Usage

From source file:org.eclipse.ajdt.internal.core.search.ExtraITDFinder.java

License:Open Source License

/**
 * Return all declaration matches that are ITDs of the proper type or in the type hierarchy of the expected type 
 * @throws JavaModelException //from   ww w.  jav a  2  s  . co  m
 */
private List<SearchMatch> findExtraDeclarationMatches(AJCompilationUnit unit,
        List<IntertypeElement> allRelevantItds, SearchPattern pattern, PossibleMatch match)
        throws JavaModelException {

    List<SearchMatch> extraDeclarationMatches = new ArrayList<SearchMatch>();
    // At this point, we know that the itds passed in have the same declaring type or are a subtype of the target type
    // So, just need to check selector and parameters
    // it is too time consuming to get the qualified parameters of the types, so
    // just match on simple names.
    if (pattern instanceof MethodPattern) {
        MethodPattern methPatt = (MethodPattern) pattern;
        char[] selector = methPatt.selector;
        char[][] simpleParamTypes = methPatt.parameterSimpleNames;

        for (IntertypeElement itd : allRelevantItds) {
            if (itd.getAJKind() == Kind.INTER_TYPE_METHOD
                    && CharOperation.equals(selector, itd.getTargetName().toCharArray())) {
                char[][] itdSimpleParamNames = extractSimpleParamNames(itd);
                if (CharOperation.equals(simpleParamTypes, itdSimpleParamNames)) {
                    ISourceRange sourceRange = itd.getNameRange();
                    extraDeclarationMatches.add(new MethodDeclarationMatch(itd, SearchMatch.A_ACCURATE,
                            sourceRange.getOffset(), sourceRange.getLength(), match.document.getParticipant(),
                            itd.getCompilationUnit().getResource()));
                }
            }
        }
    } else if (pattern instanceof ConstructorPattern) {
        ConstructorPattern consPatt = (ConstructorPattern) pattern;
        // must match the exact type
        char[] targetTypeName = TargetTypeUtils.getName(consPatt.declaringQualification,
                consPatt.declaringSimpleName);
        char[][] simpleParamTypes = consPatt.parameterSimpleNames;
        for (IntertypeElement itd : allRelevantItds) {
            if (itd.getAJKind() == Kind.INTER_TYPE_CONSTRUCTOR && targetTypeName != null
                    && CharOperation.equals(targetTypeName, fullyQualifiedTargetTypeName(itd))) {
                char[][] itdSimpleParamNames = extractSimpleParamNames(itd);
                if (CharOperation.equals(simpleParamTypes, itdSimpleParamNames)) {
                    ISourceRange sourceRange = itd.getNameRange();
                    extraDeclarationMatches.add(new MethodDeclarationMatch(itd, SearchMatch.A_ACCURATE,
                            sourceRange.getOffset(), sourceRange.getLength(), match.document.getParticipant(),
                            itd.getCompilationUnit().getResource()));
                }
            }
        }
    } else if (pattern instanceof FieldPattern) {
        FieldPattern fieldPatt = (FieldPattern) pattern;
        char[] targetTypeName = TargetTypeUtils.getName(TargetTypeUtils.getQualName(fieldPatt),
                TargetTypeUtils.getSimpleName(fieldPatt));
        char[] fieldName = fieldPatt.getIndexKey();
        for (IntertypeElement itd : allRelevantItds) {
            if (itd.getAJKind() == Kind.INTER_TYPE_FIELD
                    && CharOperation.equals(fieldName, itd.getTargetName().toCharArray()) &&
                    // must match the exact type, but only if a type exists
                    (targetTypeName == null
                            || CharOperation.equals(targetTypeName, fullyQualifiedTargetTypeName(itd)))) {
                ISourceRange sourceRange = itd.getNameRange();
                extraDeclarationMatches.add(new FieldDeclarationMatch(itd, SearchMatch.A_ACCURATE,
                        sourceRange.getOffset(), sourceRange.getLength(), match.document.getParticipant(),
                        itd.getCompilationUnit().getResource()));
            }
        }
    }
    return extraDeclarationMatches;
}