Skip to content

Commit

Permalink
Fix position of type annotations
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 397354545
  • Loading branch information
cushon authored and Javac Team committed Sep 17, 2021
1 parent 9c70fad commit 22e3c67
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 84 deletions.
3 changes: 1 addition & 2 deletions java/com/google/turbine/binder/CtSymClassBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
/** Constructs a platform {@link ClassPath} from the current JDK's ct.sym file. */
public final class CtSymClassBinder {

@Nullable
public static ClassPath bind(String version) throws IOException {
public static @Nullable ClassPath bind(String version) throws IOException {
String javaHome = JAVA_HOME.value();
requireNonNull(javaHome, "attempted to use --release, but JAVA_HOME is not set");
Path ctSym = Paths.get(javaHome).resolve("lib/ct.sym");
Expand Down
6 changes: 2 additions & 4 deletions java/com/google/turbine/binder/JimageClassBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ private class JimageTopLevelIndex implements TopLevelIndex {

final Scope topLevelScope =
new Scope() {
@Nullable
@Override
public LookupResult lookup(LookupKey lookupKey) {
public @Nullable LookupResult lookup(LookupKey lookupKey) {
// Find the longest prefix of the key that corresponds to a package name.
// TODO(cushon): SimpleTopLevelIndex uses a prefix map for this, does it matter?
Scope scope = null;
Expand Down Expand Up @@ -223,9 +222,8 @@ public Scope scope() {
return null;
}
return new PackageScope() {
@Nullable
@Override
public LookupResult lookup(LookupKey lookupKey) {
public @Nullable LookupResult lookup(LookupKey lookupKey) {
ClassSymbol sym = packageClassesBySimpleName.get(packageName, lookupKey.first().value());
return sym != null ? new LookupResult(sym, lookupKey) : null;
}
Expand Down
6 changes: 2 additions & 4 deletions java/com/google/turbine/binder/Processing.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@
/** Top level annotation processing logic, see also {@link Binder}. */
public class Processing {

@Nullable
static BindingResult process(
static @Nullable BindingResult process(
TurbineLog log,
final ImmutableList<CompUnit> initialSources,
final ClassPath classpath,
Expand Down Expand Up @@ -546,8 +545,7 @@ public abstract static class ProcessorInfo {
* The classloader to use for annotation processor implementations, and any annotations they
* access reflectively.
*/
@Nullable
abstract ClassLoader loader();
abstract @Nullable ClassLoader loader();

/** Command line annotation processing options, passed to javac with {@code -Akey=value}. */
abstract ImmutableMap<String, String> options();
Expand Down
5 changes: 2 additions & 3 deletions java/com/google/turbine/binder/bound/ModuleInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class ModuleInfo {

private final String name;
@Nullable private final String version;
private final @Nullable String version;
private final int flags;
private final ImmutableList<AnnoInfo> annos;
private final ImmutableList<RequireInfo> requires;
Expand Down Expand Up @@ -59,8 +59,7 @@ public String name() {
return name;
}

@Nullable
public String version() {
public @Nullable String version() {
return version;
}

Expand Down
5 changes: 2 additions & 3 deletions java/com/google/turbine/binder/bound/TypeBoundClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public interface TypeBoundClass extends HeaderBoundClass {
/** A type parameter declaration. */
class TyVarInfo {
private final IntersectionTy upperBound;
@Nullable private final Type lowerBound;
private final @Nullable Type lowerBound;
private final ImmutableList<AnnoInfo> annotations;

public TyVarInfo(
Expand All @@ -83,8 +83,7 @@ public IntersectionTy upperBound() {
}

/** The lower bound. */
@Nullable
public Type lowerBound() {
public @Nullable Type lowerBound() {
return lowerBound;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ public TurbineTyKind kind() {
}
});

@Nullable
@Override
public ClassSymbol owner() {
public @Nullable ClassSymbol owner() {
return owner.get();
}

Expand Down
2 changes: 1 addition & 1 deletion java/com/google/turbine/binder/lookup/CompoundScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class CompoundScope implements Scope {

private final Scope scope;
@Nullable private final Scope base;
private final @Nullable Scope base;

private CompoundScope(Scope scope, @Nullable Scope base) {
this.scope = checkNotNull(scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ public static CompoundTopLevelIndex of(TopLevelIndex... indexes) {

private final Scope scope =
new Scope() {
@Nullable
@Override
public LookupResult lookup(LookupKey lookupKey) {
public @Nullable LookupResult lookup(LookupKey lookupKey) {
// Return the first matching symbol.
for (TopLevelIndex index : indexes) {
LookupResult result = index.scope().lookup(lookupKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static class Node {
return children.get(bit);
}

@Nullable private final ClassSymbol sym;
private final @Nullable ClassSymbol sym;

// TODO(cushon): the set of children is typically going to be small, consider optimizing this
// to use a denser representation where appropriate.
Expand Down Expand Up @@ -133,8 +133,7 @@ private SimpleTopLevelIndex(Node root) {
final Scope scope =
new Scope() {
@Override
@Nullable
public LookupResult lookup(LookupKey lookupKey) {
public @Nullable LookupResult lookup(LookupKey lookupKey) {
Node curr = root;
while (true) {
curr = curr.lookup(lookupKey.first().value());
Expand Down
14 changes: 5 additions & 9 deletions java/com/google/turbine/bytecode/ClassFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,12 @@ public ImmutableList<TypeAnnotationInfo> typeAnnotations() {
}

/** A module attribute. */
@Nullable
public ModuleInfo module() {
public @Nullable ModuleInfo module() {
return module;
}

/** The original jar of a repackaged transitive class. */
@Nullable
public String transitiveJar() {
public @Nullable String transitiveJar() {
return transitiveJar;
}

Expand Down Expand Up @@ -177,8 +175,7 @@ public String descriptor() {
}

/** The value of Signature attribute. */
@Nullable
public String signature() {
public @Nullable String signature() {
return signature;
}

Expand Down Expand Up @@ -240,7 +237,7 @@ public static class MethodInfo {
private final int access;
private final String name;
private final String descriptor;
@Nullable private final String signature;
private final @Nullable String signature;
private final List<String> exceptions;
private final AnnotationInfo.@Nullable ElementValue defaultValue;
private final List<AnnotationInfo> annotations;
Expand Down Expand Up @@ -287,8 +284,7 @@ public String descriptor() {
}

/** The value of Signature attribute. */
@Nullable
public String signature() {
public @Nullable String signature() {
return signature;
}

Expand Down
2 changes: 1 addition & 1 deletion java/com/google/turbine/bytecode/ClassReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static ClassFile read(@Nullable String path, byte[] bytes) {
return new ClassReader(path, bytes).read();
}

@Nullable private final String path;
private final @Nullable String path;
private final ByteReader reader;

private ClassReader(@Nullable String path, byte[] bytes) {
Expand Down
6 changes: 2 additions & 4 deletions java/com/google/turbine/lower/Lower.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,7 @@ private ImmutableList<AnnotationInfo> lowerAnnotations(ImmutableList<AnnoInfo> a
return lowered.build();
}

@Nullable
private AnnotationInfo lowerAnnotation(AnnoInfo annotation) {
private @Nullable AnnotationInfo lowerAnnotation(AnnoInfo annotation) {
Boolean visible = isVisible(annotation.sym());
if (visible == null) {
return null;
Expand All @@ -519,8 +518,7 @@ private AnnotationInfo lowerAnnotation(AnnoInfo annotation) {
* Returns true if the annotation is visible at runtime, false if it is not visible at runtime,
* and {@code null} if it should not be retained in bytecode.
*/
@Nullable
private Boolean isVisible(ClassSymbol sym) {
private @Nullable Boolean isVisible(ClassSymbol sym) {
RetentionPolicy retention =
requireNonNull(env.getNonNull(sym).annotationMetadata()).retention();
switch (retention) {
Expand Down
10 changes: 4 additions & 6 deletions java/com/google/turbine/lower/LowerSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ private TySig wildTy(WildTy ty) {
* Produces a method signature attribute for a generic method, or {@code null} if the signature is
* unnecessary.
*/
@Nullable
public String methodSignature(
public @Nullable String methodSignature(
Env<ClassSymbol, TypeBoundClass> env, TypeBoundClass.MethodInfo method, ClassSymbol sym) {
if (!needsMethodSig(sym, env, method)) {
return null;
Expand Down Expand Up @@ -196,8 +195,8 @@ private boolean needsMethodSig(
* Produces a class signature attribute for a generic class, or {@code null} if the signature is
* unnecessary.
*/
@Nullable
public String classSignature(SourceTypeBoundClass info, Env<ClassSymbol, TypeBoundClass> env) {
public @Nullable String classSignature(
SourceTypeBoundClass info, Env<ClassSymbol, TypeBoundClass> env) {
if (!classNeedsSig(info)) {
return null;
}
Expand All @@ -214,8 +213,7 @@ public String classSignature(SourceTypeBoundClass info, Env<ClassSymbol, TypeBou
/**
* A field signature, or {@code null} if the descriptor provides all necessary type information.
*/
@Nullable
public String fieldSignature(Type type) {
public @Nullable String fieldSignature(Type type) {
return needsSig(type) ? SigWriter.type(signature(type)) : null;
}

Expand Down
33 changes: 11 additions & 22 deletions java/com/google/turbine/parse/ConstExpressionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public ConstExpressionParser(Lexer lexer, Token token, int position) {
this.position = position;
}

@Nullable
private static TurbineOperatorKind operator(Token token) {
private static @Nullable TurbineOperatorKind operator(Token token) {
switch (token) {
case ASSIGN:
// TODO(cushon): only allow in annotations?
Expand Down Expand Up @@ -209,8 +208,7 @@ private Expression maybeCast() {
}
}

@Nullable
private Expression notCast() {
private @Nullable Expression notCast() {
Expression expr = expression(null);
if (expr == null) {
return null;
Expand Down Expand Up @@ -257,8 +255,7 @@ private void eat() {
position = lexer.position();
}

@Nullable
private Expression arrayInitializer(int pos) {
private @Nullable Expression arrayInitializer(int pos) {
if (token == Token.RBRACE) {
eat();
return new Tree.ArrayInit(pos, ImmutableList.<Tree.Expression>of());
Expand Down Expand Up @@ -416,8 +413,7 @@ private long parseLong(String text, int radix) {
return r;
}

@Nullable
private Expression unaryRest(TurbineOperatorKind op) {
private @Nullable Expression unaryRest(TurbineOperatorKind op) {
boolean negate = op == TurbineOperatorKind.NEG;
Expression expr = primary(negate);
if (expr == null) {
Expand Down Expand Up @@ -466,8 +462,7 @@ private Ident ident() {
return new Ident(lexer.position(), lexer.stringValue());
}

@Nullable
private Expression finishClassLiteral(int pos, Tree.Type type) {
private @Nullable Expression finishClassLiteral(int pos, Tree.Type type) {
while (token == Token.LBRACK) {
eat();
if (token != Token.RBRACK) {
Expand All @@ -487,8 +482,7 @@ private Expression finishClassLiteral(int pos, Tree.Type type) {
return new ClassLiteral(pos, type);
}

@Nullable
public Expression expression() {
public @Nullable Expression expression() {
Expression result = expression(null);
switch (token) {
case EOF:
Expand All @@ -502,17 +496,15 @@ public Expression expression() {
}
}

@Nullable
private Expression expression(TurbineOperatorKind.Precedence prec) {
private @Nullable Expression expression(TurbineOperatorKind.Precedence prec) {
Expression term1 = primary(false);
if (term1 == null) {
return null;
}
return expression(term1, prec);
}

@Nullable
private Expression expression(Expression term1, TurbineOperatorKind.Precedence prec) {
private @Nullable Expression expression(Expression term1, TurbineOperatorKind.Precedence prec) {
while (true) {
if (token == Token.EOF) {
return term1;
Expand Down Expand Up @@ -546,8 +538,7 @@ private Expression expression(Expression term1, TurbineOperatorKind.Precedence p
}
}

@Nullable
private Expression assign(Expression term1, TurbineOperatorKind op) {
private @Nullable Expression assign(Expression term1, TurbineOperatorKind op) {
if (!(term1 instanceof Tree.ConstVarName)) {
return null;
}
Expand All @@ -563,8 +554,7 @@ private Expression assign(Expression term1, TurbineOperatorKind op) {
return new Tree.Assign(term1.position(), name, rhs);
}

@Nullable
private Expression ternary(Expression term1) {
private @Nullable Expression ternary(Expression term1) {
Expression thenExpr = expression(TurbineOperatorKind.Precedence.TERNARY);
if (thenExpr == null) {
return null;
Expand All @@ -580,8 +570,7 @@ private Expression ternary(Expression term1) {
return new Tree.Conditional(position, term1, thenExpr, elseExpr);
}

@Nullable
private Expression castTail(TurbineConstantTypeKind ty) {
private @Nullable Expression castTail(TurbineConstantTypeKind ty) {
if (token != Token.RPAREN) {
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions java/com/google/turbine/parse/StreamLexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ private void eat() {
ch = reader.next();
}

@Nullable
@Override
public String javadoc() {
public @Nullable String javadoc() {
String result = javadoc;
javadoc = null;
if (result == null) {
Expand Down
3 changes: 1 addition & 2 deletions java/com/google/turbine/processing/TurbineElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,7 @@ public TyVarInfo get() {
}
});

@Nullable
private TyVarInfo info() {
private @Nullable TyVarInfo info() {
return info.get();
}

Expand Down
3 changes: 1 addition & 2 deletions java/com/google/turbine/processing/TurbineMessager.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public void printMessage(
* Returns the {@link SourceFile} that contains the declaration of the given {@link Symbol}, or
* {@code null} if the symbol was not compiled from source.
*/
@Nullable
private SourceFile getSource(Symbol sym) {
private @Nullable SourceFile getSource(Symbol sym) {
ClassSymbol encl = ModelFactory.enclosingClass(sym);
TypeBoundClass info = factory.getSymbol(encl);
if (!(info instanceof SourceTypeBoundClass)) {
Expand Down
Loading

0 comments on commit 22e3c67

Please sign in to comment.