summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-02-08 02:34:46 -0800
committerEugene Burmako <xeno.by@gmail.com>2013-02-08 02:34:46 -0800
commit9164c2af4183e04986eb652e09081daba3d0d279 (patch)
treead7040b0d065ccc05d819b3fe658cf144227bd14 /src
parent3d75d217b2cc9199c2698ed8da100fe92b1db2be (diff)
parentb43ae58f312e4769de5a6942b4cb820cd609f31b (diff)
downloadscala-9164c2af4183e04986eb652e09081daba3d0d279.tar.gz
scala-9164c2af4183e04986eb652e09081daba3d0d279.tar.bz2
scala-9164c2af4183e04986eb652e09081daba3d0d279.zip
Merge pull request #2035 from scalamacros/ticket/6989
SI-6989 privateWithin is now populated in reflect
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala21
-rw-r--r--src/reflect/scala/reflect/internal/PrivateWithin.scala23
-rw-r--r--src/reflect/scala/reflect/internal/SymbolTable.scala1
-rw-r--r--src/reflect/scala/reflect/runtime/JavaMirrors.scala5
4 files changed, 33 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index 976f7e038b..a517a33279 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -548,8 +548,8 @@ abstract class ClassfileParser {
skipMembers() // methods
if (!isScala) {
clazz setFlag sflags
- setPrivateWithin(clazz, jflags)
- setPrivateWithin(staticModule, jflags)
+ importPrivateWithinFromJavaFlags(clazz, jflags)
+ importPrivateWithinFromJavaFlags(staticModule, jflags)
clazz.setInfo(classInfo)
moduleClass setInfo staticInfo
staticModule.setInfo(moduleClass.tpe)
@@ -612,7 +612,7 @@ abstract class ClassfileParser {
if (isEnum) ConstantType(Constant(sym))
else info
}
- setPrivateWithin(sym, jflags)
+ importPrivateWithinFromJavaFlags(sym, jflags)
parseAttributes(sym, info)
getScope(jflags).enter(sym)
@@ -663,7 +663,7 @@ abstract class ClassfileParser {
info = MethodType(newParams, clazz.tpe)
}
sym.setInfo(info)
- setPrivateWithin(sym, jflags)
+ importPrivateWithinFromJavaFlags(sym, jflags)
parseAttributes(sym, info)
if ((jflags & JAVA_ACC_VARARGS) != 0) {
sym.setInfo(arrayToRepeated(sym.info))
@@ -1264,19 +1264,6 @@ abstract class ClassfileParser {
protected def getScope(flags: Int): Scope =
if (isStatic(flags)) staticScope else instanceScope
- private def setPrivateWithin(sym: Symbol, jflags: Int) {
- if ((jflags & (JAVA_ACC_PRIVATE | JAVA_ACC_PROTECTED | JAVA_ACC_PUBLIC)) == 0)
- // See ticket #1687 for an example of when topLevelClass is NoSymbol: it
- // apparently occurs when processing v45.3 bytecode.
- if (sym.enclosingTopLevelClass != NoSymbol)
- sym.privateWithin = sym.enclosingTopLevelClass.owner
-
- // protected in java means package protected. #3946
- if ((jflags & JAVA_ACC_PROTECTED) != 0)
- if (sym.enclosingTopLevelClass != NoSymbol)
- sym.privateWithin = sym.enclosingTopLevelClass.owner
- }
-
private def isPrivate(flags: Int) = (flags & JAVA_ACC_PRIVATE) != 0
private def isStatic(flags: Int) = (flags & JAVA_ACC_STATIC) != 0
private def hasAnnotation(flags: Int) = (flags & JAVA_ACC_ANNOTATION) != 0
diff --git a/src/reflect/scala/reflect/internal/PrivateWithin.scala b/src/reflect/scala/reflect/internal/PrivateWithin.scala
new file mode 100644
index 0000000000..9b99b94b41
--- /dev/null
+++ b/src/reflect/scala/reflect/internal/PrivateWithin.scala
@@ -0,0 +1,23 @@
+package scala.reflect
+package internal
+
+import ClassfileConstants._
+
+trait PrivateWithin {
+ self: SymbolTable =>
+
+ def importPrivateWithinFromJavaFlags(sym: Symbol, jflags: Int): Symbol = {
+ if ((jflags & (JAVA_ACC_PRIVATE | JAVA_ACC_PROTECTED | JAVA_ACC_PUBLIC)) == 0)
+ // See ticket #1687 for an example of when topLevelClass is NoSymbol: it
+ // apparently occurs when processing v45.3 bytecode.
+ if (sym.enclosingTopLevelClass != NoSymbol)
+ sym.privateWithin = sym.enclosingTopLevelClass.owner
+
+ // protected in java means package protected. #3946
+ if ((jflags & JAVA_ACC_PROTECTED) != 0)
+ if (sym.enclosingTopLevelClass != NoSymbol)
+ sym.privateWithin = sym.enclosingTopLevelClass.owner
+
+ sym
+ }
+} \ No newline at end of file
diff --git a/src/reflect/scala/reflect/internal/SymbolTable.scala b/src/reflect/scala/reflect/internal/SymbolTable.scala
index 02ac59a461..f75855f1ec 100644
--- a/src/reflect/scala/reflect/internal/SymbolTable.scala
+++ b/src/reflect/scala/reflect/internal/SymbolTable.scala
@@ -38,6 +38,7 @@ abstract class SymbolTable extends macros.Universe
with StdAttachments
with StdCreators
with BuildUtils
+ with PrivateWithin
{
val gen = new TreeGen { val global: SymbolTable.this.type = SymbolTable.this }
diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala
index ea2fc4afe9..778c826dc0 100644
--- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala
+++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala
@@ -639,6 +639,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
/** used to avoid cycles while initializing classes */
private var parentsLevel = 0
private var pendingLoadActions: List[() => Unit] = Nil
+ private val relatedSymbols = clazz +: (if (module != NoSymbol) List(module, module.moduleClass) else Nil)
override def load(sym: Symbol): Unit = {
debugInfo("completing from Java " + sym + "/" + clazz.fullName)//debug
@@ -650,6 +651,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
module.moduleClass setFlag (flags & PRIVATE | JAVA)
}
+ relatedSymbols foreach (importPrivateWithinFromJavaFlags(_, jclazz.getModifiers))
copyAnnotations(clazz, jclazz)
// to do: annotations to set also for module?
@@ -1068,6 +1070,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
.newValue(newTermName(jfield.getName), NoPosition, toScalaFieldFlags(jfield.getModifiers))
.setInfo(typeToScala(jfield.getGenericType))
fieldCache enter (jfield, field)
+ importPrivateWithinFromJavaFlags(field, jfield.getModifiers)
copyAnnotations(field, jfield)
field
}
@@ -1093,6 +1096,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
val paramtpes = jmeth.getGenericParameterTypes.toList map typeToScala
val resulttpe = typeToScala(jmeth.getGenericReturnType)
setMethType(meth, tparams, paramtpes, resulttpe)
+ importPrivateWithinFromJavaFlags(meth, jmeth.getModifiers)
copyAnnotations(meth, jmeth)
if ((jmeth.getModifiers & JAVA_ACC_VARARGS) != 0) meth.setInfo(arrayToRepeated(meth.info))
meth
@@ -1116,6 +1120,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
val paramtpes = jconstr.getGenericParameterTypes.toList map typeToScala
setMethType(constr, tparams, paramtpes, clazz.tpe)
constr setInfo GenPolyType(tparams, MethodType(clazz.newSyntheticValueParams(paramtpes), clazz.tpe))
+ importPrivateWithinFromJavaFlags(constr, jconstr.getModifiers)
copyAnnotations(constr, jconstr)
constr
}