< prev index next >

test/langtools/tools/javac/valhalla/nestmate/CheckNestmateAttrs.java

Print this page




   7  * published by the Free Software Foundation.
   8  *
   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  * @summary Smoke test for nestmate classfile support
  27  * @compile -XDdisableAccessors CheckNestmateAttrs.java
  28  * @run main CheckNestmateAttrs
  29  * @modules
  30  *      jdk.compiler
  31  *      jdk.jdeps/com.sun.tools.javap
  32  */
  33 
  34 import java.io.PrintWriter;
  35 import java.io.StringWriter;
  36 import java.nio.file.Paths;
  37 
  38 public class CheckNestmateAttrs {
  39 
  40     private void test() { }
  41 
  42     class Inner {
  43         void m() {
  44             class LocalInner {
  45                 void testInner() {
  46                     test();
  47                 }


  58     public static void main(String[] args) {
  59         new CheckNestmateAttrs().run();
  60     }
  61 
  62     void run() {
  63         String [] params = new String [] { "-v",
  64                                             Paths.get(System.getProperty("test.classes"),
  65                                                 "CheckNestmateAttrs.class").toString() };
  66         runCheck(params, new String [] {
  67                         "NestMembers:" +
  68                         "  CheckNestmateAttrs$Nested" +
  69                         "  CheckNestmateAttrs$Nested$1LocalNested" +
  70                         "  CheckNestmateAttrs$Inner" +
  71                         "  CheckNestmateAttrs$Inner$1LocalInner"
  72                         });
  73 
  74         params = new String [] { "-v",
  75                                  Paths.get(System.getProperty("test.classes"),
  76                                      "CheckNestmateAttrs$Inner.class").toString() };
  77 
  78         runCheck(params, new String [] { "MemberOfNest: class CheckNestmateAttrs" });
  79 
  80         params = new String [] { "-v",
  81                                  Paths.get(System.getProperty("test.classes"),
  82                                      "CheckNestmateAttrs$Nested.class").toString() };
  83 
  84         runCheck(params, new String [] { "MemberOfNest: class CheckNestmateAttrs" });
  85 
  86         params = new String [] { "-v",
  87                                  Paths.get(System.getProperty("test.classes"),
  88                                      "CheckNestmateAttrs$Inner$1LocalInner.class").toString() };
  89 
  90         runCheck(params, new String [] {
  91                         "MemberOfNest: class CheckNestmateAttrs",
  92                         "0: aload_0",
  93                         "1: getfield      #1                  // Field this$1:LCheckNestmateAttrs$Inner;",
  94                         "4: getfield      #3                  // Field CheckNestmateAttrs$Inner.this$0:LCheckNestmateAttrs;",
  95                         "7: invokespecial #4                  // Method CheckNestmateAttrs.test:()V",
  96                         "10: return"
  97         });
  98 
  99         params = new String [] { "-v",
 100                                  Paths.get(System.getProperty("test.classes"),
 101                                      "CheckNestmateAttrs$Nested$1LocalNested.class").toString() };
 102 
 103         runCheck(params, new String [] { "MemberOfNest: class CheckNestmateAttrs" });
 104      }
 105 
 106      void runCheck(String [] params, String [] expectedOut) {
 107         StringWriter s;
 108         String out;
 109 
 110         try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
 111             com.sun.tools.javap.Main.run(params, pw);
 112             out = s.toString();
 113         }
 114         for (String eo: expectedOut) {
 115             if (!out.contains(eo)) {
 116                 System.out.println("Actual output: " + out);
 117                 throw new AssertionError("Missing output: " + eo);
 118             }
 119         }
 120     }
 121 }


   7  * published by the Free Software Foundation.
   8  *
   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  * @summary Smoke test for nestmate classfile support

  27  * @run main CheckNestmateAttrs
  28  * @modules
  29  *      jdk.compiler
  30  *      jdk.jdeps/com.sun.tools.javap
  31  */
  32 
  33 import java.io.PrintWriter;
  34 import java.io.StringWriter;
  35 import java.nio.file.Paths;
  36 
  37 public class CheckNestmateAttrs {
  38 
  39     private void test() { }
  40 
  41     class Inner {
  42         void m() {
  43             class LocalInner {
  44                 void testInner() {
  45                     test();
  46                 }


  57     public static void main(String[] args) {
  58         new CheckNestmateAttrs().run();
  59     }
  60 
  61     void run() {
  62         String [] params = new String [] { "-v",
  63                                             Paths.get(System.getProperty("test.classes"),
  64                                                 "CheckNestmateAttrs.class").toString() };
  65         runCheck(params, new String [] {
  66                         "NestMembers:" +
  67                         "  CheckNestmateAttrs$Nested" +
  68                         "  CheckNestmateAttrs$Nested$1LocalNested" +
  69                         "  CheckNestmateAttrs$Inner" +
  70                         "  CheckNestmateAttrs$Inner$1LocalInner"
  71                         });
  72 
  73         params = new String [] { "-v",
  74                                  Paths.get(System.getProperty("test.classes"),
  75                                      "CheckNestmateAttrs$Inner.class").toString() };
  76 
  77         runCheck(params, new String [] { "NestHost: class CheckNestmateAttrs" });
  78 
  79         params = new String [] { "-v",
  80                                  Paths.get(System.getProperty("test.classes"),
  81                                      "CheckNestmateAttrs$Nested.class").toString() };
  82 
  83         runCheck(params, new String [] { "NestHost: class CheckNestmateAttrs" });
  84 
  85         params = new String [] { "-v",
  86                                  Paths.get(System.getProperty("test.classes"),
  87                                      "CheckNestmateAttrs$Inner$1LocalInner.class").toString() };
  88 
  89         runCheck(params, new String [] {
  90                         "NestHost: class CheckNestmateAttrs",
  91                         "0: aload_0",
  92                         "1: getfield      #1                  // Field this$1:LCheckNestmateAttrs$Inner;",
  93                         "4: getfield      #3                  // Field CheckNestmateAttrs$Inner.this$0:LCheckNestmateAttrs;",
  94                         "7: invokevirtual #4                  // Method CheckNestmateAttrs.test:()V",
  95                         "10: return"
  96         });
  97 
  98         params = new String [] { "-v",
  99                                  Paths.get(System.getProperty("test.classes"),
 100                                      "CheckNestmateAttrs$Nested$1LocalNested.class").toString() };
 101 
 102         runCheck(params, new String [] { "NestHost: class CheckNestmateAttrs" });
 103      }
 104 
 105      void runCheck(String [] params, String [] expectedOut) {
 106         StringWriter s;
 107         String out;
 108 
 109         try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
 110             com.sun.tools.javap.Main.run(params, pw);
 111             out = s.toString();
 112         }
 113         for (String eo: expectedOut) {
 114             if (!out.contains(eo)) {
 115                 System.out.println("Actual output: " + out);
 116                 throw new AssertionError("Missing output: " + eo);
 117             }
 118         }
 119     }
 120 }
< prev index next >