-
Notifications
You must be signed in to change notification settings - Fork 6.1k
JDK-8283714: REDO - Unexpected TypeElement in ANALYZE TaskEvent #8101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jonathan-gibbons
wants to merge
3
commits into
openjdk:master
from
jonathan-gibbons:8283714-REDO-task-event
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
test/langtools/jdk/javadoc/doclet/testLinkTaglet/TestLinkTagletPrimitive.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright (c) 2022, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 8284030 | ||
* @summary LinkFactory should not attempt to link to primitive types | ||
* @library /tools/lib ../../lib | ||
* @modules jdk.javadoc/jdk.javadoc.internal.tool | ||
* @build toolbox.ToolBox javadoc.tester.* | ||
* @run main TestLinkTagletPrimitive | ||
*/ | ||
|
||
import javadoc.tester.JavadocTester; | ||
import toolbox.ToolBox; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
public class TestLinkTagletPrimitive extends JavadocTester { | ||
|
||
public static void main(String... args) throws Exception { | ||
TestLinkTagletPrimitive tester = new TestLinkTagletPrimitive(); | ||
tester.runTests(); | ||
} | ||
|
||
ToolBox tb = new ToolBox(); | ||
|
||
@Test | ||
public void testSimple(Path base) throws IOException { | ||
Path src = base.resolve("src"); | ||
|
||
tb.writeJavaFiles(src, """ | ||
/** | ||
* Comment. | ||
* Byte: {@link byte} | ||
* Void: {@link void} | ||
*/ | ||
public class C {\s | ||
private C() { } | ||
} | ||
"""); | ||
|
||
javadoc("-Xdoclint:none", | ||
"-d", base.resolve("api").toString(), | ||
"-sourcepath", src.toString(), | ||
src.resolve("C.java").toString()); | ||
checkExit(Exit.OK); | ||
|
||
checkOutput(Output.OUT, true, | ||
"C.java:3: warning: Tag @link: reference not found: byte", | ||
"C.java:4: warning: Tag @link: reference not found: void"); | ||
|
||
checkOutput("C.html", true, | ||
""" | ||
<div class="block">Comment. | ||
Byte:\s | ||
<details class="invalid-tag"> | ||
<summary>invalid @link</summary> | ||
<pre><code>byte</code></pre> | ||
</details> | ||
|
||
Void:\s | ||
<details class="invalid-tag"> | ||
<summary>invalid @link</summary> | ||
<pre><code>void</code></pre> | ||
</details> | ||
</div> | ||
"""); | ||
} | ||
@Test | ||
public void testArray(Path base) throws IOException { | ||
Path src = base.resolve("src"); | ||
|
||
tb.writeJavaFiles(src, """ | ||
/** | ||
* Comment. | ||
* Byte[]: {@link byte[]} | ||
*/ | ||
public class C {\s | ||
private C() { } | ||
} | ||
"""); | ||
|
||
javadoc("-Xdoclint:none", | ||
"-d", base.resolve("api").toString(), | ||
"-sourcepath", src.toString(), | ||
src.resolve("C.java").toString()); | ||
checkExit(Exit.OK); | ||
|
||
checkOutput(Output.OUT, true, | ||
"C.java:3: warning: Tag @link: reference not found: byte[]"); | ||
|
||
checkOutput("C.html", true, | ||
""" | ||
<div class="block">Comment. | ||
Byte[]:\s | ||
<details class="invalid-tag"> | ||
<summary>invalid @link</summary> | ||
<pre><code>byte[]</code></pre> | ||
</details> | ||
</div> | ||
"""); | ||
} | ||
} |
168 changes: 168 additions & 0 deletions
168
test/langtools/tools/javac/api/taskListeners/TestTypeElement.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
* Copyright (c) 2022, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 8283661 8283714 | ||
* @summary Unexpected TypeElement in ANALYZE TaskEvent | ||
* @modules jdk.compiler | ||
* @run main TestTypeElement | ||
*/ | ||
|
||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
|
||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.util.Elements; | ||
import javax.tools.JavaCompiler; | ||
import javax.tools.JavaFileObject; | ||
import javax.tools.SimpleJavaFileObject; | ||
import javax.tools.ToolProvider; | ||
|
||
import com.sun.source.util.JavacTask; | ||
import com.sun.source.util.TaskEvent; | ||
import com.sun.source.util.TaskListener; | ||
|
||
public class TestTypeElement { | ||
public static void main(String... args) throws Exception { | ||
new TestTypeElement().run(); | ||
} | ||
|
||
private PrintStream log; | ||
private Elements elements; | ||
private int errors; | ||
|
||
void run() throws Exception { | ||
log = System.err; | ||
|
||
List<JavaFileObject> files = List.of( | ||
createFileObject("module-info.java", "module m { }"), | ||
createFileObject("p/package-info.java", "/** Comment. */ package p;"), | ||
createFileObject("p/C.java", "package p; public class C { }") | ||
); | ||
|
||
JavaCompiler c = ToolProvider.getSystemJavaCompiler(); | ||
JavacTask t = (JavacTask) c.getTask(null, null, null, List.of("-d", "classes"), null, files); | ||
t.addTaskListener(new TaskListener() { | ||
@Override | ||
public void started(TaskEvent e) { | ||
log.println("started: " + e); | ||
checkTypeElement(e); | ||
} | ||
@Override | ||
public void finished(TaskEvent e) { | ||
log.println("finished: " + e); | ||
checkTypeElement(e); | ||
} | ||
}); | ||
elements = t.getElements(); | ||
t.call(); | ||
|
||
if (errors > 0) { | ||
log.println(errors + " errors occurred"); | ||
throw new Exception(errors + " errors occurred"); | ||
} | ||
} | ||
|
||
private void checkTypeElement(TaskEvent e) { | ||
TypeElement te = e.getTypeElement(); | ||
|
||
if (te != null) { | ||
showTypeElement(e.getTypeElement()); | ||
} | ||
|
||
switch (e.getKind()) { | ||
case COMPILATION, PARSE, ENTER -> { | ||
checkEqual(te, null); | ||
} | ||
|
||
case ANALYZE, GENERATE -> { | ||
if (te == null) { | ||
error("type element is null"); | ||
return; | ||
} | ||
|
||
|
||
switch (te.getQualifiedName().toString()) { | ||
case "m.module-info" -> { | ||
checkEqual(elements.getModuleOf(te), elements.getModuleElement("m")); | ||
checkEqual(elements.getPackageOf(te), null); | ||
} | ||
case "p.package-info", "p.C" -> { | ||
checkEqual(elements.getModuleOf(te), elements.getModuleElement("m")); | ||
checkEqual(elements.getPackageOf(te), elements.getPackageElement("p")); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void showTypeElement(TypeElement e) { | ||
log.println("type element: " + e); | ||
|
||
try { | ||
log.println(" module element: " + elements.getModuleOf(e)); | ||
} catch (Throwable t) { | ||
log.println(" module element: " + t); | ||
} | ||
|
||
try { | ||
log.println(" package element: " + elements.getPackageOf(e)); | ||
} catch (Throwable t) { | ||
log.println(" package element: " + t); | ||
} | ||
} | ||
|
||
private <T> void checkEqual(T found, T expected) { | ||
if (found != expected) { | ||
error("mismatch"); | ||
log.println(" found: " + found); | ||
log.println("expected: " + expected); | ||
} | ||
} | ||
|
||
private void error(String message) { | ||
log.println("Error: " + message); | ||
errors++; | ||
} | ||
|
||
private JavaFileObject createFileObject(String name, String body) { | ||
return createFileObject(name, JavaFileObject.Kind.SOURCE, body); | ||
} | ||
|
||
private JavaFileObject createFileObject(String name, JavaFileObject.Kind kind, String body) { | ||
try { | ||
return new SimpleJavaFileObject(new URI("myfo:///" + name), kind) { | ||
@Override | ||
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { | ||
return body; | ||
} | ||
}; | ||
} catch (URISyntaxException e) { | ||
throw new IllegalArgumentException(name, e); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume this run and the run below generate warnings. Should we check for them?