mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Make 2 flavors of parametrized cache: nullable and notnull
This commit is contained in:
@@ -843,7 +843,17 @@ public class PyUtil {
|
||||
});
|
||||
}
|
||||
|
||||
public static <T, P> T getParameterizedCachedValue(@NotNull PsiElement element, @Nullable P param, @NotNull NullableFunction<P, T> f) {
|
||||
@NotNull
|
||||
public static <T, P> T getParameterizedCachedValue(@NotNull PsiElement element, @Nullable P param, @NotNull NotNullFunction<P, T> f) {
|
||||
final T result = getNullableParameterizedCachedValue(element, param, f);
|
||||
assert result != null;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T, P> T getNullableParameterizedCachedValue(@NotNull PsiElement element,
|
||||
@Nullable P param,
|
||||
@NotNull NullableFunction<P, T> f) {
|
||||
final CachedValuesManager manager = CachedValuesManager.getManager(element.getProject());
|
||||
final Map<Optional<P>, Optional<T>> cache = CachedValuesManager.getCachedValue(element, manager.getKeyForClass(f.getClass()), () -> {
|
||||
// concurrent hash map is a null-hostile collection
|
||||
@@ -899,7 +909,7 @@ public class PyUtil {
|
||||
|
||||
/**
|
||||
* Returns the line comment that immediately precedes statement list of the given compound statement. Python parser ensures
|
||||
* that it follows the statement header, i.e. it's directly after the colon, not on its own line.
|
||||
* that it follows the statement header, i.e. it's directly after the colon, not on its own line.
|
||||
*/
|
||||
@Nullable
|
||||
public static PsiComment getCommentOnHeaderLine(@NotNull PyStatementListContainer container) {
|
||||
|
||||
@@ -79,7 +79,7 @@ public class PyClassImpl extends PyBaseElementImpl<PyClassStub> implements PyCla
|
||||
/**
|
||||
* Engine to create list of ancestors based on context
|
||||
*/
|
||||
private final class CachedAncestorsProvider implements NullableFunction<TypeEvalContext, List<PyClassLikeType>> {
|
||||
private final class CachedAncestorsProvider implements NotNullFunction<TypeEvalContext, List<PyClassLikeType>> {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<PyClassLikeType> fun(@NotNull TypeEvalContext context) {
|
||||
|
||||
@@ -115,7 +115,7 @@ public class QualifiedNameFinder {
|
||||
*/
|
||||
@Nullable
|
||||
public static QualifiedName findCanonicalImportPath(@NotNull PsiElement symbol, @Nullable PsiElement foothold) {
|
||||
return PyUtil.getParameterizedCachedValue(symbol, Couple.of(symbol, foothold), QualifiedNameFinder::doFindCanonicalImportPath);
|
||||
return PyUtil.getNullableParameterizedCachedValue(symbol, Couple.of(symbol, foothold), QualifiedNameFinder::doFindCanonicalImportPath);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user