51 Point p = __MakeDefault Point(); 52 p = __WithField(p.x, x); 53 return __WithField(p.y, y); 54 } 55 56 public static void main(String [] args) { 57 Point p = makePoint(10, 20); 58 } 59 } 60 61 public static void main(String[] args) { 62 new ValueCreationTest().run(); 63 } 64 65 void run() { 66 String [] params = new String [] { "-v", 67 Paths.get(System.getProperty("test.classes"), 68 "ValueCreationTest$Point.class").toString() }; 69 runCheck(params, new String [] { 70 71 "0: defaultvalue #4 // class ValueCreationTest$Point", 72 "3: astore_2", 73 "4: aload_2", 74 "5: iload_0", 75 "6: withfield #2 // Field x:I", 76 "9: astore_2", 77 "10: aload_2", 78 "11: iload_1", 79 "12: withfield #3 // Field y:I", 80 "15: areturn" 81 82 }); 83 84 } 85 86 void runCheck(String [] params, String [] expectedOut) { 87 StringWriter s; 88 String out; 89 90 try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { 91 com.sun.tools.javap.Main.run(params, pw); 92 out = s.toString(); 93 } 94 int errors = 0; 95 for (String eo: expectedOut) { 96 if (!out.contains(eo)) { 97 System.err.println("Match not found for string: " + eo); 98 errors++; 99 } | 51 Point p = __MakeDefault Point(); 52 p = __WithField(p.x, x); 53 return __WithField(p.y, y); 54 } 55 56 public static void main(String [] args) { 57 Point p = makePoint(10, 20); 58 } 59 } 60 61 public static void main(String[] args) { 62 new ValueCreationTest().run(); 63 } 64 65 void run() { 66 String [] params = new String [] { "-v", 67 Paths.get(System.getProperty("test.classes"), 68 "ValueCreationTest$Point.class").toString() }; 69 runCheck(params, new String [] { 70 71 "0: defaultvalue #2 // class ValueCreationTest$Point", 72 "3: astore_2", 73 "4: aload_2", 74 "5: iload_0", 75 "6: withfield #3 // Field x:I", 76 "9: astore_2", 77 "10: aload_2", 78 "11: iload_1", 79 "12: withfield #4 // Field y:I", 80 "15: areturn" 81 82 }); 83 84 } 85 86 void runCheck(String [] params, String [] expectedOut) { 87 StringWriter s; 88 String out; 89 90 try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { 91 com.sun.tools.javap.Main.run(params, pw); 92 out = s.toString(); 93 } 94 int errors = 0; 95 for (String eo: expectedOut) { 96 if (!out.contains(eo)) { 97 System.err.println("Match not found for string: " + eo); 98 errors++; 99 } |