com.intellij.util.QueryFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of symbol-processing-aa Show documentation
Show all versions of symbol-processing-aa Show documentation
KSP implementation on Kotlin Analysis API
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class QueryFactory {
private final List> myExecutors = ContainerUtil.createLockFreeCopyOnWriteList();
public void registerExecutor(@NotNull QueryExecutor executor) {
myExecutors.add(executor);
}
public void unregisterExecutor(@NotNull QueryExecutor executor) {
myExecutors.remove(executor);
}
/**
* @return query to perform the search. @param parameters of the search
*/
@NotNull
public final Query createQuery(@NotNull Parameters parameters) {
return new ExecutorsQuery<>(parameters, getExecutors());
}
@NotNull
protected List> getExecutors() {
return myExecutors;
}
public boolean hasAnyExecutors() {
return !getExecutors().isEmpty();
}
/**
* @param parameters of the search
* @return query to perform the search. Obtained results are automatically filtered wrt. equals() relation.
*/
@NotNull
public final Query createUniqueResultsQuery(@NotNull Parameters parameters) {
return new UniqueResultsQuery(createQuery(parameters));
}
/**
* @param parameters of the search
* @param mapper function that maps results to their mapping counterparts.
* @return query to perform the search. Obtained results are mapped to whatever objects that are automatically filtered wrt. equals()
* relation. Storing mapped objects instead of original elements may be wise wrt to memory consumption.
*/
public final @NotNull Query createUniqueResultsQuery(@NotNull Parameters parameters, @NotNull Function mapper) {
return new UniqueResultsQuery<>(createQuery(parameters), mapper);
}
}