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

Don't use annotations in comments #674

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -69,6 +69,7 @@
import org.checkerframework.afu.scenelib.type.Type;
import org.checkerframework.afu.scenelib.util.CommandLineUtils;
import org.checkerframework.afu.scenelib.util.coll.VivifyingMap;
import org.checkerframework.checker.signature.qual.BinaryName;
import org.objectweb.asm.TypePath;
import org.plumelib.options.Option;
import org.plumelib.options.OptionGroup;
Expand Down Expand Up @@ -305,7 +306,7 @@ private static AScene filteredScene(final AScene scene) {
final AScene filtered = new AScene();
filtered.packages.putAll(scene.packages);
filtered.imports.putAll(scene.imports);
for (Map.Entry<String, AClass> entry : scene.classes.entrySet()) {
for (Map.Entry<@BinaryName String, AClass> entry : scene.classes.entrySet()) {
String key = entry.getKey();
AClass clazz0 = entry.getValue();
AClass clazz1 = filtered.classes.getVivify(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.checkerframework.afu.scenelib.io.ASTPath;
import org.checkerframework.afu.scenelib.io.DebugWriter;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signature.qual.BinaryName;
import org.checkerframework.checker.signature.qual.ClassGetName;
import org.objectweb.asm.TypePath;

Expand Down Expand Up @@ -261,8 +262,8 @@ public ASTPath getASTPath() {
*
* @return class name from {@link InClassCriterion}, or null if none present
*/
public @Nullable @ClassGetName String getClassName() {
String result = null;
public @Nullable @BinaryName String getClassName() {
@BinaryName String result = null;
for (Criterion c : criteria.values()) {
if (c.getKind() == Criterion.Kind.IN_CLASS) {
if (result == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import javax.lang.model.element.Name;
import org.checkerframework.afu.annotator.scanner.AnonymousClassScanner;
import org.checkerframework.afu.annotator.scanner.LocalClassScanner;
import org.checkerframework.checker.signature.qual.ClassGetName;
import org.checkerframework.checker.signature.qual.BinaryName;

// If there are dollar signs in a name, then there are two
// possibilities regarding how the dollar sign got there.
Expand All @@ -31,7 +31,7 @@ public final class InClassCriterion implements Criterion {
static boolean debug = false;

/** The class name. */
public final @ClassGetName String className;
public final @BinaryName String className;

/** If true, require an exact match. */
private final boolean exactMatch;
Expand All @@ -42,7 +42,7 @@ public final class InClassCriterion implements Criterion {
* @param className the class name
* @param exactMatch if true, require an exact match
*/
public InClassCriterion(@ClassGetName String className, boolean exactMatch) {
public InClassCriterion(@BinaryName String className, boolean exactMatch) {
this.className = className;
this.exactMatch = exactMatch;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.checkerframework.afu.scenelib.type.BoundedType;
import org.checkerframework.afu.scenelib.type.DeclaredType;
import org.checkerframework.afu.scenelib.type.Type;
import org.checkerframework.checker.signature.qual.BinaryName;
import org.objectweb.asm.TypePath;

/**
Expand Down Expand Up @@ -85,7 +86,7 @@ public Insertions() {
* @return {@link java.util.Set} of {@link Insertion}s with an {@link InClassCriterion} for the
* given class
*/
public Set<Insertion> forClass(CompilationUnitTree cut, String qualifiedClassName) {
public Set<Insertion> forClass(CompilationUnitTree cut, @BinaryName String qualifiedClassName) {
Set<Insertion> set = new LinkedHashSet<>();
forClass(cut, qualifiedClassName, set);
return set;
Expand All @@ -109,16 +110,18 @@ public Set<Insertion> forOuterClass(CompilationUnitTree cut, String qualifiedOut
System.out.printf("forOuterClass(%s): map = %s%n", qualifiedOuterClassName, map);
}
Set<Insertion> set = new LinkedHashSet<>();
for (String key : map.keySet()) {
String qualifiedClassName = qualifiedOuterClassName + key;
for (String innerClassPath : map.keySet()) {
@SuppressWarnings("signature:assignment") // string concatenation
@BinaryName String qualifiedClassName = qualifiedOuterClassName + innerClassPath;
forClass(cut, qualifiedClassName, set);
}
return set;
}
}

/** Side-effects {@code result} to add {@link Insertion}s for {@code qualifiedClassName}. */
private void forClass(CompilationUnitTree cut, String qualifiedClassName, Set<Insertion> result) {
private void forClass(
CompilationUnitTree cut, @BinaryName String qualifiedClassName, Set<Insertion> result) {
if (Main.temporaryDebug) {
System.out.printf(
"calling forClass(cut, %s, set of size %d)%n", qualifiedClassName, result.size());
Expand Down Expand Up @@ -243,7 +246,7 @@ public List<Insertion> toList() {
*/
@SuppressWarnings("CatchAndPrintStackTrace") // maybe rethrow the exception
private Set<Insertion> organizeTypedInsertions(
CompilationUnitTree cut, String className, Collection<Insertion> insertions) {
CompilationUnitTree cut, @BinaryName String className, Collection<Insertion> insertions) {
Map<ASTRecord, TypedInsertion> outerInsertions = new HashMap<>();
Set<Insertion> innerInsertions = new LinkedHashSet<>();
List<Insertion> innerInsertionsList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.checkerframework.afu.scenelib.type.DeclaredType;
import org.checkerframework.afu.scenelib.type.Type;
import org.checkerframework.afu.scenelib.util.coll.VivifyingMap;
import org.checkerframework.checker.signature.qual.BinaryName;
import org.checkerframework.checker.signature.qual.ClassGetName;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
Expand Down Expand Up @@ -169,9 +170,8 @@ private void parseScene() {
parsePackage(clist, entry.getKey(), entry.getValue());
}

@SuppressWarnings("signature:assignment") // scene-lib is not fully annotated
VivifyingMap<@ClassGetName String, AClass> classes = scene.classes;
for (Map.Entry<@ClassGetName String, AClass> entry : classes.entrySet()) {
VivifyingMap<@BinaryName String, AClass> classes = scene.classes;
for (Map.Entry<@BinaryName String, AClass> entry : classes.entrySet()) {
String key = entry.getKey();
AClass clazz = entry.getValue();
if (key.endsWith(".package-info")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import javax.lang.model.element.VariableElement;
import org.checkerframework.afu.scenelib.Annotation;
import org.checkerframework.afu.scenelib.util.coll.VivifyingMap;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.plumelib.util.CollectionsPlume;

/** An annotated class. */
Expand Down Expand Up @@ -45,7 +47,7 @@ public class AClass extends ADeclaration {
* The type element representing the class. Clients must call {@link #setTypeElement(TypeElement)}
* before accessing this field.
*/
private /*@MonotonicNonNull*/ TypeElement typeElement = null;
private @MonotonicNonNull TypeElement typeElement = null;

/** The fully-qualified name of the annotated class. */
public final String className;
Expand All @@ -54,7 +56,7 @@ public class AClass extends ADeclaration {
private final HashSet<String> enums = new HashSet<>();

/** The enum constants of this class, or null if this class is not an enum. */
private /*@MonotonicNonNull*/ List<VariableElement> enumConstants = null;
private @MonotonicNonNull List<VariableElement> enumConstants = null;

/**
* The simple class names any of this class's outer classes (or this class) that are annotations.
Expand Down Expand Up @@ -290,7 +292,7 @@ public void markAsEnum(String className) {
*
* @return the enum constants, or null if this is not an enum
*/
public /*@Nullable*/ List<VariableElement> getEnumConstants() {
public @Nullable List<VariableElement> getEnumConstants() {
if (enumConstants == null) {
return null;
}
Expand Down Expand Up @@ -409,7 +411,7 @@ public void markAsRecord(String className) {
*
* @return a type element representing this class
*/
public /*@Nullable*/ TypeElement getTypeElement() {
public @Nullable TypeElement getTypeElement() {
return typeElement;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.lang.model.type.TypeMirror;
import org.checkerframework.afu.scenelib.Annotation;
import org.checkerframework.afu.scenelib.util.coll.VivifyingMap;
import org.checkerframework.checker.nullness.qual.Nullable;

/** An annotated method; contains bounds, return, parameters, receiver, and throws. */
public class AMethod extends ADeclaration {
Expand All @@ -23,14 +24,14 @@ public class AMethod extends ADeclaration {
public final String methodSignature;

/** The type parameters of this method. */
private /*@Nullable*/ List<? extends TypeParameterElement> typeParameters = null;
private @Nullable List<? extends TypeParameterElement> typeParameters = null;

/** The method's annotated type parameter bounds. */
public final VivifyingMap<BoundLocation, ATypeElement> bounds =
ATypeElement.<BoundLocation>newVivifyingLHMap_ATE();

/** The return type of the method, or null if the method's return type is unknown or void. */
private /*@Nullable*/ TypeMirror returnTypeMirror;
private @Nullable TypeMirror returnTypeMirror;

/** The method's annotated return type. Non-null even if returnTypeMirror is null. */
public final ATypeElement returnType; // initialized in constructor
Expand Down Expand Up @@ -230,7 +231,7 @@ public AField vivifyAndAddTypeMirrorToPostcondition(String expression, TypeMirro
*
* @return the return type, or null if the return type is unknown or void
*/
public /*@Nullable*/ TypeMirror getReturnTypeMirror() {
public @Nullable TypeMirror getReturnTypeMirror() {
return returnTypeMirror;
}

Expand All @@ -239,7 +240,7 @@ public AField vivifyAndAddTypeMirrorToPostcondition(String expression, TypeMirro
*
* @param returnTypeMirror the return type
*/
public void setReturnTypeMirror(/*@Nullable*/ TypeMirror returnTypeMirror) {
public void setReturnTypeMirror(@Nullable TypeMirror returnTypeMirror) {
if (returnTypeMirror == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.checkerframework.afu.scenelib.Annotation;
import org.checkerframework.afu.scenelib.io.IndexFileParser;
import org.checkerframework.afu.scenelib.util.coll.VivifyingMap;
import org.checkerframework.checker.signature.qual.BinaryName;
import org.checkerframework.checker.signature.qual.ClassGetName;

/**
* An <code>AScene</code> (annotated scene) represents the annotations on a set of Java classes and
Expand Down Expand Up @@ -57,8 +59,8 @@ public class AScene implements Cloneable {
public final Map<String, Set<String>> imports = new LinkedHashMap<>();

/** This scene's annotated classes; map key is class name */
public final VivifyingMap</*@BinaryName*/ String, AClass> classes =
new VivifyingMap<String, AClass>(new LinkedHashMap<>()) {
public final VivifyingMap<@BinaryName String, AClass> classes =
new VivifyingMap<@BinaryName String, AClass>(new LinkedHashMap<>()) {
@Override
public AClass createValueFor(String k) {
return new AClass(k);
Expand Down Expand Up @@ -133,7 +135,7 @@ public int hashCode() {
*
* @return an immutable map from binary names to AClass objects
*/
public Map</*@BinaryName*/ String, AClass> getClasses() {
public Map<@ClassGetName String, AClass> getClasses() {
return ImmutableMap.copyOf(classes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public boolean equals(LocalLocation o) {
}

@Override
public boolean equals(/*@ReadOnly*/ Object o) {
public boolean equals(Object o) {
return o instanceof LocalLocation && equals((LocalLocation) o);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Objects;
import org.checkerframework.checker.signature.qual.BinaryName;

/**
* Structure bundling an {@link ASTPath} with information about its starting point. Necessary
Expand All @@ -20,7 +21,7 @@ public class ASTRecord implements Comparable<ASTRecord> {
public final CompilationUnitTree ast;

/** Name of the enclosing class declaration. */
public final String className;
public final @BinaryName String className;

/** Name of the enclosing method declaration, or null if there is none. */
public final String methodName;
Expand All @@ -33,7 +34,7 @@ public class ASTRecord implements Comparable<ASTRecord> {

public ASTRecord(
CompilationUnitTree ast,
String className,
@BinaryName String className,
String methodName,
String varName,
ASTPath astPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.TypePath;
import org.objectweb.asm.TypeReference;
import org.plumelib.reflection.Signatures;

/**
* A ClassAnnotationSceneWriter is a {@link org.objectweb.asm.ClassVisitor} that can be used to
Expand Down Expand Up @@ -151,18 +152,19 @@ public byte[] toByteArray() {
return ((ClassWriter) cv).toByteArray();
}

@SuppressWarnings("override.param") // ASM is not annotated
@Override
public void visit(
int version,
int access,
String name,
@ClassGetName String name,
String signature,
String superName,
String[] interfaces) {
classReader.accept(new MethodCodeIndexer(api), 0);
super.visit(version, access, name, signature, superName, interfaces);
// class files store fully quantified class names with '/' instead of '.'
name = name.replace('/', '.');
// class files store fully qualified class names with '/' instead of '.'
name = Signatures.classGetNameToBinaryName(name);
aClass = scene.classes.getVivify(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.checkerframework.afu.scenelib.io.IndexFileParser;
import org.checkerframework.afu.scenelib.io.IndexFileWriter;
import org.checkerframework.afu.scenelib.util.CommandLineUtils;
import org.checkerframework.checker.signature.qual.BinaryName;
import org.plumelib.util.FileIOException;

/** Utility for merging index files, including multiple versions for the same class. */
Expand All @@ -42,7 +43,7 @@ public static void main(String[] args) {
System.exit(0);
}

final SetMultimap<String, String> annotatedFor = HashMultimap.create();
final SetMultimap<@BinaryName String, String> annotatedFor = HashMultimap.create();
String[] inputArgs;

// TODO: document assumptions
Expand Down Expand Up @@ -84,7 +85,8 @@ public static void main(String[] args) {
int ix = relPath.indexOf(File.separator);
String subdir = ix < 0 ? relPath : relPath.substring(0, ix);
// trim .jaif or .jann and subdir, convert directory to package id
String classname =
@SuppressWarnings("signature:assignment") // string manipulation
@BinaryName String classname =
relPath
.substring(0, relPath.lastIndexOf('.'))
.substring(relPath.indexOf('/') + 1)
Expand Down Expand Up @@ -259,8 +261,9 @@ public Void visitElement(AElement el, Void v) {
AnnotationDef afDef =
Annotations.createValueAnnotationDef(
"AnnotatedFor", Collections.<Annotation>emptySet(), stringArray, "IndexFileMerger");
for (Map.Entry<String, Collection<String>> entry : annotatedFor.asMap().entrySet()) {
String key = entry.getKey();
for (Map.Entry<@BinaryName String, Collection<String>> entry :
annotatedFor.asMap().entrySet()) {
@BinaryName String key = entry.getKey();
Collection<String> values = entry.getValue();
Annotation afAnno =
new Annotation(
Expand Down
Loading