Skip to content

Commit

Permalink
Apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
Ao-senXiong committed Apr 24, 2024
1 parent 8ad0c5a commit 93635f8
Showing 7 changed files with 56 additions and 38 deletions.
4 changes: 3 additions & 1 deletion src/checkers/inference/InferenceLauncher.java
Original file line number Diff line number Diff line change
@@ -223,7 +223,9 @@ public void infer() {

Mode mode = Mode.valueOf(InferenceOptions.mode);
if (InferenceOptions.makeDefaultsExplicit
&& (mode == Mode.ROUNDTRIP || mode == Mode.ROUNDTRIP_TYPECHECK || mode == Mode.INFER)) {
&& (mode == Mode.ROUNDTRIP
|| mode == Mode.ROUNDTRIP_TYPECHECK
|| mode == Mode.INFER)) {
// Two conditions have to be met to make defaults explicit:
// 1. the command-line flag `makeDefaultsExplicit` is provided
// 2. the inference solution will be written back to the source code (roundtrip `mode`)
1 change: 0 additions & 1 deletion src/checkers/inference/InferenceValidator.java
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
import org.checkerframework.framework.type.AnnotatedTypeMirror;

import javax.lang.model.element.AnnotationMirror;
import java.util.List;

/** A visitor to validate the types in a tree. */
public class InferenceValidator extends BaseTypeValidator {
52 changes: 29 additions & 23 deletions src/checkers/inference/InferenceVisitor.java
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
import org.checkerframework.framework.type.AnnotatedTypeParameterBounds;
import org.checkerframework.framework.util.AnnotatedTypes;
import org.checkerframework.javacutil.*;
import org.checkerframework.javacutil.TreeUtils;
import org.plumelib.util.ArraysPlume;

import java.lang.annotation.Annotation;
@@ -52,17 +53,6 @@
import checkers.inference.qual.VarAnnot;
import checkers.inference.util.InferenceUtil;

import com.sun.source.tree.CatchTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.ThrowTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import com.sun.source.tree.VariableTree;

import org.checkerframework.javacutil.TreeUtils;
import org.plumelib.util.ArraysPlume;


/**
* InferenceVisitor visits trees in each compilation unit both in typecheck/inference mode. In
* typecheck mode, it functions nearly identically to BaseTypeVisitor, i.e. it enforces common
@@ -91,7 +81,7 @@ public class InferenceVisitor<
protected final boolean infer;

protected final Checker realChecker;
/*
/*
* Map from type-use location to a list of qualifiers which cannot be used on that location.
* This is used to create the inequality constraint in inference.
*/
@@ -318,8 +308,12 @@ public void mainIsNoneOf(
}
}

private void addDeepPreferenceImpl(AnnotatedTypeMirror ty, AnnotationMirror goal, int weight,
java.util.List<AnnotatedTypeMirror> visited, Tree node) {
private void addDeepPreferenceImpl(
AnnotatedTypeMirror ty,
AnnotationMirror goal,
int weight,
java.util.List<AnnotatedTypeMirror> visited,
Tree node) {
if (infer) {
if (visited.contains(ty)) {
return;
@@ -330,7 +324,8 @@ private void addDeepPreferenceImpl(AnnotatedTypeMirror ty, AnnotationMirror goal
Slot el = slotManager.getSlot(ty);

if (el == null) {
logger.warning("InferenceVisitor::addDeepPreferenceImpl: no annotation in type: " + ty);
logger.warning(
"InferenceVisitor::addDeepPreferenceImpl: no annotation in type: " + ty);
} else {
addPreference(ty, goal, weight);
}
@@ -352,7 +347,8 @@ private void addDeepPreferenceImpl(AnnotatedTypeMirror ty, AnnotationMirror goal
// Else, do nothing
}

public void addDeepPreference(AnnotatedTypeMirror ty, AnnotationMirror goal, int weight, Tree node) {
public void addDeepPreference(
AnnotatedTypeMirror ty, AnnotationMirror goal, int weight, Tree node) {
addDeepPreferenceImpl(ty, goal, weight, new LinkedList<>(), node);
}

@@ -1035,10 +1031,12 @@ protected void checkConstructorResult(
protected Map<TypeUseLocation, AnnotationMirrorSet> createMapForIllegalQuals() {
Map<TypeUseLocation, AnnotationMirrorSet> locationToIllegalQuals = new HashMap<>();
// First, init each type-use location to contain all type qualifiers.
Set<Class<? extends Annotation>> supportQualifiers = atypeFactory.getSupportedTypeQualifiers();
Set<Class<? extends Annotation>> supportQualifiers =
atypeFactory.getSupportedTypeQualifiers();
AnnotationMirrorSet supportedAnnos = new AnnotationMirrorSet();
for (Class<? extends Annotation> qual: supportQualifiers) {
supportedAnnos.add(new AnnotationBuilder(atypeFactory.getProcessingEnv(), qual).build());
for (Class<? extends Annotation> qual : supportQualifiers) {
supportedAnnos.add(
new AnnotationBuilder(atypeFactory.getProcessingEnv(), qual).build());
}
for (TypeUseLocation location : TypeUseLocation.values()) {
locationToIllegalQuals.put(location, new AnnotationMirrorSet(supportedAnnos));
@@ -1053,20 +1051,26 @@ protected Map<TypeUseLocation, AnnotationMirrorSet> createMapForIllegalQuals() {
if (tls == null) {
for (TypeUseLocation location : TypeUseLocation.values()) {
AnnotationMirrorSet amSet = locationToIllegalQuals.get(location);
amSet.remove(AnnotationUtils.getAnnotationByName(supportedAnnos, qual.getCanonicalName()));
amSet.remove(
AnnotationUtils.getAnnotationByName(
supportedAnnos, qual.getCanonicalName()));
}
continue;
}
for (TypeUseLocation location : tls.value()) {
if (location == TypeUseLocation.ALL) {
for (TypeUseLocation val : TypeUseLocation.values()) {
AnnotationMirrorSet amSet = locationToIllegalQuals.get(val);
amSet.remove(AnnotationUtils.getAnnotationByName(supportedAnnos, qual.getCanonicalName()));
amSet.remove(
AnnotationUtils.getAnnotationByName(
supportedAnnos, qual.getCanonicalName()));
}
break;
}
AnnotationMirrorSet amSet = locationToIllegalQuals.get(location);
amSet.remove(AnnotationUtils.getAnnotationByName(supportedAnnos, qual.getCanonicalName()));
amSet.remove(
AnnotationUtils.getAnnotationByName(
supportedAnnos, qual.getCanonicalName()));
}
}
return locationToIllegalQuals;
@@ -1108,7 +1112,9 @@ protected void validateVariablesTargetLocation(Tree tree, AnnotatedTypeMirror ty
break;
case ENUM_CONSTANT:
location = TypeUseLocation.CONSTRUCTOR_RESULT;
// TODO: Add ? mainIsNoneOf(type, targetLocationToAnno.get(TypeUseLocation.FIELD).toArray(mirrors), "type.invalid.annotations.on.location", tree);
// TODO: Add ? mainIsNoneOf(type,
// targetLocationToAnno.get(TypeUseLocation.FIELD).toArray(mirrors),
// "type.invalid.annotations.on.location", tree);
break;
default:
throw new BugInCF("Location not matched");
6 changes: 3 additions & 3 deletions src/checkers/inference/util/SlotDefaultTypeResolver.java
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
import com.sun.source.tree.AnnotatedTypeTree;
import com.sun.source.tree.ArrayTypeTree;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.NewClassTree;
import com.sun.source.tree.ParameterizedTypeTree;
import com.sun.source.tree.PrimitiveTypeTree;
@@ -190,10 +189,11 @@ public Void visitNewClass(NewClassTree tree, Void unused) {
if (InferenceUtil.isAnonymousClass(tree)) {
// don't associate the identifier with the defaultType if it's an anonymousclass
// should associate the identifier with the direct super type of the defaultType.
// choose the last one of the directSupertypes, which is either the direct super class
// choose the last one of the directSupertypes, which is either the direct super
// class
// or implemented interface
List<? extends AnnotatedTypeMirror> superTypes = defaultType.directSupertypes();
defaultTypes.put(tree.getIdentifier(), superTypes.get(superTypes.size()-1));
defaultTypes.put(tree.getIdentifier(), superTypes.get(superTypes.size() - 1));
} else {
defaultTypes.put(tree.getIdentifier(), defaultType);
}
21 changes: 16 additions & 5 deletions tests/checkers/inference/test/CFInferenceTest.java
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public boolean useHacks() {
public boolean makeDefaultsExplicit() {
return false;
}

public abstract IPair<String, List<String>> getSolverNameAndOptions();

public List<String> getAdditionalInferenceOptions() {
@@ -59,10 +59,21 @@ public void run() {

final File testDataDir = new File("testdata");

InferenceTestConfiguration config = InferenceTestConfigurationBuilder.buildDefaultConfiguration(testDir,
testFile, testDataDir, checker, checkerOptions, getAdditionalInferenceOptions(), solverArgs.first,
solverArgs.second, useHacks(), makeDefaultsExplicit(), shouldEmitDebugInfo, getPathToAfuScripts(),
getPathToInferenceScript());
InferenceTestConfiguration config =
InferenceTestConfigurationBuilder.buildDefaultConfiguration(
testDir,
testFile,
testDataDir,
checker,
checkerOptions,
getAdditionalInferenceOptions(),
solverArgs.first,
solverArgs.second,
useHacks(),
makeDefaultsExplicit(),
shouldEmitDebugInfo,
getPathToAfuScripts(),
getPathToInferenceScript());

InferenceTestResult testResult = new InferenceTestExecutor().runTest(config);
InferenceTestUtilities.assertResultsAreValid(testResult);
4 changes: 2 additions & 2 deletions tests/checkers/inference/test/InferenceTestConfiguration.java
Original file line number Diff line number Diff line change
@@ -25,9 +25,9 @@ public interface InferenceTestConfiguration {
List<String> getFlatSolverArgs();

boolean shouldUseHacks();

boolean makeDefaultsExplicit();

String getPathToAfuScripts();

String getPathToInferenceScript();
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ public class InferenceTestConfigurationBuilder {
private String solver = null;
private boolean shouldUseHacks;
private boolean makeDefaultsExplicit;
private String pathToAfuScripts="";
private String pathToInferenceScript="";
private String pathToAfuScripts = "";
private String pathToInferenceScript = "";

private SimpleOptionMap inferenceJavacArgs = new SimpleOptionMap();
private SimpleOptionMap solverArgs = new SimpleOptionMap();
@@ -202,7 +202,7 @@ public static InferenceTestConfiguration buildDefaultConfiguration(
String solverName,
List<String> solverOptions,
boolean shouldUseHacks,
boolean makeDefaultsExplicit
boolean makeDefaultsExplicit,
boolean shouldEmitDebugInfo,
String pathToAfuScripts,
String pathToInferenceScript) {

0 comments on commit 93635f8

Please sign in to comment.