From 18242eb983d1ed3dc435b85ecf620caa3995c147 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 26 May 2026 12:27:07 -0700 Subject: [PATCH 1/3] Format `TypeCompound`s --- .../framework/util/element/MethodApplier.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java b/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java index 1498e080358..8822ad6a09b 100644 --- a/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java +++ b/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java @@ -9,6 +9,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.StringJoiner; import javax.lang.model.element.Element; import org.checkerframework.framework.type.AnnotatedTypeFactory; import org.checkerframework.framework.type.AnnotatedTypeMirror; @@ -128,7 +129,7 @@ protected boolean isAccepted() { public void extractAndApply() throws UnexpectedAnnotationLocationException { methodType.setElement(methodSymbol); // Preserves previous behavior - // Add declaration annotations to the return type if + // Add declaration annotations to the return type. if (methodType.getReturnType() instanceof AnnotatedTypeVariable) { applyTypeVarUseOnReturnType(); } @@ -152,6 +153,30 @@ public void extractAndApply() throws UnexpectedAnnotationLocationException { methodType.getTypeVariables(), methodSymbol.getTypeParameters(), typeFactory); } + /** + * Returns the formatted representation of a {@link TypeCompound}. + * + * @param tc a TypeCompound + * @return its string representation + */ + public static String toString(TypeCompound tc) { + return tc + "@" + tc.getPosition(); + } + + /** + * Returns the formatted representation of a collection of {@link TypeCompound}s. + * + * @param tc a collection of TypeCompounds + * @return its string representation + */ + public static String toString(Iterable targeted) { + StringJoiner sj = new StringJoiner(", ", "[", "]"); + for (TypeCompound tc : targeted) { + sj.add(toString(tc)); + } + return sj.toString(); + } + // NOTE that these are the only locations not handled elsewhere, otherwise we call apply @Override protected void handleTargeted(List targeted) From 4289a4f3d78d0abc3a18feff3d3010a50256f068 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 26 May 2026 13:01:17 -0700 Subject: [PATCH 2/3] Rename variable --- .../framework/util/element/MethodApplier.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java b/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java index 8822ad6a09b..4a471352a42 100644 --- a/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java +++ b/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java @@ -166,12 +166,12 @@ public static String toString(TypeCompound tc) { /** * Returns the formatted representation of a collection of {@link TypeCompound}s. * - * @param tc a collection of TypeCompounds + * @param tcs a collection of TypeCompounds * @return its string representation */ - public static String toString(Iterable targeted) { + public static String toString(Iterable tcs) { StringJoiner sj = new StringJoiner(", ", "[", "]"); - for (TypeCompound tc : targeted) { + for (TypeCompound tc : tcs) { sj.add(toString(tc)); } return sj.toString(); From a96e66ca1aa8238eac1cbaaa4388cdb9d8c0cbdc Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Wed, 27 May 2026 08:56:02 -0700 Subject: [PATCH 3/3] Move methods to `ElementAnnotationUtil.java` --- .../util/element/ElementAnnotationUtil.java | 25 +++++++++++++++++ .../framework/util/element/MethodApplier.java | 27 +------------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/framework/src/main/java/org/checkerframework/framework/util/element/ElementAnnotationUtil.java b/framework/src/main/java/org/checkerframework/framework/util/element/ElementAnnotationUtil.java index 5e35981d347..60b57c0f505 100644 --- a/framework/src/main/java/org/checkerframework/framework/util/element/ElementAnnotationUtil.java +++ b/framework/src/main/java/org/checkerframework/framework/util/element/ElementAnnotationUtil.java @@ -15,6 +15,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.StringJoiner; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.type.TypeKind; @@ -618,4 +619,28 @@ public ErrorTypeKindException(String format, Object... args) { super(String.format(format, args)); } } + + /** + * Returns the formatted representation of a {@link TypeCompound}. + * + * @param tc a TypeCompound + * @return its string representation + */ + public static String toString(TypeCompound tc) { + return tc + "@" + tc.getPosition(); + } + + /** + * Returns the formatted representation of a collection of {@link TypeCompound}s. + * + * @param tcs a collection of TypeCompounds + * @return its string representation + */ + public static String toString(Iterable tcs) { + StringJoiner sj = new StringJoiner(", ", "[", "]"); + for (TypeCompound tc : tcs) { + sj.add(toString(tc)); + } + return sj.toString(); + } } diff --git a/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java b/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java index 4a471352a42..ea13d8d1fc6 100644 --- a/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java +++ b/framework/src/main/java/org/checkerframework/framework/util/element/MethodApplier.java @@ -9,7 +9,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.StringJoiner; import javax.lang.model.element.Element; import org.checkerframework.framework.type.AnnotatedTypeFactory; import org.checkerframework.framework.type.AnnotatedTypeMirror; @@ -153,31 +152,7 @@ public void extractAndApply() throws UnexpectedAnnotationLocationException { methodType.getTypeVariables(), methodSymbol.getTypeParameters(), typeFactory); } - /** - * Returns the formatted representation of a {@link TypeCompound}. - * - * @param tc a TypeCompound - * @return its string representation - */ - public static String toString(TypeCompound tc) { - return tc + "@" + tc.getPosition(); - } - - /** - * Returns the formatted representation of a collection of {@link TypeCompound}s. - * - * @param tcs a collection of TypeCompounds - * @return its string representation - */ - public static String toString(Iterable tcs) { - StringJoiner sj = new StringJoiner(", ", "[", "]"); - for (TypeCompound tc : tcs) { - sj.add(toString(tc)); - } - return sj.toString(); - } - - // NOTE that these are the only locations not handled elsewhere, otherwise we call apply + // NOTE that these are the only locations not handled elsewhere, otherwise we call apply. @Override protected void handleTargeted(List targeted) throws UnexpectedAnnotationLocationException {