From aa6353834a7f98d42c4ef81313e088ee616a726b Mon Sep 17 00:00:00 2001 From: Chris Povirk Date: Tue, 9 Jul 2024 15:53:32 -0400 Subject: [PATCH] Disable checking of contracts. (#183) We've historically accomplished this with `-AsuppressWarnings`, but this CL's solution may be more general. Also, it avoids running some code entirely, which saves us from having to keep that code updated for the very new JDKs that we run with. (It might also help performance if we're lucky, and maybe it moves us a step closer to not needing JavaParser (though that may be on the way out, anyway).) --- .../NullSpecAnnotatedTypeFactory.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/com/google/jspecify/nullness/NullSpecAnnotatedTypeFactory.java b/src/main/java/com/google/jspecify/nullness/NullSpecAnnotatedTypeFactory.java index ce126ba..a5bed35 100644 --- a/src/main/java/com/google/jspecify/nullness/NullSpecAnnotatedTypeFactory.java +++ b/src/main/java/com/google/jspecify/nullness/NullSpecAnnotatedTypeFactory.java @@ -110,6 +110,10 @@ import org.checkerframework.framework.type.typeannotator.TypeAnnotator; import org.checkerframework.framework.type.visitor.AnnotatedTypeVisitor; import org.checkerframework.framework.util.AnnotationFormatter; +import org.checkerframework.framework.util.Contract.ConditionalPostcondition; +import org.checkerframework.framework.util.Contract.Postcondition; +import org.checkerframework.framework.util.Contract.Precondition; +import org.checkerframework.framework.util.ContractsFromMethod; import org.checkerframework.framework.util.DefaultAnnotationFormatter; import org.checkerframework.framework.util.DefaultQualifierKindHierarchy; import org.checkerframework.framework.util.QualifierKindHierarchy; @@ -919,6 +923,28 @@ public boolean applyConservativeDefaults(Element annotationScope) { } } + // Disable checking of contracts. + @Override + protected ContractsFromMethod createContractsFromMethod() { + return new ContractsFromMethod(this) { + @Override + public Set getConditionalPostconditions( + ExecutableElement methodElement) { + return emptySet(); + } + + @Override + public Set getPreconditions(ExecutableElement executableElement) { + return emptySet(); + } + + @Override + public Set getPostconditions(ExecutableElement executableElement) { + return emptySet(); + } + }; + } + @Override protected void addComputedTypeAnnotations(Tree tree, AnnotatedTypeMirror type, boolean iUseFlow) { super.addComputedTypeAnnotations(