From 41b806fb3bf133dc407dc13a3b88086c14a19b27 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 17 Aug 2012 17:30:38 +0400 Subject: [PATCH] Internal inspections cleaned up and forced to execute on IDEA project (only) --- .../internal/FileEqualsUsageInspection.java | 31 ++++----------- ...kPreferredJComboBoxRendererInspection.java | 23 ++--------- .../internal/InternalInspection.java | 39 +++++++++++-------- .../UndesirableClassUsageInspection.java | 21 +--------- .../FileEqualsUsage.html | 7 ++-- .../GtkPreferredJComboBoxRenderer.html | 7 ++-- .../UndesirableClassUsage.html | 5 +-- resources/src/META-INF/IdeaPlugin.xml | 8 ++-- 8 files changed, 47 insertions(+), 94 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/internal/FileEqualsUsageInspection.java b/java/java-impl/src/com/intellij/codeInspection/internal/FileEqualsUsageInspection.java index c453be136513..baba5bc221bd 100644 --- a/java/java-impl/src/com/intellij/codeInspection/internal/FileEqualsUsageInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/internal/FileEqualsUsageInspection.java @@ -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); } } }; diff --git a/java/java-impl/src/com/intellij/codeInspection/internal/GtkPreferredJComboBoxRendererInspection.java b/java/java-impl/src/com/intellij/codeInspection/internal/GtkPreferredJComboBoxRendererInspection.java index c63049ee677e..42d2cd83565a 100644 --- a/java/java-impl/src/com/intellij/codeInspection/internal/GtkPreferredJComboBoxRendererInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/internal/GtkPreferredJComboBoxRendererInspection.java @@ -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) { diff --git a/java/java-impl/src/com/intellij/codeInspection/internal/InternalInspection.java b/java/java-impl/src/com/intellij/codeInspection/internal/InternalInspection.java index f9c6dc475531..3a27ebda7b5f 100644 --- a/java/java-impl/src/com/intellij/codeInspection/internal/InternalInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/internal/InternalInspection.java @@ -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 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); } diff --git a/java/java-impl/src/com/intellij/codeInspection/internal/UndesirableClassUsageInspection.java b/java/java-impl/src/com/intellij/codeInspection/internal/UndesirableClassUsageInspection.java index 00373f456fa7..4477e0b37591 100644 --- a/java/java-impl/src/com/intellij/codeInspection/internal/UndesirableClassUsageInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/internal/UndesirableClassUsageInspection.java @@ -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 CLASSES = new THashMap(); - 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) { diff --git a/resources-en/src/inspectionDescriptions/FileEqualsUsage.html b/resources-en/src/inspectionDescriptions/FileEqualsUsage.html index 368545244a0b..7fc1f9339c87 100644 --- a/resources-en/src/inspectionDescriptions/FileEqualsUsage.html +++ b/resources-en/src/inspectionDescriptions/FileEqualsUsage.html @@ -1,8 +1,7 @@ - -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. - +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. +

Internal inspection - has no effect outside of IntelliJ IDEA project.

diff --git a/resources-en/src/inspectionDescriptions/GtkPreferredJComboBoxRenderer.html b/resources-en/src/inspectionDescriptions/GtkPreferredJComboBoxRenderer.html index 199e1de69b76..b28da271ac15 100644 --- a/resources-en/src/inspectionDescriptions/GtkPreferredJComboBoxRenderer.html +++ b/resources-en/src/inspectionDescriptions/GtkPreferredJComboBoxRenderer.html @@ -1,8 +1,7 @@ - -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. - +This inspection detects usages of DefaultListCellRenderer - which causes ugly UI under GTK+ L&F. +Please use ListCellRendererWrapper (or it's inheritors) instead. +

Internal inspection - has no effect outside of IntelliJ IDEA project.

diff --git a/resources-en/src/inspectionDescriptions/UndesirableClassUsage.html b/resources-en/src/inspectionDescriptions/UndesirableClassUsage.html index f26b80c4ca8a..bbbe61d159c6 100644 --- a/resources-en/src/inspectionDescriptions/UndesirableClassUsage.html +++ b/resources-en/src/inspectionDescriptions/UndesirableClassUsage.html @@ -1,7 +1,6 @@ - -Detects internally deprecated on undesirable classes usages. - +This inspection detects usages of internally deprecated classes. +

Internal inspection - has no effect outside of IntelliJ IDEA project.

diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index f2341b38a24b..087e541258f1 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -202,11 +202,11 @@ - -