mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
NPE: process usages in non-java files (17195)
This commit is contained in:
+2
-2
@@ -251,7 +251,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
|
||||
reportedNonDelegatedUsages.put(nonDelegatedMember, reportedContainers);
|
||||
}
|
||||
final PsiElement container = ConflictsUtil.getContainer(element);
|
||||
if (container != null && !reportedContainers.contains(container)) {
|
||||
if (!reportedContainers.contains(container)) {
|
||||
String message = RefactoringBundle.message("0.uses.1.of.an.instance.of.a.2", RefactoringUIUtil.getDescription(container, true),
|
||||
RefactoringUIUtil.getDescription(nonDelegatedMember, true), classDescription);
|
||||
conflicts.putValue(container, CommonRefactoringUtil.capitalize(message));
|
||||
@@ -266,7 +266,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
|
||||
reportedUpcasts.put(upcastedTo, reportedContainers);
|
||||
}
|
||||
final PsiElement container = ConflictsUtil.getContainer(element);
|
||||
if (container != null && !reportedContainers.contains(container)) {
|
||||
if (!reportedContainers.contains(container)) {
|
||||
String message = RefactoringBundle.message("0.upcasts.an.instance.of.1.to.2",
|
||||
RefactoringUIUtil.getDescription(container, true), classDescription,
|
||||
RefactoringUIUtil.getDescription(upcastedTo, false));
|
||||
|
||||
@@ -208,12 +208,13 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
Map<PsiMember, Set<PsiMember>> result = new HashMap<PsiMember, Set<PsiMember>>();
|
||||
|
||||
for (UsageInfo usage : usages) {
|
||||
final PsiMember container = ConflictsUtil.getContainer(usage.getElement());
|
||||
if (container == null) continue; // usage in import statement
|
||||
Set<PsiMember> inaccessibleReferenced = result.get(container);
|
||||
final PsiElement container = ConflictsUtil.getContainer(usage.getElement());
|
||||
if (!(container instanceof PsiMember)) continue; // usage in import statement
|
||||
PsiMember memberContainer = (PsiMember)container;
|
||||
Set<PsiMember> inaccessibleReferenced = result.get(memberContainer);
|
||||
if (inaccessibleReferenced == null) {
|
||||
inaccessibleReferenced = new HashSet<PsiMember>();
|
||||
result.put(container, inaccessibleReferenced);
|
||||
result.put(memberContainer, inaccessibleReferenced);
|
||||
for (PsiMember member : referencedElements) {
|
||||
if (!PsiUtil.isAccessible(member, usage.getElement(), null)) {
|
||||
inaccessibleReferenced.add(member);
|
||||
|
||||
-1
@@ -369,7 +369,6 @@ public class MoveClassToInnerProcessor extends BaseRefactoringProcessor {
|
||||
|
||||
public void addConflict(final PsiElement targetElement, final PsiElement sourceElement) {
|
||||
PsiElement container = ConflictsUtil.getContainer(sourceElement);
|
||||
if (container == null) return;
|
||||
if (!myReportedContainers.contains(container)) {
|
||||
myReportedContainers.add(container);
|
||||
String targetDescription = (targetElement == myClassToMove)
|
||||
|
||||
-1
@@ -245,7 +245,6 @@ public class MoveClassesOrPackagesProcessor extends BaseRefactoringProcessor {
|
||||
if (PsiModifier.PACKAGE_LOCAL.equals(visibility)) {
|
||||
if (PsiTreeUtil.getParentOfType(element, PsiImportStatement.class) != null) continue;
|
||||
PsiElement container = ConflictsUtil.getContainer(element);
|
||||
if (container == null) continue;
|
||||
HashSet<PsiElement> reported = reportedClassToContainers.get(aClass);
|
||||
if (reported == null) {
|
||||
reported = new HashSet<PsiElement>();
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -34,13 +35,13 @@ public class ConflictsUtil {
|
||||
private ConflictsUtil() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiMember getContainer(PsiElement place) {
|
||||
@NotNull
|
||||
public static PsiElement getContainer(PsiElement place) {
|
||||
PsiElement parent = place;
|
||||
while (true) {
|
||||
if (parent instanceof PsiMember && !(parent instanceof PsiTypeParameter))
|
||||
return (PsiMember)parent;
|
||||
if (parent instanceof PsiFile) return null;
|
||||
return parent;
|
||||
if (parent instanceof PsiFile) return parent;
|
||||
parent = parent.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,6 @@ public class RefactoringConflictsUtil {
|
||||
PsiElement container;
|
||||
if (usageFile instanceof PsiJavaFile) {
|
||||
container = ConflictsUtil.getContainer(element);
|
||||
if (container == null) container = usageFile;
|
||||
}
|
||||
else {
|
||||
container = usageFile;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="a.A">
|
||||
<grid id="27dc6" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="3ec2f" class="javax.swing.JTextField" binding="textField1" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<hspacer id="38a16">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="e9ce3">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,4 @@
|
||||
package a;
|
||||
public class A {
|
||||
private JTextField textField1;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package b;
|
||||
|
||||
import a.*;
|
||||
class B extends A {}
|
||||
+34
-1
@@ -9,13 +9,14 @@ import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.refactoring.memberPushDown.PushDownProcessor;
|
||||
import com.intellij.refactoring.util.DocCommentPolicy;
|
||||
import com.intellij.refactoring.util.classMembers.MemberInfo;
|
||||
|
||||
//push first method from class a.A to class b.B
|
||||
public class PushDownImportsTest extends MultiFileTestCase {
|
||||
public class PushDownMultifileTest extends MultiFileTestCase {
|
||||
protected String getTestRoot() {
|
||||
return "/refactoring/pushDown/";
|
||||
}
|
||||
@@ -79,4 +80,36 @@ public class PushDownImportsTest extends MultiFileTestCase {
|
||||
public void testStaticImportOfPushedMethod() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUsagesInXml() throws Exception {
|
||||
try {
|
||||
doTest(new PerformAction() {
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
final PsiClass srcClass = myJavaFacade.findClass("a.A");
|
||||
assertTrue("Source class not found", srcClass != null);
|
||||
|
||||
final PsiClass targetClass = myJavaFacade.findClass("b.B");
|
||||
assertTrue("Target class not found", targetClass != null);
|
||||
|
||||
final PsiField[] fields = srcClass.getFields();
|
||||
assertTrue("No methods found", fields.length > 0);
|
||||
final MemberInfo[] membersToMove = new MemberInfo[1];
|
||||
final MemberInfo memberInfo = new MemberInfo(fields[0]);
|
||||
memberInfo.setChecked(true);
|
||||
membersToMove[0] = memberInfo;
|
||||
|
||||
new PushDownProcessor(getProject(), membersToMove, srcClass, 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 local and will not be accessible from file <b><code>A.form</code></b>.");
|
||||
return;
|
||||
}
|
||||
fail("Conflict was not detected");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user