Java 类org.eclipse.jdt.core.CorrectionEngine 实例源码

项目:Eclipse-Postfix-Code-Completion    文件:CorrectionMarkerResolutionGenerator.java   
private static IProblemLocation createFromMarker(IMarker marker, ICompilationUnit cu) {
    try {
        int id= marker.getAttribute(IJavaModelMarker.ID, -1);
        int start= marker.getAttribute(IMarker.CHAR_START, -1);
        int end= marker.getAttribute(IMarker.CHAR_END, -1);
        int severity= marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
        String[] arguments= CorrectionEngine.getProblemArguments(marker);
        String markerType= marker.getType();
        if (cu != null && id != -1 && start != -1 && end != -1 && arguments != null) {
            boolean isError= (severity == IMarker.SEVERITY_ERROR);
            return new ProblemLocation(start, end - start, id, arguments, isError, markerType);
        }
    } catch (CoreException e) {
        JavaPlugin.log(e);
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CorrectionMarkerResolutionGenerator.java   
private static IProblemLocation createFromMarker(IMarker marker, ICompilationUnit cu) {
    try {
        int id= marker.getAttribute(IJavaModelMarker.ID, -1);
        int start= marker.getAttribute(IMarker.CHAR_START, -1);
        int end= marker.getAttribute(IMarker.CHAR_END, -1);
        int severity= marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
        String[] arguments= CorrectionEngine.getProblemArguments(marker);
        String markerType= marker.getType();
        if (cu != null && id != -1 && start != -1 && end != -1 && arguments != null) {
            boolean isError= (severity == IMarker.SEVERITY_ERROR);
            return new ProblemLocation(start, end - start, id, arguments, isError, markerType);
        }
    } catch (CoreException e) {
        JavaPlugin.log(e);
    }
    return null;
}
项目:che    文件:SuppressWarningsSubProcessor.java   
public static final boolean hasSuppressWarningsProposal(IJavaProject javaProject, int problemId) {
  if (CorrectionEngine.getWarningToken(problemId) != null
      && JavaModelUtil.is50OrHigher(javaProject)) {
    String optionId = JavaCore.getOptionForConfigurableSeverity(problemId);
    if (optionId != null) {
      String optionValue = javaProject.getOption(optionId, true);
      return JavaCore.WARNING.equals(optionValue)
          || (JavaCore.ERROR.equals(optionValue)
              && JavaCore.ENABLED.equals(
                  javaProject.getOption(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, true)));
    }
  }
  return false;
}
项目:che    文件:SuppressWarningsSubProcessor.java   
/**
 * Adds a proposal to correct the name of the SuppressWarning annotation
 *
 * @param context the context
 * @param problem the problem
 * @param proposals the resulting proposals
 */
public static void addUnknownSuppressWarningProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {

  ASTNode coveringNode = context.getCoveringNode();
  if (!(coveringNode instanceof StringLiteral)) return;

  AST ast = coveringNode.getAST();
  StringLiteral literal = (StringLiteral) coveringNode;

  String literalValue = literal.getLiteralValue();
  String[] allWarningTokens = CorrectionEngine.getAllWarningTokens();
  for (int i = 0; i < allWarningTokens.length; i++) {
    String curr = allWarningTokens[i];
    if (NameMatcher.isSimilarName(literalValue, curr)) {
      StringLiteral newLiteral = ast.newStringLiteral();
      newLiteral.setLiteralValue(curr);
      ASTRewrite rewrite = ASTRewrite.create(ast);
      rewrite.replace(literal, newLiteral, null);
      String label =
          Messages.format(
              CorrectionMessages.SuppressWarningsSubProcessor_fix_suppress_token_label,
              new String[] {curr});
      Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
      ASTRewriteCorrectionProposal proposal =
          new ASTRewriteCorrectionProposal(
              label,
              context.getCompilationUnit(),
              rewrite,
              IProposalRelevance.FIX_SUPPRESS_TOKEN,
              image);
      proposals.add(proposal);
    }
  }
  addRemoveUnusedSuppressWarningProposals(context, problem, proposals);
}
项目:gwt-eclipse-plugin    文件:JavaMarkerResolutionGenerator.java   
public IMarkerResolution[] getResolutions(IMarker marker) {
  if (!hasResolutions(marker)) {
    return NO_RESOLUTIONS;
  }

  ICompilationUnit cu = getCompilationUnit(marker);
  if (cu != null) {
    IEditorInput input = new FileEditorInput(
        (IFile) cu.getPrimary().getResource());
    if (input != null) {
      int offset = marker.getAttribute(IMarker.CHAR_START, -1);
      int length = marker.getAttribute(IMarker.CHAR_END, -1) - offset;
      int problemId = marker.getAttribute(IJavaModelMarker.ID, -1);
      boolean isError = (marker.getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR);
      String[] arguments = CorrectionEngine.getProblemArguments(marker);

      IProblemLocation location = new ProblemLocation(offset, length,
          problemId, arguments, isError, null);
      IInvocationContext context = new AssistContext(cu, offset, length);

      IJavaCompletionProposal[] proposals = new IJavaCompletionProposal[0];

      try {
        proposals = getCorrections(context, new IProblemLocation[] {location});
      } catch (CoreException e) {
        CorePluginLog.logError(e);
      }

      int nProposals = proposals.length;
      IMarkerResolution[] resolutions = new IMarkerResolution[nProposals];
      for (int i = 0; i < nProposals; i++) {
        resolutions[i] = new QuickFixCompletionProposalWrapper(cu, offset,
            length, proposals[i]);
      }
      return resolutions;
    }
  }

  return NO_RESOLUTIONS;
}
项目:Eclipse-Postfix-Code-Completion    文件:SuppressWarningsSubProcessor.java   
public static final boolean hasSuppressWarningsProposal(IJavaProject javaProject, int problemId) {
    if (CorrectionEngine.getWarningToken(problemId) != null && JavaModelUtil.is50OrHigher(javaProject)) {
        String optionId= JavaCore.getOptionForConfigurableSeverity(problemId);
        if (optionId != null) {
            String optionValue= javaProject.getOption(optionId, true);
            return JavaCore.WARNING.equals(optionValue) ||
                    (JavaCore.ERROR.equals(optionValue) && JavaCore.ENABLED.equals(javaProject.getOption(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, true)));
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:SuppressWarningsSubProcessor.java   
/**
 * Adds a proposal to correct the name of the SuppressWarning annotation
 * @param context the context
 * @param problem the problem
 * @param proposals the resulting proposals
 */
public static void addUnknownSuppressWarningProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {

    ASTNode coveringNode= context.getCoveringNode();
    if (!(coveringNode instanceof StringLiteral))
        return;

    AST ast= coveringNode.getAST();
    StringLiteral literal= (StringLiteral) coveringNode;

    String literalValue= literal.getLiteralValue();
    String[] allWarningTokens= CorrectionEngine.getAllWarningTokens();
    for (int i= 0; i < allWarningTokens.length; i++) {
        String curr= allWarningTokens[i];
        if (NameMatcher.isSimilarName(literalValue, curr)) {
            StringLiteral newLiteral= ast.newStringLiteral();
            newLiteral.setLiteralValue(curr);
            ASTRewrite rewrite= ASTRewrite.create(ast);
            rewrite.replace(literal, newLiteral, null);
            String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_fix_suppress_token_label, new String[] { curr });
            Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
            ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.FIX_SUPPRESS_TOKEN, image);
            proposals.add(proposal);
        }
    }
    addRemoveUnusedSuppressWarningProposals(context, problem, proposals);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SuppressWarningsSubProcessor.java   
public static final boolean hasSuppressWarningsProposal(IJavaProject javaProject, int problemId) {
    if (CorrectionEngine.getWarningToken(problemId) != null && JavaModelUtil.is50OrHigher(javaProject)) {
        String optionId= JavaCore.getOptionForConfigurableSeverity(problemId);
        if (optionId != null) {
            String optionValue= javaProject.getOption(optionId, true);
            return JavaCore.WARNING.equals(optionValue);
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SuppressWarningsSubProcessor.java   
/**
 * Adds a proposal to correct the name of the SuppressWarning annotation
 * @param context the context
 * @param problem the problem
 * @param proposals the resulting proposals
 */
public static void addUnknownSuppressWarningProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {

    ASTNode coveringNode= context.getCoveringNode();
    if (!(coveringNode instanceof StringLiteral))
        return;

    AST ast= coveringNode.getAST();
    StringLiteral literal= (StringLiteral) coveringNode;

    String literalValue= literal.getLiteralValue();
    String[] allWarningTokens= CorrectionEngine.getAllWarningTokens();
    for (int i= 0; i < allWarningTokens.length; i++) {
        String curr= allWarningTokens[i];
        if (NameMatcher.isSimilarName(literalValue, curr)) {
            StringLiteral newLiteral= ast.newStringLiteral();
            newLiteral.setLiteralValue(curr);
            ASTRewrite rewrite= ASTRewrite.create(ast);
            rewrite.replace(literal, newLiteral, null);
            String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_fix_suppress_token_label, new String[] { curr });
            Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
            ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 5, image);
            proposals.add(proposal);
        }
    }
    addRemoveUnusedSuppressWarningProposals(context, problem, proposals);
}
项目:che    文件:SuppressWarningsSubProcessor.java   
public static void addSuppressWarningsProposals(
    IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
  if (problem.isError()
      && !JavaCore.ENABLED.equals(
          context
              .getCompilationUnit()
              .getJavaProject()
              .getOption(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, true))) {
    return;
  }
  if (JavaCore.DISABLED.equals(
      context
          .getCompilationUnit()
          .getJavaProject()
          .getOption(JavaCore.COMPILER_PB_SUPPRESS_WARNINGS, true))) {
    return;
  }

  String warningToken = CorrectionEngine.getWarningToken(problem.getProblemId());
  if (warningToken == null) {
    return;
  }
  for (Iterator<ICommandAccess> iter = proposals.iterator(); iter.hasNext(); ) {
    Object element = iter.next();
    if (element instanceof SuppressWarningsProposal
        && warningToken.equals(((SuppressWarningsProposal) element).getWarningToken())) {
      return; // only one at a time
    }
  }

  ASTNode node = problem.getCoveringNode(context.getASTRoot());
  if (node == null) {
    return;
  }

  ASTNode target = node;
  int relevance = IProposalRelevance.ADD_SUPPRESSWARNINGS;
  do {
    relevance =
        addSuppressWarningsProposalIfPossible(
            context.getCompilationUnit(), target, warningToken, relevance, proposals);
    if (relevance == 0) return;
    target = target.getParent();
  } while (target != null);

  ASTNode importStatement = ASTNodes.getParent(node, ImportDeclaration.class);
  if (importStatement != null && !context.getASTRoot().types().isEmpty()) {
    target = (ASTNode) context.getASTRoot().types().get(0);
    if (target != null) {
      addSuppressWarningsProposalIfPossible(
          context.getCompilationUnit(),
          target,
          warningToken,
          IProposalRelevance.ADD_SUPPRESSWARNINGS,
          proposals);
    }
  }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaMarkerAnnotation.java   
public String[] getArguments() {
    IMarker marker= getMarker();
    if (marker != null && marker.exists() && isProblem())
        return CorrectionEngine.getProblemArguments(marker);
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:SuppressWarningsSubProcessor.java   
public static void addSuppressWarningsProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    if (problem.isError() && ! JavaCore.ENABLED.equals(context.getCompilationUnit().getJavaProject().getOption(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, true))) {
        return;
    }
    if (JavaCore.DISABLED.equals(context.getCompilationUnit().getJavaProject().getOption(JavaCore.COMPILER_PB_SUPPRESS_WARNINGS, true))) {
        return;
    }

    String warningToken= CorrectionEngine.getWarningToken(problem.getProblemId());
    if (warningToken == null) {
        return;
    }
    for (Iterator<ICommandAccess> iter= proposals.iterator(); iter.hasNext();) {
        Object element= iter.next();
        if (element instanceof SuppressWarningsProposal && warningToken.equals(((SuppressWarningsProposal) element).getWarningToken())) {
            return; // only one at a time
        }
    }

    ASTNode node= problem.getCoveringNode(context.getASTRoot());
    if (node == null) {
        return;
    }

    ASTNode target= node;
    int relevance= IProposalRelevance.ADD_SUPPRESSWARNINGS;
    do {
        relevance= addSuppressWarningsProposalIfPossible(context.getCompilationUnit(), target, warningToken, relevance, proposals);
        if (relevance == 0)
            return;
        target= target.getParent();
    } while (target != null);

    ASTNode importStatement= ASTNodes.getParent(node, ImportDeclaration.class);
    if (importStatement != null && !context.getASTRoot().types().isEmpty()) {
        target= (ASTNode) context.getASTRoot().types().get(0);
        if (target != null) {
            addSuppressWarningsProposalIfPossible(context.getCompilationUnit(), target, warningToken, IProposalRelevance.ADD_SUPPRESSWARNINGS, proposals);
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaMarkerAnnotation.java   
public String[] getArguments() {
    IMarker marker= getMarker();
    if (marker != null && marker.exists() && isProblem())
        return CorrectionEngine.getProblemArguments(marker);
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SuppressWarningsSubProcessor.java   
public static void addSuppressWarningsProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    if (problem.isError() && ! JavaCore.ENABLED.equals(context.getCompilationUnit().getJavaProject().getOption(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, true))) {
        return;
    }
    if (JavaCore.DISABLED.equals(context.getCompilationUnit().getJavaProject().getOption(JavaCore.COMPILER_PB_SUPPRESS_WARNINGS, true))) {
        return;
    }

    String warningToken= CorrectionEngine.getWarningToken(problem.getProblemId());
    if (warningToken == null) {
        return;
    }
    for (Iterator<ICommandAccess> iter= proposals.iterator(); iter.hasNext();) {
        Object element= iter.next();
        if (element instanceof SuppressWarningsProposal && warningToken.equals(((SuppressWarningsProposal) element).getWarningToken())) {
            return; // only one at a time
        }
    }

    ASTNode node= problem.getCoveringNode(context.getASTRoot());
    if (node == null) {
        return;
    }

    ASTNode target= node;
    int relevance= -2;
    do {
        relevance= addSuppressWarningsProposalIfPossible(context.getCompilationUnit(), target, warningToken, relevance, proposals);
        if (relevance == 0)
            return;
        target= target.getParent();
    } while (target != null);

    ASTNode importStatement= ASTNodes.getParent(node, ImportDeclaration.class);
    if (importStatement != null && !context.getASTRoot().types().isEmpty()) {
        target= (ASTNode) context.getASTRoot().types().get(0);
        if (target != null) {
            addSuppressWarningsProposalIfPossible(context.getCompilationUnit(), target, warningToken, -2, proposals);
        }
    }
}