diff --git a/plugins/devkit/resources/META-INF/plugin.xml b/plugins/devkit/resources/META-INF/plugin.xml index b05c49186f4f..d0d12d3744f7 100644 --- a/plugins/devkit/resources/META-INF/plugin.xml +++ b/plugins/devkit/resources/META-INF/plugin.xml @@ -66,6 +66,13 @@ bundle="org.jetbrains.idea.devkit.DevKitBundle" groupKey="inspections.group.name" enabledByDefault="true" level="WARNING" implementationClass="org.jetbrains.idea.devkit.inspections.IntentionDescriptionNotFoundInspection"/> + + +Checks if postfix template (completion) has a description. + + diff --git a/plugins/devkit/src/DevKitBundle.properties b/plugins/devkit/src/DevKitBundle.properties index 07d3b2914baf..6799f6d2415f 100644 --- a/plugins/devkit/src/DevKitBundle.properties +++ b/plugins/devkit/src/DevKitBundle.properties @@ -147,6 +147,9 @@ inspections.component.not.registered.option.ignore.non.public=Ignore non-public inspections.component.not.registered.quickfix.family=Register Component inspections.component.not.registered.quickfix.name=Register {0} inspections.component.not.registered.quickfix.error=Cannot Register {0} + +inspections.component.postfix.template.not.found.description.name=Postfix template Description Checker + InspectionUseGrayColor=Use Gray ant.build.jar.comment=Build archive for plugin ''{0}'' ant.build.jar.description=Build plugin archive for module ''{0}'' diff --git a/plugins/devkit/src/inspections/DescriptionNotFoundInspectionBase.java b/plugins/devkit/src/inspections/DescriptionNotFoundInspectionBase.java new file mode 100644 index 000000000000..d1a2fac52685 --- /dev/null +++ b/plugins/devkit/src/inspections/DescriptionNotFoundInspectionBase.java @@ -0,0 +1,135 @@ +/* + * Copyright 2000-2014 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 org.jetbrains.idea.devkit.inspections; + + +import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.LocalQuickFix; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleUtilCore; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.*; +import com.intellij.psi.search.GlobalSearchScope; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.idea.devkit.inspections.quickfix.CreateHtmlDescriptionFix; +import org.jetbrains.idea.devkit.util.PsiUtil; + +abstract class DescriptionNotFoundInspectionBase extends DevKitInspectionBase { + + @Override + public ProblemDescriptor[] checkClass(@NotNull PsiClass aClass, @NotNull InspectionManager manager, boolean isOnTheFly) { + final Project project = aClass.getProject(); + final PsiIdentifier nameIdentifier = aClass.getNameIdentifier(); + final Module module = ModuleUtilCore.findModuleForPsiElement(aClass); + + if (nameIdentifier == null || module == null || !PsiUtil.isInstantiable(aClass)) return null; + + final PsiClass base = JavaPsiFacade.getInstance(project).findClass(getClassName(), GlobalSearchScope.allScope(project)); + + if (base == null || !aClass.isInheritor(base, true)) return null; + + String descriptionDir = getDescriptionDirName(aClass); + if (StringUtil.isEmptyOrSpaces(descriptionDir)) { + return null; + } + + for (PsiDirectory description : getDescriptionsDirs(module)) { + PsiDirectory dir = description.findSubdirectory(descriptionDir); + if (dir == null) continue; + final PsiFile descr = dir.findFile("description.html"); + if (descr != null) { + if (!hasBeforeAndAfterTemplate(dir.getVirtualFile())) { + PsiElement problem = aClass.getNameIdentifier(); + ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(problem == null ? nameIdentifier : problem, + getHasNotBeforeAfterError(), + isOnTheFly, + ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false); + return new ProblemDescriptor[]{problemDescriptor}; + } + + return null; + } + } + + + final PsiElement problem = aClass.getNameIdentifier(); + final ProblemDescriptor problemDescriptor = manager + .createProblemDescriptor(problem == null ? nameIdentifier : problem, + getHasNotDescriptionError(), isOnTheFly, new LocalQuickFix[]{getFix(module, descriptionDir)}, + ProblemHighlightType.GENERIC_ERROR_OR_WARNING); + return new ProblemDescriptor[]{problemDescriptor}; + } + + protected CreateHtmlDescriptionFix getFix(Module module, String descriptionDir) { + return new CreateHtmlDescriptionFix(descriptionDir, module, true); + } + + @Nullable + private static String getDescriptionDirName(PsiClass aClass) { + String descriptionDir = ""; + PsiClass each = aClass; + while (each != null) { + String name = each.getName(); + if (StringUtil.isEmptyOrSpaces(name)) { + return null; + } + descriptionDir = name + descriptionDir; + each = each.getContainingClass(); + } + return descriptionDir; + } + + private static boolean hasBeforeAndAfterTemplate(@NotNull VirtualFile dir) { + boolean hasBefore = false; + boolean hasAfter = false; + + for (VirtualFile file : dir.getChildren()) { + String name = file.getName(); + if (name.endsWith(".template")) { + if (name.startsWith("before.")) { + hasBefore = true; + } + else if (name.startsWith("after.")) { + hasAfter = true; + } + } + } + + return hasBefore && hasAfter; + } + + @Override + public boolean isEnabledByDefault() { + return true; + } + + @NotNull + protected abstract String getClassName(); + + @NotNull + protected abstract String getHasNotDescriptionError(); + + @NotNull + protected abstract String getHasNotBeforeAfterError(); + + @NotNull + protected abstract PsiDirectory[] getDescriptionsDirs(@NotNull Module module); +} diff --git a/plugins/devkit/src/inspections/IntentionDescriptionNotFoundInspection.java b/plugins/devkit/src/inspections/IntentionDescriptionNotFoundInspection.java index e424c70f1106..bed14c0092a7 100644 --- a/plugins/devkit/src/inspections/IntentionDescriptionNotFoundInspection.java +++ b/plugins/devkit/src/inspections/IntentionDescriptionNotFoundInspection.java @@ -15,118 +15,57 @@ */ package org.jetbrains.idea.devkit.inspections; -import com.intellij.codeInspection.InspectionManager; -import com.intellij.codeInspection.LocalQuickFix; -import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtil; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.*; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiPackage; import com.intellij.psi.search.GlobalSearchScope; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.devkit.inspections.quickfix.CreateHtmlDescriptionFix; -import org.jetbrains.idea.devkit.util.PsiUtil; /** * @author Konstantin Bulenkov */ -public class IntentionDescriptionNotFoundInspection extends DevKitInspectionBase{ +public class IntentionDescriptionNotFoundInspection extends DescriptionNotFoundInspectionBase { @NonNls private static final String INTENTION = "com.intellij.codeInsight.intention.IntentionAction"; @NonNls private static final String INSPECTION_DESCRIPTIONS = "intentionDescriptions"; - @Override - public ProblemDescriptor[] checkClass(@NotNull PsiClass aClass, @NotNull InspectionManager manager, boolean isOnTheFly) { - final Project project = aClass.getProject(); - final PsiIdentifier nameIdentifier = aClass.getNameIdentifier(); - final Module module = ModuleUtil.findModuleForPsiElement(aClass); - - if (nameIdentifier == null || module == null || !PsiUtil.isInstantiable(aClass)) return null; - - final PsiClass base = JavaPsiFacade.getInstance(project).findClass(INTENTION, GlobalSearchScope.allScope(project)); - - if (base == null || ! aClass.isInheritor(base, true)) return null; - - String descriptionDir = getDescriptionDirName(aClass); - if (StringUtil.isEmptyOrSpaces(descriptionDir)) { - return null; - } - - for (PsiDirectory description : getIntentionDescriptionsDirs(module)) { - PsiDirectory dir = description.findSubdirectory(descriptionDir); - if (dir == null) continue; - final PsiFile descr = dir.findFile("description.html"); - if (descr != null) { - if (!hasBeforeAndAfterTemplate(dir.getVirtualFile())) { - PsiElement problem = aClass.getNameIdentifier(); - ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(problem == null ? nameIdentifier : problem, - "Intention must have 'before.*.template' and 'after.*.template' beside 'description.html'", - isOnTheFly, - ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false); - return new ProblemDescriptor[]{problemDescriptor}; - } - - return null; - } - } - - - final PsiElement problem = aClass.getNameIdentifier(); - final ProblemDescriptor problemDescriptor = manager - .createProblemDescriptor(problem == null ? nameIdentifier : problem, - "Intention does not have a description", isOnTheFly, new LocalQuickFix[]{new CreateHtmlDescriptionFix(descriptionDir, module, true)}, - ProblemHighlightType.GENERIC_ERROR_OR_WARNING); - return new ProblemDescriptor[]{problemDescriptor}; + protected CreateHtmlDescriptionFix getFix(Module module, String descriptionDir) { + return new CreateHtmlDescriptionFix(descriptionDir, module, true); } - @Nullable - private static String getDescriptionDirName(PsiClass aClass) { - String descriptionDir = ""; - PsiClass each = aClass; - while (each != null) { - String name = each.getName(); - if (StringUtil.isEmptyOrSpaces(name)) { - return null; - } - descriptionDir = name + descriptionDir; - each = each.getContainingClass(); - } - return descriptionDir; + @NotNull + protected String getClassName() { + return INTENTION; } - private static boolean hasBeforeAndAfterTemplate(@NotNull VirtualFile dir) { - boolean hasBefore = false; - boolean hasAfter = false; + @NotNull + protected String getHasNotDescriptionError() { + return "Intention does not have a description"; + } - for (VirtualFile file : dir.getChildren()) { - String name = file.getName(); - if (name.endsWith(".template")) { - if (name.startsWith("before.")) { - hasBefore = true; - } - else if (name.startsWith("after.")) { - hasAfter = true; - } - } - } - - return hasBefore && hasAfter; + @NotNull + protected String getHasNotBeforeAfterError() { + return "Intention must have 'before.*.template' and 'after.*.template' beside 'description.html'"; } public static PsiDirectory[] getIntentionDescriptionsDirs(Module module) { final PsiPackage aPackage = JavaPsiFacade.getInstance(module.getProject()).findPackage(INSPECTION_DESCRIPTIONS); if (aPackage != null) { return aPackage.getDirectories(GlobalSearchScope.moduleWithDependenciesScope(module)); - } else { + } + else { return PsiDirectory.EMPTY_ARRAY; } } + @NotNull + protected PsiDirectory[] getDescriptionsDirs(@NotNull Module module) { + return getIntentionDescriptionsDirs(module); + } + @Nls @NotNull public String getDisplayName() { @@ -137,9 +76,4 @@ public class IntentionDescriptionNotFoundInspection extends DevKitInspectionBase public String getShortName() { return "IntentionDescriptionNotFoundInspection"; } - - @Override - public boolean isEnabledByDefault() { - return true; - } } diff --git a/plugins/devkit/src/inspections/PostfixTemplateDescriptionNotFoundInspection.java b/plugins/devkit/src/inspections/PostfixTemplateDescriptionNotFoundInspection.java new file mode 100644 index 000000000000..b839c873df9b --- /dev/null +++ b/plugins/devkit/src/inspections/PostfixTemplateDescriptionNotFoundInspection.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2014 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 org.jetbrains.idea.devkit.inspections; + +import com.intellij.openapi.module.Module; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiPackage; +import com.intellij.psi.search.GlobalSearchScope; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.idea.devkit.DevKitBundle; +import org.jetbrains.idea.devkit.inspections.quickfix.CreateHtmlDescriptionFix; +import org.jetbrains.idea.devkit.inspections.quickfix.CreatePostfixTemplateHtmlDescriptionFix; + + +public class PostfixTemplateDescriptionNotFoundInspection extends DescriptionNotFoundInspectionBase { + + private static final String POSTFIX_TEMPLATES = "postfixTemplates"; + + @NotNull + @Override + protected PsiDirectory[] getDescriptionsDirs(@NotNull Module module) { + return getPostfixTemplateDirectories(module); + } + + @Override + protected CreateHtmlDescriptionFix getFix(Module module, String descriptionDir) { + return new CreatePostfixTemplateHtmlDescriptionFix(descriptionDir, module); + } + + @NotNull + public static PsiDirectory[] getPostfixTemplateDirectories(Module module) { + final PsiPackage aPackage = JavaPsiFacade.getInstance(module.getProject()).findPackage(POSTFIX_TEMPLATES); + if (aPackage != null) { + return aPackage.getDirectories(GlobalSearchScope.moduleWithDependenciesScope(module)); + } + else { + return PsiDirectory.EMPTY_ARRAY; + } + } + + @NotNull + @Override + protected String getHasNotDescriptionError() { + return "Postfix template does not have a description"; + } + + @NotNull + @Override + protected String getHasNotBeforeAfterError() { + return "Postfix template must have 'before.*.template' and 'after.*.template' beside 'description.html'"; + } + + @NotNull + @Override + protected String getClassName() { + return "com.intellij.codeInsight.template.postfix.templates.PostfixTemplate"; + } + + @Nls + @NotNull + @Override + public String getDisplayName() { + return DevKitBundle.message("inspections.component.postfix.template.not.found.description.name"); + } + + @NotNull + @Override + public String getShortName() { + return "PostfixTemplateDescriptionNotFound"; + } +} diff --git a/plugins/devkit/src/inspections/quickfix/CreateHtmlDescriptionFix.java b/plugins/devkit/src/inspections/quickfix/CreateHtmlDescriptionFix.java index e8f498dd28ea..6dcd46c99254 100644 --- a/plugins/devkit/src/inspections/quickfix/CreateHtmlDescriptionFix.java +++ b/plugins/devkit/src/inspections/quickfix/CreateHtmlDescriptionFix.java @@ -57,75 +57,15 @@ import java.util.List; * @author Konstantin Bulenkov */ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable { - private final String myFilename; - private final Module myModule; @NonNls private static final String TEMPLATE_NAME = "InspectionDescription.html"; + private final String myFilename; + protected final Module myModule; private final boolean isIntention; public CreateHtmlDescriptionFix(String filename, Module module, boolean isIntention) { myModule = module; this.isIntention = isIntention; - myFilename = isIntention ? filename : filename + ".html"; - } - - @NotNull - public String getName() { - return DevKitBundle.message("create.description.file"); - } - - @NotNull - public String getFamilyName() { - return "DevKit"; - } - - public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { - final PsiDirectory[] dirs; - if (isIntention) { - dirs = IntentionDescriptionNotFoundInspection.getIntentionDescriptionsDirs(myModule); - } - else { - dirs = InspectionDescriptionNotFoundInspection.getInspectionDescriptionsDirs(myModule); - } - final List virtualFiles = getPotentialRoots(myModule, dirs); - final VirtualFile[] roots = prepare(VfsUtil.toVirtualFileArray(virtualFiles)); - if (roots.length == 1) { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - public void run() { - createDescription(roots[0]); - } - }); - - } - else { - List options = new ArrayList(); - for (VirtualFile file : roots) { - String path = file.getPresentableUrl() + File.separator + getDescriptionFolderName() + File.separator + myFilename; - if (isIntention) { - path += File.separator + "description.html"; - } - options.add(path); - } - final JBList files = new JBList(ArrayUtil.toStringArray(options)); - files.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - final JBPopup popup = JBPopupFactory.getInstance() - .createListPopupBuilder(files) - .setTitle(DevKitBundle.message("select.target.location.of.description", myFilename)) - .setItemChoosenCallback(new Runnable() { - public void run() { - final int index = files.getSelectedIndex(); - if (0 <= index && index < roots.length) { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - public void run() { - createDescription(roots[index]); - } - }); - } - } - }).createPopup(); - final Editor editor = FileEditorManager.getInstance(myModule.getProject()).getSelectedTextEditor(); - if (editor == null) return; - popup.showInBestPositionFor(editor); - } + myFilename = getNormalizedFileName(filename); } private static List getPotentialRoots(Module module, PsiDirectory[] dirs) { @@ -147,6 +87,80 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable { } } + private String getNormalizedFileName(String filename) { + return isIntention ? filename : filename + ".html"; + } + + @NotNull + public String getName() { + return DevKitBundle.message("create.description.file"); + } + + @NotNull + public String getFamilyName() { + return "DevKit"; + } + + public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { + final PsiDirectory[] dirs; + dirs = getDirectories(); + final List virtualFiles = getPotentialRoots(myModule, dirs); + final VirtualFile[] roots = prepare(VfsUtil.toVirtualFileArray(virtualFiles)); + if (roots.length == 1) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + createDescription(roots[0]); + } + }); + } + else { + List options = new ArrayList(); + for (VirtualFile file : roots) { + String path = getPath(file); + options.add(path); + } + final JBList files = new JBList(ArrayUtil.toStringArray(options)); + files.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + final JBPopup popup = JBPopupFactory.getInstance() + .createListPopupBuilder(files) + .setTitle(DevKitBundle.message("select.target.location.of.description", myFilename)) + .setItemChoosenCallback(new Runnable() { + public void run() { + final int index = files.getSelectedIndex(); + if (0 <= index && index < roots.length) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + createDescription(roots[index]); + } + }); + } + } + }).createPopup(); + final Editor editor = FileEditorManager.getInstance(myModule.getProject()).getSelectedTextEditor(); + if (editor == null) return; + popup.showInBestPositionFor(editor); + } + } + + private String getPath(VirtualFile file) { + String path = file.getPresentableUrl() + File.separator + getDescriptionFolderName() + File.separator + myFilename; + if (isIntention) { + path += File.separator + "description.html"; + } + return path; + } + + protected PsiDirectory[] getDirectories() { + PsiDirectory[] dirs; + if (isIntention) { + dirs = IntentionDescriptionNotFoundInspection.getIntentionDescriptionsDirs(myModule); + } + else { + dirs = InspectionDescriptionNotFoundInspection.getInspectionDescriptionsDirs(myModule); + } + return dirs; + } + private void createDescription(VirtualFile root) { if (!root.isDirectory()) return; final PsiManager psiManager = PsiManager.getInstance(myModule.getProject()); @@ -169,7 +183,8 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable { } } final FileTemplate descrTemplate = FileTemplateManager.getInstance().getJ2eeTemplate(TEMPLATE_NAME); - final PsiElement template = FileTemplateUtil.createFromTemplate(descrTemplate, isIntention? "description.html" : myFilename, null, descrRoot); + final PsiElement template = + FileTemplateUtil.createFromTemplate(descrTemplate, getNewFileName(), null, descrRoot); if (template instanceof PsiFile) { final VirtualFile file = ((PsiFile)template).getVirtualFile(); if (file != null) { @@ -181,6 +196,10 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable { } } + private String getNewFileName() { + return isIntention ? "description.html" : myFilename; + } + public Icon getIcon(int flags) { return new LayeredIcon(AllIcons.FileTypes.Html, AllIcons.Actions.New); } @@ -205,7 +224,7 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable { return false; } - private String getDescriptionFolderName() { + protected String getDescriptionFolderName() { return isIntention ? "intentionDescriptions" : "inspectionDescriptions"; } } diff --git a/plugins/devkit/src/inspections/quickfix/CreatePostfixTemplateHtmlDescriptionFix.java b/plugins/devkit/src/inspections/quickfix/CreatePostfixTemplateHtmlDescriptionFix.java new file mode 100644 index 000000000000..1e1f9f779f31 --- /dev/null +++ b/plugins/devkit/src/inspections/quickfix/CreatePostfixTemplateHtmlDescriptionFix.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2014 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 org.jetbrains.idea.devkit.inspections.quickfix; + +import com.intellij.openapi.module.Module; +import com.intellij.psi.PsiDirectory; +import org.jetbrains.idea.devkit.inspections.PostfixTemplateDescriptionNotFoundInspection; + + +public class CreatePostfixTemplateHtmlDescriptionFix extends CreateHtmlDescriptionFix { + + public CreatePostfixTemplateHtmlDescriptionFix(String filename, Module module) { + super(filename, module, true); + } + + @Override + protected PsiDirectory[] getDirectories() { + return PostfixTemplateDescriptionNotFoundInspection.getPostfixTemplateDirectories(myModule); + } + + @Override + protected String getDescriptionFolderName() { + return "postfixTemplates"; + } +} diff --git a/plugins/devkit/testData/codeInsight/postfixTemplates/MyQuickFixTemplate.java b/plugins/devkit/testData/codeInsight/postfixTemplates/MyQuickFixTemplate.java new file mode 100644 index 000000000000..de936e4550f6 --- /dev/null +++ b/plugins/devkit/testData/codeInsight/postfixTemplates/MyQuickFixTemplate.java @@ -0,0 +1,6 @@ +import com.intellij.codeInsight.template.postfix.templates.PostfixTemplate; + +public class MyQuickFixTemplate extends PostfixTemplate { + + +} diff --git a/plugins/devkit/testData/codeInsight/postfixTemplates/MyTemplate.java b/plugins/devkit/testData/codeInsight/postfixTemplates/MyTemplate.java new file mode 100644 index 000000000000..e20fbb6be2df --- /dev/null +++ b/plugins/devkit/testData/codeInsight/postfixTemplates/MyTemplate.java @@ -0,0 +1,6 @@ +import com.intellij.codeInsight.template.postfix.templates.PostfixTemplate; + +public class MyTemplate extends PostfixTemplate { + + +} diff --git a/plugins/devkit/testData/codeInsight/postfixTemplates/MyTemplateWithDescription.java b/plugins/devkit/testData/codeInsight/postfixTemplates/MyTemplateWithDescription.java new file mode 100644 index 000000000000..02b9c8928fac --- /dev/null +++ b/plugins/devkit/testData/codeInsight/postfixTemplates/MyTemplateWithDescription.java @@ -0,0 +1,6 @@ +import com.intellij.codeInsight.template.postfix.templates.PostfixTemplate; + +public class MyTemplateWithDescription extends PostfixTemplate { + + +} diff --git a/plugins/devkit/testData/codeInsight/postfixTemplates/MyTemplateWithoutBeforeAfter.java b/plugins/devkit/testData/codeInsight/postfixTemplates/MyTemplateWithoutBeforeAfter.java new file mode 100644 index 000000000000..9e0ae10e8905 --- /dev/null +++ b/plugins/devkit/testData/codeInsight/postfixTemplates/MyTemplateWithoutBeforeAfter.java @@ -0,0 +1,6 @@ +import com.intellij.codeInsight.template.postfix.templates.PostfixTemplate; + +public class MyTemplateWithoutBeforeAfter extends PostfixTemplate{ + + + } diff --git a/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithDescription/after.java.template b/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithDescription/after.java.template new file mode 100644 index 000000000000..675fbd2b9292 --- /dev/null +++ b/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithDescription/after.java.template @@ -0,0 +1 @@ +test after diff --git a/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithDescription/before.java.template b/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithDescription/before.java.template new file mode 100644 index 000000000000..6fbfb79f92a9 --- /dev/null +++ b/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithDescription/before.java.template @@ -0,0 +1 @@ +test before diff --git a/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithDescription/description.html b/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithDescription/description.html new file mode 100644 index 000000000000..6b0d347bb279 --- /dev/null +++ b/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithDescription/description.html @@ -0,0 +1 @@ +test description diff --git a/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithoutBeforeAfter/description.html b/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithoutBeforeAfter/description.html new file mode 100644 index 000000000000..6b0d347bb279 --- /dev/null +++ b/plugins/devkit/testData/codeInsight/postfixTemplates/postfixTemplates/MyTemplateWithoutBeforeAfter/description.html @@ -0,0 +1 @@ +test description diff --git a/plugins/devkit/testSources/codeInsight/PostfixTemplateInspectionTest.java b/plugins/devkit/testSources/codeInsight/PostfixTemplateInspectionTest.java new file mode 100644 index 000000000000..6b655725985d --- /dev/null +++ b/plugins/devkit/testSources/codeInsight/PostfixTemplateInspectionTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2014 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 org.jetbrains.idea.devkit.codeInsight; + +import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase; +import org.jetbrains.idea.devkit.inspections.PostfixTemplateDescriptionNotFoundInspection; + +public class PostfixTemplateInspectionTest extends JavaCodeInsightFixtureTestCase { + + @Override + protected String getBasePath() { + return PluginPathManager.getPluginHomePathRelative("devkit") + "/testData/codeInsight/postfixTemplates"; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + myFixture.enableInspections(PostfixTemplateDescriptionNotFoundInspection.class); + myFixture.addClass("package com.intellij.codeInsight.template.postfix.templates; public class PostfixTemplate {}"); + } + + public void testHighlightingForDescription() { + myFixture.testHighlighting("MyTemplate.java"); + } + + public void testNoHighlighting() { + myFixture.copyDirectoryToProject("postfixTemplates", "postfixTemplates"); + myFixture.testHighlighting("MyTemplateWithDescription.java"); + } + + public void testHighlightingForBeforeAfter() { + myFixture.copyDirectoryToProject("postfixTemplates", "postfixTemplates"); + myFixture.testHighlighting("MyTemplateWithoutBeforeAfter.java"); + } + + public void testQuickFix() { + myFixture.configureByFiles("MyQuickFixTemplate.java"); + IntentionAction item = myFixture.findSingleIntention("Create Description File"); + myFixture.launchAction(item); + + VirtualFile path = myFixture.findFileInTempDir("postfixTemplates/MyQuickFixTemplate/description.html"); + assertNotNull(path); + assertTrue(path.exists()); + } +}