Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.errorprone.dataflow;

import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.auto.value.AutoValue;
Expand Down Expand Up @@ -73,55 +72,49 @@ public interface Result<
private static final LoadingCache<AnalysisParams, Analysis<?, ?, ?>> analysisCache =
Caffeine.newBuilder()
.build(
new CacheLoader<AnalysisParams, Analysis<?, ?, ?>>() {
@Override
public Analysis<?, ?, ?> load(AnalysisParams key) {
ControlFlowGraph cfg = key.cfg();
ForwardTransferFunction<?, ?> transfer = key.transferFunction();
(AnalysisParams key) -> {
ControlFlowGraph cfg = key.cfg();
ForwardTransferFunction<?, ?> transfer = key.transferFunction();

@SuppressWarnings({"unchecked", "rawtypes"})
Analysis<?, ?, ?> analysis = new ForwardAnalysisImpl(transfer);
analysis.performAnalysis(cfg);
return analysis;
}
@SuppressWarnings({"unchecked", "rawtypes"})
Analysis<?, ?, ?> analysis = new ForwardAnalysisImpl(transfer);
analysis.performAnalysis(cfg);
return analysis;
});

private static final LoadingCache<CfgParams, ControlFlowGraph> cfgCache =
Caffeine.newBuilder()
.maximumSize(1)
.build(
new CacheLoader<CfgParams, ControlFlowGraph>() {
@Override
public ControlFlowGraph load(CfgParams key) {
TreePath methodPath = key.methodPath();
UnderlyingAST ast;
ClassTree classTree = null;
MethodTree methodTree = null;
for (Tree parent : methodPath) {
if (parent instanceof MethodTree m) {
methodTree = m;
}
if (parent instanceof ClassTree c) {
classTree = c;
break;
}
(CfgParams key) -> {
TreePath methodPath = key.methodPath();
UnderlyingAST ast;
ClassTree classTree = null;
MethodTree methodTree = null;
for (Tree parent : methodPath) {
if (parent instanceof MethodTree m) {
methodTree = m;
}
if (methodPath.getLeaf() instanceof LambdaExpressionTree lambdaExpressionTree) {
ast = new UnderlyingAST.CFGLambda(lambdaExpressionTree, classTree, methodTree);
} else if (methodPath.getLeaf() instanceof MethodTree mt) {
methodTree = mt;
ast = new UnderlyingAST.CFGMethod(methodTree, classTree);
} else {
// must be an initializer per findEnclosingMethodOrLambdaOrInitializer
ast = new UnderlyingAST.CFGStatement(methodPath.getLeaf(), classTree);
if (parent instanceof ClassTree c) {
classTree = c;
break;
}
ProcessingEnvironment env = key.environment();

analysisCache.invalidateAll();
CompilationUnitTree root = methodPath.getCompilationUnit();
// TODO(b/158869538): replace with faster build(bodyPath, env, ast, false, false);
return CFGBuilder.build(root, ast, false, false, env);
}
if (methodPath.getLeaf() instanceof LambdaExpressionTree lambdaExpressionTree) {
ast = new UnderlyingAST.CFGLambda(lambdaExpressionTree, classTree, methodTree);
} else if (methodPath.getLeaf() instanceof MethodTree mt) {
methodTree = mt;
ast = new UnderlyingAST.CFGMethod(methodTree, classTree);
} else {
// must be an initializer per findEnclosingMethodOrLambdaOrInitializer
ast = new UnderlyingAST.CFGStatement(methodPath.getLeaf(), classTree);
}
ProcessingEnvironment env = key.environment();

analysisCache.invalidateAll();
CompilationUnitTree root = methodPath.getCompilationUnit();
// TODO(b/158869538): replace with faster build(bodyPath, env, ast, false, false);
return CFGBuilder.build(root, ast, false, false, env);
});

private static @Nullable TreePath findEnclosingMethodOrLambdaOrInitializer(TreePath path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static com.google.common.base.Preconditions.checkArgument;

import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -78,14 +77,11 @@ public class NullnessQualifierInference extends TreeScanner<Void, Void> {
Caffeine.newBuilder()
.maximumSize(1)
.build(
new CacheLoader<Tree, InferredNullability>() {
@Override
public InferredNullability load(Tree methodOrInitializer) {
NullnessQualifierInference inferenceEngine =
new NullnessQualifierInference(methodOrInitializer);
inferenceEngine.scan(methodOrInitializer, null);
return new InferredNullability(inferenceEngine.qualifierConstraints);
}
(Tree methodOrInitializer) -> {
NullnessQualifierInference inferenceEngine =
new NullnessQualifierInference(methodOrInitializer);
inferenceEngine.scan(methodOrInitializer, null);
return new InferredNullability(inferenceEngine.qualifierConstraints);
});

public static InferredNullability getInferredNullability(Tree methodOrInitializerOrLambda) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,31 +220,28 @@ private static boolean hasJUnitAttr(MethodSymbol methodSym) {
* expects tests to be annotated with @Test.
*/
public static Matcher<ExpressionTree> isJUnit4TestRunnerOfType(Iterable<String> runnerTypes) {
return new Matcher<ExpressionTree>() {
@Override
public boolean matches(ExpressionTree t, VisitorState state) {
Type type = ASTHelpers.getType(t);
// Expect a class type.
if (!(type instanceof ClassType)) {
return false;
}
// Expect one type argument, the type of the JUnit class runner to use.
com.sun.tools.javac.util.List<Type> typeArgs = type.getTypeArguments();
if (typeArgs.size() != 1) {
return false;
return (ExpressionTree t, VisitorState state) -> {
Type type = ASTHelpers.getType(t);
// Expect a class type.
if (!(type instanceof ClassType)) {
return false;
}
// Expect one type argument, the type of the JUnit class runner to use.
com.sun.tools.javac.util.List<Type> typeArgs = type.getTypeArguments();
if (typeArgs.size() != 1) {
return false;
}
Type runnerType = getOnlyElement(typeArgs);
for (String testRunner : runnerTypes) {
Symbol parent = state.getSymbolFromString(testRunner);
if (parent == null) {
continue;
}
Type runnerType = getOnlyElement(typeArgs);
for (String testRunner : runnerTypes) {
Symbol parent = state.getSymbolFromString(testRunner);
if (parent == null) {
continue;
}
if (runnerType.tsym.isSubClass(parent, state.getTypes())) {
return true;
}
if (runnerType.tsym.isSubClass(parent, state.getTypes())) {
return true;
}
return false;
}
return false;
};
}

Expand Down
Loading
Loading