public String getResultLabel(int nMatches) {
   if (nMatches == 1) {
     return Messages.format(
         fSingularLabel, new Object[] {fName, BasicElementLabels.getFileName(fElement)});
   } else {
     return Messages.format(
         fPluralLabel,
         new Object[] {fName, new Integer(nMatches), BasicElementLabels.getFileName(fElement)});
   }
 }
 @Override
 public String getName() {
   return Messages.format(
       RefactoringCoreMessages.MoveCompilationUnitChange_name,
       new String[] {
         BasicElementLabels.getFileName(getCu()), getPackageName(getDestinationPackage())
       });
 }
Ejemplo n.º 3
0
  public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
    IField primary = (IField) fField.getPrimaryElement();
    if (primary == null || !primary.exists()) {
      String message =
          Messages.format(
              RefactoringCoreMessages.RenameFieldRefactoring_deleted,
              BasicElementLabels.getFileName(fField.getCompilationUnit()));
      return RefactoringStatus.createFatalErrorStatus(message);
    }
    fField = primary;

    return Checks.checkIfCuBroken(fField);
  }
Ejemplo n.º 4
0
  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);
  }
Ejemplo n.º 5
0
  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);
  }
  public static Change create(
      ICompilationUnit cu,
      NLSSubstitution[] subs,
      String substitutionPattern,
      IPackageFragment accessorPackage,
      String accessorClassName,
      boolean isEclipseNLS)
      throws CoreException {

    NLSSourceModifier sourceModification = new NLSSourceModifier(substitutionPattern, isEclipseNLS);

    String message =
        Messages.format(
            NLSMessages.NLSSourceModifier_change_description, BasicElementLabels.getFileName(cu));

    TextChange change = new CompilationUnitChange(message, cu);
    MultiTextEdit multiTextEdit = new MultiTextEdit();
    change.setEdit(multiTextEdit);

    accessorClassName =
        sourceModification.createImportForAccessor(
            multiTextEdit, accessorClassName, accessorPackage, cu);

    for (int i = 0; i < subs.length; i++) {
      NLSSubstitution substitution = subs[i];
      int newState = substitution.getState();
      if (substitution.hasStateChanged()) {
        if (newState == NLSSubstitution.EXTERNALIZED) {
          if (substitution.getInitialState() == NLSSubstitution.INTERNALIZED) {
            sourceModification.addNLS(substitution, change, accessorClassName);
          } else if (substitution.getInitialState() == NLSSubstitution.IGNORED) {
            sourceModification.addAccessor(substitution, change, accessorClassName);
          }
        } else if (newState == NLSSubstitution.INTERNALIZED) {
          if (substitution.getInitialState() == NLSSubstitution.IGNORED) {
            sourceModification.deleteTag(substitution, change);
            if (substitution.isValueRename()) {
              sourceModification.replaceValue(substitution, change);
            }
          } else if (substitution.getInitialState() == NLSSubstitution.EXTERNALIZED) {
            sourceModification.deleteAccessor(substitution, change, cu);
            if (!isEclipseNLS) sourceModification.deleteTag(substitution, change);
          }
        } else if (newState == NLSSubstitution.IGNORED) {
          if (substitution.getInitialState() == NLSSubstitution.INTERNALIZED) {
            sourceModification.addNLS(substitution, change, accessorClassName);
            if (substitution.isValueRename()) {
              sourceModification.replaceValue(substitution, change);
            }
          } else {
            if (substitution.getInitialState() == NLSSubstitution.EXTERNALIZED) {
              sourceModification.deleteAccessor(substitution, change, cu);
            }
          }
        }
      } else {
        if (newState == NLSSubstitution.EXTERNALIZED) {
          if (substitution.isKeyRename()) {
            sourceModification.replaceKey(substitution, change);
          }
          if (substitution.isAccessorRename()) {
            sourceModification.replaceAccessor(substitution, change);
          }
        } else {
          if (substitution.isValueRename()) {
            sourceModification.replaceValue(substitution, change);
          }
        }
      }
    }

    return change;
  }