diff options
author | cushon <cushon@google.com> | 2018-12-14 16:03:33 -0800 |
---|---|---|
committer | Liam Miller-Cushon <cushon@google.com> | 2019-01-28 21:35:26 -0800 |
commit | 4897f9e0c5c9df43d6cfb86b71f6c37f0d6d0945 (patch) | |
tree | 319eb8c0dfcda3a0f046db901bba73bb1e9409ce /java/com | |
parent | 49fc8eaf64a247dc8e93127e7bb9344a1c7d5c6d (diff) | |
download | turbine-4897f9e0c5c9df43d6cfb86b71f6c37f0d6d0945.tar.gz |
Miscellaneous cleanups
MOE_MIGRATED_REVID=225619145
Diffstat (limited to 'java/com')
-rw-r--r-- | java/com/google/turbine/binder/ConstBinder.java | 4 | ||||
-rw-r--r-- | java/com/google/turbine/binder/ConstEvaluator.java | 4 | ||||
-rw-r--r-- | java/com/google/turbine/binder/CtSymClassBinder.java | 4 | ||||
-rw-r--r-- | java/com/google/turbine/binder/JimageClassBinder.java | 4 | ||||
-rw-r--r-- | java/com/google/turbine/binder/bound/TurbineClassValue.java (renamed from java/com/google/turbine/binder/bound/ClassValue.java) | 8 | ||||
-rw-r--r-- | java/com/google/turbine/binder/bytecode/BytecodeBinder.java | 8 | ||||
-rw-r--r-- | java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java | 4 | ||||
-rw-r--r-- | java/com/google/turbine/bytecode/AnnotationWriter.java | 6 | ||||
-rw-r--r-- | java/com/google/turbine/bytecode/ClassFile.java | 4 | ||||
-rw-r--r-- | java/com/google/turbine/bytecode/ClassReader.java | 7 | ||||
-rw-r--r-- | java/com/google/turbine/lower/Lower.java | 10 | ||||
-rw-r--r-- | java/com/google/turbine/main/Main.java | 6 | ||||
-rw-r--r-- | java/com/google/turbine/type/Type.java | 3 | ||||
-rw-r--r-- | java/com/google/turbine/types/Canonicalize.java | 2 |
14 files changed, 40 insertions, 34 deletions
diff --git a/java/com/google/turbine/binder/ConstBinder.java b/java/com/google/turbine/binder/ConstBinder.java index e5717b2..0f989dd 100644 --- a/java/com/google/turbine/binder/ConstBinder.java +++ b/java/com/google/turbine/binder/ConstBinder.java @@ -20,9 +20,9 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.turbine.binder.bound.AnnotationMetadata; -import com.google.turbine.binder.bound.ClassValue; import com.google.turbine.binder.bound.EnumConstantValue; import com.google.turbine.binder.bound.SourceTypeBoundClass; +import com.google.turbine.binder.bound.TurbineClassValue; import com.google.turbine.binder.bound.TypeBoundClass; import com.google.turbine.binder.bound.TypeBoundClass.FieldInfo; import com.google.turbine.binder.bound.TypeBoundClass.MethodInfo; @@ -215,7 +215,7 @@ public class ConstBinder { if (value.kind() != Kind.CLASS_LITERAL) { return null; } - Type type = ((ClassValue) value).type(); + Type type = ((TurbineClassValue) value).type(); if (type.tyKind() != TyKind.CLASS_TY) { return null; } diff --git a/java/com/google/turbine/binder/ConstEvaluator.java b/java/com/google/turbine/binder/ConstEvaluator.java index 2d8ce2d..d565cee 100644 --- a/java/com/google/turbine/binder/ConstEvaluator.java +++ b/java/com/google/turbine/binder/ConstEvaluator.java @@ -22,8 +22,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.turbine.binder.bound.AnnotationValue; -import com.google.turbine.binder.bound.ClassValue; import com.google.turbine.binder.bound.EnumConstantValue; +import com.google.turbine.binder.bound.TurbineClassValue; import com.google.turbine.binder.bound.TypeBoundClass; import com.google.turbine.binder.bound.TypeBoundClass.FieldInfo; import com.google.turbine.binder.bound.TypeBoundClass.MethodInfo; @@ -166,7 +166,7 @@ public strictfp class ConstEvaluator { /** Evaluates a class literal. */ Const evalClassLiteral(ClassLiteral t) { - return new ClassValue(evalClassLiteralType(t.type())); + return new TurbineClassValue(evalClassLiteralType(t.type())); } private Type evalClassLiteralType(Tree.Type type) { diff --git a/java/com/google/turbine/binder/CtSymClassBinder.java b/java/com/google/turbine/binder/CtSymClassBinder.java index 89e8b01..84fa966 100644 --- a/java/com/google/turbine/binder/CtSymClassBinder.java +++ b/java/com/google/turbine/binder/CtSymClassBinder.java @@ -16,6 +16,8 @@ package com.google.turbine.binder; +import static com.google.common.base.StandardSystemProperty.JAVA_HOME; + import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; @@ -42,7 +44,7 @@ public class CtSymClassBinder { @Nullable public static ClassPath bind(String version) throws IOException { - Path javaHome = Paths.get(System.getProperty("java.home")); + Path javaHome = Paths.get(JAVA_HOME.value()); Path ctSym = javaHome.resolve("lib/ct.sym"); if (!Files.exists(ctSym)) { throw new IllegalStateException("lib/ct.sym does not exist in " + javaHome); diff --git a/java/com/google/turbine/binder/JimageClassBinder.java b/java/com/google/turbine/binder/JimageClassBinder.java index 5b2b110..e3d0865 100644 --- a/java/com/google/turbine/binder/JimageClassBinder.java +++ b/java/com/google/turbine/binder/JimageClassBinder.java @@ -16,6 +16,8 @@ package com.google.turbine.binder; +import static com.google.common.base.StandardSystemProperty.JAVA_HOME; + import com.google.common.base.Joiner; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; @@ -79,7 +81,7 @@ public class JimageClassBinder { /** Returns a platform classpath for the given JDK's jimage file. */ public static ClassPath bind(String javaHome) throws IOException { - if (javaHome.equals(System.getProperty("java.home"))) { + if (javaHome.equals(JAVA_HOME.value())) { return bindDefault(); } FileSystem fileSystem = diff --git a/java/com/google/turbine/binder/bound/ClassValue.java b/java/com/google/turbine/binder/bound/TurbineClassValue.java index a75db42..df55501 100644 --- a/java/com/google/turbine/binder/bound/ClassValue.java +++ b/java/com/google/turbine/binder/bound/TurbineClassValue.java @@ -21,11 +21,11 @@ import com.google.turbine.type.Type; import java.util.Objects; /** A class literal constant. */ -public class ClassValue extends Const { +public class TurbineClassValue extends Const { private final Type type; - public ClassValue(Type type) { + public TurbineClassValue(Type type) { this.type = type; } @@ -46,11 +46,11 @@ public class ClassValue extends Const { @Override public int hashCode() { - return Objects.hash(type); + return Objects.hashCode(type); } @Override public boolean equals(Object obj) { - return obj instanceof ClassValue && type().equals(((ClassValue) obj).type()); + return obj instanceof TurbineClassValue && type().equals(((TurbineClassValue) obj).type()); } } diff --git a/java/com/google/turbine/binder/bytecode/BytecodeBinder.java b/java/com/google/turbine/binder/bytecode/BytecodeBinder.java index e5ba343..1d2eecb 100644 --- a/java/com/google/turbine/binder/bytecode/BytecodeBinder.java +++ b/java/com/google/turbine/binder/bytecode/BytecodeBinder.java @@ -19,9 +19,9 @@ package com.google.turbine.binder.bytecode; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.turbine.binder.bound.AnnotationValue; -import com.google.turbine.binder.bound.ClassValue; import com.google.turbine.binder.bound.EnumConstantValue; import com.google.turbine.binder.bound.ModuleInfo; +import com.google.turbine.binder.bound.TurbineClassValue; import com.google.turbine.binder.sym.ClassSymbol; import com.google.turbine.binder.sym.FieldSymbol; import com.google.turbine.binder.sym.TyVarSymbol; @@ -29,7 +29,7 @@ import com.google.turbine.bytecode.ClassFile; import com.google.turbine.bytecode.ClassFile.AnnotationInfo; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ArrayValue; -import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstClassValue; +import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstTurbineClassValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.EnumConstValue; import com.google.turbine.bytecode.ClassReader; @@ -118,9 +118,9 @@ public class BytecodeBinder { case ARRAY: return bindArrayValue(type, (ArrayValue) value); case CLASS: - return new ClassValue( + return new TurbineClassValue( bindTy( - new SigParser(((ConstClassValue) value).className()).parseType(), + new SigParser(((ConstTurbineClassValue) value).className()).parseType(), x -> { throw new IllegalStateException(x); })); diff --git a/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java b/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java index 962c5b4..6ff8cb4 100644 --- a/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java +++ b/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java @@ -37,7 +37,7 @@ import com.google.turbine.bytecode.ClassFile; import com.google.turbine.bytecode.ClassFile.AnnotationInfo; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ArrayValue; -import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstClassValue; +import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstTurbineClassValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.EnumConstValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.Kind; import com.google.turbine.bytecode.ClassFile.MethodInfo.ParameterInfo; @@ -530,7 +530,7 @@ public class BytecodeBoundClass implements BoundClass, HeaderBoundClass, TypeBou ElementValue val = annotation.elementValuePairs().get("value"); switch (val.kind()) { case CLASS: - String className = ((ConstClassValue) val).className(); + String className = ((ConstTurbineClassValue) val).className(); return new ClassSymbol(className.substring(1, className.length() - 1)); default: break; diff --git a/java/com/google/turbine/bytecode/AnnotationWriter.java b/java/com/google/turbine/bytecode/AnnotationWriter.java index b52cc5e..868b548 100644 --- a/java/com/google/turbine/bytecode/AnnotationWriter.java +++ b/java/com/google/turbine/bytecode/AnnotationWriter.java @@ -22,7 +22,7 @@ import com.google.turbine.bytecode.ClassFile.AnnotationInfo; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.AnnotationValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ArrayValue; -import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstClassValue; +import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstTurbineClassValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.EnumConstValue; import com.google.turbine.bytecode.ClassFile.TypeAnnotationInfo; @@ -65,7 +65,7 @@ public class AnnotationWriter { writeEnumElementValue((EnumConstValue) value); break; case CLASS: - writeClassElementValue((ConstClassValue) value); + writeClassElementValue((ConstTurbineClassValue) value); break; case ARRAY: writeArrayElementValue((ArrayValue) value); @@ -123,7 +123,7 @@ public class AnnotationWriter { output.writeShort(pool.utf8(value.constName())); } - private void writeClassElementValue(ConstClassValue value) { + private void writeClassElementValue(ConstTurbineClassValue value) { output.writeByte('c'); output.writeShort(pool.utf8(value.className())); } diff --git a/java/com/google/turbine/bytecode/ClassFile.java b/java/com/google/turbine/bytecode/ClassFile.java index b418d70..54b6983 100644 --- a/java/com/google/turbine/bytecode/ClassFile.java +++ b/java/com/google/turbine/bytecode/ClassFile.java @@ -448,11 +448,11 @@ public class ClassFile { } /** A constant class literal value. */ - class ConstClassValue implements ElementValue { + class ConstTurbineClassValue implements ElementValue { private final String className; - public ConstClassValue(String className) { + public ConstTurbineClassValue(String className) { this.className = className; } diff --git a/java/com/google/turbine/bytecode/ClassReader.java b/java/com/google/turbine/bytecode/ClassReader.java index 47f4ff5..a894997 100644 --- a/java/com/google/turbine/bytecode/ClassReader.java +++ b/java/com/google/turbine/bytecode/ClassReader.java @@ -22,7 +22,7 @@ import com.google.errorprone.annotations.CheckReturnValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.AnnotationValue; -import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstClassValue; +import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstTurbineClassValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.ConstValue; import com.google.turbine.bytecode.ClassFile.AnnotationInfo.ElementValue.EnumConstValue; import com.google.turbine.bytecode.ClassFile.MethodInfo.ParameterInfo; @@ -34,7 +34,6 @@ import com.google.turbine.bytecode.ClassFile.ModuleInfo.RequireInfo; import com.google.turbine.bytecode.ClassFile.ModuleInfo.UseInfo; import com.google.turbine.model.Const; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.checkerframework.checker.nullness.qual.Nullable; @@ -101,7 +100,7 @@ public class ClassReader { List<ClassFile.MethodInfo> methodinfos = readMethods(constantPool); String signature = null; - List<ClassFile.InnerClass> innerclasses = Collections.emptyList(); + List<ClassFile.InnerClass> innerclasses = ImmutableList.of(); ImmutableList.Builder<ClassFile.AnnotationInfo> annotations = ImmutableList.builder(); ClassFile.ModuleInfo module = null; int attributesCount = reader.u2(); @@ -346,7 +345,7 @@ public class ClassReader { { int classInfoIndex = reader.u2(); String className = constantPool.utf8(classInfoIndex); - return new ConstClassValue(className); + return new ConstTurbineClassValue(className); } case '@': return new AnnotationValue(readAnnotation(constantPool)); diff --git a/java/com/google/turbine/lower/Lower.java b/java/com/google/turbine/lower/Lower.java index fe93a62..16447ab 100644 --- a/java/com/google/turbine/lower/Lower.java +++ b/java/com/google/turbine/lower/Lower.java @@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.turbine.binder.bound.AnnotationValue; -import com.google.turbine.binder.bound.ClassValue; import com.google.turbine.binder.bound.EnumConstantValue; import com.google.turbine.binder.bound.ModuleInfo.ExportInfo; import com.google.turbine.binder.bound.ModuleInfo.OpenInfo; @@ -34,6 +33,7 @@ import com.google.turbine.binder.bound.ModuleInfo.RequireInfo; import com.google.turbine.binder.bound.ModuleInfo.UseInfo; import com.google.turbine.binder.bound.SourceModuleInfo; import com.google.turbine.binder.bound.SourceTypeBoundClass; +import com.google.turbine.binder.bound.TurbineClassValue; import com.google.turbine.binder.bound.TypeBoundClass; import com.google.turbine.binder.bound.TypeBoundClass.FieldInfo; import com.google.turbine.binder.bound.TypeBoundClass.MethodInfo; @@ -79,7 +79,6 @@ import com.google.turbine.types.Erasure; import java.lang.annotation.RetentionPolicy; import java.util.ArrayDeque; import java.util.ArrayList; -import java.util.Collections; import java.util.Deque; import java.util.LinkedHashSet; import java.util.List; @@ -373,7 +372,7 @@ public class Lower { private ClassFile.FieldInfo lowerField(FieldInfo f) { final String name = f.name(); - Function<TyVarSymbol, TyVarInfo> tenv = new TyVarEnv(Collections.emptyMap()); + Function<TyVarSymbol, TyVarInfo> tenv = new TyVarEnv(ImmutableMap.of()); String desc = SigWriter.type(sig.signature(Erasure.erase(f.type(), tenv))); String signature = sig.fieldSignature(f.type()); @@ -543,8 +542,9 @@ public class Lower { switch (value.kind()) { case CLASS_LITERAL: { - ClassValue classValue = (ClassValue) value; - return new ElementValue.ConstClassValue(SigWriter.type(sig.signature(classValue.type()))); + TurbineClassValue classValue = (TurbineClassValue) value; + return new ElementValue.ConstTurbineClassValue( + SigWriter.type(sig.signature(classValue.type()))); } case ENUM_CONSTANT: { diff --git a/java/com/google/turbine/main/Main.java b/java/com/google/turbine/main/Main.java index 03a68ce..34421e1 100644 --- a/java/com/google/turbine/main/Main.java +++ b/java/com/google/turbine/main/Main.java @@ -16,10 +16,12 @@ package com.google.turbine.main; +import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.collect.ImmutableList; import com.google.common.hash.Hashing; +import com.google.common.io.MoreFiles; import com.google.turbine.binder.Binder; import com.google.turbine.binder.Binder.BindingResult; import com.google.turbine.binder.ClassPath; @@ -145,7 +147,7 @@ public class Main { if (options.release().isPresent()) { String release = options.release().get(); - if (release.equals(System.getProperty("java.specification.version"))) { + if (release.equals(JAVA_SPECIFICATION_VERSION.value())) { // if --release matches the host JDK, use its jimage instead of ct.sym return JimageClassBinder.bindDefault(); } @@ -172,7 +174,7 @@ public class Main { ImmutableList.Builder<CompUnit> units = ImmutableList.builder(); for (String source : options.sources()) { Path path = Paths.get(source); - units.add(Parser.parse(new SourceFile(source, new String(Files.readAllBytes(path), UTF_8)))); + units.add(Parser.parse(new SourceFile(source, MoreFiles.asCharSource(path, UTF_8).read()))); } for (String sourceJar : options.sourceJars()) { for (Zip.Entry ze : new Zip.ZipIterable(Paths.get(sourceJar))) { diff --git a/java/com/google/turbine/type/Type.java b/java/com/google/turbine/type/Type.java index 3bf47d6..8950ec0 100644 --- a/java/com/google/turbine/type/Type.java +++ b/java/com/google/turbine/type/Type.java @@ -19,6 +19,7 @@ package com.google.turbine.type; import com.google.auto.value.AutoValue; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; import com.google.turbine.binder.sym.ClassSymbol; import com.google.turbine.binder.sym.TyVarSymbol; import com.google.turbine.model.TurbineConstantTypeKind; @@ -100,7 +101,7 @@ public interface Type { /** The class symbol. */ public ClassSymbol sym() { - return classes().get(classes().size() - 1).sym(); + return Iterables.getLast(classes()).sym(); } @Override diff --git a/java/com/google/turbine/types/Canonicalize.java b/java/com/google/turbine/types/Canonicalize.java index e133ab0..ab73618 100644 --- a/java/com/google/turbine/types/Canonicalize.java +++ b/java/com/google/turbine/types/Canonicalize.java @@ -157,7 +157,7 @@ public class Canonicalize { private Collection<ClassTy.SimpleClassTy> lexicalBase(ClassSymbol first, ClassSymbol owner) { if ((getInfo(first).access() & TurbineFlag.ACC_STATIC) == TurbineFlag.ACC_STATIC) { - return Collections.emptyList(); + return ImmutableList.of(); } ClassSymbol canonOwner = getInfo(first).owner(); Deque<ClassTy.SimpleClassTy> result = new ArrayDeque<>(); |