use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class InlineSuperClassRefactoringProcessor method performRefactoring.
protected void performRefactoring(@NotNull final UsageInfo[] usages) {
try {
final UsageInfo[] infos = ContainerUtil.map2Array(myTargetClasses, UsageInfo.class, UsageInfo::new);
new PushDownProcessor<>(mySuperClass, Arrays.asList(myMemberInfos), new DocCommentPolicy(myPolicy)).pushDownToClasses(infos);
CommonRefactoringUtil.sortDepthFirstRightLeftOrder(usages);
for (UsageInfo usageInfo : usages) {
if (!(usageInfo instanceof ReplaceExtendsListUsageInfo || usageInfo instanceof RemoveImportUsageInfo)) {
try {
((FixableUsageInfo) usageInfo).fixUsage();
} catch (IncorrectOperationException e) {
LOG.info(e);
}
}
}
replaceInnerTypeUsages();
//postpone broken hierarchy
for (UsageInfo usage : usages) {
if (usage instanceof ReplaceExtendsListUsageInfo || usage instanceof RemoveImportUsageInfo) {
((FixableUsageInfo) usage).fixUsage();
}
}
//delete the class if all refs replaced
if (myCurrentInheritor == null) {
mySuperClass.delete();
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class ExtractSuperClassTest method testAnonymClass.
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);
}
use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-plugins by JetBrains.
the class FlexPushDownTest method performAction.
private void performAction(String from, int docCommentPolicy, boolean makeAbstract, final String[] toPushDown) {
final JSClass sourceClass = (JSClass) JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver().findClassByQName(from, GlobalSearchScope.projectScope(getProject()));
assertNotNull("source class not found: " + from, sourceClass);
assertTrue(sourceClass.getQualifiedName() + " has no inheritors", !JSInheritanceUtil.findDirectSubClasses(sourceClass, false).isEmpty());
final List<JSMemberInfo> memberInfos = FlexPullUpTest.getMemberInfos(toPushDown, sourceClass, makeAbstract);
JSMemberInfo[] infosArray = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
new JSPushDownProcessor(myProject, infosArray, sourceClass, docCommentPolicy) {
@Override
@NotNull
protected UsageInfo[] findUsages() {
// ensure stable order
final UsageInfo[] usages = super.findUsages();
Arrays.sort(usages, (o1, o2) -> ((JSClass) o1.getElement()).getQualifiedName().compareTo(((JSClass) o2.getElement()).getQualifiedName()));
return usages;
}
}.run();
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
FileDocumentManager.getInstance().saveAllDocuments();
}
Aggregations