use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class PullUpDialog method doAction.
protected void doAction() {
if (!myCallback.checkConflicts(this))
return;
JavaRefactoringSettings.getInstance().PULL_UP_MEMBERS_JAVADOC = myJavaDocPanel.getPolicy();
final PsiClass superClass = getSuperClass();
String name = superClass.getQualifiedName();
if (name != null) {
StatisticsManager.getInstance().incUseCount(new StatisticsInfo(PULL_UP_STATISTICS_KEY + myClass.getQualifiedName(), name));
}
List<MemberInfo> infos = getSelectedMemberInfos();
invokeRefactoring(new PullUpProcessor(myClass, superClass, infos.toArray(new MemberInfo[infos.size()]), new DocCommentPolicy(getJavaDocPolicy())));
close(OK_EXIT_CODE);
}
use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class EncapsulateFieldsProcessor method generateAccessors.
private void generateAccessors() {
// generate accessors
myNameToGetter = new HashMap<>();
myNameToSetter = new HashMap<>();
for (FieldDescriptor fieldDescriptor : myFieldDescriptors) {
final DocCommentPolicy<PsiDocComment> commentPolicy = new DocCommentPolicy<>(myDescriptor.getJavadocPolicy());
PsiField field = fieldDescriptor.getField();
final PsiDocComment docComment = field.getDocComment();
if (myDescriptor.isToEncapsulateGet()) {
final PsiMethod prototype = fieldDescriptor.getGetterPrototype();
assert prototype != null;
final PsiMethod getter = addOrChangeAccessor(prototype, myNameToGetter);
if (docComment != null) {
final PsiDocComment getterJavadoc = (PsiDocComment) getter.addBefore(docComment, getter.getFirstChild());
commentPolicy.processNewJavaDoc(getterJavadoc);
}
}
if (myDescriptor.isToEncapsulateSet() && !field.hasModifierProperty(PsiModifier.FINAL)) {
PsiMethod prototype = fieldDescriptor.getSetterPrototype();
assert prototype != null;
addOrChangeAccessor(prototype, myNameToSetter);
}
if (docComment != null) {
commentPolicy.processOldJavaDoc(docComment);
}
}
}
use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class PullUpMultifileTest method doTest.
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");
}
}
}
use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class PushDownTest method doTestImplements.
private void doTestImplements(boolean toAbstract, boolean failure) {
configureByFile(BASE_PATH + getTestName(false) + ".java");
PsiClass currentClass = JavaPsiFacade.getInstance(getProject()).findClass("Test", GlobalSearchScope.projectScope(getProject()));
MemberInfoStorage memberInfoStorage = new MemberInfoStorage(currentClass, element -> true);
List<MemberInfo> members = memberInfoStorage.getClassMemberInfos(currentClass);
for (MemberInfo member : members) {
member.setChecked(true);
if (toAbstract) {
member.setToAbstract(toAbstract);
}
}
new PushDownProcessor<MemberInfo, PsiMember, PsiClass>(currentClass, members, new DocCommentPolicy(DocCommentPolicy.ASIS)) {
@Override
protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
if (failure == conflicts.isEmpty()) {
fail(failure ? "Conflict was not detected" : "False conflict was detected");
}
return true;
}
}.run();
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
use of com.intellij.refactoring.util.DocCommentPolicy in project intellij-community by JetBrains.
the class PushDownTest method doTest.
private void doTest(final boolean failure) {
configureByFile(BASE_PATH + getTestName(false) + ".java");
final PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
assertTrue("<caret> is not on member name", targetElement instanceof PsiMember);
final PsiMember psiMember = (PsiMember) targetElement;
final PsiClass currentClass = psiMember.getContainingClass();
assert currentClass != null;
final List<MemberInfo> membersToMove = new ArrayList<>();
final PsiField fieldByName = currentClass.findFieldByName("fieldToMove", false);
if (fieldByName != null) {
final MemberInfo memberInfo = new MemberInfo(fieldByName);
memberInfo.setChecked(true);
membersToMove.add(memberInfo);
}
final PsiClass classByName = currentClass.findInnerClassByName("ClassToMove", false);
if (classByName != null) {
final MemberInfo memberInfo = new MemberInfo(classByName);
memberInfo.setChecked(true);
membersToMove.add(memberInfo);
}
final MemberInfo memberInfo = new MemberInfo(psiMember);
memberInfo.setChecked(true);
membersToMove.add(memberInfo);
new PushDownProcessor<MemberInfo, PsiMember, PsiClass>(currentClass, membersToMove, new DocCommentPolicy(DocCommentPolicy.ASIS)) {
@Override
protected boolean showConflicts(@NotNull MultiMap<PsiElement, String> conflicts, UsageInfo[] usages) {
if (failure == conflicts.isEmpty()) {
fail(failure ? "Conflict was not detected" : "False conflict was detected");
}
return true;
}
}.run();
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
Aggregations