Example usage for org.eclipse.jdt.core.search FieldDeclarationMatch FieldDeclarationMatch

List of usage examples for org.eclipse.jdt.core.search FieldDeclarationMatch FieldDeclarationMatch

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.search FieldDeclarationMatch FieldDeclarationMatch.

Prototype

public FieldDeclarationMatch(IJavaElement element, int accuracy, int offset, int length,
        SearchParticipant participant, IResource resource) 

Source Link

Document

Creates a new field declaration match.

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 www  . ja va  2  s . c om
 */
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;
}

From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

public SearchMatch newDeclarationMatch(IJavaElement element, Binding binding, int accuracy, int offset,
        int length, SearchParticipant participant, IResource resource) {
    switch (element.getElementType()) {
    case IJavaElement.PACKAGE_FRAGMENT:
        return new PackageDeclarationMatch(element, accuracy, offset, length, participant, resource);
    case IJavaElement.TYPE:
        return new TypeDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding),
                accuracy, offset, length, participant, resource);
    case IJavaElement.FIELD:
        return new FieldDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding),
                accuracy, offset, length, participant, resource);
    case IJavaElement.METHOD:
        return new MethodDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding),
                accuracy, offset, length, participant, resource);
    case IJavaElement.LOCAL_VARIABLE:
        return new LocalVariableDeclarationMatch(element, accuracy, offset, length, participant, resource);
    case IJavaElement.PACKAGE_DECLARATION:
        return new PackageDeclarationMatch(element, accuracy, offset, length, participant, resource);
    case IJavaElement.TYPE_PARAMETER:
        return new TypeParameterDeclarationMatch(element, accuracy, offset, length, participant, resource);
    default://from   w  ww . j  a v a2 s  .c om
        return null;
    }
}