Internal inspections cleaned up and forced to execute on IDEA project (only)

This commit is contained in:
Roman Shevchenko
2012-08-20 18:18:41 +04:00
parent 19e4b7d2ca
commit 41b806fb3b
8 changed files with 47 additions and 94 deletions
@@ -17,31 +17,16 @@ package com.intellij.codeInspection.internal;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.psi.*;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
public class FileEqualsUsageInspection extends InternalInspection {
@Nls
@NotNull
@Override
public String getDisplayName() {
return "File.equals()/hashCode()/compareTo() Usage";
}
private static final String MESSAGE =
"Do not use File.equals/hashCode/compareTo as they don't honor case-sensitivity on MacOS. " +
"Please use FileUtil.filesEquals/fileHashCode/compareFiles instead";
@NotNull
@Override
public String getShortName() {
return "FileEqualsUsage";
}
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
if (!ApplicationManagerEx.getApplicationEx().isInternal()) {
return new JavaElementVisitor() {
};
}
public PsiElementVisitor buildInternalVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new JavaElementVisitor() {
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
@@ -55,11 +40,9 @@ public class FileEqualsUsageInspection extends InternalInspection {
if (clazz == null) return;
String methodName = method.getName();
if (CommonClassNames.JAVA_IO_FILE.equals(clazz.getQualifiedName())
&& ("equals".equals(methodName) || "compareTo".equals(methodName) || "hashCode".equals(methodName))) {
holder.registerProblem(methodExpression,
"Do not use File.equals/hashCode/compareTo as they don't honor case-sensitivity on MacOS. Use FileUtil.filesEquals/fileHashCode/compareFiles instead",
ProblemHighlightType.LIKE_DEPRECATED);
if (CommonClassNames.JAVA_IO_FILE.equals(clazz.getQualifiedName()) &&
("equals".equals(methodName) || "compareTo".equals(methodName) || "hashCode".equals(methodName))) {
holder.registerProblem(methodExpression, MESSAGE, ProblemHighlightType.LIKE_DEPRECATED);
}
}
};
@@ -16,13 +16,11 @@
package com.intellij.codeInspection.internal;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.InheritanceUtil;
import org.jetbrains.annotations.Nls;
import com.intellij.ui.ListCellRendererWrapper;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -33,26 +31,11 @@ public class GtkPreferredJComboBoxRendererInspection extends InternalInspection
private static final String SETTER_METHOD_NAME = "setRenderer";
private static final String MESSAGE =
"Default ListCellRenderer implementations are known to cause UI artifacts under GTK+ Look and Feel," +
"Default ListCellRenderer implementations are known to cause UI artifacts under GTK+ Look and Feel, " +
"so please use ListCellRendererWrapper instead.";
@Nls
@NotNull
@Override
public String getDisplayName() {
return "Preferred JComboBox renderer";
}
@NotNull
@Override
public String getShortName() {
return "GtkPreferredJComboBoxRenderer";
}
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
if (!ApplicationManagerEx.getApplicationEx().isInternal()) return new JavaElementVisitor() {};
public PsiElementVisitor buildInternalVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new JavaElementVisitor() {
@Override
public void visitMethodCallExpression(final PsiMethodCallExpression expression) {
@@ -18,35 +18,42 @@ package com.intellij.codeInspection.internal;
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
import com.intellij.codeInspection.LocalInspectionToolSession;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.components.JBList;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
public abstract class InternalInspection extends BaseJavaLocalInspectionTool {
private static final String GROUP_NAME = "IDEA Platform Inspections";
private static final Key<Boolean> INTERNAL_INSPECTIONS = Key.create("idea.internal.inspections.enabled");
private static final String MARKER_CLASS = JBList.class.getName();
private static final PsiElementVisitor EMPTY_VISITOR = new PsiElementVisitor() { };
@Nls
@NotNull
@Override
public String getGroupDisplayName() {
return GROUP_NAME;
}
public boolean isEnabledByDefault() {
return true;
public final PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
return isAllowed(holder.getProject()) ? buildInternalVisitor(holder, isOnTheFly) : EMPTY_VISITOR;
}
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder,
boolean isOnTheFly,
@NotNull LocalInspectionToolSession session) {
final GlobalSearchScope scope = GlobalSearchScope.allScope(holder.getProject());
final PsiClass markerClass = JavaPsiFacade.getInstance(holder.getProject()).findClass(JBList.class.getName(), scope);
return markerClass != null ? super.buildVisitor(holder, isOnTheFly, session) : new PsiElementVisitor() { };
public final PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder,
boolean isOnTheFly,
@NotNull LocalInspectionToolSession session) {
return isAllowed(holder.getProject()) ? buildInternalVisitor(holder, isOnTheFly) : EMPTY_VISITOR;
}
private static boolean isAllowed(@NotNull Project project) {
Boolean flag = project.getUserData(INTERNAL_INSPECTIONS);
if (flag == null) {
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
flag = JavaPsiFacade.getInstance(project).findClass(MARKER_CLASS, scope) != null;
project.putUserData(INTERNAL_INSPECTIONS, flag);
}
return flag;
}
public abstract PsiElementVisitor buildInternalVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -18,7 +18,6 @@ package com.intellij.codeInspection.internal;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.openapi.application.QueryExecutorBase;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.psi.*;
import com.intellij.ui.components.JBList;
import com.intellij.ui.components.JBScrollPane;
@@ -26,7 +25,6 @@ import com.intellij.ui.table.JBTable;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.QueryExecutor;
import gnu.trove.THashMap;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -34,7 +32,6 @@ import java.util.Map;
public class UndesirableClassUsageInspection extends InternalInspection {
private static final Map<String, String> CLASSES = new THashMap<String, String>();
static {
CLASSES.put(JList.class.getName(), JBList.class.getName());
CLASSES.put(JTable.class.getName(), JBTable.class.getName());
@@ -43,22 +40,8 @@ public class UndesirableClassUsageInspection extends InternalInspection {
CLASSES.put(QueryExecutor.class.getName(), QueryExecutorBase.class.getName());
}
@Nls
@NotNull
@Override
public String getDisplayName() {
return "Undesirable Class Usage";
}
@NotNull
@Override
public String getShortName() {
return "UndesirableClassUsage";
}
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
if (!ApplicationManagerEx.getApplicationEx().isInternal()) return new JavaElementVisitor() {};
public PsiElementVisitor buildInternalVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new JavaElementVisitor() {
@Override
public void visitNewExpression(PsiNewExpression expression) {
@@ -1,8 +1,7 @@
<html>
<body>
<font face="verdana" size="-1">
This inspection detects usages of File.equals/hashCode/compareTo which do not honor case-sensitivity on MacOS.
FileUtil.filesEquals/fileHashCode/compareFiles should be used instead.
</font>
This inspection detects usages of File.equals/hashCode/compareTo methods - which do not honor case-insensitivity on Mac OS X.
Please use FileUtil.filesEquals/fileHashCode/compareFiles methods instead.
<p><small>Internal inspection - has no effect outside of IntelliJ IDEA project.</small></p>
</body>
</html>
@@ -1,8 +1,7 @@
<html>
<body>
<font face="verdana" size="-1">
This inspection detects usages of DefaultListCellRenderer in code. Please use ListCellRendererWrapper in case you need simple cell renderer with text and icon.
This avoids ugly UI under GTK look and feel, because in this case SynthComboBoxUI#SynthComboBoxRenderer is used instead of DefaultComboBoxRenderer.
</font>
This inspection detects usages of DefaultListCellRenderer - which causes ugly UI under GTK+ L&F.
Please use ListCellRendererWrapper (or it's inheritors) instead.
<p><small>Internal inspection - has no effect outside of IntelliJ IDEA project.</small></p>
</body>
</html>
@@ -1,7 +1,6 @@
<html>
<body>
<font face="verdana" size="-1">
Detects internally deprecated on undesirable classes usages.
</font>
This inspection detects usages of internally deprecated classes.
<p><small>Internal inspection - has no effect outside of IntelliJ IDEA project.</small></p>
</body>
</html>
+4 -4
View File
@@ -202,11 +202,11 @@
<definitionsSearch implementation="com.intellij.codeInsight.navigation.MethodImplementationsSearch"/>
<definitionsSearch implementation="com.intellij.codeInsight.navigation.ClassImplementationsSearch"/>
<localInspection language="JAVA" shortName="UndesirableClassUsage" displayName="Undesirable Class Usage" groupName="IDEA Platform Inspections"
enabledByDefault="true" level="WARNING"
<localInspection language="JAVA" shortName="UndesirableClassUsage" displayName="Undesirable class usage"
groupName="IDEA Platform Inspections" enabledByDefault="true" level="WARNING"
implementationClass="com.intellij.codeInspection.internal.UndesirableClassUsageInspection"/>
<localInspection language="JAVA" shortName="FileEqualsUsage" displayName="File.equals() usage" groupName="IDEA Platform Inspections"
enabledByDefault="true" level="WARNING"
<localInspection language="JAVA" shortName="FileEqualsUsage" displayName="File.equals() usage"
groupName="IDEA Platform Inspections" enabledByDefault="true" level="WARNING"
implementationClass="com.intellij.codeInspection.internal.FileEqualsUsageInspection"/>
<localInspection language="JAVA" shortName="GtkPreferredJComboBoxRenderer" displayName="Preferred JComboBox renderer"
groupName="IDEA Platform Inspections" enabledByDefault="true" level="WARNING"