Exemple #1
0
 private RefactoringStatus checkAccessorDeclarations(IProgressMonitor pm, IMethod existingAccessor)
     throws CoreException {
   RefactoringStatus result = new RefactoringStatus();
   SearchPattern pattern =
       SearchPattern.createPattern(
           existingAccessor,
           IJavaSearchConstants.DECLARATIONS,
           SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
   IJavaSearchScope scope = SearchEngine.createHierarchyScope(fField.getDeclaringType());
   SearchResultGroup[] groupDeclarations =
       RefactoringSearchEngine.search(pattern, scope, pm, result);
   Assert.isTrue(groupDeclarations.length > 0);
   if (groupDeclarations.length != 1) {
     String message =
         Messages.format(
             RefactoringCoreMessages.RenameFieldRefactoring_overridden,
             JavaElementUtil.createMethodSignature(existingAccessor));
     result.addError(message);
   } else {
     SearchResultGroup group = groupDeclarations[0];
     Assert.isTrue(group.getSearchResults().length > 0);
     if (group.getSearchResults().length != 1) {
       String message =
           Messages.format(
               RefactoringCoreMessages.RenameFieldRefactoring_overridden_or_overrides,
               JavaElementUtil.createMethodSignature(existingAccessor));
       result.addError(message);
     }
   }
   return result;
 }
Exemple #2
0
  private RefactoringStatus checkNewAccessor(IMethod existingAccessor, String newAccessorName)
      throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    IMethod accessor =
        JavaModelUtil.findMethod(
            newAccessorName,
            existingAccessor.getParameterTypes(),
            false,
            fField.getDeclaringType());
    if (accessor == null || !accessor.exists()) return null;

    String message =
        Messages.format(
            RefactoringCoreMessages.RenameFieldRefactoring_already_exists,
            new String[] {
              JavaElementUtil.createMethodSignature(accessor),
              BasicElementLabels.getJavaElementName(
                  fField.getDeclaringType().getFullyQualifiedName('.'))
            });
    result.addError(message, JavaStatusContext.create(accessor));
    return result;
  }