Language chooser is removed from CreateTestDialog. TestGenerators are per language... pycharm/110.235
authorMaxim.Medvedev <maxim.medvedev@jetbrains.com>
Thu, 27 Oct 2011 11:25:23 +0000 (15:25 +0400)
committerMaxim.Medvedev <maxim.medvedev@jetbrains.com>
Thu, 27 Oct 2011 11:53:24 +0000 (15:53 +0400)
12 files changed:
java/java-impl/src/com/intellij/testIntegration/JavaTestFramework.java
java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestAction.java
java/java-impl/src/com/intellij/testIntegration/createTest/CreateTestDialog.java
java/java-impl/src/com/intellij/testIntegration/createTest/JavaTestGenerator.java
java/java-impl/src/com/intellij/testIntegration/createTest/TestGenerator.java
java/java-impl/src/com/intellij/testIntegration/createTest/TestGenerators.java [new file with mode: 0644]
platform/lang-api/src/com/intellij/testIntegration/TestFramework.java
platform/platform-resources/src/META-INF/LangExtensionPoints.xml
plugins/groovy/src/META-INF/plugin.xml
plugins/groovy/src/org/jetbrains/plugins/groovy/testIntegration/GroovyTestFramework.java
plugins/groovy/src/org/jetbrains/plugins/groovy/testIntegration/GroovyTestGenerator.java
resources/src/META-INF/IdeaPlugin.xml

index 69398648427bfa4fe77c100cd29cd0727bb40fa3..812738dd45949c2bd60f406df836d8813805e189 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -15,6 +15,8 @@
  */
 package com.intellij.testIntegration;
 
+import com.intellij.lang.Language;
+import com.intellij.lang.java.JavaLanguage;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.roots.ProjectRootManager;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -79,6 +81,12 @@ public abstract class JavaTestFramework implements TestFramework {
     return false;
   }
 
+  @Override
+  @NotNull
+  public Language getLanguage() {
+    return JavaLanguage.INSTANCE;
+  }
+
   @Nullable
   protected abstract PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException;
 }
index 3f4ecf29e93a4fe7bb0ac675e916766330f26043..0a07ccfddb28922fac9bcc42120c602803173272 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -110,7 +110,8 @@ public class CreateTestAction extends PsiElementBaseIntentionAction {
     CommandProcessor.getInstance().executeCommand(project, new Runnable() {
       @Override
       public void run() {
-        final TestGenerator generator = d.getGenerator();
+        TestFramework framework = d.getSelectedTestFrameworkDescriptor();
+        TestGenerator generator = TestGenerators.INSTANCE.forLanguage(framework.getLanguage());
         generator.generateTest(project, d);
       }
     }, CodeInsightBundle.message("intention.create.test"), this);
index 157966250b20e130b19c02c3135161548b9fa8dc..cd2a3ef3a05e30dda0ca06a06d675c1d8cf583d2 100644 (file)
@@ -22,7 +22,6 @@ import com.intellij.ide.util.PackageUtil;
 import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.ide.util.TreeClassChooser;
 import com.intellij.ide.util.TreeClassChooserFactory;
-import com.intellij.lang.Language;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.CustomShortcutSet;
@@ -39,7 +38,6 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.ContentEntry;
 import com.intellij.openapi.roots.ModuleRootManager;
 import com.intellij.openapi.roots.SourceFolder;
-import com.intellij.openapi.ui.ComboBox;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.IconLoader;
@@ -82,7 +80,6 @@ public class CreateTestDialog extends DialogWrapper {
   private TestFramework mySelectedFramework;
 
   private final List<JRadioButton> myLibraryButtons = new ArrayList<JRadioButton>();
-  private ComboBox myLanguageCombo;
   private EditorTextField myTargetClassNameField;
   private ReferenceEditorWithBrowseButton mySuperClassField;
   private ReferenceEditorComboWithBrowseButton myTargetPackageField;
@@ -171,16 +168,6 @@ public class CreateTestDialog extends DialogWrapper {
       }
     });
 
-    TestGenerator[] generators = TestGenerator.EP_NAME.getExtensions();
-    myLanguageCombo = new ComboBox(generators, -1);
-    final Language curLang = myTargetClass.getLanguage();
-    for (TestGenerator generator : generators) {
-      if (curLang == generator.getLanguage()) {
-        myLanguageCombo.setSelectedItem(generator);
-        break;
-      }
-    }
-
     myTargetClassNameField = new EditorTextField(targetClass.getName() + "Test");
     myTargetClassNameField.getDocument().addDocumentListener(new DocumentAdapter() {
       @Override
@@ -292,8 +279,11 @@ public class CreateTestDialog extends DialogWrapper {
       librariesPanel.add(b);
     }
 
+    
+    int gridy = 1;
+    
     constr.insets = insets(4);
-    constr.gridy = 1;
+    constr.gridy = gridy++;
     constr.gridx = 0;
     constr.weightx = 0;
     panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.testing.library")), constr);
@@ -310,25 +300,14 @@ public class CreateTestDialog extends DialogWrapper {
     myFixLibraryPanel.add(myFixLibraryButton, BorderLayout.EAST);
 
     constr.insets = insets(1);
-    constr.gridy = 2;
+    constr.gridy = gridy++;
     constr.gridx = 0;
     panel.add(myFixLibraryPanel, constr);
 
     constr.gridheight = 1;
 
-    constr.insets = insets(1);
-    constr.gridy = 3;
-    constr.gridx = 0;
-    constr.weightx = 0;
-    constr.gridwidth = 1;
-    panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.language")), constr);
-
-    constr.gridx = 1;
-    constr.weightx = 1;
-    panel.add(myLanguageCombo, constr);
-
     constr.insets = insets(6);
-    constr.gridy = 4;
+    constr.gridy = gridy++;
     constr.gridx = 0;
     constr.weightx = 0;
     constr.gridwidth = 1;
@@ -339,7 +318,7 @@ public class CreateTestDialog extends DialogWrapper {
     panel.add(myTargetClassNameField, constr);
 
     constr.insets = insets(1);
-    constr.gridy = 5;
+    constr.gridy = gridy++;
     constr.gridx = 0;
     constr.weightx = 0;
     panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.super.class")), constr);
@@ -349,7 +328,7 @@ public class CreateTestDialog extends DialogWrapper {
     panel.add(mySuperClassField, constr);
 
     constr.insets = insets(1);
-    constr.gridy = 6;
+    constr.gridy = gridy++;
     constr.gridx = 0;
     constr.weightx = 0;
     panel.add(new JLabel(CodeInsightBundle.message("dialog.create.class.destination.package.label")), constr);
@@ -362,7 +341,7 @@ public class CreateTestDialog extends DialogWrapper {
     panel.add(targetPackagePanel, constr);
 
     constr.insets = insets(6);
-    constr.gridy = 7;
+    constr.gridy = gridy++;
     constr.gridx = 0;
     constr.weightx = 0;
     panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.generate")), constr);
@@ -372,11 +351,11 @@ public class CreateTestDialog extends DialogWrapper {
     panel.add(myGenerateBeforeBox, constr);
 
     constr.insets = insets(1);
-    constr.gridy = 8;
+    constr.gridy = gridy++;
     panel.add(myGenerateAfterBox, constr);
 
     constr.insets = insets(6);
-    constr.gridy = 9;
+    constr.gridy = gridy++;
     constr.gridx = 0;
     constr.weightx = 0;
     panel.add(new JLabel(CodeInsightBundle.message("intention.create.test.dialog.select.methods")), constr);
@@ -386,7 +365,7 @@ public class CreateTestDialog extends DialogWrapper {
     panel.add(myShowInheritedMethodsBox, constr);
 
     constr.insets = insets(1, 8);
-    constr.gridy = 10;
+    constr.gridy = gridy++;
     constr.gridx = 0;
     constr.gridwidth = GridBagConstraints.REMAINDER;
     constr.fill = GridBagConstraints.BOTH;
@@ -509,11 +488,6 @@ public class CreateTestDialog extends DialogWrapper {
     HelpManager.getInstance().invokeHelp("reference.dialogs.createTest");
   }
 
-  @NotNull
-  TestGenerator getGenerator() {
-    return (TestGenerator)myLanguageCombo.getSelectedItem();
-  }
-
   private class MyChooseSuperClassAction implements ActionListener {
     public void actionPerformed(ActionEvent e) {
       TreeClassChooserFactory f = TreeClassChooserFactory.getInstance(myProject);
index 6b104173a6646c5d6fef4f790620ad9da8345dd2..1fa6543190ff3016a8d127c68ee4a8918194add7 100644 (file)
@@ -17,8 +17,6 @@ package com.intellij.testIntegration.createTest;
 
 import com.intellij.codeInsight.CodeInsightBundle;
 import com.intellij.codeInsight.CodeInsightUtil;
-import com.intellij.lang.Language;
-import com.intellij.lang.java.JavaLanguage;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory;
@@ -133,9 +131,4 @@ public class JavaTestGenerator implements TestGenerator {
   public String toString() {
     return CodeInsightBundle.message("intention.create.test.dialog.java");
   }
-
-  @Override
-  public Language getLanguage() {
-    return JavaLanguage.INSTANCE;
-  }
 }
\ No newline at end of file
index 5c372a2615eec692988472cd379b1dee52a2b949..602788267ef5bf5c94931b26d5d2f80e8d9c5f61 100644 (file)
@@ -15,8 +15,6 @@
  */
 package com.intellij.testIntegration.createTest;
 
-import com.intellij.lang.Language;
-import com.intellij.openapi.extensions.ExtensionPointName;
 import com.intellij.openapi.project.Project;
 import com.intellij.psi.PsiElement;
 import org.jetbrains.annotations.Nullable;
@@ -25,8 +23,6 @@ import org.jetbrains.annotations.Nullable;
  * @author Maxim.Medvedev
  */
 public interface TestGenerator {
-  ExtensionPointName<TestGenerator> EP_NAME = ExtensionPointName.create("com.intellij.testGenerator");
-
   /**
    *
    * @return generated test (i.e. PsiClass)
@@ -38,6 +34,4 @@ public interface TestGenerator {
    * should return text to show in dialog
    */
   String toString();
-
-  Language getLanguage();
 }
diff --git a/java/java-impl/src/com/intellij/testIntegration/createTest/TestGenerators.java b/java/java-impl/src/com/intellij/testIntegration/createTest/TestGenerators.java
new file mode 100644 (file)
index 0000000..37f173b
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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.testIntegration.createTest;
+
+import com.intellij.lang.LanguageExtension;
+
+/**
+ * @author Max Medvedev
+ */
+public class TestGenerators extends LanguageExtension<TestGenerator> {
+  public static final TestGenerators INSTANCE = new TestGenerators();
+
+  private TestGenerators() {
+    super("com.intellij.testGenerator", new JavaTestGenerator());
+  }
+}
index 5a7fc14c0ae7b2edea3d9b68bd55beb39bb84555..ee6b5e3f7d4a845954bf740c13d5cb7a497714dc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * 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.
@@ -17,6 +17,7 @@
 package com.intellij.testIntegration;
 
 import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
+import com.intellij.lang.Language;
 import com.intellij.openapi.extensions.ExtensionPointName;
 import com.intellij.openapi.module.Module;
 import com.intellij.psi.PsiElement;
@@ -71,4 +72,7 @@ public interface TestFramework {
    * should be checked for abstract method error
    */
   boolean isTestMethod(PsiElement element);
+
+  @NotNull
+  Language getLanguage();
 }
index e9c7dc52b4d5eecaafff374f0bf5100f8c4ae108..28ae518b2627d1dec3a2632d8fb1b06d31fbe9fc 100644 (file)
                   beanClass="com.intellij.lang.LanguageExtensionPoint"/>
 
   <extensionPoint name="testGenerator"
-                  interface="com.intellij.testIntegration.createTest.TestGenerator"/>
+                  beanClass="com.intellij.lang.LanguageExtensionPoint"/>
 
   <extensionPoint name="lang.smartEnterProcessor"
                   beanClass="com.intellij.lang.LanguageExtensionPoint"/>
index f53fc87ce479ad2f411590cdda1e5705803a817c..f7cdee6617fb1e5c7f6a2165635a20495a01612a 100644 (file)
   <extensions defaultExtensionNs="com.intellij">
     <testFramework implementation="org.jetbrains.plugins.groovy.testIntegration.GroovyTestFramework"/>
     <testCreator language="Groovy" implementationClass="com.intellij.testIntegration.JavaTestCreator"/>
-    <testGenerator implementation="org.jetbrains.plugins.groovy.testIntegration.GroovyTestGenerator"/>
+    <testGenerator language="Groovy" implementationClass="org.jetbrains.plugins.groovy.testIntegration.GroovyTestGenerator"/>
     <editorNotificationProvider implementation="org.jetbrains.plugins.groovy.annotator.ConfigureGroovyLibraryNotificationProvider"/>
     <refactoring.introduceParameterMethodUsagesProcessor implementation="org.jetbrains.plugins.groovy.refactoring.introduce.parameter.java2groovy.GroovyIntroduceParameterMethodUsagesProcessor"/>
     <refactoring.changeSignatureUsageProcessor implementation="org.jetbrains.plugins.groovy.refactoring.changeSignature.GrChangeSignatureUsageProcessor" id="groovyProcessor" order="before javaProcessor"/>
index db989b60ee4847d5cdfd17c6783fb14edca4c61c..fa272db569c34346ba13314ec01d13e918ab495a 100644 (file)
@@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.testIntegration;
 
 import com.intellij.execution.junit.JUnitUtil;
 import com.intellij.ide.fileTemplates.FileTemplateDescriptor;
+import com.intellij.lang.Language;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
 import com.intellij.psi.PsiClass;
@@ -139,4 +140,10 @@ public class GroovyTestFramework extends JavaTestFramework {
   public boolean isTestMethod(PsiElement element) {
     return element instanceof PsiMethod && JUnitUtil.getTestMethod(element) != null;
   }
+
+  @Override
+  @NotNull
+  public Language getLanguage() {
+    return GroovyFileType.GROOVY_LANGUAGE;
+  }
 }
index 06bb5f008c7a7a00a4f0a7244b43d6b5345b2106..77215588fcb4b0a1909cbea67af6bd8e5cdb69a0 100644 (file)
@@ -17,7 +17,6 @@ package org.jetbrains.plugins.groovy.testIntegration;
 
 import com.intellij.codeInsight.CodeInsightBundle;
 import com.intellij.codeInsight.CodeInsightUtil;
-import com.intellij.lang.Language;
 import com.intellij.openapi.application.AccessToken;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.WriteAction;
@@ -37,7 +36,6 @@ import com.intellij.testIntegration.createTest.CreateTestDialog;
 import com.intellij.testIntegration.createTest.TestGenerator;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.Nullable;
-import org.jetbrains.plugins.groovy.GroovyFileType;
 import org.jetbrains.plugins.groovy.actions.NewGroovyClassAction;
 import org.jetbrains.plugins.groovy.annotator.intentions.CreateClassActionBase;
 import org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle;
@@ -104,11 +102,6 @@ public class GroovyTestGenerator implements TestGenerator {
     return GroovyIntentionsBundle.message("intention.crete.test.groovy");
   }
 
-  @Override
-  public Language getLanguage() {
-    return GroovyFileType.GROOVY_LANGUAGE;
-  }
-
   private static void addSuperClass(GrTypeDefinition targetClass, Project project, @Nullable String superClassName)
     throws IncorrectOperationException {
     if (superClassName == null) return;
index 5176e80521beb60683e83c1cf50d00f582f8b820..d42976e3878f3970f61b444dead89ff9a6846c6c 100644 (file)
 
     <testFinder implementation="com.intellij.testIntegration.JavaTestFinder"/>
     <testCreator language="JAVA" implementationClass="com.intellij.testIntegration.JavaTestCreator"/>
-    <testGenerator implementation="com.intellij.testIntegration.createTest.JavaTestGenerator" />
+    <testGenerator language="JAVA" implementationClass="com.intellij.testIntegration.createTest.JavaTestGenerator" />
 
     <callHierarchyProvider language="JAVA" implementationClass="com.intellij.ide.hierarchy.call.JavaCallHierarchyProvider"/>
     <methodHierarchyProvider language="JAVA" implementationClass="com.intellij.ide.hierarchy.method.JavaMethodHierarchyProvider"/>