private static void addStatusErrors(
     RefactoringStatus status, boolean hasPotentialMatches, boolean hasNonCuMatches) {
   if (hasPotentialMatches) {
     final RefactoringStatusEntry entry =
         new RefactoringStatusEntry(
             RefactoringStatus.ERROR,
             RefactoringCoreMessages.RefactoringSearchEngine_potential_matches);
     if (!containsStatusEntry(status, entry)) status.addEntry(entry);
   }
   if (hasNonCuMatches) {
     final RefactoringStatusEntry entry =
         new RefactoringStatusEntry(
             RefactoringStatus.ERROR,
             RefactoringCoreMessages.RefactoringSearchEngine_non_cu_matches);
     if (!containsStatusEntry(status, entry)) status.addEntry(entry);
   }
 }
Esempio n. 2
0
 /** Basically just replaces "renamed" with "created" in all messages. */
 private static RefactoringStatus convertRenameToCreateStatus(RefactoringStatus renameStatus) {
   RefactoringStatus result = new RefactoringStatus();
   for (RefactoringStatusEntry entry : renameStatus.getEntries()) {
     String msg = entry.getMessage();
     msg = RenameAnalyzeUtil.convertRenameMessageToCreateMessage(msg);
     result.addEntry(
         entry.getSeverity(), msg, entry.getContext(), entry.getPluginId(), entry.getCode());
   }
   return result;
 }
 private static RefactoringStatus analyzeCompileErrors(
     String newCuSource, CompilationUnit newCUNode, CompilationUnit oldCUNode) {
   RefactoringStatus result = new RefactoringStatus();
   IProblem[] newProblems =
       RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, oldCUNode);
   for (int i = 0; i < newProblems.length; i++) {
     IProblem problem = newProblems[i];
     if (problem.isError())
       result.addEntry(
           new RefactoringStatusEntry(
               (problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING),
               problem.getMessage(),
               new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
   }
   return result;
 }
  private void checkSource(SubProgressMonitor monitor, RefactoringStatus result)
      throws CoreException {
    String newCuSource = fChange.getPreviewContent(new NullProgressMonitor());
    CompilationUnit newCUNode =
        new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
            .parse(newCuSource, fCu, true, true, monitor);

    IProblem[] newProblems =
        RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fCuRewrite.getRoot());
    for (int i = 0; i < newProblems.length; i++) {
      IProblem problem = newProblems[i];
      if (problem.isError())
        result.addEntry(
            new RefactoringStatusEntry(
                (problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING),
                problem.getMessage(),
                new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
    }
  }
  public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
    pm.beginTask(RefactoringCoreMessages.ExtractConstantRefactoring_checking_preconditions, 4);

    /* Note: some checks are performed on change of input widget
     * values. (e.g. see ExtractConstantRefactoring.checkConstantNameOnChange())
     */

    // TODO: possibly add more checking for name conflicts that might
    //      lead to a change in behaviour

    try {
      RefactoringStatus result = new RefactoringStatus();
      fChange = createTextChange(new SubProgressMonitor(pm, 2));

      String newCuSource = fChange.getPreviewContent(new NullProgressMonitor());
      JavaScriptUnit newCUNode =
          new RefactoringASTParser(AST.JLS3).parse(newCuSource, fCu, true, true, null);

      IProblem[] newProblems =
          RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fCuRewrite.getRoot());
      for (int i = 0; i < newProblems.length; i++) {
        IProblem problem = newProblems[i];
        if (problem.isError())
          result.addEntry(
              new RefactoringStatusEntry(
                  (problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING),
                  problem.getMessage(),
                  new JavaStringStatusContext(newCuSource, new SourceRange(problem))));
      }

      fConstantTypeCache = null;
      fCuRewrite.clearASTAndImportRewrites();

      return result;
    } finally {
      pm.done();
    }
  }