diff --git a/java/java-impl/src/com/intellij/ide/fileTemplates/JavaCreateFromTemplateHandler.java b/java/java-impl/src/com/intellij/ide/fileTemplates/JavaCreateFromTemplateHandler.java index 0d0d1054158c..039be6942c81 100644 --- a/java/java-impl/src/com/intellij/ide/fileTemplates/JavaCreateFromTemplateHandler.java +++ b/java/java-impl/src/com/intellij/ide/fileTemplates/JavaCreateFromTemplateHandler.java @@ -109,6 +109,9 @@ public class JavaCreateFromTemplateHandler implements CreateFromTemplateHandler } public boolean canCreate(final PsiDirectory[] dirs) { + for (PsiDirectory dir : dirs) { + if (canCreate(dir)) return true; + } return false; } diff --git a/java/java-impl/src/com/intellij/ide/fileTemplates/JavaInternalTemplatesHandler.java b/java/java-impl/src/com/intellij/ide/fileTemplates/JavaInternalTemplatesHandler.java new file mode 100644 index 000000000000..5637e8318265 --- /dev/null +++ b/java/java-impl/src/com/intellij/ide/fileTemplates/JavaInternalTemplatesHandler.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2015 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.ide.fileTemplates; + +import com.intellij.psi.PsiDirectory; +import com.intellij.util.ArrayUtil; + +public class JavaInternalTemplatesHandler extends JavaCreateFromTemplateHandler { + + @Override + public boolean handlesTemplate(FileTemplate template) { + return ArrayUtil.contains(template.getName(), JavaTemplateUtil.INTERNAL_JAVA_TEMPLATES); + } + + @Override + public boolean canCreate(PsiDirectory[] dirs) { + return false; + } +} diff --git a/java/java-impl/src/com/intellij/ide/fileTemplates/JavaTemplateUtil.java b/java/java-impl/src/com/intellij/ide/fileTemplates/JavaTemplateUtil.java index a3fc37e9c20e..8f872d0060f8 100644 --- a/java/java-impl/src/com/intellij/ide/fileTemplates/JavaTemplateUtil.java +++ b/java/java-impl/src/com/intellij/ide/fileTemplates/JavaTemplateUtil.java @@ -32,11 +32,15 @@ public class JavaTemplateUtil { @NonNls public static final String TEMPLATE_I18NIZED_EXPRESSION = "I18nized Expression.java"; @NonNls public static final String TEMPLATE_I18NIZED_CONCATENATION = "I18nized Concatenation.java"; @NonNls public static final String TEMPLATE_I18NIZED_JSP_EXPRESSION = "I18nized JSP Expression.jsp"; + @NonNls public static final String INTERNAL_CLASS_TEMPLATE_NAME = "Class"; @NonNls public static final String INTERNAL_INTERFACE_TEMPLATE_NAME = "Interface"; @NonNls public static final String INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME = "AnnotationType"; @NonNls public static final String INTERNAL_ENUM_TEMPLATE_NAME = "Enum"; + public static final String[] INTERNAL_JAVA_TEMPLATES = new String[]{INTERNAL_CLASS_TEMPLATE_NAME, + INTERNAL_INTERFACE_TEMPLATE_NAME, INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME, INTERNAL_ENUM_TEMPLATE_NAME}; + private JavaTemplateUtil() { } diff --git a/java/java-tests/testSrc/com/intellij/ide/fileTemplates/JavaFileTemplatesTest.java b/java/java-tests/testSrc/com/intellij/ide/fileTemplates/JavaFileTemplatesTest.java new file mode 100644 index 000000000000..65f4a60a983a --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/ide/fileTemplates/JavaFileTemplatesTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2015 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.ide.fileTemplates; + +import com.intellij.ide.fileTemplates.actions.CreateFromTemplateAction; +import com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.util.Condition; +import com.intellij.testFramework.TestActionEvent; +import com.intellij.testFramework.TestDataProvider; +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; +import com.intellij.util.containers.ContainerUtil; + +public class JavaFileTemplatesTest extends LightCodeInsightFixtureTestCase { + + public void testCreateFromTemplateGroup() throws Exception { + + myFixture.configureByText("foo.java", ""); + AnAction[] children = new CreateFromTemplateGroup().getChildren(new TestActionEvent(new TestDataProvider(getProject()))); + assertNull(ContainerUtil.find(children, new Condition() { + @Override + public boolean value(AnAction action) { + return action instanceof CreateFromTemplateAction && ((CreateFromTemplateAction)action).getTemplate().getName().equals("Class"); + } + })); + assertNotNull(ContainerUtil.find(children, new Condition() { + @Override + public boolean value(AnAction action) { + return action instanceof CreateFromTemplateAction && ((CreateFromTemplateAction)action).getTemplate().getName().equals("Singleton"); + } + })); + } +} diff --git a/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorPsiDataProvider.java b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorPsiDataProvider.java index 7400e982b5a0..db696efeacc0 100644 --- a/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorPsiDataProvider.java +++ b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorPsiDataProvider.java @@ -22,6 +22,7 @@ import com.intellij.ide.util.EditorHelper; import com.intellij.injected.editor.EditorWindow; import com.intellij.injected.editor.InjectedCaret; import com.intellij.lang.Language; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ex.EditorEx; @@ -114,7 +115,7 @@ public class TextEditorPsiDataProvider implements EditorDataProvider { if (IDE_VIEW.is(dataId)) { final PsiFile psiFile = project == null ? null : PsiManager.getInstance(project).findFile(file); final PsiDirectory psiDirectory = psiFile != null ? psiFile.getParent() : null; - if (psiDirectory != null && psiDirectory.isPhysical()) { + if (psiDirectory != null && (psiDirectory.isPhysical() || ApplicationManager.getApplication().isUnitTestMode())) { return new IdeView() { @Override diff --git a/platform/testFramework/src/com/intellij/testFramework/TestActionEvent.java b/platform/testFramework/src/com/intellij/testFramework/TestActionEvent.java index 23dc823dcd2d..cccb77ad2158 100644 --- a/platform/testFramework/src/com/intellij/testFramework/TestActionEvent.java +++ b/platform/testFramework/src/com/intellij/testFramework/TestActionEvent.java @@ -37,6 +37,10 @@ public class TestActionEvent extends AnActionEvent { super(null, DataManager.getInstance().getDataContext(), "", presentation, ActionManager.getInstance(), 0); } + public TestActionEvent(DataContext context) { + super(null, context, "", new Presentation(), ActionManager.getInstance(), 0); + } + public TestActionEvent() { super(null, DataManager.getInstance().getDataContext(), "", new Presentation(), ActionManager.getInstance(), 0); } diff --git a/platform/testFramework/src/com/intellij/testFramework/TestDataProvider.java b/platform/testFramework/src/com/intellij/testFramework/TestDataProvider.java index 1ed87bbcb0fa..e9d9d5023d7b 100644 --- a/platform/testFramework/src/com/intellij/testFramework/TestDataProvider.java +++ b/platform/testFramework/src/com/intellij/testFramework/TestDataProvider.java @@ -16,6 +16,7 @@ package com.intellij.testFramework; import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.DataProvider; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.editor.Editor; @@ -32,7 +33,7 @@ import javax.swing.*; /** * @author peter */ -public class TestDataProvider implements DataProvider { +public class TestDataProvider implements DataProvider, DataContext { private final Project myProject; public TestDataProvider(@NotNull Project project) { diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index aa814ab8d713..b59283f0fa5e 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -1273,7 +1273,9 @@ + +