Java 类org.eclipse.jdt.core.search.MethodReferenceMatch 实例源码

项目:che    文件:NewSearchResultCollector.java   
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
  IJavaElement enclosingElement = (IJavaElement) match.getElement();
  if (enclosingElement != null) {
    if (fIgnorePotentials && (match.getAccuracy() == SearchMatch.A_INACCURATE)) return;
    boolean isWriteAccess = false;
    boolean isReadAccess = false;
    if (match instanceof FieldReferenceMatch) {
      FieldReferenceMatch fieldRef = ((FieldReferenceMatch) match);
      isWriteAccess = fieldRef.isWriteAccess();
      isReadAccess = fieldRef.isReadAccess();
    } else if (match instanceof FieldDeclarationMatch) {
      isWriteAccess = true;
    } else if (match instanceof LocalVariableReferenceMatch) {
      LocalVariableReferenceMatch localVarRef = ((LocalVariableReferenceMatch) match);
      isWriteAccess = localVarRef.isWriteAccess();
      isReadAccess = localVarRef.isReadAccess();
    } else if (match instanceof LocalVariableDeclarationMatch) {
      isWriteAccess = true;
    }
    boolean isSuperInvocation = false;
    if (match instanceof MethodReferenceMatch) {
      MethodReferenceMatch methodRef = (MethodReferenceMatch) match;
      isSuperInvocation = methodRef.isSuperInvocation();
    }
    fSearch.addMatch(
        new JavaElementMatch(
            enclosingElement,
            match.getRule(),
            match.getOffset(),
            match.getLength(),
            match.getAccuracy(),
            isReadAccess,
            isWriteAccess,
            match.isInsideDocComment(),
            isSuperInvocation));
  }
}
项目:Eclipse-Postfix-Code-Completion    文件:NewSearchResultCollector.java   
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
    IJavaElement enclosingElement= (IJavaElement) match.getElement();
    if (enclosingElement != null) {
        if (fIgnorePotentials && (match.getAccuracy() == SearchMatch.A_INACCURATE))
            return;
        boolean isWriteAccess= false;
        boolean isReadAccess= false;
        if (match instanceof FieldReferenceMatch) {
            FieldReferenceMatch fieldRef= ((FieldReferenceMatch) match);
            isWriteAccess= fieldRef.isWriteAccess();
            isReadAccess= fieldRef.isReadAccess();
        } else if (match instanceof FieldDeclarationMatch) {
            isWriteAccess= true;
        } else if (match instanceof LocalVariableReferenceMatch) {
            LocalVariableReferenceMatch localVarRef= ((LocalVariableReferenceMatch) match);
            isWriteAccess= localVarRef.isWriteAccess();
            isReadAccess= localVarRef.isReadAccess();
        } else if (match instanceof LocalVariableDeclarationMatch) {
            isWriteAccess= true;
        }
        boolean isSuperInvocation= false;
        if (match instanceof MethodReferenceMatch) {
            MethodReferenceMatch methodRef= (MethodReferenceMatch) match;
            isSuperInvocation= methodRef.isSuperInvocation();
        }
        fSearch.addMatch(new JavaElementMatch(enclosingElement, match.getRule(), match.getOffset(), match.getLength(), match.getAccuracy(), isReadAccess, isWriteAccess, match.isInsideDocComment(), isSuperInvocation));
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NewSearchResultCollector.java   
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
    IJavaElement enclosingElement= (IJavaElement) match.getElement();
    if (enclosingElement != null) {
        if (fIgnorePotentials && (match.getAccuracy() == SearchMatch.A_INACCURATE))
            return;
        boolean isWriteAccess= false;
        boolean isReadAccess= false;
        if (match instanceof FieldReferenceMatch) {
            FieldReferenceMatch fieldRef= ((FieldReferenceMatch) match);
            isWriteAccess= fieldRef.isWriteAccess();
            isReadAccess= fieldRef.isReadAccess();
        } else if (match instanceof FieldDeclarationMatch) {
            isWriteAccess= true;
        } else if (match instanceof LocalVariableReferenceMatch) {
            LocalVariableReferenceMatch localVarRef= ((LocalVariableReferenceMatch) match);
            isWriteAccess= localVarRef.isWriteAccess();
            isReadAccess= localVarRef.isReadAccess();
        } else if (match instanceof LocalVariableDeclarationMatch) {
            isWriteAccess= true;
        }
        boolean isSuperInvocation= false;
        if (match instanceof MethodReferenceMatch) {
            MethodReferenceMatch methodRef= (MethodReferenceMatch) match;
            isSuperInvocation= methodRef.isSuperInvocation();
        }
        fSearch.addMatch(new JavaElementMatch(enclosingElement, match.getRule(), match.getOffset(), match.getLength(), match.getAccuracy(), isReadAccess, isWriteAccess, match.isInsideDocComment(), isSuperInvocation));
    }
}
项目:eclipse.jdt.ls    文件:RenameProcessor.java   
private TextEdit collectMatch(SearchMatch match, IJavaElement element, ICompilationUnit unit, String newName) throws IndexOutOfBoundsException, JavaModelException {
    if (match instanceof MethodReferenceMatch && ((MethodReferenceMatch) match).isSuperInvocation() && match.getAccuracy() == SearchMatch.A_INACCURATE) {
        return null;
    }

    if (!(element instanceof IMethod) || match.isImplicit()) {
        return new ReplaceEdit(match.getOffset(), match.getLength(), newName);
    }

    int start = match.getOffset();
    int length = match.getLength();
    String matchText = unit.getBuffer().getText(start, length);

    //direct match:
    if (newName.equals(matchText)) {
        return new ReplaceEdit(match.getOffset(), match.getLength(), newName);
    }

    // lambda expression
    if (match instanceof MethodDeclarationMatch && match.getElement() instanceof IMethod && ((IMethod) match.getElement()).isLambdaMethod()) {
        // don't touch the lambda
        return null;
    }

    //Not a standard reference -- use scanner to find last identifier token before left parenthesis:
    IScanner scanner = getScanner(unit);
    scanner.setSource(matchText.toCharArray());
    int simpleNameStart = -1;
    int simpleNameEnd = -1;
    try {
        int token = scanner.getNextToken();
        while (token != ITerminalSymbols.TokenNameEOF && token != ITerminalSymbols.TokenNameLPAREN) { // reference in code includes arguments in parentheses
            if (token == ITerminalSymbols.TokenNameIdentifier) {
                simpleNameStart = scanner.getCurrentTokenStartPosition();
                simpleNameEnd = scanner.getCurrentTokenEndPosition();
            }
            token = scanner.getNextToken();
        }
    } catch (InvalidInputException e) {
        //ignore
    }
    if (simpleNameStart != -1) {
        match.setOffset(start + simpleNameStart);
        match.setLength(simpleNameEnd + 1 - simpleNameStart);
    }
    return new ReplaceEdit(match.getOffset(), match.getLength(), newName);
}
项目:che    文件:ChangeSignatureProcessor.java   
private SearchResultGroup[] findOccurrences(
    IProgressMonitor pm, ReferencesInBinaryContext binaryRefs, RefactoringStatus status)
    throws JavaModelException {
  final boolean isConstructor = fMethod.isConstructor();
  CuCollectingSearchRequestor requestor =
      new CuCollectingSearchRequestor(binaryRefs) {
        @Override
        protected void acceptSearchMatch(ICompilationUnit unit, SearchMatch match)
            throws CoreException {
          // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=27236 :
          if (isConstructor && match instanceof MethodReferenceMatch) {
            MethodReferenceMatch mrm = (MethodReferenceMatch) match;
            if (mrm.isSynthetic()) {
              return;
            }
          }
          collectMatch(match);
        }
      };

  SearchPattern pattern;
  if (isConstructor) {

    //          // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=226151 : don't find
    // binary refs for constructors for now
    //          return ConstructorReferenceFinder.getConstructorOccurrences(fMethod, pm, status);

    //          SearchPattern occPattern= SearchPattern.createPattern(fMethod,
    // IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
    SearchPattern declPattern =
        SearchPattern.createPattern(
            fMethod, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
    SearchPattern refPattern =
        SearchPattern.createPattern(
            fMethod, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
    //          pattern= SearchPattern.createOrPattern(declPattern, refPattern);
    //          pattern= occPattern;

    // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=226151 : do two searches
    try {
      SearchEngine engine = new SearchEngine();
      engine.search(
          declPattern,
          SearchUtils.getDefaultSearchParticipants(),
          createRefactoringScope(),
          requestor,
          new NullProgressMonitor());
      engine.search(
          refPattern,
          SearchUtils.getDefaultSearchParticipants(),
          createRefactoringScope(),
          requestor,
          pm);
    } catch (CoreException e) {
      throw new JavaModelException(e);
    }
    return RefactoringSearchEngine.groupByCu(requestor.getResults(), status);

  } else {
    pattern =
        RefactoringSearchEngine.createOrPattern(
            fRippleMethods, IJavaSearchConstants.ALL_OCCURRENCES);
  }
  return RefactoringSearchEngine.search(pattern, createRefactoringScope(), requestor, pm, status);
}
项目:che    文件:MethodOccurenceCollector.java   
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
  if (match instanceof MethodReferenceMatch
      && ((MethodReferenceMatch) match).isSuperInvocation()
      && match.getAccuracy() == SearchMatch.A_INACCURATE) {
    return; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
  }

  if (match.isImplicit()) { // see bug 94062
    collectMatch(match);
    return;
  }

  int start = match.getOffset();
  int length = match.getLength();
  String matchText = unit.getBuffer().getText(start, length);

  // direct match:
  if (fName.equals(matchText)) {
    collectMatch(match);
    return;
  }

  // lambda expression
  if (match instanceof MethodDeclarationMatch
      && match.getElement() instanceof IMethod
      && ((IMethod) match.getElement()).isLambdaMethod()) {
    // don't touch the lambda
    return;
  }

  // Not a standard reference -- use scanner to find last identifier token before left
  // parenthesis:
  IScanner scanner = getScanner(unit);
  scanner.setSource(matchText.toCharArray());
  int simpleNameStart = -1;
  int simpleNameEnd = -1;
  try {
    int token = scanner.getNextToken();
    while (token != ITerminalSymbols.TokenNameEOF
        && token
            != ITerminalSymbols
                .TokenNameLPAREN) { // reference in code includes arguments in parentheses
      if (token == ITerminalSymbols.TokenNameIdentifier) {
        simpleNameStart = scanner.getCurrentTokenStartPosition();
        simpleNameEnd = scanner.getCurrentTokenEndPosition();
      }
      token = scanner.getNextToken();
    }
  } catch (InvalidInputException e) {
    // ignore
  }
  if (simpleNameStart != -1) {
    match.setOffset(start + simpleNameStart);
    match.setLength(simpleNameEnd + 1 - simpleNameStart);
  }
  collectMatch(match);
}
项目:Eclipse-Postfix-Code-Completion    文件:ChangeSignatureProcessor.java   
private SearchResultGroup[] findOccurrences(IProgressMonitor pm, ReferencesInBinaryContext binaryRefs, RefactoringStatus status) throws JavaModelException{
        final boolean isConstructor= fMethod.isConstructor();
        CuCollectingSearchRequestor requestor= new CuCollectingSearchRequestor(binaryRefs) {
            @Override
            protected void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
                // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=27236 :
                if (isConstructor && match instanceof MethodReferenceMatch) {
                    MethodReferenceMatch mrm= (MethodReferenceMatch) match;
                    if (mrm.isSynthetic()) {
                        return;
                    }
                }
                collectMatch(match);
            }
        };

        SearchPattern pattern;
        if (isConstructor) {

//          // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=226151 : don't find binary refs for constructors for now
//          return ConstructorReferenceFinder.getConstructorOccurrences(fMethod, pm, status);

//          SearchPattern occPattern= SearchPattern.createPattern(fMethod, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
            SearchPattern declPattern= SearchPattern.createPattern(fMethod, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
            SearchPattern refPattern= SearchPattern.createPattern(fMethod, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
//          pattern= SearchPattern.createOrPattern(declPattern, refPattern);
//          pattern= occPattern;

            // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=226151 : do two searches
            try {
                SearchEngine engine= new SearchEngine();
                engine.search(declPattern, SearchUtils.getDefaultSearchParticipants(), createRefactoringScope(), requestor, new NullProgressMonitor());
                engine.search(refPattern, SearchUtils.getDefaultSearchParticipants(), createRefactoringScope(), requestor, pm);
            } catch (CoreException e) {
                throw new JavaModelException(e);
            }
            return RefactoringSearchEngine.groupByCu(requestor.getResults(), status);

        } else {
            pattern= RefactoringSearchEngine.createOrPattern(fRippleMethods, IJavaSearchConstants.ALL_OCCURRENCES);
        }
        return RefactoringSearchEngine.search(pattern, createRefactoringScope(), requestor, pm, status);
    }
项目:Eclipse-Postfix-Code-Completion    文件:MethodOccurenceCollector.java   
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
    if (match instanceof MethodReferenceMatch
            && ((MethodReferenceMatch) match).isSuperInvocation()
            && match.getAccuracy() == SearchMatch.A_INACCURATE) {
        return; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
    }

    if (match.isImplicit()) { // see bug 94062
        collectMatch(match);
        return;
    }

    int start= match.getOffset();
    int length= match.getLength();
    String matchText= unit.getBuffer().getText(start, length);

    //direct match:
    if (fName.equals(matchText)) {
        collectMatch(match);
        return;
    }

    // lambda expression
    if (match instanceof MethodDeclarationMatch
            && match.getElement() instanceof IMethod
            && ((IMethod) match.getElement()).isLambdaMethod()) {
        // don't touch the lambda
        return;
    }

    //Not a standard reference -- use scanner to find last identifier token before left parenthesis:
    IScanner scanner= getScanner(unit);
    scanner.setSource(matchText.toCharArray());
    int simpleNameStart= -1;
    int simpleNameEnd= -1;
    try {
        int token = scanner.getNextToken();
        while (token != ITerminalSymbols.TokenNameEOF && token != ITerminalSymbols.TokenNameLPAREN) { // reference in code includes arguments in parentheses
            if (token == ITerminalSymbols.TokenNameIdentifier) {
                simpleNameStart= scanner.getCurrentTokenStartPosition();
                simpleNameEnd= scanner.getCurrentTokenEndPosition();
            }
            token = scanner.getNextToken();
        }
    } catch (InvalidInputException e){
        //ignore
    }
    if (simpleNameStart != -1) {
        match.setOffset(start + simpleNameStart);
        match.setLength(simpleNameEnd + 1 - simpleNameStart);
    }
    collectMatch(match);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ChangeSignatureProcessor.java   
private SearchResultGroup[] findOccurrences(IProgressMonitor pm, ReferencesInBinaryContext binaryRefs, RefactoringStatus status) throws JavaModelException{
        final boolean isConstructor= fMethod.isConstructor();
        CuCollectingSearchRequestor requestor= new CuCollectingSearchRequestor(binaryRefs) {
            @Override
            protected void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
                // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=27236 :
                if (isConstructor && match instanceof MethodReferenceMatch) {
                    MethodReferenceMatch mrm= (MethodReferenceMatch) match;
                    if (mrm.isSynthetic()) {
                        return;
                    }
                }
                collectMatch(match);
            }
        };

        SearchPattern pattern;
        if (isConstructor) {

//          // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=226151 : don't find binary refs for constructors for now
//          return ConstructorReferenceFinder.getConstructorOccurrences(fMethod, pm, status);

//          SearchPattern occPattern= SearchPattern.createPattern(fMethod, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
            SearchPattern declPattern= SearchPattern.createPattern(fMethod, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
            SearchPattern refPattern= SearchPattern.createPattern(fMethod, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
//          pattern= SearchPattern.createOrPattern(declPattern, refPattern);
//          pattern= occPattern;

            // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=226151 : do two searches
            try {
                SearchEngine engine= new SearchEngine();
                engine.search(declPattern, SearchUtils.getDefaultSearchParticipants(), createRefactoringScope(), requestor, new NullProgressMonitor());
                engine.search(refPattern, SearchUtils.getDefaultSearchParticipants(), createRefactoringScope(), requestor, pm);
            } catch (CoreException e) {
                throw new JavaModelException(e);
            }
            return RefactoringSearchEngine.groupByCu(requestor.getResults(), status);

        } else {
            pattern= RefactoringSearchEngine.createOrPattern(fRippleMethods, IJavaSearchConstants.ALL_OCCURRENCES);
        }
        return RefactoringSearchEngine.search(pattern, createRefactoringScope(), requestor, pm, status);
    }
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:MethodOccurenceCollector.java   
@Override
public void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException {
    if (match instanceof MethodReferenceMatch
            && ((MethodReferenceMatch) match).isSuperInvocation()
            && match.getAccuracy() == SearchMatch.A_INACCURATE) {
        return; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
    }

    if (match.isImplicit()) { // see bug 94062
        collectMatch(match);
        return;
    }

    int start= match.getOffset();
    int length= match.getLength();
    String matchText= unit.getBuffer().getText(start, length);

    //direct match:
    if (fName.equals(matchText)) {
        collectMatch(match);
        return;
    }

    //Not a standard reference -- use scanner to find last identifier token before left parenthesis:
    IScanner scanner= getScanner(unit);
    scanner.setSource(matchText.toCharArray());
    int simpleNameStart= -1;
    int simpleNameEnd= -1;
    try {
        int token = scanner.getNextToken();
        while (token != ITerminalSymbols.TokenNameEOF && token != ITerminalSymbols.TokenNameLPAREN) { // reference in code includes arguments in parentheses
            if (token == ITerminalSymbols.TokenNameIdentifier) {
                simpleNameStart= scanner.getCurrentTokenStartPosition();
                simpleNameEnd= scanner.getCurrentTokenEndPosition();
            }
            token = scanner.getNextToken();
        }
    } catch (InvalidInputException e){
        //ignore
    }
    if (simpleNameStart != -1) {
        match.setOffset(start + simpleNameStart);
        match.setLength(simpleNameEnd + 1 - simpleNameStart);
    }
    collectMatch(match);
}