mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Use single-module test for suggested visibility of classes exposed with 'module-info' (IDEA-169200)
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Api {
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
package foo.bar.impl;
|
||||
import foo.bar.Api;
|
||||
|
||||
public class Impl extends Api {
|
||||
private static class Impl2 extends Impl {}
|
||||
}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
</problems>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Service implements java.util.RandomAccess {
|
||||
private static class Impl extends Service {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
module foo.bar {
|
||||
provides java.util.RandomAccess with foo.bar.Service;
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Service implements java.util.RandomAccess {
|
||||
private static class Impl extends Service {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
module foo.bar {
|
||||
provides java.util.RandomAccess with foo.bar.Service;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Api {
|
||||
}
|
||||
class Api2 extends Api {}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Outer {
|
||||
public static class Nested {}
|
||||
protected class Inner {}
|
||||
|
||||
private static class Outer2 extends Outer.Nested {}
|
||||
private class Outer3 extends Outer.Inner {}
|
||||
}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
</problems>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package foo.bar;
|
||||
|
||||
<warning descr="Access can be package-private">public</warning> class Public {
|
||||
<warning descr="Access can be package-private">public</warning> static class Nested {}
|
||||
<warning descr="Access can be package-private">protected</warning> class Inner {}
|
||||
|
||||
private static class Impl extends Public {}
|
||||
private static class Impl2 extends Public.Nested {}
|
||||
private class Impl3 extends Public.Inner {}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
module foo.bar { exports foo.bar; }
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Public {
|
||||
public static class Nested {}
|
||||
protected class Inner {}
|
||||
|
||||
private static class Impl extends Public {}
|
||||
private static class Impl2 extends Public.Nested {}
|
||||
private class Impl3 extends Public.Inner {}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
module foo.bar { exports foo.bar; }
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Api {
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
package foo.bar.impl;
|
||||
import foo.bar.Api;
|
||||
|
||||
public class Impl extends Api {
|
||||
private static class Impl2 extends Impl {}
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Impl.java</file>
|
||||
<line>4</line>
|
||||
<entry_point TYPE="class" FQNAME="foo.bar.impl.Impl" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Member access can be tightened</problem_class>
|
||||
<description>Access can be package-private</description>
|
||||
</problem>
|
||||
</problems>
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Api {
|
||||
}
|
||||
class Api2 extends Api {}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Outer {
|
||||
public static class Nested {}
|
||||
protected class Inner {}
|
||||
|
||||
private static class Outer2 extends Outer.Nested {}
|
||||
private class Outer3 extends Outer.Inner {}
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Api.java</file>
|
||||
<line>3</line>
|
||||
<entry_point TYPE="class" FQNAME="foo.bar.Api" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Member access can be tightened</problem_class>
|
||||
<description>Access can be package-private</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>Outer.java</file>
|
||||
<line>3</line>
|
||||
<entry_point TYPE="class" FQNAME="foo.bar.Outer" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Member access can be tightened</problem_class>
|
||||
<description>Access can be package-private</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>Outer.java</file>
|
||||
<line>4</line>
|
||||
<entry_point TYPE="class" FQNAME="foo.bar.Outer.Nested" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Member access can be tightened</problem_class>
|
||||
<description>Access can be package-private</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>Outer.java</file>
|
||||
<line>5</line>
|
||||
<entry_point TYPE="class" FQNAME="foo.bar.Outer.Inner" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Member access can be tightened</problem_class>
|
||||
<description>Access can be package-private</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package foo.bar;
|
||||
|
||||
<warning descr="Access can be package-private">public</warning> class Public {
|
||||
<warning descr="Access can be package-private">public</warning> static class Nested {}
|
||||
<warning descr="Access can be package-private">protected</warning> class Inner {}
|
||||
|
||||
private static class Impl extends Public {}
|
||||
private static class Impl2 extends Public.Nested {}
|
||||
private class Impl3 extends Public.Inner {}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
module foo.bar { }
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package foo.bar;
|
||||
|
||||
<warning descr="Access can be package-private">public</warning> class Public {
|
||||
<warning descr="Access can be package-private">public</warning> static class Nested {}
|
||||
<warning descr="Access can be package-private">protected</warning> class Inner {}
|
||||
|
||||
private static class Impl extends Public {}
|
||||
private static class Impl2 extends Public.Nested {}
|
||||
private class Impl3 extends Public.Inner {}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
module foo.bar { }
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Service implements java.util.RandomAccess {
|
||||
private static class Impl extends Service {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
module foo.bar {
|
||||
uses foo.bar.Service;
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package foo.bar;
|
||||
|
||||
public class Service implements java.util.RandomAccess {
|
||||
private static class Impl extends Service {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
module foo.bar {
|
||||
uses foo.bar.Service;
|
||||
}
|
||||
+29
-23
@@ -15,45 +15,51 @@
|
||||
*/
|
||||
package com.intellij.java.codeInspection
|
||||
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper
|
||||
import com.intellij.codeInspection.java19modules.Java9ModuleEntryPoint
|
||||
import com.intellij.codeInspection.visibility.VisibilityInspection
|
||||
import com.intellij.java.testFramework.fixtures.LightJava9ModulesCodeInsightFixtureTestCase
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.ex.PathManagerEx
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.enableInspectionTool
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
|
||||
class Java9AccessCanBeTightenedTest : LightJava9ModulesCodeInsightFixtureTestCase() {
|
||||
class Java9AccessCanBeTightenedTest : LightCodeInsightFixtureTestCase() {
|
||||
|
||||
override fun getTestDataPath() = PathManagerEx.getTestDataPath() + "/inspection/java9AccessCanBeTightened/"
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = JAVA_9
|
||||
|
||||
fun testExportedPackage() {
|
||||
moduleInfo("module foo.bar { exports foo.bar; }")
|
||||
doTest("foo.bar.Api", "foo.bar.Outer")
|
||||
private lateinit var inspection: VisibilityInspection
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
inspection = createGlobalTool()
|
||||
|
||||
enableInspectionTool(project, inspection.sharedLocalInspectionTool!!, Disposable { })
|
||||
}
|
||||
|
||||
fun testNotExportedPackage() {
|
||||
moduleInfo("module foo.bar { }")
|
||||
doTest("foo.bar.Api", "foo.bar.Outer")
|
||||
}
|
||||
fun testPublicClass() = doTestClass()
|
||||
fun testPublicClassOff() = doTestClass()
|
||||
|
||||
fun testDeclaredService() {
|
||||
moduleInfo("module foo.bar { exports foo.bar; provides foo.bar.Api with foo.bar.impl.Impl; }")
|
||||
doTest("foo.bar.Api", "foo.bar.impl.Impl")
|
||||
}
|
||||
fun testExportedPackage() = doTestClass()
|
||||
fun testExportedPackageOff() = doTestClass()
|
||||
|
||||
fun testNotDeclaredService() {
|
||||
moduleInfo("module foo.bar { exports foo.bar; }")
|
||||
doTest("foo.bar.Api", "foo.bar.impl.Impl")
|
||||
}
|
||||
fun testDeclaredService() = doTestService()
|
||||
fun testDeclaredServiceOff() = doTestService()
|
||||
|
||||
fun testUsedService() = doTestService()
|
||||
fun testUsedServiceOff() = doTestService()
|
||||
|
||||
private fun doTest(vararg classNames: String) {
|
||||
val testPath = testDataPath + getTestName(true)
|
||||
addJavaFiles(testPath, classNames)
|
||||
private fun doTestClass() = doTest("Public")
|
||||
private fun doTestService() = doTest("Service")
|
||||
|
||||
val toolWrapper = LocalInspectionToolWrapper(createGlobalTool().sharedLocalInspectionTool!!)
|
||||
doGlobalInspectionTest(testPath, toolWrapper)
|
||||
private fun doTest(className: String) {
|
||||
val testName = getTestName(true)
|
||||
val enabled = !testName.endsWith("Off")
|
||||
|
||||
inspection.setEntryPointEnabled(Java9ModuleEntryPoint.ID, enabled)
|
||||
myFixture.configureByFiles("$testName/foo/bar/$className.java", "$testName/module-info.java")
|
||||
myFixture.checkHighlighting()
|
||||
}
|
||||
|
||||
private fun createGlobalTool() = VisibilityInspection().apply {
|
||||
|
||||
Reference in New Issue
Block a user