< prev index next >

test/runtime/Nestmates/privateMethods/TestInvoke.java

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8046171
  27  * @summary Test access to private methods between nestmates and nest-top
  28  *          using different flavours of named nested types
  29  * @compile -XDdisablePrivateAccessors TestInvoke.java
  30  * @run main TestInvoke
  31  */
  32 
  33 public class TestInvoke {
  34 
  35     // Private method of nest-top for nestmates to access
  36     private void priv_invoke() {
  37         System.out.println("TestInvoke::priv_invoke");
  38     }
  39 
  40     // public constructor so we aren't relying on private access
  41     public TestInvoke() {}
  42 
  43     // Methods that will access private methods of nestmates
  44 
  45     void access_priv(TestInvoke o) {
  46         o.priv_invoke();
  47     }
  48     void access_priv(InnerNested o) {
  49         o.priv_invoke();


  96         void access_priv(InnerNested o) {
  97             o.priv_invoke();
  98         }
  99         void access_priv(StaticNested o) {
 100             o.priv_invoke();
 101         }
 102         void access_priv(StaticIface o) {
 103             o.priv_invoke();
 104         }
 105     }
 106 
 107     class InnerNested {
 108 
 109         private void priv_invoke() {
 110             System.out.println("InnerNested::priv_invoke");
 111         }
 112 
 113         // public constructor so we aren't relying on private access
 114         public InnerNested() {}
 115 



 116         void access_priv(TestInvoke o) {
 117             o.priv_invoke();
 118         }
 119         void access_priv(InnerNested o) {
 120             o.priv_invoke();
 121         }
 122         void access_priv(StaticNested o) {
 123             o.priv_invoke();
 124         }
 125         void access_priv(StaticIface o) {
 126             o.priv_invoke();
 127         }
 128     }
 129 
 130     public static void main(String[] args) {
 131         TestInvoke o = new TestInvoke();
 132         StaticNested s = new StaticNested();
 133         InnerNested i = o.new InnerNested();
 134         StaticIface intf = new StaticIface() {};
 135 
 136         o.access_priv(new TestInvoke());
 137         o.access_priv(i);
 138         o.access_priv(s);
 139         o.access_priv(intf);
 140 
 141         s.access_priv(o);
 142         s.access_priv(i);
 143         s.access_priv(new StaticNested());
 144         s.access_priv(intf);
 145 

 146         i.access_priv(o);
 147         i.access_priv(o.new InnerNested());
 148         i.access_priv(s);
 149         i.access_priv(intf);
 150 
 151         intf.access_priv(o);
 152         intf.access_priv(i);
 153         intf.access_priv(s);
 154         intf.access_priv(new StaticIface(){});
 155     }
 156 }


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8046171
  27  * @summary Test access to private methods between nestmates and nest-top
  28  *          using different flavours of named nested types

  29   * @run main TestInvoke
  30  */
  31 
  32 public class TestInvoke {
  33 
  34     // Private method of nest-top for nestmates to access
  35     private void priv_invoke() {
  36         System.out.println("TestInvoke::priv_invoke");
  37     }
  38 
  39     // public constructor so we aren't relying on private access
  40     public TestInvoke() {}
  41 
  42     // Methods that will access private methods of nestmates
  43 
  44     void access_priv(TestInvoke o) {
  45         o.priv_invoke();
  46     }
  47     void access_priv(InnerNested o) {
  48         o.priv_invoke();


  95         void access_priv(InnerNested o) {
  96             o.priv_invoke();
  97         }
  98         void access_priv(StaticNested o) {
  99             o.priv_invoke();
 100         }
 101         void access_priv(StaticIface o) {
 102             o.priv_invoke();
 103         }
 104     }
 105 
 106     class InnerNested {
 107 
 108         private void priv_invoke() {
 109             System.out.println("InnerNested::priv_invoke");
 110         }
 111 
 112         // public constructor so we aren't relying on private access
 113         public InnerNested() {}
 114 
 115         void access_priv() {
 116             TestInvoke.this.priv_invoke(); // check this$0 access
 117         }
 118         void access_priv(TestInvoke o) {
 119             o.priv_invoke();
 120         }
 121         void access_priv(InnerNested o) {
 122             o.priv_invoke();
 123         }
 124         void access_priv(StaticNested o) {
 125             o.priv_invoke();
 126         }
 127         void access_priv(StaticIface o) {
 128             o.priv_invoke();
 129         }
 130     }
 131 
 132     public static void main(String[] args) {
 133         TestInvoke o = new TestInvoke();
 134         StaticNested s = new StaticNested();
 135         InnerNested i = o.new InnerNested();
 136         StaticIface intf = new StaticIface() {};
 137 
 138         o.access_priv(new TestInvoke());
 139         o.access_priv(i);
 140         o.access_priv(s);
 141         o.access_priv(intf);
 142 
 143         s.access_priv(o);
 144         s.access_priv(i);
 145         s.access_priv(new StaticNested());
 146         s.access_priv(intf);
 147 
 148         i.access_priv();
 149         i.access_priv(o);
 150         i.access_priv(o.new InnerNested());
 151         i.access_priv(s);
 152         i.access_priv(intf);
 153 
 154         intf.access_priv(o);
 155         intf.access_priv(i);
 156         intf.access_priv(s);
 157         intf.access_priv(new StaticIface(){});
 158     }
 159 }
< prev index next >