mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
DevKit: simplify/remove dups in DescriptionNotFoundInspectionBase,
add tests
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DescriptionCheckerUtil {
|
||||
|
||||
public static PsiDirectory[] getDescriptionsDirs(Module module,
|
||||
DescriptionType descriptionType) {
|
||||
final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(module.getProject());
|
||||
final PsiPackage psiPackage = javaPsiFacade.findPackage(descriptionType.getDescriptionFolder());
|
||||
if (psiPackage != null) {
|
||||
return psiPackage.getDirectories(GlobalSearchScope.moduleWithDependenciesScope(module));
|
||||
}
|
||||
return PsiDirectory.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,17 @@ 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 {
|
||||
|
||||
private final DescriptionType myDescriptionType;
|
||||
|
||||
protected DescriptionNotFoundInspectionBase(DescriptionType descriptionType) {
|
||||
myDescriptionType = descriptionType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProblemDescriptor[] checkClass(@NotNull PsiClass aClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
final Project project = aClass.getProject();
|
||||
@@ -43,10 +48,9 @@ abstract class DescriptionNotFoundInspectionBase extends DevKitInspectionBase {
|
||||
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);
|
||||
String descriptionDir = DescriptionCheckerUtil.getDescriptionDirName(aClass);
|
||||
if (StringUtil.isEmptyOrSpaces(descriptionDir)) {
|
||||
return null;
|
||||
}
|
||||
@@ -79,22 +83,7 @@ abstract class DescriptionNotFoundInspectionBase extends DevKitInspectionBase {
|
||||
}
|
||||
|
||||
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;
|
||||
return new CreateHtmlDescriptionFix(descriptionDir, module, myDescriptionType);
|
||||
}
|
||||
|
||||
private static boolean hasBeforeAndAfterTemplate(@NotNull VirtualFile dir) {
|
||||
@@ -122,14 +111,18 @@ abstract class DescriptionNotFoundInspectionBase extends DevKitInspectionBase {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract String getClassName();
|
||||
protected String getClassName() {
|
||||
return myDescriptionType.getClassName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected PsiDirectory[] getDescriptionsDirs(@NotNull Module module) {
|
||||
return DescriptionCheckerUtil.getDescriptionsDirs(module, myDescriptionType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract String getHasNotDescriptionError();
|
||||
|
||||
@NotNull
|
||||
protected abstract String getHasNotBeforeAfterError();
|
||||
|
||||
@NotNull
|
||||
protected abstract PsiDirectory[] getDescriptionsDirs(@NotNull Module module);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.template.postfix.templates.PostfixTemplate;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
|
||||
public enum DescriptionType {
|
||||
|
||||
INTENTION(IntentionAction.class.getName(), "intentionDescriptions", true),
|
||||
INSPECTION(InspectionProfileEntry.class.getName(), "inspectionDescriptions", false),
|
||||
POSTFIX_TEMPLATES(PostfixTemplate.class.getName(), "postfixTemplates", true);
|
||||
|
||||
private final String myClassName;
|
||||
private final String myDescriptionFolder;
|
||||
private final boolean myFixedDescriptionFilename;
|
||||
|
||||
DescriptionType(String className,
|
||||
String descriptionFolder,
|
||||
boolean fixedDescriptionFilename) {
|
||||
myFixedDescriptionFilename = fixedDescriptionFilename;
|
||||
myClassName = className;
|
||||
myDescriptionFolder = descriptionFolder;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return myClassName;
|
||||
}
|
||||
|
||||
public String getDescriptionFolder() {
|
||||
return myDescriptionFolder;
|
||||
}
|
||||
|
||||
public boolean isFixedDescriptionFilename() {
|
||||
return myFixedDescriptionFilename;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.idea.devkit.inspections;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
@@ -34,14 +34,13 @@ import org.jetbrains.idea.devkit.util.PsiUtil;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class InspectionDescriptionNotFoundInspection extends DevKitInspectionBase{
|
||||
@NonNls static final String INSPECTION_PROFILE_ENTRY = InspectionProfileEntry.class.getName();
|
||||
@NonNls private static final String INSPECTION_DESCRIPTIONS = "inspectionDescriptions";
|
||||
@NonNls static final String INSPECTION_PROFILE_ENTRY = DescriptionType.INSPECTION.getClassName();
|
||||
|
||||
@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);
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(aClass);
|
||||
|
||||
if (nameIdentifier == null || module == null || !PsiUtil.isInstantiable(aClass)) return null;
|
||||
|
||||
@@ -57,7 +56,7 @@ public class InspectionDescriptionNotFoundInspection extends DevKitInspectionBas
|
||||
if (filename == null) return null;
|
||||
|
||||
|
||||
for (PsiDirectory description : getInspectionDescriptionsDirs(module)) {
|
||||
for (PsiDirectory description : DescriptionCheckerUtil.getDescriptionsDirs(module, DescriptionType.INSPECTION)) {
|
||||
final PsiFile file = description.findFile(filename + ".html");
|
||||
if (file == null) continue;
|
||||
final VirtualFile vf = file.getVirtualFile();
|
||||
@@ -71,7 +70,8 @@ public class InspectionDescriptionNotFoundInspection extends DevKitInspectionBas
|
||||
final PsiElement problem = getProblemElement(aClass, method);
|
||||
final ProblemDescriptor problemDescriptor = manager
|
||||
.createProblemDescriptor(problem == null ? nameIdentifier : problem,
|
||||
"Inspection does not have a description", isOnTheFly, new LocalQuickFix[]{new CreateHtmlDescriptionFix(filename, module, false)},
|
||||
"Inspection does not have a description", isOnTheFly,
|
||||
new LocalQuickFix[]{new CreateHtmlDescriptionFix(filename, module, DescriptionType.INSPECTION)},
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
|
||||
return new ProblemDescriptor[]{problemDescriptor};
|
||||
}
|
||||
@@ -104,15 +104,6 @@ public class InspectionDescriptionNotFoundInspection extends DevKitInspectionBas
|
||||
return isLastMethodDefinitionIn(methodName, classFQN, cls.getSuperClass());
|
||||
}
|
||||
|
||||
public static PsiDirectory[] getInspectionDescriptionsDirs(Module module) {
|
||||
final PsiPackage aPackage = JavaPsiFacade.getInstance(module.getProject()).findPackage(INSPECTION_DESCRIPTIONS);
|
||||
if (aPackage != null) {
|
||||
return aPackage.getDirectories(GlobalSearchScope.moduleWithDependenciesScope(module));
|
||||
} else {
|
||||
return PsiDirectory.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiMethod findNearestMethod(String name, @Nullable PsiClass cls) {
|
||||
if (cls == null) return null;
|
||||
|
||||
@@ -16,12 +16,7 @@
|
||||
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.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.devkit.inspections.quickfix.CreateHtmlDescriptionFix;
|
||||
|
||||
@@ -29,16 +24,13 @@ import org.jetbrains.idea.devkit.inspections.quickfix.CreateHtmlDescriptionFix;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class IntentionDescriptionNotFoundInspection extends DescriptionNotFoundInspectionBase {
|
||||
@NonNls private static final String INTENTION = "com.intellij.codeInsight.intention.IntentionAction";
|
||||
@NonNls private static final String INSPECTION_DESCRIPTIONS = "intentionDescriptions";
|
||||
|
||||
protected CreateHtmlDescriptionFix getFix(Module module, String descriptionDir) {
|
||||
return new CreateHtmlDescriptionFix(descriptionDir, module, true);
|
||||
public IntentionDescriptionNotFoundInspection() {
|
||||
super(DescriptionType.INTENTION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getClassName() {
|
||||
return INTENTION;
|
||||
protected CreateHtmlDescriptionFix getFix(Module module, String descriptionDir) {
|
||||
return new CreateHtmlDescriptionFix(descriptionDir, module, DescriptionType.INTENTION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -51,21 +43,6 @@ public class IntentionDescriptionNotFoundInspection extends DescriptionNotFoundI
|
||||
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 {
|
||||
return PsiDirectory.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected PsiDirectory[] getDescriptionsDirs(@NotNull Module module) {
|
||||
return getIntentionDescriptionsDirs(module);
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
|
||||
@@ -15,42 +15,15 @@
|
||||
*/
|
||||
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;
|
||||
}
|
||||
public PostfixTemplateDescriptionNotFoundInspection() {
|
||||
super(DescriptionType.POSTFIX_TEMPLATES);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -65,12 +38,6 @@ public class PostfixTemplateDescriptionNotFoundInspection extends DescriptionNot
|
||||
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
|
||||
|
||||
@@ -31,7 +31,7 @@ import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -43,8 +43,8 @@ import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.devkit.DevKitBundle;
|
||||
import org.jetbrains.idea.devkit.inspections.InspectionDescriptionNotFoundInspection;
|
||||
import org.jetbrains.idea.devkit.inspections.IntentionDescriptionNotFoundInspection;
|
||||
import org.jetbrains.idea.devkit.inspections.DescriptionCheckerUtil;
|
||||
import org.jetbrains.idea.devkit.inspections.DescriptionType;
|
||||
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
|
||||
import org.jetbrains.jps.model.java.JavaResourceRootType;
|
||||
|
||||
@@ -57,17 +57,24 @@ import java.util.List;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable {
|
||||
@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) {
|
||||
@NonNls
|
||||
private static final String TEMPLATE_NAME = "InspectionDescription.html";
|
||||
|
||||
private final String myFilename;
|
||||
private final Module myModule;
|
||||
private final DescriptionType myDescriptionType;
|
||||
|
||||
public CreateHtmlDescriptionFix(String filename, Module module, DescriptionType descriptionType) {
|
||||
myModule = module;
|
||||
this.isIntention = isIntention;
|
||||
myDescriptionType = descriptionType;
|
||||
myFilename = getNormalizedFileName(filename);
|
||||
}
|
||||
|
||||
private boolean isFixedDescriptionFilename() {
|
||||
return myDescriptionType.isFixedDescriptionFilename();
|
||||
}
|
||||
|
||||
private static List<VirtualFile> getPotentialRoots(Module module, PsiDirectory[] dirs) {
|
||||
if (dirs.length != 0) {
|
||||
final List<VirtualFile> result = new ArrayList<VirtualFile>();
|
||||
@@ -88,7 +95,7 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable {
|
||||
}
|
||||
|
||||
private String getNormalizedFileName(String filename) {
|
||||
return isIntention ? filename : filename + ".html";
|
||||
return myDescriptionType.isFixedDescriptionFilename() ? filename : filename + ".html";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -102,10 +109,9 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable {
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiDirectory[] dirs;
|
||||
dirs = getDirectories();
|
||||
final PsiDirectory[] dirs = getDirectories();
|
||||
final List<VirtualFile> virtualFiles = getPotentialRoots(myModule, dirs);
|
||||
final VirtualFile[] roots = prepare(VfsUtil.toVirtualFileArray(virtualFiles));
|
||||
final VirtualFile[] roots = prepare(VfsUtilCore.toVirtualFileArray(virtualFiles));
|
||||
if (roots.length == 1) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
@@ -144,21 +150,14 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable {
|
||||
|
||||
private String getPath(VirtualFile file) {
|
||||
String path = file.getPresentableUrl() + File.separator + getDescriptionFolderName() + File.separator + myFilename;
|
||||
if (isIntention) {
|
||||
if (isFixedDescriptionFilename()) {
|
||||
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 PsiDirectory[] getDirectories() {
|
||||
return DescriptionCheckerUtil.getDescriptionsDirs(myModule, myDescriptionType);
|
||||
}
|
||||
|
||||
private void createDescription(VirtualFile root) {
|
||||
@@ -176,7 +175,7 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable {
|
||||
|
||||
try {
|
||||
descrRoot = descrRoot == null ? psiRoot.createSubdirectory(getDescriptionFolderName()) : descrRoot;
|
||||
if (isIntention) {
|
||||
if (isFixedDescriptionFilename()) {
|
||||
PsiDirectory dir = descrRoot.findSubdirectory(myFilename);
|
||||
if (dir == null) {
|
||||
descrRoot = descrRoot.createSubdirectory(myFilename);
|
||||
@@ -197,7 +196,7 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable {
|
||||
}
|
||||
|
||||
private String getNewFileName() {
|
||||
return isIntention ? "description.html" : myFilename;
|
||||
return isFixedDescriptionFilename() ? "description.html" : myFilename;
|
||||
}
|
||||
|
||||
public Icon getIcon(int flags) {
|
||||
@@ -211,7 +210,7 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable {
|
||||
found.add(root);
|
||||
}
|
||||
}
|
||||
return found.size() > 0 ? VfsUtil.toVirtualFileArray(found) : roots;
|
||||
return found.size() > 0 ? VfsUtilCore.toVirtualFileArray(found) : roots;
|
||||
}
|
||||
|
||||
private boolean containsDescriptionDir(VirtualFile root) {
|
||||
@@ -224,7 +223,7 @@ public class CreateHtmlDescriptionFix implements LocalQuickFix, Iconable {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected String getDescriptionFolderName() {
|
||||
return isIntention ? "intentionDescriptions" : "inspectionDescriptions";
|
||||
private String getDescriptionFolderName() {
|
||||
return myDescriptionType.getDescriptionFolder();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
public class <warning descr="Intention does not have a description">MyIntentionAction</warning> implements com.intellij.codeInsight.intention.IntentionAction {}
|
||||
+1
@@ -0,0 +1 @@
|
||||
public class MyIntentionActionWithDescription implements com.intellij.codeInsight.intention.IntentionAction {}
|
||||
+1
@@ -0,0 +1 @@
|
||||
public class <warning descr="Intention must have 'before.*.template' and 'after.*.template' beside 'description.html'">MyIntentionActionWithoutBeforeAfter</warning> implements com.intellij.codeInsight.intention.IntentionAction {}
|
||||
+1
@@ -0,0 +1 @@
|
||||
public class My<caret>QuickFixIntentionAction implements com.intellij.codeInsight.intention.IntentionAction {}
|
||||
+1
@@ -0,0 +1 @@
|
||||
test after
|
||||
+1
@@ -0,0 +1 @@
|
||||
test before
|
||||
+1
@@ -0,0 +1 @@
|
||||
Correctly mapped.
|
||||
+1
@@ -0,0 +1 @@
|
||||
Correctly mapped.
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
|
||||
@TestDataPath("$CONTENT_ROOT/testData/inspections/intentionDescription")
|
||||
public class IntentionDescriptionNotFoundInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return PluginPathManager.getPluginHomePathRelative("devkit") + "/testData/inspections/intentionDescription";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(IntentionDescriptionNotFoundInspection.class);
|
||||
myFixture.addClass("package com.intellij.codeInsight.intention; public interface IntentionAction {}");
|
||||
}
|
||||
|
||||
public void testHighlightingForDescription() {
|
||||
myFixture.testHighlighting("MyIntentionAction.java");
|
||||
}
|
||||
|
||||
public void testNoHighlighting() {
|
||||
myFixture.copyDirectoryToProject("intentionDescriptions", "intentionDescriptions");
|
||||
myFixture.testHighlighting("MyIntentionActionWithDescription.java");
|
||||
}
|
||||
|
||||
public void testHighlightingForBeforeAfter() {
|
||||
myFixture.copyDirectoryToProject("intentionDescriptions", "intentionDescriptions");
|
||||
myFixture.testHighlighting("MyIntentionActionWithoutBeforeAfter.java");
|
||||
}
|
||||
|
||||
public void testQuickFix() {
|
||||
myFixture.configureByFile("MyQuickFixIntentionAction.java");
|
||||
IntentionAction item = myFixture.findSingleIntention("Create Description File");
|
||||
myFixture.launchAction(item);
|
||||
|
||||
VirtualFile path = myFixture.findFileInTempDir("intentionDescriptions/MyQuickFixIntentionAction/description.html");
|
||||
assertNotNull(path);
|
||||
assertTrue(path.exists());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user