コード例 #1
0
  @Nullable
  public RefactoringElementListener getRefactoringElementListener(final PsiElement element) {
    if (data.TEST_OBJECT.equals(TestType.PACKAGE.getType())) {
      if (!(element instanceof PsiPackage)) return null;
      final RefactoringElementListener listener =
          RefactoringListeners.getListener((PsiPackage) element, myPackage);
      return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener);
    } else if (data.TEST_OBJECT.equals(TestType.CLASS.getType())) {
      if (!(element instanceof PsiClass) && !(element instanceof PsiPackage)) return null;
      final RefactoringElementListener listener =
          RefactoringListeners.getClassOrPackageListener(element, myClass);
      return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener);
    } else if (data.TEST_OBJECT.equals(TestType.METHOD.getType())) {
      if (!(element instanceof PsiMethod)) {
        final RefactoringElementListener listener =
            RefactoringListeners.getClassOrPackageListener(element, myClass);
        return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener);
      }
      final PsiMethod method = (PsiMethod) element;
      if (!method.getName().equals(data.getMethodName())) return null;
      if (!method.getContainingClass().equals(myClass.getPsiElement())) return null;
      class Listener extends RefactoringElementAdapter implements UndoRefactoringElementListener {
        public void elementRenamedOrMoved(@NotNull final PsiElement newElement) {
          data.setTestMethod(PsiLocation.fromPsiElement((PsiMethod) newElement));
        }

        @Override
        public void undoElementMovedOrRenamed(
            @NotNull PsiElement newElement, @NotNull String oldQualifiedName) {
          final int methodIdx = oldQualifiedName.indexOf("#") + 1;
          if (methodIdx <= 0 || methodIdx >= oldQualifiedName.length()) return;
          data.METHOD_NAME = oldQualifiedName.substring(methodIdx);
        }
      }
      return RunConfigurationExtension.wrapRefactoringElementListener(
          element, this, new Listener());
    }
    return null;
  }
コード例 #2
0
 public String getPackage() {
   return !data.TEST_OBJECT.equals(TestType.PACKAGE.getType()) ? null : data.getPackageName();
 }
コード例 #3
0
 public String getRunClass() {
   return !data.TEST_OBJECT.equals(TestType.CLASS.getType())
           && !data.TEST_OBJECT.equals(TestType.METHOD.getType())
       ? null
       : data.getMainClassName();
 }