diff options
author | Paul Phillips <paulp@improving.org> | 2012-05-11 10:25:34 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-05-11 10:26:29 -0700 |
commit | 807567230852bcadb98a91322bd348aae764801f (patch) | |
tree | e7efba8909d8c50b76a343192e6a0eb277c61527 | |
parent | 2422b064e7a52c04dfb2239fc8e7b9ffbab24251 (diff) | |
download | scala-807567230852bcadb98a91322bd348aae764801f.tar.gz scala-807567230852bcadb98a91322bd348aae764801f.tar.bz2 scala-807567230852bcadb98a91322bd348aae764801f.zip |
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.
-rw-r--r-- | src/compiler/scala/reflect/internal/StdNames.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/javac/JavaParsers.scala | 5 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 8 | ||||
-rw-r--r-- | test/files/pos/t2764/Ann.java | 5 | ||||
-rw-r--r-- | test/files/pos/t2764/Enum.java | 5 | ||||
-rw-r--r-- | test/files/pos/t2764/Use.scala | 6 |
6 files changed, 28 insertions, 2 deletions
diff --git a/src/compiler/scala/reflect/internal/StdNames.scala b/src/compiler/scala/reflect/internal/StdNames.scala index 0cdf65bd8f..bd4d9a9f34 100644 --- a/src/compiler/scala/reflect/internal/StdNames.scala +++ b/src/compiler/scala/reflect/internal/StdNames.scala @@ -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$. diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index 5c413243e8..f71e067366 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -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) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index ca4b1d3de8..e4b744dffc 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -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 diff --git a/test/files/pos/t2764/Ann.java b/test/files/pos/t2764/Ann.java new file mode 100644 index 0000000000..184fc6e864 --- /dev/null +++ b/test/files/pos/t2764/Ann.java @@ -0,0 +1,5 @@ +package bippy; + +public @interface Ann { + Enum value(); +} diff --git a/test/files/pos/t2764/Enum.java b/test/files/pos/t2764/Enum.java new file mode 100644 index 0000000000..fe07559535 --- /dev/null +++ b/test/files/pos/t2764/Enum.java @@ -0,0 +1,5 @@ +package bippy; + +public enum Enum { + VALUE; +} diff --git a/test/files/pos/t2764/Use.scala b/test/files/pos/t2764/Use.scala new file mode 100644 index 0000000000..8cf8102709 --- /dev/null +++ b/test/files/pos/t2764/Use.scala @@ -0,0 +1,6 @@ +package bippy + +class Use { + @Ann(Enum.VALUE) + def foo {} +} |