Permalink
Browse files

Overcame trait/protected/java limitation.

I think this fixes SI-2296, the inability to access java protected
members from a trait which extends a java class. Counterexamples
appreciated. Closes SI-2296. Review by @dragos.

cherry-picked and adapted from f708b87.
  • Loading branch information...
paulp authored and hubertp committed Mar 4, 2012
1 parent dcf6976 commit de82f9a04a69a68118c513bda2bee9cd03560db0

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -183,6 +183,20 @@ import Flags._
def hasTraitFlag = hasFlag(TRAIT)
def hasDefaultFlag = hasFlag(DEFAULTPARAM)
+ def accessString: String = {
+ val pw = if (hasAccessBoundary) privateWithin.toString else ""
+
+ if (pw == "") {
+ if (hasAllFlags(PRIVATE | LOCAL)) "private[this]"
+ else if (hasAllFlags(PROTECTED | LOCAL)) "protected[this]"
+ else if (hasFlag(PRIVATE)) "private"
+ else if (hasFlag(PROTECTED)) "protected"
+ else ""
+ }
+ else if (hasFlag(PROTECTED)) "protected[" + pw + "]"
+ else "private[" + pw + "]"
+ }
+
// Straightforwardly named accessors already being used differently.
// These names are most likely temporary.
def hasAbstractFlag = hasFlag(ABSTRACT)
@@ -0,0 +1,2 @@
+J.foo()
+J.foo()
@@ -0,0 +1,7 @@
+package j;
+
+public class J {
+ protected void foo() {
+ System.out.println("J.foo()");
+ }
+}
@@ -0,0 +1,18 @@
+package s {
+ import j.J
+
+ trait S extends J {
+ def bar() {
+ foo()
+ }
+ }
+
+ class SC extends J with S
+}
+
+object Test {
+ def main(args : Array[String]) {
+ (new s.SC).bar()
+ (new s.S { }).bar()
+ }
+}
@@ -0,0 +1,2 @@
+J.foo()
+J.foo()
@@ -0,0 +1,7 @@
+package j;
+
+public class J_1 {
+ protected void foo() {
+ System.out.println("J.foo()");
+ }
+}
@@ -0,0 +1,18 @@
+package s {
+ import j.J_1
+
+ trait S extends J_1 {
+ def bar() {
+ foo()
+ }
+ }
+
+ class SC extends J_1 with S
+}
+
+object Test {
+ def main(args : Array[String]) {
+ (new s.SC).bar()
+ (new s.S { }).bar()
+ }
+}

0 comments on commit de82f9a

Please sign in to comment.