private RefactoringStatus checkRelatedMethods() throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    for (Iterator<IMethod> iter = fMethodsToRename.iterator(); iter.hasNext(); ) {
      IMethod method = iter.next();

      result.merge(
          Checks.checkIfConstructorName(
              method, getNewElementName(), method.getDeclaringType().getElementName()));

      String[] msgData =
          new String[] {
            BasicElementLabels.getJavaElementName(method.getElementName()),
            BasicElementLabels.getJavaElementName(
                method.getDeclaringType().getFullyQualifiedName('.'))
          };
      if (!method.exists()) {
        result.addFatalError(
            Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_not_in_model, msgData));
        continue;
      }
      if (method.isBinary())
        result.addFatalError(
            Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_no_binary, msgData));
      if (method.isReadOnly())
        result.addFatalError(
            Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_no_read_only, msgData));
      if (JdtFlags.isNative(method))
        result.addError(
            Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_no_native_1, msgData));
    }
    return result;
  }
 /*
  * Used from www.eclipse.org/articles/article.php?file=Article-Unleashing-the-Power-of-Refactoring/index.html
  */
 @Override
 public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
     throws CoreException, OperationCanceledException {
   RefactoringStatus status = new RefactoringStatus();
   try {
     pm.beginTask("Checking preconditions...", 1);
     if (method == null) {
       status.merge(RefactoringStatus.createFatalErrorStatus("Method has not been specified."));
     } else if (varName == null) {
       status.merge(RefactoringStatus.createFatalErrorStatus("Variable has not been specified."));
     } else if (!method.exists()) {
       status.merge(RefactoringStatus.createFatalErrorStatus("Method does not exist."));
     } else {
       if (!method.isBinary() && !method.getCompilationUnit().isStructureKnown()) {
         status.merge(
             RefactoringStatus.createFatalErrorStatus(
                 "Compilation unit contains compile errors."));
       }
     }
   } finally {
     pm.done();
   }
   return status;
 }
Esempio n. 3
0
 private boolean isNuclearStrikeTargetable(IMethod method) throws JavaModelException {
   return !method.isBinary()
       && !method.isReadOnly()
       && !method.isConstructor()
       && isPrivate(method);
 }