mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
OrderEntryFix: filter suggestions by qualified name
This commit is contained in:
@@ -145,6 +145,26 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix {
|
||||
if (allowedDependencies.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
if (reference instanceof PsiJavaCodeReferenceElement) {
|
||||
String qualifiedName = null;
|
||||
if (((PsiJavaCodeReferenceElement)reference).isQualified()) {
|
||||
qualifiedName = ((PsiJavaCodeReferenceElement)reference).getQualifiedName();
|
||||
}
|
||||
else if (containingFile instanceof PsiJavaFile) {
|
||||
PsiImportList list = ((PsiJavaFile)containingFile).getImportList();
|
||||
if (list != null) {
|
||||
PsiImportStatementBase statement = list.findSingleImportStatement(shortReferenceName);
|
||||
if (statement != null) {
|
||||
//noinspection ConstantConditions
|
||||
qualifiedName = statement.getImportReference().getQualifiedName();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (qualifiedName != null) {
|
||||
String finalQualifiedName = qualifiedName;
|
||||
allowedDependencies.removeIf(aClass -> !finalQualifiedName.equals(aClass.getQualifiedName()));
|
||||
}
|
||||
}
|
||||
|
||||
OrderEntryFix moduleDependencyFix = new AddModuleDependencyFix(reference, currentModule, scope, allowedDependencies);
|
||||
registrar.register(moduleDependencyFix);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Add dependency on module 'A'" "true"
|
||||
package y;
|
||||
|
||||
import x.InA;
|
||||
|
||||
public class AddAmbiguous {
|
||||
InA<caret> a;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4" relativePaths="true" type="JAVA_MODULE">
|
||||
<component name="ModuleRootManager" />
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Lib" level="project" />
|
||||
<orderEntryProperties />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package z;
|
||||
|
||||
public class InA {
|
||||
}
|
||||
@@ -237,6 +237,7 @@
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/A/A.iml" filepath="$PROJECT_DIR$/A/A.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/B/B.iml" filepath="$PROJECT_DIR$/B/B.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/C/C.iml" filepath="$PROJECT_DIR$/C/C.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="true" project-jdk-name="1.5" project-jdk-type="JavaSDK">
|
||||
|
||||
@@ -21,8 +21,10 @@ import com.intellij.codeInsight.daemon.quickFix.ActionHint;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.module.ModifiableModuleModel;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
@@ -93,7 +95,7 @@ public class OrderEntryTest extends DaemonAnalyzerTestCase {
|
||||
if (afterAction != null) {
|
||||
fail("Action '" + text + "' is still available after its invocation in test " + testFullPath);
|
||||
}
|
||||
assertEquals(infosBefore.size() - 1, infosAfter.size());
|
||||
assertTrue(infosBefore.size() > infosAfter.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,9 +110,21 @@ public class OrderEntryTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
|
||||
public void testAddDependency() {
|
||||
removeModule();
|
||||
doTest("B/src/y/AddDependency.java");
|
||||
}
|
||||
|
||||
public void testAddAmbiguousDependency() {
|
||||
doTest("B/src/y/AddAmbiguous.java");
|
||||
}
|
||||
|
||||
private void removeModule() {
|
||||
ModuleManager manager = ModuleManager.getInstance(getProject());
|
||||
ModifiableModuleModel model = manager.getModifiableModel();
|
||||
model.disposeModule(manager.findModuleByName("C"));
|
||||
WriteAction.run(() -> model.commit());
|
||||
}
|
||||
|
||||
public void testAddLibrary() {
|
||||
doTest("B/src/y/AddLibrary.java");
|
||||
}
|
||||
@@ -119,6 +133,7 @@ public class OrderEntryTest extends DaemonAnalyzerTestCase {
|
||||
final Module a = ModuleManager.getInstance(getProject()).findModuleByName("A");
|
||||
final Module b = ModuleManager.getInstance(getProject()).findModuleByName("B");
|
||||
ModuleRootModificationUtil.addDependency(a, b);
|
||||
removeModule();
|
||||
|
||||
try {
|
||||
doTest("B/src/y/AddDependency.java");
|
||||
|
||||
Reference in New Issue
Block a user