Mercurial > hg > openjdk > aarch64-port > langtools
changeset 1722:9afeb870a2c1 preview_rc1
Merge up to jdk8-b90
author | Edward Nevill edward.nevill@linaro.org |
---|---|
date | Fri, 27 Sep 2013 15:41:28 +0100 |
parents | 410cc10bc125 (current diff) e19283cd30a4 (diff) |
children | 06c775aa7bb2 |
files | .hgtags make/Makefile-classic src/share/classes/com/sun/tools/javac/util/CloseableURLClassLoader.java test/tools/javac/diags/examples/SecondaryBoundMustBeMarkerIntf.java test/tools/javac/lambda/Intersection01.out test/tools/javac/lambda/TargetType01.out |
diffstat | 132 files changed, 5003 insertions(+), 1293 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Tue Aug 13 17:04:51 2013 +0100 +++ b/.hgtags Fri Sep 27 15:41:28 2013 +0100 @@ -208,3 +208,8 @@ 22ba3f92d4ae43bbc19793e854171cae2586f644 jdk8-b83 cfb65ca92082b2412aed66c8422c2466bde544ef jdk8-b84 90a26666a077469d5bcbd0cd38b365a7bf6c57d6 aarch64-20130813 +4a48f31735349782ad13980267358c97076adc66 jdk8-b85 +6ab578e141dfd17c4dc03869bb204aafa490c9f4 jdk8-b86 +1329f9c38d93c8caf339d7687df8371d06fe9e56 jdk8-b87 +a1e10f3adc47c8602a72e43a41403a642e73e0b1 jdk8-b88 +ec434cfd2752a7742c875c2fe7d556d8b81c0f3a jdk8-b89
--- a/make/Makefile-classic Tue Aug 13 17:04:51 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,396 +0,0 @@ -# -# Copyright (c) 2007, 2012, 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. -# - -# -# Makefile for building the langtools workspace. -# - -# -# On Solaris, the standard 'make' utility will not work with these makefiles. -# This little rule is only understood by Solaris make, and is harmless -# when seen by the GNU make tool. If using Solaris make, this causes the -# make command to fail. -# -SUN_MAKE_TEST:sh = @echo "ERROR: PLEASE USE GNU VERSION OF MAKE"; exit 33 - -#----- cancel implicit rules - -%: %.o -%: %.obj -%: %.dll -%: %.c -%: %.cc -%: %.C -%: %.p -%: %.f -%: %.s -%: %.F -%: %.r -%: %.S -%: %.mod -%: %.sh -%: %,v -%: RCS/%,v - -#----- imports - -ifdef ALT_BOOT_JAVA_HOME - BOOT_JAVA_HOME = $(ALT_BOOT_JAVA_HOME) -else - ifdef ALT_BOOTDIR - BOOT_JAVA_HOME = $(ALT_BOOTDIR) - else - BOOT_JAVA_HOME=/java/re/jdk/1.5.0/archive/fcs/binaries/solaris-sparc - endif -endif - -BOOT_JAVA=$(BOOT_JAVA_HOME)/bin/java -BOOT_JAVAC=$(BOOT_JAVA_HOME)/bin/javac -BOOTJAR=$(BOOT_JAVA_HOME)/bin/jar - -ifdef ALT_TESTJAVA_HOME - TESTJAVA_HOME = $(ALT_TESTJAVA_HOME) -else - TESTJAVA_HOME=/java/re/jdk/1.6.0/archive/fcs/binaries/solaris-sparc -endif - -TESTJAVA=$(TESTJAVA_HOME)/bin/java - -ifdef ALT_FINDBUGS_HOME - FINDBUGS_HOME = $(ALT_FINDBUGS_HOME) -else - FINDBUGS_HOME = /java/devtools/share/findbugs/1.1.2-rc4 -endif - -FINDBUGS = $(FINDBUGS_HOME)/bin/findbugs - -#----- commands - -CHMOD = chmod -CP = cp -ECHO = echo # FIXME -FIND = find -MKDIR = mkdir -SED = sed -ZIP = zip - -#----- locations and deliverables - -TOPDIR = .. -SRC_BIN_DIR = $(TOPDIR)/src/share/bin -SRC_CLASSES_DIR = $(TOPDIR)/src/share/classes - -BUILD_DIR = $(TOPDIR)/build - -CLASSES_DIR = $(BUILD_DIR)/classes -GENSRC_DIR = $(BUILD_DIR)/gensrc - -DIST_DIR = $(TOPDIR)/dist -BIN_DIR = $(DIST_DIR)/bin -LIB_DIR = $(DIST_DIR)/lib - -JAVAC_JAR = $(LIB_DIR)/javac.jar -JAVADOC_JAR = $(LIB_DIR)/javadoc.jar -JAVAH_JAR = $(LIB_DIR)/javah.jar -JAVAP_JAR = $(LIB_DIR)/javap.jar - -CLASSES_JAR = $(DIST_DIR)/classes.jar -SRC_ZIP = $(DIST_DIR)/src.zip - -BUILDTOOLSRC_DIR = tools -BUILDTOOLCLASSES_DIR = $(BUILD_DIR)/toolclasses - -#----- - -ifndef JDK_MAJOR_VERSION - JDK_MAJOR_VERSION = 1 -endif - -ifndef JDK_MINOR_VERSION - JDK_MINOR_VERSION = 7 -endif - -ifndef JDK_MICRO_VERSION - JDK_MICRO_VERSION = 0 -endif - -ifndef JDK_VERSION - JDK_VERSION = $(JDK_MAJOR_VERSION).$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION) -endif - -ifndef MILESTONE - MILESTONE = internal -endif - -# RELEASE is JDK_VERSION and -MILESTONE if MILESTONE is set -ifneq ($(MILESTONE),fcs) - RELEASE = $(JDK_VERSION)-$(MILESTONE)$(BUILD_VARIANT_RELEASE) -else - RELEASE = $(JDK_VERSION)$(BUILD_VARIANT_RELEASE) -endif - -# FULL_VERSION is RELEASE and -BUILD_NUMBER if BUILD_NUMBER is set -ifdef BUILD_NUMBER - FULL_VERSION = $(RELEASE)-$(BUILD_NUMBER) -else - BUILD_NUMBER = b00 - USER_RELEASE_SUFFIX := $(shell echo $(USER)_`date '+%d_%b_%Y_%H_%M' | tr "A-Z" "a-z"`) - FULL_VERSION = $(RELEASE)-$(USER_RELEASE_SUFFIX)-$(BUILD_NUMBER) -endif - -#----- useful macros - -TOOLS = javac javadoc javah javap - -SOURCE_LEVEL = 5 -BOOTSTRAP_TARGET_LEVEL = 5 -TARGET_LEVEL = 6 - -ifndef TARGET_JAVA - TARGET_JAVA = java -endif - -NO_PROPRIETARY_API_WARNINGS = -XDignore.symbol.file=true - -SELF = $(lastword $(MAKEFILE_LIST)) - -#----- - -# the default is to generate the following: -# dist/{bin,lib}: -# lang tools compiled to run on the target JDK - -default: - $(MAKE) -f $(SELF) \ - MILESTONE=bootstrap \ - TARGET_LEVEL=$(BOOTSTRAP_TARGET_LEVEL) \ - TARGET_JAVA=$(BOOT_JAVA_HOME)/bin/java \ - GENSRC_DIR=$(BUILD_DIR)/bootstrap/gensrc \ - CLASSES_DIR=$(BUILD_DIR)/bootstrap/classes \ - BIN_DIR=$(BUILD_DIR)/bootstrap/bin \ - LIB_DIR=$(BUILD_DIR)/bootstrap/lib \ - $(BUILD_DIR)/bootstrap/lib/javac.jar \ - $(BUILD_DIR)/bootstrap/bin/javac - $(MAKE) -f $(SELF) \ - BOOT_JAVAC=$(BUILD_DIR)/bootstrap/bin/javac \ - tools - -# for jdk, we generate the following: -# dist/bootstrap/{bin,lib}: -# lang tools compiled to run on the boot JDK -# dist/lib/classes.jar: -# lang tools recompiled to run on the target JDK, -# ready for inclusion in rt.jar and tools.jar -# dist/lib/src.zip -# .properties and .java files for classes in classes.jar, -# ready for jdk src.zip - -jdk: - $(MAKE) -f $(SELF) \ - MILESTONE=bootstrap \ - TARGET_LEVEL=$(BOOTSTRAP_TARGET_LEVEL) \ - TARGET_JAVA=$(BOOT_JAVA_HOME)/bin/java \ - GENSRC_DIR=$(BUILD_DIR)/bootstrap/gensrc \ - CLASSES_DIR=$(BUILD_DIR)/bootstrap/classes \ - BIN_DIR=$(DIST_DIR)/bootstrap/bin \ - LIB_DIR=$(DIST_DIR)/bootstrap/lib \ - tools - $(MAKE) -f $(SELF) \ - BOOT_JAVAC=$(DIST_DIR)/bootstrap/bin/javac \ - LIB_DIR=$(BUILD_DIR)/jdk/lib \ - $(DIST_DIR)/lib/classes.jar \ - $(DIST_DIR)/lib/src.zip - -tools: $(TOOLS:%=$(LIB_DIR)/%.jar) $(TOOLS:%=$(BIN_DIR)/%) - -clean: - $(RM) -r $(BUILD_DIR) - -really-clean: clean - $(RM) -r $(DIST_DIR) - -jprt_product_build \ -jprt_debug_build \ -jprt_fastdebug_build: lib - -#----- javac - -JAVAC_DIRS = \ - javax/annotation/processing \ - javax/lang/model \ - javax/tools \ - jdk/ \ - com/sun/source \ - com/sun/tools/javac - -JAVAC_RESOURCE_FILES = \ - $(shell find $(patsubst %,$(SRC_CLASSES_DIR)/%,$(JAVAC_DIRS)) -name SCCS -prune -o -name \*.properties -print ) - -JAVAC_JAVA_FILES = \ - $(shell find $(patsubst %,$(SRC_CLASSES_DIR)/%,$(JAVAC_DIRS)) -name SCCS -prune -o -name \*.java -print ) \ - $(patsubst $(SRC_CLASSES_DIR)/%.properties,$(GENSRC_DIR)/%.java,$(JAVAC_RESOURCE_FILES)) \ - $(GENSRC_DIR)/com/sun/tools/javac/resources/version.java - -$(JAVAC_JAR): $(JAVAC_JAVA_FILES) - $(MKDIR) -p $(CLASSES_DIR) $(@D) - $(BOOT_JAVAC) -d $(CLASSES_DIR) -target $(TARGET_LEVEL) $(NO_PROPRIETARY_API_WARNINGS) $(JAVAC_JAVA_FILES) - ( $(ECHO) Main-Class: com.sun.tools.javac.Main ) > $(BUILD_DIR)/javac.mf - $(BOOTJAR) -cfm $@ $(BUILD_DIR)/javac.mf $(patsubst %,-C $(CLASSES_DIR) %, $(JAVAC_DIRS)) - -#----- javadoc - -### FIXME -- javadoc has a couple of extra non-property resource files -### that need to be included - -JAVADOC_DIRS = \ - com/sun/javadoc \ - com/sun/tools/doclets \ - com/sun/tools/javadoc - -JAVADOC_RESOURCE_FILES = \ - $(shell find $(patsubst %,$(SRC_CLASSES_DIR)/%,$(JAVADOC_DIRS)) -name SCCS -prune -o -name \*.properties -print ) - -JAVADOC_JAVA_FILES = \ - $(shell find $(patsubst %,$(SRC_CLASSES_DIR)/%,$(JAVADOC_DIRS)) -name SCCS -prune -o -name \*.java -print ) \ - $(patsubst $(SRC_CLASSES_DIR)/%.properties,$(GENSRC_DIR)/%.java,$(JAVADOC_RESOURCE_FILES)) - -$(JAVADOC_JAR): $(JAVADOC_JAVA_FILES) $(JAVAC_JAR) - $(MKDIR) -p $(CLASSES_DIR) $(@D) - $(BOOT_JAVAC) -sourcepath "" -classpath $(JAVAC_JAR) -d $(CLASSES_DIR) -target $(TARGET_LEVEL) $(JAVADOC_JAVA_FILES) - ( $(ECHO) Main-Class: com.sun.tools.javadoc.Main ; $(ECHO) Class-Path: javac.jar ) > $(BUILD_DIR)/javadoc.mf - $(BOOTJAR) -cfm $@ $(BUILD_DIR)/javadoc.mf $(patsubst %,-C $(CLASSES_DIR) %, $(JAVADOC_DIRS)) - -#----- javah - -JAVAH_DIRS = \ - com/sun/tools/javah - -JAVAH_RESOURCE_FILES = \ - $(shell find $(patsubst %,$(SRC_CLASSES_DIR)/%,$(JAVAH_DIRS)) -name SCCS -prune -o -name \*.properties -print ) - -JAVAH_JAVA_FILES = \ - $(shell find $(patsubst %,$(SRC_CLASSES_DIR)/%,$(JAVAH_DIRS)) -name SCCS -prune -o -name \*.java -print ) \ - $(patsubst $(SRC_CLASSES_DIR)/%.properties,$(GENSRC_DIR)/%.java,$(JAVAH_RESOURCE_FILES)) - -$(JAVAH_JAR): $(JAVAH_JAVA_FILES) $(JAVADOC_JAR) - $(MKDIR) -p $(CLASSES_DIR) $(@D) - $(BOOT_JAVAC) -sourcepath "" -classpath $(CLASSES_DIR) -d $(CLASSES_DIR) -target $(TARGET_LEVEL) $(JAVAH_JAVA_FILES) - ( $(ECHO) Main-Class: com.sun.tools.javah.Main ; $(ECHO) Class-Path: javadoc.jar ) > $(BUILD_DIR)/javah.mf - $(BOOTJAR) -cfm $@ $(BUILD_DIR)/javah.mf $(patsubst %,-C $(CLASSES_DIR) %, $(JAVAH_DIRS)) - -#----- javap - -JAVAP_DIRS = \ - sun/tools/javap - -JAVAP_RESOURCE_FILES = \ - $(shell find $(patsubst %,$(SRC_CLASSES_DIR)/%,$(JAVAP_DIRS)) -name SCCS -prune -o -name \*.properties -print ) - -JAVAP_JAVA_FILES = \ - $(shell find $(patsubst %,$(SRC_CLASSES_DIR)/%,$(JAVAP_DIRS)) -name SCCS -prune -o -name \*.java -print ) \ - $(patsubst $(SRC_CLASSES_DIR)/%.properties,$(GENSRC_DIR)/%.java,$(JAVAP_RESOURCE_FILES)) - -$(JAVAP_JAR): $(JAVAP_JAVA_FILES) \ - $(patsubst $(SRC_CLASSES_DIR)/%.properties,$(GENSRC_DIR)/%.java,$(JAVAP_RESOURCE_FILES)) - $(MKDIR) -p $(CLASSES_DIR) - $(BOOT_JAVAC) -sourcepath "" -classpath $(CLASSES_DIR) -d $(CLASSES_DIR) -target $(TARGET_LEVEL) $(JAVAP_JAVA_FILES) - ( $(ECHO) Main-Class: sun.tools.javap.Main ) > $(BUILD_DIR)/javap.mf - $(BOOTJAR) -cfm $@ $(BUILD_DIR)/javap.mf $(patsubst %,-C $(CLASSES_DIR) %, $(JAVAP_DIRS)) - -#----- - -build-tools: $(BUILDTOOLCLASSES_DIR)/CompileProperties/CompileProperties.class - -$(GENSRC_DIR)/%.java: $(SRC_CLASSES_DIR)/%.properties $(BUILDTOOLCLASSES_DIR)/CompileProperties/CompileProperties.class - $(MKDIR) -p $(@D) - $(BOOT_JAVA) -cp $(BUILDTOOLCLASSES_DIR)/CompileProperties CompileProperties $< $(patsubst $(CLASSES_DIR)/%.class,$(GENSRC_DIR)/%.java,$@) - -$(GENSRC_DIR)/%.java: $(GENSRC_DIR)/%.properties $(BUILDTOOLCLASSES_DIR)/CompileProperties/CompileProperties.class - $(MKDIR) -p $(@D) - $(BOOT_JAVA) -cp $(BUILDTOOLCLASSES_DIR)/CompileProperties CompileProperties $< $(patsubst $(CLASSES_DIR)/%.class,$(GENSRC_DIR)/%.java,$@) - -$(GENSRC_DIR)/%.properties: $(SRC_CLASSES_DIR)/%.properties-template - $(MKDIR) -p $(@D) - $(SED) -e 's/$$(JDK_VERSION)/$(JDK_VERSION)/' \ - -e 's/$$(FULL_VERSION)/$(FULL_VERSION)/' \ - -e 's/$$(RELEASE)/$(RELEASE)/' \ - < $< > $@ - -$(BUILDTOOLCLASSES_DIR)/%.class : $(BUILDTOOLSRC_DIR)/%.java - $(MKDIR) -p $(@D) - $(BOOT_JAVAC) -d $(@D) $< - -#----- all classes - -$(DIST_DIR)/%/classes.jar: $(JAVAC_JAR) $(JAVADOC_JAR) $(JAVAH_JAR) $(JAVAP_JAR) - $(MKDIR) -p $(@D) - $(BOOTJAR) -cf $@ -C $(CLASSES_DIR) . - -#----- src.zip - -SRC_ZIP_FILES = $(shell $(FIND) $(SRC_CLASSES_DIR) \( -name SCCS -o -name \*-template \) -prune -o -type f -print ) - -$(DIST_DIR)/%/src.zip: $(SRC_ZIP_FILES) - abs_src_zip=`cd $(@D) ; pwd`/$(@F) ; \ - ( cd $(SRC_CLASSES_DIR) ; $(FIND) . \( -name SCCS -o -name \*-template \) -prune -o -type f -print | $(ZIP) -q $$abs_src_zip -@ ) ; \ - ( cd $(SRC_CLASSES_DIR) ; $(FIND) . -name SCCS -prune -o -name \*-template -print | $(SED) -e 's/-template//' ) | ( cd $(GENSRC_DIR) ; $(ZIP) -q $$abs_src_zip -@ ) - -#----- bin files - -$(BIN_DIR)/%: $(SRC_BIN_DIR)/launcher.sh-template - $(MKDIR) -p $(@D) - $(SED) -e 's|#PROGRAM#|$(@F)|' -e 's|#TARGET_JAVA#|$(TARGET_JAVA)|' $< > $@ - $(CHMOD) +x $@ - -#----- - -findbugs: $(BUILD_DIR)/findbugs.txt - -$(BUILD_DIR)/findbugs.txt: $(CLASSES_JAR) - $(MKDIR) -p $(@D) - $(FINDBUGS) -textui -javahome $(BOOT_JAVA_HOME) -high -emacs -outputFile $@ $< - -#----- - -quick-check: $(patsubst %, $(DIST_LIB_DIR)/%.jar, $(TOOLS)) - $(TESTJAVA) -jar $(JAVAC_JAR) -version - - $(TESTJAVA) -jar $(JAVADOC_JAR) -version - $(TESTJAVA) -jar $(JAVAH_JAR) -version - - $(TESTJAVA) -jar $(JAVAP_JAR) -version - -#----- - -.PHONY: \ - all \ - build \ - build-tools \ - clean \ - default \ - findbugs \ - jprt_product_build \ - jprt_debug_build \ - jprt_fastdebug_build \ - tools -
--- a/make/build.xml Tue Aug 13 17:04:51 2013 +0100 +++ b/make/build.xml Fri Sep 27 15:41:28 2013 +0100 @@ -717,6 +717,29 @@ <target name="sjavac" depends="build-sjavac,jtreg-sjavac,findbugs-sjavac"/> <!-- + **** crules targets. + --> + + <target name="build-crules" depends="-def-compilecrules,-def-build-jar-with-services"> + <compilecrules/> + <build-jar-with-services + name="crules" + includes="crules/* crules/resources/*" + classes.dir="${build.toolclasses.dir}" + lib.dir="${build.toolclasses.dir}" + jarmainclass="" + jarclasspath="crules.jar" + service.type="com.sun.source.util.Plugin" + service.provider="crules.MutableFieldsAnalyzer"/> + <build-tool name="crules"/> + </target> + + <target name="check-coding-rules" depends="build-bootstrap-javac,-create-import-jdk-stubs,build-crules"> + <build-classes includes="${javac.includes}" + plugin.options="-J-Xbootclasspath/a:${build.toolclasses.dir}/crules.jar -Xplugin:mutable_fields_analyzer" /> + </target> + + <!-- **** Create import JDK stubs. --> @@ -811,6 +834,31 @@ </macrodef> </target> + <target name="-def-build-jar-with-services"> + <macrodef name="build-jar-with-services"> + <attribute name="name"/> + <attribute name="includes"/> + <attribute name="classes.dir" default="${build.classes.dir}"/> + <attribute name="lib.dir" default="${dist.lib.dir}"/> + <attribute name="jarmainclass" default="com.sun.tools.@{name}.Main"/> + <attribute name="jarclasspath" default=""/> + <attribute name="service.type" default=""/> + <attribute name="service.provider" default=""/> + <sequential> + <mkdir dir="${build.toolclasses.dir}"/> + <jar destfile="@{lib.dir}/@{name}.jar" + basedir="@{classes.dir}" + includes="@{includes}"> + <service type="@{service.type}" provider="@{service.provider}"/> + <manifest> + <attribute name="Main-Class" value="@{jarmainclass}"/> + <attribute name="Class-Path" value="@{jarclasspath}"/> + </manifest> + </jar> + </sequential> + </macrodef> + </target> + <target name="-def-build-classes" depends="-def-pcompile"> <macrodef name="build-classes"> <attribute name="includes"/> @@ -826,6 +874,7 @@ <attribute name="target" default="${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: bootclasspath.opt=@{bootclasspath.opt}"/> @@ -868,6 +917,7 @@ <compilerarg line="${javac.no.jdk.warnings}"/> <compilerarg line="${javac.version.opt}"/> <compilerarg line="${javac.lint.opts}"/> + <compilerarg line="@{plugin.options}"/> </javac> <copy todir="@{classes.dir}" includeemptydirs="false"> <fileset dir="${src.classes.dir}" includes="@{includes}" excludes="@{excludes}"> @@ -935,6 +985,32 @@ classpath="${build.toolclasses.dir}/"/> </target> + <target name="-def-compilecrules"> + <macrodef name="compilecrules"> + <sequential> + <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="crules/*" + destdir="${build.toolclasses.dir}/" + classpath="${ant.core.lib}" + bootclasspath="${boot.java.home}/jre/lib/rt.jar" + includeantruntime="false"> + <compilerarg value="-Xbootclasspath/p:${build.bootstrap.dir}/classes"/> + <compilerarg line="${javac.lint.opts}"/> + </javac> + <copy todir="${build.toolclasses.dir}/" includeemptydirs="false"> + <fileset dir="${make.tools.dir}"> + <include name="**/*.properties"/> + </fileset> + </copy> + </sequential> + </macrodef> + </target> + <target name="-def-genstubs" depends="build-bootstrap-javac" if="require.import.jdk.stubs"> <mkdir dir="${build.toolclasses.dir}"/> <javac fork="true"
--- a/make/netbeans/langtools/nbproject/project.xml Tue Aug 13 17:04:51 2013 +0100 +++ b/make/netbeans/langtools/nbproject/project.xml Fri Sep 27 15:41:28 2013 +0100 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2007, 2013, 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 @@ -67,7 +67,7 @@ </folders> <ide-actions> <!-- - Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2007, 2013, 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 @@ -96,7 +96,7 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> - <!-- + <!-- This file defines the standard actions accepted by langtools projects. It is normally included as an entity into a project's project.xml file. @@ -104,7 +104,7 @@ - NetBeans: Setting Up Projects at http://www.netbeans.org/kb/55/using-netbeans/project_setup.html - NetBeans: Advanced Freeform Project Configuration - at http://www.netbeans.org/kb/41/freeform-config.html + at http://www.netbeans.org/kb/41/freeform-config.html --> <action name="build"> <target>build</target> @@ -144,7 +144,7 @@ </arity> </context> </action> - <!-- + <!-- Note: NetBeans does not appear to support context menu items on shell scripts :-( --> @@ -178,7 +178,7 @@ </arity> </context> </action> - <!-- + <!-- Note: NetBeans does not appear to support context menu items on shell scripts :-( --> @@ -239,10 +239,6 @@ <label>Build files</label> <location>${root}/make</location> </source-folder> - <source-folder style="packages"> - <label>Source files</label> - <location>${root}/src/share/classes</location> - </source-folder> <source-file> <label>README</label> <location>README</location> @@ -250,7 +246,7 @@ </items> <context-menu> <!-- - Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2007, 2013, 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 @@ -279,7 +275,7 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> - <!-- + <!-- This file defines the actions that will appear on the project's context menu, in the Projects viewer. It is normally included as an entity into a project's project.xml file. @@ -288,7 +284,7 @@ - NetBeans: Setting Up Projects at http://www.netbeans.org/kb/55/using-netbeans/project_setup.html - NetBeans: Advanced Freeform Project Configuration - at http://www.netbeans.org/kb/41/freeform-config.html + at http://www.netbeans.org/kb/41/freeform-config.html --> <ide-action name="select-tool"/> <separator/> @@ -305,11 +301,11 @@ </view> <subprojects/> </general-data> - <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/2"> + <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/3"> <compilation-unit> <package-root>${root}/src/share/classes</package-root> <built-to>${root}/build/classes</built-to> - <source-level>1.5</source-level> + <source-level>1.7</source-level> </compilation-unit> </java-data> </configuration>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/tools/crules/AbstractCodingRulesAnalyzer.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package crules; + +import java.text.MessageFormat; +import java.util.Locale; +import java.util.ResourceBundle; + +import javax.lang.model.element.TypeElement; +import javax.tools.JavaFileObject; + +import com.sun.source.tree.Tree; +import com.sun.source.util.JavacTask; +import com.sun.source.util.Plugin; +import com.sun.source.util.TaskEvent; +import com.sun.source.util.TaskListener; +import com.sun.source.util.Trees; +import com.sun.tools.javac.api.BasicJavacTask; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.TreeScanner; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.Log; + +import static com.sun.source.util.TaskEvent.Kind; + +public abstract class AbstractCodingRulesAnalyzer implements Plugin { + + protected Log log; + protected Trees trees; + protected TreeScanner treeVisitor; + protected Kind eventKind; + protected Messages messages; + + public void init(JavacTask task, String... args) { + BasicJavacTask impl = (BasicJavacTask)task; + Context context = impl.getContext(); + log = Log.instance(context); + trees = Trees.instance(task); + messages = new Messages(); + task.addTaskListener(new PostAnalyzeTaskListener()); + } + + public class PostAnalyzeTaskListener implements TaskListener { + + @Override + public void started(TaskEvent taskEvent) {} + + @Override + public void finished(TaskEvent taskEvent) { + if (taskEvent.getKind().equals(eventKind)) { + TypeElement typeElem = taskEvent.getTypeElement(); + Tree tree = trees.getTree(typeElem); + if (tree != null) { + JavaFileObject prevSource = log.currentSourceFile(); + try { + log.useSource(taskEvent.getCompilationUnit().getSourceFile()); + treeVisitor.scan((JCTree)tree); + } finally { + log.useSource(prevSource); + } + } + } + } + } + + class Messages { + ResourceBundle bundle; + + Messages() { + String name = getClass().getPackage().getName() + ".resources.crules"; + bundle = ResourceBundle.getBundle(name, Locale.ENGLISH); + } + + public void error(JCTree tree, String code, Object... args) { + String msg = (code == null) ? (String) args[0] : localize(code, args); + log.error(tree, "proc.messager", msg.toString()); + } + + private String localize(String code, Object... args) { + String msg = bundle.getString(code); + if (msg == null) { + StringBuilder sb = new StringBuilder(); + sb.append("message file broken: code=").append(code); + if (args.length > 0) { + sb.append(" arguments={0}"); + for (int i = 1; i < args.length; i++) { + sb.append(", {").append(i).append("}"); + } + } + msg = sb.toString(); + } + return MessageFormat.format(msg, args); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/tools/crules/MutableFieldsAnalyzer.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package crules; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.sun.tools.javac.code.Kinds; +import com.sun.tools.javac.tree.TreeScanner; + +import static com.sun.source.util.TaskEvent.Kind; +import static com.sun.tools.javac.code.Flags.*; +import static com.sun.tools.javac.tree.JCTree.JCVariableDecl; + +public class MutableFieldsAnalyzer extends AbstractCodingRulesAnalyzer { + + public MutableFieldsAnalyzer() { + treeVisitor = new MutableFieldsVisitor(); + eventKind = Kind.ANALYZE; + } + + public String getName() { + return "mutable_fields_analyzer"; + } + + private boolean ignoreField(String className, String field) { + List<String> currentFieldsToIgnore = + classFieldsToIgnoreMap.get(className); + if (currentFieldsToIgnore != null) { + for (String fieldToIgnore : currentFieldsToIgnore) { + if (field.equals(fieldToIgnore)) { + return true; + } + } + } + return false; + } + + class MutableFieldsVisitor extends TreeScanner { + + @Override + public void visitVarDef(JCVariableDecl tree) { + boolean isJavacPack = tree.sym.outermostClass().fullname.toString() + .contains(packageToCheck); + if (isJavacPack && + (tree.sym.flags() & SYNTHETIC) == 0 && + tree.sym.owner.kind == Kinds.TYP) { + if (!ignoreField(tree.sym.owner.flatName().toString(), + tree.getName().toString())) { + boolean enumClass = (tree.sym.owner.flags() & ENUM) != 0; + boolean nonFinalStaticEnumField = + (tree.sym.flags() & (ENUM | FINAL)) == 0; + boolean nonFinalStaticField = + (tree.sym.flags() & STATIC) != 0 && + (tree.sym.flags() & FINAL) == 0; + if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) { + messages.error(tree, "crules.err.var.must.be.final", tree); + } + } + } + super.visitVarDef(tree); + } + + } + + private static final String packageToCheck = "com.sun.tools.javac"; + + private static final Map<String, List<String>> classFieldsToIgnoreMap = + new HashMap<String, List<String>>(); + + static { + classFieldsToIgnoreMap. + put("com.sun.tools.javac.util.JCDiagnostic", + Arrays.asList("fragmentFormatter")); + classFieldsToIgnoreMap. + put("com.sun.tools.javac.util.JavacMessages", + Arrays.asList("defaultBundle", "defaultMessages")); + classFieldsToIgnoreMap. + put("com.sun.tools.javac.file.ZipFileIndexCache", + Arrays.asList("sharedInstance")); + classFieldsToIgnoreMap. + put("com.sun.tools.javac.main.JavaCompiler", + Arrays.asList("versionRB")); + classFieldsToIgnoreMap. + put("com.sun.tools.javac.code.Type", + Arrays.asList("moreInfo")); + classFieldsToIgnoreMap. + put("com.sun.tools.javac.util.SharedNameTable", + Arrays.asList("freelist")); + classFieldsToIgnoreMap. + put("com.sun.tools.javac.util.Log", + Arrays.asList("useRawMessages")); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/tools/crules/resources/crules.properties Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,28 @@ +# +# Copyright (c) 2013, 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. +# + +# 0: symbol +crules.err.var.must.be.final=\ + Static variable {0} must be final
--- a/src/share/classes/com/sun/javadoc/ExecutableMemberDoc.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/javadoc/ExecutableMemberDoc.java Fri Sep 27 15:41:28 2013 +0100 @@ -88,13 +88,12 @@ Parameter[] parameters(); /** - * Get the receiver annotations of this executable element. - * Return an empty array if there are none. + * Get the receiver type of this executable element. * - * @return the receiver annotations of this executable element. + * @return the receiver type of this executable element. * @since 1.8 */ - AnnotationDesc[] receiverAnnotations(); + Type receiverType(); /** * Return the throws tags in this method.
--- a/src/share/classes/com/sun/javadoc/Type.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/javadoc/Type.java Fri Sep 27 15:41:28 2013 +0100 @@ -160,4 +160,13 @@ * @since 1.5 */ AnnotationTypeDoc asAnnotationTypeDoc(); + + /** + * If this type is an array type, return the element type of the + * array. Otherwise, return null. + * + * @return a <code>Type</code> representing the element type or null. + * @since 1.8 + */ + Type getElementType(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/com/sun/source/util/DocSourcePositions.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2013, 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.util; + +import com.sun.source.doctree.DocCommentTree; +import com.sun.source.doctree.DocTree; +import com.sun.source.tree.CompilationUnitTree; + +/** + * Provides methods to obtain the position of a DocTree within a javadoc comment. + * A position is defined as a simple character offset from the start of a + * CompilationUnit where the first character is at offset 0. + * + * @since 1.8 + */ +@jdk.Supported +public interface DocSourcePositions extends SourcePositions { + + /** + * Gets the starting position of the tree within the comment within the file. If tree is not found within + * file, or if the starting position is not available, + * return {@link javax.tools.Diagnostic#NOPOS}. + * The given tree should be under the given comment tree, and the given documentation + * comment tree should be returned from a {@link DocTrees#getDocCommentTree(com.sun.source.util.TreePath) } + * for a tree under the given file. + * The returned position must be at the start of the yield of this tree, that + * is for any sub-tree of this tree, the following must hold: + * + * <p> + * {@code tree.getStartPosition() <= subtree.getStartPosition()} or <br> + * {@code tree.getStartPosition() == NOPOS} or <br> + * {@code subtree.getStartPosition() == NOPOS} + * </p> + * + * @param file CompilationUnit in which to find tree. + * @param comment the comment tree that encloses the tree for which the + * position is being sought + * @param tree tree for which a position is sought. + * @return the start position of tree. + */ + long getStartPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree); + + /** + * Gets the ending position of the tree within the comment within the file. If tree is not found within + * file, or if the ending position is not available, + * return {@link javax.tools.Diagnostic#NOPOS}. + * The given tree should be under the given comment tree, and the given documentation + * comment tree should be returned from a {@link DocTrees#getDocCommentTree(com.sun.source.util.TreePath) } + * for a tree under the given file. + * The returned position must be at the end of the yield of this tree, + * that is for any sub-tree of this tree, the following must hold: + * + * <p> + * {@code tree.getEndPosition() >= subtree.getEndPosition()} or <br> + * {@code tree.getEndPosition() == NOPOS} or <br> + * {@code subtree.getEndPosition() == NOPOS} + * </p> + * + * In addition, the following must hold: + * + * <p> + * {@code tree.getStartPosition() <= tree.getEndPosition()} or <br> + * {@code tree.getStartPosition() == NOPOS} or <br> + * {@code tree.getEndPosition() == NOPOS} + * </p> + * + * @param file CompilationUnit in which to find tree. + * @param comment the comment tree that encloses the tree for which the + * position is being sought + * @param tree tree for which a position is sought. + * @return the start position of tree. + */ + long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree); + +}
--- a/src/share/classes/com/sun/source/util/DocTrees.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/source/util/DocTrees.java Fri Sep 27 15:41:28 2013 +0100 @@ -72,6 +72,8 @@ */ public abstract Element getElement(TreePath path, ReferenceTree reference); + public abstract DocSourcePositions getSourcePositions(); + /** * Prints a message of the specified kind at the location of the * tree within the provided compilation unit
--- a/src/share/classes/com/sun/source/util/SourcePositions.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/source/util/SourcePositions.java Fri Sep 27 15:41:28 2013 +0100 @@ -59,7 +59,7 @@ /** * Gets the ending position of tree within file. If tree is not found within - * file, or if the starting position is not available, + * file, or if the ending position is not available, * return {@link javax.tools.Diagnostic#NOPOS}. * The returned position must be at the end of the yield of this tree, * that is for any sub-tree of this tree, the following must hold:
--- a/src/share/classes/com/sun/tools/classfile/Dependencies.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/classfile/Dependencies.java Fri Sep 27 15:41:28 2013 +0100 @@ -315,7 +315,7 @@ static class SimpleLocation implements Location { public SimpleLocation(String name) { this.name = name; - this.className = name.replace('/', '.').replace('$', '.'); + this.className = name.replace('/', '.'); } public String getName() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/com/sun/tools/classfile/ReferenceFinder.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2013, 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.classfile; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import com.sun.tools.classfile.Instruction.TypeKind; +import static com.sun.tools.classfile.ConstantPool.*; + +/** + * A utility class to find where in a ClassFile references + * a {@link CONSTANT_Methodref_info method}, + * a {@link CONSTANT_InterfaceMethodref_info interface method, + * or a {@link CONSTANT_Fieldref_info field}. + */ +public final class ReferenceFinder { + /** + * Filter for ReferenceFinder of what constant pool entries for reference lookup. + */ + public interface Filter { + /** + * Decides if the given CPRefInfo entry should be accepted or filtered. + * + * @param cpool ConstantPool of the ClassFile being parsed + * @param cpref constant pool entry representing a reference to + * a fields method, and interface method. + * @return {@code true} if accepted; otherwise {@code false} + */ + boolean accept(ConstantPool cpool, CPRefInfo cpref); + } + + /** + * Visitor of individual method of a ClassFile that references the + * accepted field, method, or interface method references. + */ + public interface Visitor { + /** + * Invoked for a method containing one or more accepted CPRefInfo entries + * + * @param cf ClassFile + * @param method Method that does the references the accepted references + * @param refs Accepted constant pool method/field reference + */ + void visit(ClassFile cf, Method method, List<CPRefInfo> refConstantPool); + } + + private final Filter filter; + private final Visitor visitor; + + /** + * Constructor. + */ + public ReferenceFinder(Filter filter, Visitor visitor) { + this.filter = Objects.requireNonNull(filter); + this.visitor = Objects.requireNonNull(visitor); + } + + /** + * Parses a given ClassFile and invoke the visitor if there is any reference + * to the constant pool entries referencing field, method, or + * interface method that are accepted. This method will return + * {@code true} if there is one or more accepted constant pool entries + * to lookup; otherwise, it will return {@code false}. + * + * @param cf ClassFile + * @return {@code true} if the given class file is processed to lookup + * references + * @throws ConstantPoolException if an error of the constant pool + */ + public boolean parse(ClassFile cf) throws ConstantPoolException { + List<Integer> cprefs = new ArrayList<Integer>(); + int index = 1; + for (ConstantPool.CPInfo cpInfo : cf.constant_pool.entries()) { + if (cpInfo.accept(cpVisitor, cf.constant_pool)) { + cprefs.add(index); + } + index += cpInfo.size(); + } + + if (cprefs.isEmpty()) { + return false; + } + + for (Method m : cf.methods) { + Set<Integer> ids = new HashSet<Integer>(); + Code_attribute c_attr = (Code_attribute) m.attributes.get(Attribute.Code); + if (c_attr != null) { + for (Instruction instr : c_attr.getInstructions()) { + int idx = instr.accept(codeVisitor, cprefs); + if (idx > 0) { + ids.add(idx); + } + } + } + if (ids.size() > 0) { + List<CPRefInfo> refInfos = new ArrayList<CPRefInfo>(ids.size()); + for (int id : ids) { + refInfos.add(CPRefInfo.class.cast(cf.constant_pool.get(id))); + } + visitor.visit(cf, m, refInfos); + } + } + return true; + } + + private ConstantPool.Visitor<Boolean,ConstantPool> cpVisitor = + new ConstantPool.Visitor<Boolean,ConstantPool>() + { + public Boolean visitClass(CONSTANT_Class_info info, ConstantPool cpool) { + return false; + } + + public Boolean visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ConstantPool cpool) { + return filter.accept(cpool, info); + } + + public Boolean visitMethodref(CONSTANT_Methodref_info info, ConstantPool cpool) { + return filter.accept(cpool, info); + } + + public Boolean visitFieldref(CONSTANT_Fieldref_info info, ConstantPool cpool) { + return filter.accept(cpool, info); + } + + public Boolean visitDouble(CONSTANT_Double_info info, ConstantPool cpool) { + return false; + } + + public Boolean visitFloat(CONSTANT_Float_info info, ConstantPool cpool) { + return false; + } + + public Boolean visitInteger(CONSTANT_Integer_info info, ConstantPool cpool) { + return false; + } + + public Boolean visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, ConstantPool cpool) { + return false; + } + + public Boolean visitLong(CONSTANT_Long_info info, ConstantPool cpool) { + return false; + } + + public Boolean visitNameAndType(CONSTANT_NameAndType_info info, ConstantPool cpool) { + return false; + } + + public Boolean visitMethodHandle(CONSTANT_MethodHandle_info info, ConstantPool cpool) { + return false; + } + + public Boolean visitMethodType(CONSTANT_MethodType_info info, ConstantPool cpool) { + return false; + } + + public Boolean visitString(CONSTANT_String_info info, ConstantPool cpool) { + return false; + } + + public Boolean visitUtf8(CONSTANT_Utf8_info info, ConstantPool cpool) { + return false; + } + }; + + private Instruction.KindVisitor<Integer, List<Integer>> codeVisitor = + new Instruction.KindVisitor<Integer, List<Integer>>() + { + public Integer visitNoOperands(Instruction instr, List<Integer> p) { + return 0; + } + + public Integer visitArrayType(Instruction instr, TypeKind kind, List<Integer> p) { + return 0; + } + + public Integer visitBranch(Instruction instr, int offset, List<Integer> p) { + return 0; + } + + public Integer visitConstantPoolRef(Instruction instr, int index, List<Integer> p) { + return p.contains(index) ? index : 0; + } + + public Integer visitConstantPoolRefAndValue(Instruction instr, int index, int value, List<Integer> p) { + return p.contains(index) ? index : 0; + } + + public Integer visitLocal(Instruction instr, int index, List<Integer> p) { + return 0; + } + + public Integer visitLocalAndValue(Instruction instr, int index, int value, List<Integer> p) { + return 0; + } + + public Integer visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets, List<Integer> p) { + return 0; + } + + public Integer visitTableSwitch(Instruction instr, int default_, int low, int high, int[] offsets, List<Integer> p) { + return 0; + } + + public Integer visitValue(Instruction instr, int value, List<Integer> p) { + return 0; + } + + public Integer visitUnknown(Instruction instr, List<Integer> p) { + return 0; + } + }; +} +
--- a/src/share/classes/com/sun/tools/doclets/formats/html/AbstractExecutableMemberWriter.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/AbstractExecutableMemberWriter.java Fri Sep 27 15:41:28 2013 +0100 @@ -139,12 +139,24 @@ } } - protected void addReceiverAnnotations(ExecutableMemberDoc member, - Content tree) { - if (member.receiverAnnotations().length > 0) { - tree.addContent(writer.getSpace()); - writer.addReceiverAnnotationInfo(member, tree); - } + /** + * Add the receiver annotations information. + * + * @param member the member to write receiver annotations for. + * @param rcvrType the receiver type. + * @param descList list of annotation description. + * @param tree the content tree to which the information will be added. + */ + protected void addReceiverAnnotations(ExecutableMemberDoc member, Type rcvrType, + AnnotationDesc[] descList, Content tree) { + writer.addReceiverAnnotationInfo(member, descList, tree); + tree.addContent(writer.getSpace()); + tree.addContent(rcvrType.typeName()); + LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, + LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, rcvrType); + tree.addContent(new RawHtml(writer.getTypeParameterLinks(linkInfo))); + tree.addContent(writer.getSpace()); + tree.addContent("this"); } @@ -168,14 +180,24 @@ protected void addParameters(ExecutableMemberDoc member, boolean includeAnnotations, Content htmltree) { htmltree.addContent("("); + String sep = ""; Parameter[] params = member.parameters(); String indent = makeSpace(writer.displayLength); if (configuration.linksource) { //add spaces to offset indentation changes caused by link. indent+= makeSpace(member.name().length()); } + Type rcvrType = member.receiverType(); + if (includeAnnotations && rcvrType instanceof AnnotatedType) { + AnnotationDesc[] descList = rcvrType.asAnnotatedType().annotations(); + if (descList.length > 0) { + addReceiverAnnotations(member, rcvrType, descList, htmltree); + sep = "," + DocletConstants.NL + indent; + } + } int paramstart; for (paramstart = 0; paramstart < params.length; paramstart++) { + htmltree.addContent(sep); Parameter param = params[paramstart]; if (!param.name().startsWith("this$")) { if (includeAnnotations) {
--- a/src/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java Fri Sep 27 15:41:28 2013 +0100 @@ -137,7 +137,6 @@ addName(constructor.name(), pre); } addParameters(constructor, pre); - writer.addReceiverAnnotationInfo(constructor, pre); addExceptions(constructor, pre); return pre; }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Fri Sep 27 15:41:28 2013 +0100 @@ -1860,11 +1860,13 @@ * Add the annotation types of the executable receiver. * * @param method the executable to write the receiver annotations for. + * @param descList list of annotation description. * @param htmltree the documentation tree to which the annotation info will be * added */ - public void addReceiverAnnotationInfo(ExecutableMemberDoc method, Content htmltree) { - addAnnotationInfo(method, method.receiverAnnotations(), htmltree); + public void addReceiverAnnotationInfo(ExecutableMemberDoc method, AnnotationDesc[] descList, + Content htmltree) { + addAnnotationInfo(0, method, descList, false, htmltree); } /** @@ -1915,13 +1917,16 @@ private boolean addAnnotationInfo(int indent, Doc doc, AnnotationDesc[] descList, boolean lineBreak, Content htmltree) { List<String> annotations = getAnnotations(indent, descList, lineBreak); + String sep =""; if (annotations.size() == 0) { return false; } Content annotationContent; for (Iterator<String> iter = annotations.iterator(); iter.hasNext();) { + htmltree.addContent(sep); annotationContent = new RawHtml(iter.next()); htmltree.addContent(annotationContent); + sep = " "; } return true; }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/LinkFactoryImpl.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/LinkFactoryImpl.java Fri Sep 27 15:41:28 2013 +0100 @@ -157,9 +157,9 @@ if (!isFirst) { linkInfo.displayLength += 1; output.append(" "); - isFirst = false; } output.append(anno); + isFirst = false; } if (!annos.isEmpty()) { linkInfo.displayLength += 1;
--- a/src/share/classes/com/sun/tools/doclets/formats/html/LinkOutputImpl.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/LinkOutputImpl.java Fri Sep 27 15:41:28 2013 +0100 @@ -63,6 +63,13 @@ /** * {@inheritDoc} */ + public void insert(int offset, Object o) { + output.insert(offset, o.toString()); + } + + /** + * {@inheritDoc} + */ public String toString() { return output.toString(); }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java Fri Sep 27 15:41:28 2013 +0100 @@ -130,7 +130,6 @@ addName(method.name(), pre); } addParameters(method, pre); - addReceiverAnnotations(method, pre); addExceptions(method, pre); return pre; }
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/links/LinkFactory.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/links/LinkFactory.java Fri Sep 27 15:41:28 2013 +0100 @@ -61,7 +61,7 @@ //Just a primitive. linkInfo.displayLength += type.typeName().length(); linkOutput.append(type.typeName()); - } else if (type.asAnnotatedType() != null) { + } else if (type.asAnnotatedType() != null && type.dimension().length() == 0) { linkOutput.append(getTypeAnnotationLinks(linkInfo)); linkInfo.type = type.asAnnotatedType().underlyingType(); linkOutput.append(getLinkOutput(linkInfo)); @@ -141,8 +141,21 @@ linkInfo.displayLength += 3; linkOutput.append("..."); } else { - linkInfo.displayLength += type.dimension().length(); - linkOutput.append(type.dimension()); + while (type != null && type.dimension().length() > 0) { + linkInfo.displayLength += type.dimension().length(); + if (type.asAnnotatedType() != null) { + linkInfo.type = type; + linkOutput.append(" "); + linkOutput.append(getTypeAnnotationLinks(linkInfo)); + linkOutput.append("[]"); + type = type.asAnnotatedType().underlyingType().getElementType(); + } else { + linkOutput.append("[]"); + type = type.getElementType(); + } + } + linkInfo.type = type; + linkOutput.insert(0, getTypeAnnotationLinks(linkInfo)); } return linkOutput; } else if (linkInfo.classDoc != null) {
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/links/LinkOutput.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/links/LinkOutput.java Fri Sep 27 15:41:28 2013 +0100 @@ -44,4 +44,12 @@ * @param o the object to append. */ public void append(Object o); + + /** + * Insert the given object into the output sequence. + * + * @param offset the offset. + * @param o the object to be inserted. + */ + public void insert(int offset, Object o); }
--- a/src/share/classes/com/sun/tools/doclint/Checker.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclint/Checker.java Fri Sep 27 15:41:28 2013 +0100 @@ -122,12 +122,15 @@ private Deque<TagStackItem> tagStack; // TODO: maybe want to record starting tree as well private HtmlTag currHeaderTag; + private final int implicitHeaderLevel; + // <editor-fold defaultstate="collapsed" desc="Top level"> Checker(Env env) { env.getClass(); this.env = env; tagStack = new LinkedList<TagStackItem>(); + implicitHeaderLevel = env.implicitHeaderLevel; } public Void scan(DocCommentTree tree, TreePath p) { @@ -386,7 +389,7 @@ private int getHeaderLevel(HtmlTag tag) { if (tag == null) - return 0; + return implicitHeaderLevel; switch (tag) { case H1: return 1; case H2: return 2;
--- a/src/share/classes/com/sun/tools/doclint/DocLint.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclint/DocLint.java Fri Sep 27 15:41:28 2013 +0100 @@ -30,6 +30,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import javax.lang.model.element.Name; import javax.tools.StandardLocation; @@ -72,6 +73,7 @@ public static final String XMSGS_OPTION = "-Xmsgs"; public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:"; private static final String STATS = "-stats"; + public static final String XIMPLICIT_HEADERS = "-XimplicitHeaders:"; // <editor-fold defaultstate="collapsed" desc="Command-line entry point"> public static void main(String... args) { @@ -289,6 +291,9 @@ env.messages.setOptions(null); } else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) { env.messages.setOptions(arg.substring(arg.indexOf(":") + 1)); + } else if (arg.matches(XIMPLICIT_HEADERS + "[1-6]")) { + char ch = arg.charAt(arg.length() - 1); + env.setImplicitHeaders(Character.digit(ch, 10)); } else throw new IllegalArgumentException(arg); }
--- a/src/share/classes/com/sun/tools/doclint/Env.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/doclint/Env.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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 @@ -83,6 +83,8 @@ /** Message handler. */ final Messages messages; + int implicitHeaderLevel = 0; + // Utility classes DocTrees trees; Elements elements; @@ -102,7 +104,7 @@ DocCommentTree currDocComment; /** * The access kind of the declaration containing the comment currently being analyzed. - * This is the minimum (most restrictive) access kind of the declaration iteself + * This is the minimum (most restrictive) access kind of the declaration itself * and that of its containers. For example, a public method in a private class is * noted as private. */ @@ -128,6 +130,10 @@ java_lang_Void = elements.getTypeElement("java.lang.Void").asType(); } + void setImplicitHeaders(int n) { + implicitHeaderLevel = n; + } + /** Set the current declaration and its doc comment. */ void setCurrent(TreePath path, DocCommentTree comment) { currPath = path;
--- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, 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 @@ -43,14 +43,16 @@ import javax.tools.JavaFileObject; import com.sun.source.doctree.DocCommentTree; +import com.sun.source.doctree.DocTree; import com.sun.source.doctree.ReferenceTree; import com.sun.source.tree.CatchTree; import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.Scope; import com.sun.source.tree.Tree; +import com.sun.source.util.DocSourcePositions; +import com.sun.source.util.DocTreeScanner; import com.sun.source.util.DocTrees; import com.sun.source.util.JavacTask; -import com.sun.source.util.SourcePositions; import com.sun.source.util.TreePath; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Kinds; @@ -76,8 +78,14 @@ import com.sun.tools.javac.model.JavacElements; import com.sun.tools.javac.processing.JavacProcessingEnvironment; import com.sun.tools.javac.tree.DCTree; +import com.sun.tools.javac.tree.DCTree.DCBlockTag; import com.sun.tools.javac.tree.DCTree.DCDocComment; +import com.sun.tools.javac.tree.DCTree.DCEndPosTree; +import com.sun.tools.javac.tree.DCTree.DCErroneous; +import com.sun.tools.javac.tree.DCTree.DCIdentifier; +import com.sun.tools.javac.tree.DCTree.DCParam; import com.sun.tools.javac.tree.DCTree.DCReference; +import com.sun.tools.javac.tree.DCTree.DCText; import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.*; @@ -94,6 +102,7 @@ import com.sun.tools.javac.util.Name; import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Pair; +import com.sun.tools.javac.util.Position; import static com.sun.tools.javac.code.TypeTag.*; /** @@ -166,8 +175,8 @@ javacTaskImpl = (JavacTaskImpl) t; } - public SourcePositions getSourcePositions() { - return new SourcePositions() { + public DocSourcePositions getSourcePositions() { + return new DocSourcePositions() { public long getStartPosition(CompilationUnitTree file, Tree tree) { return TreeInfo.getStartPos((JCTree) tree); } @@ -176,9 +185,80 @@ EndPosTable endPosTable = ((JCCompilationUnit) file).endPositions; return TreeInfo.getEndPos((JCTree) tree, endPosTable); } + + public long getStartPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) { + return ((DCTree) tree).getSourcePosition((DCDocComment) comment); + } + @SuppressWarnings("fallthrough") + public long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) { + DCDocComment dcComment = (DCDocComment) comment; + if (tree instanceof DCEndPosTree) { + int endPos = ((DCEndPosTree) tree).getEndPos(dcComment); + + if (endPos != Position.NOPOS) { + return endPos; + } + } + int correction = 0; + switch (tree.getKind()) { + case TEXT: + DCText text = (DCText) tree; + + return dcComment.comment.getSourcePos(text.pos + text.text.length()); + case ERRONEOUS: + DCErroneous err = (DCErroneous) tree; + + return dcComment.comment.getSourcePos(err.pos + err.body.length()); + case IDENTIFIER: + DCIdentifier ident = (DCIdentifier) tree; + + return dcComment.comment.getSourcePos(ident.pos + (ident.name != names.error ? ident.name.length() : 0)); + case PARAM: + DCParam param = (DCParam) tree; + + if (param.isTypeParameter && param.getDescription().isEmpty()) { + correction = 1; + } + case AUTHOR: case DEPRECATED: case RETURN: case SEE: + case SERIAL: case SERIAL_DATA: case SERIAL_FIELD: case SINCE: + case THROWS: case UNKNOWN_BLOCK_TAG: case VERSION: { + DocTree last = getLastChild(tree); + + if (last != null) { + return getEndPosition(file, comment, last) + correction; + } + + DCBlockTag block = (DCBlockTag) tree; + + return dcComment.comment.getSourcePos(block.pos + block.getTagName().length() + 1); + } + default: + DocTree last = getLastChild(tree); + + if (last != null) { + return getEndPosition(file, comment, last); + } + break; + } + + return Position.NOPOS; + } }; } + private DocTree getLastChild(DocTree tree) { + final DocTree[] last = new DocTree[] {null}; + + tree.accept(new DocTreeScanner<Void, Void>() { + @Override public Void scan(DocTree node, Void p) { + if (node != null) last[0] = node; + return null; + } + }, null); + + return last[0]; + } + public JCClassDecl getTree(TypeElement element) { return (JCClassDecl) getTree((Element) element); }
--- a/src/share/classes/com/sun/tools/javac/code/Flags.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java Fri Sep 27 15:41:28 2013 +0100 @@ -314,6 +314,7 @@ modifiers.add(Modifier.SYNCHRONIZED); if (0 != (flags & NATIVE)) modifiers.add(Modifier.NATIVE); if (0 != (flags & STRICTFP)) modifiers.add(Modifier.STRICTFP); + if (0 != (flags & DEFAULT)) modifiers.add(Modifier.DEFAULT); modifiers = Collections.unmodifiableSet(modifiers); modifierSets.put(flags, modifiers); }
--- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Fri Sep 27 15:41:28 2013 +0100 @@ -454,8 +454,7 @@ } public Set<Modifier> getModifiers() { - long flags = flags(); - return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags); + return Flags.asModifierSet(flags()); } public Name getSimpleName() { @@ -466,19 +465,12 @@ * This is the implementation for {@code * javax.lang.model.element.Element.getAnnotationMirrors()}. */ - public final List<? extends AnnotationMirror> getAnnotationMirrors() { + @Override + public List<Attribute.Compound> getAnnotationMirrors() { return getRawAttributes(); } /** - * TODO: Should there be a {@code - * javax.lang.model.element.Element.getTypeAnnotationMirrors()}. - */ - public final List<Attribute.TypeCompound> getTypeAnnotationMirrors() { - return getRawTypeAttributes(); - } - - /** * @deprecated this method should never be used by javac internally. */ @Deprecated @@ -496,10 +488,11 @@ return List.nil(); } - public List<TypeSymbol> getTypeParameters() { - ListBuffer<TypeSymbol> l = ListBuffer.lb(); + public List<TypeVariableSymbol> getTypeParameters() { + ListBuffer<TypeVariableSymbol> l = ListBuffer.lb(); for (Type t : type.getTypeArguments()) { - l.append(t.tsym); + Assert.check(t.tsym.getKind() == ElementKind.TYPE_PARAMETER); + l.append((TypeVariableSymbol)t.tsym); } return l.toList(); } @@ -546,19 +539,12 @@ } } - /** A class for type symbols. Type variables are represented by instances - * of this class, classes and packages by instances of subclasses. + /** A base class for Symbols representing types. */ - public static class TypeSymbol - extends Symbol implements TypeParameterElement { - // Implements TypeParameterElement because type parameters don't - // have their own TypeSymbol subclass. - // TODO: type parameters should have their own TypeSymbol subclass - - public TypeSymbol(long flags, Name name, Type type, Symbol owner) { - super(TYP, flags, name, type, owner); + public static abstract class TypeSymbol extends Symbol { + public TypeSymbol(int kind, long flags, Name name, Type type, Symbol owner) { + super(kind, flags, name, type, owner); } - /** form a fully qualified name from a name and an owner */ static public Name formFullName(Name name, Symbol owner) { @@ -610,11 +596,7 @@ return this.type.hasTag(TYPEVAR); } - // For type params; overridden in subclasses. - public ElementKind getKind() { - return ElementKind.TYPE_PARAMETER; - } - + @Override public java.util.List<Symbol> getEnclosedElements() { List<Symbol> list = List.nil(); if (kind == TYP && type.hasTag(TYPEVAR)) { @@ -627,21 +609,29 @@ return list; } - // For type params. - // Perhaps not needed if getEnclosingElement can be spec'ed - // to do the same thing. - // TODO: getGenericElement() might not be needed - public Symbol getGenericElement() { - return owner; + @Override + public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { + return v.visitTypeSymbol(this, p); + } + } + + /** + * Type variables are represented by instances of this class. + */ + public static class TypeVariableSymbol + extends TypeSymbol implements TypeParameterElement { + + public TypeVariableSymbol(long flags, Name name, Type type, Symbol owner) { + super(TYP, flags, name, type, owner); } - public <R, P> R accept(ElementVisitor<R, P> v, P p) { - Assert.check(type.hasTag(TYPEVAR)); // else override will be invoked - return v.visitTypeParameter(this, p); + public ElementKind getKind() { + return ElementKind.TYPE_PARAMETER; } - public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { - return v.visitTypeSymbol(this, p); + @Override + public Symbol getGenericElement() { + return owner; } public List<Type> getBounds() { @@ -658,6 +648,29 @@ return ct.interfaces_field; } } + + @Override + public List<Attribute.Compound> getAnnotationMirrors() { + return onlyTypeVariableAnnotations(owner.getRawTypeAttributes()); + } + + private List<Attribute.Compound> onlyTypeVariableAnnotations( + List<Attribute.TypeCompound> candidates) { + // Declaration annotations on TypeParameters are stored in type attributes + List<Attribute.Compound> res = List.nil(); + for (Attribute.TypeCompound a : candidates) { + if (a.position.type == TargetType.CLASS_TYPE_PARAMETER || + a.position.type == TargetType.METHOD_TYPE_PARAMETER) + res = res.prepend(a); + } + + return res = res.reverse(); + } + + @Override + public <R, P> R accept(ElementVisitor<R, P> v, P p) { + return v.visitTypeParameter(this, p); + } } /** A class for package symbols @@ -670,8 +683,7 @@ public ClassSymbol package_info; // see bug 6443073 public PackageSymbol(Name name, Type type, Symbol owner) { - super(0, name, type, owner); - this.kind = PCK; + super(PCK, 0, name, type, owner); this.members_field = null; this.fullname = formFullName(name, owner); } @@ -783,7 +795,7 @@ public Pool pool; public ClassSymbol(long flags, Name name, Type type, Symbol owner) { - super(flags, name, type, owner); + super(TYP, flags, name, type, owner); this.members_field = null; this.fullname = formFullName(name, owner); this.flatname = formFlatName(name, owner); @@ -1126,6 +1138,12 @@ return m; } + @Override + public Set<Modifier> getModifiers() { + long flags = flags(); + return Flags.asModifierSet((flags & DEFAULT) != 0 ? flags & ~ABSTRACT : flags); + } + /** The Java source which this symbol represents. */ public String toString() {
--- a/src/share/classes/com/sun/tools/javac/code/Symtab.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/code/Symtab.java Fri Sep 27 15:41:28 2013 +0100 @@ -404,12 +404,11 @@ return messages.getLocalizedString("compiler.misc.unnamed.package"); } }; - noSymbol = new TypeSymbol(0, names.empty, Type.noType, rootPackage) { + noSymbol = new TypeSymbol(Kinds.NIL, 0, names.empty, Type.noType, rootPackage) { public <R, P> R accept(ElementVisitor<R, P> v, P p) { return v.visitUnknown(this, p); } }; - noSymbol.kind = Kinds.NIL; // create the error symbols errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage);
--- a/src/share/classes/com/sun/tools/javac/code/Type.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Fri Sep 27 15:41:28 2013 +0100 @@ -908,6 +908,12 @@ return interfaces_field.prepend(supertype_field); } + public List<Type> getExplicitComponents() { + return allInterfaces ? + interfaces_field : + getComponents(); + } + @Override public TypeKind getKind() { return TypeKind.INTERSECTION; @@ -1139,7 +1145,7 @@ public TypeVar(Name name, Symbol owner, Type lower) { super(TYPEVAR, null); - tsym = new TypeSymbol(0, name, this, owner); + tsym = new TypeVariableSymbol(0, name, this, owner); this.lower = lower; }
--- a/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java Fri Sep 27 15:41:28 2013 +0100 @@ -206,7 +206,7 @@ sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { // Make sure all type annotations from the symbol are also // on the owner. - sym.owner.annotations.appendUniqueTypes(sym.getTypeAnnotationMirrors()); + sym.owner.annotations.appendUniqueTypes(sym.getRawTypeAttributes()); } }
--- a/src/share/classes/com/sun/tools/javac/code/Types.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Fri Sep 27 15:41:28 2013 +0100 @@ -589,7 +589,7 @@ CapturedType capVar = (CapturedType)capturedTypeargs.head; //use declared bound if it doesn't depend on formal type-args bound = capVar.bound.containsAny(capturedSite.getTypeArguments()) ? - syms.objectType : capVar.bound; + wt.type : capVar.bound; break; default: bound = wt.type; @@ -610,7 +610,7 @@ /** * Scope filter used to skip methods that should be ignored (such as methods - * overridden by j.l.Object) during function interface conversion/marker interface checks + * overridden by j.l.Object) during function interface conversion interface check */ class DescriptorFilter implements Filter<Symbol> { @@ -629,64 +629,6 @@ } }; - // <editor-fold defaultstate="collapsed" desc="isMarker"> - - /** - * A cache that keeps track of marker interfaces - */ - class MarkerCache { - - private WeakHashMap<TypeSymbol, Entry> _map = new WeakHashMap<TypeSymbol, Entry>(); - - class Entry { - final boolean isMarkerIntf; - final int prevMark; - - public Entry(boolean isMarkerIntf, - int prevMark) { - this.isMarkerIntf = isMarkerIntf; - this.prevMark = prevMark; - } - - boolean matches(int mark) { - return this.prevMark == mark; - } - } - - boolean get(TypeSymbol origin) throws FunctionDescriptorLookupError { - Entry e = _map.get(origin); - CompoundScope members = membersClosure(origin.type, false); - if (e == null || - !e.matches(members.getMark())) { - boolean isMarkerIntf = isMarkerInterfaceInternal(origin, members); - _map.put(origin, new Entry(isMarkerIntf, members.getMark())); - return isMarkerIntf; - } - else { - return e.isMarkerIntf; - } - } - - /** - * Is given symbol a marker interface - */ - public boolean isMarkerInterfaceInternal(TypeSymbol origin, CompoundScope membersCache) throws FunctionDescriptorLookupError { - return !origin.isInterface() ? - false : - !membersCache.getElements(new DescriptorFilter(origin)).iterator().hasNext(); - } - } - - private MarkerCache markerCache = new MarkerCache(); - - /** - * Is given type a marker interface? - */ - public boolean isMarkerInterface(Type site) { - return markerCache.get(site.tsym); - } - // </editor-fold> - // <editor-fold defaultstate="collapsed" desc="isSubtype"> /** * Is t an unchecked subtype of s? @@ -2625,15 +2567,15 @@ public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) { Filter<Symbol> filter = new MethodFilter(ms, site); List<MethodSymbol> candidates = List.nil(); - for (Symbol s : membersClosure(site, false).getElements(filter)) { - if (!site.tsym.isInterface() && !s.owner.isInterface()) { - return List.of((MethodSymbol)s); - } else if (!candidates.contains(s)) { - candidates = candidates.prepend((MethodSymbol)s); + for (Symbol s : membersClosure(site, false).getElements(filter)) { + if (!site.tsym.isInterface() && !s.owner.isInterface()) { + return List.of((MethodSymbol)s); + } else if (!candidates.contains(s)) { + candidates = candidates.prepend((MethodSymbol)s); + } } + return prune(candidates); } - return prune(candidates); - } public List<MethodSymbol> prune(List<MethodSymbol> methods) { ListBuffer<MethodSymbol> methodsMin = ListBuffer.lb();
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Sep 27 15:41:28 2013 +0100 @@ -148,6 +148,7 @@ varInfo = new ResultInfo(VAR, Type.noType); unknownExprInfo = new ResultInfo(VAL, Type.noType); unknownTypeInfo = new ResultInfo(TYP, Type.noType); + unknownTypeExprInfo = new ResultInfo(Kinds.TYP | Kinds.VAL, Type.noType); recoveryInfo = new RecoveryInfo(deferredAttr.emptyDeferredAttrContext); } @@ -559,6 +560,7 @@ final ResultInfo varInfo; final ResultInfo unknownExprInfo; final ResultInfo unknownTypeInfo; + final ResultInfo unknownTypeExprInfo; final ResultInfo recoveryInfo; Type pt() { @@ -667,7 +669,7 @@ List<Type> attribArgs(List<JCExpression> trees, Env<AttrContext> env) { ListBuffer<Type> argtypes = new ListBuffer<Type>(); for (JCExpression arg : trees) { - Type argtype = allowPoly && TreeInfo.isPoly(arg, env.tree) ? + Type argtype = allowPoly && deferredAttr.isDeferred(env, arg) ? deferredAttr.new DeferredType(arg, env) : chk.checkNonVoid(arg, attribExpr(arg, env, Infer.anyPoly)); argtypes.append(argtype); @@ -2273,7 +2275,7 @@ Type lambdaType; if (pt() != Type.recoveryType) { - target = checkIntersectionTarget(that, target, resultInfo.checkContext); + target = targetChecker.visit(target, that); lambdaType = types.findDescriptorType(target); chk.checkFunctionalInterface(that, target); } else { @@ -2281,7 +2283,7 @@ lambdaType = fallbackDescriptorType(that); } - setFunctionalInfo(that, pt(), lambdaType, resultInfo.checkContext.inferenceContext()); + setFunctionalInfo(that, pt(), lambdaType, target, resultInfo.checkContext.inferenceContext()); if (lambdaType.hasTag(FORALL)) { //lambda expression target desc cannot be a generic method @@ -2340,11 +2342,34 @@ new ResultInfo(VAL, lambdaType.getReturnType(), funcContext); localEnv.info.returnResult = bodyResultInfo; - if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { - attribTree(that.getBody(), localEnv, bodyResultInfo); - } else { - JCBlock body = (JCBlock)that.body; - attribStats(body.stats, localEnv); + Log.DeferredDiagnosticHandler lambdaDeferredHandler = new Log.DeferredDiagnosticHandler(log); + try { + if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { + attribTree(that.getBody(), localEnv, bodyResultInfo); + } else { + JCBlock body = (JCBlock)that.body; + attribStats(body.stats, localEnv); + } + + if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE) { + //check for errors in lambda body + for (JCDiagnostic deferredDiag : lambdaDeferredHandler.getDiagnostics()) { + if (deferredDiag.getKind() == JCDiagnostic.Kind.ERROR) { + resultInfo.checkContext + .report(that, diags.fragment("bad.arg.types.in.lambda", TreeInfo.types(that.params))); + //we mark the lambda as erroneous - this is crucial in the recovery step + //as parameter-dependent type error won't be reported in that stage, + //meaning that a lambda will be deemed erroeneous only if there is + //a target-independent error (which will cause method diagnostic + //to be skipped). + result = that.type = types.createErrorType(target); + return; + } + } + } + } finally { + lambdaDeferredHandler.reportDeferredDiagnostics(); + log.popDiagnosticHandler(lambdaDeferredHandler); } result = check(that, target, VAL, resultInfo); @@ -2373,26 +2398,55 @@ } } } - - private Type checkIntersectionTarget(DiagnosticPosition pos, Type pt, CheckContext checkContext) { - if (pt != Type.recoveryType && pt.isCompound()) { - IntersectionClassType ict = (IntersectionClassType)pt; - List<Type> bounds = ict.allInterfaces ? - ict.getComponents().tail : - ict.getComponents(); - types.findDescriptorType(bounds.head); //propagate exception outwards! - for (Type bound : bounds.tail) { - if (!types.isMarkerInterface(bound)) { - checkContext.report(pos, diags.fragment("secondary.bound.must.be.marker.intf", bound)); + //where + Types.MapVisitor<DiagnosticPosition> targetChecker = new Types.MapVisitor<DiagnosticPosition>() { + + @Override + public Type visitClassType(ClassType t, DiagnosticPosition pos) { + return t.isCompound() ? + visitIntersectionClassType((IntersectionClassType)t, pos) : t; + } + + public Type visitIntersectionClassType(IntersectionClassType ict, DiagnosticPosition pos) { + Symbol desc = types.findDescriptorSymbol(makeNotionalInterface(ict)); + Type target = null; + for (Type bound : ict.getExplicitComponents()) { + TypeSymbol boundSym = bound.tsym; + if (types.isFunctionalInterface(boundSym) && + types.findDescriptorSymbol(boundSym) == desc) { + target = bound; + } else if (!boundSym.isInterface() || (boundSym.flags() & ANNOTATION) != 0) { + //bound must be an interface + reportIntersectionError(pos, "not.an.intf.component", boundSym); + } } + return target != null ? + target : + ict.getExplicitComponents().head; //error recovery } - //for now (translation doesn't support intersection types) - return bounds.head; - } else { - return pt; - } - } - //where + + private TypeSymbol makeNotionalInterface(IntersectionClassType ict) { + ListBuffer<Type> targs = ListBuffer.lb(); + ListBuffer<Type> supertypes = ListBuffer.lb(); + for (Type i : ict.interfaces_field) { + if (i.isParameterized()) { + targs.appendList(i.tsym.type.allparams()); + } + supertypes.append(i.tsym.type); + } + IntersectionClassType notionalIntf = + (IntersectionClassType)types.makeCompoundType(supertypes.toList()); + notionalIntf.allparams_field = targs.toList(); + notionalIntf.tsym.flags_field |= INTERFACE; + return notionalIntf.tsym; + } + + private void reportIntersectionError(DiagnosticPosition pos, String key, Object... args) { + resultInfo.checkContext.report(pos, diags.fragment("bad.intersection.target.for.functional.expr", + diags.fragment(key, args))); + } + }; + private Type fallbackDescriptorType(JCExpression tree) { switch (tree.getTag()) { case LAMBDA: @@ -2403,20 +2457,24 @@ argtypes.append(param.vartype.type) : argtypes.append(syms.errType); } - return new MethodType(argtypes, Type.recoveryType, List.<Type>nil(), syms.methodClass); + return new MethodType(argtypes, Type.recoveryType, + List.of(syms.throwableType), syms.methodClass); case REFERENCE: - return new MethodType(List.<Type>nil(), Type.recoveryType, List.<Type>nil(), syms.methodClass); + return new MethodType(List.<Type>nil(), Type.recoveryType, + List.of(syms.throwableType), syms.methodClass); default: Assert.error("Cannot get here!"); } return null; } - private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final Type... ts) { + private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, + final InferenceContext inferenceContext, final Type... ts) { checkAccessibleTypes(pos, env, inferenceContext, List.from(ts)); } - private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final List<Type> ts) { + private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env, + final InferenceContext inferenceContext, final List<Type> ts) { if (inferenceContext.free(ts)) { inferenceContext.addFreeTypeListener(ts, new FreeTypeListener() { @Override @@ -2563,7 +2621,7 @@ Type target; Type desc; if (pt() != Type.recoveryType) { - target = checkIntersectionTarget(that, pt(), resultInfo.checkContext); + target = targetChecker.visit(pt(), that); desc = types.findDescriptorType(target); chk.checkFunctionalInterface(that, target); } else { @@ -2571,11 +2629,12 @@ desc = fallbackDescriptorType(that); } - setFunctionalInfo(that, pt(), desc, resultInfo.checkContext.inferenceContext()); + setFunctionalInfo(that, pt(), desc, target, resultInfo.checkContext.inferenceContext()); List<Type> argtypes = desc.getParameterTypes(); - Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = rs.resolveMemberReference(that.pos(), localEnv, that, - that.expr.type, that.name, argtypes, typeargtypes, true); + Pair<Symbol, Resolve.ReferenceLookupHelper> refResult = + rs.resolveMemberReference(that.pos(), localEnv, that, + that.expr.type, that.name, argtypes, typeargtypes, true, rs.resolveMethodCheck); Symbol refSym = refResult.fst; Resolve.ReferenceLookupHelper lookupHelper = refResult.snd; @@ -2765,19 +2824,24 @@ * might contain inference variables, we might need to register an hook in the * current inference context. */ - private void setFunctionalInfo(final JCFunctionalExpression fExpr, final Type pt, final Type descriptorType, InferenceContext inferenceContext) { + private void setFunctionalInfo(final JCFunctionalExpression fExpr, final Type pt, + final Type descriptorType, final Type primaryTarget, InferenceContext inferenceContext) { if (inferenceContext.free(descriptorType)) { inferenceContext.addFreeTypeListener(List.of(pt, descriptorType), new FreeTypeListener() { public void typesInferred(InferenceContext inferenceContext) { - setFunctionalInfo(fExpr, pt, inferenceContext.asInstType(descriptorType), inferenceContext); + setFunctionalInfo(fExpr, pt, inferenceContext.asInstType(descriptorType), + inferenceContext.asInstType(primaryTarget), inferenceContext); } }); } else { ListBuffer<TypeSymbol> targets = ListBuffer.lb(); if (pt.hasTag(CLASS)) { if (pt.isCompound()) { + targets.append(primaryTarget.tsym); //this goes first for (Type t : ((IntersectionClassType)pt()).interfaces_field) { - targets.append(t.tsym); + if (t != primaryTarget) { + targets.append(t.tsym); + } } } else { targets.append(pt.tsym); @@ -2927,7 +2991,8 @@ Env<AttrContext> localEnv = env.dup(tree); //should we propagate the target type? final ResultInfo castInfo; - final boolean isPoly = TreeInfo.isPoly(tree.expr, tree); + JCExpression expr = TreeInfo.skipParens(tree.expr); + boolean isPoly = expr.hasTag(LAMBDA) || expr.hasTag(REFERENCE); if (isPoly) { //expression is a poly - we need to propagate target type info castInfo = new ResultInfo(VAL, clazztype, new Check.NestedCheckContext(resultInfo.checkContext) {
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Sep 27 15:41:28 2013 +0100 @@ -1078,7 +1078,8 @@ mask = MethodFlags; } // Imply STRICTFP if owner has STRICTFP set. - if (((flags|implicit) & Flags.ABSTRACT) == 0) + if (((flags|implicit) & Flags.ABSTRACT) == 0 || + ((flags) & Flags.DEFAULT) != 0) implicit |= sym.owner.flags_field & STRICTFP; break; case TYP:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/CompileStates.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2013, 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.comp; + +import java.util.HashMap; + +import com.sun.tools.javac.util.Context; + +/** Partial map to record which compiler phases have been executed + * for each compilation unit. Used for ATTR and FLOW phases. + * + * <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 CompileStates extends HashMap<Env<AttrContext>, CompileStates.CompileState> { + /** The context key for the compile states. */ + protected static final Context.Key<CompileStates> compileStatesKey = + new Context.Key<CompileStates>(); + + /** Get the CompileStates instance for this context. */ + public static CompileStates instance(Context context) { + CompileStates instance = context.get(compileStatesKey); + if (instance == null) { + instance = new CompileStates(context); + } + return instance; + } + + /** Ordered list of compiler phases for each compilation unit. */ + public enum CompileState { + INIT(0), + PARSE(1), + ENTER(2), + PROCESS(3), + ATTR(4), + FLOW(5), + TRANSTYPES(6), + UNLAMBDA(7), + LOWER(8), + GENERATE(9); + + CompileState(int value) { + this.value = value; + } + public boolean isAfter(CompileState other) { + return value > other.value; + } + public static CompileState max(CompileState a, CompileState b) { + return a.value > b.value ? a : b; + } + private final int value; + }; + + private static final long serialVersionUID = 1812267524140424433L; + + protected Context context; + + public CompileStates(Context context) { + this.context = context; + context.put(compileStatesKey, this); + } + + public boolean isDone(Env<AttrContext> env, CompileState cs) { + CompileState ecs = get(env); + return (ecs != null) && !cs.isAfter(ecs); + } +}
--- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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 com.sun.tools.javac.code.*; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.util.*; +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.comp.Attr.ResultInfo; @@ -531,12 +532,13 @@ attr.memberReferenceQualifierResult(tree)); ListBuffer<Type> argtypes = ListBuffer.lb(); for (Type t : types.findDescriptorType(pt).getParameterTypes()) { - argtypes.append(syms.errType); + argtypes.append(Type.noType); } JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree); mref2.expr = exprTree; Pair<Symbol, ?> lookupRes = - rs.resolveMemberReference(tree, env, mref2, exprTree.type, tree.name, argtypes.toList(), null, true); + rs.resolveMemberReference(tree, env, mref2, exprTree.type, + tree.name, argtypes.toList(), null, true, rs.arityMethodCheck); switch (lookupRes.fst.kind) { //note: as argtypes are erroneous types, type-errors must //have been caused by arity mismatch @@ -798,4 +800,219 @@ } } } + + /** + * Does the argument expression {@code expr} need speculative type-checking? + */ + boolean isDeferred(Env<AttrContext> env, JCExpression expr) { + DeferredChecker dc = new DeferredChecker(env); + dc.scan(expr); + return dc.result.isPoly(); + } + + /** + * The kind of an argument expression. This is used by the analysis that + * determines as to whether speculative attribution is necessary. + */ + enum ArgumentExpressionKind { + + /** kind that denotes poly argument expression */ + POLY, + /** kind that denotes a standalone expression */ + NO_POLY, + /** kind that denotes a primitive/boxed standalone expression */ + PRIMITIVE; + + /** + * Does this kind denote a poly argument expression + */ + public final boolean isPoly() { + return this == POLY; + } + + /** + * Does this kind denote a primitive standalone expression + */ + public final boolean isPrimitive() { + return this == PRIMITIVE; + } + + /** + * Compute the kind of a standalone expression of a given type + */ + static ArgumentExpressionKind standaloneKind(Type type, Types types) { + return types.unboxedTypeOrType(type).isPrimitive() ? + ArgumentExpressionKind.PRIMITIVE : + ArgumentExpressionKind.NO_POLY; + } + + /** + * Compute the kind of a method argument expression given its symbol + */ + static ArgumentExpressionKind methodKind(Symbol sym, Types types) { + Type restype = sym.type.getReturnType(); + if (sym.type.hasTag(FORALL) && + restype.containsAny(((ForAll)sym.type).tvars)) { + return ArgumentExpressionKind.POLY; + } else { + return ArgumentExpressionKind.standaloneKind(restype, types); + } + } + } + + /** + * Tree scanner used for checking as to whether an argument expression + * requires speculative attribution + */ + final class DeferredChecker extends FilterScanner { + + Env<AttrContext> env; + ArgumentExpressionKind result; + + public DeferredChecker(Env<AttrContext> env) { + super(deferredCheckerTags); + this.env = env; + } + + @Override + public void visitLambda(JCLambda tree) { + //a lambda is always a poly expression + result = ArgumentExpressionKind.POLY; + } + + @Override + public void visitReference(JCMemberReference tree) { + //a method reference is always a poly expression + result = ArgumentExpressionKind.POLY; + } + + @Override + public void visitTypeCast(JCTypeCast tree) { + //a cast is always a standalone expression + result = ArgumentExpressionKind.NO_POLY; + } + + @Override + public void visitConditional(JCConditional tree) { + scan(tree.truepart); + if (!result.isPrimitive()) { + result = ArgumentExpressionKind.POLY; + return; + } + scan(tree.falsepart); + result = reduce(ArgumentExpressionKind.PRIMITIVE); + } + + @Override + public void visitNewClass(JCNewClass tree) { + result = (TreeInfo.isDiamond(tree) || attr.findDiamonds) ? + ArgumentExpressionKind.POLY : ArgumentExpressionKind.NO_POLY; + } + + @Override + public void visitApply(JCMethodInvocation tree) { + Name name = TreeInfo.name(tree.meth); + + //fast path + if (tree.typeargs.nonEmpty() || + name == name.table.names._this || + name == name.table.names._super) { + result = ArgumentExpressionKind.NO_POLY; + return; + } + + //slow path + final JCExpression rec = tree.meth.hasTag(SELECT) ? + ((JCFieldAccess)tree.meth).selected : + null; + + if (rec != null && !isSimpleReceiver(rec)) { + //give up if receiver is too complex (to cut down analysis time) + result = ArgumentExpressionKind.POLY; + return; + } + + Type site = rec != null ? + attribSpeculative(rec, env, attr.unknownTypeExprInfo).type : + env.enclClass.sym.type; + + ListBuffer<Type> args = ListBuffer.lb(); + for (int i = 0; i < tree.args.length(); i ++) { + args.append(Type.noType); + } + + Resolve.LookupHelper lh = rs.new LookupHelper(name, site, args.toList(), List.<Type>nil(), MethodResolutionPhase.VARARITY) { + @Override + Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { + return rec == null ? + rs.findFun(env, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) : + rs.findMethod(env, site, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired(), false); + } + @Override + Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { + return sym; + } + }; + + Symbol sym = rs.lookupMethod(env, tree, site.tsym, rs.arityMethodCheck, lh); + + if (sym.kind == Kinds.AMBIGUOUS) { + Resolve.AmbiguityError err = (Resolve.AmbiguityError)sym.baseSymbol(); + result = ArgumentExpressionKind.PRIMITIVE; + for (List<Symbol> ambigousSyms = err.ambiguousSyms ; + ambigousSyms.nonEmpty() && !result.isPoly() ; + ambigousSyms = ambigousSyms.tail) { + Symbol s = ambigousSyms.head; + if (s.kind == Kinds.MTH) { + result = reduce(ArgumentExpressionKind.methodKind(s, types)); + } + } + } else { + result = (sym.kind == Kinds.MTH) ? + ArgumentExpressionKind.methodKind(sym, types) : + ArgumentExpressionKind.NO_POLY; + } + } + //where + private boolean isSimpleReceiver(JCTree rec) { + switch (rec.getTag()) { + case IDENT: + return true; + case SELECT: + return isSimpleReceiver(((JCFieldAccess)rec).selected); + case TYPEAPPLY: + case TYPEARRAY: + return true; + case ANNOTATED_TYPE: + return isSimpleReceiver(((JCAnnotatedType)rec).underlyingType); + default: + return false; + } + } + private ArgumentExpressionKind reduce(ArgumentExpressionKind kind) { + switch (result) { + case PRIMITIVE: return kind; + case NO_POLY: return kind.isPoly() ? kind : result; + case POLY: return result; + default: + Assert.error(); + return null; + } + } + + @Override + public void visitLiteral(JCLiteral tree) { + Type litType = attr.litType(tree.typetag); + result = ArgumentExpressionKind.standaloneKind(litType, types); + } + + @Override + void skip(JCTree tree) { + result = ArgumentExpressionKind.NO_POLY; + } + } + //where + private EnumSet<JCTree.Tag> deferredCheckerTags = + EnumSet.of(LAMBDA, REFERENCE, PARENS, TYPECAST, + CONDEXPR, NEWCLASS, APPLY, LITERAL); }
--- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Fri Sep 27 15:41:28 2013 +0100 @@ -35,7 +35,6 @@ import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.code.Symbol.*; -import com.sun.tools.javac.comp.Resolve; import com.sun.tools.javac.tree.JCTree.*; import static com.sun.tools.javac.code.Flags.*; @@ -277,6 +276,15 @@ } /** + * Utility method to reset several Bits instances. + */ + private void resetBits(Bits... bits) { + for (Bits b : bits) { + b.reset(); + } + } + + /** * Base visitor class for all visitors implementing dataflow analysis logic. * This class define the shared logic for handling jumps (break/continue statements). */ @@ -719,7 +727,7 @@ Flow.this.make = make; pendingExits = new ListBuffer<PendingExit>(); alive = true; - scan(env.tree); + scan(tree); } finally { pendingExits = null; Flow.this.make = null; @@ -1294,11 +1302,11 @@ /** The set of definitely assigned variables. */ - Bits inits; + final Bits inits; /** The set of definitely unassigned variables. */ - Bits uninits; + final Bits uninits; /** The set of variables that are definitely unassigned everywhere * in current try block. This variable is maintained lazily; it is @@ -1308,15 +1316,15 @@ * anywhere in current try block, intersect uninitsTry and * uninits. */ - Bits uninitsTry; + final Bits uninitsTry; /** When analyzing a condition, inits and uninits are null. * Instead we have: */ - Bits initsWhenTrue; - Bits initsWhenFalse; - Bits uninitsWhenTrue; - Bits uninitsWhenFalse; + final Bits initsWhenTrue; + final Bits initsWhenFalse; + final Bits uninitsWhenTrue; + final Bits uninitsWhenFalse; /** A mapping from addresses to variable symbols. */ @@ -1348,15 +1356,25 @@ /** The starting position of the analysed tree */ int startPos; + AssignAnalyzer() { + inits = new Bits(); + uninits = new Bits(); + uninitsTry = new Bits(); + initsWhenTrue = new Bits(true); + initsWhenFalse = new Bits(true); + uninitsWhenTrue = new Bits(true); + uninitsWhenFalse = new Bits(true); + } + class AssignPendingExit extends BaseAnalyzer.PendingExit { - Bits exit_inits; - Bits exit_uninits; + final Bits exit_inits = new Bits(true); + final Bits exit_uninits = new Bits(true); - AssignPendingExit(JCTree tree, Bits inits, Bits uninits) { + AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { super(tree); - this.exit_inits = inits.dup(); - this.exit_uninits = uninits.dup(); + this.exit_inits.assign(inits); + this.exit_uninits.assign(uninits); } void resolveJump() { @@ -1476,19 +1494,20 @@ /** Split (duplicate) inits/uninits into WhenTrue/WhenFalse sets */ void split(boolean setToNull) { - initsWhenFalse = inits.dup(); - uninitsWhenFalse = uninits.dup(); - initsWhenTrue = inits; - uninitsWhenTrue = uninits; - if (setToNull) - inits = uninits = null; + initsWhenFalse.assign(inits); + uninitsWhenFalse.assign(uninits); + initsWhenTrue.assign(inits); + uninitsWhenTrue.assign(uninits); + if (setToNull) { + resetBits(inits, uninits); + } } /** Merge (intersect) inits/uninits from WhenTrue/WhenFalse sets. */ void merge() { - inits = initsWhenFalse.andSet(initsWhenTrue); - uninits = uninitsWhenFalse.andSet(uninitsWhenTrue); + inits.assign(initsWhenFalse.andSet(initsWhenTrue)); + uninits.assign(uninitsWhenFalse.andSet(uninitsWhenTrue)); } /* ************************************************************************ @@ -1501,7 +1520,7 @@ void scanExpr(JCTree tree) { if (tree != null) { scan(tree); - if (inits == null) merge(); + if (inits.isReset()) merge(); } } @@ -1518,28 +1537,29 @@ */ void scanCond(JCTree tree) { if (tree.type.isFalse()) { - if (inits == null) merge(); - initsWhenTrue = inits.dup(); + if (inits.isReset()) merge(); + initsWhenTrue.assign(inits); initsWhenTrue.inclRange(firstadr, nextadr); - uninitsWhenTrue = uninits.dup(); + uninitsWhenTrue.assign(uninits); uninitsWhenTrue.inclRange(firstadr, nextadr); - initsWhenFalse = inits; - uninitsWhenFalse = uninits; + initsWhenFalse.assign(inits); + uninitsWhenFalse.assign(uninits); } else if (tree.type.isTrue()) { - if (inits == null) merge(); - initsWhenFalse = inits.dup(); + if (inits.isReset()) merge(); + initsWhenFalse.assign(inits); initsWhenFalse.inclRange(firstadr, nextadr); - uninitsWhenFalse = uninits.dup(); + uninitsWhenFalse.assign(uninits); uninitsWhenFalse.inclRange(firstadr, nextadr); - initsWhenTrue = inits; - uninitsWhenTrue = uninits; + initsWhenTrue.assign(inits); + uninitsWhenTrue.assign(uninits); } else { scan(tree); - if (inits != null) + if (!inits.isReset()) split(tree.type != syms.unknownType); } - if (tree.type != syms.unknownType) - inits = uninits = null; + if (tree.type != syms.unknownType) { + resetBits(inits, uninits); + } } /* ------------ Visitor methods for various sorts of trees -------------*/ @@ -1619,8 +1639,8 @@ public void visitMethodDef(JCMethodDecl tree) { if (tree.body == null) return; - Bits initsPrev = inits.dup(); - Bits uninitsPrev = uninits.dup(); + final Bits initsPrev = new Bits(inits); + final Bits uninitsPrev = new Bits(uninits); int nextadrPrev = nextadr; int firstadrPrev = firstadr; int returnadrPrev = returnadr; @@ -1658,14 +1678,14 @@ exits = exits.tail; Assert.check(exit.tree.hasTag(RETURN), exit.tree); if (isInitialConstructor) { - inits = exit.exit_inits; + inits.assign(exit.exit_inits); for (int i = firstadr; i < nextadr; i++) checkInit(exit.tree.pos(), vars[i]); } } } finally { - inits = initsPrev; - uninits = uninitsPrev; + inits.assign(initsPrev); + uninits.assign(uninitsPrev); nextadr = nextadrPrev; firstadr = firstadrPrev; returnadr = returnadrPrev; @@ -1698,31 +1718,31 @@ ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; - Bits initsSkip = null; - Bits uninitsSkip = null; + final Bits initsSkip = new Bits(true); + final Bits uninitsSkip = new Bits(true); pendingExits = new ListBuffer<AssignPendingExit>(); int prevErrors = log.nerrors; do { - Bits uninitsEntry = uninits.dup(); + final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); scan(tree.body); resolveContinues(tree); scanCond(tree.cond); if (!flowKind.isFinal()) { - initsSkip = initsWhenFalse; - uninitsSkip = uninitsWhenFalse; + initsSkip.assign(initsWhenFalse); + uninitsSkip.assign(uninitsWhenFalse); } if (log.nerrors != prevErrors || flowKind.isFinal() || - uninitsEntry.dup().diffSet(uninitsWhenTrue).nextBit(firstadr)==-1) + new Bits(uninitsEntry).diffSet(uninitsWhenTrue).nextBit(firstadr)==-1) break; - inits = initsWhenTrue; - uninits = uninitsEntry.andSet(uninitsWhenTrue); + inits.assign(initsWhenTrue); + uninits.assign(uninitsEntry.andSet(uninitsWhenTrue)); flowKind = FlowKind.SPECULATIVE_LOOP; } while (true); flowKind = prevFlowKind; - inits = initsSkip; - uninits = uninitsSkip; + inits.assign(initsSkip); + uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); } @@ -1730,34 +1750,34 @@ ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; - Bits initsSkip = null; - Bits uninitsSkip = null; + final Bits initsSkip = new Bits(true); + final Bits uninitsSkip = new Bits(true); pendingExits = new ListBuffer<AssignPendingExit>(); int prevErrors = log.nerrors; - Bits uninitsEntry = uninits.dup(); + final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); do { scanCond(tree.cond); if (!flowKind.isFinal()) { - initsSkip = initsWhenFalse; - uninitsSkip = uninitsWhenFalse; + initsSkip.assign(initsWhenFalse) ; + uninitsSkip.assign(uninitsWhenFalse); } - inits = initsWhenTrue; - uninits = uninitsWhenTrue; + inits.assign(initsWhenTrue); + uninits.assign(uninitsWhenTrue); scan(tree.body); resolveContinues(tree); if (log.nerrors != prevErrors || flowKind.isFinal() || - uninitsEntry.dup().diffSet(uninits).nextBit(firstadr) == -1) + new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1) break; - uninits = uninitsEntry.andSet(uninits); + uninits.assign(uninitsEntry.andSet(uninits)); flowKind = FlowKind.SPECULATIVE_LOOP; } while (true); flowKind = prevFlowKind; //a variable is DA/DU after the while statement, if it's DA/DU assuming the //branch is not taken AND if it's DA/DU before any break statement - inits = initsSkip; - uninits = uninitsSkip; + inits.assign(initsSkip); + uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); } @@ -1767,25 +1787,25 @@ flowKind = FlowKind.NORMAL; int nextadrPrev = nextadr; scan(tree.init); - Bits initsSkip = null; - Bits uninitsSkip = null; + final Bits initsSkip = new Bits(true); + final Bits uninitsSkip = new Bits(true); pendingExits = new ListBuffer<AssignPendingExit>(); int prevErrors = log.nerrors; do { - Bits uninitsEntry = uninits.dup(); + final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); if (tree.cond != null) { scanCond(tree.cond); if (!flowKind.isFinal()) { - initsSkip = initsWhenFalse; - uninitsSkip = uninitsWhenFalse; + initsSkip.assign(initsWhenFalse); + uninitsSkip.assign(uninitsWhenFalse); } - inits = initsWhenTrue; - uninits = uninitsWhenTrue; + inits.assign(initsWhenTrue); + uninits.assign(uninitsWhenTrue); } else if (!flowKind.isFinal()) { - initsSkip = inits.dup(); + initsSkip.assign(inits); initsSkip.inclRange(firstadr, nextadr); - uninitsSkip = uninits.dup(); + uninitsSkip.assign(uninits); uninitsSkip.inclRange(firstadr, nextadr); } scan(tree.body); @@ -1793,16 +1813,16 @@ scan(tree.step); if (log.nerrors != prevErrors || flowKind.isFinal() || - uninitsEntry.dup().diffSet(uninits).nextBit(firstadr) == -1) + new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1) break; - uninits = uninitsEntry.andSet(uninits); + uninits.assign(uninitsEntry.andSet(uninits)); flowKind = FlowKind.SPECULATIVE_LOOP; } while (true); flowKind = prevFlowKind; //a variable is DA/DU after a for loop, if it's DA/DU assuming the //branch is not taken AND if it's DA/DU before any break statement - inits = initsSkip; - uninits = uninitsSkip; + inits.assign(initsSkip); + uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); nextadr = nextadrPrev; } @@ -1815,27 +1835,27 @@ flowKind = FlowKind.NORMAL; int nextadrPrev = nextadr; scan(tree.expr); - Bits initsStart = inits.dup(); - Bits uninitsStart = uninits.dup(); + final Bits initsStart = new Bits(inits); + final Bits uninitsStart = new Bits(uninits); letInit(tree.pos(), tree.var.sym); pendingExits = new ListBuffer<AssignPendingExit>(); int prevErrors = log.nerrors; do { - Bits uninitsEntry = uninits.dup(); + final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); scan(tree.body); resolveContinues(tree); if (log.nerrors != prevErrors || flowKind.isFinal() || - uninitsEntry.dup().diffSet(uninits).nextBit(firstadr) == -1) + new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1) break; - uninits = uninitsEntry.andSet(uninits); + uninits.assign(uninitsEntry.andSet(uninits)); flowKind = FlowKind.SPECULATIVE_LOOP; } while (true); flowKind = prevFlowKind; - inits = initsStart; - uninits = uninitsStart.andSet(uninits); + inits.assign(initsStart); + uninits.assign(uninitsStart.andSet(uninits)); resolveBreaks(tree, prevPendingExits); nextadr = nextadrPrev; } @@ -1852,12 +1872,12 @@ pendingExits = new ListBuffer<AssignPendingExit>(); int nextadrPrev = nextadr; scanExpr(tree.selector); - Bits initsSwitch = inits; - Bits uninitsSwitch = uninits.dup(); + final Bits initsSwitch = new Bits(inits); + final Bits uninitsSwitch = new Bits(uninits); boolean hasDefault = false; for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) { - inits = initsSwitch.dup(); - uninits = uninits.andSet(uninitsSwitch); + inits.assign(initsSwitch); + uninits.assign(uninits.andSet(uninitsSwitch)); JCCase c = l.head; if (c.pat == null) hasDefault = true; @@ -1875,8 +1895,8 @@ } // where /** Add any variables defined in stats to inits and uninits. */ - private void addVars(List<JCStatement> stats, Bits inits, - Bits uninits) { + private void addVars(List<JCStatement> stats, final Bits inits, + final Bits uninits) { for (;stats.nonEmpty(); stats = stats.tail) { JCTree stat = stats.head; if (stat.hasTag(VARDEF)) { @@ -1889,11 +1909,11 @@ public void visitTry(JCTry tree) { ListBuffer<JCVariableDecl> resourceVarDecls = ListBuffer.lb(); - Bits uninitsTryPrev = uninitsTry; + final Bits uninitsTryPrev = new Bits(uninitsTry); ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<AssignPendingExit>(); - Bits initsTry = inits.dup(); - uninitsTry = uninits.dup(); + final Bits initsTry = new Bits(inits); + uninitsTry.assign(uninits); for (JCTree resource : tree.resources) { if (resource instanceof JCVariableDecl) { JCVariableDecl vdecl = (JCVariableDecl) resource; @@ -1908,8 +1928,8 @@ } scan(tree.body); uninitsTry.andSet(uninits); - Bits initsEnd = inits; - Bits uninitsEnd = uninits; + final Bits initsEnd = new Bits(inits); + final Bits uninitsEnd = new Bits(uninits); int nextadrCatch = nextadr; if (!resourceVarDecls.isEmpty() && @@ -1925,8 +1945,8 @@ for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { JCVariableDecl param = l.head.param; - inits = initsTry.dup(); - uninits = uninitsTry.dup(); + inits.assign(initsTry); + uninits.assign(uninitsTry); scan(param); inits.incl(param.sym.adr); uninits.excl(param.sym.adr); @@ -1936,8 +1956,8 @@ nextadr = nextadrCatch; } if (tree.finalizer != null) { - inits = initsTry.dup(); - uninits = uninitsTry.dup(); + inits.assign(initsTry); + uninits.assign(uninitsTry); ListBuffer<AssignPendingExit> exits = pendingExits; pendingExits = prevPendingExits; scan(tree.finalizer); @@ -1958,8 +1978,8 @@ inits.orSet(initsEnd); } } else { - inits = initsEnd; - uninits = uninitsEnd; + inits.assign(initsEnd); + uninits.assign(uninitsEnd); ListBuffer<AssignPendingExit> exits = pendingExits; pendingExits = prevPendingExits; while (exits.nonEmpty()) pendingExits.append(exits.next()); @@ -1969,10 +1989,10 @@ public void visitConditional(JCConditional tree) { scanCond(tree.cond); - Bits initsBeforeElse = initsWhenFalse; - Bits uninitsBeforeElse = uninitsWhenFalse; - inits = initsWhenTrue; - uninits = uninitsWhenTrue; + final Bits initsBeforeElse = new Bits(initsWhenFalse); + final Bits uninitsBeforeElse = new Bits(uninitsWhenFalse); + inits.assign(initsWhenTrue); + uninits.assign(uninitsWhenTrue); if (tree.truepart.type.hasTag(BOOLEAN) && tree.falsepart.type.hasTag(BOOLEAN)) { // if b and c are boolean valued, then @@ -1980,12 +2000,12 @@ // v is (un)assigned after b when true and // v is (un)assigned after c when true scanCond(tree.truepart); - Bits initsAfterThenWhenTrue = initsWhenTrue.dup(); - Bits initsAfterThenWhenFalse = initsWhenFalse.dup(); - Bits uninitsAfterThenWhenTrue = uninitsWhenTrue.dup(); - Bits uninitsAfterThenWhenFalse = uninitsWhenFalse.dup(); - inits = initsBeforeElse; - uninits = uninitsBeforeElse; + final Bits initsAfterThenWhenTrue = new Bits(initsWhenTrue); + final Bits initsAfterThenWhenFalse = new Bits(initsWhenFalse); + final Bits uninitsAfterThenWhenTrue = new Bits(uninitsWhenTrue); + final Bits uninitsAfterThenWhenFalse = new Bits(uninitsWhenFalse); + inits.assign(initsBeforeElse); + uninits.assign(uninitsBeforeElse); scanCond(tree.falsepart); initsWhenTrue.andSet(initsAfterThenWhenTrue); initsWhenFalse.andSet(initsAfterThenWhenFalse); @@ -1993,10 +2013,10 @@ uninitsWhenFalse.andSet(uninitsAfterThenWhenFalse); } else { scanExpr(tree.truepart); - Bits initsAfterThen = inits.dup(); - Bits uninitsAfterThen = uninits.dup(); - inits = initsBeforeElse; - uninits = uninitsBeforeElse; + final Bits initsAfterThen = new Bits(inits); + final Bits uninitsAfterThen = new Bits(uninits); + inits.assign(initsBeforeElse); + uninits.assign(uninitsBeforeElse); scanExpr(tree.falsepart); inits.andSet(initsAfterThen); uninits.andSet(uninitsAfterThen); @@ -2005,16 +2025,16 @@ public void visitIf(JCIf tree) { scanCond(tree.cond); - Bits initsBeforeElse = initsWhenFalse; - Bits uninitsBeforeElse = uninitsWhenFalse; - inits = initsWhenTrue; - uninits = uninitsWhenTrue; + final Bits initsBeforeElse = new Bits(initsWhenFalse); + final Bits uninitsBeforeElse = new Bits(uninitsWhenFalse); + inits.assign(initsWhenTrue); + uninits.assign(uninitsWhenTrue); scan(tree.thenpart); if (tree.elsepart != null) { - Bits initsAfterThen = inits.dup(); - Bits uninitsAfterThen = uninits.dup(); - inits = initsBeforeElse; - uninits = uninitsBeforeElse; + final Bits initsAfterThen = new Bits(inits); + final Bits uninitsAfterThen = new Bits(uninits); + inits.assign(initsBeforeElse); + uninits.assign(uninitsBeforeElse); scan(tree.elsepart); inits.andSet(initsAfterThen); uninits.andSet(uninitsAfterThen); @@ -2055,8 +2075,8 @@ @Override public void visitLambda(JCLambda tree) { - Bits prevUninits = uninits; - Bits prevInits = inits; + final Bits prevUninits = new Bits(uninits); + final Bits prevInits = new Bits(inits); int returnadrPrev = returnadr; ListBuffer<AssignPendingExit> prevPending = pendingExits; try { @@ -2076,8 +2096,8 @@ } finally { returnadr = returnadrPrev; - uninits = prevUninits; - inits = prevInits; + uninits.assign(prevUninits); + inits.assign(prevInits); pendingExits = prevPending; } } @@ -2088,17 +2108,17 @@ } public void visitAssert(JCAssert tree) { - Bits initsExit = inits.dup(); - Bits uninitsExit = uninits.dup(); + final Bits initsExit = new Bits(inits); + final Bits uninitsExit = new Bits(uninits); scanCond(tree.cond); uninitsExit.andSet(uninitsWhenTrue); if (tree.detail != null) { - inits = initsWhenFalse; - uninits = uninitsWhenFalse; + inits.assign(initsWhenFalse); + uninits.assign(uninitsWhenFalse); scanExpr(tree.detail); } - inits = initsExit; - uninits = uninitsExit; + inits.assign(initsExit); + uninits.assign(uninitsExit); } public void visitAssign(JCAssign tree) { @@ -2120,12 +2140,12 @@ switch (tree.getTag()) { case NOT: scanCond(tree.arg); - Bits t = initsWhenFalse; - initsWhenFalse = initsWhenTrue; - initsWhenTrue = t; - t = uninitsWhenFalse; - uninitsWhenFalse = uninitsWhenTrue; - uninitsWhenTrue = t; + final Bits t = new Bits(initsWhenFalse); + initsWhenFalse.assign(initsWhenTrue); + initsWhenTrue.assign(t); + t.assign(uninitsWhenFalse); + uninitsWhenFalse.assign(uninitsWhenTrue); + uninitsWhenTrue.assign(t); break; case PREINC: case POSTINC: case PREDEC: case POSTDEC: @@ -2141,20 +2161,20 @@ switch (tree.getTag()) { case AND: scanCond(tree.lhs); - Bits initsWhenFalseLeft = initsWhenFalse; - Bits uninitsWhenFalseLeft = uninitsWhenFalse; - inits = initsWhenTrue; - uninits = uninitsWhenTrue; + final Bits initsWhenFalseLeft = new Bits(initsWhenFalse); + final Bits uninitsWhenFalseLeft = new Bits(uninitsWhenFalse); + inits.assign(initsWhenTrue); + uninits.assign(uninitsWhenTrue); scanCond(tree.rhs); initsWhenFalse.andSet(initsWhenFalseLeft); uninitsWhenFalse.andSet(uninitsWhenFalseLeft); break; case OR: scanCond(tree.lhs); - Bits initsWhenTrueLeft = initsWhenTrue; - Bits uninitsWhenTrueLeft = uninitsWhenTrue; - inits = initsWhenFalse; - uninits = uninitsWhenFalse; + final Bits initsWhenTrueLeft = new Bits(initsWhenTrue); + final Bits uninitsWhenTrueLeft = new Bits(uninitsWhenTrue); + inits.assign(initsWhenFalse); + uninits.assign(uninitsWhenFalse); scanCond(tree.rhs); initsWhenTrue.andSet(initsWhenTrueLeft); uninitsWhenTrue.andSet(uninitsWhenTrueLeft); @@ -2200,11 +2220,7 @@ attrEnv = env; Flow.this.make = make; startPos = tree.pos().getStartPosition(); - inits = new Bits(); - uninits = new Bits(); - uninitsTry = new Bits(); - initsWhenTrue = initsWhenFalse = - uninitsWhenTrue = uninitsWhenFalse = null; + if (vars == null) vars = new VarSymbol[32]; else @@ -2219,9 +2235,8 @@ } finally { // note that recursive invocations of this method fail hard startPos = -1; - inits = uninits = uninitsTry = null; - initsWhenTrue = initsWhenFalse = - uninitsWhenTrue = uninitsWhenFalse = null; + resetBits(inits, uninits, uninitsTry, initsWhenTrue, + initsWhenFalse, uninitsWhenTrue, uninitsWhenFalse); if (vars != null) for (int i=0; i<vars.length; i++) vars[i] = null; firstadr = 0;
--- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Fri Sep 27 15:41:28 2013 +0100 @@ -143,7 +143,6 @@ boolean allowBoxing, boolean useVarargs, Resolve.MethodResolutionContext resolveContext, - Resolve.MethodCheck methodCheck, Warner warn) throws InferenceException { //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG final InferenceContext inferenceContext = new InferenceContext(tvars); @@ -152,7 +151,7 @@ DeferredAttr.DeferredAttrContext deferredAttrContext = resolveContext.deferredAttrContext(msym, inferenceContext, resultInfo, warn); - methodCheck.argumentsAcceptable(env, deferredAttrContext, + resolveContext.methodCheck.argumentsAcceptable(env, deferredAttrContext, argtypes, mt.getParameterTypes(), warn); if (allowGraphInference && @@ -263,7 +262,7 @@ UndetVar uv = (UndetVar)inferenceContext.asFree(t); List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER); if (Type.containsAny(upperBounds, vars)) { - TypeSymbol fresh_tvar = new TypeSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); + TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); fresh_tvar.type = new TypeVar(fresh_tvar, types.makeCompoundType(uv.getBounds(InferenceBound.UPPER)), null); todo.append(uv); uv.inst = fresh_tvar.type;
--- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Fri Sep 27 15:41:28 2013 +0100 @@ -40,10 +40,9 @@ import com.sun.tools.javac.code.Symbol.VarSymbol; import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.MethodType; import com.sun.tools.javac.code.Types; -import com.sun.tools.javac.comp.LambdaToMethod.LambdaAnalyzer.*; +import com.sun.tools.javac.comp.LambdaToMethod.LambdaAnalyzerPreprocessor.*; import com.sun.tools.javac.comp.Lower.BasicFreeVarCollector; import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.util.*; @@ -81,7 +80,7 @@ private Env<AttrContext> attrEnv; /** the analyzer scanner */ - private LambdaAnalyzer analyzer; + private LambdaAnalyzerPreprocessor analyzer; /** map from lambda trees to translation contexts */ private Map<JCTree, TranslationContext<?>> contextMap; @@ -156,7 +155,7 @@ make = TreeMaker.instance(context); types = Types.instance(context); transTypes = TransTypes.instance(context); - analyzer = new LambdaAnalyzer(); + analyzer = new LambdaAnalyzerPreprocessor(); } // </editor-fold> @@ -206,7 +205,7 @@ public void visitClassDef(JCClassDecl tree) { if (tree.sym.owner.kind == PCK) { //analyze class - analyzer.analyzeClass(tree); + tree = analyzer.analyzeAndPreprocessClass(tree); } KlassInfo prevKlassInfo = kInfo; try { @@ -384,18 +383,6 @@ Symbol translatedSym = lambdaContext.getSymbolMap(CAPTURED_VAR).get(tree.sym); result = make.Ident(translatedSym).setType(tree.type); } else { - if (tree.sym.owner.kind == Kinds.TYP) { - for (Map.Entry<Symbol, Symbol> encl_entry : lambdaContext.getSymbolMap(CAPTURED_THIS).entrySet()) { - if (tree.sym.isMemberOf((ClassSymbol) encl_entry.getKey(), types)) { - JCExpression enclRef = make.Ident(encl_entry.getValue()); - result = tree.sym.name == names._this - ? enclRef.setType(tree.type) - : make.Select(enclRef, tree.sym).setType(tree.type); - result = tree; - return; - } - } - } //access to untranslated symbols (i.e. compile-time constants, //members defined inside the lambda body, etc.) ) super.visitIdent(tree); @@ -543,16 +530,25 @@ /** Make an attributed class instance creation expression. * @param ctype The class type. * @param args The constructor arguments. + * @param cons The constructor symbol */ - JCNewClass makeNewClass(Type ctype, List<JCExpression> args) { + JCNewClass makeNewClass(Type ctype, List<JCExpression> args, Symbol cons) { JCNewClass tree = make.NewClass(null, null, make.QualIdent(ctype.tsym), args, null); - tree.constructor = rs.resolveConstructor( - null, attrEnv, ctype, TreeInfo.types(args), List.<Type>nil()); + tree.constructor = cons; tree.type = ctype; return tree; } + /** Make an attributed class instance creation expression. + * @param ctype The class type. + * @param args The constructor arguments. + */ + JCNewClass makeNewClass(Type ctype, List<JCExpression> args) { + return makeNewClass(ctype, args, + rs.resolveConstructor(null, attrEnv, ctype, TreeInfo.types(args), List.<Type>nil())); + } + private void addDeserializationCase(int implMethodKind, Symbol refSym, Type targetType, MethodSymbol samSym, DiagnosticPosition pos, List<Object> staticArgs, MethodType indyType) { String functionalInterfaceClass = classSig(targetType); @@ -1031,8 +1027,9 @@ * This visitor collects information about translation of a lambda expression. * More specifically, it keeps track of the enclosing contexts and captured locals * accessed by the lambda being translated (as well as other useful info). + * It also translates away problems for LambdaToMethod. */ - class LambdaAnalyzer extends TreeScanner { + class LambdaAnalyzerPreprocessor extends TreeTranslator { /** the frame stack - used to reconstruct translation info about enclosing scopes */ private List<Frame> frameStack; @@ -1059,10 +1056,10 @@ private Map<ClassSymbol, Symbol> clinits = new HashMap<ClassSymbol, Symbol>(); - private void analyzeClass(JCClassDecl tree) { + private JCClassDecl analyzeAndPreprocessClass(JCClassDecl tree) { frameStack = List.nil(); localClassDefs = new HashMap<Symbol, JCClassDecl>(); - scan(tree); + return translate(tree); } @Override @@ -1166,7 +1163,7 @@ frameStack.head.addLocal(param.sym); } contextMap.put(tree, context); - scan(tree.body); + super.visitLambda(tree); context.complete(); } finally { @@ -1232,12 +1229,47 @@ }; fvc.scan(localCDef); } - } + } + /** + * Method references to local class constructors, may, if the local + * class references local variables, have implicit constructor + * parameters added in Lower; As a result, the invokedynamic bootstrap + * information added in the LambdaToMethod pass will have the wrong + * signature. Hooks between Lower and LambdaToMethod have been added to + * handle normal "new" in this case. This visitor converts potentially + * effected method references into a lambda containing a normal "new" of + * the class. + * + * @param tree + */ @Override public void visitReference(JCMemberReference tree) { - scan(tree.getQualifierExpression()); - contextMap.put(tree, makeReferenceContext(tree)); + if (tree.getMode() == ReferenceMode.NEW + && tree.kind != ReferenceKind.ARRAY_CTOR + && tree.sym.owner.isLocal()) { + MethodSymbol consSym = (MethodSymbol) tree.sym; + List<Type> ptypes = ((MethodType) consSym.type).getParameterTypes(); + Type classType = consSym.owner.type; + + // Make new-class call + List<JCVariableDecl> params = make.Params(ptypes, owner()); + JCNewClass nc = makeNewClass(classType, make.Idents(params)); + nc.pos = tree.pos; + + // Make lambda holding the new-class call + JCLambda slam = make.Lambda(params, nc); + slam.descriptorType = tree.descriptorType; + slam.targets = tree.targets; + slam.type = tree.type; + slam.pos = tree.pos; + + // Now it is a lambda, process as such + visitLambda(slam); + } else { + super.visitReference(tree); + contextMap.put(tree, makeReferenceContext(tree)); + } } @Override @@ -1252,10 +1284,8 @@ } localContext = localContext.prev; } - scan(tree.selected); - } else { - super.visitSelect(tree); } + super.visitSelect(tree); } @Override @@ -1315,6 +1345,7 @@ // the generated lambda method will not have type yet, but the // enclosing method's name will have been generated with this same // method, so it will be unique and never be overloaded. + Assert.check(owner.type != null || directlyEnclosingLambda() != null); if (owner.type != null) { int methTypeHash = methodSig(owner.type).hashCode(); buf.append(Integer.toHexString(methTypeHash));
--- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Fri Sep 27 15:41:28 2013 +0100 @@ -48,6 +48,7 @@ import static com.sun.tools.javac.code.TypeTag.*; import static com.sun.tools.javac.jvm.ByteCodes.*; import static com.sun.tools.javac.tree.JCTree.Tag.*; +import javax.lang.model.type.TypeKind; /** This pass translates away some syntactic sugar: inner classes, * class literals, assertions, foreach loops, etc. @@ -3400,8 +3401,11 @@ if (iterableType.getTypeArguments().nonEmpty()) iteratorTarget = types.erasure(iterableType.getTypeArguments().head); Type eType = tree.expr.type; + while (eType.hasTag(TYPEVAR)) { + eType = eType.getUpperBound(); + } tree.expr.type = types.erasure(eType); - if (eType.hasTag(TYPEVAR) && eType.getUpperBound().isCompound()) + if (eType.isCompound()) tree.expr = make.TypeCast(types.erasure(iterableType), tree.expr); Symbol iterator = lookupMethod(tree.expr.pos(), names.iterator,
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Sep 27 15:41:28 2013 +0100 @@ -508,7 +508,6 @@ List<Type> typeargtypes, boolean allowBoxing, boolean useVarargs, - MethodCheck methodCheck, Warner warn) throws Infer.InferenceException { Type mt = types.memberType(site, m); @@ -561,10 +560,9 @@ allowBoxing, useVarargs, currentResolutionContext, - methodCheck, warn); - methodCheck.argumentsAcceptable(env, currentResolutionContext.deferredAttrContext(m, infer.emptyContext, resultInfo, warn), + currentResolutionContext.methodCheck.argumentsAcceptable(env, currentResolutionContext.deferredAttrContext(m, infer.emptyContext, resultInfo, warn), argtypes, mt.getParameterTypes(), warn); return mt; } @@ -582,7 +580,7 @@ currentResolutionContext.attrMode = DeferredAttr.AttrMode.CHECK; MethodResolutionPhase step = currentResolutionContext.step = env.info.pendingResolutionPhase; return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes, - step.isBoxingRequired(), step.isVarargsRequired(), resolveMethodCheck, warn); + step.isBoxingRequired(), step.isVarargsRequired(), warn); } finally { currentResolutionContext = prevContext; @@ -599,11 +597,10 @@ List<Type> typeargtypes, boolean allowBoxing, boolean useVarargs, - MethodCheck methodCheck, Warner warn) { try { return rawInstantiate(env, site, m, resultInfo, argtypes, typeargtypes, - allowBoxing, useVarargs, methodCheck, warn); + allowBoxing, useVarargs, warn); } catch (InapplicableMethodException ex) { return null; } @@ -628,6 +625,12 @@ List<Type> argtypes, List<Type> formals, Warner warn); + + /** + * Retrieve the method check object that will be used during a + * most specific check. + */ + MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict); } /** @@ -661,24 +664,25 @@ } /** - * Main method applicability routine. Given a list of actual types A, - * a list of formal types F, determines whether the types in A are - * compatible (by method invocation conversion) with the types in F. - * - * Since this routine is shared between overload resolution and method - * type-inference, a (possibly empty) inference context is used to convert - * formal types to the corresponding 'undet' form ahead of a compatibility - * check so that constraints can be propagated and collected. - * - * Moreover, if one or more types in A is a deferred type, this routine uses - * DeferredAttr in order to perform deferred attribution. If one or more actual - * deferred types are stuck, they are placed in a queue and revisited later - * after the remainder of the arguments have been seen. If this is not sufficient - * to 'unstuck' the argument, a cyclic inference error is called out. - * - * A method check handler (see above) is used in order to report errors. + * Dummy method check object. All methods are deemed applicable, regardless + * of their formal parameter types. */ - MethodCheck resolveMethodCheck = new MethodCheck() { + MethodCheck nilMethodCheck = new MethodCheck() { + public void argumentsAcceptable(Env<AttrContext> env, DeferredAttrContext deferredAttrContext, List<Type> argtypes, List<Type> formals, Warner warn) { + //do nothing - method always applicable regardless of actuals + } + + public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { + return this; + } + }; + + /** + * Base class for 'real' method checks. The class defines the logic for + * iterating through formals and actuals and provides and entry point + * that can be used by subclasses in order to define the actual check logic. + */ + abstract class AbstractMethodCheck implements MethodCheck { @Override public void argumentsAcceptable(final Env<AttrContext> env, DeferredAttrContext deferredAttrContext, @@ -699,8 +703,7 @@ } while (argtypes.nonEmpty() && formals.head != varargsFormal) { - ResultInfo mresult = methodCheckResult(false, formals.head, deferredAttrContext, warn); - mresult.check(null, argtypes.head); + checkArg(false, argtypes.head, formals.head, deferredAttrContext, warn); argtypes = argtypes.tail; formals = formals.tail; } @@ -713,17 +716,19 @@ //note: if applicability check is triggered by most specific test, //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) final Type elt = types.elemtype(varargsFormal); - ResultInfo mresult = methodCheckResult(true, elt, deferredAttrContext, warn); while (argtypes.nonEmpty()) { - mresult.check(null, argtypes.head); + checkArg(true, argtypes.head, elt, deferredAttrContext, warn); argtypes = argtypes.tail; } - //check varargs element type accessibility - varargsAccessible(env, elt, inferenceContext); } } - private void reportMC(MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) { + /** + * Does the actual argument conforms to the corresponding formal? + */ + abstract void checkArg(boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn); + + protected void reportMC(MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) { boolean inferDiag = inferenceContext != infer.emptyContext; InapplicableMethodException ex = inferDiag ? infer.inferenceException : inapplicableMethodException; @@ -736,6 +741,63 @@ throw ex.setMessage(inferDiag ? diag.inferKey : diag.basicKey, args); } + public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { + return nilMethodCheck; + } + } + + /** + * Arity-based method check. A method is applicable if the number of actuals + * supplied conforms to the method signature. + */ + MethodCheck arityMethodCheck = new AbstractMethodCheck() { + @Override + void checkArg(boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { + //do nothing - actual always compatible to formals + } + }; + + /** + * Main method applicability routine. Given a list of actual types A, + * a list of formal types F, determines whether the types in A are + * compatible (by method invocation conversion) with the types in F. + * + * Since this routine is shared between overload resolution and method + * type-inference, a (possibly empty) inference context is used to convert + * formal types to the corresponding 'undet' form ahead of a compatibility + * check so that constraints can be propagated and collected. + * + * Moreover, if one or more types in A is a deferred type, this routine uses + * DeferredAttr in order to perform deferred attribution. If one or more actual + * deferred types are stuck, they are placed in a queue and revisited later + * after the remainder of the arguments have been seen. If this is not sufficient + * to 'unstuck' the argument, a cyclic inference error is called out. + * + * A method check handler (see above) is used in order to report errors. + */ + MethodCheck resolveMethodCheck = new AbstractMethodCheck() { + + @Override + void checkArg(boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { + ResultInfo mresult = methodCheckResult(varargs, formal, deferredAttrContext, warn); + mresult.check(null, actual); + } + + @Override + public void argumentsAcceptable(final Env<AttrContext> env, + DeferredAttrContext deferredAttrContext, + List<Type> argtypes, + List<Type> formals, + Warner warn) { + super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn); + //should we expand formals? + if (deferredAttrContext.phase.isVarargsRequired()) { + //check varargs element type accessibility + varargsAccessible(env, types.elemtype(formals.last()), + deferredAttrContext.inferenceContext); + } + } + private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) { if (inferenceContext.free(t)) { inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() { @@ -765,6 +827,11 @@ }; return new MethodResultInfo(to, checkContext); } + + @Override + public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { + return new MostSpecificCheck(strict, actuals); + } }; /** @@ -1042,6 +1109,11 @@ } } } + + public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { + Assert.error("Cannot get here!"); + return null; + } } public static class InapplicableMethodException extends RuntimeException { @@ -1254,7 +1326,7 @@ Assert.check(sym.kind < AMBIGUOUS); try { Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes, - allowBoxing, useVarargs, resolveMethodCheck, types.noWarnings); + allowBoxing, useVarargs, types.noWarnings); if (!operator) currentResolutionContext.addApplicableCandidate(sym, mt); } catch (InapplicableMethodException ex) { @@ -1358,11 +1430,20 @@ int maxLength = Math.max( Math.max(m1.type.getParameterTypes().length(), actuals.length()), m2.type.getParameterTypes().length()); - Type mst = instantiate(env, site, m2, null, - adjustArgs(types.lowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null, - allowBoxing, useVarargs, new MostSpecificCheck(!allowBoxing, actuals), noteWarner); - return mst != null && - !noteWarner.hasLint(Lint.LintCategory.UNCHECKED); + MethodResolutionContext prevResolutionContext = currentResolutionContext; + try { + currentResolutionContext = new MethodResolutionContext(); + currentResolutionContext.step = prevResolutionContext.step; + currentResolutionContext.methodCheck = + prevResolutionContext.methodCheck.mostSpecificCheck(actuals, !allowBoxing); + Type mst = instantiate(env, site, m2, null, + adjustArgs(types.lowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null, + allowBoxing, useVarargs, noteWarner); + return mst != null && + !noteWarner.hasLint(Lint.LintCategory.UNCHECKED); + } finally { + currentResolutionContext = prevResolutionContext; + } } private List<Type> adjustArgs(List<Type> args, Symbol msym, int length, boolean allowVarargs) { if ((msym.flags() & VARARGS) != 0 && allowVarargs) { @@ -2124,14 +2205,14 @@ Name name, List<Type> argtypes, List<Type> typeargtypes) { - return lookupMethod(env, pos, env.enclClass.sym, new BasicLookupHelper(name, env.enclClass.sym.type, argtypes, typeargtypes) { - @Override - Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { - return findFun(env, name, argtypes, typeargtypes, - phase.isBoxingRequired(), - phase.isVarargsRequired()); - } - }); + return lookupMethod(env, pos, env.enclClass.sym, resolveMethodCheck, + new BasicLookupHelper(name, env.enclClass.sym.type, argtypes, typeargtypes) { + @Override + Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { + return findFun(env, name, argtypes, typeargtypes, + phase.isBoxingRequired(), + phase.isVarargsRequired()); + }}); } /** Resolve a qualified method identifier @@ -2313,36 +2394,36 @@ Type site, List<Type> argtypes, List<Type> typeargtypes) { - return lookupMethod(env, pos, site.tsym, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) { - @Override - Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { - return findDiamond(env, site, argtypes, typeargtypes, - phase.isBoxingRequired(), - phase.isVarargsRequired()); - } - @Override - Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { - if (sym.kind >= AMBIGUOUS) { - final JCDiagnostic details = sym.kind == WRONG_MTH ? - ((InapplicableSymbolError)sym).errCandidate().details : - null; - sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) { - @Override - JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, - Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { - String key = details == null ? - "cant.apply.diamond" : - "cant.apply.diamond.1"; - return diags.create(dkind, log.currentSource(), pos, key, - diags.fragment("diamond", site.tsym), details); + return lookupMethod(env, pos, site.tsym, resolveMethodCheck, + new BasicLookupHelper(names.init, site, argtypes, typeargtypes) { + @Override + Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { + return findDiamond(env, site, argtypes, typeargtypes, + phase.isBoxingRequired(), + phase.isVarargsRequired()); + } + @Override + Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) { + if (sym.kind >= AMBIGUOUS) { + final JCDiagnostic details = sym.kind == WRONG_MTH ? + ((InapplicableSymbolError)sym).errCandidate().details : + null; + sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) { + @Override + JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, + Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { + String key = details == null ? + "cant.apply.diamond" : + "cant.apply.diamond.1"; + return diags.create(dkind, log.currentSource(), pos, key, + diags.fragment("diamond", site.tsym), details); + } + }; + sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes); + env.info.pendingResolutionPhase = currentResolutionContext.step; } - }; - sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes); - env.info.pendingResolutionPhase = currentResolutionContext.step; - } - return sym; - } - }); + return sym; + }}); } /** This method scans all the constructor symbol in a given class scope - @@ -2475,7 +2556,8 @@ Type site, Name name, List<Type> argtypes, List<Type> typeargtypes, - boolean boxingAllowed) { + boolean boxingAllowed, + MethodCheck methodCheck) { MethodResolutionPhase maxPhase = boxingAllowed ? VARARITY : BASIC; ReferenceLookupHelper boundLookupHelper; @@ -2495,12 +2577,12 @@ //step 1 - bound lookup Env<AttrContext> boundEnv = env.dup(env.tree, env.info.dup()); - Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(), site.tsym, boundLookupHelper); + Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(), site.tsym, methodCheck, boundLookupHelper); //step 2 - unbound lookup ReferenceLookupHelper unboundLookupHelper = boundLookupHelper.unboundLookup(); Env<AttrContext> unboundEnv = env.dup(env.tree, env.info.dup()); - Symbol unboundSym = lookupMethod(unboundEnv, env.tree.pos(), site.tsym, unboundLookupHelper); + Symbol unboundSym = lookupMethod(unboundEnv, env.tree.pos(), site.tsym, methodCheck, unboundLookupHelper); //merge results Pair<Symbol, ReferenceLookupHelper> res; @@ -2671,7 +2753,7 @@ ReferenceLookupHelper unboundLookup() { if (TreeInfo.isStaticSelector(referenceTree.expr, names) && argtypes.nonEmpty() && - types.isSubtypeUnchecked(argtypes.head, site)) { + (argtypes.head.hasTag(NONE) || types.isSubtypeUnchecked(argtypes.head, site))) { return new UnboundMethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase); } else { @@ -2704,8 +2786,8 @@ UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) { super(referenceTree, name, site, argtypes.tail, typeargtypes, maxPhase); - Type asSuperSite = types.asSuper(argtypes.head, site.tsym); - if (site.isRaw() && !asSuperSite.isErroneous()) { + if (site.isRaw() && !argtypes.head.hasTag(NONE)) { + Type asSuperSite = types.asSuper(argtypes.head, site.tsym); this.site = asSuperSite; } } @@ -2800,8 +2882,10 @@ * at the end of the lookup, the helper is used to validate the results * (this last step might trigger overload resolution diagnostics). */ - Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, LookupHelper lookupHelper) { - return lookupMethod(env, pos, location, new MethodResolutionContext(), lookupHelper); + Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, MethodCheck methodCheck, LookupHelper lookupHelper) { + MethodResolutionContext resolveContext = new MethodResolutionContext(); + resolveContext.methodCheck = methodCheck; + return lookupMethod(env, pos, location, resolveContext, lookupHelper); } Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, @@ -3520,6 +3604,11 @@ } @Override + public Symbol baseSymbol() { + return delegatedError.baseSymbol(); + } + + @Override protected Symbol access(Name name, TypeSymbol location) { return delegatedError.access(name, location); } @@ -3595,6 +3684,8 @@ MethodResolutionPhase step = null; + MethodCheck methodCheck = resolveMethodCheck; + private boolean internalResolution = false; private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE;
--- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Fri Sep 27 15:41:28 2013 +0100 @@ -40,6 +40,7 @@ import static com.sun.tools.javac.code.TypeTag.CLASS; import static com.sun.tools.javac.code.TypeTag.TYPEVAR; import static com.sun.tools.javac.code.TypeTag.VOID; +import static com.sun.tools.javac.comp.CompileStates.CompileState; /** This pass translates Generic Java to conventional Java. * @@ -77,8 +78,11 @@ */ private final boolean addBridges; + private final CompileStates compileStates; + protected TransTypes(Context context) { context.put(transTypesKey, this); + compileStates = CompileStates.instance(context); names = Names.instance(context); log = Log.instance(context); syms = Symtab.instance(context); @@ -706,8 +710,18 @@ public void visitTypeCast(JCTypeCast tree) { tree.clazz = translate(tree.clazz, null); + Type originalTarget = tree.type; tree.type = erasure(tree.type); tree.expr = translate(tree.expr, tree.type); + if (originalTarget.isCompound()) { + Type.IntersectionClassType ict = (Type.IntersectionClassType)originalTarget; + for (Type c : ict.getExplicitComponents()) { + Type ec = erasure(c); + if (!types.isSameType(ec, tree.type)) { + tree.expr = coerce(tree.expr, ec); + } + } + } result = tree; } @@ -904,16 +918,40 @@ private Env<AttrContext> env; + private static final String statePreviousToFlowAssertMsg = + "The current compile state [%s] of class %s is previous to FLOW"; + void translateClass(ClassSymbol c) { Type st = types.supertype(c.type); - // process superclass before derived - if (st.hasTag(CLASS)) + if (st.hasTag(CLASS)) { translateClass((ClassSymbol)st.tsym); + } Env<AttrContext> myEnv = enter.typeEnvs.remove(c); - if (myEnv == null) + if (myEnv == null) { return; + } + + /* The two assertions below are set for early detection of any attempt + * to translate a class that: + * + * 1) has no compile state being it the most outer class. + * We accept this condition for inner classes. + * + * 2) has a compile state which is previous to Flow state. + */ + boolean envHasCompState = compileStates.get(myEnv) != null; + if (!envHasCompState && c.outermostClass() == c) { + Assert.error("No info for outermost class: " + myEnv.enclClass.sym); + } + + if (envHasCompState && + CompileState.FLOW.isAfter(compileStates.get(myEnv))) { + Assert.error(String.format(statePreviousToFlowAssertMsg, + compileStates.get(myEnv), myEnv.enclClass.sym)); + } + Env<AttrContext> oldEnv = env; try { env = myEnv;
--- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Fri Sep 27 15:41:28 2013 +0100 @@ -1016,7 +1016,8 @@ // log.errWriter.println("enter inner " + c);//DEBUG enterInner(c.owner.enclClass()); pool.put(c); - pool.put(c.name); + if (c.name != names.empty) + pool.put(c.name); if (innerClasses == null) { innerClasses = new HashSet<ClassSymbol>(); innerClassesQueue = new ListBuffer<ClassSymbol>();
--- a/src/share/classes/com/sun/tools/javac/jvm/Code.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java Fri Sep 27 15:41:28 2013 +0100 @@ -373,6 +373,17 @@ Assert.check(alive || state.stacksize == 0); } + /** Emit a ldc (or ldc_w) instruction, taking into account operand size + */ + public void emitLdc(int od) { + if (od <= 255) { + emitop1(ldc1, od); + } + else { + emitop2(ldc2, od); + } + } + /** Emit a multinewarray instruction. */ public void emitMultianewarray(int ndims, int type, Type arrayType) { @@ -459,7 +470,15 @@ public void emitInvokedynamic(int desc, Type mtype) { // N.B. this format is under consideration by the JSR 292 EG int argsize = width(mtype.getParameterTypes()); - emitop(invokedynamic); + int prevPos = pendingStatPos; + try { + //disable line number generation (we could have used 'emit1', that + //bypasses stackmap generation - which is needed for indy calls) + pendingStatPos = Position.NOPOS; + emitop(invokedynamic); + } finally { + pendingStatPos = prevPos; + } if (!alive) return; emit2(desc); emit2(0); @@ -1628,7 +1647,7 @@ State dup() { try { State state = (State)super.clone(); - state.defined = defined.dup(); + state.defined = new Bits(defined); state.stack = stack.clone(); if (locks != null) state.locks = locks.clone(); if (debugCode) { @@ -1756,7 +1775,7 @@ } State join(State other) { - defined = defined.andSet(other.defined); + defined.andSet(other.defined); Assert.check(stacksize == other.stacksize && nlocks == other.nlocks); for (int i=0; i<stacksize; ) { @@ -1868,7 +1887,7 @@ /** Set the current variable defined state. */ public void setDefined(Bits newDefined) { if (alive && newDefined != state.defined) { - Bits diff = state.defined.dup().xorSet(newDefined); + Bits diff = new Bits(state.defined).xorSet(newDefined); for (int adr = diff.nextBit(0); adr >= 0; adr = diff.nextBit(adr+1)) {
--- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Fri Sep 27 15:41:28 2013 +0100 @@ -1748,10 +1748,13 @@ // Generate code for all arguments, where the expected types are // the parameters of the method's external type (that is, any implicit // outer instance of a super(...) call appears as first parameter). + MethodSymbol msym = (MethodSymbol)TreeInfo.symbol(tree.meth); genArgs(tree.args, - TreeInfo.symbol(tree.meth).externalType(types).getParameterTypes()); - code.statBegin(tree.pos); - code.markStatBegin(); + msym.externalType(types).getParameterTypes()); + if (!msym.isDynamic()) { + code.statBegin(tree.pos); + code.markStatBegin(); + } result = m.invoke(); } @@ -2227,7 +2230,7 @@ if (tree.name == names._class) { Assert.check(target.hasClassLiterals()); - code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type)); + code.emitLdc(makeRef(tree.pos(), tree.selected.type)); result = items.makeStackItem(pt); return; }
--- a/src/share/classes/com/sun/tools/javac/jvm/Items.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/jvm/Items.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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 @@ -571,10 +571,8 @@ int idx = pool.put(value); if (typecode == LONGcode || typecode == DOUBLEcode) { code.emitop2(ldc2w, idx); - } else if (idx <= 255) { - code.emitop1(ldc1, idx); } else { - code.emitop2(ldc2, idx); + code.emitLdc(idx); } }
--- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Fri Sep 27 15:41:28 2013 +0100 @@ -25,6 +25,7 @@ package com.sun.tools.javac.main; +import com.sun.tools.javac.comp.CompileStates; import java.io.*; import java.util.HashMap; import java.util.HashSet; @@ -61,6 +62,7 @@ import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.util.*; +import com.sun.tools.javac.comp.CompileStates.CompileState; import com.sun.tools.javac.util.Log.WriterKind; import static com.sun.tools.javac.code.TypeTag.CLASS; @@ -326,6 +328,8 @@ **/ protected boolean implicitSourceFilesRead; + protected CompileStates compileStates; + /** Construct a new compiler using a shared context. */ public JavaCompiler(Context context) { @@ -348,6 +352,7 @@ fileManager = context.get(JavaFileManager.class); parserFactory = ParserFactory.instance(context); + compileStates = CompileStates.instance(context); try { // catch completion problems with predefineds @@ -521,42 +526,6 @@ */ public List<Closeable> closeables = List.nil(); - /** Ordered list of compiler phases for each compilation unit. */ - public enum CompileState { - INIT(0), - PARSE(1), - ENTER(2), - PROCESS(3), - ATTR(4), - FLOW(5), - TRANSTYPES(6), - UNLAMBDA(7), - LOWER(8), - GENERATE(9); - - CompileState(int value) { - this.value = value; - } - boolean isAfter(CompileState other) { - return value > other.value; - } - public static CompileState max(CompileState a, CompileState b) { - return a.value > b.value ? a : b; - } - private final int value; - }; - /** Partial map to record which compiler phases have been executed - * for each compilation unit. Used for ATTR and FLOW phases. - */ - protected class CompileStates extends HashMap<Env<AttrContext>,CompileState> { - private static final long serialVersionUID = 1812267524140424433L; - boolean isDone(Env<AttrContext> env, CompileState cs) { - CompileState ecs = get(env); - return (ecs != null) && !cs.isAfter(ecs); - } - } - private CompileStates compileStates = new CompileStates(); - /** The set of currently compiled inputfiles, needed to ensure * we don't accidentally overwrite an input file when -s is set. * initialized by `compile'. @@ -1395,13 +1364,17 @@ @Override public void visitClassDef(JCClassDecl node) { Type st = types.supertype(node.sym.type); - if (st.hasTag(CLASS)) { + boolean envForSuperTypeFound = false; + while (!envForSuperTypeFound && st.hasTag(CLASS)) { ClassSymbol c = st.tsym.outermostClass(); Env<AttrContext> stEnv = enter.getEnv(c); if (stEnv != null && env != stEnv) { - if (dependencies.add(stEnv)) + if (dependencies.add(stEnv)) { scan(stEnv.tree); + } + envForSuperTypeFound = true; } + st = types.supertype(st); } super.visitClassDef(node); }
--- a/src/share/classes/com/sun/tools/javac/main/Main.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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 @@ -497,6 +497,8 @@ if (!(doclintOpts.size() == 1 && doclintOpts.iterator().next().equals(DocLint.XMSGS_CUSTOM_PREFIX + "none"))) { JavacTask t = BasicJavacTask.instance(context); + // standard doclet normally generates H1, H2 + doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); new DocLint().init(t, doclintOpts.toArray(new String[doclintOpts.size()])); comp.keepComments = true; }
--- a/src/share/classes/com/sun/tools/javac/model/JavacAnnoConstructs.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/model/JavacAnnoConstructs.java Fri Sep 27 15:41:28 2013 +0100 @@ -33,10 +33,13 @@ import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.ClassSymbol; +import com.sun.tools.javac.code.Symbol.TypeVariableSymbol; +import com.sun.tools.javac.code.TargetType; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type.AnnotatedType; import com.sun.tools.javac.util.ListBuffer; import static com.sun.tools.javac.code.TypeTag.CLASS; +import com.sun.tools.javac.util.List; /** * Utility methods for operating on annotated constructs. @@ -61,8 +64,12 @@ throw new IllegalArgumentException("Not an annotation type: " + annoType); Attribute.Compound c; - if (annotated.kind == Kinds.TYP && annotated instanceof ClassSymbol) { + if (annotated.kind == Kinds.TYP && + annotated instanceof ClassSymbol) { c = getAttributeOnClass((ClassSymbol)annotated, annoType); + } else if (annotated.kind == Kinds.TYP && + annotated instanceof TypeVariableSymbol) { + c = getAttributeOnTypeVariable((TypeVariableSymbol)annotated, annoType); } else { c = getAttribute(annotated, annoType); } @@ -83,6 +90,24 @@ } // Helper to getAnnotation[s] + private static <A extends Annotation> Attribute.Compound + getAttributeOnTypeVariable(TypeVariableSymbol annotated, Class<A> annoType) { + String name = annoType.getName(); + + // Declaration annotations on type variables are stored in type attributes + // on the owner of the TypeVariableSymbol + List<Attribute.Compound> res = List.nil(); + List<Attribute.TypeCompound> candidates = annotated.owner.getRawTypeAttributes(); + for (Attribute.TypeCompound anno : candidates) + if (anno.position.type == TargetType.CLASS_TYPE_PARAMETER || + anno.position.type == TargetType.METHOD_TYPE_PARAMETER) + if (name.equals(anno.type.tsym.flatName().toString())) + return anno; + + return null; + } + + // Helper to getAnnotation[s] private static <A extends Annotation> Attribute.Compound getAttributeOnClass(ClassSymbol annotated, Class<A> annoType) { boolean inherited = annoType.isAnnotationPresent(Inherited.class);
--- a/src/share/classes/com/sun/tools/javac/model/JavacElements.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/model/JavacElements.java Fri Sep 27 15:41:28 2013 +0100 @@ -402,9 +402,10 @@ * @param e the element being examined * @return all annotations of the element */ + @Override public List<Attribute.Compound> getAllAnnotationMirrors(Element e) { Symbol sym = cast(Symbol.class, e); - List<Attribute.Compound> annos = sym.getRawAttributes(); + List<Attribute.Compound> annos = sym.getAnnotationMirrors(); while (sym.getKind() == ElementKind.CLASS) { Type sup = ((ClassSymbol) sym).getSuperclass(); if (!sup.hasTag(CLASS) || sup.isErroneous() || @@ -413,7 +414,7 @@ } sym = sup.tsym; List<Attribute.Compound> oldAnnos = annos; - List<Attribute.Compound> newAnnos = sym.getRawAttributes(); + List<Attribute.Compound> newAnnos = sym.getAnnotationMirrors(); for (Attribute.Compound anno : newAnnos) { if (isInherited(anno.type) && !containsAnnoOfType(oldAnnos, anno.type)) {
--- a/src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java Fri Sep 27 15:41:28 2013 +0100 @@ -41,6 +41,7 @@ import com.sun.tools.javac.tree.DCTree.DCAttribute; import com.sun.tools.javac.tree.DCTree.DCDocComment; import com.sun.tools.javac.tree.DCTree.DCEndElement; +import com.sun.tools.javac.tree.DCTree.DCEndPosTree; import com.sun.tools.javac.tree.DCTree.DCErroneous; import com.sun.tools.javac.tree.DCTree.DCIdentifier; import com.sun.tools.javac.tree.DCTree.DCReference; @@ -336,12 +337,12 @@ DCTree text = inlineText(); if (text != null) { nextChar(); - return m.at(p).UnknownInlineTag(name, List.of(text)); + return m.at(p).UnknownInlineTag(name, List.of(text)).setEndPos(bp); } } else if (tp.getKind() == TagParser.Kind.INLINE) { - DCTree tree = tp.parse(p); + DCEndPosTree<?> tree = (DCEndPosTree<?>) tp.parse(p); if (tree != null) { - return tree; + return tree.setEndPos(bp); } } else { inlineText(); // skip content @@ -509,7 +510,7 @@ fac.log.popDiagnosticHandler(deferredDiagnosticHandler); } - return m.at(pos).Reference(sig, qualExpr, member, paramTypes); + return m.at(pos).Reference(sig, qualExpr, member, paramTypes).setEndPos(bp); } JCTree parseType(String s) throws ParseException { @@ -741,7 +742,7 @@ } if (ch == '>') { nextChar(); - return m.at(p).StartElement(name, attrs, selfClosing); + return m.at(p).StartElement(name, attrs, selfClosing).setEndPos(bp); } } } else if (ch == '/') {
--- a/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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 @@ -770,7 +770,7 @@ * (which is treated as the beginning of the first line). * Stops positioned at the closing '/'. */ - protected class BasicComment<U extends UnicodeReader> implements Comment { + protected static class BasicComment<U extends UnicodeReader> implements Comment { CommentStyle cs; U comment_reader;
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri Sep 27 15:41:28 2013 +0100 @@ -171,8 +171,8 @@ protected AbstractEndPosTable newEndPosTable(boolean keepEndPositions) { return keepEndPositions - ? new SimpleEndPosTable() - : new EmptyEndPosTable(); + ? new SimpleEndPosTable(this) + : new EmptyEndPosTable(this); } protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFactory fac) { @@ -3088,6 +3088,7 @@ toplevel.docComments = docComments; if (keepLineMap) toplevel.lineMap = S.getLineMap(); + this.endPosTable.setParser(null); // remove reference to parser toplevel.endPositions = this.endPosTable; return toplevel; } @@ -4003,11 +4004,12 @@ /* * a functional source tree and end position mappings */ - protected class SimpleEndPosTable extends AbstractEndPosTable { + protected static class SimpleEndPosTable extends AbstractEndPosTable { private final Map<JCTree, Integer> endPosMap; - SimpleEndPosTable() { + SimpleEndPosTable(JavacParser parser) { + super(parser); endPosMap = new HashMap<JCTree, Integer>(); } @@ -4016,12 +4018,12 @@ } protected <T extends JCTree> T to(T t) { - storeEnd(t, token.endPos); + storeEnd(t, parser.token.endPos); return t; } protected <T extends JCTree> T toP(T t) { - storeEnd(t, S.prevToken().endPos); + storeEnd(t, parser.S.prevToken().endPos); return t; } @@ -4043,7 +4045,11 @@ /* * a default skeletal implementation without any mapping overhead. */ - protected class EmptyEndPosTable extends AbstractEndPosTable { + protected static class EmptyEndPosTable extends AbstractEndPosTable { + + EmptyEndPosTable(JavacParser parser) { + super(parser); + } protected void storeEnd(JCTree tree, int endpos) { /* empty */ } @@ -4065,13 +4071,21 @@ } - protected abstract class AbstractEndPosTable implements EndPosTable { + protected static abstract class AbstractEndPosTable implements EndPosTable { + /** + * The current parser. + */ + protected JavacParser parser; /** * Store the last error position. */ protected int errorEndPos; + public AbstractEndPosTable(JavacParser parser) { + this.parser = parser; + } + /** * Store ending position for a tree, the value of which is the greater * of last error position and the given ending position. @@ -4106,5 +4120,9 @@ errorEndPos = errPos; } } + + protected void setParser(JavacParser parser) { + this.parser = parser; + } } }
--- a/src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java Fri Sep 27 15:41:28 2013 +0100 @@ -206,7 +206,7 @@ } } - protected class JavadocComment extends JavaTokenizer.BasicComment<DocReader> { + protected static class JavadocComment extends JavaTokenizer.BasicComment<DocReader> { /** * Translated and stripped contents of doc comment
--- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Fri Sep 27 15:41:28 2013 +0100 @@ -59,7 +59,6 @@ import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.jvm.ClassReader.BadClassFile; import com.sun.tools.javac.main.JavaCompiler; -import com.sun.tools.javac.main.JavaCompiler.CompileState; import com.sun.tools.javac.model.JavacElements; import com.sun.tools.javac.model.JavacTypes; import com.sun.tools.javac.parser.*; @@ -79,6 +78,7 @@ import com.sun.tools.javac.util.Options; import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING; import static com.sun.tools.javac.main.Option.*; +import static com.sun.tools.javac.comp.CompileStates.CompileState; import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag.*; /**
--- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Sep 27 15:41:28 2013 +0100 @@ -216,9 +216,14 @@ compiler.misc.no.suitable.functional.intf.inst=\ cannot infer functional interface descriptor for {0} +# 0: message segment +compiler.misc.bad.intersection.target.for.functional.expr=\ + bad intersection type target for lambda or method reference\n\ + {0} + # 0: type -compiler.misc.secondary.bound.must.be.marker.intf=\ - secondary bound {0} must be a marker interface +compiler.misc.not.an.intf.component=\ + component type {0} is not an interface # 0: symbol kind, 1: message segment compiler.err.invalid.mref=\ @@ -731,6 +736,11 @@ compiler.misc.incompatible.arg.types.in.mref=\ incompatible parameter types in method reference +# 0: list of type +compiler.misc.bad.arg.types.in.lambda=\ + cannot type-check lambda expression with inferred parameter types\n\ + inferred types: {0} + compiler.err.new.not.allowed.in.annotation=\ ''new'' not allowed in an annotation
--- a/src/share/classes/com/sun/tools/javac/tree/DCTree.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/tree/DCTree.java Fri Sep 27 15:41:28 2013 +0100 @@ -36,6 +36,7 @@ import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Name; +import com.sun.tools.javac.util.Position; import java.io.IOException; import java.io.StringWriter; import javax.tools.JavaFileObject; @@ -82,8 +83,24 @@ return s.toString(); } + public static abstract class DCEndPosTree<T extends DCEndPosTree<T>> extends DCTree { + + private int endPos = Position.NOPOS; + + public int getEndPos(DCDocComment dc) { + return dc.comment.getSourcePos(endPos); + } + + @SuppressWarnings("unchecked") + public T setEndPos(int endPos) { + this.endPos = endPos; + return (T) this; + } + + } + public static class DCDocComment extends DCTree implements DocCommentTree { - final Comment comment; // required for the implicit source pos table + public final Comment comment; // required for the implicit source pos table public final List<DCTree> firstSentence; public final List<DCTree> body; @@ -125,7 +142,7 @@ } } - public static abstract class DCInlineTag extends DCTree implements InlineTagTree { + public static abstract class DCInlineTag extends DCEndPosTree<DCInlineTag> implements InlineTagTree { public String getTagName() { return getKind().tagName; } @@ -345,6 +362,7 @@ public int getEndPosition(EndPosTable endPosTable) { return pos + body.length(); } + } public static class DCIdentifier extends DCTree implements IdentifierTree { @@ -478,7 +496,7 @@ } } - public static class DCReference extends DCTree implements ReferenceTree { + public static class DCReference extends DCEndPosTree<DCReference> implements ReferenceTree { public final String signature; // The following are not directly exposed through ReferenceTree @@ -663,7 +681,7 @@ } } - public static class DCStartElement extends DCTree implements StartElementTree { + public static class DCStartElement extends DCEndPosTree<DCStartElement> implements StartElementTree { public final Name name; public final List<DCTree> attrs; public final boolean selfClosing;
--- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Fri Sep 27 15:41:28 2013 +0100 @@ -249,23 +249,6 @@ } } - /** Return true if a a tree corresponds to a poly expression. */ - public static boolean isPoly(JCTree tree, JCTree origin) { - switch (tree.getTag()) { - case APPLY: - case NEWCLASS: - case CONDEXPR: - return !origin.hasTag(TYPECAST); - case LAMBDA: - case REFERENCE: - return true; - case PARENS: - return isPoly(((JCParens)tree).expr, origin); - default: - return false; - } - } - /** set 'polyKind' on given tree */ public static void setPolyKind(JCTree tree, PolyKind pkind) { switch (tree.getTag()) {
--- a/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2013, 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 @@ -112,9 +112,8 @@ protected ClassLoader getClassLoader(URL[] urls) { ClassLoader thisClassLoader = getClass().getClassLoader(); - // Bug: 6558476 - // Ideally, ClassLoader should be Closeable, but before JDK7 it is not. - // On older versions, try the following, to get a closeable classloader. + // Allow the following to specify a closeable classloader + // other than URLClassLoader. // 1: Allow client to specify the class to use via hidden option if (classLoaderClass != null) { @@ -128,19 +127,6 @@ // ignore errors loading user-provided class loader, fall through } } - - // 2: If URLClassLoader implements Closeable, use that. - if (Closeable.class.isAssignableFrom(URLClassLoader.class)) - return new URLClassLoader(urls, thisClassLoader); - - // 3: Try using private reflection-based CloseableURLClassLoader - try { - return new CloseableURLClassLoader(urls, thisClassLoader); - } catch (Throwable t) { - // ignore errors loading workaround class loader, fall through - } - - // 4: If all else fails, use plain old standard URLClassLoader return new URLClassLoader(urls, thisClassLoader); }
--- a/src/share/classes/com/sun/tools/javac/util/Bits.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/util/Bits.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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,8 @@ import java.util.Arrays; +import static com.sun.tools.javac.util.Bits.BitsOpKind.*; + /** A class for extensible, mutable bit sets. * * <p><b>This is NOT part of any supported API. @@ -36,31 +38,114 @@ */ public class Bits { + public enum BitsOpKind { + INIT, + CLEAR, + INCL_BIT, + EXCL_BIT, + ASSIGN, + AND_SET, + OR_SET, + DIFF_SET, + XOR_SET, + INCL_RANGE, + EXCL_RANGE, + } + + // ____________ reset _________ + // / UNKNOWN \ <-------- / UNINIT \ + // \____________/ | \_________/ + // | | | + // |assign | | any + // | ___________ | + // ------> / NORMAL \ <---- + // \___________/ | + // | | + // | | + // ----------- + // any + private enum BitsState { + /* A Bits instance is in UNKNOWN state if it has been explicitly reset. + * It is possible to get to this state from any other by calling the + * reset method. An instance in the UNKNOWN state can pass to the + * NORMAL state after being assigned another Bits instance. + */ + UNKNOWN, + /* A Bits instance is in UNINIT when it is created with the default + * constructor but it isn't explicitly reset. The main objective of this + * internal state is to save some memory. + */ + UNINIT, + /* The normal state is reached after creating a Bits instance from an + * existing one or after applying any operation to an instance on UNINIT + * or NORMAL state. From this state a bits instance can pass to the + * UNKNOWN state by calling the reset method. + */ + NORMAL; + + static BitsState getState(int[] someBits, boolean reset) { + if (reset) { + return UNKNOWN; + } else { + if (someBits != unassignedBits) { + return NORMAL; + } else { + return UNINIT; + } + } + } + + } private final static int wordlen = 32; private final static int wordshift = 5; private final static int wordmask = wordlen - 1; - private int[] bits; + public int[] bits = null; + // This field will store last version of bits after every change. + public int[] oldBits = null; + + public BitsOpKind lastOperation = null; + + private static final int[] unassignedBits = new int[0]; + + private BitsState currentState; /** Construct an initially empty set. */ public Bits() { - this(new int[1]); + this(false); + } + + public Bits(Bits someBits) { + this(someBits.dup().bits, BitsState.getState(someBits.bits, false)); + } + + public Bits(boolean reset) { + this(unassignedBits, BitsState.getState(unassignedBits, reset)); } /** Construct a set consisting initially of given bit vector. */ - public Bits(int[] bits) { + private Bits(int[] bits, BitsState initState) { this.bits = bits; + this.currentState = initState; + switch (initState) { + case UNKNOWN: + reset(); //this will also set current state; + break; + case NORMAL: + Assert.check(bits != unassignedBits); + lastOperation = INIT; + break; + } } - /** Construct a set consisting initially of given range. + /** This method will be called after any operation that causes a change to + * the bits. Subclasses can thus override it in order to extract information + * from the changes produced to the bits by the given operation. */ - public Bits(int start, int limit) { - this(); - inclRange(start, limit); - } + public void changed() {} private void sizeTo(int len) { if (bits.length < len) { @@ -71,57 +156,110 @@ /** This set = {}. */ public void clear() { + Assert.check(currentState != BitsState.UNKNOWN); + oldBits = bits; + lastOperation = CLEAR; for (int i = 0; i < bits.length; i++) bits[i] = 0; + changed(); + currentState = BitsState.NORMAL; + } + + public void reset() { + bits = null; + oldBits = null; + currentState = BitsState.UNKNOWN; + } + + public boolean isReset() { + return currentState == BitsState.UNKNOWN; + } + + public Bits assign(Bits someBits) { + lastOperation = ASSIGN; + oldBits = bits; + bits = someBits.dup().bits; + changed(); + currentState = BitsState.NORMAL; + return this; } /** Return a copy of this set. */ - public Bits dup() { - int[] newbits = new int[bits.length]; - System.arraycopy(bits, 0, newbits, 0, bits.length); - return new Bits(newbits); + private Bits dup() { + Assert.check(currentState != BitsState.UNKNOWN); + Bits tmp = new Bits(); + if (currentState != BitsState.NORMAL) { + tmp.bits = bits; + } else { + tmp.bits = new int[bits.length]; + System.arraycopy(bits, 0, tmp.bits, 0, bits.length); + } + currentState = BitsState.NORMAL; + return tmp; } /** Include x in this set. */ public void incl(int x) { + Assert.check(currentState != BitsState.UNKNOWN); Assert.check(x >= 0); + oldBits = bits; + lastOperation = INCL_BIT; sizeTo((x >>> wordshift) + 1); bits[x >>> wordshift] = bits[x >>> wordshift] | (1 << (x & wordmask)); + changed(); + currentState = BitsState.NORMAL; } /** Include [start..limit) in this set. */ public void inclRange(int start, int limit) { + Assert.check(currentState != BitsState.UNKNOWN); + oldBits = bits; + lastOperation = INCL_RANGE; sizeTo((limit >>> wordshift) + 1); - for (int x = start; x < limit; x++) + for (int x = start; x < limit; x++) { bits[x >>> wordshift] = bits[x >>> wordshift] | (1 << (x & wordmask)); + } + changed(); + currentState = BitsState.NORMAL; } /** Exclude [start...end] from this set. */ public void excludeFrom(int start) { + Assert.check(currentState != BitsState.UNKNOWN); + oldBits = bits; + lastOperation = EXCL_RANGE; Bits temp = new Bits(); temp.sizeTo(bits.length); temp.inclRange(0, start); - andSet(temp); + internalAndSet(temp); + changed(); + currentState = BitsState.NORMAL; } /** Exclude x from this set. */ public void excl(int x) { + Assert.check(currentState != BitsState.UNKNOWN); Assert.check(x >= 0); + oldBits = bits; + lastOperation = EXCL_BIT; sizeTo((x >>> wordshift) + 1); bits[x >>> wordshift] = bits[x >>> wordshift] & ~(1 << (x & wordmask)); + changed(); + currentState = BitsState.NORMAL; } /** Is x an element of this set? */ public boolean isMember(int x) { + Assert.check(currentState != BitsState.UNKNOWN); return 0 <= x && x < (bits.length << wordshift) && (bits[x >>> wordshift] & (1 << (x & wordmask))) != 0; @@ -130,38 +268,66 @@ /** {@literal this set = this set & xs}. */ public Bits andSet(Bits xs) { + Assert.check(currentState != BitsState.UNKNOWN); + oldBits = bits; + lastOperation = AND_SET; + internalAndSet(xs); + changed(); + currentState = BitsState.NORMAL; + return this; + } + + private void internalAndSet(Bits xs) { + Assert.check(currentState != BitsState.UNKNOWN); sizeTo(xs.bits.length); - for (int i = 0; i < xs.bits.length; i++) + for (int i = 0; i < xs.bits.length; i++) { bits[i] = bits[i] & xs.bits[i]; - return this; + } } /** this set = this set | xs. */ public Bits orSet(Bits xs) { + Assert.check(currentState != BitsState.UNKNOWN); + oldBits = bits; + lastOperation = OR_SET; sizeTo(xs.bits.length); - for (int i = 0; i < xs.bits.length; i++) + for (int i = 0; i < xs.bits.length; i++) { bits[i] = bits[i] | xs.bits[i]; + } + changed(); + currentState = BitsState.NORMAL; return this; } /** this set = this set \ xs. */ public Bits diffSet(Bits xs) { + Assert.check(currentState != BitsState.UNKNOWN); + oldBits = bits; + lastOperation = DIFF_SET; for (int i = 0; i < bits.length; i++) { if (i < xs.bits.length) { bits[i] = bits[i] & ~xs.bits[i]; } } + changed(); + currentState = BitsState.NORMAL; return this; } /** this set = this set ^ xs. */ public Bits xorSet(Bits xs) { + Assert.check(currentState != BitsState.UNKNOWN); + oldBits = bits; + lastOperation = XOR_SET; sizeTo(xs.bits.length); - for (int i = 0; i < xs.bits.length; i++) + for (int i = 0; i < xs.bits.length; i++) { bits[i] = bits[i] ^ xs.bits[i]; + } + changed(); + currentState = BitsState.NORMAL; return this; } @@ -187,6 +353,7 @@ * }</pre> */ public int nextBit(int x) { + Assert.check(currentState != BitsState.UNKNOWN); int windex = x >>> wordshift; if (windex >= bits.length) return -1; int word = bits[windex] & ~((1 << (x & wordmask))-1); @@ -202,17 +369,20 @@ /** a string representation of this set. */ public String toString() { - char[] digits = new char[bits.length * wordlen]; - for (int i = 0; i < bits.length * wordlen; i++) - digits[i] = isMember(i) ? '1' : '0'; - return new String(digits); + if (bits.length > 0) { + char[] digits = new char[bits.length * wordlen]; + for (int i = 0; i < bits.length * wordlen; i++) + digits[i] = isMember(i) ? '1' : '0'; + return new String(digits); + } else { + return "[]"; + } } /** Test Bits.nextBit(int). */ public static void main(String[] args) { java.util.Random r = new java.util.Random(); Bits bits = new Bits(); - int dupCount = 0; for (int i=0; i<125; i++) { int k; do {
--- a/src/share/classes/com/sun/tools/javac/util/CloseableURLClassLoader.java Tue Aug 13 17:04:51 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2007, 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.util; - -import java.io.Closeable; -import java.io.IOException; -import java.lang.reflect.Field; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.jar.JarFile; - -/** - * A URLClassLoader that also implements Closeable. - * Reflection is used to access internal data structures in the URLClassLoader, - * since no public API exists for this purpose. Therefore this code is somewhat - * fragile. Caveat emptor. - * @throws Error if the internal data structures are not as expected. - * - * <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 CloseableURLClassLoader - extends URLClassLoader implements Closeable { - public CloseableURLClassLoader(URL[] urls, ClassLoader parent) throws Error { - super(urls, parent); - try { - getLoaders(); //proactive check that URLClassLoader is as expected - } catch (Throwable t) { - throw new Error("cannot create CloseableURLClassLoader", t); - } - } - - /** - * Close any jar files that may have been opened by the class loader. - * Reflection is used to access the jar files in the URLClassLoader's - * internal data structures. - * @throws java.io.IOException if the jar files cannot be found for any - * reson, or if closing the jar file itself causes an IOException. - */ - @Override - public void close() throws IOException { - try { - for (Object l: getLoaders()) { - if (l.getClass().getName().equals("sun.misc.URLClassPath$JarLoader")) { - Field jarField = l.getClass().getDeclaredField("jar"); - JarFile jar = (JarFile) getField(l, jarField); - if (jar != null) { - //System.err.println("CloseableURLClassLoader: closing " + jar); - jar.close(); - } - } - } - } catch (Throwable t) { - IOException e = new IOException("cannot close class loader"); - e.initCause(t); - throw e; - } - } - - private ArrayList<?> getLoaders() - throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException - { - Field ucpField = URLClassLoader.class.getDeclaredField("ucp"); - Object urlClassPath = getField(this, ucpField); - if (urlClassPath == null) - throw new AssertionError("urlClassPath not set in URLClassLoader"); - Field loadersField = urlClassPath.getClass().getDeclaredField("loaders"); - return (ArrayList<?>) getField(urlClassPath, loadersField); - } - - private Object getField(Object o, Field f) - throws IllegalArgumentException, IllegalAccessException { - boolean prev = f.isAccessible(); - try { - f.setAccessible(true); - return f.get(o); - } finally { - f.setAccessible(prev); - } - } - -}
--- a/src/share/classes/com/sun/tools/javac/util/Pair.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/util/Pair.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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,8 @@ package com.sun.tools.javac.util; +import java.util.Objects; + /** A generic class for pairs. * * <p><b>This is NOT part of any supported API. @@ -46,15 +48,11 @@ return "Pair[" + fst + "," + snd + "]"; } - private static boolean equals(Object x, Object y) { - return (x == null && y == null) || (x != null && x.equals(y)); - } - public boolean equals(Object other) { return other instanceof Pair<?,?> && - equals(fst, ((Pair<?,?>)other).fst) && - equals(snd, ((Pair<?,?>)other).snd); + Objects.equals(fst, ((Pair<?,?>)other).fst) && + Objects.equals(snd, ((Pair<?,?>)other).snd); } public int hashCode() {
--- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Fri Sep 27 15:41:28 2013 +0100 @@ -395,6 +395,9 @@ @Override public String visitClassSymbol(ClassSymbol s, Locale locale) { + if (s.type.isCompound()) { + return visit(s.type, locale); + } String name = nameSimplifier.simplify(s); if (name.length() == 0 || !getConfiguration().isEnabled(RichFormatterFeature.SIMPLE_NAMES)) { @@ -583,7 +586,11 @@ @Override public Void visitClassSymbol(ClassSymbol s, Void ignored) { - nameSimplifier.addUsage(s); + if (s.type.isCompound()) { + typePreprocessor.visit(s.type); + } else { + nameSimplifier.addUsage(s); + } return null; }
--- a/src/share/classes/com/sun/tools/javadoc/AbstractTypeImpl.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javadoc/AbstractTypeImpl.java Fri Sep 27 15:41:28 2013 +0100 @@ -61,6 +61,10 @@ return type.tsym.getQualifiedName().toString(); } + public com.sun.javadoc.Type getElementType() { + return null; + } + public String simpleTypeName() { return type.tsym.name.toString(); }
--- a/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java Fri Sep 27 15:41:28 2013 +0100 @@ -108,6 +108,10 @@ this.tsym = sym; } + public com.sun.javadoc.Type getElementType() { + return null; + } + /** * Returns the flags in terms of javac's flags */ @@ -337,9 +341,14 @@ * </pre> */ public String name() { - return getClassName(tsym, false); + if (name == null) { + name = getClassName(tsym, false); + } + return name; } + private String name; + /** * Return the qualified class name as a String. * <pre> @@ -350,9 +359,14 @@ * </pre> */ public String qualifiedName() { - return getClassName(tsym, true); + if (qualifiedName == null) { + qualifiedName = getClassName(tsym, true); + } + return qualifiedName; } + private String qualifiedName; + /** * Return unqualified name of type excluding any dimension information. * <p> @@ -376,9 +390,14 @@ * Return the simple name of this type. */ public String simpleTypeName() { - return tsym.name.toString(); + if (simpleTypeName == null) { + simpleTypeName = tsym.name.toString(); + } + return simpleTypeName; } + private String simpleTypeName; + /** * Return the qualified name and any type parameters. * Each parameter is a type variable with optional bounds.
--- a/src/share/classes/com/sun/tools/javadoc/DocEnv.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javadoc/DocEnv.java Fri Sep 27 15:41:28 2013 +0100 @@ -810,6 +810,8 @@ JavacTask t = BasicJavacTask.instance(context); doclint = new DocLint(); + // standard doclet normally generates H1, H2 + doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false); }
--- a/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java Fri Sep 27 15:41:28 2013 +0100 @@ -199,22 +199,15 @@ return result; } - public AnnotationDesc[] receiverAnnotations() { - // TODO: change how receiver annotations are output! + /** + * Get the receiver type of this executable element. + * + * @return the receiver type of this executable element. + * @since 1.8 + */ + public com.sun.javadoc.Type receiverType() { Type recvtype = sym.type.asMethodType().recvtype; - if (recvtype == null) { - return new AnnotationDesc[0]; - } - if (!recvtype.isAnnotated()) { - return new AnnotationDesc[0]; - } - List<? extends Compound> typeAnnos = ((com.sun.tools.javac.code.Type.AnnotatedType)recvtype).typeAnnotations; - AnnotationDesc result[] = new AnnotationDesc[typeAnnos.length()]; - int i = 0; - for (Attribute.Compound a : typeAnnos) { - result[i++] = new AnnotationDescImpl(env, a); - } - return result; + return (recvtype != null) ? TypeMaker.getType(env, recvtype, false, true) : null; } /**
--- a/src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javadoc/FieldDocImpl.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, 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 @@ -252,13 +252,23 @@ } public String name() { - return sym.name.toString(); + if (name == null) { + name = sym.name.toString(); + } + return name; } + private String name; + public String qualifiedName() { - return sym.enclClass().getQualifiedName() + "." + name(); + if (qualifiedName == null) { + qualifiedName = sym.enclClass().getQualifiedName() + "." + name(); + } + return qualifiedName; } + private String qualifiedName; + /** * Return the source position of the entity, or null if * no position is available.
--- a/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, 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 @@ -203,13 +203,23 @@ public String name() { - return sym.name.toString(); + if (name == null) { + name = sym.name.toString(); + } + return name; } + private String name; + public String qualifiedName() { - return sym.enclClass().getQualifiedName() + "." + sym.name; + if (qualifiedName == null) { + qualifiedName = sym.enclClass().getQualifiedName() + "." + sym.name; + } + return qualifiedName; } + private String qualifiedName; + /** * Returns a string representation of this method. Includes the * qualified signature, the qualified method name, and any type
--- a/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javadoc/PackageDocImpl.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2013, 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 @@ -334,12 +334,17 @@ * Get package name. */ public String qualifiedName() { - Name fullname = sym.getQualifiedName(); - // Some bogus tests depend on the interned "" being returned. - // See 6457276. - return fullname.isEmpty() ? "" : fullname.toString(); + if (qualifiedName == null) { + Name fullname = sym.getQualifiedName(); + // Some bogus tests depend on the interned "" being returned. + // See 6457276. + qualifiedName = fullname.isEmpty() ? "" : fullname.toString(); + } + return qualifiedName; } + private String qualifiedName; + /** * set doc path for an unzipped directory */
--- a/src/share/classes/com/sun/tools/javadoc/PrimitiveType.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javadoc/PrimitiveType.java Fri Sep 27 15:41:28 2013 +0100 @@ -63,6 +63,10 @@ return name; } + public com.sun.javadoc.Type getElementType() { + return null; + } + /** * Return qualified name of type excluding any dimension information. *<p>
--- a/src/share/classes/com/sun/tools/javadoc/TypeMaker.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/com/sun/tools/javadoc/TypeMaker.java Fri Sep 27 15:41:28 2013 +0100 @@ -222,6 +222,10 @@ private com.sun.javadoc.Type skipArraysCache = null; + public com.sun.javadoc.Type getElementType() { + return TypeMaker.getType(env, env.types.elemtype(arrayType)); + } + private com.sun.javadoc.Type skipArrays() { if (skipArraysCache == null) { Type t;
--- a/src/share/classes/javax/annotation/processing/AbstractProcessor.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/javax/annotation/processing/AbstractProcessor.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, 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.Set; import java.util.HashSet; import java.util.Collections; +import java.util.Objects; import javax.lang.model.element.*; import javax.lang.model.SourceVersion; import javax.tools.Diagnostic; @@ -146,8 +147,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) { if (initialized) throw new IllegalStateException("Cannot call init more than once."); - if (processingEnv == null) - throw new NullPointerException("Tool provided null ProcessingEnvironment"); + Objects.requireNonNull(processingEnv, "Tool provided null ProcessingEnvironment"); this.processingEnv = processingEnv; initialized = true;
--- a/src/share/classes/javax/lang/model/element/Modifier.java Tue Aug 13 17:04:51 2013 +0100 +++ b/src/share/classes/javax/lang/model/element/Modifier.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, 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 @@ -53,6 +53,11 @@ /** The modifier {@code protected} */ PROTECTED, /** The modifier {@code private} */ PRIVATE, /** The modifier {@code abstract} */ ABSTRACT, + /** + * The modifier {@code default} + * @since 1.8 + */ + DEFAULT, /** The modifier {@code static} */ STATIC, /** The modifier {@code final} */ FINAL, /** The modifier {@code transient} */ TRANSIENT,
--- a/test/com/sun/javadoc/testAnnotationOptional/TestAnnotationOptional.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/com/sun/javadoc/testAnnotationOptional/TestAnnotationOptional.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 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
--- a/test/com/sun/javadoc/testAnnotationOptional/pkg/AnnotationOptional.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/com/sun/javadoc/testAnnotationOptional/pkg/AnnotationOptional.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/TestTypeAnnotations.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,421 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8005091 8009686 + * @summary Make sure that type annotations are displayed correctly + * @author Bhavesh Patel + * @library ../lib/ + * @build JavadocTester TestTypeAnnotations + * @run main TestTypeAnnotations + */ + +public class TestTypeAnnotations extends JavadocTester { + + //Test information. + private static final String BUG_ID = "8005091-8009686"; + + //Javadoc arguments. + private static final String[] ARGS = new String[] { + "-d", BUG_ID, "-sourcepath", SRC_DIR, "-private", "typeannos" + }; + + //Input for string search tests. + private static final String[][] NEGATED_TEST = NO_TEST; + private static final String[][] TEST = { + // Test for type annotations on Class Extends (ClassExtends.java). + /* @ignore 8012173 + {BUG_ID + FS + "typeannos" + FS + "MyClass.html", + "extends <a href=\"../typeannos/ClassExtA.html\" title=\"annotation " + + "in typeannos\">@ClassExtA</a> <a href=\"../typeannos/ParameterizedClass.html\" " + + "title=\"class in typeannos\">ParameterizedClass</a><<a href=\"" + + "../typeannos/ClassExtB.html\" title=\"annotation in typeannos\">" + + "@ClassExtB</a> java.lang.String>" + }, + */ + /* @ignore 8012173 + {BUG_ID + FS + "typeannos" + FS + "MyClass.html", + "implements <a href=\"../typeannos/ClassExtB.html\" title=\"" + + "annotation in typeannos\">@ClassExtB</a> java.lang.CharSequence, " + + "<a href=\"../typeannos/ClassExtA.html\" title=\"annotation in " + + "typeannos\">@ClassExtA</a> <a href=\"../typeannos/ParameterizedInterface.html\" " + + "title=\"interface in typeannos\">ParameterizedInterface</a><" + + "<a href=\"../typeannos/ClassExtB.html\" title=\"annotation in " + + "typeannos\">@ClassExtB</a> java.lang.String></pre>" + }, + */ + /* @ignore 8012173 + {BUG_ID + FS + "typeannos" + FS + "MyInterface.html", + "extends <a href=\"../typeannos/ClassExtA.html\" title=\"annotation " + + "in typeannos\">@ClassExtA</a> <a href=\"../typeannos/" + + "ParameterizedInterface.html\" title=\"interface in typeannos\">" + + "ParameterizedInterface</a><<a href=\"../typeannos/ClassExtA.html\" " + + "title=\"annotation in typeannos\">@ClassExtA</a> java.lang.String>, " + + "<a href=\"../typeannos/ClassExtB.html\" title=\"annotation in " + + "typeannos\">@ClassExtB</a> java.lang.CharSequence</pre>" + }, + */ + + // Test for type annotations on Class Parameters (ClassParameters.java). + {BUG_ID + FS + "typeannos" + FS + "ExtendsBound.html", + "class <span class=\"strong\">ExtendsBound<K extends <a " + + "href=\"../typeannos/ClassParamA.html\" title=\"annotation in " + + "typeannos\">@ClassParamA</a> java.lang.String></span>" + }, + /* @ignore 8012173 + {BUG_ID + FS + "typeannos" + FS + "ExtendsGeneric.html", + "<pre> class <span class=\"strong\">ExtendsGeneric<K extends " + + "<a href=\"../typeannos/ClassParamA.html\" title=\"annotation in " + + "typeannos\">@ClassParamA</a> <a href=\"../typeannos/Unannotated.html\" " + + "title=\"class in typeannos\">Unannotated</a><<a href=\"" + + "../typeannos/ClassParamB.html\" title=\"annotation in typeannos\">" + + "@ClassParamB</a> java.lang.String>></span>" + }, + */ + {BUG_ID + FS + "typeannos" + FS + "TwoBounds.html", + "<pre> class <span class=\"strong\">TwoBounds<K extends <a href=\"" + + "../typeannos/ClassParamA.html\" title=\"annotation in typeannos\">" + + "@ClassParamA</a> java.lang.String,V extends <a href=\"../typeannos/" + + "ClassParamB.html\" title=\"annotation in typeannos\">@ClassParamB" + + "</a> java.lang.String></span>" + }, + {BUG_ID + FS + "typeannos" + FS + "Complex1.html", + "class <span class=\"strong\">Complex1<K extends <a href=\"../" + + "typeannos/ClassParamA.html\" title=\"annotation in typeannos\">" + + "@ClassParamA</a> java.lang.String & java.lang.Runnable></span>" + }, + {BUG_ID + FS + "typeannos" + FS + "Complex2.html", + "class <span class=\"strong\">Complex2<K extends java.lang." + + "String & <a href=\"../typeannos/ClassParamB.html\" title=\"" + + "annotation in typeannos\">@ClassParamB</a> java.lang.Runnable></span>" + }, + {BUG_ID + FS + "typeannos" + FS + "ComplexBoth.html", + "class <span class=\"strong\">ComplexBoth<K extends <a href=\"" + + "../typeannos/ClassParamA.html\" title=\"annotation in typeannos\"" + + ">@ClassParamA</a> java.lang.String & <a href=\"../typeannos/" + + "ClassParamA.html\" title=\"annotation in typeannos\">@ClassParamA" + + "</a> java.lang.Runnable></span>" + }, + + // Test for type annotations on fields (Fields.java). + /* @ignore 8012173 + {BUG_ID + FS + "typeannos" + FS + "DefaultScope.html", + "<pre><a href=\"../typeannos/Parameterized.html\" title=\"class in " + + "typeannos\">Parameterized</a><<a href=\"../typeannos/FldA.html\" " + + "title=\"annotation in typeannos\">@FldA</a> java.lang.String,<a " + + "href=\"../typeannos/FldB.html\" title=\"annotation in typeannos\">" + + "@FldB</a> java.lang.String> bothTypeArgs</pre>" + }, + */ + {BUG_ID + FS + "typeannos" + FS + "DefaultScope.html", + "<pre><a href=\"../typeannos/FldA.html\" title=\"annotation in " + + "typeannos\">@FldA</a> java.lang.String <a href=\"../typeannos/" + + "FldB.html\" title=\"annotation in typeannos\">@FldB</a> [] " + + "array1Deep</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "DefaultScope.html", + "<pre>java.lang.String[] <a href=\"../typeannos/FldB.html\" " + + "title=\"annotation in typeannos\">@FldB</a> [] array2SecondOld</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "DefaultScope.html", + "<pre><a href=\"../typeannos/FldD.html\" title=\"annotation in " + + "typeannos\">@FldD</a> java.lang.String <a href=\"../typeannos/" + + "FldC.html\" title=\"annotation in typeannos\">@FldC</a> <a href=\"" + + "../typeannos/FldA.html\" title=\"annotation in typeannos\">@FldA" + + "</a> [] <a href=\"../typeannos/FldC.html\" title=\"annotation in " + + "typeannos\">@FldC</a> <a href=\"../typeannos/FldB.html\" title=\"" + + "annotation in typeannos\">@FldB</a> [] array2Deep</pre>" + }, + /* @ignore 8012173 + {BUG_ID + FS + "typeannos" + FS + "ModifiedScoped.html", + "<pre>public final <a href=\"../typeannos/Parameterized.html\" " + + "title=\"class in typeannos\">Parameterized</a><<a href=\"../" + + "typeannos/FldA.html\" title=\"annotation in typeannos\">@FldA</a> " + + "<a href=\"../typeannos/Parameterized.html\" title=\"class in " + + "typeannos\">Parameterized</a><<a href=\"../typeannos/FldA.html\" " + + "title=\"annotation in typeannos\">@FldA</a> java.lang.String,<a " + + "href=\"../typeannos/FldB.html\" title=\"annotation in typeannos\">" + + "@FldB</a> java.lang.String>,<a href=\"../typeannos/FldB.html\" " + + "title=\"annotation in typeannos\">@FldB</a> java.lang.String> " + + "nestedParameterized</pre>" + }, + */ + {BUG_ID + FS + "typeannos" + FS + "ModifiedScoped.html", + "<pre>public final <a href=\"../typeannos/FldA.html\" " + + "title=\"annotation in typeannos\">@FldA</a> java.lang.String[][] " + + "array2</pre>" + }, + + // Test for type annotations on method return types (MethodReturnType.java). + {BUG_ID + FS + "typeannos" + FS + "MtdDefaultScope.html", + "<pre>public <T> <a href=\"../typeannos/MRtnA.html\" " + + "title=\"annotation in typeannos\">@MRtnA</a> java.lang.String" + + " method()</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "MtdDefaultScope.html", + "<pre><a href=\"../typeannos/MRtnA.html\" title=\"annotation in " + + "typeannos\">@MRtnA</a> java.lang.String <a href=\"../typeannos/" + + "MRtnA.html\" title=\"annotation in typeannos\">@MRtnA</a> [] <a " + + "href=\"../typeannos/MRtnB.html\" title=\"annotation in typeannos\">" + + "@MRtnB</a> [] array2Deep()</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "MtdDefaultScope.html", + "<pre><a href=\"../typeannos/MRtnA.html\" title=\"annotation in " + + "typeannos\">@MRtnA</a> java.lang.String[][] array2()</pre>" + }, + /* @ignore 8012173 + {BUG_ID + FS + "typeannos" + FS + "MtdModifiedScoped.html", + "<pre>public final <a href=\"../typeannos/MtdParameterized.html\" " + + "title=\"class in typeannos\">MtdParameterized</a><<a href=\"../" + + "typeannos/MRtnA.html\" title=\"annotation in typeannos\">@MRtnA</a> " + + "<a href=\"../typeannos/MtdParameterized.html\" title=\"class in " + + "typeannos\">MtdParameterized</a><<a href=\"../typeannos/MRtnA." + + "html\" title=\"annotation in typeannos\">@MRtnA</a> java.lang." + + "String,<a href=\"../typeannos/MRtnB.html\" title=\"annotation in " + + "typeannos\">@MRtnB</a> java.lang.String>,<a href=\"../typeannos/" + + "MRtnB.html\" title=\"annotation in typeannos\">@MRtnB</a> java." + + "lang.String> nestedMtdParameterized()</pre>" + }, + */ + + // Test for type annotations on method type parameters (MethodTypeParameters.java). + {BUG_ID + FS + "typeannos" + FS + "UnscopedUnmodified.html", + "<pre><K extends <a href=\"../typeannos/MTyParamA.html\" title=\"" + + "annotation in typeannos\">@MTyParamA</a> java.lang.String>" + + " void methodExtends()</pre>" + }, + /* @ignore 8012173 + {BUG_ID + FS + "typeannos" + FS + "UnscopedUnmodified.html", + "<pre><K extends <a href=\"../typeannos/MTyParamA.html\" title=\"" + + "annotation in typeannos\">@MTyParamA</a> <a href=\"../typeannos/" + + "MtdTyParameterized.html\" title=\"class in typeannos\">" + + "MtdTyParameterized</a><<a href=\"../typeannos/MTyParamB.html\" " + + "title=\"annotation in typeannos\">@MTyParamB</a> java.lang.String" + + ">> void nestedExtends()</pre>" + }, + */ + {BUG_ID + FS + "typeannos" + FS + "PublicModifiedMethods.html", + "<pre>public final <K extends <a href=\"../typeannos/" + + "MTyParamA.html\" title=\"annotation in typeannos\">@MTyParamA</a> " + + "java.lang.String> void methodExtends()</pre>" + }, + /* @ignore 8012173 + {BUG_ID + FS + "typeannos" + FS + "PublicModifiedMethods.html", + "<pre>public final <K extends <a href=\"../typeannos/" + + "MTyParamA.html\" title=\"annotation in typeannos\">@MTyParamA</a> " + + "java.lang.String,V extends <a href=\"../typeannos/MTyParamA.html\" " + + "title=\"annotation in typeannos\">@MTyParamA</a> <a href=\"../" + + "typeannos/MtdTyParameterized.html\" title=\"class in typeannos\">" + + "MtdTyParameterized</a><<a href=\"../typeannos/MTyParamB.html\" " + + "title=\"annotation in typeannos\">@MTyParamB</a> java.lang.String" + + ">> void dual()</pre>" + }, + */ + + // Test for type annotations on parameters (Parameters.java). + {BUG_ID + FS + "typeannos" + FS + "Parameters.html", + "<pre>void unannotated(<a href=\"../typeannos/" + + "ParaParameterized.html\" title=\"class in typeannos\">" + + "ParaParameterized</a><java.lang.String,java.lang.String>" + + " a)</pre>" + }, + /* @ignore 8012173 + {BUG_ID + FS + "typeannos" + FS + "Parameters.html", + "<pre>void nestedParaParameterized(<a href=\"../typeannos/" + + "ParaParameterized.html\" title=\"class in typeannos\">" + + "ParaParameterized</a><<a href=\"../typeannos/ParamA.html\" " + + "title=\"annotation in typeannos\">@ParamA</a> <a href=\"../" + + "typeannos/ParaParameterized.html\" title=\"class in typeannos\">" + + "ParaParameterized</a><<a href=\"../typeannos/ParamA.html\" " + + "title=\"annotation in typeannos\">@ParamA</a> java.lang.String," + + "<a href=\"../typeannos/ParamB.html\" title=\"annotation in " + + "typeannos\">@ParamB</a> java.lang.String>,<a href=\"../" + + "typeannos/ParamB.html\" title=\"annotation in typeannos\">@ParamB" + + "</a> java.lang.String> a)</pre>" + }, + */ + {BUG_ID + FS + "typeannos" + FS + "Parameters.html", + "<pre>void array2Deep(<a href=\"../typeannos/ParamA.html\" " + + "title=\"annotation in typeannos\">@ParamA</a> java.lang.String " + + "<a href=\"../typeannos/ParamA.html\" title=\"annotation in " + + "typeannos\">@ParamA</a> [] <a href=\"../typeannos/ParamB.html\" " + + "title=\"annotation in typeannos\">@ParamB</a> [] a)</pre>" + }, + + // Test for type annotations on throws (Throws.java). + {BUG_ID + FS + "typeannos" + FS + "ThrDefaultUnmodified.html", + "<pre>void oneException()" + NL + + " throws <a href=\"../typeannos/ThrA.html\" title=\"" + + "annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "ThrDefaultUnmodified.html", + "<pre>void twoExceptions()" + NL + + " throws <a href=\"../typeannos/ThrA.html\" title=\"" + + "annotation in typeannos\">@ThrA</a> java.lang.RuntimeException," + NL + + " <a href=\"../typeannos/ThrA.html\" title=\"" + + "annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "ThrPublicModified.html", + "<pre>public final void oneException(java.lang.String a)" + NL + + " throws <a href=\"../typeannos/ThrA.html\" " + + "title=\"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "ThrPublicModified.html", + "<pre>public final void twoExceptions(java.lang.String a)" + NL + + " throws <a href=\"../typeannos/ThrA.html\" " + + "title=\"annotation in typeannos\">@ThrA</a> java.lang.RuntimeException," + NL + + " <a href=\"../typeannos/ThrA.html\" " + + "title=\"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "ThrWithValue.html", + "<pre>void oneException()" + NL + + " throws <a href=\"../typeannos/ThrB.html\" title=\"" + + "annotation in typeannos\">@ThrB</a>(<a href=\"../typeannos/" + + "ThrB.html#value()\">value</a>=\"m\") java.lang.Exception</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "ThrWithValue.html", + "<pre>void twoExceptions()" + NL + + " throws <a href=\"../typeannos/ThrB.html\" title=\"" + + "annotation in typeannos\">@ThrB</a>(<a href=\"../typeannos/" + + "ThrB.html#value()\">value</a>=\"m\") java.lang.RuntimeException," + NL + + " <a href=\"../typeannos/ThrA.html\" title=\"" + + "annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>" + }, + + // Test for type annotations on type parameters (TypeParameters.java). + {BUG_ID + FS + "typeannos" + FS + "TestMethods.html", + "<pre><K,V extends <a href=\"../typeannos/TyParaA.html\" title=\"" + + "annotation in typeannos\">@TyParaA</a> java.lang.String> " + + "void secondAnnotated()</pre>" + }, + + // Test for type annotations on wildcard type (Wildcards.java). + {BUG_ID + FS + "typeannos" + FS + "BoundTest.html", + "<pre>void wcExtends(<a href=\"../typeannos/MyList.html\" " + + "title=\"class in typeannos\">MyList</a><? extends <a href=\"" + + "../typeannos/WldA.html\" title=\"annotation in typeannos\">@WldA" + + "</a> java.lang.String> l)</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "BoundTest.html", + "<pre><a href=\"../typeannos/MyList.html\" title=\"class in " + + "typeannos\">MyList</a><? super <a href=\"../typeannos/WldA.html\" " + + "title=\"annotation in typeannos\">@WldA</a> java.lang.String>" + + " returnWcSuper()</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "BoundWithValue.html", + "<pre>void wcSuper(<a href=\"../typeannos/MyList.html\" title=\"" + + "class in typeannos\">MyList</a><? super <a href=\"../typeannos/" + + "WldB.html\" title=\"annotation in typeannos\">@WldB</a>(<a href=\"" + + "../typeannos/WldB.html#value()\">value</a>=\"m\") java.lang." + + "String> l)</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "BoundWithValue.html", + "<pre><a href=\"../typeannos/MyList.html\" title=\"class in " + + "typeannos\">MyList</a><? extends <a href=\"../typeannos/WldB." + + "html\" title=\"annotation in typeannos\">@WldB</a>(<a href=\"../" + + "typeannos/WldB.html#value()\">value</a>=\"m\") java.lang.String" + + "> returnWcExtends()</pre>" + }, + + // Test for receiver annotations (Receivers.java). + {BUG_ID + FS + "typeannos" + FS + "DefaultUnmodified.html", + "<pre>void withException(<a href=\"../typeannos/RcvrA.html\" " + + "title=\"annotation in typeannos\">@RcvrA</a> " + + "DefaultUnmodified this)" + NL + " throws java." + + "lang.Exception</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "DefaultUnmodified.html", + "<pre>java.lang.String nonVoid(<a href=\"../typeannos/RcvrA." + + "html\" title=\"annotation in typeannos\">@RcvrA</a> <a href=\"../" + + "typeannos/RcvrB.html\" title=\"annotation in typeannos\">@RcvrB" + + "</a>(<a href=\"../typeannos/RcvrB.html#value()\">value</a>=\"m\")" + + " DefaultUnmodified this)</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "DefaultUnmodified.html", + "<pre><T extends java.lang.Runnable> void accept(" + + "<a href=\"../typeannos/RcvrA.html\" title=\"annotation in " + + "typeannos\">@RcvrA</a> DefaultUnmodified this," + NL + + " T r)" + NL + + " throws java.lang.Exception</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "PublicModified.html", + "<pre>public final java.lang.String nonVoid(<a href=\"" + + "../typeannos/RcvrA.html\" title=\"annotation in typeannos\">" + + "@RcvrA</a> PublicModified this)</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "PublicModified.html", + "<pre>public final <T extends java.lang.Runnable> " + + "void accept(<a href=\"../typeannos/RcvrA.html\" title=\"" + + "annotation in typeannos\">@RcvrA</a> PublicModified this," + NL + + " T r)" + NL + + " throws java.lang.Exception</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "WithValue.html", + "<pre><T extends java.lang.Runnable> void accept(" + + "<a href=\"../typeannos/RcvrB.html\" title=\"annotation in " + + "typeannos\">@RcvrB</a>(<a href=\"../typeannos/RcvrB.html#value()\">" + + "value</a>=\"m\") WithValue this," + NL + + " T r)" + NL + + " throws java.lang.Exception</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "WithFinal.html", + "<pre>java.lang.String nonVoid(<a href=\"../typeannos/RcvrB." + + "html\" title=\"annotation in typeannos\">@RcvrB</a>(<a href=\"../" + + "typeannos/RcvrB.html#value()\">value</a>=\"m\") WithFinal" + + " this)</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "WithBody.html", + "<pre>void field(<a href=\"../typeannos/RcvrA.html\" title=\"" + + "annotation in typeannos\">@RcvrA</a> WithBody this)</pre>" + }, + {BUG_ID + FS + "typeannos" + FS + "Generic2.html", + "<pre>void test2(<a href=\"../typeannos/RcvrA.html\" title=\"" + + "annotation in typeannos\">@RcvrA</a> Generic2<X> this)</pre>" + } + }; + + /** + * The entry point of the test. + * @param args the array of command line arguments. + */ + public static void main(String[] args) { + TestTypeAnnotations tester = new TestTypeAnnotations(); + run(tester, ARGS, TEST, NEGATED_TEST); + tester.printSummary(); + } + + /** + * {@inheritDoc} + */ + public String getBugId() { + return BUG_ID; + } + + /** + * {@inheritDoc} + */ + public String getBugName() { + return getClass().getName(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/ClassExtends.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package typeannos; + +import java.lang.annotation.*; + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +abstract class MyClass extends @ClassExtA ParameterizedClass<@ClassExtB String> + implements @ClassExtB CharSequence, @ClassExtA ParameterizedInterface<@ClassExtB String> { } + +interface MyInterface extends @ClassExtA ParameterizedInterface<@ClassExtA String>, + @ClassExtB CharSequence { } + +class ParameterizedClass<K> {} +interface ParameterizedInterface<K> {} + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface ClassExtA {} +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface ClassExtB {}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/ClassParameters.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package typeannos; + +import java.lang.annotation.*; + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +class Unannotated<K> { } + +class ExtendsBound<K extends @ClassParamA String> { } +class ExtendsGeneric<K extends @ClassParamA Unannotated<@ClassParamB String>> { } +class TwoBounds<K extends @ClassParamA String, V extends @ClassParamB String> { } + +class Complex1<K extends @ClassParamA String&Runnable> { } +class Complex2<K extends String & @ClassParamB Runnable> { } +class ComplexBoth<K extends @ClassParamA String & @ClassParamA Runnable> { } + +class ClassParamOuter { + void inner() { + class LUnannotated<K> { } + + class LExtendsBound<K extends @ClassParamA String> { } + class LExtendsGeneric<K extends @ClassParamA LUnannotated<@ClassParamB String>> { } + class LTwoBounds<K extends @ClassParamA String, V extends @ClassParamB String> { } + + class LComplex1<K extends @ClassParamA String&Runnable> { } + class LComplex2<K extends String & @ClassParamB Runnable> { } + class LComplexBoth<K extends @ClassParamA String & @ClassParamA Runnable> { } + } +} + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface ClassParamA { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface ClassParamB { }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/Fields.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package typeannos; + +import java.lang.annotation.*; + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +class DefaultScope { + Parameterized<String, String> unannotated; + Parameterized<@FldA String, String> firstTypeArg; + Parameterized<String, @FldA String> secondTypeArg; + Parameterized<@FldA String, @FldB String> bothTypeArgs; + + Parameterized<@FldA Parameterized<@FldA String, @FldB String>, @FldB String> + nestedParameterized; + + @FldA String [] array1; + @FldA String @FldB [] array1Deep; + @FldA String [] [] array2; + @FldD String @FldC @FldA [] @FldC @FldB [] array2Deep; + String @FldA [] [] array2First; + String [] @FldB [] array2Second; + + // Old-style array syntax + String array2FirstOld @FldA []; + String array2SecondOld [] @FldB []; +} + +class ModifiedScoped { + public final Parameterized<String, String> unannotated = null; + public final Parameterized<@FldA String, String> firstTypeArg = null; + public final Parameterized<String, @FldA String> secondTypeArg = null; + public final Parameterized<@FldA String, @FldB String> bothTypeArgs = null; + + public final Parameterized<@FldA Parameterized<@FldA String, @FldB String>, @FldB String> + nestedParameterized = null; + + public final @FldA String [] array1 = null; + public final @FldA String @FldB [] array1Deep = null; + public final @FldA String [] [] array2 = null; + public final @FldA String @FldA [] @FldB [] array2Deep = null; + public final String @FldA [] [] array2First = null; + public final String [] @FldB [] array2Second = null; +} + +class Parameterized<K, V> { } + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface FldA { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface FldB { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface FldC { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface FldD { }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/MethodReturnType.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package typeannos; + +import java.lang.annotation.*; + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +class MtdDefaultScope { + MtdParameterized<String, String> unannotated() { return null; } + MtdParameterized<@MRtnA String, String> firstTypeArg() { return null; } + MtdParameterized<String, @MRtnA String> secondTypeArg() { return null; } + MtdParameterized<@MRtnA String, @MRtnB String> bothTypeArgs() { return null; } + + MtdParameterized<@MRtnA MtdParameterized<@MRtnA String, @MRtnB String>, @MRtnB String> + nestedMtdParameterized() { return null; } + + public <T> @MRtnA String method() { return null; } + + @MRtnA String [] array1() { return null; } + @MRtnA String @MRtnB [] array1Deep() { return null; } + @MRtnA String [] [] array2() { return null; } + @MRtnA String @MRtnA [] @MRtnB [] array2Deep() { return null; } + String @MRtnA [] [] array2First() { return null; } + String [] @MRtnB [] array2Second() { return null; } + + // Old-style array syntax + String array2FirstOld() @MRtnA [] { return null; } + String array2SecondOld() [] @MRtnB [] { return null; } +} + +class MtdModifiedScoped { + public final MtdParameterized<String, String> unannotated() { return null; } + public final MtdParameterized<@MRtnA String, String> firstTypeArg() { return null; } + public final MtdParameterized<String, @MRtnA String> secondTypeArg() { return null; } + public final MtdParameterized<@MRtnA String, @MRtnB String> bothTypeArgs() { return null; } + + public final MtdParameterized<@MRtnA MtdParameterized<@MRtnA String, @MRtnB String>, @MRtnB String> + nestedMtdParameterized() { return null; } + + public final @MRtnA String [] array1() { return null; } + public final @MRtnA String @MRtnB [] array1Deep() { return null; } + public final @MRtnA String [] [] array2() { return null; } + public final @MRtnA String @MRtnA [] @MRtnB [] array2Deep() { return null; } + public final String @MRtnA [] [] array2First() { return null; } + public final String [] @MRtnB [] array2Second() { return null; } +} + +class MtdParameterized<K, V> { } + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface MRtnA { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface MRtnB { }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/MethodTypeParameters.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package typeannos; + +import java.lang.annotation.*; + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +class UnscopedUnmodified { + <K extends @MTyParamA String> void methodExtends() {} + <K extends @MTyParamA MtdTyParameterized<@MTyParamB String>> void nestedExtends() {} + <K extends @MTyParamA String, V extends @MTyParamA MtdTyParameterized<@MTyParamB String>> void dual() {} + <K extends String, V extends MtdTyParameterized<@MTyParamB String>> void dualOneAnno() {} +} + +class PublicModifiedMethods { + public final <K extends @MTyParamA String> void methodExtends() {} + public final <K extends @MTyParamA MtdTyParameterized<@MTyParamB String>> void nestedExtends() {} + public final <K extends @MTyParamA String, V extends @MTyParamA MtdTyParameterized<@MTyParamB String>> void dual() {} + public final <K extends String, V extends MtdTyParameterized<@MTyParamB String>> void dualOneAnno() {} +} + +class MtdTyParameterized<K> { } + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface MTyParamA { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface MTyParamB { }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/Parameters.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package typeannos; + +import java.lang.annotation.*; + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +class Parameters { + void unannotated(ParaParameterized<String, String> a) {} + void firstTypeArg(ParaParameterized<@ParamA String, String> a) {} + void secondTypeArg(ParaParameterized<String, @ParamA String> a) {} + void bothTypeArgs(ParaParameterized<@ParamA String, @ParamB String> both) {} + + void nestedParaParameterized(ParaParameterized<@ParamA ParaParameterized<@ParamA String, @ParamB String>, @ParamB String> a) {} + + void array1(@ParamA String [] a) {} + void array1Deep(@ParamA String @ParamB [] a) {} + void array2(@ParamA String [] [] a) {} + void array2Deep(@ParamA String @ParamA [] @ParamB [] a) {} + void array2First(String @ParamA [] [] a) {} + void array2Second(String [] @ParamB [] a) {} +} + +class ParaParameterized<K, V> { } + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface ParamA { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface ParamB { }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/Receivers.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package typeannos; + +import java.lang.annotation.*; + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +class DefaultUnmodified { + void plain(@RcvrA DefaultUnmodified this) { } + <T> void generic(@RcvrA DefaultUnmodified this) { } + void withException(@RcvrA DefaultUnmodified this) throws Exception { } + String nonVoid(@RcvrA @RcvrB("m") DefaultUnmodified this) { return null; } + <T extends Runnable> void accept(@RcvrA DefaultUnmodified this, T r) throws Exception { } +} + +class PublicModified { + public final void plain(@RcvrA PublicModified this) { } + public final <T> void generic(@RcvrA PublicModified this) { } + public final void withException(@RcvrA PublicModified this) throws Exception { } + public final String nonVoid(@RcvrA PublicModified this) { return null; } + public final <T extends Runnable> void accept(@RcvrA PublicModified this, T r) throws Exception { } +} + +class WithValue { + void plain(@RcvrB("m") WithValue this) { } + <T> void generic(@RcvrB("m") WithValue this) { } + void withException(@RcvrB("m") WithValue this) throws Exception { } + String nonVoid(@RcvrB("m") WithValue this) { return null; } + <T extends Runnable> void accept(@RcvrB("m") WithValue this, T r) throws Exception { } +} + +class WithFinal { + void plain(final @RcvrB("m") WithFinal this) { } + <T> void generic(final @RcvrB("m") WithFinal this) { } + void withException(final @RcvrB("m") WithFinal this) throws Exception { } + String nonVoid(final @RcvrB("m") WithFinal this) { return null; } + <T extends Runnable> void accept(final @RcvrB("m") WithFinal this, T r) throws Exception { } +} + +class WithBody { + Object f; + + void field(@RcvrA WithBody this) { + this.f = null; + } + void meth(@RcvrA WithBody this) { + this.toString(); + } +} + +class Generic1<X> { + void test1(Generic1<X> this) {} + void test2(@RcvrA Generic1<X> this) {} + void test3(Generic1<@RcvrA X> this) {} + void test4(@RcvrA Generic1<@RcvrA X> this) {} +} + +class Generic2<@RcvrA X> { + void test1(Generic2<X> this) {} + void test2(@RcvrA Generic2<X> this) {} + void test3(Generic2<@RcvrA X> this) {} + void test4(@RcvrA Generic2<@RcvrA X> this) {} +} + +class Generic3<X extends @RcvrA Object> { + void test1(Generic3<X> this) {} + void test2(@RcvrA Generic3<X> this) {} + void test3(Generic3<@RcvrA X> this) {} + void test4(@RcvrA Generic3<@RcvrA X> this) {} +} + +class Generic4<X extends @RcvrA Object> { + <Y> void test1(Generic4<X> this) {} + <Y> void test2(@RcvrA Generic4<X> this) {} + <Y> void test3(Generic4<@RcvrA X> this) {} + <Y> void test4(@RcvrA Generic4<@RcvrA X> this) {} +} + +class Outer { + class Inner { + void none(Outer.Inner this) {} + void outer(@RcvrA Outer.Inner this) {} + void inner(Outer. @RcvrB("i") Inner this) {} + void both(@RcvrA Outer.@RcvrB("i") Inner this) {} + + void innerOnlyNone(Inner this) {} + void innerOnly(@RcvrA Inner this) {} + } +} + +class GenericOuter<S, T> { + class GenericInner<U, V> { + void none(GenericOuter<S, T>.GenericInner<U, V> this) {} + void outer(@RcvrA GenericOuter<S, T>.GenericInner<U, V> this) {} + void inner(GenericOuter<S, T>. @RcvrB("i") GenericInner<U, V> this) {} + void both(@RcvrA GenericOuter<S, T>.@RcvrB("i") GenericInner<U, V> this) {} + + void innerOnlyNone(GenericInner<U, V> this) {} + void innerOnly(@RcvrA GenericInner<U, V> this) {} + } +} + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface RcvrA {} +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface RcvrB { String value(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/Throws.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package typeannos; + +import java.lang.annotation.*; + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +class ThrDefaultUnmodified { + void oneException() throws @ThrA Exception {} + void twoExceptions() throws @ThrA RuntimeException, @ThrA Exception {} +} + +class ThrPublicModified { + public final void oneException(String a) throws @ThrA Exception {} + public final void twoExceptions(String a) throws @ThrA RuntimeException, @ThrA Exception {} +} + +class ThrWithValue { + void oneException() throws @ThrB("m") Exception {} + void twoExceptions() throws @ThrB(value="m") RuntimeException, @ThrA Exception {} +} + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface ThrA {} +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface ThrB { String value(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/TypeParameters.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package typeannos; + +import java.lang.annotation.*; + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +class TypUnannotated<K> { } +class OneAnnotated<@TyParaA K> { } +class TwoAnnotated<@TyParaA K, @TyParaA V> { } +class SecondAnnotated<K, @TyParaA V extends String> { } + +class TestMethods { + <K> void unannotated() { } + <@TyParaA K> void oneAnnotated() { } + <@TyParaA K, @TyParaB("m") V> void twoAnnotated() { } + <K, @TyParaA V extends @TyParaA String> void secondAnnotated() { } +} + +class UnannotatedB<K> { } +class OneAnnotatedB<@TyParaB("m") K> { } +class TwoAnnotatedB<@TyParaB("m") K, @TyParaB("m") V> { } +class SecondAnnotatedB<K, @TyParaB("m") V extends @TyParaB("m") String> { } + +class OneAnnotatedC<@TyParaC K> { } +class TwoAnnotatedC<@TyParaC K, @TyParaC V> { } +class SecondAnnotatedC<K, @TyParaC V extends String> { } + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface TyParaA { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface TyParaB { String value(); } +@Target(ElementType.TYPE_USE) +@Documented +@interface TyParaC { }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/Varargs.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package typeannos; + +import java.lang.annotation.*; + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface VarArgA {} + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +class Varargs { + + // Handle annotations on a varargs element type + void varargPlain(Object @VarArgA... objs) { + } + + void varargGeneric(Class<?> @VarArgA ... clz) { + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testTypeAnnotations/typeannos/Wildcards.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package typeannos; + +import java.lang.annotation.*; + +/* + * This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations. + */ +class BoundTest { + void wcExtends(MyList<? extends @WldA String> l) { } + void wcSuper(MyList<? super @WldA String> l) { } + + MyList<? extends @WldA String> returnWcExtends() { return null; } + MyList<? super @WldA String> returnWcSuper() { return null; } + MyList<? extends @WldA MyList<? super @WldB("m") String>> complex() { return null; } +} + +class BoundWithValue { + void wcExtends(MyList<? extends @WldB("m") String> l) { } + void wcSuper(MyList<? super @WldB(value="m") String> l) { } + + MyList<? extends @WldB("m") String> returnWcExtends() { return null; } + MyList<? super @WldB(value="m") String> returnWcSuper() { return null; } + MyList<? extends @WldB("m") MyList<? super @WldB("m") String>> complex() { return null; } +} + +class SelfTest { + void wcExtends(MyList<@WldA ?> l) { } + void wcSuper(MyList<@WldA ?> l) { } + + MyList<@WldA ?> returnWcExtends() { return null; } + MyList<@WldA ?> returnWcSuper() { return null; } + MyList<@WldA ? extends @WldA MyList<@WldB("m") ?>> complex() { return null; } +} + +class SelfWithValue { + void wcExtends(MyList<@WldB("m") ?> l) { } + void wcSuper(MyList<@WldB(value="m") ?> l) { } + + MyList<@WldB("m") ?> returnWcExtends() { return null; } + MyList<@WldB(value="m") ?> returnWcSuper() { return null; } + MyList<@WldB("m") ? extends MyList<@WldB("m") ? super String>> complex() { return null; } +} + +class MyList<K> { } + +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface WldA { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) +@Documented +@interface WldB { String value(); }
--- a/test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/com/sun/javadoc/typeAnnotations/smoke/TestSmoke.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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
--- a/test/com/sun/javadoc/typeAnnotations/smoke/pkg/TargetTypes.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/com/sun/javadoc/typeAnnotations/smoke/pkg/TargetTypes.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T4965689/ClassLiteralWastesByteTest.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4965689 + * @summary class literal code wastes a byte + */ + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.Paths; + +public class ClassLiteralWastesByteTest { + + private static final String assertionErrorMsg = + "Instead of ldc_w, ldc instruction should have been generated"; + + public static void main(String[] args) { + new ClassLiteralWastesByteTest().run(); + } + + void run() { + check("-c", Paths.get(System.getProperty("test.classes"), + "test.class").toString()); + } + + void check(String... params) { + StringWriter s; + String out; + try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { + com.sun.tools.javap.Main.run(params, pw); + out = s.toString(); + } + if (out.contains("ldc_w")) { + throw new AssertionError(assertionErrorMsg); + } + } + +} + +class test { + void m() { + Class<?> aClass = test.class; + } +}
--- a/test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java Fri Sep 27 15:41:28 2013 +0100 @@ -23,8 +23,9 @@ /* * @test - * @bug 5053846 + * @bug 5053846 8011432 * @summary javac: MethodRef entries are duplicated in the constant pool + * @summary javac, compiler regression iterable + captured type */ import java.io.PrintWriter; @@ -43,9 +44,13 @@ void run() { check("-v", Paths.get(System.getProperty("test.classes"), - "TestHelper1.class").toString()); + this.getClass().getSimpleName() + "$TestHelper1.class").toString()); + check("-v", Paths.get(System.getProperty("test.classes"), + this.getClass().getSimpleName() + "$TestHelper2.class").toString()); check("-v", Paths.get(System.getProperty("test.classes"), - "TestHelper2.class").toString()); + this.getClass().getSimpleName() + "$TestHelper3.class").toString()); + check("-v", Paths.get(System.getProperty("test.classes"), + this.getClass().getSimpleName() + "$TestHelper4.class").toString()); } void check(String... params) { @@ -68,24 +73,38 @@ int end = out.indexOf("{"); return out.substring(start, end); } -} -class TestHelper1 { - void m() { - Vector v = new Vector(); - Iterator iter = v.iterator(); - while (iter.hasNext()) { - Object o = iter.next(); - Object o2 = o; - } - for (Object o: v) { - Object o2 = o; + class TestHelper1 { + void m() { + Vector v = new Vector(); + Iterator iter = v.iterator(); + while (iter.hasNext()) { + Object o = iter.next(); + Object o2 = o; + } + for (Object o: v) { + Object o2 = o; + } } } -} + + class TestHelper2<X extends Number & Iterable<String>> { + void test(X x) { + for (String s : x) { } + } + } + + interface Data extends Iterable<String> {} -class TestHelper2<X extends Number & Iterable<String>> { - void test(X x) { - for (String s : x) { } + class TestHelper3<X extends Number & Iterable<? extends Data>> { + void test(X x) { + for (Data s : x) { } + } + } + + class TestHelper4 { + void test(Iterable<? extends Data> t) { + for(Object a: t.iterator().next()); + } } }
--- a/test/tools/javac/T6558476.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/T6558476.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2013, 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,6 +23,8 @@ /* * @test + * @bug 6558476 + * @summary com/sun/tools/javac/Main.compile don't release file handles on return * @run main/othervm -Xmx512m -Xms512m T6558476 */ @@ -70,8 +72,7 @@ public static void main(String[] args) throws IOException { File javaHomeDir = new File(System.getProperty("java.home")); - File tmpDir = new File(System.getProperty("java.io.tmpdir")); - File outputDir = new File(tmpDir, "outputDir" + new Random().nextInt(65536)); + File outputDir = new File("outputDir" + new Random().nextInt(65536)); outputDir.mkdir(); outputDir.deleteOnExit();
--- a/test/tools/javac/T6900149.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/T6900149.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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 @@ -39,7 +39,7 @@ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); - File emptyFile = File.createTempFile("Empty", ".java"); + File emptyFile = createTempFile("Empty.java"); File[] files = new File[] { emptyFile, emptyFile }; CompilationTask task = compiler.getTask(null, fm, diag, null, null, fm.getJavaFileObjects(files)); @@ -47,4 +47,10 @@ throw new AssertionError("compilation failed"); } } + + private static File createTempFile(String path) throws IOException { + File f = new File(path); + try (FileWriter out = new FileWriter(f)) { } + return f; + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8010659/CompilerCrashWhenMixingBinariesAndSourcesTest.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, 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. + */ + +/* + * @test + * @bug 8010659 + * @summary Javac Crashes while building OpenJFX + * @library /tools/javac/lib + * @build ToolBox + * @run main CompilerCrashWhenMixingBinariesAndSourcesTest + */ + +public class CompilerCrashWhenMixingBinariesAndSourcesTest { + private static final String ASource = + "class A {\n" + + " void test() {new B(){};}\n" + + "}"; + private static final String BSource = + "class B extends C {}"; + private static final String CSource = + "class C extends D {\n" + + " String m(int i) {return null;}\n" + + "}"; + private static final String DSource = + "class D {\n" + + " Object m(int i) {return null;}\n" + + "}"; + + public static void main (String[] args) throws Exception{ + ToolBox.JavaToolArgs javacParams = new ToolBox.JavaToolArgs() + .setSources(ASource, BSource, CSource, DSource); + ToolBox.javac(javacParams); + + ToolBox.rm("A.class"); + ToolBox.rm("A$1.class"); + ToolBox.rm("C.class"); + ToolBox.rm("D.class"); + + javacParams = new ToolBox.JavaToolArgs() + .setOptions("-cp", ".") + .setSources(ASource, CSource, DSource); + ToolBox.javac(javacParams); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8011181/EmptyUTF8ForInnerClassNameTest.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013, 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. + */ + +/* + * @test + * @bug 8011181 + * @summary javac, empty UTF8 entry generated for inner class + */ + +import java.io.BufferedInputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import com.sun.tools.javac.util.Assert; +import com.sun.tools.classfile.ClassFile; + +import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8; +import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info; +import static com.sun.tools.classfile.ConstantPool.CPInfo; + +public class EmptyUTF8ForInnerClassNameTest { + + public static void main(String[] args) throws Exception { + new EmptyUTF8ForInnerClassNameTest().run(); + } + + void run() throws Exception { + checkClassFile(Paths.get(System.getProperty("test.classes"), + this.getClass().getName() + "$1.class")); + checkClassFile(Paths.get(System.getProperty("test.classes"), + this.getClass().getName() + "$EnumPlusSwitch.class")); + } + + void checkClassFile(final Path path) throws Exception { + ClassFile classFile = ClassFile.read( + new BufferedInputStream(Files.newInputStream(path))); + for (CPInfo cpInfo : classFile.constant_pool.entries()) { + if (cpInfo.getTag() == CONSTANT_Utf8) { + CONSTANT_Utf8_info utf8Info = (CONSTANT_Utf8_info)cpInfo; + Assert.check(utf8Info.value.length() > 0, + "UTF8 with length 0 found at class " + classFile.getName()); + } + } + } + + static class EnumPlusSwitch { + enum E {E1} + + public int m (E e) { + switch (e) { + case E1: + return 0; + } + return -1; + } + } + +}
--- a/test/tools/javac/annotations/typeAnnotations/TypeProcOnly.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/annotations/typeAnnotations/TypeProcOnly.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2013, 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 @@ -32,12 +32,12 @@ import com.sun.source.util.JavacTask; import com.sun.source.util.TaskEvent; import com.sun.source.util.TaskListener; -import com.sun.source.util.TreePath; import com.sun.tools.javac.main.JavaCompiler; -import com.sun.tools.javac.main.JavaCompiler.CompileState; import com.sun.tools.javac.processing.JavacProcessingEnvironment; import com.sun.tools.javac.util.Context; +import static com.sun.tools.javac.comp.CompileStates.CompileState; + /* * @test * @summary test that type processors are run when -proc:only is passed.
--- a/test/tools/javac/annotations/typeAnnotations/packageanno/PackageProcessor.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/annotations/typeAnnotations/packageanno/PackageProcessor.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2013, 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,12 +31,12 @@ import com.sun.source.util.JavacTask; import com.sun.source.util.TaskEvent; import com.sun.source.util.TaskListener; -import com.sun.source.util.TreePath; import com.sun.tools.javac.main.JavaCompiler; -import com.sun.tools.javac.main.JavaCompiler.CompileState; import com.sun.tools.javac.processing.JavacProcessingEnvironment; import com.sun.tools.javac.util.Context; +import static com.sun.tools.javac.comp.CompileStates.CompileState; + /* * @test * @summary test that package annotations are available to type processors.
--- a/test/tools/javac/api/TestJavacTaskScanner.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/api/TestJavacTaskScanner.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, 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 @@ -93,7 +93,7 @@ System.out.println("#allMembers: " + numAllMembers); check(numTokens, "#Tokens", 1222); - check(numParseTypeElements, "#parseTypeElements", 136); + check(numParseTypeElements, "#parseTypeElements", 158); check(numAllMembers, "#allMembers", 52); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defaultMethods/CheckACC_STRICTFlagOnDefaultMethodTest.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2013, 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. + */ + +/* + * @test + * @bug 8012723 + * @summary strictfp interface misses strictfp modifer on default method + * @run main CheckACC_STRICTFlagOnDefaultMethodTest + */ + +import java.util.ArrayList; +import java.util.List; +import java.io.File; +import java.io.IOException; + +import com.sun.tools.classfile.ClassFile; +import com.sun.tools.classfile.ConstantPoolException; +import com.sun.tools.classfile.Descriptor; +import com.sun.tools.classfile.Descriptor.InvalidDescriptor; +import com.sun.tools.classfile.Method; + +import static com.sun.tools.classfile.AccessFlags.ACC_STRICT; + +public class CheckACC_STRICTFlagOnDefaultMethodTest { + private static final String AssertionErrorMessage = + "All methods should have the ACC_STRICT access flag " + + "please check output"; + private static final String offendingMethodErrorMessage = + "Method %s of class %s doesn't have the ACC_STRICT access flag"; + + private List<String> errors = new ArrayList<>(); + + public static void main(String[] args) + throws IOException, ConstantPoolException, InvalidDescriptor { + new CheckACC_STRICTFlagOnDefaultMethodTest().run(); + } + + private void run() + throws IOException, ConstantPoolException, InvalidDescriptor { + String testClasses = System.getProperty("test.classes"); + check(testClasses, + "CheckACC_STRICTFlagOnDefaultMethodTest$StrictfpInterface.class"); + if (errors.size() > 0) { + for (String error: errors) { + System.err.println(error); + } + throw new AssertionError(AssertionErrorMessage); + } + } + + void check(String dir, String... fileNames) + throws + IOException, + ConstantPoolException, + Descriptor.InvalidDescriptor { + for (String fileName : fileNames) { + ClassFile classFileToCheck = ClassFile.read(new File(dir, fileName)); + + for (Method method : classFileToCheck.methods) { + if ((method.access_flags.flags & ACC_STRICT) == 0) { + errors.add(String.format(offendingMethodErrorMessage, + method.getName(classFileToCheck.constant_pool), + classFileToCheck.getName())); + } + } + } + } + + strictfp interface StrictfpInterface { + default void default_interface_method() {} + static void static_interface_method() {} + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defaultMethods/DefaultMethodFlags.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8011383 + * @summary Symbol.getModifiers omits ACC_ABSTRACT from interface with default methods + */ + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + +import javax.lang.model.element.*; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider; + +import com.sun.source.util.JavacTask; +import com.sun.source.util.TaskEvent; +import com.sun.source.util.TaskListener; +import com.sun.tools.javac.util.Assert; + +public class DefaultMethodFlags { + + public static void main(String[] args) throws IOException { + new DefaultMethodFlags().run(args); + } + + void run(String[] args) throws IOException { + checkDefaultMethodFlags(); + } + + void checkDefaultMethodFlags() throws IOException { + JavaCompiler c = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); + Iterable<? extends JavaFileObject> fos = + fm.getJavaFileObjectsFromFiles( + Arrays.asList(new File( + System.getProperty("test.src"), + this.getClass().getSimpleName() + ".java"))); + JavacTask task = (JavacTask) c.getTask(null, fm, null, null, null, fos); + + task.addTaskListener(new TaskListener() { + + @Override + public void started(TaskEvent e) {} + + @Override + public void finished(TaskEvent e) { + if (e.getKind() == TaskEvent.Kind.ANALYZE) { + TypeElement te = e.getTypeElement(); + if (te.getSimpleName().toString().equals("I")) { + checkDefaultInterface(te); + } + } + } + }); + + task.analyze(); + } + + void checkDefaultInterface(TypeElement te) { + System.err.println("Checking " + te.getSimpleName()); + Assert.check(te.getModifiers().contains(Modifier.ABSTRACT)); + for (Element e : te.getEnclosedElements()) { + if (e.getSimpleName().toString().matches("(\\w)_(default|static|abstract)")) { + boolean abstractExpected = false; + String methodKind = e.getSimpleName().toString().substring(2); + switch (methodKind) { + case "default": + case "static": + break; + case "abstract": + abstractExpected = true; + break; + default: + Assert.error("Cannot get here!" + methodKind); + } + Assert.check(e.getModifiers().contains(Modifier.ABSTRACT) == abstractExpected); + } + } + } +} + +interface I { + default void m_default() { } + static void m_static() { } + void m_abstract(); +}
--- a/test/tools/javac/diags/CheckExamples.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/diags/CheckExamples.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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 @@ -34,6 +34,8 @@ */ import java.io.*; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; import java.util.*; /** @@ -53,7 +55,27 @@ * Standard entry point. */ public static void main(String... args) throws Exception { - new CheckExamples().run(); + boolean jtreg = (System.getProperty("test.src") != null); + Path tmpDir; + boolean deleteOnExit; + if (jtreg) { + // use standard jtreg scratch directory: the current directory + tmpDir = Paths.get(System.getProperty("user.dir")); + deleteOnExit = false; + } else { + tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), + CheckExamples.class.getName()); + deleteOnExit = true; + } + Example.setTempDir(tmpDir.toFile()); + + try { + new CheckExamples().run(); + } finally { + if (deleteOnExit) { + clean(tmpDir); + } + } } /** @@ -190,6 +212,25 @@ int errors; + /** + * Clean the contents of a directory. + */ + static void clean(Path dir) throws IOException { + Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return super.visitFile(file, attrs); + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (exc == null) Files.delete(dir); + return super.postVisitDirectory(dir, exc); + } + }); + } + static class Counts { static String[] prefixes = { "compiler.err.",
--- a/test/tools/javac/diags/RunExamples.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/diags/RunExamples.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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,7 +33,8 @@ */ import java.io.*; -import java.text.SimpleDateFormat; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -56,16 +57,18 @@ public class RunExamples { public static void main(String... args) throws Exception { jtreg = (System.getProperty("test.src") != null); - File tmpDir; + Path tmpDir; + boolean deleteOnExit; if (jtreg) { // use standard jtreg scratch directory: the current directory - tmpDir = new File(System.getProperty("user.dir")); + tmpDir = Paths.get(System.getProperty("user.dir")); + deleteOnExit = false; } else { - tmpDir = new File(System.getProperty("java.io.tmpdir"), - RunExamples.class.getName() - + (new SimpleDateFormat("yyMMddHHmmss")).format(new Date())); + tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), + RunExamples.class.getName()); + deleteOnExit = true; } - Example.setTempDir(tmpDir); + Example.setTempDir(tmpDir.toFile()); RunExamples r = new RunExamples(); @@ -73,15 +76,8 @@ if (r.run(args)) return; } finally { - /* VERY IMPORTANT NOTE. In jtreg mode, tmpDir is set to the - * jtreg scratch directory, which is the current directory. - * In case someone is faking jtreg mode, make sure to only - * clean tmpDir when it is reasonable to do so. - */ - if (tmpDir.isDirectory() && - tmpDir.getName().startsWith(RunExamples.class.getName())) { - if (clean(tmpDir)) - tmpDir.delete(); + if (deleteOnExit) { + clean(tmpDir); } } @@ -203,14 +199,20 @@ /** * Clean the contents of a directory. */ - static boolean clean(File dir) { - boolean ok = true; - for (File f: dir.listFiles()) { - if (f.isDirectory()) - ok &= clean(f); - ok &= f.delete(); - } - return ok; + static void clean(Path dir) throws IOException { + Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return super.visitFile(file, attrs); + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (exc == null) Files.delete(dir); + return super.postVisitDirectory(dir, exc); + } + }); } static abstract class Runner {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/BadArgTypesInLambda.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.cant.apply.symbol +// key: compiler.misc.no.conforming.assignment.exists +// key: compiler.misc.bad.arg.types.in.lambda + +class BadArgTypesInLambda { + interface SAM { + void m(Integer i); + } + + void g(SAM s) { } + + void test() { + g(x->{ String s = x; }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/NotAnInterfaceComponent.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.prob.found.req +// key: compiler.misc.bad.intersection.target.for.functional.expr +// key: compiler.misc.not.an.intf.component + +class NotAnInterfaceComponent { + Object o = (Object & Runnable) ()-> { }; +}
--- a/test/tools/javac/diags/examples/SecondaryBoundMustBeMarkerIntf.java Tue Aug 13 17:04:51 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -// key: compiler.err.prob.found.req -// key: compiler.misc.secondary.bound.must.be.marker.intf - -class SecondaryBoundMustBeMarkerInterface { - Runnable r = (Runnable & Comparable<?>)()->{}; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/doclint/ImplicitHeadersTest.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8006346 + * @summary doclint should make allowance for headers generated by standard doclet + * @compile -Xdoclint:all/public ImplicitHeadersTest.java + */ + +/** + * <h3> Header </h3> + */ +public class ImplicitHeadersTest { } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/doctree/positions/TestPosition.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8008174 + * @summary proper source positions for doc comments + * @build TestPosition + * @compile/ref=TestPosition.out -processor TestPosition -proc:only TestPositionSource.java + */ + +import com.sun.source.doctree.DocCommentTree; +import com.sun.source.doctree.DocTree; +import com.sun.source.tree.MethodTree; +import com.sun.source.util.DocSourcePositions; +import com.sun.source.util.DocTreeScanner; +import com.sun.source.util.DocTrees; +import com.sun.source.util.TreePath; +import com.sun.source.util.TreePathScanner; +import java.io.IOException; +import java.util.Set; +import javax.annotation.processing.*; +import javax.lang.model.*; +import javax.lang.model.element.*; + +@SupportedAnnotationTypes("*") +public class TestPosition extends AbstractProcessor { + + @Override + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + TypeElement source = processingEnv.getElementUtils().getTypeElement("TestPositionSource"); + + if (source == null) throw new IllegalStateException(); + + if (!roundEnv.getRootElements().contains(source)) return false; + + final DocTrees trees = DocTrees.instance(processingEnv); + final TreePath testElement = trees.getPath(source); + + if (testElement == null) throw new IllegalStateException(); + + String code; + + try { + code = testElement.getCompilationUnit().getSourceFile().getCharContent(false).toString(); + } catch ( IOException ex) { + throw new IllegalStateException(ex); + } + + new TreePathScanner<Void, Void>() { + @Override public Void visitMethod(MethodTree node, Void p) { + final DocCommentTree docCommentTree = trees.getDocCommentTree(getCurrentPath()); + + if (docCommentTree != null) { + System.out.println(node.getName() + ":"); + new DocTreeScanner<Void, Void>() { + @Override public Void scan(DocTree node, Void p) { + if (node != null) { + DocSourcePositions sp = (DocSourcePositions) trees.getSourcePositions(); //XXX: the cast??? + int start = (int) sp.getStartPosition(testElement.getCompilationUnit(), docCommentTree, node); + int end = (int) sp.getEndPosition(testElement.getCompilationUnit(), docCommentTree, node); + String snippet = code.substring(start, end).replace(" \n", "!trailing-whitespace!\n"); + + if (snippet.endsWith(" ")) { + snippet = snippet.substring(0, snippet.length() - 1) + "!trailing-whitespace!"; + } + System.out.println(node.getKind().name() + ":" + snippet); + } + return super.scan(node, p); + } + }.scan(docCommentTree, null); + } + + return super.visitMethod(node, p); + } + }.scan(testElement, null); + + return false; + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/doctree/positions/TestPosition.out Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,99 @@ +valid: +DOC_COMMENT:First sentence. + * + * <p>Description with {@link java.io.InputStream link} + * + * @param first description + * @param second description + * @return whatever + * @throws IllegalStateException why? + * @since 1.15 + * @see java.util.List +TEXT:First sentence. +START_ELEMENT:<p> +TEXT:Description with!trailing-whitespace! +LINK:{@link java.io.InputStream link} +REFERENCE:java.io.InputStream +TEXT:link +PARAM:@param first description +IDENTIFIER:first +TEXT:description +PARAM:@param second description +IDENTIFIER:second +TEXT:description +RETURN:@return whatever +TEXT:whatever +THROWS:@throws IllegalStateException why? +REFERENCE:IllegalStateException +TEXT:why? +SINCE:@since 1.15 +TEXT:1.15 +SEE:@see java.util.List +REFERENCE:java.util.List +erroneous: +DOC_COMMENT:First sentence. + * + * <p>Description with {@link}, {@link java.util.List}, {@link + * + * @param + * @param second + * @return + * @throws + * @throws IllegalStateException + * @since + * @see +TEXT:First sentence. +START_ELEMENT:<p> +TEXT:Description with!trailing-whitespace! +LINK:{@link} +TEXT:,!trailing-whitespace! +LINK:{@link java.util.List} +REFERENCE:java.util.List +TEXT:,!trailing-whitespace! +ERRONEOUS:{@link +ERRONEOUS:@param +PARAM:@param second +IDENTIFIER:second +RETURN:@return +ERRONEOUS:@throws +THROWS:@throws IllegalStateException +REFERENCE:IllegalStateException +SINCE:@since +ERRONEOUS:@see +withWhiteSpaces: +DOC_COMMENT:First sentence. + * + * <p>Description with {@link }, {@link java.util.List#add( int )}, + * {@link java.util.List#add( int ) some text with whitespaces}, {@link + * + * @param first + * @param second some text with trailing whitespace + * @return some return + * @throws java.lang.IllegalStateException + * @throws java.lang.IllegalStateException some text +TEXT:First sentence. +START_ELEMENT:<p> +TEXT:Description with!trailing-whitespace! +LINK:{@link } +TEXT:,!trailing-whitespace! +LINK:{@link java.util.List#add( int )} +REFERENCE:java.util.List#add( int ) +TEXT:, + *!trailing-whitespace! +LINK:{@link java.util.List#add( int ) some text with whitespaces} +REFERENCE:java.util.List#add( int ) +TEXT:some text with whitespaces +TEXT:,!trailing-whitespace! +ERRONEOUS:{@link +PARAM:@param first +IDENTIFIER:first +PARAM:@param second some text with trailing whitespace +IDENTIFIER:second +TEXT:some text with trailing whitespace +RETURN:@return some return +TEXT:some return +THROWS:@throws java.lang.IllegalStateException +REFERENCE:java.lang.IllegalStateException +THROWS:@throws java.lang.IllegalStateException some text +REFERENCE:java.lang.IllegalStateException +TEXT:some text \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/doctree/positions/TestPositionSource.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +public class TestPositionSource { + + /**First sentence. + * + * <p>Description with {@link java.io.InputStream link} + * + * @param first description + * @param second description + * @return whatever + * @throws IllegalStateException why? + * @since 1.15 + * @see java.util.List + */ + public boolean valid(int first, int second) throws IllegalStateException { + return true; + } + + /**First sentence. + * + * <p>Description with {@link}, {@link java.util.List}, {@link + * + * @param + * @param second + * @return + * @throws + * @throws IllegalStateException + * @since + * @see + */ + public boolean erroneous(int first, int second) throws IllegalStateException { + return true; + } + + /**First sentence. + * + * <p>Description with {@link }, {@link java.util.List#add( int )}, + * {@link java.util.List#add( int ) some text with whitespaces}, {@link + * + * @param first + * @param second some text with trailing whitespace + * @return some return + * @throws java.lang.IllegalStateException + * @throws java.lang.IllegalStateException some text + */ + public boolean withWhiteSpaces(int first, int second) throws IllegalStateException { + return true; + } + +}
--- a/test/tools/javac/lambda/BadRecovery.out Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/lambda/BadRecovery.out Fri Sep 27 15:41:28 2013 +0100 @@ -1,3 +1,2 @@ -BadRecovery.java:17:9: compiler.err.cant.apply.symbol: kindname.method, m, BadRecovery.SAM1, @369, kindname.class, BadRecovery, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.lambda)) BadRecovery.java:17:77: compiler.err.cant.resolve.location: kindname.variable, f, , , (compiler.misc.location: kindname.class, BadRecovery, null) -2 errors +1 error
--- a/test/tools/javac/lambda/Intersection01.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/lambda/Intersection01.java Fri Sep 27 15:41:28 2013 +0100 @@ -25,7 +25,7 @@ * @test * @bug 8002099 * @summary Add support for intersection types in cast expression - * @compile/fail/ref=Intersection01.out -XDrawDiagnostics Intersection01.java + * @compile Intersection01.java */ class Intersection01 {
--- a/test/tools/javac/lambda/Intersection01.out Tue Aug 13 17:04:51 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -Intersection01.java:36:45: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf.1: java.io.Serializable, (compiler.misc.no.abstracts: kindname.interface, java.io.Serializable)) -Intersection01.java:38:45: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf.1: java.io.Serializable, (compiler.misc.no.abstracts: kindname.interface, java.io.Serializable)) -2 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/Intersection03.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8011392 + * @summary Missing checkcast when casting to intersection type + */ +import java.util.*; + +public class Intersection03 { + + static int assertionCount = 0; + + static void assertTrue(boolean cond) { + assertionCount++; + if (!cond) throw new AssertionError(); + } + + public static void main(String[] args) { + try { + Runnable r = (List<?> & Runnable)new ArrayList<String>(); + assertTrue(false); + } catch (ClassCastException cce) { + assertTrue(true); + } + assertTrue(assertionCount == 1); + } +}
--- a/test/tools/javac/lambda/TargetType01.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/lambda/TargetType01.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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,11 +23,10 @@ /* * @test - * @bug 8003280 + * @bug 8003280 8009131 * @summary Add lambda tests * check nested case of overload resolution and lambda parameter inference - * @author Maurizio Cimadamore - * @compile/fail/ref=TargetType01.out -XDrawDiagnostics TargetType01.java + * @compile TargetType01.java */ class TargetType01 {
--- a/test/tools/javac/lambda/TargetType01.out Tue Aug 13 17:04:51 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -TargetType01.java:46:9: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 -TargetType01.java:46:26: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 -2 errors
--- a/test/tools/javac/lambda/TargetType43.out Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/lambda/TargetType43.out Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,4 @@ TargetType43.java:13:20: compiler.err.prob.found.req: (compiler.misc.not.a.functional.intf: java.lang.Object) TargetType43.java:13:30: compiler.err.cant.resolve.location: kindname.class, NonExistentClass, , , (compiler.misc.location: kindname.class, TargetType43, null) -TargetType43.java:14:9: compiler.err.cant.apply.symbol: kindname.method, m, java.lang.Object, @359, kindname.class, TargetType43, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: java.lang.Object)) TargetType43.java:14:21: compiler.err.cant.resolve.location: kindname.class, NonExistentClass, , , (compiler.misc.location: kindname.class, TargetType43, null) -4 errors +3 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/TargetType66.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,26 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8009131 + * @summary Overload: javac should discard methods that lead to errors in lambdas with implicit parameter types + * @compile/fail/ref=TargetType66.out -XDrawDiagnostics TargetType66.java + */ +class TargetType66 { + interface SAM1 { + void m(String s); + } + + interface SAM2 { + void m(Integer s); + } + + void g(SAM1 s1) { } + void g(SAM2 s2) { } + + void test() { + g(x->{ String s = x; }); //g(SAM1) + g(x->{ Integer i = x; }); //g(SAM2) + g(x->{ Object o = x; }); //ambiguous + g(x->{ Character c = x; }); //error: inapplicable methods + g(x->{ Character c = ""; }); //error: incompatible types + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/TargetType66.out Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,4 @@ +TargetType66.java:22:9: compiler.err.ref.ambiguous: g, kindname.method, g(TargetType66.SAM1), TargetType66, kindname.method, g(TargetType66.SAM2), TargetType66 +TargetType66.java:23:9: compiler.err.cant.apply.symbols: kindname.method, g, @578,{(compiler.misc.inapplicable.method: kindname.method, TargetType66, g(TargetType66.SAM1), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.bad.arg.types.in.lambda: java.lang.String))),(compiler.misc.inapplicable.method: kindname.method, TargetType66, g(TargetType66.SAM2), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.bad.arg.types.in.lambda: java.lang.Integer)))} +TargetType66.java:24:30: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Character) +3 errors
--- a/test/tools/javac/lambda/TargetType69.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/lambda/TargetType69.java Fri Sep 27 15:41:28 2013 +0100 @@ -25,11 +25,11 @@ * @test * @bug 8010303 * @summary Graph inference: missing incorporation step causes spurious inference error - * @compile TargetType68.java + * @compile TargetType69.java */ import java.util.*; -class TargetType68 { +class TargetType69 { interface Function<X,Y> { Y m(X x);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/TargetType70.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8011028 + * @summary lang/INFR/infr001/infr00101md/infr00101md.java fails to compile after switch to JDK8-b82 + * @compile TargetType70.java + */ +class TargetType70 { + + static class Sup {} + static class Sub extends Sup {} + + interface I<T extends GenSup<U>, U> { + T m(U o); + } + + static class GenSup<T> { + GenSup(T f) { } + } + + static class GenSub<T> extends GenSup<T> { + GenSub(T f) { super(f); } + } + + <T extends Sup> void m(I<? extends GenSup<T>, T> o1, T o2) { } + + void test(Sub sub) { + m(GenSub::new, sub); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/TargetType71.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8011377 + * @summary Javac crashes when multiple lambdas are defined in an array + * @compile TargetType71.java + */ +class TargetType71 { + void test() { + Runnable[] rs = { () -> { String x = null; }, () -> { String x = null; } }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/TargetType72.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8011376 + * @summary Spurious checked exception errors in nested method call + * @compile TargetType72.java + */ +import java.io.IOException; +import java.util.concurrent.Callable; + +class TargetType72 { + + Callable<Number> c = id(id(()->{ if (true) throw new java.io.IOException(); return 0; })); + + <Z> Z id(Z z) { return null; } + +}
--- a/test/tools/javac/lambda/TestInvokeDynamic.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/lambda/TestInvokeDynamic.java Fri Sep 27 15:41:28 2013 +0100 @@ -24,7 +24,7 @@ /* * @test * @bug 7194586 - * @bug 8003280 8006694 + * @bug 8003280 8006694 8010404 * @summary Add lambda tests * Add back-end support for invokedynamic * temporarily workaround combo tests are causing time out in several platforms @@ -48,6 +48,7 @@ import com.sun.tools.classfile.Code_attribute; import com.sun.tools.classfile.ConstantPool.*; import com.sun.tools.classfile.Instruction; +import com.sun.tools.classfile.LineNumberTable_attribute; import com.sun.tools.classfile.Method; import com.sun.tools.javac.api.JavacTaskImpl; @@ -239,7 +240,7 @@ int id = checkCount.incrementAndGet(); JavaSource source = new JavaSource(id); JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, fm.get(), dc, - null, null, Arrays.asList(source)); + Arrays.asList("-g"), null, Arrays.asList(source)); Context context = ct.getContext(); Symtab syms = Symtab.instance(context); Names names = Names.instance(context); @@ -349,6 +350,16 @@ bsm_ref.getNameAndTypeInfo().getType() + " " + asBSMSignatureString()); } + + LineNumberTable_attribute lnt = + (LineNumberTable_attribute)ea.attributes.get(Attribute.LineNumberTable); + + if (lnt == null) { + throw new Error("No LineNumberTable attribute"); + } + if (lnt.line_number_table_length != 2) { + throw new Error("Wrong number of entries in LineNumberTable"); + } } catch (Exception e) { e.printStackTrace(); throw new Error("error reading " + compiledTest +": " + e); @@ -376,7 +387,10 @@ "}\n" + "class Test#ID {\n" + " void m() { }\n" + - " void test() { m(); }\n" + + " void test() {\n" + + " Object o = this; // marker statement \n" + + " m();\n" + + " }\n" + "}"; String source;
--- a/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java Fri Sep 27 15:41:28 2013 +0100 @@ -28,10 +28,11 @@ */ import com.sun.source.util.JavacTask; -import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import java.net.URI; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import javax.tools.Diagnostic; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; @@ -45,37 +46,45 @@ enum BoundKind { INTF, - CLASS, - SAM, - ZAM; + CLASS; } enum MethodKind { - NONE, - ABSTRACT, - DEFAULT; + NONE(false), + ABSTRACT_M(true), + DEFAULT_M(false), + ABSTRACT_G(true), + DEFAULT_G(false); + + boolean isAbstract; + + MethodKind(boolean isAbstract) { + this.isAbstract = isAbstract; + } } enum TypeKind { - A("interface A { }\n", "A", BoundKind.ZAM), - B("interface B { default void m() { } }\n", "B", BoundKind.ZAM), - C("interface C { void m(); }\n", "C", BoundKind.SAM), - D("interface D extends B { }\n", "D", BoundKind.ZAM), - E("interface E extends C { }\n", "E", BoundKind.SAM), - F("interface F extends C { void g(); }\n", "F", BoundKind.INTF), - G("interface G extends B { void g(); }\n", "G", BoundKind.SAM), - H("interface H extends A { void g(); }\n", "H", BoundKind.SAM), + A("interface A { }\n", "A", BoundKind.INTF, MethodKind.NONE), + B("interface B { default void m() { } }\n", "B", BoundKind.INTF, MethodKind.DEFAULT_M), + C("interface C { void m(); }\n", "C", BoundKind.INTF, MethodKind.ABSTRACT_M), + D("interface D extends B { }\n", "D", BoundKind.INTF, MethodKind.DEFAULT_M), + E("interface E extends C { }\n", "E", BoundKind.INTF, MethodKind.ABSTRACT_M), + F("interface F extends C { void g(); }\n", "F", BoundKind.INTF, MethodKind.ABSTRACT_G, MethodKind.ABSTRACT_M), + G("interface G extends B { void g(); }\n", "G", BoundKind.INTF, MethodKind.ABSTRACT_G, MethodKind.DEFAULT_M), + H("interface H extends A { void g(); }\n", "H", BoundKind.INTF, MethodKind.ABSTRACT_G), OBJECT("", "Object", BoundKind.CLASS), STRING("", "String", BoundKind.CLASS); String declStr; String typeStr; BoundKind boundKind; + MethodKind[] methodKinds; - private TypeKind(String declStr, String typeStr, BoundKind boundKind) { + private TypeKind(String declStr, String typeStr, BoundKind boundKind, MethodKind... methodKinds) { this.declStr = declStr; this.typeStr = typeStr; this.boundKind = boundKind; + this.methodKinds = methodKinds; } boolean compatibleSupertype(TypeKind tk) { @@ -263,14 +272,22 @@ boolean errorExpected = !cInfo.wellFormed(); if (ek.isFunctional) { - //first bound must be a SAM - errorExpected |= cInfo.types[0].boundKind != BoundKind.SAM; - if (cInfo.types.length > 1) { - //additional bounds must be ZAMs - for (int i = 1; i < cInfo.types.length; i++) { - errorExpected |= cInfo.types[i].boundKind != BoundKind.ZAM; + List<MethodKind> mks = new ArrayList<>(); + for (TypeKind tk : cInfo.types) { + if (tk.boundKind == BoundKind.CLASS) { + errorExpected = true; + break; + } else { + mks = mergeMethods(mks, Arrays.asList(tk.methodKinds)); } } + int abstractCount = 0; + for (MethodKind mk : mks) { + if (mk.isAbstract) { + abstractCount++; + } + } + errorExpected |= abstractCount != 1; } if (errorExpected != diagChecker.errorFound) { @@ -281,6 +298,32 @@ } } + List<MethodKind> mergeMethods(List<MethodKind> l1, List<MethodKind> l2) { + List<MethodKind> mergedMethods = new ArrayList<>(l1); + for (MethodKind mk2 : l2) { + boolean add = !mergedMethods.contains(mk2); + switch (mk2) { + case ABSTRACT_G: + add = add && !mergedMethods.contains(MethodKind.DEFAULT_G); + break; + case ABSTRACT_M: + add = add && !mergedMethods.contains(MethodKind.DEFAULT_M); + break; + case DEFAULT_G: + mergedMethods.remove(MethodKind.ABSTRACT_G); + case DEFAULT_M: + mergedMethods.remove(MethodKind.ABSTRACT_M); + case NONE: + add = false; + break; + } + if (add) { + mergedMethods.add(mk2); + } + } + return mergedMethods; + } + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { boolean errorFound;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestNewInnerImplicitArgs.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013, 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. + */ + +/** + * @test + * @bug 8011591 + * @summary BootstrapMethodError when capturing constructor ref to local classes + * @run testng MethodReferenceTestNewInnerImplicitArgs + */ + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +/** + * Test the case that a constructor has implicit parameters added to + * access local variables and that this constructor is used in a + * method reference. + * @author Robert Field + */ + +@Test +public class MethodReferenceTestNewInnerImplicitArgs { + + + static class S { + String b; + S(String s, String s2) { b = s + s2; } + } + + interface I { + S m(); + } + + interface I2 { + S m(int i, int j); + } + + public static void testConstructorReferenceImplicitParameters() { + String title = "Hey"; + String a2 = "!!!"; + class MS extends S { + MS() { + super(title, a2); + } + } + + I result = MS::new; + assertEquals(result.m().b, "Hey!!!"); + + class MS2 extends S { + MS2(int x, int y) { + super(title+x, a2+y); + } + } + + I2 result2 = MS2::new; + assertEquals(result2.m(8, 4).b, "Hey8!!!4"); + } +}
--- a/test/tools/javac/lambdaShapes/org/openjdk/tests/vm/DefaultMethodsTest.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/lambdaShapes/org/openjdk/tests/vm/DefaultMethodsTest.java Fri Sep 27 15:41:28 2013 +0100 @@ -427,6 +427,8 @@ */ public void testReflectCall() { Interface I = new Interface("I", DefaultMethod.std("99")); + //workaround accessibility issue when loading C with DirectedClassLoader + I.addAccessFlag(AccessFlag.PUBLIC); Class C = new Class("C", I); Compiler.Flags[] flags = this.verbose ?
--- a/test/tools/javac/processing/model/element/TestExecutableElement.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/processing/model/element/TestExecutableElement.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 8005046 + * @bug 8005046 8011052 * @summary Test basic properties of javax.lang.element.Element * @author Joseph D. Darcy * @library /tools/javac/lib @@ -35,6 +35,7 @@ import java.util.Formatter; import java.util.Set; import java.util.Objects; +import java.util.regex.*; import javax.annotation.processing.*; import javax.lang.model.SourceVersion; import static javax.lang.model.SourceVersion.*; @@ -79,9 +80,39 @@ boolean methodIsDefault = method.isDefault(); + if (expectedDefault) { + if (!method.getModifiers().contains(Modifier.DEFAULT)) { + messager.printMessage(ERROR, + "Modifier \"default\" not present as expected.", + method); + } + + // Check printing output + java.io.Writer stringWriter = new java.io.StringWriter(); + eltUtils.printElements(stringWriter, method); + Pattern p = Pattern.compile(expectedIsDefault.expectedTextRegex(), Pattern.DOTALL); + + if (! p.matcher(stringWriter.toString()).matches()) { + messager.printMessage(ERROR, + new Formatter().format("Unexpected printing ouptput:%n\tgot %s,%n\texpected pattern %s.", + stringWriter.toString(), + expectedIsDefault.expectedTextRegex()).toString(), + method); + } + + System.out.println("\t" + stringWriter.toString()); + + } else { + if (method.getModifiers().contains(Modifier.DEFAULT)) { + messager.printMessage(ERROR, + "Modifier \"default\" present when not expected.", + method); + } + } + if (methodIsDefault != expectedDefault) { messager.printMessage(ERROR, - new Formatter().format("Unexpected Executable.isDefault result: got %s, expected %s", + new Formatter().format("Unexpected Executable.isDefault result: got ``%s'', expected ``%s''.", expectedDefault, methodIsDefault).toString(), method); @@ -98,6 +129,7 @@ @Target(ElementType.METHOD) @interface IsDefault { boolean value(); + String expectedTextRegex() default ""; } /** @@ -108,6 +140,6 @@ boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv); - @IsDefault(true) - default void quux() {}; + @IsDefault(value=true, expectedTextRegex="\\s*@IsDefault\\(.*\\)\\s*default strictfp void quux\\(\\);\\s*$") + default strictfp void quux() {}; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/model/element/TestTypeParameterAnnotations.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8011027 + * @library /tools/javac/lib + * @build JavacTestingAbstractProcessor TestTypeParameterAnnotations + * @compile -processor TestTypeParameterAnnotations -proc:only TestTypeParameterAnnotations.java + */ + +import java.util.*; +import java.lang.annotation.*; +import javax.annotation.processing.*; +import javax.lang.model.element.*; +import javax.lang.model.util.*; +import javax.tools.*; + +public class TestTypeParameterAnnotations<@Foo @Bar @Baz T> extends JavacTestingAbstractProcessor { + int round = 0; + + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + if (++round == 1) { + int found = (new Scanner()).scan(roundEnv.getRootElements(), null); + if (found == expect) { + ; //nop + } else { + error("unexpected number of results: expected " + expect + + ", found " + found); + } + + } + return true; + } + + class Scanner extends JavacTestingAbstractProcessor.ElementScanner<Integer,Void> { + @Override + public Integer visitExecutable(ExecutableElement e, Void p) { + super.visitExecutable(e, p); + found += check(e, e.getTypeParameters()); + return found; + } + + @Override + public Integer visitType(TypeElement e, Void p) { + super.visitType(e, p); + found += check(e, e.getTypeParameters()); + return found; + } + + int found; + } + + int check(Element e, List<? extends TypeParameterElement> typarams) { + if (typarams.isEmpty()) + return 0; + if (typarams.size() != 1) + return 0; + + for (TypeParameterElement tpe: typarams) { + boolean b1 = checkAnnotationMirrors(tpe, tpe.getAnnotationMirrors()); + boolean b2 = checkAnnotationMirrors(tpe, elements.getAllAnnotationMirrors(tpe)); + boolean b3 = checkGetAnnotation(tpe); + boolean b4 = checkGetAnnotations(tpe); + return b1 && b2 && b3 && b4 ? 1 : 0; + } + return 0; + } + + boolean checkAnnotationMirrors(TypeParameterElement tpe, List<? extends AnnotationMirror> l) { + if (l.size() != 3) { + error("To few annotations, got " + l.size() + + ", should be 3", tpe); + return false; + } + + AnnotationMirror m = l.get(0); + if (!m.getAnnotationType().asElement().equals(elements.getTypeElement("Foo"))) { + error("Wrong type of annotation, was expecting @Foo", m.getAnnotationType().asElement()); + return false; + } + m = l.get(1); + if (!m.getAnnotationType().asElement().equals(elements.getTypeElement("Bar"))) { + error("Wrong type of annotation, was expecting @Bar", m.getAnnotationType().asElement()); + return false; + } + m = l.get(2); + if (!m.getAnnotationType().asElement().equals(elements.getTypeElement("Baz"))) { + error("Wrong type of annotation, was expecting @Baz", m.getAnnotationType().asElement()); + return false; + } + return true; + } + + boolean checkGetAnnotation(TypeParameterElement tpe) { + Foo f = tpe.getAnnotation(Foo.class); + if (f == null) + error("Expecting @Foo to be present in getAnnotation()", tpe); + + Bar b = tpe.getAnnotation(Bar.class); + if (b == null) + error("Expecting @Bar to be present in getAnnotation()", tpe); + + Baz z = tpe.getAnnotation(Baz.class); + if (z == null) + error("Expecting @Baz to be present in getAnnotation()", tpe); + + return f != null && + b != null && + z != null; + } + + boolean checkGetAnnotations(TypeParameterElement tpe) { + Foo[] f = tpe.getAnnotationsByType(Foo.class); + if (f.length != 1) { + error("Expecting 1 @Foo to be present in getAnnotationsByType()", tpe); + return false; + } + + Bar[] b = tpe.getAnnotationsByType(Bar.class); + if (b.length != 1) { + error("Expecting 1 @Bar to be present in getAnnotationsByType()", tpe); + return false; + } + + Baz[] z = tpe.getAnnotationsByType(Baz.class); + if (z.length != 1) { + error("Expecting 1 @Baz to be present in getAnnotationsByType()", tpe); + return false; + } + + return true; + } + + void note(String msg) { + messager.printMessage(Diagnostic.Kind.NOTE, msg); + } + + void note(String msg, Element e) { + messager.printMessage(Diagnostic.Kind.NOTE, msg, e); + } + + void error(String msg, Element e) { + messager.printMessage(Diagnostic.Kind.ERROR, msg, e); + } + + void error(String msg) { + messager.printMessage(Diagnostic.Kind.ERROR, msg); + } + + // additional generic elements to test + <@Foo @Bar @Baz X> X m(X x) { return x; } + + interface Intf<@Foo @Bar @Baz X> { X m() ; } + + class Class<@Foo @Bar @Baz X> { + <@Foo @Bar @Baz Y> Class() { } + } + + final int expect = 5; // top level class, plus preceding examples +} + +@Target(ElementType.TYPE_PARAMETER) +@interface Foo {} + +@Target(ElementType.TYPE_PARAMETER) +@interface Bar {} + +@Target(ElementType.TYPE_PARAMETER) +@interface Baz {}
--- a/test/tools/javac/scope/7017664/CompoundScopeTest.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/scope/7017664/CompoundScopeTest.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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 @@ -147,7 +147,7 @@ Scope createScope(int nelems) { Scope s = new Scope(symtab.noSymbol); for (int i = 0 ; i < nelems ; i++) { - Symbol sym = new TypeSymbol(0, names.fromString("s" + i), null, null); + Symbol sym = new TypeVariableSymbol(0, names.fromString("s" + i), null, null); s.enter(sym); elems = elems.prepend(sym); List<Symbol> shadowed = shadowedMap.get(sym.name);
--- a/test/tools/javac/types/TypeHarness.java Tue Aug 13 17:04:51 2013 +0100 +++ b/test/tools/javac/types/TypeHarness.java Fri Sep 27 15:41:28 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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 @@ -309,7 +309,7 @@ } public TypeVar TypeVariable(Type bound) { - TypeSymbol tvsym = new TypeSymbol(0, syntheticName(), null, predef.noSymbol); + TypeSymbol tvsym = new TypeVariableSymbol(0, syntheticName(), null, predef.noSymbol); tvsym.type = new TypeVar(tvsym, bound, null); return (TypeVar)tvsym.type; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javadoc/doclint/ImplicitHeadersTest.java Fri Sep 27 15:41:28 2013 +0100 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8006346 + * @summary doclint should make allowance for headers generated by standard doclet + */ + +import java.io.File; + +/** + * <h3> Header </h3> + */ +public class ImplicitHeadersTest { + public static void main(String... args) { + File testSrc = new File(System.getProperty("test.src")); + File testFile = new File(testSrc, ImplicitHeadersTest.class.getSimpleName() + ".java"); + String[] javadocArgs = { "-d", "out", testFile.getPath() }; + int rc = com.sun.tools.javadoc.Main.execute(javadocArgs); + if (rc != 0) + throw new Error("unexpected exit: rc=" + rc); + } +} +