use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class PushDownMultifileTest method doTest.
private void doTest(final boolean fail, final String sourceClassName, final String targetClassName) throws Exception {
try {
doTest((rootDir, rootAfter) -> {
final PsiClass srcClass = myJavaFacade.findClass(sourceClassName, GlobalSearchScope.allScope(myProject));
assertTrue("Source class not found", srcClass != null);
final PsiClass targetClass = myJavaFacade.findClass(targetClassName, GlobalSearchScope.allScope(myProject));
assertTrue("Target class not found", targetClass != null);
final PsiMethod[] methods = srcClass.getMethods();
assertTrue("No methods found", methods.length > 0);
final MemberInfo memberInfo = new MemberInfo(methods[0]);
memberInfo.setChecked(true);
new PushDownProcessor<>(srcClass, Collections.singletonList(memberInfo), new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
//LocalFileSystem.getInstance().refresh(false);
//FileDocumentManager.getInstance().saveAllDocuments();
});
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
if (fail) {
return;
} else {
throw e;
}
}
if (fail) {
fail("Conflict was not detected");
}
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class PushDownMultifileTest method testUsagesInXml.
public void testUsagesInXml() throws Exception {
try {
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 PsiField[] fields = srcClass.getFields();
assertTrue("No methods found", fields.length > 0);
final MemberInfo memberInfo = new MemberInfo(fields[0]);
memberInfo.setChecked(true);
new PushDownProcessor<>(srcClass, Collections.singletonList(memberInfo), new DocCommentPolicy(DocCommentPolicy.ASIS)).run();
//LocalFileSystem.getInstance().refresh(false);
//FileDocumentManager.getInstance().saveAllDocuments();
});
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
assertEquals(e.getMessage(), "Class <b><code>b.B</code></b> is package-private and will not be accessible from file <b><code>A.form</code></b>.");
return;
}
fail("Conflict was not detected");
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class RefactoringTestUtil method findMembers.
public static MemberInfo[] findMembers(final PsiClass sourceClass, final MemberDescriptor... membersToFind) {
MemberInfo[] infos = new MemberInfo[membersToFind.length];
for (int i = 0; i < membersToFind.length; i++) {
final Class<? extends PsiMember> clazz = membersToFind[i].myClass;
final String name = membersToFind[i].myName;
PsiMember member = null;
boolean overrides = false;
PsiReferenceList refList = null;
if (PsiClass.class.isAssignableFrom(clazz)) {
member = sourceClass.findInnerClassByName(name, false);
if (member == null) {
final PsiClass[] supers = sourceClass.getSupers();
for (PsiClass superTypeClass : supers) {
if (superTypeClass.getName().equals(name)) {
member = superTypeClass;
overrides = true;
refList = superTypeClass.isInterface() ? sourceClass.getImplementsList() : sourceClass.getExtendsList();
break;
}
}
}
} else if (PsiMethod.class.isAssignableFrom(clazz)) {
final PsiMethod[] methods = sourceClass.findMethodsByName(name, false);
Assert.assertEquals(1, methods.length);
member = methods[0];
} else if (PsiField.class.isAssignableFrom(clazz)) {
member = sourceClass.findFieldByName(name, false);
}
Assert.assertNotNull(member);
infos[i] = new MemberInfo(member, overrides, refList);
infos[i].setToAbstract(membersToFind[i].myAbstract);
}
return infos;
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class ExtractSuperClassTest method doTest.
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);
doTest(members, newClassName, targetPackageName, rootDir, psiClass, conflicts);
}
use of com.intellij.refactoring.util.classMembers.MemberInfo in project intellij-community by JetBrains.
the class ExtractEnumTest method doTest.
private void doTest(final String conflicts, final boolean generateAccessors, final RefactoringTestUtil.MemberDescriptor... memberDescriptors) throws Exception {
doTest((rootDir, rootAfter) -> {
final PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
assertNotNull("Class Test not found", aClass);
final ArrayList<PsiField> fields = new ArrayList<>();
final ArrayList<PsiMethod> methods = new ArrayList<>();
final List<MemberInfo> enumConstants = new ArrayList<>();
for (MemberInfo memberInfo : RefactoringTestUtil.findMembers(aClass, memberDescriptors)) {
final PsiMember member = memberInfo.getMember();
if (member instanceof PsiField) {
fields.add((PsiField) member);
if (member.hasModifierProperty(PsiModifier.STATIC) && member.hasModifierProperty(PsiModifier.FINAL) && ((PsiField) member).hasInitializer()) {
if (memberInfo.isToAbstract()) {
enumConstants.add(memberInfo);
memberInfo.setChecked(true);
}
}
} else if (member instanceof PsiMethod) {
methods.add((PsiMethod) member);
}
}
try {
final ExtractClassProcessor processor = new ExtractClassProcessor(aClass, fields, methods, new ArrayList<>(), "", null, "EEnum", null, generateAccessors, enumConstants);
processor.run();
LocalFileSystem.getInstance().refresh(false);
FileDocumentManager.getInstance().saveAllDocuments();
} catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
if (conflicts != null) {
TreeSet expectedConflictsSet = new TreeSet(Arrays.asList(conflicts.split("\n")));
TreeSet actualConflictsSet = new TreeSet(Arrays.asList(e.getMessage().split("\n")));
Assert.assertEquals(expectedConflictsSet, actualConflictsSet);
return;
} else {
fail(e.getMessage());
}
}
if (conflicts != null) {
fail("Conflicts were not detected: " + conflicts);
}
});
}
Aggregations