mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[devkit] support description file features for ModCommand (IJPL-162811)
GitOrigin-RevId: fd94a5c490d3091ff6f10792ad6d459058b9bfba
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2895b31c70
commit
50bef321f5
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.idea.devkit.inspections;
|
||||
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
@@ -10,7 +10,10 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.devkit.inspections.quickfix.CreateHtmlDescriptionFix;
|
||||
@@ -36,9 +39,7 @@ abstract class DescriptionNotFoundInspectionBase extends DevKitUastInspectionBas
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(psiClass);
|
||||
if (nameIdentifier == null || module == null || !PsiUtil.isInstantiable(psiClass)) return null;
|
||||
|
||||
final PsiClass base = JavaPsiFacade.getInstance(manager.getProject()).findClass(myDescriptionType.getClassName(),
|
||||
psiClass.getResolveScope());
|
||||
if (base == null || !psiClass.isInheritor(base, true)) return null;
|
||||
if (!myDescriptionType.matches(psiClass)) return null;
|
||||
|
||||
if (skipIfNotRegistered(psiClass)) {
|
||||
return null;
|
||||
|
||||
@@ -1,44 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.idea.devkit.inspections;
|
||||
|
||||
import com.intellij.codeInsight.intention.CommonIntentionAction;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.template.postfix.templates.PostfixTemplate;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum DescriptionType {
|
||||
|
||||
INTENTION(IntentionAction.class.getName(), "intentionDescriptions", true),
|
||||
INSPECTION(InspectionProfileEntry.class.getName(), "inspectionDescriptions", false),
|
||||
POSTFIX_TEMPLATES(PostfixTemplate.class.getName(), "postfixTemplates", true);
|
||||
INTENTION(CommonIntentionAction.class.getName(), IntentionAction.class.getName(), "intentionDescriptions", true),
|
||||
INSPECTION(InspectionProfileEntry.class.getName(), null, "inspectionDescriptions", false),
|
||||
POSTFIX_TEMPLATES(PostfixTemplate.class.getName(), null, "postfixTemplates", true);
|
||||
|
||||
private final String myClassName;
|
||||
@Nullable private final String myFallbackClassName;
|
||||
private final String myDescriptionFolder;
|
||||
private final boolean myFixedDescriptionFilename;
|
||||
|
||||
DescriptionType(String className,
|
||||
@Nullable String fallbackClassName,
|
||||
String descriptionFolder,
|
||||
boolean fixedDescriptionFilename) {
|
||||
myFallbackClassName = fallbackClassName;
|
||||
myFixedDescriptionFilename = fixedDescriptionFilename;
|
||||
myClassName = className;
|
||||
myDescriptionFolder = descriptionFolder;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return myClassName;
|
||||
public boolean matches(PsiClass psiClass) {
|
||||
if (InheritanceUtil.isInheritor(psiClass, myClassName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return myFallbackClassName != null && InheritanceUtil.isInheritor(psiClass, myFallbackClassName);
|
||||
}
|
||||
|
||||
public String getDescriptionFolder() {
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.idea.devkit.inspections;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.util.InspectionMessage;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -13,7 +14,7 @@ import org.jetbrains.idea.devkit.DevKitBundle;
|
||||
@VisibleForTesting
|
||||
@ApiStatus.Internal
|
||||
public final class InspectionDescriptionNotFoundInspection extends DescriptionNotFoundInspectionBase {
|
||||
@NonNls private static final String INSPECTION_PROFILE_ENTRY = DescriptionType.INSPECTION.getClassName();
|
||||
@NonNls private static final String INSPECTION_PROFILE_ENTRY = InspectionProfileEntry.class.getName();
|
||||
|
||||
public InspectionDescriptionNotFoundInspection() {
|
||||
super(DescriptionType.INSPECTION);
|
||||
|
||||
+2
-3
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.idea.devkit.navigation;
|
||||
|
||||
import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo;
|
||||
@@ -9,7 +9,6 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.SortedList;
|
||||
@@ -64,7 +63,7 @@ final class DescriptionTypeRelatedItemLineMarkerProvider extends DevkitRelatedCl
|
||||
if (module == null) return;
|
||||
|
||||
for (DescriptionType type : DescriptionType.values()) {
|
||||
if (!InheritanceUtil.isInheritor(psiClass, type.getClassName())) {
|
||||
if (!type.matches(psiClass)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.idea.devkit.refactoring;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
@@ -12,7 +12,6 @@ import com.intellij.psi.ElementManipulators;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo;
|
||||
@@ -49,7 +48,7 @@ final class InspectionAutomaticRenamerFactory implements AutomaticRenamerFactory
|
||||
String inspectionClassName = inspectionClass.getName();
|
||||
return inspectionClassName != null &&
|
||||
inspectionClassName.endsWith(INSPECTION_CLASS_SUFFIX) &&
|
||||
InheritanceUtil.isInheritor(inspectionClass, DescriptionType.INSPECTION.getClassName()) &&
|
||||
DescriptionType.INSPECTION.matches(inspectionClass) &&
|
||||
!isGetShortNameMethodOverridden(inspectionClass);
|
||||
}
|
||||
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import com.intellij.modcommand.ActionContext;
|
||||
import com.intellij.modcommand.ModCommand;
|
||||
import com.intellij.modcommand.ModCommandAction;
|
||||
import com.intellij.modcommand.Presentation;
|
||||
|
||||
public class MyModCommandIntentionWithDescription implements ModCommandAction {
|
||||
@Override
|
||||
public Presentation getPresentation(ActionContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModCommand perform(ActionContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
Correctly mapped.
|
||||
+6
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.idea.devkit.inspections;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
@@ -51,6 +51,11 @@ public class IntentionDescriptionNotFoundInspectionTest extends JavaCodeInsightF
|
||||
myFixture.testHighlighting("MyIntentionActionWithDescription.java");
|
||||
}
|
||||
|
||||
public void testNoHighlightingModCommand() {
|
||||
myFixture.copyDirectoryToProject("intentionDescriptions", "intentionDescriptions");
|
||||
myFixture.testHighlighting("MyModCommandIntentionWithDescription.java");
|
||||
}
|
||||
|
||||
public void testHighlightingForBeforeAfter() {
|
||||
myFixture.copyDirectoryToProject("intentionDescriptions", "intentionDescriptions");
|
||||
myFixture.testHighlighting("MyIntentionActionWithoutBeforeAfter.java");
|
||||
|
||||
Reference in New Issue
Block a user