mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] "dependency on an automatic module" inspection
This commit is contained in:
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.java19modules;
|
||||
|
||||
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.light.LightJavaModule;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class JavaRequiresAutoModuleInspection extends BaseJavaLocalInspectionTool {
|
||||
public boolean TRANSITIVE_ONLY = true;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel(InspectionsBundle.message("inspection.requires.auto.module.option"), this, "TRANSITIVE_ONLY");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
|
||||
return !PsiUtil.isModuleFile(holder.getFile()) ? PsiElementVisitor.EMPTY_VISITOR : new JavaElementVisitor() {
|
||||
@Override
|
||||
public void visitRequiresStatement(PsiRequiresStatement statement) {
|
||||
super.visitRequiresStatement(statement);
|
||||
PsiJavaModuleReferenceElement refElement = statement.getReferenceElement();
|
||||
if (refElement != null) {
|
||||
PsiPolyVariantReference reference = refElement.getReference();
|
||||
if (reference != null) {
|
||||
PsiElement target = reference.resolve();
|
||||
if (target instanceof LightJavaModule) {
|
||||
if (!TRANSITIVE_ONLY) {
|
||||
holder.registerProblem(refElement, InspectionsBundle.message("inspection.requires.auto.module.message"));
|
||||
}
|
||||
else if (statement.hasModifierProperty(PsiModifier.TRANSITIVE)) {
|
||||
holder.registerProblem(refElement, InspectionsBundle.message("inspection.requires.auto.module.transitive"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.java.codeInspection
|
||||
|
||||
import com.intellij.codeInspection.java19modules.JavaRequiresAutoModuleInspection
|
||||
import com.intellij.java.testFramework.fixtures.LightJava9ModulesCodeInsightFixtureTestCase
|
||||
|
||||
class JavaRequiresAutoModuleInspectionTest : LightJava9ModulesCodeInsightFixtureTestCase() {
|
||||
private lateinit var inspection: JavaRequiresAutoModuleInspection
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
inspection = JavaRequiresAutoModuleInspection()
|
||||
myFixture.enableInspections(inspection)
|
||||
}
|
||||
|
||||
fun testTransitive() {
|
||||
highlighting("""module M { requires transitive <warning descr="'requires transitive' directive for an automatic module">lib.claimed</warning>; }""")
|
||||
}
|
||||
|
||||
fun testAny() {
|
||||
inspection.TRANSITIVE_ONLY = false
|
||||
highlighting("""module M { requires <warning descr="'requires' directive for an automatic module">lib.claimed</warning>; }""")
|
||||
}
|
||||
|
||||
private fun highlighting(text: String) {
|
||||
myFixture.configureByText("module-info.java", text)
|
||||
myFixture.checkHighlighting()
|
||||
}
|
||||
}
|
||||
@@ -767,6 +767,11 @@ inspection.module.exports.package.to.itself=Module exports/opens package to itse
|
||||
exports.to.itself.delete.statement.fix=Delete statement
|
||||
exports.to.itself.delete.module.ref.fix=Delete reference to module ''{0}''
|
||||
|
||||
inspection.requires.auto.module=Java module naming conventions
|
||||
inspection.requires.auto.module.message='requires' directive for an automatic module
|
||||
inspection.requires.auto.module.transitive='requires transitive' directive for an automatic module
|
||||
inspection.requires.auto.module.option=Highlight only transitive dependencies
|
||||
|
||||
inspection.replace.with.bulk.message=Iteration can be replaced with bulk ''{0}'' call
|
||||
inspection.replace.with.bulk.fix.name=Replace iteration with bulk ''{0}'' call
|
||||
inspection.replace.with.bulk.fix.family.name=Replace with bulk method call
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
The inspection warns about use of automatic modules in the "requires" clauses.
|
||||
Corresponds to <code>-Xlint:requires-automatic</code> and <code>-Xlint:requires-transitive-automatic</code> Javac options.
|
||||
</body>
|
||||
</html>
|
||||
@@ -948,6 +948,10 @@
|
||||
enabledByDefault="true" level="WARNING"
|
||||
key="inspection.module.exports.package.to.itself" bundle="messages.InspectionsBundle"
|
||||
implementationClass="com.intellij.codeInspection.java19modules.Java9ModuleExportsPackageToItselfInspection"/>
|
||||
<localInspection language="JAVA" shortName="JavaRequiresAutoModule" enabledByDefault="true" level="WARNING"
|
||||
groupPath="Java" groupBundle="messages.InspectionsBundle" groupKey="group.names.language.level.specific.issues.and.migration.aids9"
|
||||
bundle="messages.InspectionsBundle" key="inspection.requires.auto.module"
|
||||
implementationClass="com.intellij.codeInspection.java19modules.JavaRequiresAutoModuleInspection"/>
|
||||
<localInspection language="JAVA" shortName="JavaLangInvokeHandleSignature" enabledByDefault="true" level="WARNING"
|
||||
groupPath="Java" groupBundle="messages.InspectionsBundle" groupKey="group.names.reflective.access.issues"
|
||||
bundle="messages.InspectionsBundle" key="inspection.handle.signature.name"
|
||||
|
||||
Reference in New Issue
Block a user