mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-10 13:17:09 +07:00
IDEA-68179 (Javac quirks inspection)
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.compiler;
|
||||
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.ex.BaseLocalInspectionTool;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JavacQuirksInspection extends BaseLocalInspectionTool {
|
||||
@Nls @NotNull
|
||||
@Override
|
||||
public String getGroupDisplayName() {
|
||||
return GroupNames.COMPILER_ISSUES;
|
||||
}
|
||||
|
||||
@Nls @NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return InspectionsBundle.message("inspection.compiler.javac.quirks.name");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getShortName() {
|
||||
return "JavacQuirks";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
|
||||
return new JavaElementVisitor() {
|
||||
@Override
|
||||
public void visitAnnotationArrayInitializer(final PsiArrayInitializerMemberValue initializer) {
|
||||
final PsiElement lastElement = PsiTreeUtil.skipSiblingsBackward(initializer.getLastChild(), PsiWhiteSpace.class, PsiComment.class);
|
||||
if (lastElement != null && PsiUtil.isJavaToken(lastElement, JavaTokenType.COMMA)) {
|
||||
holder.registerProblem(lastElement, InspectionsBundle.message("inspection.compiler.javac.quirks.anno.array.comma.problem"), new RemoveCommaQuickFix());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static class RemoveCommaQuickFix implements LocalQuickFix {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return InspectionsBundle.message("inspection.compiler.javac.quirks.anno.array.comma.fix");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
final PsiElement psiElement = descriptor.getPsiElement();
|
||||
if (PsiUtil.isJavaToken(psiElement, JavaTokenType.COMMA)) {
|
||||
psiElement.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -18,6 +18,7 @@ package com.intellij.codeInspection.ex;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance;
|
||||
import com.intellij.codeInspection.canBeFinal.CanBeFinalInspection;
|
||||
import com.intellij.codeInspection.compiler.JavacQuirksInspection;
|
||||
import com.intellij.codeInspection.concurrencyAnnotations.*;
|
||||
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
@@ -117,7 +118,9 @@ public class StandardInspectionToolsProvider implements InspectionToolProvider {
|
||||
UnknownGuardInspection.class,
|
||||
|
||||
ExplicitTypeCanBeDiamondInspection.class,
|
||||
PossibleHeapPollutionVarargsInspection.class
|
||||
PossibleHeapPollutionVarargsInspection.class,
|
||||
|
||||
JavacQuirksInspection.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class C {
|
||||
@interface TestAnnotation {
|
||||
int[] value();
|
||||
}
|
||||
|
||||
@TestAnnotation({0, 1<warning descr="Trailing comma in annotation array initializer may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6).">,</warning>})
|
||||
void m() { }
|
||||
}
|
||||
+10
-1
@@ -3,6 +3,7 @@ package com.intellij.codeInsight.daemon;
|
||||
import com.intellij.ExtensionPoints;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.compiler.JavacQuirksInspection;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
import com.intellij.codeInspection.defUse.DefUseInspection;
|
||||
import com.intellij.codeInspection.reference.EntryPoint;
|
||||
@@ -32,7 +33,11 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[]{new UnusedSymbolLocalInspection(), new UncheckedWarningLocalInspection()};
|
||||
return new LocalInspectionTool[]{
|
||||
new UnusedSymbolLocalInspection(),
|
||||
new UncheckedWarningLocalInspection(),
|
||||
new JavacQuirksInspection()
|
||||
};
|
||||
}
|
||||
|
||||
public void testDuplicateAnnotations() throws Exception {
|
||||
@@ -207,4 +212,8 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testPreciseRethrow() throws Exception {
|
||||
doTest(false, false);
|
||||
}
|
||||
|
||||
public void testJavacQuirks() throws Exception {
|
||||
doTest(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -59,15 +59,15 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
myUnusedSymbolLocalInspection = new UnusedSymbolLocalInspection();
|
||||
return new LocalInspectionTool[]{
|
||||
new SillyAssignmentInspection(),
|
||||
new AccessStaticViaInstance(),
|
||||
new DeprecationInspection(),
|
||||
new RedundantThrowsDeclaration(),
|
||||
myUnusedSymbolLocalInspection,
|
||||
myUnusedSymbolLocalInspection = new UnusedSymbolLocalInspection(),
|
||||
new UnusedImportLocalInspection(),
|
||||
new UncheckedWarningLocalInspection()};
|
||||
new UncheckedWarningLocalInspection()
|
||||
};
|
||||
}
|
||||
|
||||
public void testCanHaveBody() throws Exception { doTest(false, false); }
|
||||
|
||||
@@ -28,6 +28,7 @@ public interface GroupNames {
|
||||
String BITWISE_GROUP_NAME = InspectionsBundle.message("group.names.bitwise.operation.issues");
|
||||
String CLASSLAYOUT_GROUP_NAME = InspectionsBundle.message("group.names.class.structure");
|
||||
String CLASSMETRICS_GROUP_NAME = InspectionsBundle.message("group.names.class.metrics");
|
||||
String COMPILER_ISSUES = InspectionsBundle.message("group.names.compiler.issues");
|
||||
String CONFUSING_GROUP_NAME = InspectionsBundle.message("group.names.potentially.confusing.code.constructs");
|
||||
String ENCAPSULATION_GROUP_NAME = InspectionsBundle.message("group.names.encapsulation.issues");
|
||||
String ERRORHANDLING_GROUP_NAME = InspectionsBundle.message("group.names.error.handling");
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<span>This inspection warns about known Javac issues, problems and incompatibilities.</span>
|
||||
</body>
|
||||
</html>
|
||||
@@ -403,6 +403,10 @@ inspection.duplicates.message.in.this.file=(in this file)
|
||||
inspection.duplicates.message.more=... ({0} more)
|
||||
inspection.duplicates.message=<html><body>Duplicate string literal found in<br>{0}</body></html>
|
||||
|
||||
inspection.compiler.javac.quirks.name=Javac quirks
|
||||
inspection.compiler.javac.quirks.anno.array.comma.problem=Trailing comma in annotation array initializer may cause compilation error in some Javac versions (e.g. JDK 5 and JDK 6).
|
||||
inspection.compiler.javac.quirks.anno.array.comma.fix=Remove trailing comma
|
||||
|
||||
inspection.root.node.title=Inspections
|
||||
|
||||
# inspection tools list actions:
|
||||
@@ -441,6 +445,7 @@ group.names.probable.bugs=Probable bugs
|
||||
group.names.bitwise.operation.issues=Bitwise operation issues
|
||||
group.names.class.structure=Class structure
|
||||
group.names.class.metrics=Class metrics
|
||||
group.names.compiler.issues=Compiler issues
|
||||
group.names.potentially.confusing.code.constructs=Potentially confusing code constructs
|
||||
group.names.encapsulation.issues=Encapsulation issues
|
||||
group.names.error.handling=Error handling
|
||||
|
||||
Reference in New Issue
Block a user