mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-CR-2295: [dynamic plugins] a common way to inspect plugins code only #IDEA-245855
(cherry picked from commit 60e9ca315b32757bad5bb1f1b8427140e098fc90) GitOrigin-RevId: 356d54b3fb5934e181e0db2b0b92009da3a32998
This commit is contained in:
committed by
intellij-monorepo-bot
parent
961c70558a
commit
4bd450284e
@@ -11,6 +11,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.devkit.module.PluginModuleType;
|
||||
import org.jetbrains.idea.devkit.util.PsiUtil;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Consider using {@link DevKitUastInspectionBase} instead.
|
||||
*
|
||||
@@ -24,29 +26,41 @@ public abstract class DevKitInspectionBase extends AbstractBaseJavaLocalInspecti
|
||||
return isAllowed(holder) ? buildInternalVisitor(holder, isOnTheFly) : PsiElementVisitor.EMPTY_VISITOR;
|
||||
}
|
||||
|
||||
static boolean isAllowed(@NotNull ProblemsHolder holder) {
|
||||
if (PsiUtil.isIdeaProject(holder.getProject())) {
|
||||
return true;
|
||||
}
|
||||
protected PsiElementVisitor buildInternalVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
|
||||
return super.buildVisitor(holder, isOnTheFly);
|
||||
}
|
||||
|
||||
static boolean isAllowed(@NotNull ProblemsHolder holder) {
|
||||
return isAllowed(holder, h -> true);
|
||||
}
|
||||
|
||||
static boolean isAllowedInPluginsOnly(@NotNull ProblemsHolder holder) {
|
||||
return isAllowed(holder, DevKitInspectionBase::isPluginFile);
|
||||
}
|
||||
|
||||
static boolean isAllowed(@NotNull ProblemsHolder holder,
|
||||
@NotNull Predicate<? super ProblemsHolder> predicate) {
|
||||
return ApplicationManager.getApplication().isUnitTestMode() /* always run in tests */ ||
|
||||
(PsiUtil.isIdeaProject(holder.getProject()) && predicate.test(holder)) ||
|
||||
isInPluginModule(holder);
|
||||
}
|
||||
|
||||
private static boolean isInPluginModule(@NotNull ProblemsHolder holder) {
|
||||
Module module = ModuleUtilCore.findModuleForPsiElement(holder.getFile());
|
||||
if (module == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PluginModuleType.isPluginModuleOrDependency(module)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PsiUtil.isPluginModule(module)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// always run in tests
|
||||
return ApplicationManager.getApplication().isUnitTestMode();
|
||||
return PluginModuleType.isPluginModuleOrDependency(module) ||
|
||||
PsiUtil.isPluginModule(module);
|
||||
}
|
||||
|
||||
protected PsiElementVisitor buildInternalVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
|
||||
return super.buildVisitor(holder, isOnTheFly);
|
||||
// TODO expand this check
|
||||
private static boolean isPluginFile(@NotNull ProblemsHolder holder) {
|
||||
return !holder
|
||||
.getFile()
|
||||
.getVirtualFile()
|
||||
.getPath()
|
||||
.contains("/platform/");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import com.intellij.psi.PsiElementVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.uast.UElement;
|
||||
|
||||
import static org.jetbrains.idea.devkit.inspections.DevKitInspectionBase.isAllowed;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
@@ -27,6 +25,10 @@ public abstract class DevKitUastInspectionBase extends AbstractBaseUastLocalInsp
|
||||
return isAllowed(holder) ? buildInternalVisitor(holder, isOnTheFly) : PsiElementVisitor.EMPTY_VISITOR;
|
||||
}
|
||||
|
||||
protected boolean isAllowed(@NotNull ProblemsHolder holder) {
|
||||
return DevKitInspectionBase.isAllowed(holder);
|
||||
}
|
||||
|
||||
protected PsiElementVisitor buildInternalVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
|
||||
return super.buildVisitor(holder, isOnTheFly);
|
||||
}
|
||||
|
||||
@@ -8,30 +8,23 @@ import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiClassType
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.uast.UastHintedVisitorAdapter.Companion.create
|
||||
import org.jetbrains.idea.devkit.util.PsiUtil
|
||||
import org.jetbrains.uast.UCallExpression
|
||||
import org.jetbrains.uast.visitor.AbstractUastNonRecursiveVisitor
|
||||
|
||||
class IncorrectParentDisposableInspection : DevKitUastInspectionBase(UCallExpression::class.java) {
|
||||
override fun buildInternalVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
|
||||
if (PsiUtil.isIdeaProject(holder.file.project) && isPlatformFile(holder.file)) {
|
||||
return PsiElementVisitor.EMPTY_VISITOR
|
||||
}
|
||||
|
||||
return create(holder.file.language, object : AbstractUastNonRecursiveVisitor() {
|
||||
override fun isAllowed(holder: ProblemsHolder): Boolean =
|
||||
DevKitInspectionBase.isAllowedInPluginsOnly(holder)
|
||||
|
||||
override fun buildInternalVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor =
|
||||
create(holder.file.language, object : AbstractUastNonRecursiveVisitor() {
|
||||
override fun visitCallExpression(node: UCallExpression): Boolean {
|
||||
checkCallExpression(node, holder)
|
||||
|
||||
return true
|
||||
}
|
||||
}, arrayOf(UCallExpression::class.java))
|
||||
}
|
||||
|
||||
private fun isPlatformFile(file: PsiFile): Boolean {
|
||||
return "/platform/" in file.virtualFile.path // TODO expand this check
|
||||
}
|
||||
|
||||
private val sdkLink = "(<a href=\"https://www.jetbrains.org/intellij/sdk/docs/basics/disposers.html#choosing-a-disposable-parent\">Choosing a Disposable Parent</a>)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user