< prev index next >

test/langtools/tools/javac/switchexpr/SwitchExpressionSimpleVisitorTest.java

Print this page




  72                         return null;
  73                     }
  74                 }, null);
  75                 return super.visitSwitchExpression(node, p);
  76             }
  77         }.scan(parse(code), null);
  78 
  79         if (callCount[0] != 1 || switchExprNodeCount[0] != 1) {
  80             throw new AssertionError("Unexpected counts; callCount=" + callCount[0] +
  81                                      ", switchExprNodeCount=" + switchExprNodeCount[0]);
  82         }
  83     }
  84 
  85     private CompilationUnitTree parse(String code) throws IOException {
  86         final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
  87         assert tool != null;
  88         DiagnosticListener<JavaFileObject> noErrors = d -> {};
  89 
  90         StringWriter out = new StringWriter();
  91         JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
  92             List.of("--enable-preview", "-source", "12"), null,
  93             Arrays.asList(new MyFileObject(code)));
  94         return ct.parse().iterator().next();
  95     }
  96 
  97     static class MyFileObject extends SimpleJavaFileObject {
  98         private String text;
  99 
 100         public MyFileObject(String text) {
 101             super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
 102             this.text = text;
 103         }
 104 
 105         @Override
 106         public CharSequence getCharContent(boolean ignoreEncodingErrors) {
 107             return text;
 108         }
 109     }
 110 }


  72                         return null;
  73                     }
  74                 }, null);
  75                 return super.visitSwitchExpression(node, p);
  76             }
  77         }.scan(parse(code), null);
  78 
  79         if (callCount[0] != 1 || switchExprNodeCount[0] != 1) {
  80             throw new AssertionError("Unexpected counts; callCount=" + callCount[0] +
  81                                      ", switchExprNodeCount=" + switchExprNodeCount[0]);
  82         }
  83     }
  84 
  85     private CompilationUnitTree parse(String code) throws IOException {
  86         final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
  87         assert tool != null;
  88         DiagnosticListener<JavaFileObject> noErrors = d -> {};
  89 
  90         StringWriter out = new StringWriter();
  91         JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
  92             List.of("--enable-preview", "-source", "13"), null,
  93             Arrays.asList(new MyFileObject(code)));
  94         return ct.parse().iterator().next();
  95     }
  96 
  97     static class MyFileObject extends SimpleJavaFileObject {
  98         private String text;
  99 
 100         public MyFileObject(String text) {
 101             super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
 102             this.text = text;
 103         }
 104 
 105         @Override
 106         public CharSequence getCharContent(boolean ignoreEncodingErrors) {
 107             return text;
 108         }
 109     }
 110 }
< prev index next >