mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unused library: don't check runtime dependencies (IDEA-178133ˆ)
This commit is contained in:
+3
-1
@@ -100,7 +100,9 @@ public class UnusedLibrariesInspection extends GlobalInspectionTool {
|
||||
|
||||
final List<CommonProblemDescriptor> result = new ArrayList<>();
|
||||
for (OrderEntry entry : moduleRootManager.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry && !((LibraryOrderEntry)entry).isExported()) {
|
||||
if (entry instanceof LibraryOrderEntry &&
|
||||
!((LibraryOrderEntry)entry).isExported() &&
|
||||
((LibraryOrderEntry)entry).getScope() != DependencyScope.RUNTIME) {
|
||||
final Set<VirtualFile> files = new HashSet<>(Arrays.asList(((LibraryOrderEntry)entry).getRootFiles(OrderRootType.CLASSES)));
|
||||
boolean allRootsUnused = usedRoots == null || !files.removeAll(usedRoots);
|
||||
if (allRootsUnused) {
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems/>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
class Test {
|
||||
}
|
||||
+12
@@ -19,6 +19,10 @@ package com.intellij.java.codeInspection;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInspection.unusedLibraries.UnusedLibrariesInspection;
|
||||
import com.intellij.openapi.roots.DependencyScope;
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.project.IntelliJProjectConfiguration;
|
||||
import com.intellij.testFramework.InspectionTestCase;
|
||||
@@ -35,6 +39,13 @@ public class UnusedLibraryInspectionTest extends InspectionTestCase {
|
||||
protected void setupRootModel(@NotNull String testDir, @NotNull VirtualFile[] sourceDir, String sdkName) {
|
||||
super.setupRootModel(testDir, sourceDir, sdkName);
|
||||
PsiTestUtil.addProjectLibrary(getModule(), "JUnit", IntelliJProjectConfiguration.getProjectLibraryClassesRootPaths("JUnit4"));
|
||||
if (getTestName(true).endsWith("Runtime")) {
|
||||
for (OrderEntry entry : ModuleRootManager.getInstance(getModule()).getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry && "JUnit".equals(((LibraryOrderEntry)entry).getLibraryName())) {
|
||||
((LibraryOrderEntry)entry).setScope(DependencyScope.RUNTIME);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
@@ -49,6 +60,7 @@ public class UnusedLibraryInspectionTest extends InspectionTestCase {
|
||||
|
||||
public void testSimple() { doTest(); }
|
||||
public void testUsedJunit() { doTest(); }
|
||||
public void testJunitAsRuntime() { doTest(); }
|
||||
public void testUsedJunitFromField() { doTest(); }
|
||||
public void testUsedInParameterAnnotation() { doTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user