コード例 #1
0
ファイル: ConflictsUtil.java プロジェクト: jexp/idea2
  public static void checkMethodConflicts(
      @Nullable PsiClass aClass,
      PsiMethod refactoredMethod,
      PsiMethod prototype,
      final MultiMap<PsiElement, String> conflicts) {
    if (prototype == null) return;

    PsiMethod method = aClass != null ? aClass.findMethodBySignature(prototype, true) : null;

    if (method != null && method != refactoredMethod) {
      if (aClass.equals(method.getContainingClass())) {
        final String classDescr =
            aClass instanceof PsiAnonymousClass
                ? RefactoringBundle.message("current.class")
                : RefactoringUIUtil.getDescription(aClass, false);
        conflicts.putValue(
            method,
            RefactoringBundle.message(
                "method.0.is.already.defined.in.the.1",
                getMethodPrototypeString(prototype),
                classDescr));
      } else { // method somewhere in base class
        if (JavaPsiFacade.getInstance(method.getProject())
            .getResolveHelper()
            .isAccessible(method, aClass, null)) {
          String protoMethodInfo = getMethodPrototypeString(prototype);
          String className =
              CommonRefactoringUtil.htmlEmphasize(
                  UsageViewUtil.getDescriptiveName(method.getContainingClass()));
          if (PsiUtil.getAccessLevel(prototype.getModifierList())
              >= PsiUtil.getAccessLevel(method.getModifierList())) {
            boolean isMethodAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
            boolean isMyMethodAbstract =
                refactoredMethod != null
                    && refactoredMethod.hasModifierProperty(PsiModifier.ABSTRACT);
            final String conflict =
                isMethodAbstract != isMyMethodAbstract
                    ? RefactoringBundle.message(
                        "method.0.will.implement.method.of.the.base.class",
                        protoMethodInfo,
                        className)
                    : RefactoringBundle.message(
                        "method.0.will.override.a.method.of.the.base.class",
                        protoMethodInfo,
                        className);
            conflicts.putValue(method, conflict);
          } else { // prototype is private, will be compile-error
            conflicts.putValue(
                method,
                RefactoringBundle.message(
                    "method.0.will.hide.method.of.the.base.class", protoMethodInfo, className));
          }
        }
      }
    }
  }
コード例 #2
0
  private void setNewName(@NotNull String newName) {
    if (myPrimaryElement == null) {
      myCommandName = RefactoringBundle.message("renaming.something");
      return;
    }

    myNewName = newName;
    myAllRenames.put(myPrimaryElement, newName);
    myCommandName =
        RefactoringBundle.message(
            "renaming.0.1.to.2",
            UsageViewUtil.getType(myPrimaryElement),
            UsageViewUtil.getDescriptiveName(myPrimaryElement),
            newName);
  }
コード例 #3
0
  @Override
  protected void performRefactoringRename(final String newName, final StartMarkAction markAction) {
    try {
      final PsiNamedElement variable = getVariable();
      if (variable != null && !newName.equals(myOldName)) {
        if (isIdentifier(newName, variable.getLanguage())) {
          final PsiElement substituted = getSubstituted();
          if (substituted == null) {
            return;
          }

          final String commandName =
              RefactoringBundle.message(
                  "renaming.0.1.to.2",
                  UsageViewUtil.getType(variable),
                  UsageViewUtil.getDescriptiveName(variable),
                  newName);
          CommandProcessor.getInstance()
              .executeCommand(
                  myProject,
                  new Runnable() {
                    @Override
                    public void run() {
                      performRenameInner(substituted, newName);
                      PsiDocumentManager.getInstance(myProject).commitAllDocuments();
                    }
                  },
                  commandName,
                  null);
        }
      }
    } finally {
      try {
        ((EditorImpl) InjectedLanguageUtil.getTopLevelEditor(myEditor)).stopDumbLater();
      } finally {
        FinishMarkAction.finish(myProject, myEditor, markAction);
      }
    }
  }
コード例 #4
0
 private String getCommandName(final PsiClass subclass, String newName) {
   return RefactoringBundle.message(
       "extract.superclass.command.name", newName, UsageViewUtil.getDescriptiveName(subclass));
 }
コード例 #5
0
 private String getCommandName() {
   return RefactoringBundle.message(
       "extract.interface.command.name",
       myInterfaceName,
       UsageViewUtil.getDescriptiveName(myClass));
 }