Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support emitting "sourceType" diagnostics #36

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -209,28 +209,38 @@ public class BaseTypeVisitor<Factory extends GenericAnnotatedTypeFactory<?, ?, ?
/** The @{@link Deterministic} annotation. */
protected final AnnotationMirror DETERMINISTIC =
AnnotationBuilder.fromClass(elements, Deterministic.class);

netdpb marked this conversation as resolved.
Show resolved Hide resolved
/** The @{@link SideEffectFree} annotation. */
protected final AnnotationMirror SIDE_EFFECT_FREE =
AnnotationBuilder.fromClass(elements, SideEffectFree.class);

/** The @{@link Pure} annotation. */
protected final AnnotationMirror PURE = AnnotationBuilder.fromClass(elements, Pure.class);

/** The {@code value} element/field of the @java.lang.annotation.Target annotation. */
protected final ExecutableElement targetValueElement;

/** The {@code when} element/field of the @Unused annotation. */
protected final ExecutableElement unusedWhenElement;

/** 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. */
private final boolean suggestPureMethods;

/**
* True if "-AcheckPurityAnnotations" or "-AsuggestPureMethods" or "-Ainfer" was passed on the
* command line.
*/
private final boolean checkPurity;

/**
* True if purity annotations should be inferred. Should be set to false if both the Lock Checker
* (or some other checker that overrides {@link CFAbstractStore#isSideEffectFree} in a
Expand Down Expand Up @@ -268,6 +278,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 @@ -1228,6 +1239,7 @@ protected Void visitLocalVariable(LocalVariable localVarExpr, Set<Element> param
return super.visitLocalVariable(localVarExpr, parameters);
}
};

/**
* Check that the parameters used in {@code javaExpression} are effectively final for method
* {@code method}.
Expand Down Expand Up @@ -2587,6 +2599,7 @@ private List<AnnotationTree> supportedAnnoTrees(List<? extends AnnotationTree> a

/** Cache to avoid calling {@link #getExceptionParameterLowerBoundAnnotations} more than once. */
private Set<? extends AnnotationMirror> getExceptionParameterLowerBoundAnnotationsCache = null;

/** The same as {@link #getExceptionParameterLowerBoundAnnotations}, but uses a cache. */
private Set<? extends AnnotationMirror> getExceptionParameterLowerBoundAnnotationsCached() {
if (getExceptionParameterLowerBoundAnnotationsCache == null) {
Expand Down Expand Up @@ -2849,6 +2862,9 @@ protected final void commonAssignmentCheckStartDiagnostic(
varType.getKind(),
varType.toString());
}
if (showTypes) {
checker.reportWarning(valueTree, "sourceType", valueType, valueTree);
}
}

/**
Expand Down Expand Up @@ -3636,19 +3652,25 @@ public class OverrideChecker {

/** The declaration of an overriding method. */
protected final Tree overriderTree;

/** True if {@link #overriderTree} is a MEMBER_REFERENCE. */
protected final boolean isMethodReference;

/** The type of the overriding method. */
protected final AnnotatedExecutableType overrider;

/** The subtype that declares the overriding method. */
protected final AnnotatedTypeMirror overriderType;

/** The type of the overridden method. */
protected final AnnotatedExecutableType overridden;

/** The supertype that declares the overridden method. */
protected final AnnotatedDeclaredType overriddenType;

/** The teturn type of the overridden method. */
protected final AnnotatedTypeMirror overriddenReturnType;

/** The return type of the overriding method. */
protected final AnnotatedTypeMirror overriderReturnType;

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 Expand Up @@ -1958,6 +1963,7 @@ private void reportUnneededSuppression(Tree tree, String suppressWarningsString)
/** The name of the @SuppressWarnings annotation. */
private final @CanonicalName String suppressWarningsClassName =
SuppressWarnings.class.getCanonicalName();

/**
* Finds the tree that is a {@code @SuppressWarnings} annotation.
*
Expand Down