当前位置: 首页>>代码示例>>Java>>正文


Java PullUpProcessor类代码示例

本文整理汇总了Java中com.intellij.refactoring.memberPullUp.PullUpProcessor的典型用法代码示例。如果您正苦于以下问题:Java PullUpProcessor类的具体用法?Java PullUpProcessor怎么用?Java PullUpProcessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PullUpProcessor类属于com.intellij.refactoring.memberPullUp包,在下文中一共展示了PullUpProcessor类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pullUp

import com.intellij.refactoring.memberPullUp.PullUpProcessor; //导入依赖的package包/类
private static void pullUp(PsiMethod method, PsiClass containingClass, PsiClass baseClass) {
  if (!FileModificationService.getInstance().prepareFileForWrite(baseClass.getContainingFile())) return;
  final MemberInfo memberInfo = new MemberInfo(method);
  memberInfo.setChecked(true);
  memberInfo.setToAbstract(true);
  new PullUpProcessor(containingClass, baseClass, new MemberInfo[]{memberInfo}, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:PullAsAbstractUpFix.java

示例2: doTest

import com.intellij.refactoring.memberPullUp.PullUpProcessor; //导入依赖的package包/类
private void doTest(final String... conflicts) throws Exception {
  final MultiMap<PsiElement, String> conflictsMap = new MultiMap<>();
  doTest((rootDir, rootAfter) -> {
    final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
    assertTrue("Source class not found", srcClass != null);

    final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
    assertTrue("Target class not found", targetClass != null);

    final PsiMethod[] methods = srcClass.getMethods();
    assertTrue("No methods found", methods.length > 0);
    final MemberInfo[] membersToMove = new MemberInfo[1];
    final MemberInfo memberInfo = new MemberInfo(methods[0]);
    memberInfo.setChecked(true);
    membersToMove[0] = memberInfo;

    final PsiDirectory targetDirectory = targetClass.getContainingFile().getContainingDirectory();
    final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
    conflictsMap.putAllValues(
      PullUpConflictsUtil.checkConflicts(membersToMove, srcClass, targetClass, targetPackage, targetDirectory,
                                         psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(membersToMove), psiMethod)));

    new PullUpProcessor(srcClass, targetClass, membersToMove, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
  });

  if (conflicts.length != 0 && conflictsMap.isEmpty()) {
    fail("Conflict was not detected");
  }
  final HashSet<String> values = new HashSet<>(conflictsMap.values());
  final HashSet<String> expected = new HashSet<>(Arrays.asList(conflicts));

  assertEquals(expected.size(), values.size());
  for (String value : values) {
    if (!expected.contains(value)) {
      fail("Conflict: " + value + " is unexpectedly reported");
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:PullUpMultifileTest.java

示例3: checkedInterfacesContain

import com.intellij.refactoring.memberPullUp.PullUpProcessor; //导入依赖的package包/类
public boolean checkedInterfacesContain(PsiMethod psiMethod) {
  return PullUpProcessor.checkedInterfacesContain(myMemberInfos, psiMethod);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:ExtractSuperclassDialog.java

示例4: doTest

import com.intellij.refactoring.memberPullUp.PullUpProcessor; //导入依赖的package包/类
private void doTest(MemberInfo[] members,
                    @NonNls String newClassName,
                    String targetPackageName,
                    VirtualFile rootDir,
                    PsiClass psiClass,
                    String[] conflicts) throws IOException {
  PsiDirectory targetDirectory;
  if (targetPackageName == null) {
    targetDirectory = psiClass.getContainingFile().getContainingDirectory();
  } else {
    final PsiPackage aPackage = myJavaFacade.findPackage(targetPackageName);
    assertNotNull(aPackage);
    targetDirectory = aPackage.getDirectories()[0];
  }
  ExtractSuperClassProcessor processor = new ExtractSuperClassProcessor(myProject,
                                                                        targetDirectory,
                                                                        newClassName,
                                                                        psiClass, members,
                                                                        false,
                                                                        new DocCommentPolicy<>(DocCommentPolicy.ASIS));
  final PsiPackage targetPackage;
  if (targetDirectory != null) {
    targetPackage = JavaDirectoryService.getInstance().getPackage(targetDirectory);
  }
  else {
    targetPackage = null;
  }
  final PsiClass superClass = psiClass.getExtendsListTypes().length > 0 ? psiClass.getSuperClass() : null;
  final MultiMap<PsiElement, String> conflictsMap =
    PullUpConflictsUtil.checkConflicts(members, psiClass, superClass, targetPackage, targetDirectory,
                                       psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(members), psiMethod), false);
  if (conflicts != null) {
    if (conflictsMap.isEmpty()) {
      fail("Conflicts were not detected");
    }
    final HashSet<String> expectedConflicts = new HashSet<>(Arrays.asList(conflicts));
    final HashSet<String> actualConflicts = new HashSet<>(conflictsMap.values());
    assertEquals(expectedConflicts.size(), actualConflicts.size());
    for (String actualConflict : actualConflicts) {
      if (!expectedConflicts.contains(actualConflict)) {
        fail("Unexpected conflict: " + actualConflict);
      }
    }
  } else if (!conflictsMap.isEmpty()) {
    fail("Unexpected conflicts!!!");
  }
  processor.run();
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();
  FileDocumentManager.getInstance().saveAllDocuments();

  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,代码行数:56,代码来源:ExtractSuperClassTest.java

示例5: doTest

import com.intellij.refactoring.memberPullUp.PullUpProcessor; //导入依赖的package包/类
private void doTest(final boolean checkMembersMovedCount,
                    String conflictMessage,
                    RefactoringTestUtil.MemberDescriptor... membersToFind) {
  final MultiMap<PsiElement, String> conflictsMap = new MultiMap<>();
  configureByFile(BASE_PATH + getTestName(false) + ".java");
  PsiElement elementAt = getFile().findElementAt(getEditor().getCaretModel().getOffset());
  final PsiClass sourceClass = PsiTreeUtil.getParentOfType(elementAt, PsiClass.class);
  assertNotNull(sourceClass);

  PsiClass targetClass = sourceClass.getSuperClass();
  assertNotNull(targetClass);
  if (!targetClass.isWritable()) {
    final PsiClass[] interfaces = sourceClass.getInterfaces();
    assertEquals(1, interfaces.length);
    assertTrue(interfaces[0].isWritable());
    targetClass = interfaces[0];
  }
  final MemberInfo[] infos = RefactoringTestUtil.findMembers(sourceClass, membersToFind);

  final int[] countMoved = {0};
  final MoveMemberListener listener = (aClass, member) -> {
    assertEquals(sourceClass, aClass);
    countMoved[0]++;
  };
  JavaRefactoringListenerManager.getInstance(getProject()).addMoveMembersListener(listener);
  final PsiDirectory targetDirectory = targetClass.getContainingFile().getContainingDirectory();
  final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
  conflictsMap.putAllValues(
    PullUpConflictsUtil
      .checkConflicts(infos, sourceClass, targetClass, targetPackage, targetDirectory,
                      psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(infos), psiMethod))
  );
  final PullUpProcessor helper = new PullUpProcessor(sourceClass, targetClass, infos, new DocCommentPolicy(DocCommentPolicy.ASIS));
  helper.run();
  UIUtil.dispatchAllInvocationEvents();
  JavaRefactoringListenerManager.getInstance(getProject()).removeMoveMembersListener(listener);

  if (conflictMessage != null && conflictsMap.isEmpty()) {
    fail("Conflict was not detected");
  }

  if (conflictMessage == null && !conflictsMap.isEmpty()) {
    fail(conflictsMap.values().iterator().next());
  }

  if (conflictMessage != null && !IGNORE_CONFLICTS.equals(conflictMessage)) {
    assertEquals(conflictMessage, conflictsMap.values().iterator().next());
    return;
  }

  if (checkMembersMovedCount) {
    assertEquals(countMoved[0], membersToFind.length);
  }
  checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:56,代码来源:PullUpTest.java

示例6: checkedInterfacesContain

import com.intellij.refactoring.memberPullUp.PullUpProcessor; //导入依赖的package包/类
@Override
public boolean checkedInterfacesContain(PsiMethod psiMethod) {
  return PullUpProcessor.checkedInterfacesContain(myMemberInfos, psiMethod);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:GrPullUpDialog.java

示例7: doTest

import com.intellij.refactoring.memberPullUp.PullUpProcessor; //导入依赖的package包/类
private void doTest(final String... conflicts) throws Exception
{
	final MultiMap<PsiElement, String> conflictsMap = new MultiMap<>();
	doTest((rootDir, rootAfter) ->
	{
		final PsiClass srcClass = myJavaFacade.findClass("a.A", GlobalSearchScope.allScope(myProject));
		assertTrue("Source class not found", srcClass != null);

		final PsiClass targetClass = myJavaFacade.findClass("b.B", GlobalSearchScope.allScope(myProject));
		assertTrue("Target class not found", targetClass != null);

		final PsiMethod[] methods = srcClass.getMethods();
		assertTrue("No methods found", methods.length > 0);
		final MemberInfo[] membersToMove = new MemberInfo[1];
		final MemberInfo memberInfo = new MemberInfo(methods[0]);
		memberInfo.setChecked(true);
		membersToMove[0] = memberInfo;

		final PsiDirectory targetDirectory = targetClass.getContainingFile().getContainingDirectory();
		final PsiJavaPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
		conflictsMap.putAllValues(PullUpConflictsUtil.checkConflicts(membersToMove, srcClass, targetClass, targetPackage, targetDirectory, psiMethod -> PullUpProcessor.checkedInterfacesContain
				(Arrays.asList(membersToMove), psiMethod)));

		new PullUpProcessor(srcClass, targetClass, membersToMove, new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
	});

	if(conflicts.length != 0 && conflictsMap.isEmpty())
	{
		fail("Conflict was not detected");
	}
	final HashSet<String> values = new HashSet<>(conflictsMap.values());
	final HashSet<String> expected = new HashSet<>(Arrays.asList(conflicts));

	assertEquals(expected.size(), values.size());
	for(String value : values)
	{
		if(!expected.contains(value))
		{
			fail("Conflict: " + value + " is unexpectedly reported");
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:43,代码来源:PullUpMultifileTest.java

示例8: doTest

import com.intellij.refactoring.memberPullUp.PullUpProcessor; //导入依赖的package包/类
private void doTest(@NonNls final String className,
                    @NonNls final String newClassName,
                    String[] conflicts,
                    String targetPackageName,
                    RefactoringTestUtil.MemberDescriptor... membersToFind) throws Exception {
  String rootBefore = getRoot() + "/before";
  PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk14());
  final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
  PsiClass psiClass = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
  assertNotNull(psiClass);
  final MemberInfo[] members = RefactoringTestUtil.findMembers(psiClass, membersToFind);
  PsiDirectory targetDirectory;
  if (targetPackageName == null) {
    targetDirectory = psiClass.getContainingFile().getContainingDirectory();
  } else {
    final PsiJavaPackage aPackage = myJavaFacade.findPackage(targetPackageName);
    assertNotNull(aPackage);
    targetDirectory = aPackage.getDirectories()[0];
  }
  ExtractSuperClassProcessor processor = new ExtractSuperClassProcessor(myProject,
                                                                        targetDirectory,
                                                                        newClassName,
                                                                        psiClass, members,
                                                                        false,
                                                                        new DocCommentPolicy<PsiComment>(DocCommentPolicy.ASIS));
  final PsiJavaPackage targetPackage;
  if (targetDirectory != null) {
    targetPackage = JavaDirectoryService.getInstance().getPackage(targetDirectory);
  }
  else {
    targetPackage = null;
  }
  final PsiClass superClass = psiClass.getExtendsListTypes().length > 0 ? psiClass.getSuperClass() : null;
  final MultiMap<PsiElement, String> conflictsMap =
    PullUpConflictsUtil.checkConflicts(members, psiClass, superClass, targetPackage, targetDirectory, new InterfaceContainmentVerifier() {
      @Override
      public boolean checkedInterfacesContain(PsiMethod psiMethod) {
        return PullUpProcessor.checkedInterfacesContain(Arrays.asList(members), psiMethod);
      }
    }, false);
  if (conflicts != null) {
    if (conflictsMap.isEmpty()) {
      fail("Conflicts were not detected");
    }
    final HashSet<String> expectedConflicts = new HashSet<String>(Arrays.asList(conflicts));
    final HashSet<String> actualConflicts = new HashSet<String>(conflictsMap.values());
    assertEquals(expectedConflicts.size(), actualConflicts.size());
    for (String actualConflict : actualConflicts) {
      if (!expectedConflicts.contains(actualConflict)) {
        fail("Unexpected conflict: " + actualConflict);
      }
    }
  } else if (!conflictsMap.isEmpty()) {
    fail("Unexpected conflicts!!!");
  }
  processor.run();
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();
  FileDocumentManager.getInstance().saveAllDocuments();

  String rootAfter = getRoot() + "/after";
  VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
  myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
  IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:65,代码来源:ExtractSuperClassTest.java

示例9: doTest

import com.intellij.refactoring.memberPullUp.PullUpProcessor; //导入依赖的package包/类
private void doTest(final boolean checkMembersMovedCount, String conflictMessage, RefactoringTestUtil.MemberDescriptor... membersToFind)
{
	final MultiMap<PsiElement, String> conflictsMap = new MultiMap<>();
	configureByFile(BASE_PATH + getTestName(false) + ".java");
	PsiElement elementAt = getFile().findElementAt(getEditor().getCaretModel().getOffset());
	final PsiClass sourceClass = PsiTreeUtil.getParentOfType(elementAt, PsiClass.class);
	assertNotNull(sourceClass);

	PsiClass targetClass = sourceClass.getSuperClass();
	assertNotNull(targetClass);
	if(!targetClass.isWritable())
	{
		final PsiClass[] interfaces = sourceClass.getInterfaces();
		assertEquals(1, interfaces.length);
		assertTrue(interfaces[0].isWritable());
		targetClass = interfaces[0];
	}
	final MemberInfo[] infos = RefactoringTestUtil.findMembers(sourceClass, membersToFind);

	final int[] countMoved = {0};
	final MoveMemberListener listener = (aClass, member) ->
	{
		assertEquals(sourceClass, aClass);
		countMoved[0]++;
	};
	JavaRefactoringListenerManager.getInstance(getProject()).addMoveMembersListener(listener);
	final PsiDirectory targetDirectory = targetClass.getContainingFile().getContainingDirectory();
	final PsiJavaPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
	conflictsMap.putAllValues(PullUpConflictsUtil.checkConflicts(infos, sourceClass, targetClass, targetPackage, targetDirectory, psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays
			.asList(infos), psiMethod)));
	final PullUpProcessor helper = new PullUpProcessor(sourceClass, targetClass, infos, new DocCommentPolicy(DocCommentPolicy.ASIS));
	helper.run();
	UIUtil.dispatchAllInvocationEvents();
	JavaRefactoringListenerManager.getInstance(getProject()).removeMoveMembersListener(listener);

	if(conflictMessage != null && conflictsMap.isEmpty())
	{
		fail("Conflict was not detected");
	}

	if(conflictMessage == null && !conflictsMap.isEmpty())
	{
		fail(conflictsMap.values().iterator().next());
	}

	if(conflictMessage != null && !IGNORE_CONFLICTS.equals(conflictMessage))
	{
		TreeSet<String> conflicts = new TreeSet<>(conflictsMap.values());
		assertEquals(conflictMessage, conflicts.iterator().next());
		return;
	}

	if(checkMembersMovedCount)
	{
		assertEquals(countMoved[0], membersToFind.length);
	}
	checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:59,代码来源:PullUpTest.java


注:本文中的com.intellij.refactoring.memberPullUp.PullUpProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。