icons for test methods (IDEA-73084)
authoranna <anna.kozlova@jetbrains.com>
Mon, 15 Aug 2011 15:03:42 +0000 (19:03 +0400)
committeranna <anna.kozlova@jetbrains.com>
Mon, 15 Aug 2011 15:05:19 +0000 (19:05 +0400)
java/java-impl/src/com/intellij/testIntegration/JavaTestFramework.java
platform/icons/src/runConfigurations/ignoredTest.png [new file with mode: 0644]
platform/icons/src/runConfigurations/testMark.png [new file with mode: 0644]
platform/lang-api/src/com/intellij/testIntegration/TestFramework.java
platform/testRunner/src/com/intellij/execution/testframework/TestIconProvider.java [new file with mode: 0644]
plugins/junit/src/com/intellij/execution/junit/JUnit3Framework.java
plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java
plugins/testng/src/com/theoryinpractice/testng/TestNGFramework.java
resources/src/META-INF/IdeaPlugin.xml

index 8cf21dd96b9a2547d61b9e11df8d1a685cc3bc21..69398648427bfa4fe77c100cd29cd0727bb40fa3 100644 (file)
@@ -74,6 +74,11 @@ public abstract class JavaTestFramework implements TestFramework {
     return clazz instanceof PsiClass ? findOrCreateSetUpMethod((PsiClass)clazz) : null;
   }
 
+  @Override
+  public boolean isIgnoredMethod(PsiElement element) {
+    return false;
+  }
+
   @Nullable
   protected abstract PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException;
 }
diff --git a/platform/icons/src/runConfigurations/ignoredTest.png b/platform/icons/src/runConfigurations/ignoredTest.png
new file mode 100644 (file)
index 0000000..4d17d9b
Binary files /dev/null and b/platform/icons/src/runConfigurations/ignoredTest.png differ
diff --git a/platform/icons/src/runConfigurations/testMark.png b/platform/icons/src/runConfigurations/testMark.png
new file mode 100644 (file)
index 0000000..7effff8
Binary files /dev/null and b/platform/icons/src/runConfigurations/testMark.png differ
index 7dce065423b7b2d7b73694189c509ed1bdfd20a0..0f51a3c7d14fe84bea655addec0d1d28460a0b89 100644 (file)
@@ -61,4 +61,8 @@ public interface TestFramework {
   FileTemplateDescriptor getTearDownMethodFileTemplateDescriptor();
 
   FileTemplateDescriptor getTestMethodFileTemplateDescriptor();
+
+  boolean isIgnoredMethod(PsiElement element);
+
+  boolean isTestMethod(PsiElement element);
 }
diff --git a/platform/testRunner/src/com/intellij/execution/testframework/TestIconProvider.java b/platform/testRunner/src/com/intellij/execution/testframework/TestIconProvider.java
new file mode 100644 (file)
index 0000000..325c375
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.execution.testframework;
+
+import com.intellij.ide.IconProvider;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.psi.PsiElement;
+import com.intellij.testIntegration.TestFramework;
+import com.intellij.ui.LayeredIcon;
+import com.intellij.util.PlatformIcons;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+
+/**
+ * User: anna
+ */
+public class TestIconProvider extends IconProvider {
+  @Override
+  public Icon getIcon(@NotNull PsiElement element, int flags) {
+    final TestFramework[] testFrameworks = Extensions.getExtensions(TestFramework.EXTENSION_NAME);
+
+    for (TestFramework framework : testFrameworks) {
+      if (framework.isIgnoredMethod(element)) {
+        return TestsUIUtil.loadIcon("ignoredTest");
+      }
+    }
+
+    for (TestFramework framework : testFrameworks) {
+      if (framework.isTestMethod(element)) {
+        return new LayeredIcon(PlatformIcons.METHOD_ICON, TestsUIUtil.loadIcon("testMark"));
+      }
+    }
+
+    return null;
+  }
+}
index 3faa405da6ff83a6dbfddc52576811611263bf4b..7e13eb2509667e7eca78baa23ed1caa911a1f677 100644 (file)
@@ -116,4 +116,9 @@ public class JUnit3Framework extends JavaTestFramework {
   public FileTemplateDescriptor getTestMethodFileTemplateDescriptor() {
     return new FileTemplateDescriptor("JUnit3 Test Method.java");
   }
+
+  @Override
+  public boolean isTestMethod(PsiElement element) {
+    return element instanceof PsiMethod && JUnitUtil.getTestMethod(element) != null;
+  }
 }
index cd8cebf28bbea95951c45ce638c057677e2ec9bf..c91257e24abb4765988735bf3ac52862aa8435c9 100644 (file)
@@ -24,6 +24,7 @@ import com.intellij.testIntegration.JavaTestFramework;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.junit.Ignore;
 
 import javax.swing.*;
 
@@ -97,6 +98,17 @@ public class JUnit4Framework extends JavaTestFramework {
     return method;
   }
 
+  @Override
+  public boolean isIgnoredMethod(PsiElement element) {
+    final PsiMethod testMethod = element instanceof PsiMethod ? JUnitUtil.getTestMethod(element) : null;
+    return testMethod != null && AnnotationUtil.isAnnotated(testMethod, Ignore.class.getName(), false);
+  }
+
+  @Override
+  public boolean isTestMethod(PsiElement element) {
+    return element instanceof PsiMethod && JUnitUtil.getTestMethod(element) != null;
+  }
+
   public FileTemplateDescriptor getSetUpMethodFileTemplateDescriptor() {
     return new FileTemplateDescriptor("JUnit4 SetUp Method.java");
   }
index cbff43fb79cf6dea169e9cfaa5635d6b35e935d0..2dcb9d188663152b4d0af1b68fd203b0b55d8eba 100644 (file)
@@ -152,4 +152,9 @@ public class TestNGFramework extends JavaTestFramework {
   public FileTemplateDescriptor getTestMethodFileTemplateDescriptor() {
     return new FileTemplateDescriptor("TestNG Test Method.java");
   }
+
+  @Override
+  public boolean isTestMethod(PsiElement element) {
+    return element instanceof PsiMethod && TestNGUtil.hasTest((PsiModifierListOwner)element);
+  }
 }
index f27646725c35ba0bd0ac5443bd80fc7c0224b211..f38211bb7bd545f360afebee4427d59c0087fe2c 100644 (file)
       <descriptionDirectoryName>AddAnnotationFix</descriptionDirectoryName>
     </intentionAction>
     <intentionAction>
+      <className>com.intellij.codeInsight.daemon.impl.quickfix.IterateOverSelectedIterableIntention</className>
+      <category>Control Flow</category>
+    </intentionAction>
+    <intentionAction>
       <className>com.intellij.codeInsight.intention.impl.DeannotateIntentionAction</className>                                ยก
       <category>Control Flow</category>
     </intentionAction>
     <lang.smartEnterProcessor language="JSPX" implementationClass="com.intellij.codeInsight.completion.XmlSmartEnterProcessor"/>
 
     <iconProvider implementation="com.intellij.psi.impl.JavaDirectoryIconProvider" id="javaDirectory"/>
+    <iconProvider implementation="com.intellij.execution.testframework.TestIconProvider" id="testIcons"/>
 
     <codeStyleSettingsProvider implementation="com.intellij.application.options.JavaCodeStyleSettingsProvider"/>
     <codeStyleSettingsProvider implementation="com.intellij.application.options.GenerationSettingsProvider"/>