aboutsummaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorcushon <cushon@google.com>2018-08-31 15:37:36 -0700
committerLiam Miller-Cushon <cushon@google.com>2018-09-09 16:48:49 -0700
commit02a8ec44df13dbc573c18b04f1e16242c62d319d (patch)
tree7ce33d948b96f961ab96309bd07d91a6c0966022 /java
parentde88247e48cea7efc588f35d37abedf920282e12 (diff)
downloadturbine-02a8ec44df13dbc573c18b04f1e16242c62d319d.tar.gz
Don't depend on the JDK's ElementType enum
in order to support Java 11 compilation with a JDK < 11 host javabase. MOE_MIGRATED_REVID=211155545
Diffstat (limited to 'java')
-rw-r--r--java/com/google/turbine/binder/ConstBinder.java12
-rw-r--r--java/com/google/turbine/binder/DisambiguateTypeAnnotations.java24
-rw-r--r--java/com/google/turbine/binder/bound/AnnotationMetadata.java18
-rw-r--r--java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java12
-rw-r--r--java/com/google/turbine/model/TurbineElementType.java32
5 files changed, 68 insertions, 30 deletions
diff --git a/java/com/google/turbine/binder/ConstBinder.java b/java/com/google/turbine/binder/ConstBinder.java
index 4b48dd3..f8783b3 100644
--- a/java/com/google/turbine/binder/ConstBinder.java
+++ b/java/com/google/turbine/binder/ConstBinder.java
@@ -37,6 +37,7 @@ import com.google.turbine.model.Const;
import com.google.turbine.model.Const.ArrayInitValue;
import com.google.turbine.model.Const.Kind;
import com.google.turbine.model.Const.Value;
+import com.google.turbine.model.TurbineElementType;
import com.google.turbine.model.TurbineFlag;
import com.google.turbine.model.TurbineTyKind;
import com.google.turbine.type.AnnoInfo;
@@ -50,7 +51,6 @@ import com.google.turbine.type.Type.WildLowerBoundedTy;
import com.google.turbine.type.Type.WildTy;
import com.google.turbine.type.Type.WildUnboundedTy;
import com.google.turbine.type.Type.WildUpperBoundedTy;
-import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;
import java.util.Map;
@@ -156,7 +156,7 @@ public class ConstBinder {
return null;
}
RetentionPolicy retention = null;
- ImmutableSet<ElementType> target = null;
+ ImmutableSet<TurbineElementType> target = null;
ClassSymbol repeatable = null;
for (AnnoInfo annotation : annotations) {
switch (annotation.sym().binaryName()) {
@@ -188,8 +188,8 @@ public class ConstBinder {
return RetentionPolicy.valueOf(enumValue.sym().name());
}
- private static ImmutableSet<ElementType> bindTarget(AnnoInfo annotation) {
- ImmutableSet.Builder<ElementType> result = ImmutableSet.builder();
+ private static ImmutableSet<TurbineElementType> bindTarget(AnnoInfo annotation) {
+ ImmutableSet.Builder<TurbineElementType> result = ImmutableSet.builder();
Const val = annotation.values().get("value");
switch (val.kind()) {
case ARRAY:
@@ -221,9 +221,9 @@ public class ConstBinder {
}
private static void bindTargetElement(
- ImmutableSet.Builder<ElementType> target, EnumConstantValue enumVal) {
+ ImmutableSet.Builder<TurbineElementType> target, EnumConstantValue enumVal) {
if (enumVal.sym().owner().binaryName().equals("java/lang/annotation/ElementType")) {
- target.add(ElementType.valueOf(enumVal.sym().name()));
+ target.add(TurbineElementType.valueOf(enumVal.sym().name()));
}
}
diff --git a/java/com/google/turbine/binder/DisambiguateTypeAnnotations.java b/java/com/google/turbine/binder/DisambiguateTypeAnnotations.java
index 26dce32..14c9866 100644
--- a/java/com/google/turbine/binder/DisambiguateTypeAnnotations.java
+++ b/java/com/google/turbine/binder/DisambiguateTypeAnnotations.java
@@ -34,6 +34,7 @@ import com.google.turbine.binder.sym.ClassSymbol;
import com.google.turbine.diag.TurbineError;
import com.google.turbine.diag.TurbineError.ErrorKind;
import com.google.turbine.model.Const;
+import com.google.turbine.model.TurbineElementType;
import com.google.turbine.type.AnnoInfo;
import com.google.turbine.type.Type;
import com.google.turbine.type.Type.ArrayTy;
@@ -41,7 +42,6 @@ import com.google.turbine.type.Type.ClassTy;
import com.google.turbine.type.Type.ClassTy.SimpleClassTy;
import com.google.turbine.type.Type.PrimTy;
import com.google.turbine.type.Type.TyVar;
-import java.lang.annotation.ElementType;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
@@ -101,7 +101,9 @@ public class DisambiguateTypeAnnotations {
Type returnType =
disambiguate(
env,
- base.name().equals("<init>") ? ElementType.CONSTRUCTOR : ElementType.METHOD,
+ base.name().equals("<init>")
+ ? TurbineElementType.CONSTRUCTOR
+ : TurbineElementType.METHOD,
base.returnType(),
base.annotations(),
declarationAnnotations);
@@ -131,7 +133,11 @@ public class DisambiguateTypeAnnotations {
ImmutableList.Builder<AnnoInfo> declarationAnnotations = ImmutableList.builder();
Type type =
disambiguate(
- env, ElementType.PARAMETER, base.type(), base.annotations(), declarationAnnotations);
+ env,
+ TurbineElementType.PARAMETER,
+ base.type(),
+ base.annotations(),
+ declarationAnnotations);
return new ParamInfo(type, base.name(), declarationAnnotations.build(), base.access());
}
@@ -141,7 +147,7 @@ public class DisambiguateTypeAnnotations {
*/
private static Type disambiguate(
Env<ClassSymbol, TypeBoundClass> env,
- ElementType declarationTarget,
+ TurbineElementType declarationTarget,
Type type,
ImmutableList<AnnoInfo> annotations,
Builder<AnnoInfo> declarationAnnotations) {
@@ -150,8 +156,8 @@ public class DisambiguateTypeAnnotations {
annotations = groupRepeated(env, annotations);
ImmutableList.Builder<AnnoInfo> typeAnnotations = ImmutableList.builder();
for (AnnoInfo anno : annotations) {
- Set<ElementType> target = env.get(anno.sym()).annotationMetadata().target();
- if (target.contains(ElementType.TYPE_USE)) {
+ Set<TurbineElementType> target = env.get(anno.sym()).annotationMetadata().target();
+ if (target.contains(TurbineElementType.TYPE_USE)) {
typeAnnotations.add(anno);
}
if (target.contains(declarationTarget)) {
@@ -174,7 +180,7 @@ public class DisambiguateTypeAnnotations {
ImmutableList.Builder<AnnoInfo> declarationAnnotations = ImmutableList.builder();
Type type =
disambiguate(
- env, ElementType.FIELD, base.type(), base.annotations(), declarationAnnotations);
+ env, TurbineElementType.FIELD, base.type(), base.annotations(), declarationAnnotations);
return new FieldInfo(
base.sym(), type, base.access(), declarationAnnotations.build(), base.decl(), base.value());
}
@@ -230,8 +236,8 @@ public class DisambiguateTypeAnnotations {
* <p>For example, convert {@code @Foo @Foo} to {@code @Foos({@Foo, @Foo})}.
*
* <p>This method is used by {@link DisambiguateTypeAnnotations} for declaration annotations, and
- * by {@link Lower} for type annotations. We could group type annotations here, but it would
- * require another rewrite pass.
+ * by {@link com.google.turbine.lower.Lower} for type annotations. We could group type annotations
+ * here, but it would require another rewrite pass.
*/
public static ImmutableList<AnnoInfo> groupRepeated(
Env<ClassSymbol, TypeBoundClass> env, ImmutableList<AnnoInfo> annotations) {
diff --git a/java/com/google/turbine/binder/bound/AnnotationMetadata.java b/java/com/google/turbine/binder/bound/AnnotationMetadata.java
index 1155e51..9c81a5f 100644
--- a/java/com/google/turbine/binder/bound/AnnotationMetadata.java
+++ b/java/com/google/turbine/binder/bound/AnnotationMetadata.java
@@ -20,7 +20,7 @@ import static com.google.common.base.MoreObjects.firstNonNull;
import com.google.common.collect.ImmutableSet;
import com.google.turbine.binder.sym.ClassSymbol;
-import java.lang.annotation.ElementType;
+import com.google.turbine.model.TurbineElementType;
import java.lang.annotation.RetentionPolicy;
import java.util.EnumSet;
@@ -30,22 +30,22 @@ import java.util.EnumSet;
*/
public class AnnotationMetadata {
- private static final ImmutableSet<ElementType> DEFAULT_TARGETS = getDefaultElements();
+ private static final ImmutableSet<TurbineElementType> DEFAULT_TARGETS = getDefaultElements();
- private static ImmutableSet<ElementType> getDefaultElements() {
- EnumSet<ElementType> values = EnumSet.allOf(ElementType.class);
- values.remove(ElementType.TYPE_PARAMETER);
- values.remove(ElementType.TYPE_USE);
+ private static ImmutableSet<TurbineElementType> getDefaultElements() {
+ EnumSet<TurbineElementType> values = EnumSet.allOf(TurbineElementType.class);
+ values.remove(TurbineElementType.TYPE_PARAMETER);
+ values.remove(TurbineElementType.TYPE_USE);
return ImmutableSet.copyOf(values);
}
private final RetentionPolicy retention;
- private final ImmutableSet<ElementType> target;
+ private final ImmutableSet<TurbineElementType> target;
private final ClassSymbol repeatable;
public AnnotationMetadata(
RetentionPolicy retention,
- ImmutableSet<ElementType> annotationTarget,
+ ImmutableSet<TurbineElementType> annotationTarget,
ClassSymbol repeatable) {
this.retention = firstNonNull(retention, RetentionPolicy.CLASS);
this.target = firstNonNull(annotationTarget, DEFAULT_TARGETS);
@@ -58,7 +58,7 @@ public class AnnotationMetadata {
}
/** Target element types specified by the {@code @Target} meta-annotation. */
- public ImmutableSet<ElementType> target() {
+ public ImmutableSet<TurbineElementType> target() {
return target;
}
diff --git a/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java b/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java
index cfab044..59e07d5 100644
--- a/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java
+++ b/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java
@@ -45,11 +45,11 @@ import com.google.turbine.bytecode.sig.Sig;
import com.google.turbine.bytecode.sig.Sig.ClassSig;
import com.google.turbine.bytecode.sig.SigParser;
import com.google.turbine.model.Const;
+import com.google.turbine.model.TurbineElementType;
import com.google.turbine.model.TurbineFlag;
import com.google.turbine.model.TurbineTyKind;
import com.google.turbine.type.Type;
import com.google.turbine.type.Type.ClassTy;
-import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;
import java.util.Map;
import java.util.function.Function;
@@ -415,7 +415,7 @@ public class BytecodeBoundClass implements BoundClass, HeaderBoundClass, TypeBou
return null;
}
RetentionPolicy retention = null;
- ImmutableSet<ElementType> target = null;
+ ImmutableSet<TurbineElementType> target = null;
ClassSymbol repeatable = null;
for (ClassFile.AnnotationInfo annotation : classFile.get().annotations()) {
switch (annotation.typeName()) {
@@ -448,8 +448,8 @@ public class BytecodeBoundClass implements BoundClass, HeaderBoundClass, TypeBou
return RetentionPolicy.valueOf(enumVal.constName());
}
- private static ImmutableSet<ElementType> bindTarget(AnnotationInfo annotation) {
- ImmutableSet.Builder<ElementType> result = ImmutableSet.builder();
+ private static ImmutableSet<TurbineElementType> bindTarget(AnnotationInfo annotation) {
+ ImmutableSet.Builder<TurbineElementType> result = ImmutableSet.builder();
ElementValue val = annotation.elementValuePairs().get("value");
switch (val.kind()) {
case ARRAY:
@@ -469,9 +469,9 @@ public class BytecodeBoundClass implements BoundClass, HeaderBoundClass, TypeBou
}
private static void bindTargetElement(
- ImmutableSet.Builder<ElementType> target, EnumConstValue enumVal) {
+ ImmutableSet.Builder<TurbineElementType> target, EnumConstValue enumVal) {
if (enumVal.typeName().equals("Ljava/lang/annotation/ElementType;")) {
- target.add(ElementType.valueOf(enumVal.constName()));
+ target.add(TurbineElementType.valueOf(enumVal.constName()));
}
}
diff --git a/java/com/google/turbine/model/TurbineElementType.java b/java/com/google/turbine/model/TurbineElementType.java
new file mode 100644
index 0000000..a68df3a
--- /dev/null
+++ b/java/com/google/turbine/model/TurbineElementType.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2018 Google Inc. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.turbine.model;
+
+/** Program locations where an annotation may appear. */
+public enum TurbineElementType {
+ ANNOTATION_TYPE,
+ CONSTRUCTOR,
+ FIELD,
+ LOCAL_VARIABLE,
+ METHOD,
+ MODULE,
+ PACKAGE,
+ PARAMETER,
+ TYPE,
+ TYPE_PARAMETER,
+ TYPE_USE
+}