aboutsummaryrefslogtreecommitdiff
path: root/java/com/google/turbine/binder/TypeBinder.java
diff options
context:
space:
mode:
authorcushon <cushon@google.com>2016-11-29 12:05:31 -0800
committerLiam Miller-Cushon <cushon@google.com>2016-11-30 15:55:12 -0800
commitd6310c5080e37e61d7a21a0e91329e99b3b7ff8d (patch)
tree99010b5826a193f9b1fc768477eb472312d80894 /java/com/google/turbine/binder/TypeBinder.java
parent4d8df55924dbbb3b931303fd95b73eaf6280b5f3 (diff)
downloadturbine-d6310c5080e37e61d7a21a0e91329e99b3b7ff8d.tar.gz
Match javac's method and field order
and stop sorting method and fields in integration tests. This isn't strictly necessary, but it avoids a source of churn when comparing compile-time artifacts produced by javac-turbine and the real implementation. MOE_MIGRATED_REVID=140509052
Diffstat (limited to 'java/com/google/turbine/binder/TypeBinder.java')
-rw-r--r--java/com/google/turbine/binder/TypeBinder.java108
1 files changed, 53 insertions, 55 deletions
diff --git a/java/com/google/turbine/binder/TypeBinder.java b/java/com/google/turbine/binder/TypeBinder.java
index 45d4abc..62249ca 100644
--- a/java/com/google/turbine/binder/TypeBinder.java
+++ b/java/com/google/turbine/binder/TypeBinder.java
@@ -43,6 +43,8 @@ import com.google.turbine.model.TurbineTyKind;
import com.google.turbine.model.TurbineVisibility;
import com.google.turbine.tree.Tree;
import com.google.turbine.tree.Tree.ClassTy;
+import com.google.turbine.tree.Tree.Kind;
+import com.google.turbine.tree.Tree.MethDecl;
import com.google.turbine.tree.Tree.PrimTy;
import com.google.turbine.tree.TurbineModifier;
import com.google.turbine.type.AnnoInfo;
@@ -210,8 +212,11 @@ public class TypeBinder {
CompoundScope scope = base.scope().append(new ClassMemberScope(owner, env));
- List<MethodInfo> methods = bindMethods(scope, base.decl().members());
- addSyntheticMethods(methods);
+ List<MethodInfo> methods =
+ ImmutableList.<MethodInfo>builder()
+ .addAll(syntheticMethods())
+ .addAll(bindMethods(scope, base.decl().members()))
+ .build();
ImmutableList<FieldInfo> fields = bindFields(scope, base.decl().members());
@@ -236,23 +241,21 @@ public class TypeBinder {
base.source());
}
- /** Add synthetic and implicit methods, including default constructors and enum methods. */
- void addSyntheticMethods(List<MethodInfo> methods) {
+ /** Collect synthetic and implicit methods, including default constructors and enum methods. */
+ ImmutableList<MethodInfo> syntheticMethods() {
switch (base.kind()) {
case CLASS:
- maybeAddDefaultConstructor(methods);
- break;
+ return maybeDefaultConstructor();
case ENUM:
- addEnumMethods(methods);
- break;
+ return syntheticEnumMethods();
default:
- break;
+ return ImmutableList.of();
}
}
- private void maybeAddDefaultConstructor(List<MethodInfo> methods) {
- if (hasConstructor(methods)) {
- return;
+ private ImmutableList<MethodInfo> maybeDefaultConstructor() {
+ if (hasConstructor()) {
+ return ImmutableList.of();
}
ImmutableList<ParamInfo> formals;
if (hasEnclosingInstance(base)) {
@@ -260,23 +263,27 @@ public class TypeBinder {
} else {
formals = ImmutableList.of();
}
- int access = TurbineVisibility.fromAccess(base.access()).flag();
+ return ImmutableList.of(
+ syntheticConstructor(formals, TurbineVisibility.fromAccess(base.access())));
+ }
+
+ private MethodInfo syntheticConstructor(
+ ImmutableList<ParamInfo> formals, TurbineVisibility visibility) {
+ int access = visibility.flag();
if (isStrictFp) {
access |= TurbineFlag.ACC_STRICT;
}
- access |= TurbineFlag.ACC_SYNTH_CTOR;
- methods.add(
- new MethodInfo(
- new MethodSymbol(owner, "<init>"),
- ImmutableMap.of(),
- Type.VOID,
- formals,
- ImmutableList.of(),
- access,
- null,
- null,
- ImmutableList.of(),
- null));
+ return new MethodInfo(
+ new MethodSymbol(owner, "<init>"),
+ ImmutableMap.of(),
+ Type.VOID,
+ formals,
+ ImmutableList.of(),
+ access | TurbineFlag.ACC_SYNTH_CTOR,
+ null,
+ null,
+ ImmutableList.of(),
+ null);
}
private ParamInfo enclosingInstanceParameter() {
@@ -318,59 +325,50 @@ public class TypeBinder {
/*synthetic*/
TurbineFlag.ACC_SYNTHETIC));
- private void addEnumMethods(List<MethodInfo> methods) {
+ private ImmutableList<MethodInfo> syntheticEnumMethods() {
+ ImmutableList.Builder<MethodInfo> methods = ImmutableList.builder();
int access = 0;
if (isStrictFp) {
access |= TurbineFlag.ACC_STRICT;
}
-
- if (!hasConstructor(methods)) {
- methods.add(
- new MethodInfo(
- new MethodSymbol(owner, "<init>"),
- ImmutableMap.of(),
- Type.VOID,
- ENUM_CTOR_PARAMS,
- ImmutableList.of(),
- access | TurbineFlag.ACC_PRIVATE | TurbineFlag.ACC_SYNTH_CTOR,
- null,
- null,
- ImmutableList.of(),
- null));
+ if (!hasConstructor()) {
+ methods.add(syntheticConstructor(ENUM_CTOR_PARAMS, TurbineVisibility.PRIVATE));
}
-
methods.add(
new MethodInfo(
- new MethodSymbol(owner, "valueOf"),
+ new MethodSymbol(owner, "values"),
ImmutableMap.of(),
- Type.ClassTy.asNonParametricClassTy(owner),
- ImmutableList.of(
- new ParamInfo(
- Type.ClassTy.STRING, "name", ImmutableList.of(), TurbineFlag.ACC_MANDATED)),
+ new Type.ArrayTy(Type.ClassTy.asNonParametricClassTy(owner), ImmutableList.of()),
+ ImmutableList.of(),
ImmutableList.of(),
access | TurbineFlag.ACC_PUBLIC | TurbineFlag.ACC_STATIC,
null,
null,
ImmutableList.of(),
null));
-
methods.add(
new MethodInfo(
- new MethodSymbol(owner, "values"),
+ new MethodSymbol(owner, "valueOf"),
ImmutableMap.of(),
- new Type.ArrayTy(Type.ClassTy.asNonParametricClassTy(owner), ImmutableList.of()),
- ImmutableList.of(),
+ Type.ClassTy.asNonParametricClassTy(owner),
+ ImmutableList.of(
+ new ParamInfo(
+ Type.ClassTy.STRING, "name", ImmutableList.of(), TurbineFlag.ACC_MANDATED)),
ImmutableList.of(),
access | TurbineFlag.ACC_PUBLIC | TurbineFlag.ACC_STATIC,
null,
null,
ImmutableList.of(),
null));
+ return methods.build();
}
- private static boolean hasConstructor(List<MethodInfo> methods) {
- for (MethodInfo m : methods) {
- if (m.name().equals("<init>")) {
+ private boolean hasConstructor() {
+ for (Tree m : base.decl().members()) {
+ if (m.kind() != Kind.METH_DECL) {
+ continue;
+ }
+ if (((MethDecl) m).name().equals("<init>")) {
return true;
}
}
@@ -503,7 +501,7 @@ public class TypeBinder {
if (isStrictFp && (access & TurbineFlag.ACC_ABSTRACT) == 0) {
access |= TurbineFlag.ACC_STRICT;
}
-
+
ImmutableList<AnnoInfo> annotations = bindAnnotations(scope, t.annos());
return new MethodInfo(
sym,