Skip to content

Commit

Permalink
Support emitting "sourceType" diagnostics (#36)
Browse files Browse the repository at this point in the history
* Support `test:expression-type` assertions.

* Better docs for ``-AshowTypes`.

* Fix typo.

* Revert whitespace changes to minimize the diff.
  • Loading branch information
netdpb authored Jul 26, 2023
1 parent c92af7d commit 763b130
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ public class BaseTypeVisitor<Factory extends GenericAnnotatedTypeFactory<?, ?, ?

/** True if "-Ashowchecks" was passed on the command line. */
private final boolean showchecks;
/** True if "-AshowTypes" was passed on the command line. */
private final boolean showTypes;
/** True if "-Ainfer" was passed on the command line. */
private final boolean infer;
/** True if "-AsuggestPureMethods" or "-Ainfer" was passed on the command line. */
Expand Down Expand Up @@ -268,6 +270,7 @@ protected BaseTypeVisitor(BaseTypeChecker checker, Factory typeFactory) {
targetValueElement = TreeUtils.getMethod(Target.class, "value", 0, env);
unusedWhenElement = TreeUtils.getMethod(Unused.class, "when", 0, env);
showchecks = checker.hasOption("showchecks");
showTypes = checker.hasOption("showTypes");
infer = checker.hasOption("infer");
suggestPureMethods = checker.hasOption("suggestPureMethods") || infer;
checkPurity = checker.hasOption("checkPurityAnnotations") || suggestPureMethods;
Expand Down Expand Up @@ -2849,6 +2852,9 @@ protected final void commonAssignmentCheckStartDiagnostic(
varType.getKind(),
varType.toString());
}
if (showTypes) {
checker.reportWarning(valueTree, "sourceType", valueType, valueTree);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@
// org.checkerframework.common.basetype.BaseTypeVisitor
"showchecks",

// Emit a diagnostic showing the type of each expression whose value is used and each receiver of
// an expression, including assignments and method argument slots.
// org.checkerframework.common.basetype.BaseTypeVisitor
"showTypes",

// Output information about intermediate steps in method type argument inference
// org.checkerframework.framework.util.typeinference.DefaultTypeArgumentInference
"showInferenceSteps",
Expand Down

0 comments on commit 763b130

Please sign in to comment.