當前位置: 首頁>>代碼示例>>Java>>正文


Java ExtractSuperClassUtil類代碼示例

本文整理匯總了Java中com.intellij.refactoring.extractSuperclass.ExtractSuperClassUtil的典型用法代碼示例。如果您正苦於以下問題:Java ExtractSuperClassUtil類的具體用法?Java ExtractSuperClassUtil怎麽用?Java ExtractSuperClassUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ExtractSuperClassUtil類屬於com.intellij.refactoring.extractSuperclass包,在下文中一共展示了ExtractSuperClassUtil類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: invoke

import com.intellij.refactoring.extractSuperclass.ExtractSuperClassUtil; //導入依賴的package包/類
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
  if (elements.length != 1) return;

  myProject = project;
  myClass = (PsiClass)elements[0];


  if (!CommonRefactoringUtil.checkReadOnlyStatus(project, myClass)) return;

  final ExtractInterfaceDialog dialog = new ExtractInterfaceDialog(myProject, myClass);
  if (!dialog.showAndGet() || !dialog.isExtractSuperclass()) {
    return;
  }
  final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
  ExtractSuperClassUtil.checkSuperAccessible(dialog.getTargetDirectory(), conflicts, myClass);
  if (!ExtractSuperClassUtil.showConflicts(dialog, conflicts, myProject)) return;
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    public void run() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        public void run() {
          myInterfaceName = dialog.getExtractedSuperName();
          mySelectedMembers = ArrayUtil.toObjectArray(dialog.getSelectedMemberInfos(), MemberInfo.class);
          myTargetDir = dialog.getTargetDirectory();
          myJavaDocPolicy = new DocCommentPolicy(dialog.getDocCommentPolicy());
          try {
            doRefactoring();
          }
          catch (IncorrectOperationException e) {
            LOG.error(e);
          }
        }
      });
    }
  }, REFACTORING_NAME, null);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:36,代碼來源:ExtractInterfaceHandler.java

示例2: testAnonymClass

import com.intellij.refactoring.extractSuperclass.ExtractSuperClassUtil; //導入依賴的package包/類
public void testAnonymClass() throws Exception {
  String rootBefore = getRoot() + "/before";
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk14());
  final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
  PsiClass psiClass = myJavaFacade.findClass("Test", ProjectScope.getAllScope(myProject));
  assertNotNull(psiClass);
  final PsiField[] fields = psiClass.getFields();
  assertTrue(fields.length == 1);
  final PsiExpression initializer = fields[0].getInitializer();
  assertNotNull(initializer);
  assertInstanceOf(initializer, PsiNewExpression.class);
  final PsiAnonymousClass anonymousClass = ((PsiNewExpression)initializer).getAnonymousClass();
  assertNotNull(anonymousClass);
  final ArrayList<MemberInfo> infos = new ArrayList<>();
  MemberInfo.extractClassMembers(anonymousClass, infos, member -> true, false);
  for (MemberInfo info : infos) {
    info.setChecked(true);
  }
  new WriteCommandAction.Simple(myProject) {
    @Override
    protected void run() throws Throwable {
      ExtractSuperClassUtil
        .extractSuperClass(myProject, psiClass.getContainingFile().getContainingDirectory(), "TestSubclass", anonymousClass,
                           infos.toArray(new MemberInfo[infos.size()]), new DocCommentPolicy(DocCommentPolicy.ASIS));
    }
  }.execute();
  String rootAfter = getRoot() + "/after";
  VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
  myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
  IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:32,代碼來源:ExtractSuperClassTest.java

示例3: invoke

import com.intellij.refactoring.extractSuperclass.ExtractSuperClassUtil; //導入依賴的package包/類
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
  if (elements.length != 1) return;

  myProject = project;
  myClass = (PsiClass)elements[0];


  if (!CommonRefactoringUtil.checkReadOnlyStatus(project, myClass)) return;

  final ExtractInterfaceDialog dialog = new ExtractInterfaceDialog(myProject, myClass);
  dialog.show();
  if (!dialog.isOK() || !dialog.isExtractSuperclass()) return;
  final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
  ExtractSuperClassUtil.checkSuperAccessible(dialog.getTargetDirectory(), conflicts, myClass);
  if (!ExtractSuperClassUtil.showConflicts(dialog, conflicts, myProject)) return;
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    public void run() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        public void run() {
          myInterfaceName = dialog.getExtractedSuperName();
          mySelectedMembers = ArrayUtil.toObjectArray(dialog.getSelectedMemberInfos(), MemberInfo.class);
          myTargetDir = dialog.getTargetDirectory();
          myJavaDocPolicy = new DocCommentPolicy(dialog.getDocCommentPolicy());
          try {
            doRefactoring();
          }
          catch (IncorrectOperationException e) {
            LOG.error(e);
          }
        }
      });
    }
  }, REFACTORING_NAME, null);

}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:36,代碼來源:ExtractInterfaceHandler.java


注:本文中的com.intellij.refactoring.extractSuperclass.ExtractSuperClassUtil類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。