protected void ensureProjectHasRefactoringEnabled(RefactoringStatus status)
      throws PreconditionFailure {
    if (FortranCorePlugin.inTestingMode()) return;

    HashSet<IFile> filesToBeRemoved = new HashSet<IFile>();

    for (IFile f : this.selectedFiles) {
      if (!PhotranVPG.getInstance().doesProjectHaveRefactoringEnabled(f)) {
        if (f.getProject() == null) {
          status.addWarning(
              Messages.bind(
                  Messages.FortranResourceRefactoring_FileIsNotInAFortranProject, f.getName()));
          filesToBeRemoved.add(f);
        } else {
          status.addWarning(
              Messages.bind(
                  Messages.FortranResourceRefactoring_AnalysisRefactoringNotEnabled,
                  f.getProject().getName()));
          filesToBeRemoved.add(f);
        }
      }
    }
    // Remove files that didn't have Refactoring enabled in their projects
    this.selectedFiles.removeAll(filesToBeRemoved);
  }
Esempio n. 2
0
  private RefactoringStatus addDelegates() throws JavaModelException, CoreException {

    RefactoringStatus status = new RefactoringStatus();
    CompilationUnitRewrite rewrite = new CompilationUnitRewrite(fField.getCompilationUnit());
    rewrite.setResolveBindings(true);

    // add delegate for the field
    if (RefactoringAvailabilityTester.isDelegateCreationAvailable(fField)) {
      FieldDeclaration fieldDeclaration =
          ASTNodeSearchUtil.getFieldDeclarationNode(fField, rewrite.getRoot());
      if (fieldDeclaration.fragments().size() > 1) {
        status.addWarning(
            Messages.format(
                RefactoringCoreMessages
                    .DelegateCreator_cannot_create_field_delegate_more_than_one_fragment,
                BasicElementLabels.getJavaElementName(fField.getElementName())),
            JavaStatusContext.create(fField));
      } else if (((VariableDeclarationFragment) fieldDeclaration.fragments().get(0))
              .getInitializer()
          == null) {
        status.addWarning(
            Messages.format(
                RefactoringCoreMessages.DelegateCreator_cannot_create_field_delegate_no_initializer,
                BasicElementLabels.getJavaElementName(fField.getElementName())),
            JavaStatusContext.create(fField));
      } else {
        DelegateFieldCreator creator = new DelegateFieldCreator();
        creator.setDeclareDeprecated(fDelegateDeprecation);
        creator.setDeclaration(fieldDeclaration);
        creator.setNewElementName(getNewElementName());
        creator.setSourceRewrite(rewrite);
        creator.prepareDelegate();
        creator.createEdit();
      }
    }

    // add delegates for getter and setter methods
    // there may be getters even if the field is static final
    if (getGetter() != null && fRenameGetter)
      addMethodDelegate(getGetter(), getNewGetterName(), rewrite);
    if (getSetter() != null && fRenameSetter)
      addMethodDelegate(getSetter(), getNewSetterName(), rewrite);

    final CompilationUnitChange change = rewrite.createChange(true);
    if (change != null) {
      change.setKeepPreviewEdits(true);
      fChangeManager.manage(fField.getCompilationUnit(), change);
    }

    return status;
  }
Esempio n. 3
0
 private static void checkMethodInType(
     IType destinationType, RefactoringStatus result, IMethod method) throws JavaModelException {
   IMethod[] destinationTypeMethods = destinationType.getMethods();
   IMethod found = findMethod(method, destinationTypeMethods);
   if (found != null) {
     RefactoringStatusContext context =
         JavaStatusContext.create(destinationType.getCompilationUnit(), found.getSourceRange());
     String message =
         Messages.format(
             RefactoringCoreMessages.MemberCheckUtil_signature_exists,
             new String[] {
               BasicElementLabels.getJavaElementName(method.getElementName()),
               getQualifiedLabel(destinationType)
             });
     result.addError(message, context);
   } else {
     IMethod similar = Checks.findMethod(method, destinationType);
     if (similar != null) {
       String message =
           Messages.format(
               RefactoringCoreMessages.MemberCheckUtil_same_param_count,
               new String[] {
                 BasicElementLabels.getJavaElementName(method.getElementName()),
                 getQualifiedLabel(destinationType)
               });
       RefactoringStatusContext context =
           JavaStatusContext.create(
               destinationType.getCompilationUnit(), similar.getSourceRange());
       result.addWarning(message, context);
     }
   }
 }
  @Override
  protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm)
      throws PreconditionFailure {
    ensureProjectHasRefactoringEnabled(status);

    // ASTSubroutineSubprogramNode s = getNode(astOfFileInEditor, selectedRegionInEditor,
    // ASTSubroutineSubprogramNode.class);

    newParameterList = new ArrayList<ASTSubroutineParNode>();
    if (sigma == null) sigma = new ArrayList<Integer>();

    IASTNode temporaryNode = findEnclosingNode(astOfFileInEditor, selectedRegionInEditor);

    if (temporaryNode == null)
      fail(Messages.PermuteSubroutineArgsRefactoring_selectedTextNotSubroutine);

    if (temporaryNode instanceof ASTSubroutineSubprogramNode)
      selectedSubroutine = ((ASTSubroutineSubprogramNode) temporaryNode).getSubroutineStmt();
    else if (temporaryNode instanceof ASTSubroutineStmtNode) {
      if (temporaryNode.findNearestAncestor(ASTSubroutineSubprogramNode.class) == null)
        fail(Messages.PermuteSubroutineArgsRefactoring_selectSubroutineError);
      selectedSubroutine = (ASTSubroutineStmtNode) temporaryNode;
    } else fail(Messages.PermuteSubroutineArgsRefactoring_selectedTextNotSubroutine);

    oldParameterList = getSubroutineParameters();
    newParameterList = getSubroutineParameters();

    if (!matchingDeclarationsInInterfacesUniquelyBind())
      status.addWarning(
          Messages.PermuteSubroutineArgsRefactoring_matchingDeclarationsDoNotUniquelyBind);
  }
  @Override
  protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm)
      throws PreconditionFailure {
    ensureProjectHasRefactoringEnabled(status);

    // Change AST to represent DO-loops as ASTProperLoopConstructNodes
    LoopReplacer.replaceAllLoopsIn(this.astOfFileInEditor.getRoot());

    outerLoop = findOuterLoop();
    innerLoop = findInnerLoop();
    if (outerLoop == null || innerLoop == null || outerLoop == innerLoop)
      fail(Messages.InterchangeLoopsRefactoring_SelectTwoPerfNextedLoops);

    status.addWarning(Messages.InterchangeLoopsRefactoring_UncheckedTransNotGuaranteedToPreserve);
  }
 private void checkDirtyFile(RefactoringStatus result, IFile file) {
   if (!file.exists()) return;
   ITextFileBuffer buffer =
       FileBuffers.getTextFileBufferManager()
           .getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
   if (buffer != null && buffer.isDirty()) {
     String message = RefactoringCoreMessages.DeleteResourcesProcessor_warning_unsaved_file;
     if (buffer.isStateValidated() && buffer.isSynchronized()) {
       result.addWarning(
           Messages.format(message, BasicElementLabels.getPathLabel(file.getFullPath(), false)));
     } else {
       result.addFatalError(
           Messages.format(message, BasicElementLabels.getPathLabel(file.getFullPath(), false)));
     }
   }
 }
  @Override
  protected final void preCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm)
      throws PreconditionFailure {
    // status.addWarning("C preprocessor directives are IGNORED by the refactoring engine.  Use at
    // your own risk.");

    if (FIXED_FORM_REFACTORING_ENABLED) {
      for (IFile file : this.selectedFiles) {
        if (org.eclipse.photran.internal.core.sourceform.SourceForm.isFixedForm(file)) {
          status.addWarning(
              Messages.FortranResourceRefactoring_IndentationAndLineLengthAreNotChecked);
          return;
        }
      }
    }
  }
Esempio n. 8
0
 private RefactoringStatus checkEnclosingHierarchy() {
   IType current = fField.getDeclaringType();
   if (Checks.isTopLevel(current)) return null;
   RefactoringStatus result = new RefactoringStatus();
   while (current != null) {
     IField otherField = current.getField(getNewElementName());
     if (otherField.exists()) {
       String msg =
           Messages.format(
               RefactoringCoreMessages.RenameFieldRefactoring_hiding2,
               new String[] {
                 BasicElementLabels.getJavaElementName(getNewElementName()),
                 BasicElementLabels.getJavaElementName(current.getFullyQualifiedName('.')),
                 BasicElementLabels.getJavaElementName(otherField.getElementName())
               });
       result.addWarning(msg, JavaStatusContext.create(otherField));
     }
     current = current.getDeclaringType();
   }
   return result;
 }
Esempio n. 9
0
 private RefactoringStatus checkNestedHierarchy(IType type) throws CoreException {
   IType[] nestedTypes = type.getTypes();
   if (nestedTypes == null) return null;
   RefactoringStatus result = new RefactoringStatus();
   for (int i = 0; i < nestedTypes.length; i++) {
     IField otherField = nestedTypes[i].getField(getNewElementName());
     if (otherField.exists()) {
       String msg =
           Messages.format(
               RefactoringCoreMessages.RenameFieldRefactoring_hiding,
               new String[] {
                 BasicElementLabels.getJavaElementName(fField.getElementName()),
                 BasicElementLabels.getJavaElementName(getNewElementName()),
                 BasicElementLabels.getJavaElementName(nestedTypes[i].getFullyQualifiedName('.'))
               });
       result.addWarning(msg, JavaStatusContext.create(otherField));
     }
     result.merge(checkNestedHierarchy(nestedTypes[i]));
   }
   return result;
 }
Esempio n. 10
0
  public RefactoringStatus checkNewElementName(String newName) throws CoreException {
    Assert.isNotNull(newName, "new name"); // $NON-NLS-1$
    RefactoringStatus result = Checks.checkFieldName(newName, fField);

    if (isInstanceField(fField) && (!Checks.startsWithLowerCase(newName)))
      result.addWarning(
          fIsComposite
              ? Messages.format(
                  RefactoringCoreMessages.RenameFieldRefactoring_should_start_lowercase2,
                  new String[] {
                    BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel()
                  })
              : RefactoringCoreMessages.RenameFieldRefactoring_should_start_lowercase);

    if (Checks.isAlreadyNamed(fField, newName))
      result.addError(
          fIsComposite
              ? Messages.format(
                  RefactoringCoreMessages.RenameFieldRefactoring_another_name2,
                  new String[] {
                    BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel()
                  })
              : RefactoringCoreMessages.RenameFieldRefactoring_another_name,
          JavaStatusContext.create(fField));

    if (fField.getDeclaringType().getField(newName).exists())
      result.addError(
          fIsComposite
              ? Messages.format(
                  RefactoringCoreMessages.RenameFieldRefactoring_field_already_defined2,
                  new String[] {
                    BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel()
                  })
              : RefactoringCoreMessages.RenameFieldRefactoring_field_already_defined,
          JavaStatusContext.create(fField.getDeclaringType().getField(newName)));
    return result;
  }