< prev index next >

test/langtools/tools/javac/parser/JavacParserTest.java

Print this page




 982         assertEquals("actual parameters: " + lambda.getParameters().size(),
 983                      lambda.getParameters().size(),
 984                      1);
 985 
 986         Tree paramType = lambda.getParameters().get(0).getType();
 987 
 988         assertEquals("actual parameter type: " + paramType.getKind(),
 989                      paramType.getKind(),
 990                      Kind.PRIMITIVE_TYPE);
 991 
 992         TypeKind primitiveTypeKind = ((PrimitiveTypeTree) paramType).getPrimitiveTypeKind();
 993 
 994         assertEquals("actual parameter type: " + primitiveTypeKind,
 995                      primitiveTypeKind,
 996                      TypeKind.VOID);
 997     }
 998 
 999     @Test //JDK-8065753
1000     void testWrongFirstToken() throws IOException {
1001         String code = "<";
1002         String expectedErrors = "Test.java:1:1: compiler.err.expected3: class, interface, enum\n" +
1003                                 "1 error\n";
1004         StringWriter out = new StringWriter();
1005         JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(out, fm, null,
1006                 Arrays.asList("-XDrawDiagnostics"), null, Arrays.asList(new MyFileObject(code)));
1007 
1008         Result errorCode = ct.doCall();
1009         assertEquals("the error code is not correct; actual:" + errorCode, Main.Result.ERROR, errorCode);
1010         String actualErrors = normalize(out.toString());
1011         assertEquals("the error message is not correct, actual: " + actualErrors, expectedErrors, actualErrors);
1012     }
1013 
1014     @Test //JDK-8205913
1015     void testForInit() throws IOException {
1016         String code = "class T { void t() { for (n : ns) { } } }";
1017         String expectedErrors = "Test.java:1:27: compiler.err.bad.initializer: for-loop\n";
1018         StringWriter out = new StringWriter();
1019         JavacTask ct = (JavacTask) tool.getTask(out, fm, null,
1020                 Arrays.asList("-XDrawDiagnostics"), null, Arrays.asList(new MyFileObject(code)));
1021 
1022         Iterable<? extends CompilationUnitTree> cuts = ct.parse();




 982         assertEquals("actual parameters: " + lambda.getParameters().size(),
 983                      lambda.getParameters().size(),
 984                      1);
 985 
 986         Tree paramType = lambda.getParameters().get(0).getType();
 987 
 988         assertEquals("actual parameter type: " + paramType.getKind(),
 989                      paramType.getKind(),
 990                      Kind.PRIMITIVE_TYPE);
 991 
 992         TypeKind primitiveTypeKind = ((PrimitiveTypeTree) paramType).getPrimitiveTypeKind();
 993 
 994         assertEquals("actual parameter type: " + primitiveTypeKind,
 995                      primitiveTypeKind,
 996                      TypeKind.VOID);
 997     }
 998 
 999     @Test //JDK-8065753
1000     void testWrongFirstToken() throws IOException {
1001         String code = "<";
1002         String expectedErrors = "Test.java:1:1: compiler.err.expected4: class, interface, enum, record\n" +
1003                                 "1 error\n";
1004         StringWriter out = new StringWriter();
1005         JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(out, fm, null,
1006                 Arrays.asList("-XDrawDiagnostics"), null, Arrays.asList(new MyFileObject(code)));
1007 
1008         Result errorCode = ct.doCall();
1009         assertEquals("the error code is not correct; actual:" + errorCode, Main.Result.ERROR, errorCode);
1010         String actualErrors = normalize(out.toString());
1011         assertEquals("the error message is not correct, actual: " + actualErrors, expectedErrors, actualErrors);
1012     }
1013 
1014     @Test //JDK-8205913
1015     void testForInit() throws IOException {
1016         String code = "class T { void t() { for (n : ns) { } } }";
1017         String expectedErrors = "Test.java:1:27: compiler.err.bad.initializer: for-loop\n";
1018         StringWriter out = new StringWriter();
1019         JavacTask ct = (JavacTask) tool.getTask(out, fm, null,
1020                 Arrays.asList("-XDrawDiagnostics"), null, Arrays.asList(new MyFileObject(code)));
1021 
1022         Iterable<? extends CompilationUnitTree> cuts = ct.parse();


< prev index next >