@Override
  public final RefactoringStatus checkNewElementName(String newName) {
    Assert.isNotNull(newName, "new name"); // $NON-NLS-1$

    RefactoringStatus status =
        Checks.checkName(newName, JavaConventionsUtil.validateMethodName(newName, fMethod));
    if (status.isOK() && !Checks.startsWithLowerCase(newName))
      status =
          RefactoringStatus.createWarningStatus(
              fIsComposite
                  ? Messages.format(
                      RefactoringCoreMessages.Checks_method_names_lowercase2,
                      new String[] {
                        BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel()
                      })
                  : RefactoringCoreMessages.Checks_method_names_lowercase);

    if (Checks.isAlreadyNamed(fMethod, newName))
      status.addFatalError(
          fIsComposite
              ? Messages.format(
                  RefactoringCoreMessages.RenameMethodRefactoring_same_name2,
                  new String[] {
                    BasicElementLabels.getJavaElementName(newName), getDeclaringTypeLabel()
                  })
              : RefactoringCoreMessages.RenameMethodRefactoring_same_name,
          JavaStatusContext.create(fMethod));
    return status;
  }
Exemple #2
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;
  }