IDEA-335326 Support JetBrains annotations @Async.Schedule and @Async.Execute in kotlin

GitOrigin-RevId: 0c49fa85b59a24e58c1315ed0a5376b82a8adfd5
This commit is contained in:
Egor Ushakov
2024-10-11 18:13:28 +00:00
committed by intellij-monorepo-bot
parent 2d2263626c
commit 4855ba7c77
2 changed files with 20 additions and 21 deletions
@@ -30,7 +30,9 @@ import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileWrapper;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifierListOwner;
import com.intellij.psi.PsiParameter;
import com.intellij.serviceContainer.AlreadyDisposedException;
import com.intellij.ui.*;
import com.intellij.ui.table.JBTable;
@@ -484,7 +486,8 @@ public final class CaptureConfigurable implements SearchableConfigurable, NoScro
try {
getAsyncAnnotations(debuggerProjectSettings, capture)
.forEach(annotationName -> NodeRendererSettings.visitAnnotatedElements(annotationName, project,
(e, annotation) -> consumer.accept(capture, e, annotation)));
(e, annotation) -> consumer.accept(capture, e, annotation),
PsiMethod.class, PsiParameter.class));
}
catch (IndexNotReadyException | ProcessCanceledException | AlreadyDisposedException ignore) {
}
@@ -1,6 +1,7 @@
// 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 com.intellij.debugger.settings;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.debugger.DebuggerContext;
import com.intellij.debugger.JavaDebuggerBundle;
import com.intellij.debugger.engine.DebugProcess;
@@ -35,8 +36,8 @@ import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.impl.java.stubs.index.JavaAnnotationIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.AnnotatedElementsSearch;
import com.intellij.util.EventDispatcher;
import com.intellij.util.IncorrectOperationException;
import com.intellij.xdebugger.frame.presentation.XValuePresentation;
@@ -50,7 +51,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;
@@ -279,7 +279,7 @@ public class NodeRendererSettings implements PersistentStateComponent<Element> {
renderer.setEnabled(true);
renderers.add(renderer);
}
});
}, PsiClass.class);
}
catch (IndexNotReadyException | ProcessCanceledException ignore) {
}
@@ -589,21 +589,17 @@ public class NodeRendererSettings implements PersistentStateComponent<Element> {
}
}
static void visitAnnotatedElements(String annotationFqn,
Project project,
BiConsumer<? super PsiModifierListOwner, ? super PsiAnnotation> consumer) {
Collection<PsiAnnotation> annotations =
ReadAction.compute(
() -> JavaAnnotationIndex.getInstance().getAnnotations(StringUtil.getShortName(annotationFqn), project, GlobalSearchScope.allScope(project)));
annotations.forEach(annotation -> ReadAction.run(() -> {
if (!annotation.isValid()) return;
PsiElement parent = annotation.getContext();
if (parent instanceof PsiModifierList) {
PsiElement owner = parent.getParent();
if (owner instanceof PsiModifierListOwner && annotationFqn.equals(annotation.getQualifiedName())) {
consumer.accept((PsiModifierListOwner)owner, annotation);
}
}
}));
static <T extends PsiModifierListOwner> void visitAnnotatedElements(String annotationFqn,
Project project,
BiConsumer<? super PsiModifierListOwner, ? super PsiAnnotation> consumer,
Class<? extends T> @NotNull ... types) {
ReadAction.run(() -> {
PsiClass annotationClass = JavaPsiFacade.getInstance(project).findClass(annotationFqn, GlobalSearchScope.allScope(project));
if (annotationClass == null) return;
AnnotatedElementsSearch.searchElements(annotationClass, GlobalSearchScope.allScope(project), types)
.forEach((PsiModifierListOwner owner) -> {
consumer.accept(owner, AnnotationUtil.findAnnotation(owner, annotationFqn));
});
});
}
}