summaryrefslogtreecommitdiff
path: root/test/files/jvm/protectedacc.scala
blob: 43d218fa89fd9a6c1afa5e48ff39af985e52bdd5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//############################################################################
// Test Java interaction with scala inner classes
//############################################################################

import java.io.{BufferedReader, File, FileWriter, InputStreamReader}

/** The entry point of this test. It has to come first,
 *  before the package declarations. The parser wouldn't want it
 *  any other way.
 */
object Test {
  def main(args: Array[String]): Unit = {
    val b = new p.b.B;
    val c = new b.C;
    c.m

    val ji = new p.b.JavaInteraction(Array('a', 'b', 'c'));
    (new ji.Inner).m;

    (new p.b.OuterObj.Inner).m
  }
}

package p {
  package a {

    class A {
      protected val x = 10;

      protected def meth1(x: Int) = x + 1;
      protected def meth1(x: Double) = x + 1
      protected def meth2(x: Int)(y: String) = y + (x - 1);
      protected def meth3 = Array(1, 2)

      protected def f[a](x: a) = x

      def getA: this.type = this;
    }

    /** Test type members */
    trait HighlighterXXX {
      type Node;
      protected def highlight(node : Node) : Unit;
    }

    /** Test type parameters */
    abstract class PolyA[a] {
      protected def m(x: a): Unit;

      class B {

        trait Node {
          def s: String = "";
        }
        protected def tie(x: Node): Unit = { x.s; () }
      }
    }

    /** bug 853, longer path members */
    class Global {
      abstract class Tree;
    }

    trait HasNSC {
      trait GlobalExt extends Global;
      val global : GlobalExt;
      import global._;
      protected def doTyped(tree : Tree): Tree = tree;
      def mkTree : Tree;
      doTyped(mkTree);
    }
  }

  package b {
    import a._;

    /** Test interaction with Scala inherited methods and currying. */
    class B extends A {
      class C {
        def m = {
          Console.println(x);
          Console.println("meth1(1) = " + meth1(1));
          Console.println("meth1(1.0) = " + meth1(1.0));
          // test accesses from closures
          for (x <- 1 until 3)
            Console.println("meth2(1)(1) = " + meth2(1)("prefix: "));

          Console.println("meth3 = " + meth3.getClass);

          val inc = meth2(1)_;
          Console.println("100 = " + inc("10"));

          Console.println("id(1) = " + f(1))
          Console.println("id('a') = " + f("a"))

          getA.x;
        }
      }
    }

    /** Test interaction with Java inherited protected fields. */
    class JavaInteraction(arr: Array[Char]) extends java.io.CharArrayReader(arr) {
      class Inner {
        def m = {
          Console.println("count before: " + count);
          count = count + 1;
          Console.println("count after: " + count);
        }
      }
    }

    /** Test interaction when outer is an object. */
    object OuterObj extends p.a.A {
      class Inner {
        def m = {
          Console.println(x);
          Console.println("meth1(1) = " + meth1(1));
          Console.println("meth2(1)(1) = " + meth2(1)("1"));

          val inc = meth2(1)_;
          Console.println("100 = " + inc("10"));

          getA.x;
        }
      }
    }

    trait ScalaAutoEditXXX extends HighlighterXXX {
      trait NodeImpl {
        def self : Node;
        highlight(self);
      }
    }

    abstract class X[T] extends PolyA[T] {

      trait Inner extends B {
        def self: T;
        def self2: Node;
        def getB: Inner;

        m(self)

        trait InnerInner {
          val g = getB
          g.tie(self2.asInstanceOf[g.Node])
        }
      }
    }

    trait ScalaTyperXXX extends HasNSC {
      val global : GlobalExt;
      import global._;
      trait XXX {
        def foo(tree : Tree) = doTyped(tree);
      }
    }
  }
}