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

项目:che    文件:RenameNonVirtualMethodProcessor.java   
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
  SearchResultGroup[] grouped = getOccurrences();
  for (int i = 0; i < grouped.length; i++) {
    SearchResultGroup group = grouped[i];
    SearchMatch[] results = group.getSearchResults();
    ICompilationUnit cu = group.getCompilationUnit();
    TextChange change = manager.get(cu);
    for (int j = 0; j < results.length; j++) {
      SearchMatch match = results[j];
      if (!(match instanceof MethodDeclarationMatch)) {
        ReplaceEdit replaceEdit = createReplaceEdit(match, cu);
        String editName = RefactoringCoreMessages.RenamePrivateMethodRefactoring_update;
        addTextEdit(change, editName, replaceEdit);
      }
    }
  }
  pm.done();
}
项目:che    文件:RenameAnalyzeUtil.java   
private static void addReferenceShadowedError(
    ICompilationUnit cu, SearchMatch newMatch, String newElementName, RefactoringStatus result) {
  // Found a new match with no corresponding old match.
  // -> The new match is a reference which was pointing to another element,
  // but that other element has been shadowed

  // TODO: should not have to filter declarations:
  if (newMatch instanceof MethodDeclarationMatch || newMatch instanceof FieldDeclarationMatch)
    return;
  ISourceRange range = getOldSourceRange(newMatch);
  RefactoringStatusContext context = JavaStatusContext.create(cu, range);
  String message =
      Messages.format(
          RefactoringCoreMessages.RenameAnalyzeUtil_reference_shadowed,
          new String[] {
            BasicElementLabels.getFileName(cu),
            BasicElementLabels.getJavaElementName(newElementName)
          });
  result.addError(message, context);
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameNonVirtualMethodProcessor.java   
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
    SearchResultGroup[] grouped= getOccurrences();
    for (int i= 0; i < grouped.length; i++) {
        SearchResultGroup group= grouped[i];
        SearchMatch[] results= group.getSearchResults();
        ICompilationUnit cu= group.getCompilationUnit();
        TextChange change= manager.get(cu);
        for (int j= 0; j < results.length; j++){
            SearchMatch match= results[j];
            if (!(match instanceof MethodDeclarationMatch)) {
                ReplaceEdit replaceEdit= createReplaceEdit(match, cu);
                String editName= RefactoringCoreMessages.RenamePrivateMethodRefactoring_update;
                addTextEdit(change, editName, replaceEdit);
            }
        }
    }
    pm.done();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenameNonVirtualMethodProcessor.java   
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
    SearchResultGroup[] grouped= getOccurrences();
    for (int i= 0; i < grouped.length; i++) {
        SearchResultGroup group= grouped[i];
        SearchMatch[] results= group.getSearchResults();
        ICompilationUnit cu= group.getCompilationUnit();
        TextChange change= manager.get(cu);
        for (int j= 0; j < results.length; j++){
            SearchMatch match= results[j];
            if (!(match instanceof MethodDeclarationMatch)) {
                ReplaceEdit replaceEdit= createReplaceEdit(match, cu);
                String editName= RefactoringCoreMessages.RenamePrivateMethodRefactoring_update;
                addTextEdit(change, editName, replaceEdit);
            }
        }
    }
    pm.done();
}
项目:che    文件:RenameAnalyzeUtil.java   
private static void addShadowsError(
    ICompilationUnit cu, SearchMatch oldMatch, RefactoringStatus result) {
  // Old match not found in new matches -> reference has been shadowed

  // TODO: should not have to filter declarations:
  if (oldMatch instanceof MethodDeclarationMatch || oldMatch instanceof FieldDeclarationMatch)
    return;
  ISourceRange range = new SourceRange(oldMatch.getOffset(), oldMatch.getLength());
  RefactoringStatusContext context = JavaStatusContext.create(cu, range);
  String message =
      Messages.format(
          RefactoringCoreMessages.RenameAnalyzeUtil_shadows, BasicElementLabels.getFileName(cu));
  result.addError(message, context);
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameAnalyzeUtil.java   
private static void addReferenceShadowedError(ICompilationUnit cu, SearchMatch newMatch, String newElementName, RefactoringStatus result) {
    //Found a new match with no corresponding old match.
    //-> The new match is a reference which was pointing to another element,
    //but that other element has been shadowed

    //TODO: should not have to filter declarations:
    if (newMatch instanceof MethodDeclarationMatch || newMatch instanceof FieldDeclarationMatch)
        return;
    ISourceRange range= getOldSourceRange(newMatch);
    RefactoringStatusContext context= JavaStatusContext.create(cu, range);
    String message= Messages.format(
            RefactoringCoreMessages.RenameAnalyzeUtil_reference_shadowed,
            new String[] {BasicElementLabels.getFileName(cu), BasicElementLabels.getJavaElementName(newElementName)});
    result.addError(message, context);
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameAnalyzeUtil.java   
private static void addShadowsError(ICompilationUnit cu, SearchMatch oldMatch, RefactoringStatus result) {
    // Old match not found in new matches -> reference has been shadowed

    //TODO: should not have to filter declarations:
    if (oldMatch instanceof MethodDeclarationMatch || oldMatch instanceof FieldDeclarationMatch)
        return;
    ISourceRange range= new SourceRange(oldMatch.getOffset(), oldMatch.getLength());
    RefactoringStatusContext context= JavaStatusContext.create(cu, range);
    String message= Messages.format(RefactoringCoreMessages.RenameAnalyzeUtil_shadows, BasicElementLabels.getFileName(cu));
    result.addError(message, context);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenameAnalyzeUtil.java   
private static void addReferenceShadowedError(ICompilationUnit cu, SearchMatch newMatch, String newElementName, RefactoringStatus result) {
    //Found a new match with no corresponding old match.
    //-> The new match is a reference which was pointing to another element,
    //but that other element has been shadowed

    //TODO: should not have to filter declarations:
    if (newMatch instanceof MethodDeclarationMatch || newMatch instanceof FieldDeclarationMatch)
        return;
    ISourceRange range= getOldSourceRange(newMatch);
    RefactoringStatusContext context= JavaStatusContext.create(cu, range);
    String message= Messages.format(
            RefactoringCoreMessages.RenameAnalyzeUtil_reference_shadowed,
            new String[] {BasicElementLabels.getFileName(cu), BasicElementLabels.getJavaElementName(newElementName)});
    result.addError(message, context);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenameAnalyzeUtil.java   
private static void addShadowsError(ICompilationUnit cu, SearchMatch oldMatch, RefactoringStatus result) {
    // Old match not found in new matches -> reference has been shadowed

    //TODO: should not have to filter declarations:
    if (oldMatch instanceof MethodDeclarationMatch || oldMatch instanceof FieldDeclarationMatch)
        return;
    ISourceRange range= new SourceRange(oldMatch.getOffset(), oldMatch.getLength());
    RefactoringStatusContext context= JavaStatusContext.create(cu, range);
    String message= Messages.format(RefactoringCoreMessages.RenameAnalyzeUtil_shadows, BasicElementLabels.getFileName(cu));
    result.addError(message, context);
}
项目: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);
}
项目:Constants-to-Enum-Eclipse-Plugin    文件:ConvertConstantsToEnumRefactoring.java   
private void rewriteDeclarationsAndNamespaces(CompilationUnit node,
        SearchMatch match, RefactoringStatus status, ASTRewrite astRewrite,
        ImportRewrite importRewrite) throws CoreException {
    // final ASTNode result = NodeFinder.perform(node, match
    // .getOffset(), match.getLength());
    final ASTNode result = Util.getExactASTNode(node, match);

    // Must be simple name node.
    if (result.getNodeType() != ASTNode.SIMPLE_NAME) {
        final String errorMessage = Messages.ConvertConstantsToEnumRefactoring_WrongType;
        status.merge(RefactoringStatus.createFatalErrorStatus(MessageFormat
                .format(errorMessage,
                        new Object[] { node, node.getClass() })));
        final IStatus stateStatus = new InternalStateStatus(IStatus.ERROR,
                errorMessage);
        throw new CoreException(stateStatus);
    }

    // Get the fully qualified type name.
    final String fqn = this.getFullyQualifiedName(((Name) result)
            .resolveBinding().getJavaElement());

    if (match instanceof FieldDeclarationMatch
            && this.fieldsToRefactor.contains(match.getElement()))
        status.merge(this.removeConstField(astRewrite, importRewrite,
                Util.getFieldDeclaration(result),
                (IField) match.getElement()));

    else if (match instanceof FieldDeclarationMatch)
        status.merge(this.rewriteFieldDeclaration(astRewrite,
                importRewrite, Util.getFieldDeclaration(result), fqn));

    // Workaround for Bug 207257.
    else if (match instanceof LocalVariableDeclarationMatch
            || match instanceof LocalVariableReferenceMatch)
        if (((IVariableBinding) ((Name) result).resolveBinding())
                .isParameter())
            status.merge(this.rewriteFormalParameterDeclaration(astRewrite,
                    importRewrite,
                    Util.getSingleVariableDeclaration(result), fqn));

        else
            status.merge(this.rewriteLocalVariableDeclaration(astRewrite,
                    importRewrite,
                    Util.getVariableDeclarationStatement(result), fqn));

    else if (match instanceof MethodDeclarationMatch)
        status.merge(this.rewriteMethodDeclaration(astRewrite,
                importRewrite, Util.getMethodDeclaration(result), fqn));

    else if (match instanceof FieldReferenceMatch)
        // Rewrite the reference.
        status.merge(this.rewriteReference(astRewrite, importRewrite,
                (SimpleName) result, fqn));

}
项目: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    文件: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);
}