Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
8216497: javadoc should auto-link to platform classes
Co-authored-by: Jan Lahoda <jlahoda@openjdk.org> Reviewed-by: erikj, jjg
- Loading branch information
Showing
51 changed files
with
1,840 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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
136 changes: 136 additions & 0 deletions
136
make/langtools/src/classes/build/tools/symbolgenerator/JavadocElementList.java
This file contains 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,136 @@ | ||
/* | ||
* Copyright (c) 2017, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package build.tools.symbolgenerator; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.io.Writer; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayDeque; | ||
import java.util.Arrays; | ||
import java.util.Deque; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.lang.model.element.ModuleElement.ExportsDirective; | ||
import javax.lang.model.util.Elements; | ||
import javax.tools.JavaCompiler; | ||
|
||
import com.sun.tools.javac.api.JavacTaskImpl; | ||
import com.sun.tools.javac.api.JavacTool; | ||
import com.sun.tools.javac.code.Source; | ||
import com.sun.tools.javac.code.Symbol.ModuleSymbol; | ||
import com.sun.tools.javac.jvm.Target; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.TreeMap; | ||
import java.util.TreeSet; | ||
import javax.lang.model.element.ModuleElement; | ||
|
||
/** | ||
* Generate list of modules and packages in the current release. | ||
* Used by the javadoc tool. | ||
*/ | ||
public class JavadocElementList { | ||
|
||
private static void help() { | ||
System.err.println("java JavadocElementList <target-file> <module-source-path> <root-modules>"); | ||
} | ||
|
||
public static void main(String... args) throws IOException { | ||
if (args.length < 2) { | ||
help(); | ||
return ; | ||
} | ||
|
||
JavaCompiler compiler = JavacTool.create(); | ||
List<String> options = List.of("-source", Source.DEFAULT.name, | ||
"-target", Target.DEFAULT.name, | ||
"-proc:only", | ||
"--system", "none", | ||
"--module-source-path", args[1], | ||
"--add-modules", Arrays.stream(args) | ||
.skip(2) | ||
.collect(Collectors.joining(","))); | ||
List<String> jlObjectList = List.of("java.lang.Object"); | ||
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, null, null, options, jlObjectList, null); | ||
task.enter(); | ||
Elements elements = task.getElements(); | ||
Deque<String> todo = new ArrayDeque<>(); | ||
Arrays.stream(args).skip(2).forEach(todo::add); | ||
|
||
todo.add("java.base"); | ||
|
||
Map<String, Set<String>> modulesAndExports = new TreeMap<>(); | ||
|
||
while (!todo.isEmpty()) { | ||
String current = todo.removeFirst(); | ||
|
||
if (modulesAndExports.containsKey(current)) | ||
continue; | ||
|
||
ModuleSymbol mod = (ModuleSymbol) elements.getModuleElement(current); | ||
|
||
if (mod == null) { | ||
throw new IllegalStateException("Missing: " + current); | ||
} | ||
|
||
//use the internal structure to avoid unnecesarily completing the symbol using the UsesProvidesVisitor: | ||
modulesAndExports.put(mod.getQualifiedName().toString(), | ||
mod.exports | ||
.stream() | ||
.filter((ExportsDirective ed) -> ed.getTargetModules() == null) | ||
.map((ExportsDirective ed) -> ed.getPackage().getQualifiedName().toString()) | ||
.collect(Collectors.toCollection(() -> new TreeSet<>())) | ||
); | ||
for (ModuleElement.RequiresDirective rd : mod.requires) { | ||
if (rd.isTransitive()) { | ||
todo.offerLast(rd.getDependency().getQualifiedName().toString()); | ||
} | ||
} | ||
} | ||
|
||
Path targetFile = Paths.get(args[0]); | ||
|
||
Files.createDirectories(targetFile.getParent()); | ||
|
||
try (Writer w = Files.newBufferedWriter(targetFile); | ||
PrintWriter out = new PrintWriter(w)) { | ||
for (Entry<String, Set<String>> moduleAndExports : modulesAndExports.entrySet()) { | ||
out.write("module:" + moduleAndExports.getKey()); | ||
out.write("\n"); | ||
for (String pack : moduleAndExports.getValue()) { | ||
out.write(pack); | ||
out.write("\n"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains 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,97 @@ | ||
# | ||
# Copyright (c) 2015, 2020, 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. Oracle designates this | ||
# particular file as subject to the "Classpath" exception as provided | ||
# by Oracle in the LICENSE file that accompanied this code. | ||
# | ||
# 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. | ||
# | ||
|
||
include JavaCompilation.gmk | ||
include Modules.gmk | ||
|
||
################################################################################ | ||
|
||
# Hook to include the corresponding custom file, if present. | ||
$(eval $(call IncludeCustomExtension, modules/jdk.javadoc/Gendata.gmk)) | ||
|
||
# This is needed to properly setup DOCS_MODULES. | ||
$(eval $(call ReadImportMetaData)) | ||
|
||
JAVADOC_MODULES := $(DOCS_MODULES) | ||
|
||
# Get the complete module source path: | ||
JAVADOC_MODULESOURCEPATH := $(call GetModuleSrcPath) | ||
|
||
CT_DATA_DESCRIPTION += $(TOPDIR)/make/data/symbols/symbols | ||
|
||
COMPILECREATESYMBOLS_ADD_EXPORTS := \ | ||
--add-exports java.base/jdk.internal=java.compiler.interim,jdk.compiler.interim \ | ||
--add-exports jdk.compiler.interim/com.sun.tools.javac.api=ALL-UNNAMED \ | ||
--add-exports jdk.compiler.interim/com.sun.tools.javac.code=ALL-UNNAMED \ | ||
--add-exports jdk.compiler.interim/com.sun.tools.javac.util=ALL-UNNAMED \ | ||
--add-exports jdk.compiler.interim/com.sun.tools.javac.jvm=ALL-UNNAMED \ | ||
# | ||
|
||
$(eval $(call SetupJavaCompilation, COMPILE_CREATE_SYMBOLS, \ | ||
TARGET_RELEASE := $(TARGET_RELEASE_BOOTJDK), \ | ||
SRC := $(TOPDIR)/make/langtools/src/classes \ | ||
$(TOPDIR)/src/jdk.jdeps/share/classes, \ | ||
INCLUDES := build/tools/symbolgenerator com/sun/tools/classfile, \ | ||
BIN := $(BUILDTOOLS_OUTPUTDIR)/create_symbols, \ | ||
DISABLED_WARNINGS := options, \ | ||
JAVAC_FLAGS := \ | ||
$(INTERIM_LANGTOOLS_ARGS) \ | ||
--patch-module java.base=$(BUILDTOOLS_OUTPUTDIR)/gensrc/java.base.interim \ | ||
$(COMPILECREATESYMBOLS_ADD_EXPORTS), \ | ||
)) | ||
|
||
$(SUPPORT_OUTPUTDIR)/javadoc-symbols/symbols: \ | ||
$(COMPILE_CREATE_SYMBOLS) \ | ||
$(wildcard $(TOPDIR)/make/data/symbols/*) \ | ||
$(MODULE_INFOS) | ||
$(RM) -r $(@D) | ||
$(MKDIR) -p $(@D) | ||
$(ECHO) Creating javadoc element list | ||
$(JAVA_SMALL) $(INTERIM_LANGTOOLS_ARGS) \ | ||
$(COMPILECREATESYMBOLS_ADD_EXPORTS) \ | ||
-classpath $(BUILDTOOLS_OUTPUTDIR)/create_symbols \ | ||
build.tools.symbolgenerator.CreateSymbols \ | ||
build-javadoc-data \ | ||
$(CT_DATA_DESCRIPTION) \ | ||
$(JDK_OUTPUTDIR)/modules/jdk.javadoc/jdk/javadoc/internal/doclets/toolkit/resources/releases \ | ||
11 | ||
$(JAVA_SMALL) $(INTERIM_LANGTOOLS_ARGS) \ | ||
$(COMPILECREATESYMBOLS_ADD_EXPORTS) \ | ||
-classpath $(BUILDTOOLS_OUTPUTDIR)/create_symbols \ | ||
build.tools.symbolgenerator.JavadocElementList \ | ||
$(JDK_OUTPUTDIR)/modules/jdk.javadoc/jdk/javadoc/internal/doclets/toolkit/resources/releases/element-list-$(JDK_SOURCE_TARGET_VERSION).txt \ | ||
$(JAVADOC_MODULESOURCEPATH) \ | ||
$(JAVADOC_MODULES) | ||
$(TOUCH) $@ | ||
|
||
# Copy ct.sym to the modules libs dir | ||
$(eval $(call SetupCopyFiles, COPY_TO_LIBS, \ | ||
FILES := $(SUPPORT_OUTPUTDIR)/javadoc-symbols/*.txt, \ | ||
DEST := $(JDK_OUTPUTDIR)/modules/jdk.javadoc/jdk/javadoc/internal/doclets/toolkit/resources/releases, \ | ||
)) | ||
|
||
TARGETS += $(SUPPORT_OUTPUTDIR)/javadoc-symbols/symbols | ||
|
||
################################################################################ |
This file contains 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
Oops, something went wrong.
1e8e543
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.
Review
Issues