mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8205913: Inconsistent source code model
Ensuring variable declarations have non-null modifiers and names. Reviewed-by: mcimadamore
This commit is contained in:
parent
2183a72fe3
commit
152488eeee
3 changed files with 39 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -23,7 +23,7 @@
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7073631 7159445 7156633 8028235 8065753
|
||||
* @bug 7073631 7159445 7156633 8028235 8065753 8205913
|
||||
* @summary tests error and diagnostics positions
|
||||
* @author Jan Lahoda
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
|
@ -49,7 +49,9 @@ import com.sun.source.tree.Tree;
|
|||
import com.sun.source.tree.Tree.Kind;
|
||||
import com.sun.source.tree.VariableTree;
|
||||
import com.sun.source.tree.WhileLoopTree;
|
||||
import com.sun.source.util.JavacTask;
|
||||
import com.sun.source.util.SourcePositions;
|
||||
import com.sun.source.util.TreePathScanner;
|
||||
import com.sun.source.util.TreeScanner;
|
||||
import com.sun.source.util.Trees;
|
||||
import com.sun.tools.javac.api.JavacTaskImpl;
|
||||
|
@ -1005,6 +1007,36 @@ public class JavacParserTest extends TestCase {
|
|||
assertEquals("the error message is not correct, actual: " + actualErrors, expectedErrors, actualErrors);
|
||||
}
|
||||
|
||||
@Test //JDK-8205913
|
||||
void testForInit() throws IOException {
|
||||
String code = "class T { void t() { for (n : ns) { } } }";
|
||||
String expectedErrors = "Test.java:1:27: compiler.err.bad.initializer: for-loop\n";
|
||||
StringWriter out = new StringWriter();
|
||||
JavacTask ct = (JavacTask) tool.getTask(out, fm, null,
|
||||
Arrays.asList("-XDrawDiagnostics"), null, Arrays.asList(new MyFileObject(code)));
|
||||
|
||||
Iterable<? extends CompilationUnitTree> cuts = ct.parse();
|
||||
boolean[] foundVar = new boolean[1];
|
||||
|
||||
new TreePathScanner<Void, Void>() {
|
||||
@Override public Void visitVariable(VariableTree vt, Void p) {
|
||||
assertNotNull(vt.getModifiers());
|
||||
assertNotNull(vt.getType());
|
||||
assertNotNull(vt.getName());
|
||||
assertEquals("name should be <error>", "<error>", vt.getName().toString());
|
||||
foundVar[0] = true;
|
||||
return super.visitVariable(vt, p);
|
||||
}
|
||||
}.scan(cuts, null);
|
||||
|
||||
if (!foundVar[0]) {
|
||||
fail("haven't found a variable");
|
||||
}
|
||||
|
||||
String actualErrors = normalize(out.toString());
|
||||
assertEquals("the error message is not correct, actual: " + actualErrors, expectedErrors, actualErrors);
|
||||
}
|
||||
|
||||
void run(String[] args) throws Exception {
|
||||
int passed = 0, failed = 0;
|
||||
final Pattern p = (args != null && args.length > 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue