mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[jam] Reflection free JAM instantiation
GitOrigin-RevId: 71812333e2a796ebaa387ad6878576f16038658a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1ace7ea179
commit
5ad829802c
@@ -4,12 +4,13 @@ package com.intellij.semantic;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
@@ -20,10 +21,10 @@ public interface SemRegistrar {
|
||||
@SuppressWarnings("unchecked")
|
||||
default <T extends SemElement, V extends PsiElement> void registerSemElementProvider(SemKey<T> key,
|
||||
ElementPattern<? extends V> place,
|
||||
NullableFunction<? super V, ? extends T> provider) {
|
||||
Function<? super V, ? extends @Nullable T> provider) {
|
||||
registerSemProvider(key, (element, context) -> {
|
||||
if (place.accepts(element, context)) {
|
||||
return Collections.singleton(provider.fun((V)element));
|
||||
return Collections.singleton(provider.apply((V)element));
|
||||
}
|
||||
return emptyList();
|
||||
});
|
||||
@@ -32,10 +33,10 @@ public interface SemRegistrar {
|
||||
@SuppressWarnings("unchecked")
|
||||
default <T extends SemElement, V extends PsiElement> void registerRepeatableSemElementProvider(SemKey<T> key,
|
||||
ElementPattern<? extends V> place,
|
||||
NullableFunction<? super V, ? extends Collection<T>> provider) {
|
||||
Function<? super V, ? extends @Nullable Collection<T>> provider) {
|
||||
registerSemProvider(key, (element, context) -> {
|
||||
if (place.accepts(element, context)) {
|
||||
return provider.fun((V)element);
|
||||
return provider.apply((V)element);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -43,7 +43,7 @@ public final class SemServiceImpl extends SemService implements Disposable {
|
||||
Result.create(createSemCache(), PsiModificationTracker.MODIFICATION_COUNT);
|
||||
|
||||
private final Object lock = ObjectUtils.sentinel(getClass().getName());
|
||||
private volatile MultiMap<SemKey<?>, BiFunction<PsiElement, ProcessingContext, Collection<? extends SemElement>>> producers;
|
||||
private volatile MultiMap<SemKey<?>, BiFunction<? super PsiElement, ? super ProcessingContext, ? extends Collection<? extends SemElement>>> producers;
|
||||
private final Project project;
|
||||
private final CachedValuesManager myCVManager;
|
||||
|
||||
@@ -67,8 +67,8 @@ public final class SemServiceImpl extends SemService implements Disposable {
|
||||
});
|
||||
}
|
||||
|
||||
private MultiMap<SemKey<?>, BiFunction<PsiElement, ProcessingContext, Collection<? extends SemElement>>> collectProducers() {
|
||||
MultiMap<SemKey<?>, BiFunction<PsiElement, ProcessingContext, Collection<? extends SemElement>>> map = new MultiMap<>();
|
||||
private MultiMap<SemKey<?>, BiFunction<? super PsiElement, ? super ProcessingContext, ? extends Collection<? extends SemElement>>> collectProducers() {
|
||||
var map = new MultiMap<SemKey<?>, BiFunction<? super PsiElement, ? super ProcessingContext, ? extends Collection<? extends SemElement>>>();
|
||||
|
||||
SemRegistrar registrar = new SemRegistrar() {
|
||||
@Override
|
||||
@@ -76,7 +76,7 @@ public final class SemServiceImpl extends SemService implements Disposable {
|
||||
SemKey<T> key,
|
||||
BiFunction<? super PsiElement, ? super ProcessingContext, ? extends Collection<T>> provider
|
||||
) {
|
||||
map.putValue(key, provider::apply);
|
||||
map.putValue(key, provider);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -114,7 +114,7 @@ public final class SemServiceImpl extends SemService implements Disposable {
|
||||
@SuppressWarnings("unchecked")
|
||||
private @NotNull <T extends SemElement> List<T> createSemElements(@NotNull SemKey<T> key, @NotNull PsiElement psi,
|
||||
IntObjectMap<List<SemElement>> chunk) {
|
||||
MultiMap<SemKey<?>, BiFunction<PsiElement, ProcessingContext, Collection<? extends SemElement>>> currentProducers = ensureInitialized();
|
||||
var currentProducers = ensureInitialized();
|
||||
|
||||
RecursionGuard.StackStamp stamp = RecursionManager.markStack();
|
||||
|
||||
@@ -146,8 +146,8 @@ public final class SemServiceImpl extends SemService implements Disposable {
|
||||
return List.copyOf(result);
|
||||
}
|
||||
|
||||
private MultiMap<SemKey<?>, BiFunction<PsiElement, ProcessingContext, Collection<? extends SemElement>>> ensureInitialized() {
|
||||
MultiMap<SemKey<?>, BiFunction<PsiElement, ProcessingContext, Collection<? extends SemElement>>> current = producers;
|
||||
private MultiMap<SemKey<?>, BiFunction<? super PsiElement, ? super ProcessingContext, ? extends Collection<? extends SemElement>>> ensureInitialized() {
|
||||
var current = producers;
|
||||
if (current != null) {
|
||||
return current;
|
||||
}
|
||||
@@ -158,20 +158,20 @@ public final class SemServiceImpl extends SemService implements Disposable {
|
||||
return current;
|
||||
}
|
||||
|
||||
MultiMap<SemKey<?>, BiFunction<PsiElement, ProcessingContext, Collection<? extends SemElement>>> newProducers = collectProducers();
|
||||
var newProducers = collectProducers();
|
||||
producers = newProducers;
|
||||
return newProducers;
|
||||
}
|
||||
}
|
||||
|
||||
private static @NotNull List<SemElement> createSemElements(
|
||||
MultiMap<SemKey<?>, BiFunction<PsiElement, ProcessingContext, Collection<? extends SemElement>>> producers,
|
||||
MultiMap<SemKey<?>, BiFunction<? super PsiElement, ? super ProcessingContext, ? extends Collection<? extends SemElement>>> producers,
|
||||
SemKey<?> key, PsiElement psi, ProcessingContext processingContext
|
||||
) {
|
||||
List<SemElement> result = null;
|
||||
Collection<BiFunction<PsiElement, ProcessingContext, Collection<? extends SemElement>>> functions = producers.get(key);
|
||||
Collection<BiFunction<? super PsiElement, ? super ProcessingContext, ? extends Collection<? extends SemElement>>> functions = producers.get(key);
|
||||
if (!functions.isEmpty()) {
|
||||
for (BiFunction<PsiElement, ProcessingContext, Collection<? extends SemElement>> producer : functions) {
|
||||
for (var producer : functions) {
|
||||
Collection<? extends SemElement> elements = producer.apply(psi, processingContext);
|
||||
if (elements != null && !elements.isEmpty()) {
|
||||
if (result == null) result = new SmartList<>();
|
||||
|
||||
Reference in New Issue
Block a user