OpenJDK / bsd-port / jdk9 / langtools
changeset 3324:82f94333bd7e
Merge
author | zmajo |
---|---|
date | Thu, 24 Mar 2016 16:21:21 +0100 |
parents | 680712ce0386 7b2109432f9f |
children | f54b675d5eee |
files | src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java src/jdk.compiler/share/classes/com/sun/tools/javac/sym/CreateSymbols.java src/jdk.compiler/share/classes/com/sun/tools/javac/sym/Profiles.java src/jdk.compiler/share/classes/com/sun/tools/javac/util/ServiceLoader.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/AbstractProfileIndexWriter.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ProfileIndexFrameWriter.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageFrameWriter.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageIndexFrameWriter.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageWriterImpl.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ProfileWriterImpl.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/ProfilePackageSummaryWriter.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/ProfileSummaryWriter.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ProfilePackageSummaryBuilder.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ProfileSummaryBuilder.java src/jdk.jdeps/share/classes/com/sun/tools/jdeps/ModulesXmlReader.java src/jdk.jdeps/share/classes/com/sun/tools/jdeps/PlatformClassPath.java test/com/sun/javadoc/testLinkOption/java/lang/StringBuilderChild.java test/com/sun/javadoc/testLinkOption/package-list test/com/sun/javadoc/testProfiles/TestProfiles.java test/com/sun/javadoc/testProfiles/TestProfilesConfiguration.java test/com/sun/javadoc/testProfiles/pkg1/Class1Pkg1.java test/com/sun/javadoc/testProfiles/pkg1/Class2Pkg1.java test/com/sun/javadoc/testProfiles/pkg1/Class3Pkg1.java test/com/sun/javadoc/testProfiles/pkg1/Interface1Pkg1.java test/com/sun/javadoc/testProfiles/pkg2/Anno1Pkg2.java test/com/sun/javadoc/testProfiles/pkg2/Anno2Pkg2.java test/com/sun/javadoc/testProfiles/pkg2/Class1Pkg2.java test/com/sun/javadoc/testProfiles/pkg2/ClassError.java test/com/sun/javadoc/testProfiles/pkg2/ClassException.java test/com/sun/javadoc/testProfiles/pkg3/Class1Pkg3.java test/com/sun/javadoc/testProfiles/pkg3/Class2Pkg3.java test/com/sun/javadoc/testProfiles/pkg3/Interface1Pkg3.java test/com/sun/javadoc/testProfiles/pkg4/Anno1Pkg4.java test/com/sun/javadoc/testProfiles/pkg4/Class1Pkg4.java test/com/sun/javadoc/testProfiles/pkg5/Class1Pkg5.java test/com/sun/javadoc/testProfiles/pkg5/Interface1Pkg5.java test/com/sun/javadoc/testProfiles/pkgDeprecated/Class1PkgDeprecated.java test/com/sun/javadoc/testProfiles/pkgDeprecated/package-info.java test/com/sun/javadoc/testProfiles/profile-rtjar-includes-nopkgs.txt test/com/sun/javadoc/testProfiles/profile-rtjar-includes.txt test/jdk/javadoc/doclet/testLinkOption/java/lang/StringBuilderChild.java test/jdk/javadoc/doclet/testLinkOption/package-list test/tools/javac/Object1.java test/tools/javac/Object1.out test/tools/javac/Object2.java test/tools/javac/Object2.out test/tools/javac/profiles/ProfileTest.java test/tools/javac/proprietary/WarnClass.java test/tools/javac/proprietary/WarnClass.out test/tools/javac/proprietary/WarnImport.java test/tools/javac/proprietary/WarnImport.out test/tools/javac/proprietary/WarnMethod.java test/tools/javac/proprietary/WarnMethod.out test/tools/javac/proprietary/WarnStaticImport.java test/tools/javac/proprietary/WarnStaticImport.out test/tools/javac/proprietary/WarnVariable.java test/tools/javac/proprietary/WarnVariable.out test/tools/javac/proprietary/WarnWildcard.java test/tools/javac/proprietary/WarnWildcard.out test/tools/javac/synthesize/Boolean.java test/tools/javac/synthesize/Byte.java test/tools/javac/synthesize/Character.java test/tools/javac/synthesize/Cloneable.java test/tools/javac/synthesize/Double.java test/tools/javac/synthesize/Float.java test/tools/javac/synthesize/Integer.java test/tools/javac/synthesize/Long.java test/tools/javac/synthesize/Number.java test/tools/javac/synthesize/Object.java test/tools/javac/synthesize/Serializable.java test/tools/javac/synthesize/Short.java test/tools/javac/synthesize/Test.java test/tools/javac/synthesize/Void.java test/tools/jdeps/VerboseFormat/use/indirect/DontUseUnsafe2.java test/tools/jdeps/VerboseFormat/use/indirect/UseUnsafeIndirectly.java test/tools/jdeps/VerboseFormat/use/indirect2/DontUseUnsafe3.java test/tools/jdeps/VerboseFormat/use/indirect2/UseUnsafeIndirectly2.java test/tools/jdeps/VerboseFormat/use/unsafe/DontUseUnsafe.java test/tools/jdeps/VerboseFormat/use/unsafe/UseClassWithUnsafe.java test/tools/jdeps/VerboseFormat/use/unsafe/UseUnsafeClass.java test/tools/jdeps/VerboseFormat/use/unsafe/UseUnsafeClass2.java test/tools/jdeps/javax/activity/NotCompactProfile.java |
diffstat | 926 files changed, 28123 insertions(+), 11563 deletions(-) [+] |
line wrap: on
line diff
--- a/make/CompileInterim.gmk Thu Mar 24 11:21:37 2016 +0100 +++ b/make/CompileInterim.gmk Thu Mar 24 16:21:21 2016 +0100 @@ -32,23 +32,35 @@ include SetupJavaCompilers.gmk ################################################################################ -# Setup the rules to build the interim langtools jar, which is compiled by -# the boot javac and can be run on the boot jdk. This will be used to compile -# the rest of the product. Include the Genstubs build tool in this compilation -# as it will be used together with the interim javac. -$(eval $(call SetupJavaCompilation,BUILD_INTERIM_LANGTOOLS, \ - SETUP := BOOT_JAVAC, \ - DISABLE_SJAVAC := true, \ - SRC := $(LANGTOOLS_TOPDIR)/src/java.compiler/share/classes \ - $(LANGTOOLS_TOPDIR)/src/jdk.compiler/share/classes \ - $(LANGTOOLS_TOPDIR)/src/jdk.javadoc/share/classes \ - $(LANGTOOLS_TOPDIR)/src/jdk.jdeps/share/classes \ - $(SUPPORT_OUTPUTDIR)/gensrc/jdk.compiler \ - $(SUPPORT_OUTPUTDIR)/gensrc/jdk.javadoc \ - $(SUPPORT_OUTPUTDIR)/gensrc/jdk.jdeps, \ - EXCLUDES := sun, \ - COPY := .gif .png .xml .css .js javax.tools.JavaCompilerTool, \ - BIN := $(BUILDTOOLS_OUTPUTDIR)/langtools_interim_classes, \ - JAR := $(INTERIM_LANGTOOLS_JAR))) +# Setup the rules to build interim langtools, which is compiled by the boot +# javac and can be run on the boot jdk. This will be used to compile +# the rest of the product. Each module is compiled separately to allow a modular +# boot jdk to override system classes using -Xoverride:. -all: $(BUILD_INTERIM_LANGTOOLS) +# Param 1 - Name of module to compile +# Param 2 - Name of modules to depend on +define SetupInterimModule + $$(eval $$(call SetupJavaCompilation,BUILD_INTERIM_$(strip $1), \ + SETUP := BOOT_JAVAC, \ + DISABLE_SJAVAC := true, \ + SRC := $(LANGTOOLS_TOPDIR)/src/$(strip $1)/share/classes \ + $$(wildcard $(SUPPORT_OUTPUTDIR)/gensrc/$(strip $1)), \ + EXCLUDES := sun com/sun/tools/jdeps com/sun/tools/javap, \ + EXCLUDE_FILES := module-info.java, \ + COPY := .gif .png .xml .css .js javax.tools.JavaCompilerTool, \ + BIN := $(BUILDTOOLS_OUTPUTDIR)/override_modules/$(strip $1), \ + ADD_JAVAC_FLAGS := -Xbootclasspath/p:$$(call PathList, \ + $$(foreach m, $2, $(BUILDTOOLS_OUTPUTDIR)/override_modules/$$m)), \ + )) + + $$(BUILD_INTERIM_$(strip $1)): $$(foreach m, $2, $$(BUILD_INTERIM_$(strip $$m))) + + TARGETS += $$(BUILD_INTERIM_$(strip $1)) +endef + +$(eval $(call SetupInterimModule, java.compiler)) +$(eval $(call SetupInterimModule, jdk.compiler, java.compiler)) +$(eval $(call SetupInterimModule, jdk.jdeps, jdk.compiler java.compiler)) +$(eval $(call SetupInterimModule, jdk.javadoc, java.compiler jdk.compiler)) + +all: $(TARGETS)
--- a/make/build.properties Thu Mar 24 11:21:37 2016 +0100 +++ b/make/build.properties Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ # -# Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2007, 2016, 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 @@ -24,58 +24,13 @@ # #javac configuration for "normal build" (these will be passed to the bootstrap compiler): -javac.debug = true -javac.debuglevel = source,lines,vars -javac.extra.opts=-XDignore.symbol.file=true -javac.includes= -javac.lint.opts = -Xlint:all,-deprecation -Werror -javac.source = 8 -javac.target = 8 +javac.opts = -XDignore.symbol.file=true -Xlint:all,-deprecation,-options -Werror -g:source,lines,vars +javac.source = 9 +javac.target = 9 -#javac configuration for bootstrap build (these will be passed to the compiler from the given boot JDK): -boot.javac.extra.opts=-XDignore.symbol.file=true -boot.javac.includes = \ - javax/annotation/processing/ \ - javax/lang/model/ \ - javax/tools/ \ - jdk/ \ - com/sun/source/ \ - com/sun/tools/javac/ \ - com/sun/tools/doclint/ -boot.javac.lint.opts= -boot.javac.source = 8 -boot.javac.target = 8 - -#configuration of submodules (share by both the bootstrap and normal compilation): -langtools.modules=java.compiler:jdk.compiler:jdk.jdeps:jdk.javadoc:jdk.jshell:jdk.internal.le:jdk.jdi -java.compiler.dependencies= -jdk.compiler.dependencies=java.compiler -jdk.javadoc.dependencies=java.compiler:jdk.compiler -jdk.jdeps.dependencies=java.compiler:jdk.compiler -jdk.internal.le.dependencies= -jdk.jdi.dependencies= -jdk.jshell.dependencies=java.compiler:jdk.internal.le:jdk.compiler:jdk.jdi - -tool.javac.main.class=com.sun.tools.javac.Main -tool.javadoc.main.class=com.sun.tools.javadoc.Main -tool.javap.main.class=com.sun.tools.javap.Main -tool.javah.main.class=com.sun.tools.javah.Main -tool.sjavac.main.class=com.sun.tools.sjavac.Main -tool.jshell.main.class=jdk.internal.jshell.tool.JShellTool - -javac.resource.includes = \ +langtools.resource.includes = \ com/sun/tools/javac/resources/compiler.properties -#test configuration: -jtreg.tests= -boot.javac.tests = tools/javac -crules.tests = ../make/test/crules - -#javadoc configuration -javadoc.jls.cite=The Java™ Language Specification -javadoc.jls.option=-tag "jls:a:See <cite>${javadoc.jls.cite}</cite>:" \ - -tag "implNote:a:Implementation Note:" - # Version info -- override as needed jdk.version = 9 build.number = b00 @@ -89,3 +44,14 @@ # FIXME -- need to include openjdk as needed release = ${jdk.version}-${milestone} full.version = ${release}+${build.number} + +#tools configuration: +tool.javac.main.class=com.sun.tools.javac.Main +tool.javadoc.main.class=jdk.javadoc.internal.tool.Main +tool.javap.main.class=com.sun.tools.javap.Main +tool.javah.main.class=com.sun.tools.javah.Main +tool.sjavac.main.class=com.sun.tools.sjavac.Main +tool.jshell.main.class=jdk.internal.jshell.tool.JShellTool + +#test configuration: +jtreg.tests=
--- a/make/build.xml Thu Mar 24 11:21:37 2016 +0100 +++ b/make/build.xml Thu Mar 24 16:21:21 2016 +0100 @@ -1,28 +1,28 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright (c) 2007, 2015, 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. ---> + ~ Copyright (c) 2007, 2016, 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. + --> <!-- This is a convenience build file supporting development in the langtools @@ -33,33 +33,23 @@ External dependencies are specified via properties. These can be given on the command line, or by providing a local build.properties file. (They can also be edited into make/build.properties, although that is not - recommended.) At a minimum, boot.java.home must be set to the installed + recommended.) At a minimum, langtools.jdk.home must be set to the installed location of the version of JDK used to build this repository. Additional properties may be required, depending on the targets that are built. - For example, to run any of the jtreg tests you must set jtreg.home, - to run findbugs on the code you must set findbugs.home, and so on. + For example, to run any of the jtreg tests you must set jtreg.home. - The main build happens in two phases: - - First, javac is built using ${boot.java.home}. (This implies a constraint - on the source code that they can be compiled with the previous version of JDK. - - Second, all required classes are compiled with the latest javac, created - in the previous step. - The build generally builds one module at time. + The output of the build is as follows: - For more details on the stub generator, see - http://blogs.sun.com/jjg/entry/building_javac_for_jdk7 - - Internal details ... - - Bootstrap classes are built into the build/bootstrap/<module-name>/classes directory. - Final classes are built into the build/<module-name>/classes directory. - Final runnable javac is in dist/bin and dist/lib. Bootstrap javac (if requested by - using the build-bootstrap-javac target) is built into dist/bootstrap. + build + |-bin (scripts to invoke various tools, javac, javah etc.) + |-genrsc (generated sources - i.e. properties) + |-modules (compiled classes in a modular layout) + |-jtreg (test work/results) + |-toolclasses (tools used for building - like the property compiler) This file is organized into sections as follows: - global property definitions - - primary top level targets (cleaning, building, testing, producing javac) - - secondary top level targets (code analysis, diagnostics, extra documentation, etc.) + - primary top level targets (cleaning, building) - utility definitions --> @@ -80,25 +70,19 @@ <property file="${user.home}/.openjdk/build.properties"/> <!-- Convenient shorthands for standard locations within the workspace. --> - <property name="build.dir" location="build"/> - <property name="build.crules.dir" location="${build.dir}/crules"/> - <property name="build.jtreg.dir" location="${build.dir}/jtreg"/> - <property name="build.toolclasses.dir" location="${build.dir}/toolclasses"/> - <property name="build.javadoc.dir" location="${build.dir}/javadoc"/> - <property name="dist.dir" location="dist"/> - <property name="dist.bin.dir" location="${dist.dir}/bin"/> - <property name="dist.lib.dir" location="${dist.dir}/lib"/> - <property name="dist.findbugs.dir" location="${dist.dir}/findbugs"/> - <property name="dist.checkstyle.dir" location="${dist.dir}/checkstyle"/> + <property name="src.dir" location="src"/> + <property name="test.dir" location="test"/> <property name="make.dir" location="make"/> <property name="make.conf.dir" location="${make.dir}/conf"/> <property name="make.tools.dir" location="${make.dir}/tools"/> - <property name="test.dir" location="test"/> + <property name="build.dir" location="build"/> + <property name="build.modules" location="${build.dir}/modules"/> + <property name="build.gensrc" location="${build.dir}/gensrc"/> + <property name="build.tools" location="${build.dir}/toolclasses"/> + <property name="build.bin" location="${build.dir}/bin"/> + <property name="build.jtreg" location="${build.dir}/jtreg"/> + <property name="build.prevsrc" location="${build.dir}/prevsrc"/> - <property name="boot.build.dir" location="${build.dir}/bootstrap"/> - <property name="boot.dist.dir" location="${dist.dir}/bootstrap"/> - <property name="boot.dist.bin.dir" location="${boot.dist.dir}/bin"/> - <property name="boot.dist.lib.dir" location="${boot.dist.dir}/lib"/> <!-- java.marker is set to a marker file to check for within a Java install dir. The best file to check for across Solaris/Linux/Windows/MacOS is one of the @@ -113,786 +97,28 @@ <!-- Standard property values, if not overriden by earlier settings. --> <property file="${make.dir}/build.properties"/> + <condition property="langtools.jdk.home" value="${jdk.home}"> + <isset property="jdk.home" /> + </condition> + <!-- launcher.java is used in the launcher scripts provided to run the tools' jar files. If it has not already been set, then - default it to use ${target.java.home}, if available, otherwise + default it to use ${langtools.jdk.home}, if available, otherwise quietly default to simply use "java". --> <condition property="launcher.java" - value="${target.java.home}/bin/java" else="java"> - <isset property="target.java.home"/> + value="${langtools.jdk.home}/bin/java" else="java"> + <isset property="langtools.jdk.home"/> </condition> - <!-- setup basic properties holding paths to all sources, generated source and class directories - (both boot and non-boot) --> - <pathconvert property="langtools.sources"> - <path> - <pathelement path="${langtools.modules}" /> - </path> - <map from="${basedir}/" to="${basedir}/src/" /> - <mapper type="glob" from="*" to="*/share/classes"/> - </pathconvert> - <pathconvert property="langtools.gensrc"> - <path> - <pathelement path="${langtools.modules}" /> - </path> - <map from="${basedir}/" to="${build.dir}/" /> - <mapper type="glob" from="*" to="*/gensrc"/> - </pathconvert> - <pathconvert property="langtools.boot.classes"> - <path> - <pathelement path="${langtools.modules}" /> - </path> - <map from="${basedir}/" to="${boot.build.dir}/" /> - <mapper type="glob" from="*" to="*/classes"/> - </pathconvert> - <pathconvert property="langtools.classes"> - <path> - <pathelement path="${langtools.modules}" /> - </path> - <map from="${basedir}/" to="${build.dir}/" /> - <mapper type="glob" from="*" to="*/classes"/> - </pathconvert> - <!-- - **** Primary targets + **** Check targets --> - <target name="clean" description="Delete all generated files"> - <delete dir="${build.dir}"/> - <delete dir="${dist.dir}"/> - </target> - - <target name="build" depends="build-all-tools"> - </target> - - <target name="build-all-tools" depends="build-all-classes,-def-build-all-module-jars,-def-build-tool"> - <build-all-module-jars /> - <build-tool name="javac"/> - <build-tool name="javadoc"/> - <build-tool name="javap"/> - <build-tool name="javah"/> - <build-tool name="sjavac"/> - <build-tool name="jshell"/> - </target> - - <target name="build-all-classes" depends="-def-build-all-module-classes,build-bootstrap-javac-classes"> - <build-all-module-classes /> - </target> - - <target name="jtreg" depends="build-all-tools,-def-jtreg"> - <jtreg-tool name="all" tests="${jtreg.tests}"/> - </target> - - <target name="javadoc" depends="build-all-classes,-def-javadoc-tool"> - <javadoc-tool options="${javadoc.jls.option}"/> - </target> - - <target name="build-bootstrap-javac-classes" depends="-check-boot.java.home,-def-build-all-module-classes"> - <build-all-module-classes compilation.kind="boot." /> - </target> - - <!-- - **** Extra targets - --> - - <target name="build-bootstrap-javac" depends="build-bootstrap-javac-classes,-def-build-all-module-jars,-def-build-tool"> - <build-all-module-jars compilation.kind="boot." /> - <build-tool name="javac" compilation.kind="boot." /> - </target> - - <target name="jtreg-bootstrap-javac" depends="build-bootstrap-javac,-def-jtreg"> - <jtreg-tool name="bootstrap-javac" - tests="${boot.javac.tests}" - langtools.classes="${langtools.boot.classes}"/> - </target> - - <target name="checkstyle" depends="-def-checkstyle" - description="Generates reports for code convention violations."> - <mkdir dir="${dist.checkstyle.dir}"/> - <checkstyle config="${make.conf.dir}/checkstyle-langtools.xml" - failureProperty="checkstyle.failure" - failOnViolation="false"> - <formatter type="xml" tofile="${dist.checkstyle.dir}/checkstyle_report.xml"/> - <fileset dir="src" includes="**/*.java, **/*.properties"/> - </checkstyle> - <!-- transform the output to a simple html --> - <xslt in="${dist.checkstyle.dir}/checkstyle_report.xml" - out="${dist.checkstyle.dir}/checkstyle_report.html" - style="${checkstyle.home}/contrib/checkstyle-simple.xsl"/> - <!-- transform the output to a very simple emacs friendly text file --> - <xslt in="${dist.checkstyle.dir}/checkstyle_report.xml" - out="${dist.checkstyle.dir}/checkstyle_report.tmp" - style="${make.conf.dir}/checkstyle-emacs.xsl"/> - <!-- beautify remove extra lines --> - <move file="${dist.checkstyle.dir}/checkstyle_report.tmp" - toFile="${dist.checkstyle.dir}/checkstyle_report.emacs.txt"> - <filterchain> - <ignoreblank/> - <replaceregex byline="true" pattern="^File:" replace="${line.separator}File:"/> - </filterchain> - </move> - </target> - <!-- target can be invoked from an ide, the output of which can be used - to access and fix the errors directly. - --> - <target name="checkstyle-ide" depends="checkstyle"> - <concat> - <fileset file="${dist.checkstyle.dir}/checkstyle_report.emacs.txt"/> - </concat> - </target> - - <target name="findbugs" depends="-def-findbugs,build-all-tools"> - <property name="findbugs.reportLevel" value="medium"/> - <mkdir dir="${dist.findbugs.dir}"/> - <findbugs - home="${findbugs.home}" - projectName="JDK langtools ${full.version}" - output="xml" - outputFile="${dist.findbugs.dir}/findbugs.xml" - reportLevel="${findbugs.reportLevel}" - failOnError="false" - errorProperty="findbugs.all.errors" - warningsProperty="findbugs.all.warnings" - jvm="${target.java.home}/bin/java" - jvmargs="-Xmx512M"> - <class location="${build.dir}/java.compiler/classes"/> - <class location="${build.dir}/jdk.compiler/classes"/> - <class location="${build.dir}/jdk.javadoc/classes"/> - <class location="${build.dir}/jdk.jdeps/classes"/> - <sourcePath> - <pathelement path="${langtools.sources}"/> - </sourcePath> - </findbugs> - <exec executable="sh"> - <arg value="${findbugs.home}/bin/convertXmlToText"/> - <arg value="-longBugCodes"/> - <arg value="-html:${findbugs.home}/src/xsl/fancy.xsl"/> - <arg value="${dist.findbugs.dir}/findbugs.xml"/> - <redirector output="${dist.findbugs.dir}/findbugs.html"/> - </exec> - </target> - - <target name="diags-examples" depends="build-all-tools"> - <!-- can override the following on the command line if desired. --> - <property name="diags.examples.out" location="${build.dir}/diag-examples/diags-examples.html"/> - <mkdir dir="${build.dir}/diag-examples/classes"/> - <javac fork="true" - executable="${dist.bin.dir}/javac" - srcdir="test/tools/javac/diags" - destdir="${build.dir}/diag-examples/classes" - includes="ArgTypeCompilerFactory.java,Example.java,FileManager.java,HTMLWriter.java,RunExamples.java,DocCommentProcessor.java" - sourcepath="" - classpath="${langtools.classes}" - includeAntRuntime="no" - debug="${javac.debug}" - debuglevel="${javac.debuglevel}"> - <compilerarg line="${javac.lint.opts}"/> - </javac> - <java fork="true" - jvm="${target.java.home}/bin/java" - dir="test/tools/javac/diags" - classpath="${build.dir}/diag-examples/classes;${langtools.classes}" - classname="RunExamples"> - <jvmarg value="-Dtest.classes=${build.dir}/diag-examples/classes"/> - <arg value="-examples"/> - <arg value="examples"/> - <arg value="-o"/> - <arg file="${diags.examples.out}"/> - <arg value="-showFiles"/> - <arg value="-title"/> - <arg value="Examples of javac diagnostics"/> - </java> - </target> - - <target name="doclint-api" depends="build-all-classes"> - <delete dir="${build.dir}/doclint/classes"/> - <mkdir dir="${build.dir}/doclint/classes"/> - <javac fork="true" - executable="${boot.java.home}/bin/javac" - destdir="${build.dir}/doclint/classes" - includes="javax/lang/model/** com/sun/javadoc/** com/sun/source/**" - excludes="" - sourcepath="" - classpath="${langtools.classes}" - includeAntRuntime="no" - source="${javac.source}" - target="${javac.target}" - debug="${javac.debug}" - debuglevel="${javac.debuglevel}"> - <compilerarg value="-implicit:none"/> - <compilerarg value="-Xprefer:source"/> - <compilerarg value="-J-Xbootclasspath/p:${build.bootstrap.dir}/classes"/> - <compilerarg line="${javac.extra.opts}"/> - <compilerarg line="-Xdoclint:all/protected,-missing"/> - <src> - <pathelement path="${langtools.sources}"/> - <pathelement path="${langtools.gensrc}"/> - </src> - </javac> - </target> - - <!-- Generate API docs for "important" test classes that are used by - multiple tests. - --> - <target name="test-framework-docs" depends="build-all-classes"> - <javadoc executable="${target.java.home}/bin/javadoc" - destdir="${build.dir}/testframeworkdocs"> - <!-- disable doclint for now; it might be good to enable -Xdoclint:missing --> - <arg value="-Xdoclint:none"/> - <!-- source files to be documented --> - <sourcefiles> - <fileset dir="${test.dir}"> - <include name="**/ToolBox.java"/> - <include name="**/*Tester.java"/> - <include name="**/*TestBase.java"/> - <include name="**/*Testing*.java"/> - </fileset> - </sourcefiles> - <!-- source path used for documentation --> - <sourcepath> - <pathelement path="${test.dir}/lib"/> - <pathelement path="${test.dir}/lib/combo"/> - <pathelement path="${test.dir}/tools/javac/lib"/> - <pathelement path="${test.dir}/tools/javac/classfiles/attributes/LocalVariableTable"/> - </sourcepath> - <!-- exclude the following "packages" found by <javadoc> - on the sourcepath --> - <excludepackage name="combo.tools.javac.combo"/> - <excludepackage name="tools.javac.combo"/> - <!-- library classes used for documentation --> - <classpath> - <pathelement path="${jtreg.home}/lib/testng.jar"/> - </classpath> - <!-- platform classes used for documentation --> - <bootclasspath> - <pathelement path="${langtools.classes}"/> - <pathelement path="${target.java.home}/jre/lib/rt.jar"/> - </bootclasspath> - </javadoc> - </target> - - <target name="sanity" - description="display settings of configuration values"> - <echo level="info">ant.home = ${ant.home}</echo> - <echo level="info">boot.java.home = ${boot.java.home}</echo> - <echo level="info">target.java.home = ${target.java.home}</echo> - <echo level="info">jtreg.home = ${jtreg.home}</echo> - <echo level="info">findbugs.home = ${findbugs.home}</echo> - <echo level="info">checkstyle.home = ${checkstyle.home}</echo> - </target> - - <target name="diagnostics"> - <diagnostics/> - </target> - - <target name="jtreg-crules" depends="build-all-classes,-def-jtreg"> - <mkdir dir="${build.crules.dir}/classes"/> - <javac fork="true" - source="${boot.javac.source}" - target="${boot.javac.target}" - executable="${boot.java.home}/bin/javac" - srcdir="${make.tools.dir}" - includes="crules/*" - destdir="${build.crules.dir}/classes" - includeantruntime="false"> - <compilerarg value="-Xbootclasspath/p:${langtools.classes}"/> - <compilerarg line="${javac.lint.opts}"/> - </javac> - <copy todir="${build.crules.dir}/classes" includeemptydirs="false"> - <fileset dir="${make.tools.dir}"> - <include name="**/*.properties"/> - </fileset> - </copy> - <echo file="${build.crules.dir}/classes/META-INF/services/com.sun.source.util.Plugin">crules.CodingRulesAnalyzerPlugin</echo> - <jtreg-tool name="crules" - tests="${crules.tests}" - extra.jvmargs="-Xbootclasspath/a:${build.crules.dir}/classes" /> - </target> - - <!-- - **** IDE support - --> - - <target name="idea"> - <mkdir dir=".idea"/> - <copy todir=".idea" > - <fileset dir="make/intellij" excludes="**/src/**"/> - </copy> - <condition property="idea.jtreg.home" value="${jtreg.home}" else = "[jtreg.home]"> - <isset property="jtreg.home"/> - </condition> - <condition property="idea.target.jdk" value="${target.java.home}" else = "$JDKPath$"> - <isset property="target.java.home"/> - </condition> - <replace file=".idea/ant.xml" token="@IDEA_JTREG_HOME@" value="${idea.jtreg.home}"/> - <replace file=".idea/ant.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/> - <replace file=".idea/workspace.xml" token="@FILE_SEP@" value="${file.separator}"/> - <replace file=".idea/workspace.xml" token="@PATH_SEP@" value="${path.separator}"/> - <mkdir dir=".idea/classes"/> - <javac srcdir="make/intellij/src" - destdir=".idea/classes"/> - </target> - - <!-- - **** Check targets. - **** "-check-*" targets check that a required property is set, and set to a reasonable value. - **** A user friendly message is generated if not, and the build exits. - --> - - <target name="-check-boot.java.home" depends="-def-check"> - <check name="bootstrap java" property="boot.java.home" marker="${java.marker}"/> - </target> - - <target name="-check-target.java.home" depends="-def-check"> - <check name="target java" property="target.java.home" marker="${java.marker}"/> - </target> - - <target name="-check-jtreg.home" depends="-def-check"> - <check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/> - </target> - - <target name="-check-findbugs.home" depends="-def-check"> - <check name="findbugs" property="findbugs.home" marker="lib/findbugs.jar"/> - </target> - - <target name="-check-checkstyle.home" depends="-def-check"> - <check name="checkstyle" property="checkstyle.home" marker=""/> <!--TODO: better checkstyle verification--> - </target> - - <!-- Definitions --> - - <target name="-def-build-all-module-jars" depends="-def-build-module-jar"> - <macrodef name="build-all-module-jars"> - <attribute name="compilation.kind" default=""/> - <sequential> - <build-module-jar module.name="java.compiler" compilation.kind="@{compilation.kind}" /> - <build-module-jar module.name="jdk.compiler" compilation.kind="@{compilation.kind}" /> - <build-module-jar module.name="jdk.javadoc" compilation.kind="@{compilation.kind}" /> - <build-module-jar module.name="jdk.jdeps" compilation.kind="@{compilation.kind}" /> - <build-module-jar module.name="jdk.internal.le" compilation.kind="@{compilation.kind}" /> - <build-module-jar module.name="jdk.jdi" compilation.kind="@{compilation.kind}" /> - <build-module-jar module.name="jdk.jshell" compilation.kind="@{compilation.kind}" /> - </sequential> - </macrodef> - </target> - - <target name="-def-build-module-jar"> - <macrodef name="build-module-jar"> - <attribute name="module.name"/> - <attribute name="compilation.kind"/> - <attribute name="dependencies" default="${@{compilation.kind}@{module.name}.dependencies}"/> - <attribute name="build.dir" default="${@{compilation.kind}build.dir}"/> - <attribute name="lib.dir" default="${@{compilation.kind}dist.lib.dir}"/> - <attribute name="classes.dir" default="@{build.dir}/@{module.name}/classes"/> - <sequential> - <mkdir dir="@{lib.dir}"/> - <local name="jarclasspath" /> - <pathconvert property="jarclasspath"> - <path> - <pathelement path="@{dependencies}" /> - </path> - <map from="${basedir}/" to="" /> - <mapper type="glob" from="*" to="*.jar"/> - </pathconvert> - <jar destfile="@{lib.dir}/@{module.name}.jar" - basedir="@{classes.dir}"> - <manifest> - <attribute name="Class-Path" value="@{jarclasspath}"/> - </manifest> - </jar> - </sequential> - </macrodef> - </target> - - <target name="-def-build-tool"> - <macrodef name="build-tool"> - <attribute name="name"/> - <attribute name="compilation.kind" default=""/> - <attribute name="bin.dir" default="${@{compilation.kind}dist.bin.dir}"/> - <attribute name="java" default="${launcher.java}"/> - <attribute name="main.class" default="${tool.@{name}.main.class}"/> - <sequential> - <mkdir dir="@{bin.dir}"/> - <copy file="${make.dir}/launcher.sh-template" tofile="@{bin.dir}/@{name}"> - <filterset begintoken="#" endtoken="#"> - <filter token="PROGRAM" value="@{main.class}"/> - <filter token="TARGET_JAVA" value="@{java}"/> - <filter token="PS" value="${path.separator}"/> - </filterset> - </copy> - <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/> - </sequential> - </macrodef> - </target> - - <target name="-def-build-all-module-classes" depends="-def-build-module-classes"> - <macrodef name="build-all-module-classes"> - <attribute name="compilation.kind" default=""/> - <sequential> - <build-module-classes module.name="java.compiler" - compilation.kind="@{compilation.kind}" /> - <build-module-classes module.name="jdk.compiler" - compilation.kind="@{compilation.kind}" - resource.includes="${javac.resource.includes}" /> - <build-module-classes module.name="jdk.javadoc" - compilation.kind="@{compilation.kind}" /> - <build-module-classes module.name="jdk.jdeps" - compilation.kind="@{compilation.kind}" /> - <copy-module-classes module.name="jdk.internal.le" - compilation.kind="@{compilation.kind}" /> - <copy-module-classes module.name="jdk.jdi" - compilation.kind="@{compilation.kind}" /> - <build-module-classes module.name="jdk.jshell" - compilation.kind="@{compilation.kind}" /> - </sequential> - </macrodef> - </target> - - <target name="-def-build-module-classes" depends="-def-pcompile,-def-pparse,-def-cdumper"> - <macrodef name="build-module-classes"> - <attribute name="module.name"/> - <attribute name="compilation.kind" default=""/> - <attribute name="resource.includes" default="nonExistent" /> - <attribute name="dependencies" default="${@{module.name}.dependencies}"/> - <attribute name="includes" default="${@{compilation.kind}javac.includes}"/> - <attribute name="javac.lint.opts" default="${@{compilation.kind}javac.lint.opts}"/> - <attribute name="javac.extra.opts" default="${@{compilation.kind}javac.extra.opts}"/> - <attribute name="build.dir" default="${@{compilation.kind}build.dir}"/> - <attribute name="excludes" default="${exclude.files} **/package-info.java"/> - <attribute name="classes.dir" default="@{build.dir}/@{module.name}/classes"/> - <attribute name="gensrc.dir" default="@{build.dir}/@{module.name}/gensrc"/> - <attribute name="depcache.dir" default="@{build.dir}/@{module.name}/depcache"/> - <attribute name="java.home" default="${boot.java.home}"/> - <attribute name="source" default="${@{compilation.kind}javac.source}"/> - <attribute name="target" default="${@{compilation.kind}javac.target}"/> - <attribute name="release" default="${release}"/> - <attribute name="full.version" default="${full.version}"/> - <attribute name="plugin.options" default=""/> - <sequential> - <echo level="verbose" message="build-classes: excludes=@{excludes}"/> - <echo level="verbose" message="build-classes: classpath=@{classpath}"/> - <echo level="verbose" message="build-classes: sourcepath=@{sourcepath}"/> - <echo level="verbose" message="build-classes: dependencies=@{dependencies}"/> - <local name="src.dir" /> - <property name="src.dir" location="${basedir}/src/@{module.name}/share/classes"/> - <local name="classpath" /> - <pathconvert property="classpath"> - <path> - <pathelement path="@{dependencies}" /> - </path> - <map from="${basedir}/" to="@{build.dir}/" /> - <mapper type="glob" from="*" to="*/classes"/> - </pathconvert> - <local name="bootclasspath.prepend"/> - <condition property="bootclasspath.prepend" value="" else="${langtools.boot.classes}"> - <equals arg1="@{compilation.kind}" arg2="boot."/> - </condition> - <mkdir dir="@{classes.dir}"/> - <mkdir dir="@{gensrc.dir}"/> - <mkdir dir="@{depcache.dir}"/> - <pcompile destdir="@{gensrc.dir}" - includes="@{includes}"> - <src> - <path location="${src.dir}"/> - </src> - </pcompile> - <pparse destdir="@{gensrc.dir}" - includes="@{resource.includes}"> - <src> - <path location="${src.dir}"/> - </src> - </pparse> - <copy todir="@{gensrc.dir}"> - <fileset dir="${src.dir}" includes="@{includes}" /> - <globmapper from="*.properties-template" to="*.properties"/> - <filterset begintoken="$(" endtoken=")"> - <filter token="JDK_VERSION" value="${jdk.version}"/> - <filter token="RELEASE" value="@{release}"/> - <filter token="FULL_VERSION" value="@{full.version}"/> - </filterset> - </copy> - <pcompile destdir="@{gensrc.dir}" - includes="**/*.properties"> - <src> - <pathelement location="@{gensrc.dir}"/> - </src> - </pcompile> - <antcall target="-do-depend"> - <param name="src.dir" value="${src.dir}" /> - <param name="classes.dir" value="@{classes.dir}" /> - <param name="gensrc.dir" value="@{gensrc.dir}" /> - <param name="depcache.dir" value="@{depcache.dir}" /> - <param name="classpath" value="${classpath}" /> - </antcall> - <javac fork="true" - executable="@{java.home}/bin/javac" - destdir="@{classes.dir}" - includes="@{includes}" - excludes="@{excludes}" - sourcepath="${src.dir}:@{gensrc.dir}" - classpath="${classpath}" - includeAntRuntime="no" - source="@{source}" - target="@{target}" - debug="${javac.debug}" - debuglevel="${javac.debuglevel}"> - <compilerarg value="-implicit:none"/> - <compilerarg value="-Xprefer:source"/> - <compilerarg value="-J-Xbootclasspath/p:${bootclasspath.prepend}"/> - <compilerarg value="-Xbootclasspath/p:${classpath}"/> - <compilerarg line="@{javac.extra.opts}"/> - <compilerarg line="@{javac.lint.opts}"/> - <compilerarg line="@{plugin.options}"/> - <src> - <path location="${src.dir}"/> - <path location="@{gensrc.dir}"/> - </src> - </javac> - <copy todir="@{classes.dir}" includeemptydirs="false"> - <fileset dir="${src.dir}" includes="@{includes}" excludes="@{excludes}"> - <exclude name="**/*.java"/> - <exclude name="**/*.properties"/> - <exclude name="**/*-template"/> - <exclude name="**/*.rej"/> - <exclude name="**/*.orig"/> - <exclude name="**/overview.html"/> - <exclude name="**/package.html"/> - </fileset> - </copy> - </sequential> - </macrodef> - <macrodef name="copy-module-classes"> - <attribute name="module.name"/> - <attribute name="compilation.kind" default=""/> - <attribute name="build.dir" default="${@{compilation.kind}build.dir}"/> - <attribute name="classes.dir" default="@{build.dir}/@{module.name}/classes"/> - <attribute name="java.home" default="${boot.java.home}"/> - <sequential> - <property name="classes.origin.dir" location="${target.java.home}/../../jdk/modules/@{module.name}"/> - <mkdir dir="@{classes.dir}"/> - <dumpclasses moduleName="@{module.name}" destDir="@{classes.dir}" /> - </sequential> - </macrodef> - </target> - - <target name="-def-pparse"> - <mkdir dir="${build.toolclasses.dir}"/> - <copy todir="${build.toolclasses.dir}/propertiesparser" > - <fileset dir="make/tools/propertiesparser" includes="**/resources/**"/> - </copy> - <javac fork="true" - source="${boot.javac.source}" - target="${boot.javac.target}" - executable="${boot.java.home}/bin/javac" - srcdir="${make.tools.dir}" - includes="propertiesparser/* anttasks/PropertiesParser* anttasks/PathFileSet*" - destdir="${build.toolclasses.dir}/" - classpath="${ant.core.lib}" - bootclasspath="${boot.java.home}/jre/lib/rt.jar" - includeantruntime="false"> - <compilerarg line="${javac.lint.opts}"/> - </javac> - <taskdef name="pparse" - classname="anttasks.PropertiesParserTask" - classpath="${build.toolclasses.dir}/"/> - </target> - - <target name="-def-cdumper"> - <mkdir dir="${build.toolclasses.dir}"/> - <javac fork="true" - source="${boot.javac.source}" - target="${boot.javac.target}" - executable="${boot.java.home}/bin/javac" - srcdir="${make.tools.dir}" - includes="anttasks/DumpClass*" - destdir="${build.toolclasses.dir}/" - classpath="${ant.core.lib}" - bootclasspath="${boot.java.home}/jre/lib/rt.jar" - includeantruntime="false"> - <compilerarg line="${javac.lint.opts}"/> - </javac> - <taskdef name="dumpclasses" - classname="anttasks.DumpClassesTask" - classpath="${build.toolclasses.dir}/:${target.java.home}/jrt-fs.jar"/> - </target> - - <target name="-do-depend" if="do.depend"> - <depend srcdir="${src.dir}:${gensrc.dir}" destdir="${classes.dir}" classpath="${classpath}" - cache="${depcache.dir}"/> - </target> - - <target name="-def-pcompile"> - <mkdir dir="${build.toolclasses.dir}"/> - <javac fork="true" - source="${boot.javac.source}" - target="${boot.javac.target}" - executable="${boot.java.home}/bin/javac" - srcdir="${make.tools.dir}" - includes="compileproperties/* anttasks/CompileProperties* anttasks/PathFileSet*" - destdir="${build.toolclasses.dir}/" - classpath="${ant.core.lib}" - bootclasspath="${boot.java.home}/jre/lib/rt.jar" - includeantruntime="false"> - <compilerarg line="${javac.lint.opts}"/> - </javac> - <taskdef name="pcompile" - classname="anttasks.CompilePropertiesTask" - classpath="${build.toolclasses.dir}/"/> - </target> - - <target name="-def-javadoc-tool" depends="-check-target.java.home"> - <macrodef name="javadoc-tool"> - <attribute name="includes" default="${javac.includes}"/> - <attribute name="options" default=""/> - <attribute name="source" default="${javac.source}"/> - <sequential> - <property name="javadoc.options" value=""/> <!-- default, can be overridden per user or per project --> - <!-- Note: even with this default value, includes - from source directories get javadoc'd; see packageset below --> - <property name="javadoc.packagenames" value="none"/> <!-- default, can be overridden per user or per project --> - <javadoc - executable="${target.java.home}/bin/javadoc" - destdir="${build.javadoc.dir}" - source="@{source}" - windowtitle="UNOFFICIAL" - failonerror="true" - use="true" - author="false" - version="false" - packagenames="${javadoc.packagenames}" > - <header><![CDATA[<strong>Unofficial Javadoc</strong> generated from developer sources for preview purposes only]]></header> - <arg line="@{options}"/> - <bootclasspath> - <pathelement path="${langtools.classes}"/> - <path location="${target.java.home}/jre/lib/rt.jar"/> - </bootclasspath> - <sourcepath> - <pathelement path="${langtools.sources}"/> - </sourcepath> - <!-- XXX just <fileset> (restricted further to **/*.java) and no <packageset> --> - <!-- means that {@link some.package} will not work, which is no good. --> - <!-- (It correctly skips excluded single classes, but not if packageset is also included, --> - <!-- which also causes duplicates in the class index for included files.) --> - <packageset dir="${basedir}/src/java.compiler/share/classes" includes="@{includes}"> - <or> - <filename name="javax/"/> - </or> - </packageset> - <packageset dir="${basedir}/src/jdk.compiler/share/classes" includes="@{includes}"> - <or> - <filename name="com/sun/source/"/> - </or> - </packageset> - <packageset dir="${basedir}/src/jdk.javadoc/share/classes" includes="@{includes}"> - <or> - <filename name="com/sun/javadoc/"/> - </or> - </packageset> - </javadoc> - </sequential> - </macrodef> - </target> - - <target name="-def-jtreg" unless="jtreg.defined" depends="-check-jtreg.home,-check-target.java.home"> - <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant"> - <classpath> - <pathelement location="${jtreg.home}/lib/jtreg.jar"/> - <pathelement location="${jtreg.home}/lib/javatest.jar"/> - </classpath> - </taskdef> - <macrodef name="jtreg-tool"> - <attribute name="name"/> - <attribute name="tests"/> - <attribute name="langtools.classes" default="${langtools.classes}"/> - <attribute name="jdk" default="${target.java.home}"/> - <attribute name="samevm" default="true"/> - <attribute name="verbose" default="${default.jtreg.verbose}"/> - <attribute name="options" default="${other.jtreg.options}"/> - <attribute name="keywords" default="-keywords:!ignore"/> - <attribute name="jpda.jvmargs" default=""/> - <attribute name="extra.jvmargs" default=""/> - <attribute name="build.dir" default="${build.dir}"/> - <sequential> - <property name="coverage.options" value=""/> <!-- default --> - <property name="coverage.classpath" value=""/> <!-- default --> - <property name="default.jtreg.verbose" value="summary"/> <!-- default --> - <property name="other.jtreg.options" value=""/> <!-- default --> - <jtreg - dir="${test.dir}" - workDir="${build.jtreg.dir}/@{name}/work" - reportDir="${build.jtreg.dir}/@{name}/report" - jdk="@{jdk}" - samevm="@{samevm}" verbose="@{verbose}" - failonerror="false" resultproperty="jtreg.@{name}.result" - javacoptions="-g" - vmoptions="${coverage.options} -Xbootclasspath/p:${coverage.classpath}${path.separator}@{langtools.classes} @{jpda.jvmargs} @{extra.jvmargs}"> - <arg line="@{keywords}"/> - <arg line="@{options}"/> - <arg line="@{tests}"/> - </jtreg> - <!-- the next two properties are for convenience, when only - a single instance of jtreg will be invoked. --> - <condition property="jtreg.passed"> - <equals arg1="${jtreg.@{name}.result}" arg2="0"/> - </condition> - <property name="jtreg.report" value="${build.jtreg.dir}/@{name}/report"/> - </sequential> - </macrodef> - <property name="jtreg.defined" value="true"/> - </target> - - <target name="-def-checkstyle" unless="checkstyle.defined" depends="-check-checkstyle.home"> - <taskdef resource="checkstyletask.properties"> - <classpath> - <fileset dir="${checkstyle.home}"> - <include name="checkstyle-*-all.jar"/> - </fileset> - </classpath> - </taskdef> - <property name="checkstyle.defined" value="true"/> - </target> - - <target name="-def-findbugs" unless="findbugs.defined" - depends="-check-findbugs.home,-check-target.java.home"> - <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"> - <classpath> - <pathelement location="${findbugs.home}/lib/findbugs.jar"/> - </classpath> - </taskdef> - <macrodef name="findbugs-tool"> - <attribute name="name"/> - <attribute name="output" default="emacs"/> - <attribute name="outputFile" default=""/> - <attribute name="reportLevel" default="high"/> - <sequential> - <findbugs - home="${findbugs.home}" - output="@{output}" - outputFile="@{outputFile}" - reportLevel="@{reportLevel}" - failOnError="false" - errorProperty="findbugs.@{name}.errors" - warningsProperty="findbugs.@{name}.warnings" - jvm="${target.java.home}/bin/java" - jvmargs="-Xmx512M" > - <class location="${dist.dir}/lib/@{name}.jar"/> - <auxClasspath> - <pathelement location="${langtools.classes}"/> - </auxClasspath> - <sourcePath> - <path refid="src.dirs"/> - </sourcePath> - </findbugs> - </sequential> - </macrodef> - <property name="findbugs.defined" value="true"/> - </target> - <target name="-def-check"> - <macrodef name="check"> - <attribute name="name"/> - <attribute name="property"/> - <attribute name="marker" default=""/> + <macrodef name="check"> + <attribute name="name"/> + <attribute name="property"/> + <attribute name="marker" default=""/> <sequential> <fail message="Cannot locate @{name}: please set @{property} to its location"> <condition> @@ -917,5 +143,207 @@ </macrodef> </target> + <target name="-check-langtools.jdk.home" depends="-def-check"> + <check name="target java" property="langtools.jdk.home" marker="${java.marker}"/> + </target> + + <target name="-check-jtreg.home" depends="-def-check"> + <check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/> + </target> + + <!-- + **** Primary targets + --> + + <target name="clean" description="Delete all generated files"> + <delete dir="${build.dir}"/> + </target> + + <target name="build" depends="build-all-tools"/> + + <target name="-prepare-build" depends="-check-langtools.jdk.home"> + <mkdir dir="${build.modules}"/> + <mkdir dir="${build.tools}"/> + <mkdir dir="${build.gensrc}"/> + <mkdir dir="${build.bin}"/> + <mkdir dir="${build.prevsrc}"/> + </target> + + <target name="generate-sources-internal"> + <basename property="module.name" file="${basedir}"/> + <pparse destdir="${build.gensrc}/${module.name}" includes="${langtools.resource.includes}"> + <src path="./share/classes"/> + </pparse> + <pcompile destdir="${build.gensrc}/${module.name}" includes="**/*.properties"> + <src path="./share/classes"/> + </pcompile> + </target> + + <target name="generate-sources" depends="-prepare-build,-def-pparse,-def-pcompile"> + <subant inheritall="true" target="generate-sources-internal" genericantfile="${make.dir}/build.xml"> + <dirset dir="${src.dir}" includes="*.*"/> + </subant> + </target> + + <target name="build-all-classes" depends="generate-sources"> + <exec executable="${langtools.jdk.home}/bin/javac" failonerror="true"> + <arg line="-source ${javac.source} -target ${javac.target}" /> + <arg value="-d" /> + <arg value="${build.modules}" /> + <arg line="${javac.opts} -modulesourcepath ${src.dir}${file.separator}*${file.separator}share${file.separator}classes:${build.gensrc} -m java.compiler,jdk.compiler,jdk.javadoc,jdk.jdeps,jdk.jshell" /> + </exec> + <delete> + <fileset dir="${build.modules}" includes="**/module-info.class"/> + </delete> + </target> + + <target name="build-all-tools" depends="build-all-classes, -def-build-tool"> + <build-tool name="javac"/> + <build-tool name="javadoc"/> + <build-tool name="javap"/> + <build-tool name="javah"/> + <build-tool name="jdeps"/> + <build-tool name="sjavac"/> + <build-tool name="jshell"/> + </target> + + <target name="jtreg" depends="build-all-tools,-def-jtreg"> + <jtreg-tool name="all" tests="${jtreg.tests}"/> + </target> + + <!-- + **** IDE support + --> + + <target name="idea" depends="-check-langtools.jdk.home"> + <mkdir dir=".idea"/> + <copy todir=".idea" > + <fileset dir="make/intellij" excludes="**/src/**"/> + </copy> + <condition property="idea.jtreg.home" value="${jtreg.home}" else = "[jtreg.home]"> + <isset property="jtreg.home"/> + </condition> + <condition property="idea.target.jdk" value="${langtools.jdk.home}" else = "$JDKPath$"> + <isset property="langtools.jdk.home"/> + </condition> + <replace file=".idea/ant.xml" token="@IDEA_JTREG_HOME@" value="${idea.jtreg.home}"/> + <replace file=".idea/ant.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/> + <replace file=".idea/workspace.xml" token="@IDEA_TARGET_JDK@" value="${idea.target.jdk}"/> + <replace file=".idea/workspace.xml" token="@FILE_SEP@" value="${file.separator}"/> + <replace file=".idea/workspace.xml" token="@PATH_SEP@" value="${path.separator}"/> + <mkdir dir=".idea/classes"/> + <javac srcdir="make/intellij/src" + destdir=".idea/classes"/> + </target> + + <!-- + **** Utility definitions + --> + + <target name="-def-pparse"> + <copy todir="${build.tools}/propertiesparser" > + <fileset dir="${make.tools.dir}/propertiesparser" includes="**/resources/**"/> + </copy> + <javac fork="true" + source="${javac.source}" + target="${javac.target}" + executable="${langtools.jdk.home}/bin/javac" + srcdir="${make.tools.dir}" + includes="propertiesparser/* anttasks/PropertiesParser* anttasks/PathFileSet*" + destdir="${build.tools}" + classpath="${ant.core.lib}" + bootclasspath="${langtools.jdk.home}/jre/lib/rt.jar" + includeantruntime="false"> + <compilerarg line="${javac.opts} -XDstringConcat=inline"/> + </javac> + <taskdef name="pparse" + classname="anttasks.PropertiesParserTask" + classpath="${build.tools}"/> + </target> + + <target name="-def-pcompile"> + <javac fork="true" + source="${javac.source}" + target="${javac.target}" + executable="${langtools.jdk.home}/bin/javac" + srcdir="${make.tools.dir}" + includes="compileproperties/* anttasks/CompileProperties* anttasks/PathFileSet*" + destdir="${build.dir}/toolclasses/" + classpath="${ant.core.lib}" + includeantruntime="false"> + <compilerarg line="${javac.opts} -XDstringConcat=inline"/> + </javac> + <taskdef name="pcompile" + classname="anttasks.CompilePropertiesTask" + classpath="${build.tools}"/> + </target> + + <target name="-def-build-tool"> + <macrodef name="build-tool"> + <attribute name="name"/> + <attribute name="compilation.kind" default=""/> + <attribute name="bin.dir" default="${build.bin}"/> + <attribute name="java" default="${launcher.java}"/> + <attribute name="main.class" default="${tool.@{name}.main.class}"/> + <sequential> + <mkdir dir="@{bin.dir}"/> + <copy file="${make.dir}/launcher.sh-template" tofile="@{bin.dir}/@{name}"> + <filterset begintoken="#" endtoken="#"> + <filter token="PROGRAM" value="@{main.class}"/> + <filter token="TARGET_JAVA" value="@{java}"/> + <filter token="PS" value="${path.separator}"/> + </filterset> + </copy> + <chmod file="@{bin.dir}/@{name}" perm="ugo+rx"/> + </sequential> + </macrodef> + </target> + + <target name="-def-jtreg" unless="jtreg.defined" depends="-check-jtreg.home,-check-langtools.jdk.home"> + <taskdef name="jtreg" classname="com.sun.javatest.regtest.Main$$Ant"> + <classpath> + <pathelement location="${jtreg.home}/lib/jtreg.jar"/> + <pathelement location="${jtreg.home}/lib/javatest.jar"/> + </classpath> + </taskdef> + <macrodef name="jtreg-tool"> + <attribute name="name"/> + <attribute name="tests"/> + <attribute name="jdk" default="${langtools.jdk.home}"/> + <attribute name="agentvm" default="true"/> + <attribute name="verbose" default="${default.jtreg.verbose}"/> + <attribute name="options" default="${other.jtreg.options}"/> + <attribute name="keywords" default="-keywords:!ignore"/> + <attribute name="jpda.jvmargs" default=""/> + <attribute name="extra.jvmargs" default=""/> + <attribute name="build.modules" default="${build.modules}"/> + <sequential> + <property name="coverage.options" value=""/> <!-- default --> + <property name="coverage.classpath" value=""/> <!-- default --> + <property name="default.jtreg.verbose" value="summary"/> <!-- default --> + <property name="other.jtreg.options" value=""/> <!-- default --> + <property name="jtreg.classfiles.to.modules" value="@{agentvm}"/> + <jtreg + dir="${test.dir}" + workDir="${build.jtreg}/@{name}/work" + reportDir="${build.jtreg}/@{name}/report" + jdk="@{jdk}" + agentvm="@{agentvm}" verbose="@{verbose}" + failonerror="false" resultproperty="jtreg.@{name}.result" + vmoptions="${coverage.options} @{extra.jvmargs} -Xpatch:@{build.modules}"> + <arg value="-debug:@{jpda.jvmargs}"/> + <arg line="@{keywords}"/> + <arg line="@{options}"/> + <arg line="@{tests}"/> + </jtreg> + <!-- the next two properties are for convenience, when only + a single instance of jtreg will be invoked. --> + <condition property="jtreg.passed"> + <equals arg1="${jtreg.@{name}.result}" arg2="0"/> + </condition> + <property name="jtreg.report" value="${build.jtreg}/@{name}/report"/> + </sequential> + </macrodef> + <property name="jtreg.defined" value="true"/> + </target> </project> -
--- a/make/gendata/Gendata-jdk.compiler.gmk Thu Mar 24 11:21:37 2016 +0100 +++ b/make/gendata/Gendata-jdk.compiler.gmk Thu Mar 24 16:21:21 2016 +0100 @@ -39,6 +39,10 @@ BIN := $(BUILDTOOLS_OUTPUTDIR)/create_symbols, \ )) +ifeq ($(BOOT_JDK_MODULAR), true) + COMPILECREATESYMBOLS_ADD_EXPORTS := -XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED,jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED,jdk.jdeps/com.sun.tools.classfile=ALL-UNNAMED +endif + $(SUPPORT_OUTPUTDIR)/symbols/ct.sym-files/_the.symbols: \ $(COMPILE_CREATE_SYMBOLS) \ $(wildcard $(LANGTOOLS_TOPDIR)/make/data/symbols/*) @@ -46,6 +50,7 @@ $(MKDIR) -p $(@D) $(ECHO) Creating ct.sym classes $(JAVA) $(INTERIM_LANGTOOLS_ARGS) \ + $(COMPILECREATESYMBOLS_ADD_EXPORTS) \ -classpath $(BUILDTOOLS_OUTPUTDIR)/create_symbols \ build.tools.symbolgenerator.CreateSymbols \ build-ctsym \
--- a/make/intellij/ant.xml Thu Mar 24 11:21:37 2016 +0100 +++ b/make/intellij/ant.xml Thu Mar 24 16:21:21 2016 +0100 @@ -3,16 +3,12 @@ <component name="AntConfiguration"> <buildFile url="file://$PROJECT_DIR$/.idea/build.xml"> <properties> - <property name="boot.java.home" value="$JDKPath$" /> <property name="jtreg.tests" value="$FilePath$" /> - <property name="target.java.home" value="@IDEA_TARGET_JDK@" /> + <property name="langtools.jdk.home" value="@IDEA_TARGET_JDK@" /> <property name="jtreg.home" value="@IDEA_JTREG_HOME@" /> - <property name="javac.debuglevel" value="source,lines,vars" /> - <property name="jtreg.jpda.jvmargs" value="-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5900,suspend=y" /> + <property name="jtreg.jpda.jvmargs" value="-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=5900" /> </properties> <executeOn event="afterCompilation" target="post-make" /> </buildFile> </component> </project> - -
--- a/make/intellij/build.xml Thu Mar 24 11:21:37 2016 +0100 +++ b/make/intellij/build.xml Thu Mar 24 16:21:21 2016 +0100 @@ -15,8 +15,7 @@ <java classname="org.apache.tools.ant.Main" fork="true" spawn="true"> <arg value="-f"/> <arg value="@{antfile}"/> - <arg value="-Dboot.java.home=${boot.java.home}"/> - <arg value="-Dtarget.java.home=${target.java.home}"/> + <arg value="-Dlangtools.jdk.home=${langtools.jdk.home}"/> <arg value="-Djtreg.home=${jtreg.home}"/> <arg value="-Djtreg.tests=${jtreg.tests}"/> <arg value="-Djtreg.jpda.jvmargs=${jtreg.jpda.jvmargs}"/> @@ -28,18 +27,13 @@ </sequential> </macrodef> - <target name="crules" depends="build-all-tools,-def-jtreg"> - <jtreg-tool name="all" tests="tools/all/RunCodingRules.java"/> - </target> - <target name="post-make" depends="clean, build-all-tools"/> - <target name="jtreg-debug" depends="build-all-tools,-def-jtreg"> + <target name="jtreg-debug" depends="build-all-tools, -def-jtreg"> <exec-target target="jtreg-debug-internal"/> </target> <target name="jtreg-debug-internal" depends="-def-jtreg"> - <jtreg-tool name="all" tests="${jtreg.tests}" jpda.jvmargs="${jtreg.jpda.jvmargs}"/> + <jtreg-tool name="all" tests="${jtreg.tests}" options="-conc:1" jpda.jvmargs="${jtreg.jpda.jvmargs}"/> </target> </project> -
--- a/make/intellij/langtools.iml Thu Mar 24 11:21:37 2016 +0100 +++ b/make/intellij/langtools.iml Thu Mar 24 16:21:21 2016 +0100 @@ -8,12 +8,11 @@ <sourceFolder url="file://$MODULE_DIR$/src/jdk.compiler/share/classes" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/jdk.javadoc/share/classes" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/jdk.jdeps/share/classes" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/jdk.jshell/share/classes" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> - <sourceFolder url="file://$MODULE_DIR$/build/bootstrap/java.compiler/gensrc" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/build/bootstrap/jdk.compiler/gensrc" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/build/bootstrap/jdk.javadoc/gensrc" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/build/bootstrap/jdk.jdeps/gensrc" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/src/jdk.jshell/share/classes" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/build/gensrc/jdk.compiler" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/build/gensrc/jdk.javadoc" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/build/gensrc/jdk.jdeps" isTestSource="false" /> </content> <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="inheritedJdk" />
--- a/make/intellij/src/idea/LangtoolsIdeaAntLogger.java Thu Mar 24 11:21:37 2016 +0100 +++ b/make/intellij/src/idea/LangtoolsIdeaAntLogger.java Thu Mar 24 16:21:21 2016 +0100 @@ -124,8 +124,8 @@ * This enum is used to represent the list of tasks we need to keep track of during logging. */ enum Task { - /** javac task - invoked during compilation */ - JAVAC("javac", MessageKind.JAVAC_ERROR, MessageKind.JAVAC_WARNING, MessageKind.JAVAC_NOTE, + /** exec task - invoked during compilation */ + JAVAC("exec", MessageKind.JAVAC_ERROR, MessageKind.JAVAC_WARNING, MessageKind.JAVAC_NOTE, MessageKind.JAVAC_NESTED_DIAG, MessageKind.JAVAC_CRASH), /** jtreg task - invoked during test execution */ JTREG("jtreg", MessageKind.JTREG_TEST_PASSED, MessageKind.JTREG_TEST_FAILED, MessageKind.JTREG_TEST_ERROR, MessageKind.JTREG_TEST_REPORT),
--- a/make/intellij/workspace.xml Thu Mar 24 11:21:37 2016 +0100 +++ b/make/intellij/workspace.xml Thu Mar 24 16:21:21 2016 +0100 @@ -7,14 +7,14 @@ <option name="MAKE_PROJECT_ON_SAVE" value="true" /> </component> <component name="RunManager" selected="Application.javac"> - <!-- standard tools --> + <!-- javac --> <configuration default="false" name="javac" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.javac.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xpatch:build@FILE_SEP@modules" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> - <option name="ALTERNATIVE_JRE_PATH" value="" /> + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" /> + <option name="ALTERNATIVE_JRE_PATH" value="@IDEA_TARGET_JDK@" /> <option name="ENABLE_SWING_INSPECTOR" value="false" /> <option name="ENV_VARIABLES" /> <option name="PASS_PARENT_ENVS" value="true" /> @@ -27,13 +27,14 @@ <option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-all-classes" /> </method> </configuration> + <!-- javadoc --> <configuration default="false" name="javadoc" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.javadoc.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xpatch:build@FILE_SEP@modules" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> - <option name="ALTERNATIVE_JRE_PATH" value="" /> + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" /> + <option name="ALTERNATIVE_JRE_PATH" value="@IDEA_TARGET_JDK@" /> <option name="ENABLE_SWING_INSPECTOR" value="false" /> <option name="ENV_VARIABLES" /> <option name="PASS_PARENT_ENVS" value="true" /> @@ -46,13 +47,14 @@ <option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-all-classes" /> </method> </configuration> + <!-- javap --> <configuration default="false" name="javap" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.javap.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xpatch:build@FILE_SEP@modules" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> - <option name="ALTERNATIVE_JRE_PATH" value="" /> + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" /> + <option name="ALTERNATIVE_JRE_PATH" value="@IDEA_TARGET_JDK@" /> <option name="ENABLE_SWING_INSPECTOR" value="false" /> <option name="ENV_VARIABLES" /> <option name="PASS_PARENT_ENVS" value="true" /> @@ -65,13 +67,14 @@ <option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-all-classes" /> </method> </configuration> + <!-- javah --> <configuration default="false" name="javah" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.javah.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xpatch:build@FILE_SEP@modules" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> - <option name="ALTERNATIVE_JRE_PATH" value="" /> + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" /> + <option name="ALTERNATIVE_JRE_PATH" value="@IDEA_TARGET_JDK@" /> <option name="ENABLE_SWING_INSPECTOR" value="false" /> <option name="ENV_VARIABLES" /> <option name="PASS_PARENT_ENVS" value="true" /> @@ -84,13 +87,14 @@ <option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-all-classes" /> </method> </configuration> + <!-- sjavac --> <configuration default="false" name="sjavac" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.sjavac.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xpatch:build@FILE_SEP@modules" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> - <option name="ALTERNATIVE_JRE_PATH" value="" /> + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" /> + <option name="ALTERNATIVE_JRE_PATH" value="@IDEA_TARGET_JDK@" /> <option name="ENABLE_SWING_INSPECTOR" value="false" /> <option name="ENV_VARIABLES" /> <option name="PASS_PARENT_ENVS" value="true" /> @@ -103,13 +107,15 @@ <option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-all-classes" /> </method> </configuration> + <!-- jshell --> <configuration default="false" name="jshell" type="Application" factoryName="Application"> <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" /> <option name="MAIN_CLASS_NAME" value="jdk.internal.jshell.tool.JShellTool" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build/jdk.internal.le/classes:build/jdk.jdi/classes:build/jdk.jshell/classes:build/java.compiler/classes:build/jdk.compiler/classes:build/jdk.javadoc/classes:build/jdk.jdeps/classes" /> + <option name="VM_PARAMETERS" value="-Xpatch:build@FILE_SEP@modules -XaddExports:jdk.jshell/jdk.internal.jshell.tool=ALL-UNNAMED" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> + <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" /> + <option name="ALTERNATIVE_JRE_PATH" value="@IDEA_TARGET_JDK@" /> <option name="ENABLE_SWING_INSPECTOR" value="false" /> <option name="ENV_VARIABLES" /> <option name="PASS_PARENT_ENVS" value="true" /> @@ -120,24 +126,11 @@ <option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-all-classes" /> </method> </configuration> - <!-- bootstrap javac --> - <configuration default="false" name="javac (bootstrap)" type="Application" factoryName="Application"> - <option name="MAIN_CLASS_NAME" value="com.sun.tools.javac.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@bootstrap@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> - <option name="PROGRAM_PARAMETERS" value="" /> - <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> - <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> - <option name="ALTERNATIVE_JRE_PATH" value="" /> - <option name="ENABLE_SWING_INSPECTOR" value="false" /> - <option name="ENV_VARIABLES" /> - <option name="PASS_PARENT_ENVS" value="true" /> - <module name="langtools" /> - <envs /> - <RunnerSettings RunnerId="Run" /> - <ConfigurationWrapper RunnerId="Run" /> + <!-- jtreg run --> + <configuration default="false" name="jtreg (run)" type="AntRunConfiguration" factoryName="Ant Target"> + <antsettings antfile="file://$PROJECT_DIR$/.idea/build.xml" target="jtreg" /> <method> <option name="Make" enabled="false" /> - <option name="AntTarget" enabled="true" antfile="file://$PROJECT_DIR$/.idea/build.xml" target="build-bootstrap-javac" /> </method> </configuration> <!-- jtreg debug --> @@ -181,4 +174,3 @@ </buildFile> </component> </project> -
--- a/make/launcher.sh-template Thu Mar 24 11:21:37 2016 +0100 +++ b/make/launcher.sh-template Thu Mar 24 16:21:21 2016 +0100 @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2016, 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 @@ -31,22 +31,10 @@ mydir=`cygpath -m $mydir` ;; esac -mylib="$mydir/../lib" +mylib="$mydir/../modules" -# By default, put the jar file and its dependencies on the bootclasspath. -# This is always required on a Mac, because the system langtools classes -# are always on the main class path; in addition, it may be required on -# standard versions of JDK (i.e. using rt.jar and tools.jar) because some -# langtools interfaces are in rt.jar. -# Assume that the jar file being invoked lists all the necessary langtools -# jar files in its Class-Path manifest entry, so there is no need to search -# dependent jar files for additional dependencies. - -if [ "$LANGTOOLS_USE_BOOTCLASSPATH" != "no" ]; then - cp=`echo "$mylib"/*.jar | - sed -e 's|\([a-z.]*\.jar\) *|\1#PS#|g'` - bcp=$cp -fi +# patch langtools modules +bcp=-Xpatch:"$mylib" # tools currently assumes that assertions are enabled in the launcher ea=-ea:com.sun.tools... @@ -71,4 +59,4 @@ unset DUALCASE IFS=$nl -"#TARGET_JAVA#" "${bcp:+-Xbootclasspath/p:"$bcp"}" ${ea} ${javaOpts} #PROGRAM# ${toolOpts} +"#TARGET_JAVA#" $bcp ${ea} ${javaOpts} #PROGRAM# ${toolOpts}
--- a/make/netbeans/langtools/build.xml Thu Mar 24 11:21:37 2016 +0100 +++ b/make/netbeans/langtools/build.xml Thu Mar 24 16:21:21 2016 +0100 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -48,20 +48,12 @@ <!-- Build project. (action: build; F11) --> - <target name="build" depends="-get-tool-if-set,-build-bootstrap-javac,-build-all" /> - <target name="-build-bootstrap-javac" if="langtools.tool.bootstrap"> - <antcall target="build-bootstrap-javac"/> - </target> - <target name="-build-all" unless="langtools.tool.bootstrap"> - <antcall target="build-all-tools"/> - </target> - <!-- Compile a single file. (action: compile.single; F9) --> - <target name="compile-single" depends="-get-tool-if-set,build-bootstrap-javac-classes" unless="langtools.tool.bootstrap"> + <target name="compile-single" depends="-get-tool-if-set,-check-langtools.jdk.home"> <fail unless="includes">Must set property 'includes'</fail> <mkdir dir="${build.dir}/${module.name}/classes" /> - <javac fork="true" executable="${boot.java.home}/bin/javac" + <javac fork="true" executable="${java.home}/bin/javac" srcdir="${basedir}/src/${module.name}/share/classes" destdir="${build.dir}/${module.name}/classes" includes="${includes}" @@ -72,7 +64,6 @@ target="${javac.target}" debug="${javac.debug}" debuglevel="${javac.debuglevel}"> - <compilerarg value="-J-Xbootclasspath/p:${build.bootstrap.dir}/classes"/> </javac> </target> @@ -81,12 +72,11 @@ the user. --> - <target name="run" depends="-check-target.java.home,-build-classes,-def-run,-get-tool-and-args,-setup-bootclasspath,-def-resolve-main-class" + <target name="run" depends="-check-langtools.jdk.home,-build-classes,-def-run,-get-tool-and-args,-def-resolve-main-class" description="run tool"> - <echo level="info" message="${with_bootclasspath}"/> - <echo level="info" message="Run ${use_bootstrap}${langtools.tool.name} with args ${langtools.tool.args}"/> + <echo level="info" message="Run ${langtools.tool.name} with args ${langtools.tool.args}"/> <resolve-main-class tool.name="${langtools.tool.name}" /> - <run bcp="${with_bootclasspath}" mainclass="${langtools.main.class}" args="${langtools.tool.args}"/> + <run mainclass="${langtools.main.class}" args="${langtools.tool.args}"/> </target> <target name="-def-resolve-main-class"> @@ -102,17 +92,14 @@ </macrodef> </target> - <target name="-build-classes" depends="-get-tool-if-set,-build-classes-bootstrap-javac,-build-classes-all" /> - <target name="-build-classes-bootstrap-javac" if="langtools.tool.bootstrap"> - <antcall target="build-bootstrap-javac-classes"/> - </target> - <target name="-build-classes-all" unless="langtools.tool.bootstrap"> + <target name="-build-classes" depends="-get-tool-if-set,-build-classes-all" /> + <target name="-build-classes-all"> <antcall target="build-all-classes"/> </target> <!-- Run a selected class. (action: run.single; shift-F6) --> - <target name="run-single" depends="-check-target.java.home,-setup-bootclasspath,-def-run"> + <target name="run-single" depends="-check-langtools.jdk.home,-def-run"> <fail unless="run.classname">Must set property 'run.classname' </fail> <echo level="info" message="run ${run.classname}"/> <run mainclass="${run.classname}" args=""/> @@ -123,22 +110,12 @@ test all tools. --> - <target name="jtreg" depends="-get-tool-if-set,-jtreg-bootstrap-javac,-jtreg-all" - description="Test langtools tools or bootstrap javac" + <target name="jtreg" depends="-get-tool-if-set,-jtreg-all" + description="Test langtools tools" /> - <target name="-jtreg-bootstrap-javac" if="langtools.tool.bootstrap"> - <echo level="info" message="Testing bootstrap javac"/> - <echo level="verbose" message="(Unset langtools.tool.bootstrap to test all tools)"/> - <antcall> - <target name="jtreg-bootstrap-javac"/> - <target name="-show-jtreg"/> - </antcall> - </target> - - <target name="-jtreg-all" unless="langtools.tool.bootstrap"> + <target name="-jtreg-all"> <echo level="info" message="Testing all tools"/> - <echo level="verbose" message="(Set langtools.tool.bootstrap to test bootstrap javac)"/> <antcall> <target name="langtools.jtreg"/> <target name="-show-jtreg"/> @@ -173,29 +150,27 @@ <!-- Debug tool in NetBeans. --> - <target name="debug" depends="-check-target.java.home,-def-run,-def-start-debugger,-get-tool-and-args,-setup-bootclasspath,-build-classes,-def-resolve-main-class" if="netbeans.home"> - <echo level="info" message="Debug ${use_bootstrap}${langtools.tool.name} with args ${langtools.tool.args}"/> + <target name="debug" depends="-check-langtools.jdk.home,-def-run,-def-start-debugger,-get-tool-and-args,-build-classes,-def-resolve-main-class" if="netbeans.home"> + <echo level="info" message="Debug ${langtools.tool.name} with args ${langtools.tool.args}"/> <start-debugger/> <resolve-main-class tool.name="${langtools.tool.name}" /> - <run bcp="${with_bootclasspath}" mainclass="${langtools.main.class}" args="${langtools.tool.args}" jpda.jvmargs="${jpda.jvmargs}"/> + <run mainclass="${langtools.main.class}" args="${langtools.tool.args}" jpda.jvmargs="${jpda.jvmargs}"/> </target> <!-- Debug a selected class . --> - <target name="debug-single" depends="-check-target.java.home,-def-start-debugger,-def-run"> + <target name="debug-single" depends="-check-langtools.jdk.home,-def-start-debugger,-def-run"> <fail unless="debug.classname">Must set property 'debug.classname'</fail> <start-debugger/> <run mainclass="${debug.classname}" args="" jpda.jvmargs="${jpda.jvmargs}"/> </target> <!-- Debug a jtreg test. --> - <target name="debug-jtreg" depends="-check-target.java.home,-def-start-debugger,-def-jtreg,-get-tool-if-set,-setup-bootclasspath"> + <target name="debug-jtreg" depends="-check-langtools.jdk.home,-def-start-debugger,-def-jtreg,-get-tool-if-set"> <fail unless="jtreg.tests">Must set property 'jtreg.tests'</fail> <start-debugger/> <jtreg-tool name="debug" - samevm="false" tests="${jtreg.tests}" - jpda.jvmargs="${jpda.jvmargs}" - langtools.classes="${with_bootclasspath}"/> + jpda.jvmargs="${jpda.jvmargs}"/> </target> <!-- Update a class being debugged. --> @@ -206,11 +181,7 @@ <antcall target="compile-single"> <param name="includes" value="${class}.java"/> </antcall> - <condition property="build.classes.dir" - value="${build.dir}/${module.name}/classes" - else="${boot.build.dir}/${module.name}/classes"> - <isset property="use_bootstrap"/> - </condition> + <property name="build.classes.dir" value="${build.dir}/${module.name}/classes" /> <nbjpdareload> <fileset dir="${build.classes.dir}"> <include name="${class}.class"/> @@ -218,23 +189,11 @@ </nbjpdareload> </target> - <!-- Generate javadoc for one or all tools. (action: javadoc; Alt-F6) - If langtools.tool.name is set, then just test that tool; otherwise - test all tools. - --> - - <target name="javadoc" depends="langtools.javadoc,-show-javadoc" /> - - <target name="-show-javadoc" if="netbeans.home"> - <nbbrowse file="${build.javadoc.dir}/index.html"/> - </target> - <!-- Prompt for values. --> <target name="-get-tool-if-set" depends="-def-select-tool"> <select-tool toolproperty="langtools.tool.name" - bootstrapproperty="langtools.tool.bootstrap" propertyfile="${langtools.properties}" askIfUnset="false" /> @@ -244,32 +203,22 @@ <select-tool toolproperty="langtools.tool.name" argsproperty="langtools.tool.args" - bootstrapproperty="langtools.tool.bootstrap" propertyfile="${langtools.properties}" askIfUnset="true" /> </target> - <target name="-setup-bootclasspath"> - <condition property="use_bootstrap" value="bootstrap-" else=""> - <isset property="langtools.tool.bootstrap"/> - </condition> - <condition property="with_bootclasspath" value="${langtools.boot.classes}" else="${langtools.classes}"> - <isset property="langtools.tool.bootstrap"/> - </condition> - </target> - <!-- Macro to run a tool or selected class - used by run* and debug* tasks --> <target name="-def-run"> <macrodef name="run"> <attribute name="mainclass"/> <attribute name="args" default=""/> - <attribute name="bcp" default="${with_bootclasspath}"/> + <attribute name="build.modules" default="${build.modules}"/> <attribute name="jpda.jvmargs" default=""/> <sequential> - <java fork="true" jvm="${target.java.home}/bin/java" classname="@{mainclass}"> - <jvmarg line="-Xbootclasspath/p:@{bcp}"/> + <java fork="true" jvm="${langtools.jdk.home}/bin/java" classname="@{mainclass}"> + <jvmarg line="-Xpatch:@{build.modules}"/> <jvmarg line="@{jpda.jvmargs}"/> <arg line="@{args}"/> </java> @@ -285,11 +234,7 @@ <nbjpdastart name="${ant.project.name}" addressproperty="jpda.address" transport="dt_socket"> <bootclasspath> <pathelement path="${langtools.classes}"/> - <pathelement location="${target.java.home}/jre/lib/rt.jar"/> </bootclasspath> - <sourcepath> - <pathelement path="${langtools.sources}"/> - </sourcepath> </nbjpdastart> <property name="@{jpda.jvmargs.property}" @@ -300,6 +245,7 @@ </target> <target name="-def-select-tool"> + <property name="build.toolclasses.dir" location="${build.dir}/toolclasses"/> <mkdir dir="${build.toolclasses.dir}"/> <javac srcdir="${make.tools.dir}" includes="anttasks/SelectTool*"
--- a/make/netbeans/langtools/nbproject/project.xml Thu Mar 24 11:21:37 2016 +0100 +++ b/make/netbeans/langtools/nbproject/project.xml Thu Mar 24 16:21:21 2016 +0100 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -408,9 +408,6 @@ </arity> </context> </action> - <action name="javadoc"> - <target>javadoc</target> - </action> <action name="select-tool"> <target>select-tool</target> </action> @@ -477,7 +474,6 @@ <ide-action name="build"/> <ide-action name="rebuild"/> <ide-action name="clean"/> - <ide-action name="javadoc"/> <separator/> <ide-action name="run"/> <ide-action name="debug"/> @@ -490,37 +486,35 @@ <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/4"> <compilation-unit> <package-root>${root}/src/java.compiler/share/classes</package-root> - <package-root>${root}/build/bootstrap/java.compiler/gensrc</package-root> + <package-root>${root}/build/gensrc/java.compiler</package-root> <built-to>${root}/build/java.compiler/classes</built-to> <source-level>1.8</source-level> </compilation-unit> <compilation-unit> <package-root>${root}/src/jdk.compiler/share/classes</package-root> - <package-root>${root}/build/bootstrap/jdk.compiler/gensrc</package-root> + <package-root>${root}/build/gensrc/jdk.compiler</package-root> <classpath mode="compile">${root}/build/java.compiler/classes</classpath> <built-to>${root}/build/jdk.compiler/classes</built-to> <source-level>1.8</source-level> </compilation-unit> <compilation-unit> <package-root>${root}/src/jdk.jdeps/share/classes</package-root> - <package-root>${root}/build/bootstrap/jdk.jdeps/gensrc</package-root> + <package-root>${root}/build/gensrc/jdk.jdeps</package-root> <classpath mode="compile">${root}/build/java.compiler/classes:${root}/build/jdk.compiler/classes</classpath> <built-to>${root}/build/jdk.jdeps/classes</built-to> <source-level>1.8</source-level> </compilation-unit> <compilation-unit> <package-root>${root}/src/jdk.javadoc/share/classes</package-root> - <package-root>${root}/build/bootstrap/jdk.javadoc/gensrc</package-root> + <package-root>${root}/build/gensrc/jdk.javadoc</package-root> <classpath mode="compile">${root}/build/java.compiler/classes:${root}/build/jdk.compiler/classes</classpath> <built-to>${root}/build/jdk.javadoc/classes</built-to> <source-level>1.8</source-level> </compilation-unit> <compilation-unit> <package-root>${root}/src/jdk.jshell/share/classes</package-root> - <package-root>${root}/build/bootstrap/jdk.jshell/gensrc</package-root> - <package-root>${root}/../jdk/src/jdk.internal.le/share/classes</package-root> - <package-root>${root}/../jdk/src/jdk.jdi/share/classes</package-root> - <classpath mode="compile">${root}/build/java.compiler/classes:${root}/build/jdk.compiler/classes:${root}/build/jdk.internal.le/classes:${root}/build/jdk.jdi/classes</classpath> + <package-root>${root}/build/gensrc/jdk.jshell</package-root> + <classpath mode="compile">${root}/build/java.compiler/classes:${root}/build/jdk.compiler/classes</classpath> <built-to>${root}/build/jdk.jshell/classes</built-to> <source-level>1.8</source-level> </compilation-unit>
--- a/make/tools/anttasks/SelectToolTask.java Thu Mar 24 11:21:37 2016 +0100 +++ b/make/tools/anttasks/SelectToolTask.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -74,18 +74,7 @@ enum ToolChoices { NONE(""), - BOOSTRAP_JAVAC("bootstrap-javac", true) { - @Override - public ToolChoices baseTool() { - return JAVAC; - } - }, - JAVAC("javac") { - @Override - public ToolChoices asBootstrap() { - return BOOSTRAP_JAVAC; - } - }, + JAVAC("javac"), JAVADOC("javadoc"), JAVAH("javah"), JAVAP("javap"), @@ -103,14 +92,6 @@ this.bootstrap = bootstrap; } - public ToolChoices asBootstrap() { - return this; - } - - public ToolChoices baseTool() { - return this; - } - @Override public String toString() { return toolName; @@ -146,15 +127,6 @@ } /** - * Set the name of the property which will be used to bootstrap the - * selected tool, if any. The property will remain unset. - * @param bootstrapProperty - */ - public void setBootstrapProperty(String bootstrapProperty) { - this.bootstrapProperty = bootstrapProperty; - } - - /** * Specify whether or not to pop up a dialog if the user has not specified * a default value for a property. * @param askIfUnset a boolean flag indicating to prompt the user or not @@ -169,7 +141,6 @@ Properties props = readProperties(propertyFile); toolName = props.getProperty("tool.name"); - toolBootstrap = props.getProperty("tool.bootstrap") != null; if (toolName != null) { toolArgs = props.getProperty(toolName + ".args", ""); } @@ -183,8 +154,6 @@ // finally, return required values, if any if (toolProperty != null && !(toolName == null || toolName.equals(""))) { p.setProperty(toolProperty, toolName); - if (toolBootstrap) - p.setProperty(bootstrapProperty, "true"); if (argsProperty != null && toolArgs != null) p.setProperty(argsProperty, toolArgs); @@ -198,20 +167,15 @@ ToolChoices tool = (ToolChoices)toolChoice.getSelectedItem(); - toolName = tool.baseTool().toolName; - toolBootstrap = tool.bootstrap; + toolName = tool.toolName; toolArgs = argsField.getText(); if (defaultCheck.isSelected()) { if (toolName.equals("")) { fileProps.remove("tool.name"); fileProps.remove("tool.bootstrap"); } else { + fileProps.remove("tool.bootstrap"); fileProps.put("tool.name", toolName); - if (toolBootstrap) { - fileProps.put("tool.bootstrap", "true"); - } else { - fileProps.remove("tool.bootstrap"); - } fileProps.put(toolName + ".args", toolArgs); } writeProperties(propertyFile, fileProps); @@ -237,8 +201,6 @@ toolChoice = new JComboBox<>(toolChoices.toArray()); ToolChoices tool = toolName != null ? ToolChoices.valueOf(toolName.toUpperCase()) : null; if (toolName != null) { - if (toolBootstrap) - tool = tool.asBootstrap(); toolChoice.setSelectedItem(tool); } toolChoice.addItemListener(new ItemListener() { @@ -348,14 +310,13 @@ String getDefaultArgsForTool(Properties props, ToolChoices tool) { if (tool == null) return ""; - String toolName = tool.baseTool().toolName; + String toolName = tool.toolName; return toolName.equals("") ? "" : props.getProperty(toolName + ".args", ""); } // Ant task parameters private boolean askIfUnset; private String toolProperty; - private String bootstrapProperty; private String argsProperty; private File propertyFile; @@ -367,6 +328,5 @@ // Result values for the client private String toolName; - private boolean toolBootstrap; private String toolArgs; }
--- a/make/tools/crules/CodingRulesAnalyzerPlugin.java Thu Mar 24 11:21:37 2016 +0100 +++ b/make/tools/crules/CodingRulesAnalyzerPlugin.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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,10 +23,13 @@ package crules; +import java.lang.reflect.Layer; +import java.lang.reflect.Module; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import javax.lang.model.element.TypeElement; import javax.tools.JavaFileObject; @@ -52,6 +55,11 @@ @DefinedBy(Api.COMPILER_TREE) public void init(JavacTask task, String... args) { + addExports("jdk.compiler", + "com.sun.tools.javac.api", + "com.sun.tools.javac.code", + "com.sun.tools.javac.tree", + "com.sun.tools.javac.util"); BasicJavacTask impl = (BasicJavacTask)task; Context context = impl.getContext(); log = Log.instance(context); @@ -63,6 +71,20 @@ )); } + private void addExports(String moduleName, String... packageNames) { + for (String packageName : packageNames) { + try { + Layer layer = Layer.boot(); + Optional<Module> m = layer.findModule(moduleName); + if (!m.isPresent()) + throw new Error("module not found: " + moduleName); + m.get().addExports(packageName, getClass().getModule()); + } catch (Exception e) { + throw new Error("failed to add exports for " + moduleName + "/" + packageName); + } + } + } + public class PostAnalyzeTaskListener implements TaskListener { private final Map<Kind, List<AbstractCodingRulesAnalyzer>> analyzers = new HashMap<>();
--- a/make/tools/propertiesparser/parser/MessageType.java Thu Mar 24 11:21:37 2016 +0100 +++ b/make/tools/propertiesparser/parser/MessageType.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2016, 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 @@ -77,6 +77,7 @@ MODIFIER("modifier", "Modifier", "javax.lang.model.element"), FILE("file", "File", "java.io"), FILE_OBJECT("file object", "JavaFileObject", "javax.tools"), + PATH("path", "Path", "java.nio.file"), NAME("name", "Name", "com.sun.tools.javac.util"), NUMBER("number", "int", null), OPTION_NAME("option name", "Option", "com.sun.tools.javac.main"),
--- a/src/java.compiler/share/classes/javax/lang/model/element/Element.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/element/Element.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -105,8 +105,8 @@ * java.util.Set<E>} is {@code "Set"}. * * If this element represents an unnamed {@linkplain - * PackageElement#getSimpleName package}, an empty name is - * returned. + * PackageElement#getSimpleName package} or unnamed {@linkplain + * ModuleElement#getSimpleName module}, an empty name is returned. * * If it represents a {@linkplain ExecutableElement#getSimpleName * constructor}, the name "{@code <init>}" is returned. If it @@ -122,6 +122,7 @@ * @see ExecutableElement#getSimpleName * @see TypeElement#getSimpleName * @see VariableElement#getSimpleName + * @see ModuleElement#getSimpleName */ Name getSimpleName(); @@ -137,7 +138,7 @@ * top-level type}, its package is returned. * * <li> If this is a {@linkplain - * PackageElement#getEnclosingElement package}, {@code null} is + * PackageElement#getEnclosingElement package}, its module is * returned. * * <li> If this is a {@linkplain @@ -150,6 +151,9 @@ * parameter}, {@linkplain ExecutableElement the executable * element} which declares the parameter is returned. * + * <li> If this is a {@linkplain ModuleElement#getEnclosingElement + * module}, {@code null} is returned. + * * </ul> * * @return the enclosing element, or {@code null} if there is none @@ -169,6 +173,9 @@ * encloses the top-level classes and interfaces within it, but is * not considered to enclose subpackages. * + * A {@linkplain ModuleElement#getEnclosedElements module} + * encloses packages within it. + * * Other kinds of elements are not currently considered to enclose * any elements; however, that may change as this API or the * programming language evolves. @@ -177,8 +184,9 @@ * methods in {@link ElementFilter}. * * @return the enclosed elements, or an empty list if none + * @see TypeElement#getEnclosedElements * @see PackageElement#getEnclosedElements - * @see TypeElement#getEnclosedElements + * @see ModuleElement#getEnclosedElements * @see Elements#getAllMembers * @jls 8.8.9 Default Constructor * @jls 8.9 Enums
--- a/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/element/ElementKind.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -94,7 +94,13 @@ * A resource variable. * @since 1.7 */ - RESOURCE_VARIABLE; + RESOURCE_VARIABLE, + + /** + * A module. + * @since 9 + */ + MODULE; /**
--- a/src/java.compiler/share/classes/javax/lang/model/element/ElementVisitor.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/element/ElementVisitor.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -143,4 +143,13 @@ * a visitor implementation may optionally throw this exception */ R visitUnknown(Element e, P p); + + /** + * Visits a module element. + * @param e the element to visit + * @param p a visitor-specified parameter + * @return a visitor-specified result + * @since 9 + */ + R visitModule(ModuleElement e, P p); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java.compiler/share/classes/javax/lang/model/element/ModuleElement.java Thu Mar 24 16:21:21 2016 +0100 @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2005, 2016, 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 javax.lang.model.element; + +import java.util.List; + +/** + * Represents a module program element. Provides access to information + * about the module and its members. + * + * @see javax.lang.model.util.Elements#getModuleOf + * @since 9 + */ // TODO: add @jls to module section +public interface ModuleElement extends Element, QualifiedNameable { + + /** + * Returns the fully qualified name of this module. + * + * @return the qualified name of this module, or an + * empty name if this is an unnamed module + */ + @Override + Name getQualifiedName(); + + /** + * Returns the simple name of this module. For an unnamed + * module, an empty name is returned. + * + * @return the simple name of this module or an empty name if + * this is an unnamed module + */ + @Override + Name getSimpleName(); + + /** + * Returns the packages within this module. + * @return the packages within this module + */ + @Override + List<? extends Element> getEnclosedElements(); + + /** + * Returns {@code true} if this is an unnamed module and {@code + * false} otherwise. + * + * @return {@code true} if this is an unnamed module and {@code + * false} otherwise + */ // TODO: add @jls to unnamed module section + boolean isUnnamed(); + + /** + * Returns {@code null} since a module is not enclosed by another + * element. + * + * @return {@code null} + */ + @Override + Element getEnclosingElement(); + + /** + * Returns the directives contained in the declaration of this module. + * @return the directives in the declaration of this module + */ + List<? extends Directive> getDirectives(); + + /** + * The {@code kind} of a directive. + * + * <p>Note that it is possible additional directive kinds will be added + * to accommodate new, currently unknown, language structures added to + * future versions of the Java™ programming language. + * + * @since 9 + */ + enum DirectiveKind { + /** A "requires [public] module-name" directive. */ + REQUIRES, + /** An "exports package-name [to module-name-list]" directive. */ + EXPORTS, + /** A "uses service-name" directive. */ + USES, + /** A "provides service-name with implementation-name" directive. */ + PROVIDES + }; + + /** + * Represents a "module statement" within the declaration of this module. + * + * @since 9 + * + */ // TODO: add jls to Module Statement + interface Directive { + /** + * Returns the {@code kind} of this directive. + * + * @return the kind of this directive + */ + DirectiveKind getKind(); + } + + /** + * A dependency of a module. + * @since 9 + */ + interface RequiresDirective extends Directive { + /** + * Returns whether or not this is a public dependency. + * @return whether or not this is a public dependency + */ + boolean isPublic(); + + /** + * Returns the module that is required + * @return the module that is required + */ + ModuleElement getDependency(); + } + + /** + * An exported package of a module. + * @since 9 + */ + interface ExportsDirective extends Directive { + /** + * Returns the package being exported. + * @return the package being exported + */ + PackageElement getPackage(); + + /** + * Returns the specific modules to which the package is being exported, + * or null, if the package is exported to all modules which + * have readability to this module. + * @return the specific modules to which the package is being exported + */ + List<? extends ModuleElement> getTargetModules(); + } + + /** + * An implementation of a service provided by a module. + * @since 9 + */ + interface ProvidesDirective extends Directive { + /** + * Returns the service being provided. + * @return the service being provided + */ + TypeElement getService(); + + /** + * Returns the implementation of the service being provided. + * @return the implementation of the service being provided + */ + TypeElement getImplementation(); + } + + /** + * A reference to a service used by a module. + * @since 9 + */ + interface UsesDirective extends Directive { + /** + * Returns the service that is used. + * @return the service that is used + */ + TypeElement getService(); + } +}
--- a/src/java.compiler/share/classes/javax/lang/model/element/PackageElement.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/element/PackageElement.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -72,20 +72,19 @@ List<? extends Element> getEnclosedElements(); /** - * Returns {@code true} is this is an unnamed package and {@code + * Returns {@code true} if this is an unnamed package and {@code * false} otherwise. * - * @return {@code true} is this is an unnamed package and {@code + * @return {@code true} if this is an unnamed package and {@code * false} otherwise * @jls 7.4.2 Unnamed Packages */ boolean isUnnamed(); /** - * Returns {@code null} since a package is not enclosed by another - * element. + * Returns the enclosing module. * - * @return {@code null} + * @return the enclosing module */ @Override Element getEnclosingElement();
--- a/src/java.compiler/share/classes/javax/lang/model/type/TypeKind.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/type/TypeKind.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, 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 @@ -151,7 +151,14 @@ * * @since 1.8 */ - INTERSECTION; + INTERSECTION, + + /** + * A pseudo-type corresponding to a module element. + * @see NoType + * @since 9 + */ + MODULE; /** * Returns {@code true} if this kind corresponds to a primitive
--- a/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor6.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor6.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -132,4 +132,19 @@ public R visitUnknown(Element e, P p) { throw new UnknownElementException(e, p); } + + /** + * Visits a {@code ModuleElement} by calling {@code + * visitUnknown}. + + * @param e {@inheritDoc} + * @param p {@inheritDoc} + * @return the result of {@code visitUnknown} + * + * @since 9 + */ + @Override + public R visitModule(ModuleElement e, P p) { + return visitUnknown(e, p); + } }
--- a/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor9.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/util/AbstractElementVisitor9.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -27,6 +27,7 @@ import javax.annotation.processing.SupportedSourceVersion; import javax.lang.model.SourceVersion; +import javax.lang.model.element.ModuleElement; import static javax.lang.model.SourceVersion.*; @@ -71,4 +72,15 @@ protected AbstractElementVisitor9(){ super(); } + + /** + * Visits a {@code ModuleElement} in a manner defined by a + * subclass. + * + * @param t {@inheritDoc} + * @param p {@inheritDoc} + * @return the result of the visit as defined by a subclass + */ + @Override + public abstract R visitModule(ModuleElement t, P p); }
--- a/src/java.compiler/share/classes/javax/lang/model/util/ElementFilter.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementFilter.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -33,6 +33,12 @@ import java.util.LinkedHashSet; import javax.lang.model.element.*; +import javax.lang.model.element.ModuleElement.Directive; +import javax.lang.model.element.ModuleElement.DirectiveKind; +import javax.lang.model.element.ModuleElement.ExportsDirective; +import javax.lang.model.element.ModuleElement.ProvidesDirective; +import javax.lang.model.element.ModuleElement.RequiresDirective; +import javax.lang.model.element.ModuleElement.UsesDirective; /** @@ -78,6 +84,9 @@ private static final Set<ElementKind> PACKAGE_KIND = Collections.unmodifiableSet(EnumSet.of(ElementKind.PACKAGE)); + private static final Set<ElementKind> MODULE_KIND = + Collections.unmodifiableSet(EnumSet.of(ElementKind.MODULE)); + private static final Set<ElementKind> TYPE_KINDS = Collections.unmodifiableSet(EnumSet.of(ElementKind.CLASS, ElementKind.ENUM, @@ -183,6 +192,28 @@ return setFilter(elements, PACKAGE_KIND, PackageElement.class); } + /** + * Returns a list of modules in {@code elements}. + * @return a list of modules in {@code elements} + * @param elements the elements to filter + * @since 9 + */ + public static List<ModuleElement> + modulesIn(Iterable<? extends Element> elements) { + return listFilter(elements, MODULE_KIND, ModuleElement.class); + } + + /** + * Returns a set of modules in {@code elements}. + * @return a set of modules in {@code elements} + * @param elements the elements to filter + * @since 9 + */ + public static Set<ModuleElement> + modulesIn(Set<? extends Element> elements) { + return setFilter(elements, MODULE_KIND, ModuleElement.class); + } + // Assumes targetKinds and E are sensible. private static <E extends Element> List<E> listFilter(Iterable<? extends Element> elements, Set<ElementKind> targetKinds, @@ -207,4 +238,62 @@ } return set; } + + + + /** + * Returns a list of export directives in {@code directives}. + * @return a list of export directives in {@code directives} + * @param directives the directives to filter + * @since 9 + */ + public static List<ExportsDirective> + exportsIn(Iterable<? extends Directive> directives) { + return listFilter(directives, DirectiveKind.EXPORTS, ExportsDirective.class); + } + + /** + * Returns a list of provides directives in {@code directives}. + * @return a list of provides directives in {@code directives} + * @param directives the directives to filter + * @since 9 + */ + public static List<ProvidesDirective> + providesIn(Iterable<? extends Directive> directives) { + return listFilter(directives, DirectiveKind.PROVIDES, ProvidesDirective.class); + } + + /** + * Returns a list of requires directives in {@code directives}. + * @return a list of requires directives in {@code directives} + * @param directives the directives to filter + * @since 9 + */ + public static List<RequiresDirective> + requiresIn(Iterable<? extends Directive> directives) { + return listFilter(directives, DirectiveKind.REQUIRES, RequiresDirective.class); + } + + /** + * Returns a list of uses directives in {@code directives}. + * @return a list of uses directives in {@code directives} + * @param directives the directives to filter + * @since 9 + */ + public static List<UsesDirective> + usesIn(Iterable<? extends Directive> directives) { + return listFilter(directives, DirectiveKind.USES, UsesDirective.class); + } + + // Assumes directiveKind and D are sensible. + private static <D extends Directive> List<D> listFilter(Iterable<? extends Directive> directives, + DirectiveKind directiveKind, + Class<D> clazz) { + List<D> list = new ArrayList<>(); + for (Directive d : directives) { + if (d.getKind() == directiveKind) + list.add(clazz.cast(d)); + } + return list; + } }
--- a/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor9.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementKindVisitor9.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -95,4 +95,17 @@ protected ElementKindVisitor9(R defaultValue) { super(defaultValue); } + + /** + * Visits a {@code ModuleElement} by calling {@code + * defaultAction}. + * + * @param e the element to visit + * @param p a visitor-specified parameter + * @return the result of {@code defaultAction} + */ + @Override + public R visitModule(ModuleElement e, P p) { + return defaultAction(e, p); + } }
--- a/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner9.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner9.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -108,4 +108,17 @@ protected ElementScanner9(R defaultValue){ super(defaultValue); } + + /** + * Visits a {@code ModuleElement} by scanning the enclosed + * elements. + * + * @param e the element to visit + * @param p a visitor-specified parameter + * @return the result of the scan + */ + @Override + public R visitModule(ModuleElement e, P p) { + return scan(e.getEnclosedElements(), p); // TODO: Hmmm, this might not be right + } }
--- a/src/java.compiler/share/classes/javax/lang/model/util/Elements.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/util/Elements.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -30,7 +30,6 @@ import java.util.Map; import javax.lang.model.element.*; -import javax.lang.model.type.*; /** @@ -64,6 +63,15 @@ TypeElement getTypeElement(CharSequence name); /** + * Returns a module element given its fully qualified name. + * + * @param name the name + * @return the named module element, or {@code null} if it cannot be found + * @since 9 + */ + ModuleElement getModuleElement(CharSequence name); + + /** * Returns the values of an annotation's elements, including defaults. * * @see AnnotationMirror#getElementValues() @@ -129,6 +137,16 @@ PackageElement getPackageOf(Element type); /** + * Returns the module of an element. The module of a module is + * itself. + * + * @param type the element being examined + * @return the module of an element + * @since 9 + */ + ModuleElement getModuleOf(Element type); + + /** * Returns all members of a type element, whether inherited or * declared directly. For a class the result also includes its * constructors, but not local or anonymous classes.
--- a/src/java.compiler/share/classes/javax/lang/model/util/SimpleElementVisitor9.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/lang/model/util/SimpleElementVisitor9.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -27,6 +27,7 @@ import javax.annotation.processing.SupportedSourceVersion; import javax.lang.model.SourceVersion; +import javax.lang.model.element.ModuleElement; import static javax.lang.model.SourceVersion.*; /** @@ -90,4 +91,17 @@ protected SimpleElementVisitor9(R defaultValue){ super(defaultValue); } + + /** + * Visits a {@code ModuleElement} by calling {@code + * defaultAction}. + * + * @param e the element to visit + * @param p a visitor-specified parameter + * @return the result of {@code defaultAction} + */ + @Override + public R visitModule(ModuleElement e, P p) { + return defaultAction(e, p); + } }
--- a/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/tools/ForwardingJavaFileManager.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -28,6 +28,7 @@ import java.io.IOException; import java.util.Iterator; import java.util.Objects; +import java.util.ServiceLoader; import java.util.Set; import javax.tools.JavaFileObject.Kind; @@ -163,4 +164,24 @@ public void close() throws IOException { fileManager.close(); } + + public Location getModuleLocation(Location location, String moduleName) throws IOException { + return fileManager.getModuleLocation(location, moduleName); + } + + public Location getModuleLocation(Location location, JavaFileObject fo, String pkgName) throws IOException { + return fileManager.getModuleLocation(location, fo, pkgName); + } + + public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException { + return fileManager.getServiceLoader(location, service); + } + + public String inferModuleName(Location location) throws IOException { + return fileManager.inferModuleName(location); + } + + public Iterable<Set<Location>> listModuleLocations(Location location) throws IOException { + return fileManager.listModuleLocations(location); + } }
--- a/src/java.compiler/share/classes/javax/tools/JavaFileManager.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/tools/JavaFileManager.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, 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 @@ -29,7 +29,9 @@ import java.io.Flushable; import java.io.IOException; import java.util.Iterator; +import java.util.ServiceLoader; import java.util.Set; + import static javax.tools.JavaFileObject.Kind; /** @@ -124,6 +126,17 @@ * @return true if this is an output location, false otherwise */ boolean isOutputLocation(); + + /** + * Indicates if this location is expected to contain modules, + * as compared to a location which contains packages and classes. + * + * @return true if this location is expected to contain modules + * @since 9 + */ + default boolean isModuleLocation() { + return false; + } } /** @@ -385,6 +398,7 @@ * @throws IOException if an I/O error occurred * @see #close */ + @Override void flush() throws IOException; /** @@ -398,5 +412,84 @@ * @throws IOException if an I/O error occurred * @see #flush */ + @Override void close() throws IOException; + + /** + * Gets a location for a named module within a module-oriented location. + * + * @param location the module-oriented location + * @param moduleName the name of the module to be found + * @return the location for the named module + * + * @throws IOException if an I/O error occurred + * @throws UnsupportedOperationException if this operation if not supported by this file manager + * @since 9 + */ // TODO: describe failure modes + default Location getModuleLocation(Location location, String moduleName) throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * Gets a location for the module containing a specific file representing a Java + * source or class. + * + * @param location a module-oriented location + * @param fo the file + * @param pkgName the package name for the class(es) defined in this file + * @return the module containing the file + * + * @throws IOException if an I/O error occurred + * @throws UnsupportedOperationException if this operation if not supported by this file manager + * @since 9 + */ // TODO: describe failure modes + default Location getModuleLocation(Location location, JavaFileObject fo, String pkgName) throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * Get a service loader for a specific service class from a given location. + * + * @param location the location + * @param service the {@code Class} object of the service class + * @param <S> the service class + * @return a service loader for the given service class + * + * @throws IOException if an I/O error occurred + * @throws UnsupportedOperationException if this operation if not supported by this file manager + * @since 9 + */ // TODO: describe failure modes + default <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * Infer the name of the module from its location, as returned by + * getModuleLocation or listModuleLocations. + * + * @param location a location representing a module + * @return the name of the module + * + * @throws IOException if an I/O error occurred + * @throws UnsupportedOperationException if this operation if not supported by this file manager + * @since 9 + */ // TODO: describe failure modes + default String inferModuleName(Location location) throws IOException { + throw new UnsupportedOperationException(); + } + + /** + * Lists the modules in a module-oriented location. + * + * @param location the location for which to list the modules + * @return a series of sets of locations containing modules + * + * @throws IOException if an I/O error occurred + * @throws UnsupportedOperationException if this operation if not supported by this file manager + * @since 9 + */ // TODO: describe failure modes + default Iterable<Set<Location>> listModuleLocations(Location location) throws IOException { + throw new UnsupportedOperationException(); + } + }
--- a/src/java.compiler/share/classes/javax/tools/StandardLocation.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/tools/StandardLocation.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2016, 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 @@ -63,6 +63,12 @@ ANNOTATION_PROCESSOR_PATH, /** + * Location to search for modules containing annotation processors. + * @since 9 + */ + ANNOTATION_PROCESSOR_MODULE_PATH, + + /** * Location to search for platform classes. Sometimes called * the boot class path. */ @@ -72,7 +78,31 @@ * Location of new native header files. * @since 1.8 */ - NATIVE_HEADER_OUTPUT; + NATIVE_HEADER_OUTPUT, + + /** + * Location to search for the source code of modules. + * @since 9 + */ + MODULE_SOURCE_PATH, + + /** + * Location to search for upgradeable system modules. + * @since 9 + */ + UPGRADE_MODULE_PATH, + + /** + * Location to search for system modules. + * @since 9 + */ + SYSTEM_MODULES, + + /** + * Location to search for precompiled user modules. + * @since 9 + */ + MODULE_PATH; /** * Returns a location object with the given name. The following @@ -90,8 +120,11 @@ for (Location location : values()) locations.putIfAbsent(location.getName(), location); } - locations.putIfAbsent(name.toString(/* null-check */), new Location() { + name.getClass(); /* null-check */ + locations.putIfAbsent(name, new Location() { + @Override public String getName() { return name; } + @Override public boolean isOutputLocation() { return name.endsWith("_OUTPUT"); } }); return locations.get(name); @@ -100,8 +133,10 @@ private static final ConcurrentMap<String,Location> locations = new ConcurrentHashMap<>(); + @Override public String getName() { return name(); } + @Override public boolean isOutputLocation() { switch (this) { case CLASS_OUTPUT: @@ -112,4 +147,18 @@ return false; } } + + @Override + public boolean isModuleLocation() { + switch (this) { + case MODULE_SOURCE_PATH: + case ANNOTATION_PROCESSOR_MODULE_PATH: + case UPGRADE_MODULE_PATH: + case SYSTEM_MODULES: + case MODULE_PATH: + return true; + default: + return false; + } + } }
--- a/src/java.compiler/share/classes/javax/tools/ToolProvider.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/java.compiler/share/classes/javax/tools/ToolProvider.java Thu Mar 24 16:21:21 2016 +0100 @@ -25,10 +25,11 @@ package javax.tools; -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.util.HashMap; -import java.util.Map; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.ServiceConfigurationError; +import java.util.ServiceLoader; /** * Provides methods for locating tool providers, for example, @@ -40,8 +41,8 @@ */ public class ToolProvider { - private static final String systemJavaCompilerName - = "com.sun.tools.javac.api.JavacTool"; + private static final String systemJavaCompilerModule = "jdk.compiler"; + private static final String systemJavaCompilerName = "com.sun.tools.javac.api.JavacTool"; /** * Returns the Java™ programming language compiler provided @@ -52,13 +53,17 @@ * {@linkplain java.nio.file.FileSystem filesystem}.</p> * @return the compiler provided with this platform or * {@code null} if no compiler is provided + * @implNote This implementation returns the compiler provided + * by the {@code jdk.compiler} module if that module is available, + * and null otherwise. */ public static JavaCompiler getSystemJavaCompiler() { - return instance().getSystemTool(JavaCompiler.class, systemJavaCompilerName); + return getSystemTool(JavaCompiler.class, + systemJavaCompilerModule, systemJavaCompilerName); } - private static final String systemDocumentationToolName - = "jdk.javadoc.internal.api.JavadocTool"; + private static final String systemDocumentationToolModule = "jdk.javadoc"; + private static final String systemDocumentationToolName = "jdk.javadoc.internal.api.JavadocTool"; /** * Returns the Java™ programming language documentation tool provided @@ -69,9 +74,13 @@ * {@linkplain java.nio.file.FileSystem filesystem}.</p> * @return the documentation tool provided with this platform or * {@code null} if no documentation tool is provided + * @implNote This implementation returns the tool provided + * by the {@code jdk.javadoc} module if that module is available, + * and null otherwise. */ public static DocumentationTool getSystemDocumentationTool() { - return instance().getSystemTool(DocumentationTool.class, systemDocumentationToolName); + return getSystemTool(DocumentationTool.class, + systemDocumentationToolModule, systemDocumentationToolName); } /** @@ -87,41 +96,70 @@ return ClassLoader.getSystemClassLoader(); } + private static final boolean useLegacy; - private static ToolProvider instance; - - private static synchronized ToolProvider instance() { - if (instance == null) - instance = new ToolProvider(); - return instance; + static { + Class<?> c = null; + try { + c = Class.forName("java.lang.reflect.Module"); + } catch (Throwable t) { + } + useLegacy = (c == null); } - // Cache for tool classes. - // Use weak references to avoid keeping classes around unnecessarily - private final Map<String, Reference<Class<?>>> toolClasses = new HashMap<>(); + /** + * Get an instance of a system tool using the service loader. + * @implNote By default, this returns the implementation in the specified module. + * For limited backward compatibility, if this code is run on an older version + * of the Java platform that does not support modules, this method will + * try and create an instance of the named class. Note that implies the + * class must be available on the system class path. + * @param <T> the interface of the tool + * @param clazz the interface of the tool + * @param moduleName the name of the module containing the desired implementation + * @param className the class name of the desired implementation + * @return the specified implementation of the tool + */ + private static <T> T getSystemTool(Class<T> clazz, String moduleName, String className) { + if (useLegacy) { + try { + return Class.forName(className, true, ClassLoader.getSystemClassLoader()).asSubclass(clazz).newInstance(); + } catch (ReflectiveOperationException e) { + throw new Error(e); + } + } - private ToolProvider() { } - - private <T> T getSystemTool(Class<T> clazz, String name) { - Class<? extends T> c = getSystemToolClass(clazz, name); try { - return c.asSubclass(clazz).newInstance(); - } catch (InstantiationException | IllegalAccessException | RuntimeException | Error e) { + ServiceLoader<T> sl = ServiceLoader.load(clazz, ClassLoader.getSystemClassLoader()); + for (Iterator<T> iter = sl.iterator(); iter.hasNext(); ) { + T tool = iter.next(); + if (matches(tool, moduleName)) + return tool; + } + } catch (ServiceConfigurationError e) { throw new Error(e); } + return null; } - private <T> Class<? extends T> getSystemToolClass(Class<T> clazz, String name) { - Reference<Class<?>> refClass = toolClasses.get(name); - Class<?> c = (refClass == null ? null : refClass.get()); - if (c == null) { - try { - c = Class.forName(name, false, ClassLoader.getSystemClassLoader()); - } catch (ClassNotFoundException | RuntimeException | Error e) { - throw new Error(e); - } - toolClasses.put(name, new WeakReference<>(c)); + /** + * Determine if this is tho desired tool instance. + * @param <T> the interface of the tool + * @param tool the instance of the tool + * @param moduleName the name of the module containing the desired implementation + * @return true if and only if the tool matches the specified criteria + */ + private static <T> boolean matches(T tool, String moduleName) { + // for now, use reflection to implement + // return moduleName.equals(tool.getClass().getModule().getName()); + try { + Method getModuleMethod = Class.class.getDeclaredMethod("getModule"); + Object toolModule = getModuleMethod.invoke(tool.getClass()); + Method getNameMethod = toolModule.getClass().getDeclaredMethod("getName"); + String toolModuleName = (String) getNameMethod.invoke(toolModule); + return moduleName.equals(toolModuleName); + } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) { + return false; } - return c.asSubclass(clazz); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java.compiler/share/classes/module-info.java Thu Mar 24 16:21:21 2016 +0100 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014, 2016, 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. + */ + +module java.compiler { + exports javax.annotation.processing; + exports javax.lang.model; + exports javax.lang.model.element; + exports javax.lang.model.type; + exports javax.lang.model.util; + exports javax.tools; + + uses javax.tools.DocumentationTool; + uses javax.tools.JavaCompiler; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/DirectiveTree.java Thu Mar 24 16:21:21 2016 +0100 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011, 2014, 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 com.sun.source.tree; + +/** + * A super-type for all the directives in a ModuleTree. + */ +public interface DirectiveTree extends Tree { }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/ExportsTree.java Thu Mar 24 16:21:21 2016 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2009, 2016, 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 com.sun.source.tree; + +import java.util.List; + +/** + * A tree node for an 'exports' directive in a module declaration. + * + * For example: + * <pre> + * exports <em>package-name</em>; + * exports <em>package-name</em> to <em>module-name</em>; + * </pre> + * + * @since 9 + */ +public interface ExportsTree extends DirectiveTree { + /** + * Returns the name of the package to be exported. + * @return the name of the package to be exported + */ + ExpressionTree getExportName(); + + /** + * Returns the names of the modules to which the package is exported, + * or null, if the package is exported to all modules. + * + * @return the names of the modules to which the package is exported, or null + */ + List<? extends ExpressionTree> getModuleNames(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/ModuleTree.java Thu Mar 24 16:21:21 2016 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2009, 2016, 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 com.sun.source.tree; + +import java.util.List; + + +/** + * A tree node for a module declaration. + * + * For example: + * <pre> + * module <em>module-name</em> { + * <em>directives</em> + * } + * </pre> + * + * @since 9 + */ +public interface ModuleTree extends Tree { + /** + * Returns the name of the module. + * @return the name of the module + */ + ExpressionTree getName(); + + /** + * Returns the directives in the module declaration. + * @return the directives in the module declaration + */ + List<? extends DirectiveTree> getDirectives(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/ProvidesTree.java Thu Mar 24 16:21:21 2016 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2009, 2016, 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 com.sun.source.tree; + +/** + * A tree node for a 'provides' directive in a module declaration. + * + * For example: + * <pre> + * provides <em>service-name</em> with <em>implementation-name</em>; + * </pre> + + * @since 9 + */ +public interface ProvidesTree extends DirectiveTree { + /** + * Returns the name of the service type being provided. + * @return the name of the service type being provided + */ + ExpressionTree getServiceName(); + + /** + * Returns the name of the implementation type being provided. + * @return the name of the implementation type being provided + */ + ExpressionTree getImplementationName(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/RequiresTree.java Thu Mar 24 16:21:21 2016 +0100 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2009, 2016, 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 com.sun.source.tree; + +/** + * A tree node for a 'requires' directive in a module declaration. + * + * For example: + * <pre> + * requires <em>module-name</em>; + * requires public <em>module-name</em>; + * </pre> + * + * @since 9 + */ +public interface RequiresTree extends DirectiveTree { + /** + * Returns true if this is a "requires public" directive. + * @return true if this is a "requires public" directive + */ + boolean isPublic(); + + /** + * Returns the name of the module that is required. + * @return the name of the module that is required + */ + ExpressionTree getModuleName(); +}
--- a/src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -604,6 +604,35 @@ ANNOTATION_TYPE(ClassTree.class), /** + * Used for instances of {@link ModuleTree} representing module declarations. + */ + MODULE(ModuleTree.class), + + /** + * Used for instances of {@link ExportsTree} representing + * export directives in a module declaration. + */ + EXPORTS(ExportsTree.class), + + /** + * Used for instances of {@link ProvidesTree} representing + * export directives in a module declaration. + */ + PROVIDES(ProvidesTree.class), + + /** + * Used for instances of {@link RequiresTree} representing + * export directives in a module declaration. + */ + REQUIRES(RequiresTree.class), + + /** + * Used for instances of {@link UsesTree} representing + * export directives in a module declaration. + */ + USES(UsesTree.class), + + /** * An implementation-reserved node. This is the not the node * you are looking for. */
--- a/src/jdk.compiler/share/classes/com/sun/source/tree/TreeVisitor.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/TreeVisitor.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, 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 @@ -482,6 +482,46 @@ R visitWildcard(WildcardTree node, P p); /** + * Visits a ModuleTree node. + * @param node the node being visited + * @param p a parameter value + * @return a result value + */ + R visitModule(ModuleTree node, P p); + + /** + * Visits an ExportsTree node. + * @param node the node being visited + * @param p a parameter value + * @return a result value + */ + R visitExports(ExportsTree node, P p); + + /** + * Visits a ProvidesTree node. + * @param node the node being visited + * @param p a parameter value + * @return a result value + */ + R visitProvides(ProvidesTree node, P p); + + /** + * Visits a RequiresTree node. + * @param node the node being visited + * @param p a parameter value + * @return a result value + */ + R visitRequires(RequiresTree node, P p); + + /** + * Visits a UsesTree node. + * @param node the node being visited + * @param p a parameter value + * @return a result value + */ + R visitUses(UsesTree node, P p); + + /** * Visits an unknown type of Tree node. * This can occur if the language evolves and new kinds * of nodes are added to the {@code Tree} hierarchy.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/UsesTree.java Thu Mar 24 16:21:21 2016 +0100 @@ -0,0 +1,45 @@ + +/* + * Copyright (c) 2009, 2016, 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 com.sun.source.tree; + +/** + * A tree node for a 'uses' directive in a module declaration. + * + * For example: + * <pre> + * uses <em>service-name</em>; + * </pre> + * + * @since 9 + */ +public interface UsesTree extends DirectiveTree { + /** + * Returns the name of the service type. + * @return the name of the service type + */ + ExpressionTree getServiceName(); +}
--- a/src/jdk.compiler/share/classes/com/sun/source/util/SimpleTreeVisitor.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/source/util/SimpleTreeVisitor.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -719,14 +719,30 @@ return defaultAction(node, p); } - /** - * {@inheritDoc} This implementation calls {@code defaultAction}. - * - * @param node {@inheritDoc} - * @param p {@inheritDoc} - * @return the result of {@code defaultAction} - */ + public R visitModule(ModuleTree node, P p) { + return defaultAction(node, p); + } + @Override + public R visitExports(ExportsTree node, P p) { + return defaultAction(node, p); + } + + @Override + public R visitProvides(ProvidesTree node, P p) { + return defaultAction(node, p); + } + + @Override + public R visitRequires(RequiresTree node, P p) { + return defaultAction(node, p); + } + + @Override + public R visitUses(UsesTree node, P p) { + return defaultAction(node, p); + } + public R visitErroneous(ErroneousTree node, P p) { return defaultAction(node, p); }
--- a/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/source/util/TreeScanner.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -846,6 +846,32 @@ return r; } + public R visitModule(ModuleTree node, P p) { + R r = scan(node.getName(), p); + r = scanAndReduce(node.getDirectives(), p, r); + return r; + } + + public R visitExports(ExportsTree node, P p) { + R r = scan(node.getExportName(), p); + r = scanAndReduce(node.getModuleNames(), p, r); + return r; + } + + public R visitProvides(ProvidesTree node, P p) { + R r = scan(node.getServiceName(), p); + r = scanAndReduce(node.getImplementationName(), p, r); + return r; + } + + public R visitRequires(RequiresTree node, P p) { + return scan(node.getModuleName(), p); + } + + public R visitUses(UsesTree node, P p) { + return scan(node.getServiceName(), p); + } + /** * {@inheritDoc} This implementation returns {@code null}. *
--- a/src/jdk.compiler/share/classes/com/sun/tools/doclint/DocLint.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/doclint/DocLint.java Thu Mar 24 16:21:21 2016 +0100 @@ -195,6 +195,9 @@ } else { throw new BadArgs("dc.bad.value.for.option", arg, args[i]); } + } else if ((arg.equals("-target") || arg.equals("-source")) && i + 1 < args.length) { + javacOpts.add(arg); + javacOpts.add(args[++i]); } else if (arg.equals(STATS)) { env.messages.setStatsEnabled(true); } else if (arg.equals("-bootclasspath") && i + 1 < args.length) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -28,6 +28,7 @@ import java.util.Collection; import java.util.LinkedHashSet; import java.util.Locale; +import java.util.ServiceLoader; import java.util.Set; import java.util.stream.Collectors; @@ -57,7 +58,6 @@ import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.PropagatedException; -import com.sun.tools.javac.util.ServiceLoader; /** * Provides basic functionality for implementations of JavacTask. @@ -195,8 +195,7 @@ Set<List<String>> pluginsToCall = new LinkedHashSet<>(pluginOpts); JavacProcessingEnvironment pEnv = JavacProcessingEnvironment.instance(context); - ClassLoader cl = pEnv.getProcessorClassLoader(); - ServiceLoader<Plugin> sl = ServiceLoader.load(Plugin.class, cl); + ServiceLoader<Plugin> sl = pEnv.getServiceLoader(Plugin.class); for (Plugin plugin : sl) { for (List<String> p : pluginsToCall) { if (plugin.getName().equals(p.head)) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -36,6 +36,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.net.URI; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -347,6 +348,50 @@ } @Override @DefinedBy(Api.COMPILER) + public Location getModuleLocation(Location location, String moduleName) throws IOException { + try { + return clientJavaFileManager.getModuleLocation(location, moduleName); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException | Error e) { + throw new ClientCodeException(e); + } + } + + @Override @DefinedBy(Api.COMPILER) + public Location getModuleLocation(Location location, JavaFileObject fo, String pkgName) throws IOException { + try { + return clientJavaFileManager.getModuleLocation(location, fo, pkgName); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException | Error e) { + throw new ClientCodeException(e); + } + } + + @Override @DefinedBy(Api.COMPILER) + public String inferModuleName(Location location) throws IOException { + try { + return clientJavaFileManager.inferModuleName(location); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException | Error e) { + throw new ClientCodeException(e); + } + } + + @Override @DefinedBy(Api.COMPILER) + public Iterable<Set<Location>> listModuleLocations(Location location) throws IOException { + try { + return clientJavaFileManager.listModuleLocations(location); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException | Error e) { + throw new ClientCodeException(e); + } + } + + @Override @DefinedBy(Api.COMPILER) public int isSupportedOption(String option) { try { return clientJavaFileManager.isSupportedOption(option); @@ -381,6 +426,17 @@ } @Override @DefinedBy(Api.COMPILER) + public Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(Iterable<? extends Path> paths) { + try { + return ((StandardJavaFileManager)clientJavaFileManager).getJavaFileObjectsFromPaths(paths); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException | Error e) { + throw new ClientCodeException(e); + } + } + + @Override @DefinedBy(Api.COMPILER) public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) { try { return ((StandardJavaFileManager)clientJavaFileManager).getJavaFileObjects(files); @@ -392,6 +448,17 @@ } @Override @DefinedBy(Api.COMPILER) + public Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths) { + try { + return ((StandardJavaFileManager)clientJavaFileManager).getJavaFileObjects(paths); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException | Error e) { + throw new ClientCodeException(e); + } + } + + @Override @DefinedBy(Api.COMPILER) public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) { try { return ((StandardJavaFileManager)clientJavaFileManager).getJavaFileObjectsFromStrings(names); @@ -414,9 +481,20 @@ } @Override @DefinedBy(Api.COMPILER) - public void setLocation(Location location, Iterable<? extends File> path) throws IOException { + public void setLocation(Location location, Iterable<? extends File> files) throws IOException { try { - ((StandardJavaFileManager)clientJavaFileManager).setLocation(location, path); + ((StandardJavaFileManager)clientJavaFileManager).setLocation(location, files); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException | Error e) { + throw new ClientCodeException(e); + } + } + + @Override @DefinedBy(Api.COMPILER) + public void setLocationFromPaths(Location location, Iterable<? extends Path> paths) throws IOException { + try { + ((StandardJavaFileManager)clientJavaFileManager).setLocationFromPaths(location, paths); } catch (ClientCodeException e) { throw e; } catch (RuntimeException | Error e) { @@ -434,6 +512,28 @@ throw new ClientCodeException(e); } } + + @Override @DefinedBy(Api.COMPILER) + public Iterable<? extends Path> getLocationAsPaths(Location location) { + try { + return ((StandardJavaFileManager)clientJavaFileManager).getLocationAsPaths(location); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException | Error e) { + throw new ClientCodeException(e); + } + } + + @Override @DefinedBy(Api.COMPILER) + public Path asPath(FileObject file) { + try { + return ((StandardJavaFileManager)clientJavaFileManager).asPath(file); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException | Error e) { + throw new ClientCodeException(e); + } + } } protected class WrappedFileObject implements FileObject {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 @@ -33,12 +33,17 @@ import javax.annotation.processing.Processor; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; +import javax.lang.model.util.ElementFilter; import javax.tools.*; +import javax.tools.JavaFileObject.Kind; import com.sun.source.tree.*; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.ClassSymbol; +import com.sun.tools.javac.code.Symbol.ModuleSymbol; +import com.sun.tools.javac.code.Symbol.PackageSymbol; import com.sun.tools.javac.comp.*; import com.sun.tools.javac.file.BaseFileManager; import com.sun.tools.javac.main.*; @@ -49,6 +54,8 @@ import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; +import com.sun.tools.javac.tree.JCTree.JCModuleDecl; +import com.sun.tools.javac.tree.JCTree.Tag; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.DefinedBy.Api; import com.sun.tools.javac.util.List; @@ -253,7 +260,7 @@ * @return a list of elements corresponding to the top level * classes in the abstract syntax trees */ - public Iterable<? extends TypeElement> enter() { + public Iterable<? extends Element> enter() { return enter(null); } @@ -264,11 +271,13 @@ * @return a list of elements corresponding to the top level * classes in the abstract syntax trees */ - public Iterable<? extends TypeElement> enter(Iterable<? extends CompilationUnitTree> trees) + public Iterable<? extends Element> enter(Iterable<? extends CompilationUnitTree> trees) { if (trees == null && notYetEntered != null && notYetEntered.isEmpty()) return List.nil(); + boolean wasInitialized = compiler != null; + prepareCompiler(true); ListBuffer<JCCompilationUnit> roots = null; @@ -305,22 +314,38 @@ } } - if (roots == null) + if (roots == null) { + if (trees == null && !wasInitialized) { + compiler.initModules(List.nil()); + } return List.nil(); + } + + List<JCCompilationUnit> units = compiler.initModules(roots.toList()); try { - List<JCCompilationUnit> units = compiler.enterTrees(roots.toList()); + units = compiler.enterTrees(units); if (notYetEntered.isEmpty()) compiler.processAnnotations(units); - ListBuffer<TypeElement> elements = new ListBuffer<>(); + ListBuffer<Element> elements = new ListBuffer<>(); for (JCCompilationUnit unit : units) { - for (JCTree node : unit.defs) { - if (node.hasTag(JCTree.Tag.CLASSDEF)) { - JCClassDecl cdef = (JCClassDecl) node; - if (cdef.sym != null) // maybe null if errors in anno processing - elements.append(cdef.sym); + boolean isPkgInfo = unit.sourcefile.isNameCompatible("package-info", + JavaFileObject.Kind.SOURCE); + if (isPkgInfo) { + elements.append(unit.packge); + } else { + for (JCTree node : unit.defs) { + if (node.hasTag(JCTree.Tag.CLASSDEF)) { + JCClassDecl cdef = (JCClassDecl) node; + if (cdef.sym != null) // maybe null if errors in anno processing + elements.append(cdef.sym); + } else if (node.hasTag(JCTree.Tag.MODULEDEF)) { + JCModuleDecl mdef = (JCModuleDecl) node; + if (mdef.sym != null) + elements.append(mdef.sym); + } } } } @@ -353,7 +378,7 @@ // This implementation requires that we open up privileges on JavaCompiler. // An alternative implementation would be to move this code to JavaCompiler and // wrap it here - public Iterable<? extends Element> analyze(Iterable<? extends TypeElement> classes) { + public Iterable<? extends Element> analyze(Iterable<? extends Element> classes) { enter(null); // ensure all classes have been entered final ListBuffer<Element> results = new ListBuffer<>(); @@ -383,8 +408,13 @@ if (cdef.sym != null) elems.append(cdef.sym); break; - case TOPLEVEL: - JCCompilationUnit unit = (JCCompilationUnit) env.tree; + case MODULEDEF: + JCModuleDecl mod = (JCModuleDecl) env.tree; + if (mod.sym != null) + elems.append(mod.sym); + break; + case PACKAGEDEF: + JCCompilationUnit unit = env.toplevel; if (unit.packge != null) elems.append(unit.packge); break; @@ -413,7 +443,7 @@ * @param classes a list of class elements * @return the files that were generated */ - public Iterable<? extends JavaFileObject> generate(Iterable<? extends TypeElement> classes) { + public Iterable<? extends JavaFileObject> generate(Iterable<? extends Element> classes) { final ListBuffer<JavaFileObject> results = new ListBuffer<>(); try { analyze(null); // ensure all classes have been parsed, entered, and analyzed @@ -447,17 +477,33 @@ return TreeInfo.pathFor((JCTree) node, (JCTree.JCCompilationUnit) unit).reverse(); } + public void ensureEntered() { + args.allowEmpty(); + enter(null); + } + abstract class Filter { - void run(Queue<Env<AttrContext>> list, Iterable<? extends TypeElement> classes) { - Set<TypeElement> set = new HashSet<>(); - for (TypeElement item: classes) + void run(Queue<Env<AttrContext>> list, Iterable<? extends Element> elements) { + Set<Element> set = new HashSet<>(); + for (Element item: elements) { set.add(item); + } ListBuffer<Env<AttrContext>> defer = new ListBuffer<>(); while (list.peek() != null) { Env<AttrContext> env = list.remove(); - ClassSymbol csym = env.enclClass.sym; - if (csym != null && set.contains(csym.outermostClass())) + Symbol test = null; + + if (env.tree.hasTag(Tag.MODULEDEF)) { + test = ((JCModuleDecl) env.tree).sym; + } else if (env.tree.hasTag(Tag.PACKAGEDEF)) { + test = env.toplevel.packge; + } else { + ClassSymbol csym = env.enclClass.sym; + if (csym != null) + test = csym.outermostClass(); + } + if (test != null && set.contains(test)) process(env); else defer = defer.append(env);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTool.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTool.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, 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 @@ -129,9 +129,17 @@ } if (classes != null) { - for (String cls : classes) - if (!SourceVersion.isName(cls)) // implicit null check + for (String cls : classes) { + int sep = cls.indexOf('/'); // implicit null check + if (sep > 0) { + String mod = cls.substring(0, sep); + if (!SourceVersion.isName(mod)) + throw new IllegalArgumentException("Not a valid module name: " + mod); + cls = cls.substring(sep + 1); + } + if (!SourceVersion.isName(cls)) throw new IllegalArgumentException("Not a valid class name: " + cls); + } } if (compilationUnits != null) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java Thu Mar 24 16:21:21 2016 +0100 @@ -76,6 +76,7 @@ import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.MethodSymbol; +import com.sun.tools.javac.code.Symbol.ModuleSymbol; import com.sun.tools.javac.code.Symbol.PackageSymbol; import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symbol.VarSymbol; @@ -92,6 +93,7 @@ import com.sun.tools.javac.comp.Enter; import com.sun.tools.javac.comp.Env; import com.sun.tools.javac.comp.MemberEnter; +import com.sun.tools.javac.comp.Modules; import com.sun.tools.javac.comp.Resolve; import com.sun.tools.javac.file.BaseFileManager; import com.sun.tools.javac.model.JavacElements; @@ -156,6 +158,7 @@ public class JavacTrees extends DocTrees { // in a world of a single context per compilation, these would all be final + private Modules modules; private Resolve resolve; private Enter enter; private Log log; @@ -206,6 +209,7 @@ } private void init(Context context) { + modules = Modules.instance(context); attr = Attr.instance(context); enter = Enter.instance(context); elements = JavacElements.instance(context); @@ -434,21 +438,31 @@ // and if not, then we check to see if it identifies a package. Type t = attr.attribType(ref.qualifierExpression, env); if (t.isErroneous()) { - if (ref.memberName == null) { - // Attr/Resolve assume packages exist and create symbols as needed - // so use getPackageElement to restrict search to existing packages - PackageSymbol pck = elements.getPackageElement(ref.qualifierExpression.toString()); - if (pck != null) { - return pck; - } else if (ref.qualifierExpression.hasTag(JCTree.Tag.IDENT)) { + JCCompilationUnit toplevel = + treeMaker.TopLevel(List.<JCTree>nil()); + final ModuleSymbol msym = modules.getDefaultModule(); + toplevel.modle = msym; + toplevel.packge = msym.unnamedPackage; + Symbol sym = attr.attribIdent(ref.qualifierExpression, toplevel); + + sym.complete(); + + if ((sym.kind == PCK || sym.kind == TYP) && sym.exists()) { + tsym = (TypeSymbol) sym; + memberName = (Name) ref.memberName; + if (sym.kind == PCK && memberName != null) { + //cannot refer to a package "member" + return null; + } + } else { + if (ref.qualifierExpression.hasTag(JCTree.Tag.IDENT)) { // fixup: allow "identifier" instead of "#identifier" // for compatibility with javadoc tsym = env.enclClass.sym; memberName = ((JCIdent) ref.qualifierExpression).name; - } else + } else { return null; - } else { - return null; + } } } else { tsym = t.tsym; @@ -1179,7 +1193,8 @@ } }; - PackageSymbol psym = javaFileObjectToPackageMap.getOrDefault(jfo, syms.unnamedPackage); + PackageSymbol psym = javaFileObjectToPackageMap.getOrDefault(jfo, + syms.unnamedModule.unnamedPackage); jcCompilationUnit.docComments = new DocCommentTable() { @Override @@ -1209,13 +1224,12 @@ }; jcCompilationUnit.lineMap = jcCompilationUnit.getLineMap(); + jcCompilationUnit.modle = psym.modle; + jcCompilationUnit.sourcefile = jfo; jcCompilationUnit.namedImportScope = new NamedImportScope(psym, jcCompilationUnit.toplevelScope); jcCompilationUnit.packge = psym; - jcCompilationUnit.starImportScope = null; - jcCompilationUnit.sourcefile = jfo; jcCompilationUnit.starImportScope = new StarImportScope(psym); jcCompilationUnit.toplevelScope = WriteableScope.create(psym); - return new TreePath(jcCompilationUnit); } }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java Thu Mar 24 16:21:21 2016 +0100 @@ -37,11 +37,13 @@ import javax.tools.JavaFileManager.Location; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; +import javax.tools.StandardLocation; import com.sun.tools.javac.code.Scope.WriteableScope; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.Completer; import com.sun.tools.javac.code.Symbol.CompletionFailure; +import com.sun.tools.javac.code.Symbol.ModuleSymbol; import com.sun.tools.javac.code.Symbol.PackageSymbol; import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.comp.Annotate; @@ -118,6 +120,10 @@ */ final Name completionFailureName; + /** Module specified with -Xmodule: + */ + final Name moduleOverride; + /** Access to files */ private final JavaFileManager fileManager; @@ -178,7 +184,7 @@ return instance; } - /** Construct a new class reader. */ + /** Construct a new class finder. */ protected ClassFinder(Context context) { context.put(classFinderKey, this); reader = ClassReader.instance(context); @@ -205,6 +211,9 @@ ? names.fromString(options.get("failcomplete")) : null; + moduleOverride = options.isSet(XMODULE) ? names.fromString(options.get(XMODULE)) + : null; + // Temporary, until more info is available from the module system. boolean useCtProps; JavaFileManager fm = context.get(JavaFileManager.class); @@ -237,7 +246,7 @@ * available from the module system. */ long getSupplementaryFlags(ClassSymbol c) { - if (jrtIndex == null || !jrtIndex.isInJRT(c.classfile)) { + if (jrtIndex == null || !jrtIndex.isInJRT(c.classfile) || c.name == names.module_info) { return 0; } @@ -318,7 +327,7 @@ for (Name name : Convert.enclosingCandidates(Convert.shortName(c.name))) { Symbol encl = owner.members().findFirst(name); if (encl == null) - encl = syms.classes.get(TypeSymbol.formFlatName(name, owner)); + encl = syms.getClass(c.packge().modle, TypeSymbol.formFlatName(name, owner)); if (encl != null) encl.complete(); } @@ -328,7 +337,7 @@ /** Fill in definition of class `c' from corresponding class or * source file. */ - private void fillIn(ClassSymbol c) { + void fillIn(ClassSymbol c) { if (completionFailureName == c.fullname) { throw new CompletionFailure(c, "user-selected completion failure by class name"); } @@ -397,14 +406,21 @@ /** Load a toplevel class with given fully qualified name * The class is entered into `classes' only if load was successful. */ - public ClassSymbol loadClass(Name flatname) throws CompletionFailure { - boolean absent = syms.classes.get(flatname) == null; - ClassSymbol c = syms.enterClass(flatname); + public ClassSymbol loadClass(ModuleSymbol msym, Name flatname) throws CompletionFailure { + Assert.checkNonNull(msym); + Name packageName = Convert.packagePart(flatname); + PackageSymbol ps = syms.lookupPackage(msym, packageName); + + Assert.checkNonNull(ps.modle, () -> "msym=" + msym + "; flatName=" + flatname); + + boolean absent = syms.getClass(ps.modle, flatname) == null; + ClassSymbol c = syms.enterClass(ps.modle, flatname); + if (c.members_field == null) { try { c.complete(); } catch (CompletionFailure ex) { - if (absent) syms.classes.remove(flatname); + if (absent) syms.removeClass(ps.modle, flatname); throw ex; } } @@ -438,7 +454,7 @@ ? p.package_info : (ClassSymbol) p.members_field.findFirst(classname); if (c == null) { - c = syms.enterClass(classname, p); + c = syms.enterClass(p.modle, classname, p); if (c.classfile == null) // only update the file if's it's newly created c.classfile = file; if (isPkgInfo) { @@ -479,6 +495,7 @@ /** * specifies types of files to be read when filling in a package symbol */ + // Note: overridden by JavadocClassFinder protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() { return EnumSet.of(JavaFileObject.Kind.CLASS, JavaFileObject.Kind.SOURCE); } @@ -502,16 +519,83 @@ if (p.members_field == null) p.members_field = WriteableScope.create(p); - preferCurrent = false; - if (userPathsFirst) { + ModuleSymbol msym = p.modle; + + Assert.checkNonNull(msym, () -> p.toString()); + + msym.complete(); + + if (msym == syms.noModule) { + preferCurrent = false; + if (userPathsFirst) { + scanUserPaths(p); + preferCurrent = true; + scanPlatformPath(p); + } else { + scanPlatformPath(p); + scanUserPaths(p); + } + } else if (msym.classLocation == StandardLocation.CLASS_PATH) { + // assert p.modle.sourceLocation == StandardLocation.SOURCE_PATH); scanUserPaths(p); - preferCurrent = true; - scanPlatformPath(p); } else { - scanPlatformPath(p); - scanUserPaths(p); + scanModulePaths(p, msym); } - verbosePath = false; + } + + // TODO: for now, this is a much simplified form of scanUserPaths + // and (deliberately) does not default sourcepath to classpath. + // But, we need to think about retaining existing behavior for + // -classpath and -sourcepath for single module mode. + // One plausible solution is to detect if the module's sourceLocation + // is the same as the module's classLocation. + private void scanModulePaths(PackageSymbol p, ModuleSymbol msym) throws IOException { + Set<JavaFileObject.Kind> kinds = getPackageFileKinds(); + + Set<JavaFileObject.Kind> classKinds = EnumSet.copyOf(kinds); + classKinds.remove(JavaFileObject.Kind.SOURCE); + boolean wantClassFiles = !classKinds.isEmpty(); + + Set<JavaFileObject.Kind> sourceKinds = EnumSet.copyOf(kinds); + sourceKinds.remove(JavaFileObject.Kind.CLASS); + boolean wantSourceFiles = !sourceKinds.isEmpty(); + + String packageName = p.fullname.toString(); + + if (msym.name == moduleOverride) { + if (wantClassFiles) { + fillIn(p, CLASS_PATH, + fileManager.list(CLASS_PATH, + packageName, + classKinds, + false)); + } + if (wantSourceFiles && fileManager.hasLocation(SOURCE_PATH)) { + fillIn(p, SOURCE_PATH, + fileManager.list(SOURCE_PATH, + packageName, + sourceKinds, + false)); + } + } + + Location classLocn = msym.classLocation; + Location sourceLocn = msym.sourceLocation; + + if (wantClassFiles && (classLocn != null)) { + fillIn(p, classLocn, + fileManager.list(classLocn, + packageName, + classKinds, + false)); + } + if (wantSourceFiles && (sourceLocn != null)) { + fillIn(p, sourceLocn, + fileManager.list(sourceLocn, + packageName, + sourceKinds, + false)); + } } /**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Directive.java Thu Mar 24 16:21:21 2016 +0100 @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2009, 2015, 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 com.sun.tools.javac.code; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.Set; + +import javax.lang.model.element.ModuleElement; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; + +import com.sun.tools.javac.code.Symbol.ClassSymbol; +import com.sun.tools.javac.code.Symbol.ModuleSymbol; +import com.sun.tools.javac.code.Symbol.PackageSymbol; +import com.sun.tools.javac.util.DefinedBy; +import com.sun.tools.javac.util.DefinedBy.Api; +import com.sun.tools.javac.util.List; + + +/** + * Root class for the directives that may appear in module compilation units. + * + * <p><b>This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own risk. + * This code and its internal interfaces are subject to change or + * deletion without notice.</b> + */ +public abstract class Directive implements ModuleElement.Directive { + + /** Flags for RequiresDirective. */ + public enum RequiresFlag { + PUBLIC(0x0020), + SYNTHETIC(0x1000), + MANDATED(0x8000), + EXTRA(0x10000); + + // overkill? move to ClassWriter? + public static int value(Set<RequiresFlag> s) { + int v = 0; + for (RequiresFlag f: s) + v |= f.value; + return v; + } + + RequiresFlag(int value) { + this.value = value; + } + + public final int value; + } + + /** + * 'exports' Package ';' + */ + public static class ExportsDirective extends Directive + implements ModuleElement.ExportsDirective { + public final PackageSymbol packge; + public final List<ModuleSymbol> modules; + + public ExportsDirective(PackageSymbol packge, List<ModuleSymbol> modules) { + this.packge = packge; + this.modules = modules; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public ModuleElement.DirectiveKind getKind() { + return ModuleElement.DirectiveKind.EXPORTS; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public PackageElement getPackage() { + return packge; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public java.util.List<? extends ModuleElement> getTargetModules() { + return Collections.unmodifiableList(modules); + } + + @Override + public String toString() { + if (modules == null) + return "Exports[" + packge + "]"; + else + return "Exports[" + packge + ":" + modules + "]"; + } + } + + /** + * 'provides' ServiceName 'with' QualifiedIdentifer ';' + */ + public static class ProvidesDirective extends Directive + implements ModuleElement.ProvidesDirective { + public final ClassSymbol service; + public final ClassSymbol impl; + + public ProvidesDirective(ClassSymbol service, ClassSymbol impl) { + this.service = service; + this.impl = impl; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public ModuleElement.DirectiveKind getKind() { + return ModuleElement.DirectiveKind.PROVIDES; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public TypeElement getService() { + return service; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public TypeElement getImplementation() { + return impl; + } + + @Override + public String toString() { + return "Provides[" + service + "," + impl + "]"; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ProvidesDirective)) { + return false; + } + ProvidesDirective other = (ProvidesDirective)obj; + return service == other.service && impl == other.impl; + } + + @Override + public int hashCode() { + return service.hashCode() * 31 + impl.hashCode() * 37; + } + } + + /** + * 'requires' ['public'] ModuleName ';' + */ + public static class RequiresDirective extends Directive + implements ModuleElement.RequiresDirective { + public final ModuleSymbol module; + public final Set<RequiresFlag> flags; + + public RequiresDirective(ModuleSymbol module) { + this(module, EnumSet.noneOf(RequiresFlag.class)); + } + + public RequiresDirective(ModuleSymbol module, Set<RequiresFlag> flags) { + this.module = module; + this.flags = flags; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public ModuleElement.DirectiveKind getKind() { + return ModuleElement.DirectiveKind.REQUIRES; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public boolean isPublic() { + return flags.contains(RequiresFlag.PUBLIC); + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public ModuleElement getDependency() { + return module; + } + + @Override + public String toString() { + return "Requires[" + flags + "," + module + "]"; + } + } + + /** + * 'uses' ServiceName ';' + */ + public static class UsesDirective extends Directive + implements ModuleElement.UsesDirective { + public final ClassSymbol service; + + public UsesDirective(ClassSymbol service) { + this.service = service; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public ModuleElement.DirectiveKind getKind() { + return ModuleElement.DirectiveKind.USES; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public TypeElement getService() { + return service; + } + + @Override + public String toString() { + return "Uses[" + service + "]"; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof UsesDirective)) { + return false; + } + UsesDirective other = (UsesDirective)obj; + return service == other.service; + } + + @Override + public int hashCode() { + return service.hashCode() * 31; + } + } +}
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java Thu Mar 24 16:21:21 2016 +0100 @@ -107,6 +107,7 @@ public static final int ACC_SUPER = 0x0020; public static final int ACC_BRIDGE = 0x0040; public static final int ACC_VARARGS = 0x0080; + public static final int ACC_MODULE = 0x8000; /***************************************** * Internal compiler flags (no bits in the lower 16). @@ -277,6 +278,21 @@ */ public static final long TYPE_TRANSLATED = 1L<<50; + /** + * Flag to indicate class symbol is for module-info + */ + public static final long MODULE = 1L<<51; + + /** + * Flag to indicate the given ModuleSymbol is an automatic module. + */ + public static final long AUTOMATIC_MODULE = 1L<<52; + + /** + * Flag to indicate the given ModuleSymbol is a system module. + */ + public static final long SYSTEM_MODULE = 1L<<53; + /** Modifier masks. */ public static final int @@ -385,7 +401,8 @@ SIGNATURE_POLYMORPHIC(Flags.SIGNATURE_POLYMORPHIC), THROWS(Flags.THROWS), LAMBDA_METHOD(Flags.LAMBDA_METHOD), - TYPE_TRANSLATED(Flags.TYPE_TRANSLATED); + TYPE_TRANSLATED(Flags.TYPE_TRANSLATED), + MODULE(Flags.MODULE); Flag(long flag) { this.value = flag;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java Thu Mar 24 16:21:21 2016 +0100 @@ -65,6 +65,7 @@ VAR(Category.BASIC, KindName.VAR, KindSelector.VAR), MTH(Category.BASIC, KindName.METHOD, KindSelector.MTH), POLY(Category.BASIC, KindSelector.POLY), + MDL(Category.BASIC, KindSelector.MDL), ERR(Category.ERROR, KindSelector.ERR), AMBIGUOUS(Category.RESOLUTION_TARGET), // overloaded target HIDDEN(Category.RESOLUTION_TARGET), // not overloaded non-target @@ -169,9 +170,10 @@ public static final KindSelector VAR = new KindSelector(0x04); public static final KindSelector VAL = new KindSelector(0x0c); public static final KindSelector MTH = new KindSelector(0x10); - public static final KindSelector ERR = new KindSelector(0x3f); public static final KindSelector POLY = new KindSelector(0x20); - public static final KindSelector ASG = new KindSelector(0x44); + public static final KindSelector MDL = new KindSelector(0x40); + public static final KindSelector ERR = new KindSelector(0x7f); + public static final KindSelector ASG = new KindSelector(0x84); //common derived selectors public static final KindSelector TYP_PCK = of(TYP, PCK); @@ -212,6 +214,7 @@ if ((data & MTH.data) != 0) kinds.add(KindName.METHOD); if ((data & TYP.data) != 0) kinds.add(KindName.CLASS); if ((data & PCK.data) != 0) kinds.add(KindName.PACKAGE); + if ((data & MDL.data) != 0) kinds.add(KindName.MODULE); return kinds; } } @@ -230,7 +233,8 @@ CLASS("kindname.class"), STATIC_INIT("kindname.static.init"), INSTANCE_INIT("kindname.instance.init"), - PACKAGE("kindname.package"); + PACKAGE("kindname.package"), + MODULE("kindname.module"); private final String name;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ModuleFinder.java Thu Mar 24 16:21:21 2016 +0100 @@ -0,0 +1,335 @@ +/* + * Copyright (c) 2015, 2016, 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 com.sun.tools.javac.code; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; + +import javax.tools.JavaFileManager; +import javax.tools.JavaFileManager.Location; +import javax.tools.JavaFileObject; +import javax.tools.JavaFileObject.Kind; +import javax.tools.StandardLocation; + +import com.sun.tools.javac.code.Symbol.CompletionFailure; +import com.sun.tools.javac.code.Symbol.ModuleSymbol; +import com.sun.tools.javac.resources.CompilerProperties.Errors; +import com.sun.tools.javac.resources.CompilerProperties.Fragments; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.JCDiagnostic; +import com.sun.tools.javac.util.JCDiagnostic.Fragment; +import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; +import com.sun.tools.javac.util.Log; +import com.sun.tools.javac.util.Name; +import com.sun.tools.javac.util.Names; +import com.sun.tools.javac.util.StringUtils; + +import static com.sun.tools.javac.code.Kinds.Kind.*; + +/** + * This class provides operations to locate module definitions + * from the source and class files on the paths provided to javac. + * + * <p><b>This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own risk. + * This code and its internal interfaces are subject to change or + * deletion without notice.</b> + */ +public class ModuleFinder { + /** The context key for the module finder. */ + protected static final Context.Key<ModuleFinder> moduleFinderKey = new Context.Key<>(); + + /** The log to use for verbose output. */ + private final Log log; + + /** The symbol table. */ + private final Symtab syms; + + /** The name table. */ + private final Names names; + + private final ClassFinder classFinder; + + /** Access to files + */ + private final JavaFileManager fileManager; + + private final JCDiagnostic.Factory diags; + + /** Get the ModuleFinder instance for this invocation. */ + public static ModuleFinder instance(Context context) { + ModuleFinder instance = context.get(moduleFinderKey); + if (instance == null) + instance = new ModuleFinder(context); + return instance; + } + + /** Construct a new module finder. */ + protected ModuleFinder(Context context) { + context.put(moduleFinderKey, this); + names = Names.instance(context); + syms = Symtab.instance(context); + fileManager = context.get(JavaFileManager.class); + log = Log.instance(context); + classFinder = ClassFinder.instance(context); + + diags = JCDiagnostic.Factory.instance(context); + } + + class ModuleLocationIterator implements Iterator<Set<Location>> { + StandardLocation outer; + Set<Location> next = null; + + Iterator<StandardLocation> outerIter = Arrays.asList( + StandardLocation.MODULE_SOURCE_PATH, + StandardLocation.UPGRADE_MODULE_PATH, + StandardLocation.SYSTEM_MODULES, + StandardLocation.MODULE_PATH + ).iterator(); + Iterator<Set<Location>> innerIter = null; + + @Override + public boolean hasNext() { + while (next == null) { + while (innerIter == null || !innerIter.hasNext()) { + if (outerIter.hasNext()) { + outer = outerIter.next(); + try { + innerIter = fileManager.listModuleLocations(outer).iterator(); + } catch (IOException e) { + System.err.println("error listing module locations for " + outer + ": " + e); // FIXME + } + } else + return false; + } + + if (innerIter.hasNext()) + next = innerIter.next(); + } + return true; + } + + @Override + public Set<Location> next() { + hasNext(); + if (next != null) { + Set<Location> result = next; + next = null; + return result; + } + throw new NoSuchElementException(); + } + + } + + ModuleLocationIterator moduleLocationIterator = new ModuleLocationIterator(); + + public ModuleSymbol findModule(Name name) { + return findModule(syms.enterModule(name)); + } + + public ModuleSymbol findModule(ModuleSymbol msym) { + if (msym.kind != ERR && msym.sourceLocation == null && msym.classLocation == null) { + // fill in location + List<ModuleSymbol> list = scanModulePath(msym); + if (list.isEmpty()) { + msym.kind = ERR; + } + } + if (msym.kind != ERR && msym.module_info.sourcefile == null && msym.module_info.classfile == null) { + // fill in module-info + findModuleInfo(msym); + } + return msym; + } + + public List<ModuleSymbol> findAllModules() { + List<ModuleSymbol> list = scanModulePath(null); + for (ModuleSymbol msym: list) { + if (msym.kind != ERR && msym.module_info.sourcefile == null && msym.module_info.classfile == null) { + // fill in module-info + findModuleInfo(msym); + } + } + return list; + } + + public ModuleSymbol findSingleModule() { + try { + JavaFileObject src_fo = getModuleInfoFromLocation(StandardLocation.SOURCE_PATH, Kind.SOURCE); + JavaFileObject class_fo = getModuleInfoFromLocation(StandardLocation.CLASS_OUTPUT, Kind.CLASS); + JavaFileObject fo = (src_fo == null) ? class_fo + : (class_fo == null) ? src_fo + : classFinder.preferredFileObject(src_fo, class_fo); + + ModuleSymbol msym; + if (fo == null) { + msym = syms.unnamedModule; + } else { + // Note: the following may trigger a re-entrant call to Modules.enter +// msym = new ModuleSymbol(); +// ClassSymbol info = new ClassSymbol(Flags.MODULE, names.module_info, msym); +// info.modle = msym; +// info.classfile = fo; +// info.members_field = WriteableScope.create(info); +// msym.module_info = info; + msym = ModuleSymbol.create(null, names.module_info); + msym.module_info.classfile = fo; + msym.completer = sym -> classFinder.fillIn(msym.module_info); +// // TODO: should we do the following here, or as soon as we find the name in +// // the source or class file? +// // Consider the case when the class/source path module shadows one on the +// // module source path +// if (syms.modules.get(msym.name) != null) { +// // error: module already defined +// System.err.println("ERROR: module already defined: " + msym); +// } else { +// syms.modules.put(msym.name, msym); +// } + } + + msym.classLocation = StandardLocation.CLASS_OUTPUT; + return msym; + + } catch (IOException e) { + throw new Error(e); // FIXME + } + } + + private JavaFileObject getModuleInfoFromLocation(Location location, Kind kind) throws IOException { + if (!fileManager.hasLocation(location)) + return null; + + return fileManager.getJavaFileForInput(location, + names.module_info.toString(), + kind); + } + + private List<ModuleSymbol> scanModulePath(ModuleSymbol toFind) { + ListBuffer<ModuleSymbol> results = new ListBuffer<>(); + Map<Name, Location> namesInSet = new HashMap<>(); + while (moduleLocationIterator.hasNext()) { + Set<Location> locns = (moduleLocationIterator.next()); + namesInSet.clear(); + for (Location l: locns) { + try { + Name n = names.fromString(fileManager.inferModuleName(l)); + if (namesInSet.put(n, l) == null) { + ModuleSymbol msym = syms.enterModule(n); + if (msym.sourceLocation != null || msym.classLocation != null) { + // module has already been found, so ignore this instance + continue; + } + if (moduleLocationIterator.outer == StandardLocation.MODULE_SOURCE_PATH) { + msym.sourceLocation = l; + if (fileManager.hasLocation(StandardLocation.CLASS_OUTPUT)) { + msym.classLocation = fileManager.getModuleLocation(StandardLocation.CLASS_OUTPUT, msym.name.toString()); + } + } else { + msym.classLocation = l; + } + if (moduleLocationIterator.outer == StandardLocation.SYSTEM_MODULES || + moduleLocationIterator.outer == StandardLocation.UPGRADE_MODULE_PATH) { + msym.flags_field |= Flags.SYSTEM_MODULE; + } + if (toFind == msym || toFind == null) { + // Note: cannot return msym directly, because we must finish + // processing this set first + results.add(msym); + } + } else { + log.error(Errors.DuplicateModuleOnPath( + getDescription(moduleLocationIterator.outer), n)); + } + } catch (IOException e) { + // skip location for now? log error? + } + } + if (toFind != null && results.nonEmpty()) + return results.toList(); + } + + return results.toList(); + } + + private void findModuleInfo(ModuleSymbol msym) { + try { + JavaFileObject src_fo = (msym.sourceLocation == null) ? null + : fileManager.getJavaFileForInput(msym.sourceLocation, + names.module_info.toString(), Kind.SOURCE); + + JavaFileObject class_fo = (msym.classLocation == null) ? null + : fileManager.getJavaFileForInput(msym.classLocation, + names.module_info.toString(), Kind.CLASS); + + JavaFileObject fo = (src_fo == null) ? class_fo : + (class_fo == null) ? src_fo : + classFinder.preferredFileObject(src_fo, class_fo); + + if (fo == null) { + String moduleName = msym.sourceLocation == null && msym.classLocation != null ? + fileManager.inferModuleName(msym.classLocation) : null; + if (moduleName != null) { + msym.module_info.classfile = null; + msym.flags_field |= Flags.AUTOMATIC_MODULE; + } else { + msym.kind = ERR; + } + } else { + msym.module_info.classfile = fo; + msym.module_info.completer = new Symbol.Completer() { + @Override + public void complete(Symbol sym) throws CompletionFailure { + classFinder.fillIn(msym.module_info); + } + @Override + public String toString() { + return "ModuleInfoCompleter"; + } + }; + } + } catch (IOException e) { + msym.kind = ERR; + } + } + + Fragment getDescription(StandardLocation l) { + switch (l) { + case MODULE_PATH: return Fragments.LocnModule_path; + case MODULE_SOURCE_PATH: return Fragments.LocnModule_source_path; + case SYSTEM_MODULES: return Fragments.LocnSystem_modules; + case UPGRADE_MODULE_PATH: return Fragments.LocnUpgrade_module_path; + default: + throw new AssertionError(); + } + } + +}
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Printer.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Printer.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2014, 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 @@ -152,14 +152,14 @@ if (seenCaptured.contains(t)) return printAnnotations(t) + localize(locale, "compiler.misc.type.captureof.1", - capturedVarId(t, locale)); + capturedVarId(t, locale)); else { try { seenCaptured = seenCaptured.prepend(t); return printAnnotations(t) + localize(locale, "compiler.misc.type.captureof", - capturedVarId(t, locale), - visit(t.wildcard, locale)); + capturedVarId(t, locale), + visit(t.wildcard, locale)); } finally { seenCaptured = seenCaptured.tail; @@ -274,6 +274,11 @@ return visitType(t, locale); } + @Override + public String visitModuleType(ModuleType t, Locale locale) { + return visitType(t, locale); + } + public String visitType(Type t, Locale locale) { String s = (t.tsym == null || t.tsym.name == null) ? localize(locale, "compiler.misc.type.none")
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java Thu Mar 24 16:21:21 2016 +0100 @@ -137,6 +137,9 @@ public boolean allowImprovedCatchAnalysis() { return compareTo(JDK1_7) >= 0; } + public boolean allowModules() { + return compareTo(JDK1_9) >= 0; + } public boolean allowTryWithResources() { return compareTo(JDK1_7) >= 0; }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2016, 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 @@ -27,16 +27,26 @@ import java.lang.annotation.Annotation; import java.lang.annotation.Inherited; +import java.util.Collections; +import java.util.Map; import java.util.Set; import java.util.concurrent.Callable; -import javax.lang.model.element.*; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ElementVisitor; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.ModuleElement; +import javax.lang.model.element.NestingKind; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.TypeParameterElement; +import javax.lang.model.element.VariableElement; +import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; -import com.sun.tools.javac.code.Attribute.Compound; -import com.sun.tools.javac.code.TypeAnnotations.AnnotationType; -import com.sun.tools.javac.code.TypeMetadata.Entry; -import com.sun.tools.javac.comp.Annotate.AnnotationTypeCompleter; +import com.sun.tools.javac.code.Kinds.Kind; import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata; import com.sun.tools.javac.code.Scope.WriteableScope; import com.sun.tools.javac.code.Type.*; @@ -48,6 +58,7 @@ import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.DefinedBy.Api; import com.sun.tools.javac.util.Name; + import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.Kind.*; @@ -843,7 +854,7 @@ boolean isCurrentSymbolsAnnotation(Attribute.TypeCompound anno, int index) { return (anno.position.type == TargetType.CLASS_TYPE_PARAMETER || anno.position.type == TargetType.METHOD_TYPE_PARAMETER) && - anno.position.parameter_index == index; + anno.position.parameter_index == index; } @@ -852,6 +863,122 @@ return v.visitTypeParameter(this, p); } } + /** A class for module symbols. + */ + public static class ModuleSymbol extends TypeSymbol + implements ModuleElement { + + public Name version; + public JavaFileManager.Location sourceLocation; + public JavaFileManager.Location classLocation; + + /** All directives, in natural order. */ + public List<com.sun.tools.javac.code.Directive> directives; + public List<com.sun.tools.javac.code.Directive.RequiresDirective> requires; + public List<com.sun.tools.javac.code.Directive.ExportsDirective> exports; + public List<com.sun.tools.javac.code.Directive.ProvidesDirective> provides; + public List<com.sun.tools.javac.code.Directive.UsesDirective> uses; + + public ClassSymbol module_info; + + public PackageSymbol unnamedPackage; + public Map<Name, PackageSymbol> visiblePackages; + public List<Symbol> enclosedPackages = List.nil(); + + public Completer usesProvidesCompleter = Completer.NULL_COMPLETER; + + /** + * Create a ModuleSymbol with an associated module-info ClassSymbol. + * The name of the module may be null, if it is not known yet. + */ + public static ModuleSymbol create(Name name, Name module_info) { + ModuleSymbol msym = new ModuleSymbol(name, null); + ClassSymbol info = new ClassSymbol(Flags.MODULE, module_info, msym); + info.fullname = formFullName(module_info, msym); + info.flatname = info.fullname; + info.members_field = WriteableScope.create(info); + msym.module_info = info; + return msym; + } + + public ModuleSymbol() { + super(MDL, 0, null, null, null); + this.type = new ModuleType(this); + } + + public ModuleSymbol(Name name, Symbol owner) { + super(MDL, 0, name, null, owner); + this.type = new ModuleType(this); + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public boolean isUnnamed() { + return name.isEmpty() && owner == null; + } + + public boolean isNoModule() { + return false; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public ElementKind getKind() { + return ElementKind.MODULE; + } + + @Override @DefinedBy(Api.LANGUAGE_MODEL) + public java.util.List<Directive> getDirectives() { + completeUsesProvides(); + return Collections.unmodifiableList(directives); + } + + public void completeUsesProvides() { + if (usesProvidesCompleter != Completer.NULL_COMPLETER) { + Completer c = usesProvidesCompleter; + usesProvidesCompleter = Completer.NULL_COMPLETER; + c.complete(this); + } + } + + @Override + public ClassSymbol outermostClass() { + return null; + } + + @Override + public String toString() { + // TODO: the following strings should be localized + // Do this with custom anon subtypes in Symtab + String n = (name == null) ? "<unknown>" + : (name.isEmpty()) ? "<unnamed>" + : String.valueOf(name); + return n; + } + + @Override + public <R, P> R accept(ElementVisitor<R, P> v, P p) { + return v.visitModule(this, p); + } + + @Override + public List<Symbol> getEnclosedElements() { + List<Symbol> list = List.nil(); + for (Symbol sym : enclosedPackages) { + if (sym.members().anyMatch(m -> m.kind == TYP)) + list = list.prepend(sym); + } + return list; + } + + public void reset() { + this.directives = null; + this.requires = null; + this.exports = null; + this.provides = null; + this.uses = null; + this.visiblePackages = null; + } + + } /** A class for package symbols */ @@ -861,6 +988,7 @@ public WriteableScope members_field; public Name fullname; public ClassSymbol package_info; // see bug 6443073 + public ModuleSymbol modle; public PackageSymbol(Name name, Type type, Symbol owner) { super(PCK, 0, name, type, owner); @@ -929,7 +1057,7 @@ @DefinedBy(Api.LANGUAGE_MODEL) public Symbol getEnclosingElement() { - return null; + return modle != null && !modle.isNoModule() ? modle : null; } @DefinedBy(Api.LANGUAGE_MODEL)
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2016, 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 @@ -25,18 +25,20 @@ package com.sun.tools.javac.code; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import javax.lang.model.element.ElementVisitor; -import javax.tools.JavaFileObject; - import com.sun.tools.javac.code.Scope.WriteableScope; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.Completer; import com.sun.tools.javac.code.Symbol.CompletionFailure; import com.sun.tools.javac.code.Symbol.MethodSymbol; +import com.sun.tools.javac.code.Symbol.ModuleSymbol; import com.sun.tools.javac.code.Symbol.PackageSymbol; import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symbol.VarSymbol; @@ -47,17 +49,18 @@ import com.sun.tools.javac.code.Type.JCVoidType; import com.sun.tools.javac.code.Type.MethodType; import com.sun.tools.javac.code.Type.UnknownType; -import com.sun.tools.javac.jvm.Target; +import com.sun.tools.javac.comp.Modules; import com.sun.tools.javac.util.Assert; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Convert; import com.sun.tools.javac.util.DefinedBy; import com.sun.tools.javac.util.DefinedBy.Api; +import com.sun.tools.javac.util.Iterators; import com.sun.tools.javac.util.JavacMessages; import com.sun.tools.javac.util.List; -import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Name; import com.sun.tools.javac.util.Names; +import com.sun.tools.javac.util.Options; import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Kinds.Kind.*; @@ -100,17 +103,26 @@ public final JCVoidType voidType = new JCVoidType(); private final Names names; + private final JavacMessages messages; private final Completer initialCompleter; - private final Target target; + private final Completer moduleCompleter; + + /** A symbol for the unnamed module. + */ + public final ModuleSymbol unnamedModule; + + /** The error module. + */ + public final ModuleSymbol errModule; + + /** A symbol for no module, for use with -source 8 or less + */ + public final ModuleSymbol noModule; /** A symbol for the root package. */ public final PackageSymbol rootPackage; - /** A symbol for the unnamed package. - */ - public final PackageSymbol unnamedPackage; - /** A symbol that stands for a missing symbol. */ public final TypeSymbol noSymbol; @@ -139,6 +151,10 @@ /** The builtin type of all methods. */ public final ClassSymbol methodClass; + /** A symbol for the java.base module. + */ + public final ModuleSymbol java_base; + /** Predefined types. */ public final Type objectType; @@ -209,7 +225,7 @@ */ public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()]; - /** The name of the class that belongs to a basix type tag. + /** The name of the class that belongs to a basic type tag. */ public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()]; @@ -218,13 +234,17 @@ * It should be updated from the outside to reflect classes defined * by compiled source files. */ - public final Map<Name, ClassSymbol> classes = new HashMap<>(); + private final Map<Name, Map<ModuleSymbol,ClassSymbol>> classes = new HashMap<>(); /** A hashtable containing the encountered packages. * the table should be updated from outside to reflect packages defined * by compiled source files. */ - public final Map<Name, PackageSymbol> packages = new HashMap<>(); + private final Map<Name, Map<ModuleSymbol,PackageSymbol>> packages = new HashMap<>(); + + /** A hashtable giving the encountered modules. + */ + private final Map<Name, ModuleSymbol> modules = new LinkedHashMap<>(); public void initType(Type type, ClassSymbol c) { type.tsym = c; @@ -240,7 +260,7 @@ public void initType(Type type, String name, String bname) { initType(type, name); - boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname); + boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname); } /** The class symbol that owns all predefined symbols. @@ -251,12 +271,13 @@ * @param s The name of the class. */ private Type enterClass(String s) { - return enterClass(names.fromString(s)).type; + return enterClass(java_base, names.fromString(s)).type; } public void synthesizeEmptyInterfaceIfMissing(final Type type) { final Completer completer = type.tsym.completer; type.tsym.completer = new Completer() { + @Override public void complete(Symbol sym) throws CompletionFailure { try { completer.complete(sym); @@ -274,9 +295,10 @@ } public void synthesizeBoxTypeIfMissing(final Type type) { - ClassSymbol sym = enterClass(boxedName[type.getTag().ordinal()]); + ClassSymbol sym = enterClass(java_base, boxedName[type.getTag().ordinal()]); final Completer completer = sym.completer; sym.completer = new Completer() { + @Override public void complete(Symbol sym) throws CompletionFailure { try { completer.complete(sym); @@ -309,7 +331,9 @@ // Enter a synthetic class that is used to mark classes in ct.sym. // This class does not have a class file. private Type enterSyntheticAnnotation(String name) { - ClassType type = (ClassType)enterClass(name); + // for now, leave the module null, to prevent problems from synthesizing the + // existence of a class in any specific module, including noModule + ClassType type = (ClassType)enterClass(java_base, names.fromString(name)).type; ClassSymbol sym = (ClassSymbol)type.tsym; sym.completer = Completer.NULL_COMPLETER; sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE; @@ -329,22 +353,35 @@ context.put(symtabKey, this); names = Names.instance(context); - target = Target.instance(context); // Create the unknown type unknownType = new UnknownType(); + messages = JavacMessages.instance(context); + + rootPackage = new PackageSymbol(names.empty, null); + // create the basic builtin symbols - rootPackage = new PackageSymbol(names.empty, null); - packages.put(names.empty, rootPackage); - final JavacMessages messages = JavacMessages.instance(context); - unnamedPackage = new PackageSymbol(names.empty, rootPackage) { + unnamedModule = new ModuleSymbol(names.empty, null) { + @Override public String toString() { - return messages.getLocalizedString("compiler.misc.unnamed.package"); + return messages.getLocalizedString("compiler.misc.unnamed.module"); } }; + addRootPackageFor(unnamedModule); + + errModule = new ModuleSymbol(names.empty, null) { }; + addRootPackageFor(errModule); + + noModule = new ModuleSymbol(names.empty, null) { + @Override public boolean isNoModule() { + return true; + } + }; + addRootPackageFor(noModule); + noSymbol = new TypeSymbol(NIL, 0, names.empty, Type.noType, rootPackage) { - @DefinedBy(Api.LANGUAGE_MODEL) + @Override @DefinedBy(Api.LANGUAGE_MODEL) public <R, P> R accept(ElementVisitor<R, P> v, P p) { return v.visitUnknown(this, p); } @@ -390,8 +427,7 @@ // Get the initial completer for Symbols from the ClassFinder initialCompleter = ClassFinder.instance(context).getCompleter(); - rootPackage.completer = initialCompleter; - unnamedPackage.completer = initialCompleter; + rootPackage.members_field = WriteableScope.create(rootPackage); // Enter symbols for basic types. scope.enter(byteType.tsym); @@ -407,9 +443,22 @@ // Enter symbol for the errSymbol scope.enter(errSymbol); - classes.put(predefClass.fullname, predefClass); + Source source = Source.instance(context); + Options options = Options.instance(context); + boolean noModules = options.isSet("noModules"); + if (source.allowModules() && !noModules) { + java_base = enterModule(names.java_base); + //avoid completing java.base during the Symtab initialization + java_base.completer = Completer.NULL_COMPLETER; + java_base.visiblePackages = Collections.emptyMap(); + } else { + java_base = noModule; + } - // Enter predefined classes. + // Get the initial completer for ModuleSymbols from Modules + moduleCompleter = Modules.instance(context).getCompleter(); + + // Enter predefined classes. All are assumed to be in the java.base module. objectType = enterClass("java.lang.Object"); objectsType = enterClass("java.util.Objects"); classType = enterClass("java.lang.Class"); @@ -436,7 +485,7 @@ cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException"); annotationType = enterClass("java.lang.annotation.Annotation"); classLoaderType = enterClass("java.lang.ClassLoader"); - enumSym = enterClass(names.java_lang_Enum); + enumSym = enterClass(java_base, names.java_lang_Enum); enumFinalFinalize = new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL, names.finalize, @@ -514,14 +563,16 @@ List.<Type>nil(), methodClass), arrayClass); arrayClass.members().enter(arrayCloneMethod); + + if (java_base != noModule) + java_base.completer = sym -> moduleCompleter.complete(sym); //bootstrap issues + } /** Define a new class given its name and owner. */ public ClassSymbol defineClass(Name name, Symbol owner) { ClassSymbol c = new ClassSymbol(0, name, owner); - if (owner.kind == PCK) - Assert.checkNull(classes.get(c.flatname), c); c.completer = initialCompleter; return c; } @@ -529,12 +580,13 @@ /** Create a new toplevel or member class symbol with given name * and owner and enter in `classes' unless already there. */ - public ClassSymbol enterClass(Name name, TypeSymbol owner) { + public ClassSymbol enterClass(ModuleSymbol msym, Name name, TypeSymbol owner) { + Assert.checkNonNull(msym); Name flatname = TypeSymbol.formFlatName(name, owner); - ClassSymbol c = classes.get(flatname); + ClassSymbol c = getClass(msym, flatname); if (c == null) { c = defineClass(name, owner); - classes.put(flatname, c); + doEnterClass(msym, c); } else if ((c.name != name || c.owner != owner) && owner.kind == TYP && c.owner.kind == PCK) { // reassign fields of classes that might have been loaded with // their flat names. @@ -546,71 +598,212 @@ return c; } - /** - * Creates a new toplevel class symbol with given flat name and - * given class (or source) file. - * - * @param flatName a fully qualified binary class name - * @param classFile the class file or compilation unit defining - * the class (may be {@code null}) - * @return a newly created class symbol - * @throws AssertionError if the class symbol already exists - */ - public ClassSymbol enterClass(Name flatName, JavaFileObject classFile) { - ClassSymbol cs = classes.get(flatName); - if (cs != null) { - String msg = Log.format("%s: completer = %s; class file = %s; source file = %s", - cs.fullname, - cs.completer, - cs.classfile, - cs.sourcefile); - throw new AssertionError(msg); + public ClassSymbol getClass(ModuleSymbol msym, Name flatName) { + Assert.checkNonNull(msym, () -> flatName.toString()); + return classes.getOrDefault(flatName, Collections.emptyMap()).get(msym); + } + + public PackageSymbol lookupPackage(ModuleSymbol msym, Name flatName) { + Assert.checkNonNull(msym); + + if (flatName.isEmpty()) { + //unnamed packages only from the current module - visiblePackages contains *root* package, not unnamed package! + return msym.unnamedPackage; } - Name packageName = Convert.packagePart(flatName); - PackageSymbol owner = packageName.isEmpty() - ? unnamedPackage - : enterPackage(packageName); - cs = defineClass(Convert.shortName(flatName), owner); - cs.classfile = classFile; - classes.put(flatName, cs); - return cs; + + if (msym == noModule) { + return enterPackage(msym, flatName); + } + + msym.complete(); + + PackageSymbol pack; + + pack = msym.visiblePackages.get(flatName); + + if (pack != null) + return pack; + + pack = getPackage(msym, flatName); + + if (pack != null && pack.exists()) + return pack; + + boolean dependsOnUnnamed = msym.requires != null && + msym.requires.stream() + .map(rd -> rd.module) + .anyMatch(mod -> mod == unnamedModule); + + if (dependsOnUnnamed) { + //msyms depends on the unnamed module, for which we generally don't know + //the list of packages it "exports" ahead of time. So try to lookup the package in the + //current module, and in the unnamed module and see if it exists in one of them + PackageSymbol unnamedPack = getPackage(unnamedModule, flatName); + + if (unnamedPack != null && unnamedPack.exists()) { + msym.visiblePackages.put(unnamedPack.fullname, unnamedPack); + return unnamedPack; + } + + pack = enterPackage(msym, flatName); + pack.complete(); + if (pack.exists()) + return pack; + + unnamedPack = enterPackage(unnamedModule, flatName); + unnamedPack.complete(); + if (unnamedPack.exists()) { + msym.visiblePackages.put(unnamedPack.fullname, unnamedPack); + return unnamedPack; + } + + return pack; + } + + return enterPackage(msym, flatName); + } + + private static final Map<ModuleSymbol, ClassSymbol> EMPTY = new HashMap<>(); + + public void removeClass(ModuleSymbol msym, Name flatName) { + classes.getOrDefault(flatName, EMPTY).remove(msym); + } + + public Iterable<ClassSymbol> getAllClasses() { + return () -> Iterators.createCompoundIterator(classes.values(), v -> v.values().iterator()); + } + + private void doEnterClass(ModuleSymbol msym, ClassSymbol cs) { + classes.computeIfAbsent(cs.flatname, n -> new HashMap<>()).put(msym, cs); } /** Create a new member or toplevel class symbol with given flat name * and enter in `classes' unless already there. */ - public ClassSymbol enterClass(Name flatname) { - ClassSymbol c = classes.get(flatname); - if (c == null) - return enterClass(flatname, (JavaFileObject)null); - else + public ClassSymbol enterClass(ModuleSymbol msym, Name flatname) { + Assert.checkNonNull(msym); + PackageSymbol ps = lookupPackage(msym, Convert.packagePart(flatname)); + Assert.checkNonNull(ps); + Assert.checkNonNull(ps.modle); + ClassSymbol c = getClass(ps.modle, flatname); + if (c == null) { + c = defineClass(Convert.shortName(flatname), ps); + doEnterClass(ps.modle, c); + return c; + } else return c; } /** Check to see if a package exists, given its fully qualified name. */ - public boolean packageExists(Name fullname) { - return enterPackage(fullname).exists(); + public boolean packageExists(ModuleSymbol msym, Name fullname) { + Assert.checkNonNull(msym); + return enterPackage(msym, fullname).exists(); } /** Make a package, given its fully qualified name. */ - public PackageSymbol enterPackage(Name fullname) { - PackageSymbol p = packages.get(fullname); + public PackageSymbol enterPackage(ModuleSymbol currModule, Name fullname) { + Assert.checkNonNull(currModule); + PackageSymbol p = getPackage(currModule, fullname); if (p == null) { - Assert.check(!fullname.isEmpty(), "rootPackage missing!"); + Assert.check(!fullname.isEmpty(), () -> "rootPackage missing!; currModule: " + currModule); p = new PackageSymbol( - Convert.shortName(fullname), - enterPackage(Convert.packagePart(fullname))); + Convert.shortName(fullname), + enterPackage(currModule, Convert.packagePart(fullname))); p.completer = initialCompleter; - packages.put(fullname, p); + p.modle = currModule; + doEnterPackage(currModule, p); } return p; } - /** Make a package, given its unqualified name and enclosing package. - */ - public PackageSymbol enterPackage(Name name, PackageSymbol owner) { - return enterPackage(TypeSymbol.formFullName(name, owner)); + private void doEnterPackage(ModuleSymbol msym, PackageSymbol pack) { + packages.computeIfAbsent(pack.fullname, n -> new HashMap<>()).put(msym, pack); + msym.enclosedPackages = msym.enclosedPackages.prepend(pack); + } + + private void addRootPackageFor(ModuleSymbol module) { + doEnterPackage(module, rootPackage); + PackageSymbol unnamedPackage = new PackageSymbol(names.empty, rootPackage) { + @Override + public String toString() { + return messages.getLocalizedString("compiler.misc.unnamed.package"); + } + }; + unnamedPackage.modle = module; + unnamedPackage.completer = sym -> initialCompleter.complete(sym); + module.unnamedPackage = unnamedPackage; + } + + public PackageSymbol getPackage(ModuleSymbol module, Name fullname) { + return packages.getOrDefault(fullname, Collections.emptyMap()).get(module); + } + + public ModuleSymbol enterModule(Name name) { + ModuleSymbol msym = modules.get(name); + if (msym == null) { + msym = ModuleSymbol.create(name, names.module_info); + addRootPackageFor(msym); + msym.completer = sym -> moduleCompleter.complete(sym); //bootstrap issues + modules.put(name, msym); + } + return msym; + } + + public void enterModule(ModuleSymbol msym, Name name) { + Assert.checkNull(modules.get(name)); + Assert.checkNull(msym.name); + msym.name = name; + addRootPackageFor(msym); + ClassSymbol info = msym.module_info; + info.fullname = msym.name.append('.', names.module_info); + info.flatname = info.fullname; + modules.put(name, msym); + } + + public ModuleSymbol getModule(Name name) { + return modules.get(name); + } + + //temporary: + public ModuleSymbol inferModule(Name packageName) { + if (packageName.isEmpty()) + return java_base == noModule ? noModule : unnamedModule;//! + + ModuleSymbol msym = null; + Map<ModuleSymbol,PackageSymbol> map = packages.get(packageName); + if (map == null) + return null; + for (Map.Entry<ModuleSymbol,PackageSymbol> e: map.entrySet()) { + if (!e.getValue().members().isEmpty()) { + if (msym == null) { + msym = e.getKey(); + } else { + return null; + } + } + } + return msym; + } + + public List<ModuleSymbol> listPackageModules(Name packageName) { + if (packageName.isEmpty()) + return List.nil(); + + List<ModuleSymbol> result = List.nil(); + Map<ModuleSymbol,PackageSymbol> map = packages.get(packageName); + if (map != null) { + for (Map.Entry<ModuleSymbol, PackageSymbol> e: map.entrySet()) { + if (!e.getValue().members().isEmpty()) { + result = result.prepend(e.getKey()); + } + } + } + return result; + } + + public Collection<ModuleSymbol> getAllModules() { + return modules.values(); } }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java Thu Mar 24 16:21:21 2016 +0100 @@ -1525,7 +1525,7 @@ public static class PackageType extends Type implements NoType { - PackageType(TypeSymbol tsym) { + PackageType(PackageSymbol tsym) { // Package types cannot be annotated super(tsym, TypeMetadata.EMPTY); } @@ -1561,6 +1561,49 @@ } } + public static class ModuleType extends Type implements NoType { + + ModuleType(ModuleSymbol tsym) { + // Module types cannot be annotated + super(tsym, TypeMetadata.EMPTY); + } + + @Override + public ModuleType cloneWithMetadata(TypeMetadata md) { + throw new AssertionError("Cannot add metadata to a module type"); + } + + @Override + public ModuleType annotatedType(List<Attribute.TypeCompound> annos) { + throw new AssertionError("Cannot annotate a module type"); + } + + @Override + public TypeTag getTag() { + return TypeTag.MODULE; + } + + @Override + public <R,S> R accept(Type.Visitor<R,S> v, S s) { + return v.visitModuleType(this, s); + } + + @Override + public String toString() { + return tsym.getQualifiedName().toString(); + } + + @Override + public TypeKind getKind() { + return TypeKind.MODULE; + } + + @Override + public <R, P> R accept(TypeVisitor<R, P> v, P p) { + return v.visitNoType(this, p); + } + } + public static class TypeVar extends Type implements TypeVariable { /** The upper bound of this type variable; set from outside. @@ -2384,6 +2427,7 @@ R visitArrayType(ArrayType t, S s); R visitMethodType(MethodType t, S s); R visitPackageType(PackageType t, S s); + R visitModuleType(ModuleType t, S s); R visitTypeVar(TypeVar t, S s); R visitCapturedType(CapturedType t, S s); R visitForAll(ForAll t, S s);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Thu Mar 24 16:21:21 2016 +0100 @@ -49,6 +49,7 @@ import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntryKind; import com.sun.tools.javac.code.Symbol.VarSymbol; import com.sun.tools.javac.code.Symbol.MethodSymbol; +import com.sun.tools.javac.code.Type.ModuleType; import com.sun.tools.javac.code.TypeMetadata.Entry.Kind; import com.sun.tools.javac.comp.Annotate; import com.sun.tools.javac.comp.Attr; @@ -652,6 +653,11 @@ } @Override + public Type visitModuleType(ModuleType t, List<TypeCompound> s) { + return t.annotatedType(s); + } + + @Override public Type visitCapturedType(CapturedType t, List<TypeCompound> s) { return t.annotatedType(s); }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeTag.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeTag.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, 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 @@ -89,6 +89,10 @@ */ PACKAGE, + /** The tag of all module "types". + */ + MODULE, + /** The tag of all (source-level) type variables. */ TYPEVAR,
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java Thu Mar 24 16:21:21 2016 +0100 @@ -3939,7 +3939,7 @@ * Return the class that boxes the given primitive. */ public ClassSymbol boxedClass(Type t) { - return syms.enterClass(syms.boxedName[t.getTag().ordinal()]); + return syms.enterClass(syms.java_base, syms.boxedName[t.getTag().ordinal()]); } /** @@ -3958,7 +3958,7 @@ for (int i=0; i<syms.boxedName.length; i++) { Name box = syms.boxedName[i]; if (box != null && - asSuper(t, syms.enterClass(box)) != null) + asSuper(t, syms.enterClass(syms.java_base, box)) != null) return syms.typeOfTag[i]; } return Type.noType; @@ -4537,6 +4537,7 @@ public R visitArrayType(ArrayType t, S s) { return visitType(t, s); } public R visitMethodType(MethodType t, S s) { return visitType(t, s); } public R visitPackageType(PackageType t, S s) { return visitType(t, s); } + public R visitModuleType(ModuleType t, S s) { return visitType(t, s); } public R visitTypeVar(TypeVar t, S s) { return visitType(t, s); } public R visitCapturedType(CapturedType t, S s) { return visitType(t, s); } public R visitForAll(ForAll t, S s) { return visitType(t, s); }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Thu Mar 24 16:21:21 2016 +0100 @@ -36,6 +36,7 @@ import com.sun.source.tree.TreeVisitor; import com.sun.source.util.SimpleTreeVisitor; import com.sun.tools.javac.code.*; +import com.sun.tools.javac.code.Directive.RequiresFlag; import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.code.Scope.WriteableScope; import com.sun.tools.javac.code.Symbol.*; @@ -60,6 +61,7 @@ import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.Fragment; import com.sun.tools.javac.util.List; + import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.ANNOTATION; import static com.sun.tools.javac.code.Flags.BLOCK; @@ -332,7 +334,15 @@ syms.errSymbol.name, null, null, null, null); localEnv.enclClass.sym = syms.errSymbol; - return tree.accept(identAttributer, localEnv); + return attribIdent(tree, localEnv); + } + + /** Attribute a parsed identifier. + * @param tree Parsed identifier name + * @param env The env to use + */ + public Symbol attribIdent(JCTree tree, Env<AttrContext> env) { + return tree.accept(identAttributer, env); } // where private TreeVisitor<Symbol,Env<AttrContext>> identAttributer = new IdentAttributer(); @@ -4238,13 +4248,19 @@ } /** - * Attribute an env for either a top level tree or class declaration. + * Attribute an env for either a top level tree or class or module declaration. */ public void attrib(Env<AttrContext> env) { - if (env.tree.hasTag(TOPLEVEL)) - attribTopLevel(env); - else - attribClass(env.tree.pos(), env.enclClass.sym); + switch (env.tree.getTag()) { + case MODULEDEF: + attribModule(env.tree.pos(), ((JCModuleDecl)env.tree).sym); + break; + case TOPLEVEL: + attribTopLevel(env); + break; + default: + attribClass(env.tree.pos(), env.enclClass.sym); + } } /** @@ -4260,6 +4276,21 @@ } } + public void attribModule(DiagnosticPosition pos, ModuleSymbol m) { + try { + annotate.flush(); + attribModule(m); + } catch (CompletionFailure ex) { + chk.completionError(pos, ex); + } + } + + void attribModule(ModuleSymbol m) { + // Get environment current at the point of module definition. + Env<AttrContext> env = enter.typeEnvs.get(m); + attribStat(env.tree, env); + } + /** Main method: attribute class definition associated with given class symbol. * reporting completion failures at the given position. * @param pos The source position at which completion errors are to be @@ -4358,6 +4389,10 @@ // nothing to do } + public void visitModuleDef(JCModuleDecl tree) { + tree.sym.completeUsesProvides(); + } + /** Finish the attribution of a class. */ private void attribClassBody(Env<AttrContext> env, ClassSymbol c) { JCClassDecl tree = (JCClassDecl)env.tree; @@ -4929,4 +4964,22 @@ } } // </editor-fold> + + public void setPackageSymbols(JCExpression pid, Symbol pkg) { + new TreeScanner() { + Symbol packge = pkg; + @Override + public void visitIdent(JCIdent that) { + that.sym = packge; + } + + @Override + public void visitSelect(JCFieldAccess that) { + that.sym = packge; + packge = packge.owner; + super.visitSelect(that); + } + }.scan(pid); + } + }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Thu Mar 24 16:21:21 2016 +0100 @@ -173,10 +173,10 @@ */ char syntheticNameChar; - /** A table mapping flat names of all compiled classes in this run to their - * symbols; maintained from outside. + /** A table mapping flat names of all compiled classes for each module in this run + * to their symbols; maintained from outside. */ - public Map<Name,ClassSymbol> compiled = new HashMap<>(); + private Map<Pair<ModuleSymbol, Name>,ClassSymbol> compiled = new HashMap<>(); /** A handler for messages about deprecated usage. */ @@ -404,7 +404,7 @@ for (int i = (index == null) ? 1 : index; ; i++) { Name flatname = names.fromString(enclFlatnameStr + syntheticNameChar + i + c.name); - if (compiled.get(flatname) == null) { + if (getCompiled(c.packge().modle, flatname) == null) { localClassNameIndexes.put(key, i + 1); return flatname; } @@ -421,6 +421,22 @@ localClassNameIndexes.clear(); } + public void putCompiled(ClassSymbol csym) { + compiled.put(Pair.of(csym.packge().modle, csym.flatname), csym); + } + + public ClassSymbol getCompiled(ClassSymbol csym) { + return compiled.get(Pair.of(csym.packge().modle, csym.flatname)); + } + + public ClassSymbol getCompiled(ModuleSymbol msym, Name flatname) { + return compiled.get(Pair.of(msym, flatname)); + } + + public void removeCompiled(ClassSymbol csym) { + compiled.remove(Pair.of(csym.packge().modle, csym.flatname)); + } + /* ************************************************************************* * Type Checking **************************************************************************/ @@ -3473,7 +3489,7 @@ private boolean isCanonical(JCTree tree) { while (tree.hasTag(SELECT)) { JCFieldAccess s = (JCFieldAccess) tree; - if (s.sym.owner != TreeInfo.symbol(s.selected)) + if (s.sym.owner.name != TreeInfo.symbol(s.selected).name) return false; tree = s.selected; } @@ -3576,9 +3592,19 @@ // Check that packages imported are in scope (JLS 7.4.3, 6.3, 6.5.3.1, 6.5.3.2) public void checkImportedPackagesObservable(final JCCompilationUnit toplevel) { - for (JCImport imp : toplevel.getImports()) { + OUTER: for (JCImport imp : toplevel.getImports()) { if (!imp.staticImport && TreeInfo.name(imp.qualid) == names.asterisk) { TypeSymbol tsym = ((JCFieldAccess)imp.qualid).selected.type.tsym; + if (toplevel.modle.visiblePackages != null) { + //TODO - unclear: selects like javax.* will get resolved from the current module + //(as javax is not an exported package from any module). And as javax in the current + //module typically does not contain any classes or subpackages, we need to go through + //the visible packages to find a sub-package: + for (PackageSymbol known : toplevel.modle.visiblePackages.values()) { + if (Convert.packagePart(known.fullname) == tsym.flatName()) + continue OUTER; + } + } if (tsym.kind == PCK && tsym.members().isEmpty() && !tsym.exists()) { log.error(DiagnosticFlag.RESOLVE_ERROR, imp.pos, "doesnt.exist", tsym); }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Thu Mar 24 16:21:21 2016 +0100 @@ -452,17 +452,21 @@ Log.DeferredDiagnosticHandler deferredDiagnosticHandler = diagHandlerCreator.apply(newTree); try { attr.attribTree(newTree, speculativeEnv, resultInfo); - unenterScanner.scan(newTree); return newTree; } finally { - unenterScanner.scan(newTree); + new UnenterScanner(env.toplevel.modle).scan(newTree); log.popDiagnosticHandler(deferredDiagnosticHandler); } } //where - protected UnenterScanner unenterScanner = new UnenterScanner(); class UnenterScanner extends TreeScanner { + private final ModuleSymbol msym; + + public UnenterScanner(ModuleSymbol msym) { + this.msym = msym; + } + @Override public void visitClassDef(JCClassDecl tree) { ClassSymbol csym = tree.sym; @@ -471,9 +475,9 @@ //are left unchecked - in such cases there's nothing to clean up. if (csym == null) return; typeEnvs.remove(csym); - chk.compiled.remove(csym.flatname); + chk.removeCompiled(csym); chk.clearLocalClassNameIndexes(csym); - syms.classes.remove(csym.flatname); + syms.removeClass(msym, csym.flatname); super.visitClassDef(tree); } }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Thu Mar 24 11:21:37 2016 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java Thu Mar 24 16:21:21 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2016, 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 @@ -25,6 +25,9 @@ package com.sun.tools.javac.comp; +import java.util.Map; +import java.util.Optional; + import javax.tools.JavaFileObject; import javax.tools.JavaFileManager; @@ -34,13 +37,13 @@ import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.main.Option.PkgInfo; +import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.List; - import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Kinds.Kind.*; @@ -97,6 +100,8 @@ JavaFileManager fileManager; PkgInfo pkginfoOpt; TypeEnvs typeEnvs; + Modules modules; + JCDiagnostic.Factory diags; private final Todo todo; @@ -119,6 +124,8 @@ annotate = Annotate.instance(context); lint = Lint.instance(context); names = Names.instance(context); + modules = Modules.instance(context); + diags = JCDiagnostic.Factory.instance(context); predefClassDef = make.ClassDef( make.Modifiers(PUBLIC), @@ -229,6 +236,24 @@ : env.info.scope; } + /** Create a fresh environment for modules. + * + * @param tree The module definition. + * @param env The environment current outside of the module definition. + */ + public Env<AttrContext> moduleEnv(JCModuleDecl tree, Env<AttrContext> env) { + Assert.checkNonNull(tree.sym); + Env<AttrContext> localEnv = + env.dup(tree, env.info.dup(WriteableScope.create(tree.sym))); + localEnv.enclClass = predefClassDef; + localEnv.outer = env; + localEnv.info.isSelfCall = false; + localEnv.info.lint = null; // leave this to be filled in by Attr, + // when annotations have been processed + return localEnv; + } + + /* ************************************************************************ * Visitor methods for phase 1: class enter *************************************************************************/ @@ -276,57 +301,80 @@ @Override public void visitTopLevel(JCCompilationUnit tree) { +// Assert.checkNonNull(tree.modle, tree.sourcefile.toString()); + JavaFileObject prev = log.useSource(tree.sourcefile); boolean addEnv = false; boolean isPkgInfo = tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE); - JCPackageDecl pd = tree.getPackage(); - if (pd != null) { - tree.packge = pd.packge = syms.enterPackage(TreeInfo.fullName(pd.pid)); - if ( pd.annotations.nonEmpty() - || pkginfoOpt == PkgInfo.ALWAYS - || tree.docComments != null) { - if (isPkgInfo) { - addEnv = true; - } else if (pd.annotations.nonEmpty()) { - log.error(pd.annotations.head.pos(), - "pkg.annotations.sb.in.package-info.java"); + if (TreeInfo.isModuleInfo(tree)) { + tree.packge = syms.rootPackage; + Env<AttrContext> topEnv = topLevelEnv(tree); + classEnter(tree.defs, topEnv); + tree.modle.usesProvidesCompleter = modules.getUsesProvidesCompleter(); + } else { + JCPackageDecl pd = tree.getPackage(); + if (pd != null) { + tree.packge = pd.packge = syms.enterPackage(tree.modle, TreeInfo.fullName(pd.pid)); + if ( pd.annotations.nonEmpty() + || pkginfoOpt == PkgInfo.ALWAYS + || tree.docComments != null) { + if (isPkgInfo) { + addEnv = true; + } else if (pd.annotations.nonEmpty()) { + log.error(pd.annotations.head.pos(), + "pkg.annotations.sb.in.package-info.java"); + } }