Permalink
Browse files

Recognize java enums as constants from source.

Fixed up one of the mismatches between how java source is modeled
and how java bytecode is modeled.  We should get the rest of them
too.  Closes SI-2764.
  • Loading branch information...
paulp committed May 11, 2012
1 parent 2422b06 commit 807567230852bcadb98a91322bd348aae764801f
@@ -766,7 +766,6 @@ trait StdNames {
object fulltpnme extends TypeNames {
val RuntimeNothing: NameType = "scala.runtime.Nothing$"
val RuntimeNull: NameType = "scala.runtime.Null$"
- val JavaLangEnum: NameType = "java.lang.Enum"
}
/** Java binary names, like scala/runtime/Nothing$.
@@ -872,7 +872,10 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
skipAhead()
accept(RBRACE)
}
- ValDef(Modifiers(Flags.JAVA | Flags.STATIC), name, enumType, blankExpr)
+ // The STABLE flag is to signal to namer that this was read from a
+ // java enum, and so should be given a Constant type (thereby making
+ // it usable in annotations.)
+ ValDef(Modifiers(Flags.STABLE | Flags.JAVA | Flags.STATIC), name, enumType, blankExpr)
}
}
@@ -567,7 +567,15 @@ trait Namers extends MethodSynthesis {
assignAndEnterFinishedSymbol(tree)
else
enterGetterSetter(tree)
+
+ // When java enums are read from bytecode, they are known to have
+ // constant types by the jvm flag and assigned accordingly. When
+ // they are read from source, the java parser marks them with the
+ // STABLE flag, and now we receive that signal.
+ if (tree.symbol hasAllFlags STABLE | JAVA)
+ tree.symbol setInfo ConstantType(Constant(tree.symbol))
}
+
def enterLazyVal(tree: ValDef, lazyAccessor: Symbol): TermSymbol = {
// If the owner is not a class, this is a lazy val from a method,
// with no associated field. It has an accessor with $lzy appended to its name and
@@ -0,0 +1,5 @@
+package bippy;
+
+public @interface Ann {
+ Enum value();
+}
@@ -0,0 +1,5 @@
+package bippy;
+
+public enum Enum {
+ VALUE;
+}
@@ -0,0 +1,6 @@
+package bippy
+
+class Use {
+ @Ann(Enum.VALUE)
+ def foo {}
+}

1 comment on commit 8075672

@lrytz

This comment has been minimized.

Show comment
Hide comment
@lrytz

lrytz May 12, 2012

Member

thanks paul for fixing this. for the second half of the ticket (using java static constants in annotations) i created a new issue (SI-5791).

Member

lrytz commented on 8075672 May 12, 2012

thanks paul for fixing this. for the second half of the ticket (using java static constants in annotations) i created a new issue (SI-5791).

Please sign in to comment.