# HG changeset patch # User lana # Date 1302456312 25200 # Node ID 06671f24eb6c0cdd3e41a95496db8b81012b6226 # Parent 5dbb4c781342b277b20f29984225fb792e80886d# Parent 7c9ef56ec288feb178d07c62cb8a404f3012b7e9 Merge diff -r 5dbb4c781342 -r 06671f24eb6c langtools/make/build.xml --- a/langtools/make/build.xml Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/make/build.xml Sun Apr 10 10:25:12 2011 -0700 @@ -806,6 +806,9 @@ + + + diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/classfile/Type.java --- a/langtools/src/share/classes/com/sun/tools/classfile/Type.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/classfile/Type.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2011, 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 @@ -41,6 +41,11 @@ */ public abstract class Type { protected Type() { } + + public boolean isObject() { + return false; + } + public abstract R accept(Visitor visitor, D data); protected static void append(StringBuilder sb, String prefix, List types, String suffix) { @@ -262,6 +267,13 @@ return sb.toString(); } + @Override + public boolean isObject() { + return (outerType == null) + && name.equals("java/lang/Object") + && (typeArgs == null || typeArgs.isEmpty()); + } + public final ClassType outerType; public final String name; public final List typeArgs; diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -154,8 +154,8 @@ div.addStyle(HtmlStyle.header); if (pkgname.length() > 0) { Content pkgNameContent = new StringContent(pkgname); - Content pkgNamePara = HtmlTree.P(HtmlStyle.subTitle, pkgNameContent); - div.addContent(pkgNamePara); + Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, pkgNameContent); + div.addContent(pkgNameDiv); } LinkInfoImpl linkInfo = new LinkInfoImpl( LinkInfoImpl.CONTEXT_CLASS_HEADER, annotationType, false); @@ -216,12 +216,15 @@ pre.addContent(modifiers); LinkInfoImpl linkInfo = new LinkInfoImpl( LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, annotationType, false); - Content name = new RawHtml (annotationType.name() + - getTypeParameterLinks(linkInfo)); + Content annotationName = new StringContent(annotationType.name()); + Content parameterLinks = new RawHtml(getTypeParameterLinks(linkInfo)); if (configuration().linksource) { - addSrcLink(annotationType, name, pre); + addSrcLink(annotationType, annotationName, pre); + pre.addContent(parameterLinks); } else { - pre.addContent(HtmlTree.STRONG(name)); + Content span = HtmlTree.SPAN(HtmlStyle.strong, annotationName); + span.addContent(parameterLinks); + pre.addContent(span); } annotationInfoTree.addContent(pre); } diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -161,8 +161,8 @@ div.addStyle(HtmlStyle.header); if (pkgname.length() > 0) { Content pkgNameContent = new StringContent(pkgname); - Content pkgNamePara = HtmlTree.P(HtmlStyle.subTitle, pkgNameContent); - div.addContent(pkgNamePara); + Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, pkgNameContent); + div.addContent(pkgNameDiv); } LinkInfoImpl linkInfo = new LinkInfoImpl( LinkInfoImpl.CONTEXT_CLASS_HEADER, classDoc, false); @@ -228,12 +228,15 @@ LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, classDoc, false); //Let's not link to ourselves in the signature. linkInfo.linkToSelf = false; - Content name = new RawHtml (classDoc.name() + - getTypeParameterLinks(linkInfo)); + Content className = new StringContent(classDoc.name()); + Content parameterLinks = new RawHtml(getTypeParameterLinks(linkInfo)); if (configuration().linksource) { - addSrcLink(classDoc, name, pre); + addSrcLink(classDoc, className, pre); + pre.addContent(parameterLinks); } else { - pre.addContent(HtmlTree.STRONG(name)); + Content span = HtmlTree.SPAN(HtmlStyle.strong, className); + span.addContent(parameterLinks); + pre.addContent(span); } if (!isInterface) { Type superclass = Util.getFirstVisibleSuperClass(classDoc, diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java Sun Apr 10 10:25:12 2011 -0700 @@ -114,13 +114,10 @@ Content noframesHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, getResource("doclet.Frame_Alert")); noframes.addContent(noframesHead); - Content p = HtmlTree.P(getResource("doclet.Frame_Warning_Message")); + Content p = HtmlTree.P(getResource("doclet.Frame_Warning_Message", + getHyperLinkString(configuration.topFile, + configuration.getText("doclet.Non_Frame_Version")))); noframes.addContent(p); - noframes.addContent(new HtmlTree(HtmlTag.BR)); - noframes.addContent(getResource("doclet.Link_To")); - Content link = getHyperLink(configuration.topFile, - getResource("doclet.Non_Frame_Version")); - noframes.addContent(link); contentTree.addContent(noframes); } diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 @@ -96,7 +96,7 @@ Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, HtmlStyle.title, getResource("doclet.Help_line_1")); Content div = HtmlTree.DIV(HtmlStyle.header, heading); - Content line2 = HtmlTree.P(HtmlStyle.subTitle, + Content line2 = HtmlTree.DIV(HtmlStyle.subTitle, getResource("doclet.Help_line_2")); div.addContent(line2); contentTree.addContent(div); diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/formats/html/LinkFactoryImpl.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/LinkFactoryImpl.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/LinkFactoryImpl.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -69,9 +69,6 @@ StringBuffer label = new StringBuffer( classLinkInfo.getClassLinkLabel(m_writer.configuration)); classLinkInfo.displayLength += label.length(); - if (noLabel && classLinkInfo.excludeTypeParameterLinks) { - label.append(getTypeParameterLinks(linkInfo).toString()); - } Configuration configuration = ConfigurationImpl.getInstance(); LinkOutputImpl linkOutput = new LinkOutputImpl(); if (classDoc.isIncluded()) { diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/formats/html/LinkInfoImpl.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/LinkInfoImpl.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/LinkInfoImpl.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -408,10 +408,6 @@ case CONTEXT_PACKAGE: case CONTEXT_CLASS_USE: - excludeTypeBoundsLinks = true; - excludeTypeParameterLinks = true; - break; - case CONTEXT_CLASS_HEADER: case CONTEXT_CLASS_SIGNATURE: excludeTypeParameterLinks = true; diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -163,10 +163,10 @@ */ protected void addOverviewHeader(Content body) { if (root.inlineTags().length > 0) { - HtmlTree p = new HtmlTree(HtmlTag.P); - p.addStyle(HtmlStyle.subTitle); - addSummaryComment(root, p); - Content div = HtmlTree.DIV(HtmlStyle.header, p); + HtmlTree subTitleDiv = new HtmlTree(HtmlTag.DIV); + subTitleDiv.addStyle(HtmlStyle.subTitle); + addSummaryComment(root, subTitleDiv); + Content div = HtmlTree.DIV(HtmlStyle.header, subTitleDiv); Content see = seeLabel; see.addContent(" "); Content descPara = HtmlTree.P(see); @@ -188,10 +188,10 @@ protected void addOverviewComment(Content htmltree) { if (root.inlineTags().length > 0) { htmltree.addContent(getMarkerAnchor("overview_description")); - HtmlTree p = new HtmlTree(HtmlTag.P); - p.addStyle(HtmlStyle.subTitle); - addInlineComment(root, p); - htmltree.addContent(p); + HtmlTree div = new HtmlTree(HtmlTag.DIV); + div.addStyle(HtmlStyle.subTitle); + addInlineComment(root, div); + htmltree.addContent(div); } } diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageWriterImpl.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageWriterImpl.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageWriterImpl.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -115,10 +115,10 @@ tHeading.addContent(packageHead); div.addContent(tHeading); if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) { - HtmlTree p = new HtmlTree(HtmlTag.P); - p.addStyle(HtmlStyle.subTitle); - addSummaryComment(packageDoc, p); - div.addContent(p); + HtmlTree subTitleDiv = new HtmlTree(HtmlTag.DIV); + subTitleDiv.addStyle(HtmlStyle.subTitle); + addSummaryComment(packageDoc, subTitleDiv); + div.addContent(subTitleDiv); Content space = getSpace(); Content descLink = getHyperLink("", "package_description", descriptionLabel, "", ""); diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, 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 @@ -188,8 +188,8 @@ nextclassLabel = getResource("doclet.Next_Class"); summaryLabel = getResource("doclet.Summary"); detailLabel = getResource("doclet.Detail"); - framesLabel = getResource("doclet.FRAMES"); - noframesLabel = getResource("doclet.NO_FRAMES"); + framesLabel = getResource("doclet.Frames"); + noframesLabel = getResource("doclet.No_Frames"); treeLabel = getResource("doclet.Tree"); classLabel = getResource("doclet.Class"); deprecatedLabel = getResource("doclet.navDeprecated"); diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties Sun Apr 10 10:25:12 2011 -0700 @@ -11,54 +11,30 @@ doclet.Interface_Hierarchy=Interface Hierarchy doclet.Enum_Hierarchy=Enum Hierarchy doclet.Annotation_Type_Hierarchy=Annotation Type Hierarchy -# The following ALL CAPS words should be translated. It is used as "Previous" link on javadoc. -doclet.Prev=PREV -# The following ALL CAPS words should be translated. It is used as "Next" link on javadoc. -doclet.Next=NEXT -# The following ALL CAPS words should be translated. It is used as "Previous Class" link on javadoc. -doclet.Prev_Class=PREV CLASS -# The following ALL CAPS words should be translated. It is used as "Next Class" link on javadoc. -doclet.Next_Class=NEXT CLASS -# The following ALL CAPS words should be translated. It is used as "Previous Package" link on javadoc. -doclet.Prev_Package=PREV PACKAGE -# The following ALL CAPS words should be translated. It is used as "Next Package" link on javadoc. -doclet.Next_Package=NEXT PACKAGE -# The following ALL CAPS words should be translated. It is used as "Previous Letter" link on javadoc alphabetical index. -doclet.Prev_Letter=PREV LETTER -# The following ALL CAPS words should be translated. It is used as "Next Letter" link on javadoc alphabetical index. -doclet.Next_Letter=NEXT LETTER -# The following ALL CAPS words should be translated. It is used as "Show List" link on javadoc. -doclet.Show_Lists=SHOW LISTS -# The following ALL CAPS words should be translated. It is used as "Hide List" link on javadoc. -doclet.Hide_Lists=HIDE LISTS +doclet.Prev=Prev +doclet.Next=Next +doclet.Prev_Class=Prev Class +doclet.Next_Class=Next Class +doclet.Prev_Package=Prev Package +doclet.Next_Package=Next Package +doclet.Prev_Letter=Prev Letter +doclet.Next_Letter=Next Letter doclet.Href_Class_Title=class in {0} doclet.Href_Interface_Title=interface in {0} doclet.Href_Annotation_Title=annotation in {0} doclet.Href_Enum_Title=enum in {0} doclet.Href_Type_Param_Title=type parameter in {0} doclet.Href_Class_Or_Interface_Title=class or interface in {0} -# The following ALL CAPS words should be translated. It's used as SUMMARY: NESTED | FIELD | CONSTR | METHOD, meaning Nested Class Summary, Field Summary, Constructor Summary, or Method Summary. -doclet.Summary=SUMMARY: -# The following ALL CAPS words should be translated. It is used as DETAIL: FIELD | CONSTR | METHOD, meaning Field Detail, Constructor Detail, or Method Detail. -doclet.Detail=DETAIL: -# The following ALL CAPS words should be translated. It is used as "Nested" (Nested Class Summary) link on javadoc. -doclet.navNested=NESTED -# The following ALL CAPS words should be translated. It is used as "Optional" (Optional Element Summary) link on javadoc. -doclet.navAnnotationTypeOptionalMember=OPTIONAL -# The following ALL CAPS words should be translated. It is used as "Required" (Required Element Summary) link on javadoc. -doclet.navAnnotationTypeRequiredMember=REQUIRED -# The following ALL CAPS words should be translated. It is used as "Element" (Required Element Summary) link on javadoc. -doclet.navAnnotationTypeMember=ELEMENT -# The following ALL CAPS words should be translated. It is used as "Field" (Field Detail) link on javadoc. -doclet.navField=FIELD -# The following ALL CAPS words should be translated. It is used as "Enum Constants" link on javadoc. -doclet.navEnum=ENUM CONSTANTS -# The following ALL CAPS words should be translated. It is used as "Constructor" (Constructor Detail) link on javadoc. -doclet.navConstructor=CONSTR -# The following ALL CAPS words should be translated. It is used as "Method" (Method Detail) link on javadoc. -doclet.navMethod=METHOD -# The following resource does not seem to be used anymore. -doclet.navFactoryMethod=FACTORY +doclet.Summary=Summary: +doclet.Detail=Detail: +doclet.navNested=Nested +doclet.navAnnotationTypeOptionalMember=Optional +doclet.navAnnotationTypeRequiredMember=Required +doclet.navAnnotationTypeMember=Element +doclet.navField=Field +doclet.navEnum=Enum Constants +doclet.navConstructor=Constr +doclet.navMethod=Method doclet.Index=Index doclet.Window_Single_Index=Index doclet.Window_Split_Index={0}-Index @@ -66,12 +42,6 @@ doclet.Skip_navigation_links=Skip navigation links doclet.New_Page=NewPage doclet.None=None -# The following resource does not seem to be used anymore -doclet.CLASSES=CLASSES -# The following resource does not seem to be used anymore -doclet.MEMBERS=MEMBERS -# The following resource does not seem to be used anymore -doclet.NONE=NONE doclet.Factory_Method_Detail=Static Factory Method Detail doclet.navDeprecated=Deprecated doclet.Deprecated_List=Deprecated List @@ -136,10 +106,7 @@ doclet.Option=Option doclet.Or=Or doclet.Frames=Frames -# The following ALL CAPS words should be translated. It is used as "FRAMES" javadoc navigation link to indicate displaying the page with HTML frames. -doclet.FRAMES=FRAMES -# The following ALL CAPS words should be translated. It is used as "NO FRAMES" javadoc navigation link to indicate displaying the page without HTML frames. -doclet.NO_FRAMES=NO FRAMES +doclet.No_Frames=No Frames doclet.Package_Hierarchies=Package Hierarchies: doclet.Hierarchy_For_Package=Hierarchy For Package {0} doclet.Source_Code=Source Code: @@ -147,11 +114,10 @@ doclet.Cannot_handle_no_packages=Cannot handle no packages. doclet.Frame_Alert=Frame Alert doclet.Overview-Member-Frame=Overview Member Frame -doclet.Frame_Warning_Message=This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. +doclet.Frame_Warning_Message=This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to {0}. doclet.No_Script_Message=JavaScript is disabled on your browser. -doclet.Non_Frame_Version=Non-frame version. +doclet.Non_Frame_Version=Non-frame version doclet.Frame_Version=Frame version -doclet.Link_To=Link to doclet.Following_From_Class=Following copied from class: {0} doclet.Following_From_Interface=Following copied from interface: {0} doclet.Description_From_Interface=Description copied from interface: @@ -200,7 +166,6 @@ doclet.Help_annotation_type_line_1=Each annotation type has its own separate page with the following sections: doclet.Help_annotation_type_line_2=Annotation Type declaration doclet.Help_annotation_type_line_3=Annotation Type description -doclet.The=The doclet.Style_line_1=Javadoc style sheet doclet.Style_line_2=Define colors, fonts and other style attributes here to override the defaults doclet.Style_line_3=Page background color diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css --- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css Sun Apr 10 10:25:12 2011 -0700 @@ -142,19 +142,19 @@ .subNav ul.navList { float:left; margin:0; - font-size:0.7em; + font-size:0.8em; width:350px; } ul.subNavList { float:left; margin:0; - font-size:0.7em; + font-size:0.8em; width:350px; } ul.subNavList li{ list-style:none; float:left; - font-size:90%; + font-size:98%; } /* Page header and footer styles @@ -183,8 +183,6 @@ .subTitle { margin:0; padding-top:10px; - font-size:0.75em; - font-weight:bold; } /* Page layout container styles diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java Sun Apr 10 10:25:12 2011 -0700 @@ -0,0 +1,593 @@ +/* + * Copyright (c) 2011, 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.api; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.lang.model.element.NestingKind; +import javax.tools.Diagnostic; +import javax.tools.FileObject; +import javax.tools.JavaFileManager; +import javax.tools.JavaFileManager.Location; +import javax.tools.JavaFileObject; + +import com.sun.source.util.TaskEvent; +import com.sun.source.util.TaskListener; +import com.sun.tools.javac.util.ClientCodeException; +import com.sun.tools.javac.util.Context; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import javax.lang.model.element.Modifier; +import javax.tools.DiagnosticListener; +import javax.tools.JavaFileObject.Kind; + +/** + * Wrap objects to enable unchecked exceptions to be caught and handled. + * + * For each method, exceptions are handled as follows: + *
    + *
  • Checked exceptions are left alone and propogate upwards in the + * obvious way, since they are an expected aspect of the method's + * specification. + *
  • Unchecked exceptions which have already been caught and wrapped in + * ClientCodeException are left alone to continue propogating upwards. + *
  • All other unchecked exceptions (i.e. subtypes of RuntimeException + * and Error) and caught, and rethrown as a ClientCodeException with + * its cause set to the original exception. + *
+ * + * The intent is that ClientCodeException can be caught at an appropriate point + * in the program and can be distinguished from any unanticipated unchecked + * exceptions arising in the main body of the code (i.e. bugs.) When the + * ClientCodeException has been caught, either a suitable message can be + * generated, or if appropriate, the original cause can be rethrown. + * + *

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. + */ +public class ClientCodeWrapper { + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + public @interface Trusted { } + + public static ClientCodeWrapper instance(Context context) { + ClientCodeWrapper instance = context.get(ClientCodeWrapper.class); + if (instance == null) + instance = new ClientCodeWrapper(context); + return instance; + } + + /** + * A map to cache the results of whether or not a specific classes can + * be "trusted", and thus does not need to be wrapped. + */ + Map, Boolean> trustedClasses; + + protected ClientCodeWrapper(Context context) { + trustedClasses = new HashMap, Boolean>(); + } + + public JavaFileManager wrap(JavaFileManager fm) { + if (isTrusted(fm)) + return fm; + return new WrappedJavaFileManager(fm); + } + + public FileObject wrap(FileObject fo) { + if (isTrusted(fo)) + return fo; + return new WrappedFileObject(fo); + } + + FileObject unwrap(FileObject fo) { + if (fo instanceof WrappedFileObject) + return ((WrappedFileObject) fo).clientFileObject; + else + return fo; + } + + public JavaFileObject wrap(JavaFileObject fo) { + if (isTrusted(fo)) + return fo; + return new WrappedJavaFileObject(fo); + } + + public Iterable wrapJavaFileObjects(Iterable list) { + List wrapped = new ArrayList(); + for (JavaFileObject fo : list) + wrapped.add(wrap(fo)); + return Collections.unmodifiableList(wrapped); + } + + JavaFileObject unwrap(JavaFileObject fo) { + if (fo instanceof WrappedJavaFileObject) + return ((JavaFileObject) ((WrappedJavaFileObject) fo).clientFileObject); + else + return fo; + } + + DiagnosticListener wrap(DiagnosticListener dl) { + if (isTrusted(dl)) + return dl; + return new WrappedDiagnosticListener(dl); + } + + TaskListener wrap(TaskListener tl) { + if (isTrusted(tl)) + return tl; + return new WrappedTaskListener(tl); + } + + protected boolean isTrusted(Object o) { + Class c = o.getClass(); + Boolean trusted = trustedClasses.get(c); + if (trusted == null) { + trusted = c.getName().startsWith("com.sun.tools.javac.") + || c.isAnnotationPresent(Trusted.class); + trustedClasses.put(c, trusted); + } + return trusted; + } + + // + + // FIXME: all these classes should be converted to use multi-catch when + // that is available in the bootstrap compiler. + + protected class WrappedJavaFileManager implements JavaFileManager { + protected JavaFileManager clientJavaFileManager; + WrappedJavaFileManager(JavaFileManager clientJavaFileManager) { + clientJavaFileManager.getClass(); // null check + this.clientJavaFileManager = clientJavaFileManager; + } + + @Override + public ClassLoader getClassLoader(Location location) { + try { + return clientJavaFileManager.getClassLoader(location); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public Iterable list(Location location, String packageName, Set kinds, boolean recurse) throws IOException { + try { + return wrapJavaFileObjects(clientJavaFileManager.list(location, packageName, kinds, recurse)); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public String inferBinaryName(Location location, JavaFileObject file) { + try { + return clientJavaFileManager.inferBinaryName(location, unwrap(file)); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public boolean isSameFile(FileObject a, FileObject b) { + try { + return clientJavaFileManager.isSameFile(unwrap(a), unwrap(b)); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public boolean handleOption(String current, Iterator remaining) { + try { + return clientJavaFileManager.handleOption(current, remaining); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public boolean hasLocation(Location location) { + try { + return clientJavaFileManager.hasLocation(location); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException { + try { + return wrap(clientJavaFileManager.getJavaFileForInput(location, className, kind)); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException { + try { + return wrap(clientJavaFileManager.getJavaFileForOutput(location, className, kind, unwrap(sibling))); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { + try { + return wrap(clientJavaFileManager.getFileForInput(location, packageName, relativeName)); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { + try { + return wrap(clientJavaFileManager.getFileForOutput(location, packageName, relativeName, unwrap(sibling))); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public void flush() throws IOException { + try { + clientJavaFileManager.flush(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public void close() throws IOException { + try { + clientJavaFileManager.close(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public int isSupportedOption(String option) { + try { + return clientJavaFileManager.isSupportedOption(option); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + } + + protected class WrappedFileObject implements FileObject { + protected FileObject clientFileObject; + WrappedFileObject(FileObject clientFileObject) { + clientFileObject.getClass(); // null check + this.clientFileObject = clientFileObject; + } + + @Override + public URI toUri() { + try { + return clientFileObject.toUri(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public String getName() { + try { + return clientFileObject.getName(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public InputStream openInputStream() throws IOException { + try { + return clientFileObject.openInputStream(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public OutputStream openOutputStream() throws IOException { + try { + return clientFileObject.openOutputStream(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public Reader openReader(boolean ignoreEncodingErrors) throws IOException { + try { + return clientFileObject.openReader(ignoreEncodingErrors); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + try { + return clientFileObject.getCharContent(ignoreEncodingErrors); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public Writer openWriter() throws IOException { + try { + return clientFileObject.openWriter(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public long getLastModified() { + try { + return clientFileObject.getLastModified(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public boolean delete() { + try { + return clientFileObject.delete(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + } + + protected class WrappedJavaFileObject extends WrappedFileObject implements JavaFileObject { + WrappedJavaFileObject(JavaFileObject clientJavaFileObject) { + super(clientJavaFileObject); + } + + @Override + public Kind getKind() { + try { + return ((JavaFileObject)clientFileObject).getKind(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public boolean isNameCompatible(String simpleName, Kind kind) { + try { + return ((JavaFileObject)clientFileObject).isNameCompatible(simpleName, kind); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public NestingKind getNestingKind() { + try { + return ((JavaFileObject)clientFileObject).getNestingKind(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public Modifier getAccessLevel() { + try { + return ((JavaFileObject)clientFileObject).getAccessLevel(); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + } + + protected class WrappedDiagnosticListener implements DiagnosticListener { + protected DiagnosticListener clientDiagnosticListener; + WrappedDiagnosticListener(DiagnosticListener clientDiagnosticListener) { + clientDiagnosticListener.getClass(); // null check + this.clientDiagnosticListener = clientDiagnosticListener; + } + + @Override + public void report(Diagnostic diagnostic) { + try { + clientDiagnosticListener.report(diagnostic); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + } + + protected class WrappedTaskListener implements TaskListener { + protected TaskListener clientTaskListener; + WrappedTaskListener(TaskListener clientTaskListener) { + clientTaskListener.getClass(); // null check + this.clientTaskListener = clientTaskListener; + } + + @Override + public void started(TaskEvent ev) { + try { + clientTaskListener.started(ev); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + + @Override + public void finished(TaskEvent ev) { + try { + clientTaskListener.finished(ev); + } catch (ClientCodeException e) { + throw e; + } catch (RuntimeException e) { + throw new ClientCodeException(e); + } catch (Error e) { + throw new ClientCodeException(e); + } + } + } + + // +} diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java --- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Sun Apr 10 10:25:12 2011 -0700 @@ -65,7 +65,7 @@ * @author Jonathan Gibbons */ public class JavacTaskImpl extends JavacTask { - private JavacTool tool; + private ClientCodeWrapper ccw; private Main compilerMain; private JavaCompiler compiler; private Locale locale; @@ -80,12 +80,11 @@ private Integer result = null; - JavacTaskImpl(JavacTool tool, - Main compilerMain, + JavacTaskImpl(Main compilerMain, String[] args, Context context, List fileObjects) { - this.tool = tool; + this.ccw = ClientCodeWrapper.instance(context); this.compilerMain = compilerMain; this.args = args; this.context = context; @@ -94,17 +93,15 @@ // null checks compilerMain.getClass(); args.getClass(); - context.getClass(); fileObjects.getClass(); } - JavacTaskImpl(JavacTool tool, - Main compilerMain, + JavacTaskImpl(Main compilerMain, Iterable flags, Context context, Iterable classes, Iterable fileObjects) { - this(tool, compilerMain, toArray(flags, classes), context, toList(fileObjects)); + this(compilerMain, toArray(flags, classes), context, toList(fileObjects)); } static private String[] toArray(Iterable flags, Iterable classes) { @@ -131,7 +128,7 @@ if (!used.getAndSet(true)) { initContext(); notYetEntered = new HashMap(); - compilerMain.setFatalErrors(true); + compilerMain.setAPIMode(true); result = compilerMain.compile(args, context, fileObjects, processors); cleanup(); return result == 0; @@ -185,31 +182,9 @@ if (context.get(TaskListener.class) != null) context.put(TaskListener.class, (TaskListener)null); if (taskListener != null) - context.put(TaskListener.class, wrap(taskListener)); + context.put(TaskListener.class, ccw.wrap(taskListener)); //initialize compiler's default locale - JavacMessages.instance(context).setCurrentLocale(locale); - } - // where - private TaskListener wrap(final TaskListener tl) { - tl.getClass(); // null check - return new TaskListener() { - public void started(TaskEvent e) { - try { - tl.started(e); - } catch (Throwable t) { - throw new ClientCodeException(t); - } - } - - public void finished(TaskEvent e) { - try { - tl.finished(e); - } catch (Throwable t) { - throw new ClientCodeException(t); - } - } - - }; + context.put(Locale.class, locale); } void cleanup() { diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java --- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java Sun Apr 10 10:25:12 2011 -0700 @@ -28,8 +28,10 @@ import java.io.File; import java.io.InputStream; import java.io.OutputStream; +import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; @@ -47,12 +49,11 @@ import com.sun.tools.javac.main.Main; import com.sun.tools.javac.main.RecognizedOptions.GrumpyHelper; import com.sun.tools.javac.main.RecognizedOptions; +import com.sun.tools.javac.util.ClientCodeException; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Log; -import com.sun.tools.javac.util.JavacMessages; import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Pair; -import java.nio.charset.Charset; /** * TODO: describe com.sun.tools.javac.api.Tool @@ -145,10 +146,13 @@ Locale locale, Charset charset) { Context context = new Context(); - JavacMessages.instance(context).setCurrentLocale(locale); + context.put(Locale.class, locale); if (diagnosticListener != null) context.put(DiagnosticListener.class, diagnosticListener); - context.put(Log.outKey, new PrintWriter(System.err, true)); // FIXME + PrintWriter pw = (charset == null) + ? new PrintWriter(System.err, true) + : new PrintWriter(new OutputStreamWriter(System.err, charset), true); + context.put(Log.outKey, pw); return new JavacFileManager(context, true, charset); } @@ -159,38 +163,45 @@ Iterable classes, Iterable compilationUnits) { - final String kindMsg = "All compilation units must be of SOURCE kind"; - if (options != null) - for (String option : options) - option.getClass(); // null check - if (classes != null) { - for (String cls : classes) - if (!SourceVersion.isName(cls)) // implicit null check - throw new IllegalArgumentException("Not a valid class name: " + cls); - } - if (compilationUnits != null) { - for (JavaFileObject cu : compilationUnits) { - if (cu.getKind() != JavaFileObject.Kind.SOURCE) // implicit null check - throw new IllegalArgumentException(kindMsg); - } - } + try { + Context context = new Context(); + ClientCodeWrapper ccw = ClientCodeWrapper.instance(context); - Context context = new Context(); - - if (diagnosticListener != null) - context.put(DiagnosticListener.class, diagnosticListener); + final String kindMsg = "All compilation units must be of SOURCE kind"; + if (options != null) + for (String option : options) + option.getClass(); // null check + if (classes != null) { + for (String cls : classes) + if (!SourceVersion.isName(cls)) // implicit null check + throw new IllegalArgumentException("Not a valid class name: " + cls); + } + if (compilationUnits != null) { + compilationUnits = ccw.wrapJavaFileObjects(compilationUnits); // implicit null check + for (JavaFileObject cu : compilationUnits) { + if (cu.getKind() != JavaFileObject.Kind.SOURCE) + throw new IllegalArgumentException(kindMsg); + } + } - if (out == null) - context.put(Log.outKey, new PrintWriter(System.err, true)); - else - context.put(Log.outKey, new PrintWriter(out, true)); + if (diagnosticListener != null) + context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener)); + + if (out == null) + context.put(Log.outKey, new PrintWriter(System.err, true)); + else + context.put(Log.outKey, new PrintWriter(out, true)); - if (fileManager == null) - fileManager = getStandardFileManager(diagnosticListener, null, null); - context.put(JavaFileManager.class, fileManager); - processOptions(context, fileManager, options); - Main compiler = new Main("javacTask", context.get(Log.outKey)); - return new JavacTaskImpl(this, compiler, options, context, classes, compilationUnits); + if (fileManager == null) + fileManager = getStandardFileManager(diagnosticListener, null, null); + fileManager = ccw.wrap(fileManager); + context.put(JavaFileManager.class, fileManager); + processOptions(context, fileManager, options); + Main compiler = new Main("javacTask", context.get(Log.outKey)); + return new JavacTaskImpl(compiler, options, context, classes, compilationUnits); + } catch (ClientCodeException ex) { + throw new RuntimeException(ex.getCause()); + } } private static void processOptions(Context context, diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/code/Symtab.java --- a/langtools/src/share/classes/com/sun/tools/javac/code/Symtab.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symtab.java Sun Apr 10 10:25:12 2011 -0700 @@ -125,12 +125,11 @@ public final Type stringBuilderType; public final Type cloneableType; public final Type serializableType; - public final Type transientMethodHandleType; // transient - 292 public final Type methodHandleType; - public final Type transientPolymorphicSignatureType; // transient - 292 public final Type polymorphicSignatureType; public final Type throwableType; public final Type errorType; + public final Type interruptedExceptionType; public final Type illegalArgumentExceptionType; public final Type exceptionType; public final Type runtimeExceptionType; @@ -435,12 +434,11 @@ cloneableType = enterClass("java.lang.Cloneable"); throwableType = enterClass("java.lang.Throwable"); serializableType = enterClass("java.io.Serializable"); - transientMethodHandleType = enterClass("java.dyn.MethodHandle"); // transient - 292 methodHandleType = enterClass("java.lang.invoke.MethodHandle"); - transientPolymorphicSignatureType = enterClass("java.dyn.MethodHandle$PolymorphicSignature"); // transient - 292 polymorphicSignatureType = enterClass("java.lang.invoke.MethodHandle$PolymorphicSignature"); errorType = enterClass("java.lang.Error"); illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException"); + interruptedExceptionType = enterClass("java.lang.InterruptedException"); exceptionType = enterClass("java.lang.Exception"); runtimeExceptionType = enterClass("java.lang.RuntimeException"); classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException"); @@ -480,9 +478,9 @@ autoCloseableType.tsym); trustMeType = enterClass("java.lang.SafeVarargs"); + synthesizeEmptyInterfaceIfMissing(autoCloseableType); synthesizeEmptyInterfaceIfMissing(cloneableType); synthesizeEmptyInterfaceIfMissing(serializableType); - synthesizeEmptyInterfaceIfMissing(transientPolymorphicSignatureType); // transient - 292 synthesizeEmptyInterfaceIfMissing(polymorphicSignatureType); synthesizeBoxTypeIfMissing(doubleType); synthesizeBoxTypeIfMissing(floatType); diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/code/Types.java --- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Sun Apr 10 10:25:12 2011 -0700 @@ -2461,6 +2461,22 @@ } }; + public Type createMethodTypeWithReturn(Type original, Type newReturn) { + return original.accept(methodWithReturn, newReturn); + } + // where + private final MapVisitor methodWithReturn = new MapVisitor() { + public Type visitType(Type t, Type newReturn) { + throw new IllegalArgumentException("Not a method type: " + t); + } + public Type visitMethodType(MethodType t, Type newReturn) { + return new MethodType(t.argtypes, newReturn, t.thrown, t.tsym); + } + public Type visitForAll(ForAll t, Type newReturn) { + return new ForAll(t.tvars, t.qtype.accept(this, newReturn)); + } + }; + // public Type createErrorType(Type originalType) { return new ErrorType(originalType, syms.errSymbol); diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Sun Apr 10 10:25:12 2011 -0700 @@ -1089,6 +1089,10 @@ if (resource.getTag() == JCTree.VARDEF) { attribStat(resource, tryEnv); chk.checkType(resource, resource.type, syms.autoCloseableType, "try.not.applicable.to.type"); + + //check that resource type cannot throw InterruptedException + checkAutoCloseable(resource.pos(), localEnv, resource.type); + VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource); var.setData(ElementKind.RESOURCE_VARIABLE); } else { @@ -1127,6 +1131,35 @@ result = null; } + void checkAutoCloseable(DiagnosticPosition pos, Env env, Type resource) { + if (!resource.isErroneous() && + types.asSuper(resource, syms.autoCloseableType.tsym) != null) { + Symbol close = syms.noSymbol; + boolean prevDeferDiags = log.deferDiagnostics; + Queue prevDeferredDiags = log.deferredDiagnostics; + try { + log.deferDiagnostics = true; + log.deferredDiagnostics = ListBuffer.lb(); + close = rs.resolveQualifiedMethod(pos, + env, + resource, + names.close, + List.nil(), + List.nil()); + } + finally { + log.deferDiagnostics = prevDeferDiags; + log.deferredDiagnostics = prevDeferredDiags; + } + if (close.kind == MTH && + close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && + chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes()) && + env.info.lint.isEnabled(LintCategory.TRY)) { + log.warning(LintCategory.TRY, pos, "try.resource.throws.interrupted.exc", resource); + } + } + } + public void visitConditional(JCConditional tree) { attribExpr(tree.cond, env, syms.booleanType); attribExpr(tree.truepart, env); @@ -1580,7 +1613,7 @@ // Attribute clazz expression and store // symbol + type back into the attributed tree. Type clazztype = attribType(clazz, env); - Pair mapping = getSyntheticScopeMapping(clazztype, cdef != null); + Pair mapping = getSyntheticScopeMapping(clazztype); clazztype = chk.checkDiamond(tree, clazztype); chk.validate(clazz, localEnv); if (tree.encl != null) { @@ -1778,62 +1811,48 @@ Pair mapping, List argtypes, List typeargtypes) { - if (clazztype.isErroneous() || mapping == erroneousMapping) { + if (clazztype.isErroneous() || + clazztype.isInterface() || + mapping == erroneousMapping) { //if the type of the instance creation expression is erroneous, - //or something prevented us to form a valid mapping, return the - //(possibly erroneous) type unchanged + //or if it's an interface, or if something prevented us to form a valid + //mapping, return the (possibly erroneous) type unchanged return clazztype; } - else if (clazztype.isInterface()) { - //if the type of the instance creation expression is an interface - //skip the method resolution step (JLS 15.12.2.7). The type to be - //inferred is of the kind C - clazztype = new ForAll(clazztype.tsym.type.allparams(), clazztype.tsym.type) { - @Override - public List getConstraints(TypeVar tv, ConstraintKind ck) { - switch (ck) { - case EXTENDS: return types.getBounds(tv); - default: return List.nil(); - } - } - @Override - public Type inst(List inferred, Types types) throws Infer.NoInstanceException { - // check that inferred bounds conform to their bounds - infer.checkWithinBounds(tvars, - types.subst(tvars, tvars, inferred), Warner.noWarnings); - return super.inst(inferred, types); - } - }; + + //dup attribution environment and augment the set of inference variables + Env localEnv = env.dup(tree); + localEnv.info.tvars = clazztype.tsym.type.getTypeArguments(); + + //if the type of the instance creation expression is a class type + //apply method resolution inference (JLS 15.12.2.7). The return type + //of the resolved constructor will be a partially instantiated type + ((ClassSymbol) clazztype.tsym).members_field = mapping.snd; + Symbol constructor; + try { + constructor = rs.resolveDiamond(tree.pos(), + localEnv, + clazztype.tsym.type, + argtypes, + typeargtypes); + } finally { + ((ClassSymbol) clazztype.tsym).members_field = mapping.fst; + } + if (constructor.kind == MTH) { + ClassType ct = new ClassType(clazztype.getEnclosingType(), + clazztype.tsym.type.getTypeArguments(), + clazztype.tsym); + clazztype = checkMethod(ct, + constructor, + localEnv, + tree.args, + argtypes, + typeargtypes, + localEnv.info.varArgs).getReturnType(); } else { - //if the type of the instance creation expression is a class type - //apply method resolution inference (JLS 15.12.2.7). The return type - //of the resolved constructor will be a partially instantiated type - ((ClassSymbol) clazztype.tsym).members_field = mapping.snd; - Symbol constructor; - try { - constructor = rs.resolveDiamond(tree.pos(), - env, - clazztype.tsym.type, - argtypes, - typeargtypes); - } finally { - ((ClassSymbol) clazztype.tsym).members_field = mapping.fst; - } - if (constructor.kind == MTH) { - ClassType ct = new ClassType(clazztype.getEnclosingType(), - clazztype.tsym.type.getTypeArguments(), - clazztype.tsym); - clazztype = checkMethod(ct, - constructor, - env, - tree.args, - argtypes, - typeargtypes, - env.info.varArgs).getReturnType(); - } else { - clazztype = syms.errType; - } + clazztype = syms.errType; } + if (clazztype.tag == FORALL && !pt.isErroneous()) { //if the resolved constructor's return type has some uninferred //type-variables, infer them using the expected type and declared @@ -1863,34 +1882,28 @@ * inference. The inferred return type of the synthetic constructor IS * the inferred type for the diamond operator. */ - private Pair getSyntheticScopeMapping(Type ctype, boolean overrideProtectedAccess) { + private Pair getSyntheticScopeMapping(Type ctype) { if (ctype.tag != CLASS) { return erroneousMapping; } + Pair mapping = new Pair(ctype.tsym.members(), new Scope(ctype.tsym)); - List typevars = ctype.tsym.type.getTypeArguments(); + + //for each constructor in the original scope, create a synthetic constructor + //whose return type is the type of the class in which the constructor is + //declared, and insert it into the new scope. for (Scope.Entry e = mapping.fst.lookup(names.init); e.scope != null; e = e.next()) { - MethodSymbol newConstr = (MethodSymbol) e.sym.clone(ctype.tsym); - if (overrideProtectedAccess && (newConstr.flags() & PROTECTED) != 0) { - //make protected constructor public (this is required for - //anonymous inner class creation expressions using diamond) - newConstr.flags_field |= PUBLIC; - newConstr.flags_field &= ~PROTECTED; - } - newConstr.name = names.init; - List oldTypeargs = List.nil(); - if (newConstr.type.tag == FORALL) { - oldTypeargs = ((ForAll) newConstr.type).tvars; - } - newConstr.type = new MethodType(newConstr.type.getParameterTypes(), - new ClassType(ctype.getEnclosingType(), ctype.tsym.type.getTypeArguments(), ctype.tsym), - newConstr.type.getThrownTypes(), - syms.methodClass); - newConstr.type = new ForAll(typevars.prependList(oldTypeargs), newConstr.type); - mapping.snd.enter(newConstr); + Type synthRestype = new ClassType(ctype.getEnclosingType(), + ctype.tsym.type.getTypeArguments(), + ctype.tsym); + MethodSymbol synhConstr = new MethodSymbol(e.sym.flags(), + names.init, + types.createMethodTypeWithReturn(e.sym.type, synthRestype), + e.sym.owner); + mapping.snd.enter(synhConstr); } return mapping; } @@ -2276,6 +2289,7 @@ sitesym.kind == VAR && ((VarSymbol)sitesym).isResourceVariable() && sym.kind == MTH && + sym.name.equals(names.close) && sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) && env.info.lint.isEnabled(LintCategory.TRY)) { log.warning(LintCategory.TRY, tree, "try.explicit.close.call"); @@ -2901,7 +2915,23 @@ ctype = chk.checkType(typeTree.pos(), chk.checkClassType(typeTree.pos(), ctype), syms.throwableType); - multicatchTypes.append(ctype); + if (!ctype.isErroneous()) { + //check that alternatives of a disjunctive type are pairwise + //unrelated w.r.t. subtyping + if (chk.intersects(ctype, multicatchTypes.toList())) { + for (Type t : multicatchTypes) { + boolean sub = types.isSubtype(ctype, t); + boolean sup = types.isSubtype(t, ctype); + if (sub || sup) { + //assume 'a' <: 'b' + Type a = sub ? ctype : t; + Type b = sub ? t : ctype; + log.error(typeTree.pos(), "multicatch.types.must.be.disjoint", a, b); + } + } + } + multicatchTypes.append(ctype); + } } tree.type = result = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt); } @@ -3173,6 +3203,9 @@ // method conform to the method they implement. chk.checkImplementations(tree); + //check that a resource implementing AutoCloseable cannot throw InterruptedException + checkAutoCloseable(tree.pos(), env, c.type); + for (List l = tree.defs; l.nonEmpty(); l = l.tail) { // Attribute declaration attribStat(l.head, env); diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/comp/Check.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Sun Apr 10 10:25:12 2011 -0700 @@ -676,7 +676,7 @@ "cant.apply.diamond.1", t, diags.fragment("diamond.and.anon.class", t)); return types.createErrorType(t); - } else if (!t.tsym.type.isParameterized()) { + } else if (t.tsym.type.getTypeArguments().isEmpty()) { log.error(tree.clazz.pos(), "cant.apply.diamond.1", t, diags.fragment("diamond.non.generic", t)); diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Sun Apr 10 10:25:12 2011 -0700 @@ -788,8 +788,7 @@ // Internally to java.lang.invoke, a @PolymorphicSignature annotation // acts like a classfile attribute. if (!c.type.isErroneous() && - (types.isSameType(c.type, syms.polymorphicSignatureType) || - types.isSameType(c.type, syms.transientPolymorphicSignatureType))) { + types.isSameType(c.type, syms.polymorphicSignatureType)) { if (!target.hasMethodHandles()) { // Somebody is compiling JDK7 source code to a JDK6 target. // Make it an error, since it is unlikely but important. diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Sun Apr 10 10:25:12 2011 -0700 @@ -338,7 +338,11 @@ // tvars is the list of formal type variables for which type arguments // need to inferred. - List tvars = env.info.tvars; + List tvars = null; + if (env.info.tvars != null) { + tvars = types.newInstances(env.info.tvars); + mt = types.subst(mt, env.info.tvars, tvars); + } if (typeargtypes == null) typeargtypes = List.nil(); if (mt.tag != FORALL && typeargtypes.nonEmpty()) { // This is not a polymorphic method, but typeargs are supplied diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Sun Apr 10 10:25:12 2011 -0700 @@ -1162,6 +1162,9 @@ ClassSymbol c = readClassSymbol(nextChar()); NameAndType nt = (NameAndType)readPool(nextChar()); + if (c.members_field == null) + throw badClassFile("bad.enclosing.class", self, c); + MethodSymbol m = findMethod(nt, c.members_field, self.flags()); if (nt != null && m == null) throw badClassFile("bad.enclosing.method", self); @@ -1318,8 +1321,7 @@ else proxies.append(proxy); if (majorVersion >= V51.major && - (proxy.type.tsym == syms.polymorphicSignatureType.tsym || - proxy.type.tsym == syms.transientPolymorphicSignatureType.tsym)) { + proxy.type.tsym == syms.polymorphicSignatureType.tsym) { sym.flags_field |= POLYMORPHIC_SIGNATURE; } } diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/main/Main.java --- a/langtools/src/share/classes/com/sun/tools/javac/main/Main.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/main/Main.java Sun Apr 10 10:25:12 2011 -0700 @@ -65,9 +65,11 @@ PrintWriter out; /** - * If true, any command line arg errors will cause an exception. + * If true, certain errors will cause an exception, such as command line + * arg errors, or exceptions in user provided code. */ - boolean fatalErrors; + boolean apiMode; + /** Result codes. */ @@ -163,7 +165,7 @@ /** Report a usage error. */ void error(String key, Object... args) { - if (fatalErrors) { + if (apiMode) { String msg = getLocalizedString(key, args); throw new PropagatedException(new IllegalStateException(msg)); } @@ -192,8 +194,8 @@ this.options = options; } - public void setFatalErrors(boolean fatalErrors) { - this.fatalErrors = fatalErrors; + public void setAPIMode(boolean apiMode) { + this.apiMode = apiMode; } /** Process command line arguments: store all command line options @@ -440,7 +442,9 @@ } catch (FatalError ex) { feMessage(ex); return EXIT_SYSERR; - } catch(AnnotationProcessingError ex) { + } catch (AnnotationProcessingError ex) { + if (apiMode) + throw new RuntimeException(ex.getCause()); apMessage(ex); return EXIT_SYSERR; } catch (ClientCodeException ex) { @@ -458,7 +462,13 @@ bugMessage(ex); return EXIT_ABNORMAL; } finally { - if (comp != null) comp.close(); + if (comp != null) { + try { + comp.close(); + } catch (ClientCodeException ex) { + throw new RuntimeException(ex.getCause()); + } + } filenames = null; options = null; } diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java --- a/langtools/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java Sun Apr 10 10:25:12 2011 -0700 @@ -37,6 +37,7 @@ import java.nio.CharBuffer; import java.nio.charset.CharsetDecoder; import java.nio.file.Files; +import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import javax.lang.model.element.Modifier; @@ -170,7 +171,7 @@ if (pn.equalsIgnoreCase(sn)) { try { // allow for Windows - return path.toRealPath(false).getFileName().toString().equals(sn); + return path.toRealPath(LinkOption.NOFOLLOW_LINKS).getFileName().toString().equals(sn); } catch (IOException e) { } } diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java --- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Sun Apr 10 10:25:12 2011 -0700 @@ -971,7 +971,7 @@ if ((mode & EXPR) != 0) { mode = EXPR; S.nextToken(); - if (S.token() == LT) typeArgs = typeArguments(); + if (S.token() == LT) typeArgs = typeArguments(false); t = creator(pos, typeArgs); typeArgs = null; } else return illegal(); @@ -1036,7 +1036,7 @@ mode = EXPR; int pos1 = S.pos(); S.nextToken(); - if (S.token() == LT) typeArgs = typeArguments(); + if (S.token() == LT) typeArgs = typeArguments(false); t = innerCreator(pos1, typeArgs, t); typeArgs = null; break loop; @@ -1116,7 +1116,7 @@ mode = EXPR; int pos2 = S.pos(); S.nextToken(); - if (S.token() == LT) typeArgs = typeArguments(); + if (S.token() == LT) typeArgs = typeArguments(false); t = innerCreator(pos2, typeArgs, t); typeArgs = null; } else { @@ -1146,7 +1146,7 @@ } else { int pos = S.pos(); accept(DOT); - typeArgs = (S.token() == LT) ? typeArguments() : null; + typeArgs = (S.token() == LT) ? typeArguments(false) : null; t = toP(F.at(pos).Select(t, ident())); t = argumentsOpt(typeArgs, t); } @@ -1206,7 +1206,7 @@ (mode & NOPARAMS) == 0) { mode = TYPE; checkGenerics(); - return typeArguments(t); + return typeArguments(t, false); } else { return t; } @@ -1223,51 +1223,54 @@ illegal(); } mode = useMode; - return typeArguments(); + return typeArguments(false); } return null; } /** TypeArguments = "<" TypeArgument {"," TypeArgument} ">" */ - List typeArguments() { - ListBuffer args = lb(); + List typeArguments(boolean diamondAllowed) { if (S.token() == LT) { S.nextToken(); - if (S.token() == GT && (mode & DIAMOND) != 0) { + if (S.token() == GT && diamondAllowed) { checkDiamond(); + mode |= DIAMOND; S.nextToken(); return List.nil(); - } - args.append(((mode & EXPR) == 0) ? typeArgument() : parseType()); - while (S.token() == COMMA) { - S.nextToken(); + } else { + ListBuffer args = ListBuffer.lb(); args.append(((mode & EXPR) == 0) ? typeArgument() : parseType()); - } - switch (S.token()) { - case GTGTGTEQ: - S.token(GTGTEQ); - break; - case GTGTEQ: - S.token(GTEQ); - break; - case GTEQ: - S.token(EQ); - break; - case GTGTGT: - S.token(GTGT); - break; - case GTGT: - S.token(GT); - break; - default: - accept(GT); - break; + while (S.token() == COMMA) { + S.nextToken(); + args.append(((mode & EXPR) == 0) ? typeArgument() : parseType()); + } + switch (S.token()) { + case GTGTGTEQ: + S.token(GTGTEQ); + break; + case GTGTEQ: + S.token(GTEQ); + break; + case GTEQ: + S.token(EQ); + break; + case GTGTGT: + S.token(GTGT); + break; + case GTGT: + S.token(GT); + break; + default: + accept(GT); + break; + } + return args.toList(); } } else { syntaxError(S.pos(), "expected", LT); + return List.nil(); } - return args.toList(); } /** TypeArgument = Type @@ -1303,9 +1306,9 @@ } } - JCTypeApply typeArguments(JCExpression t) { + JCTypeApply typeArguments(JCExpression t, boolean diamondAllowed) { int pos = S.pos(); - List args = typeArguments(); + List args = typeArguments(diamondAllowed); return toP(F.at(pos).TypeApply(t, args)); } @@ -1370,18 +1373,25 @@ } JCExpression t = qualident(); int oldmode = mode; - mode = TYPE | DIAMOND; + mode = TYPE; + boolean diamondFound = false; if (S.token() == LT) { checkGenerics(); - t = typeArguments(t); + t = typeArguments(t, true); + diamondFound = (mode & DIAMOND) != 0; } while (S.token() == DOT) { + if (diamondFound) { + //cannot select after a diamond + illegal(S.pos()); + } int pos = S.pos(); S.nextToken(); t = toP(F.at(pos).Select(t, ident())); if (S.token() == LT) { checkGenerics(); - t = typeArguments(t); + t = typeArguments(t, true); + diamondFound = (mode & DIAMOND) != 0; } } mode = oldmode; @@ -1416,9 +1426,8 @@ JCExpression t = toP(F.at(S.pos()).Ident(ident())); if (S.token() == LT) { int oldmode = mode; - mode |= DIAMOND; checkGenerics(); - t = typeArguments(t); + t = typeArguments(t, true); mode = oldmode; } return classCreatorRest(newpos, encl, typeArgs, t); diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java --- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Sun Apr 10 10:25:12 2011 -0700 @@ -34,8 +34,8 @@ import java.io.File; import java.io.PrintWriter; import java.io.IOException; +import java.io.StringWriter; import java.net.MalformedURLException; -import java.io.StringWriter; import javax.annotation.processing.*; import javax.lang.model.SourceVersion; @@ -58,6 +58,7 @@ import com.sun.tools.javac.file.FSInfo; import com.sun.tools.javac.file.JavacFileManager; 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; @@ -67,6 +68,7 @@ import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.util.Abort; import com.sun.tools.javac.util.Assert; +import com.sun.tools.javac.util.ClientCodeException; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Convert; import com.sun.tools.javac.util.FatalError; @@ -432,6 +434,8 @@ log.error("proc.processor.cant.instantiate", processorName); return false; } + } catch(ClientCodeException e) { + throw e; } catch(Throwable t) { throw new AnnotationProcessingError(t); } @@ -527,6 +531,8 @@ supportedOptionNames.add(optionName); } + } catch (ClientCodeException e) { + throw e; } catch (Throwable t) { throw new AnnotationProcessingError(t); } @@ -785,11 +791,16 @@ RoundEnvironment renv) { try { return proc.process(tes, renv); + } catch (BadClassFile ex) { + log.error("proc.cant.access.1", ex.sym, ex.getDetailValue()); + return false; } catch (CompletionFailure ex) { StringWriter out = new StringWriter(); ex.printStackTrace(new PrintWriter(out)); log.error("proc.cant.access", ex.sym, ex.getDetailValue(), out.toString()); return false; + } catch (ClientCodeException e) { + throw e; } catch (Throwable t) { throw new AnnotationProcessingError(t); } @@ -1061,6 +1072,11 @@ PrintWriter out = context.get(Log.outKey); Assert.checkNonNull(out); next.put(Log.outKey, out); + Locale locale = context.get(Locale.class); + if (locale != null) + next.put(Locale.class, locale); + Assert.checkNonNull(messages); + next.put(JavacMessages.messagesKey, messages); final boolean shareNames = true; if (shareNames) { diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Sun Apr 10 10:25:12 2011 -0700 @@ -302,6 +302,11 @@ compiler.err.multicatch.parameter.may.not.be.assigned=\ multi-catch parameter {0} may not be assigned +# 0: type, 1: type +compiler.err.multicatch.types.must.be.disjoint=\ + Alternatives in a multi-catch statement cannot be related by subclassing\n\ + Alternative {0} is a subclass of alternative {1} + compiler.err.finally.without.try=\ ''finally'' without ''try'' @@ -606,12 +611,18 @@ # Errors related to annotation processing +# 0: symbol, 1: string, 2: stack-trace compiler.err.proc.cant.access=\ cannot access {0}\n\ {1}\n\ Consult the following stack trace for details.\n\ {2} +# 0: symbol, 1: string +compiler.err.proc.cant.access.1=\ + cannot access {0}\n\ + {1} + # 0: string compiler.err.proc.cant.find.class=\ Could not find class file for ''{0}''. @@ -1239,6 +1250,10 @@ compiler.warn.try.resource.not.referenced=\ auto-closeable resource {0} is never referenced in body of corresponding try statement +# 0: type +compiler.warn.try.resource.throws.interrupted.exc=\ + auto-closeable resource {0} has a member method close() that could throw InterruptedException + compiler.warn.unchecked.assign=\ unchecked assignment: {0} to {1} @@ -1415,8 +1430,13 @@ compiler.misc.bad.class.signature=\ bad class signature: {0} +#0: symbol, 1: symbol +compiler.misc.bad.enclosing.class=\ + bad enclosing class for {0}: {1} + +# 0: symbol compiler.misc.bad.enclosing.method=\ - bad enclosing method attribute: {0} + bad enclosing method attribute for class {0} compiler.misc.bad.runtime.invisible.param.annotations=\ bad RuntimeInvisibleParameterAnnotations attribute: {0} diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/util/JavacMessages.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/JavacMessages.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/JavacMessages.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -44,7 +44,7 @@ */ public class JavacMessages implements Messages { /** The context key for the JavacMessages object. */ - protected static final Context.Key messagesKey = + public static final Context.Key messagesKey = new Context.Key(); /** Get the JavacMessages instance for this context. */ @@ -77,7 +77,7 @@ /** Creates a JavacMessages object. */ public JavacMessages(Context context) { - this(defaultBundleName); + this(defaultBundleName, context.get(Locale.class)); context.put(messagesKey, this); } @@ -85,10 +85,17 @@ * @param bundleName the name to identify the resource buundle of localized messages. */ public JavacMessages(String bundleName) throws MissingResourceException { + this(bundleName, null); + } + + /** Creates a JavacMessages object. + * @param bundleName the name to identify the resource buundle of localized messages. + */ + public JavacMessages(String bundleName, Locale locale) throws MissingResourceException { bundleNames = List.nil(); bundleCache = new HashMap>>(); add(bundleName); - setCurrentLocale(Locale.getDefault()); + setCurrentLocale(locale); } public JavacMessages() throws MissingResourceException { diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/util/Log.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Sun Apr 10 10:25:12 2011 -0700 @@ -425,13 +425,8 @@ */ protected void writeDiagnostic(JCDiagnostic diag) { if (diagListener != null) { - try { - diagListener.report(diag); - return; - } - catch (Throwable t) { - throw new ClientCodeException(t); - } + diagListener.report(diag); + return; } PrintWriter writer = getWriterForDiagnosticType(diag.getType()); diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javac/util/Names.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/Names.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/Names.java Sun Apr 10 10:25:12 2011 -0700 @@ -73,7 +73,6 @@ public final Name java_io_Serializable; public final Name serialVersionUID; public final Name java_lang_Enum; - public final Name transient_java_dyn_MethodHandle; // transient - 292 public final Name java_lang_invoke_MethodHandle; public final Name package_info; public final Name ConstantValue; @@ -184,7 +183,6 @@ java_lang_Cloneable = fromString("java.lang.Cloneable"); java_io_Serializable = fromString("java.io.Serializable"); java_lang_Enum = fromString("java.lang.Enum"); - transient_java_dyn_MethodHandle = fromString("java.dyn.MethodHandle"); //transient - 292 java_lang_invoke_MethodHandle = fromString("java.lang.invoke.MethodHandle"); package_info = fromString("package-info"); serialVersionUID = fromString("serialVersionUID"); diff -r 5dbb4c781342 -r 06671f24eb6c langtools/src/share/classes/com/sun/tools/javap/ClassWriter.java --- a/langtools/src/share/classes/com/sun/tools/javap/ClassWriter.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javap/ClassWriter.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, 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 @@ -48,6 +48,13 @@ import com.sun.tools.classfile.Signature_attribute; import com.sun.tools.classfile.SourceFile_attribute; import com.sun.tools.classfile.Type; +import com.sun.tools.classfile.Type.ArrayType; +import com.sun.tools.classfile.Type.ClassSigType; +import com.sun.tools.classfile.Type.ClassType; +import com.sun.tools.classfile.Type.MethodType; +import com.sun.tools.classfile.Type.SimpleType; +import com.sun.tools.classfile.Type.TypeParamType; +import com.sun.tools.classfile.Type.WildcardType; import static com.sun.tools.classfile.AccessFlags.*; @@ -166,8 +173,10 @@ // use info from class file header if (classFile.isClass() && classFile.super_class != 0 ) { String sn = getJavaSuperclassName(cf); - print(" extends "); - print(sn); + if (!sn.equals("java.lang.Object")) { + print(" extends "); + print(sn); + } } for (int i = 0; i < classFile.interfaces.length; i++) { print(i == 0 ? (classFile.isClass() ? " implements " : " extends ") : ","); @@ -176,13 +185,14 @@ } else { try { Type t = sigAttr.getParsedSignature().getType(constant_pool); + JavaTypePrinter p = new JavaTypePrinter(classFile.isInterface()); // The signature parser cannot disambiguate between a // FieldType and a ClassSignatureType that only contains a superclass type. - if (t instanceof Type.ClassSigType) - print(getJavaName(t.toString())); - else { + if (t instanceof Type.ClassSigType) { + print(p.print(t)); + } else if (options.verbose || !t.isObject()) { print(" extends "); - print(getJavaName(t.toString())); + print(p.print(t)); } } catch (ConstantPoolException e) { print(report(e)); @@ -210,6 +220,124 @@ indent(-1); println("}"); } + // where + class JavaTypePrinter implements Type.Visitor { + boolean isInterface; + + JavaTypePrinter(boolean isInterface) { + this.isInterface = isInterface; + } + + String print(Type t) { + return t.accept(this, new StringBuilder()).toString(); + } + + public StringBuilder visitSimpleType(SimpleType type, StringBuilder sb) { + sb.append(getJavaName(type.name)); + return sb; + } + + public StringBuilder visitArrayType(ArrayType type, StringBuilder sb) { + append(sb, type.elemType); + sb.append("[]"); + return sb; + } + + public StringBuilder visitMethodType(MethodType type, StringBuilder sb) { + appendIfNotEmpty(sb, "<", type.typeParamTypes, "> "); + append(sb, type.returnType); + append(sb, " (", type.paramTypes, ")"); + appendIfNotEmpty(sb, " throws ", type.throwsTypes, ""); + return sb; + } + + public StringBuilder visitClassSigType(ClassSigType type, StringBuilder sb) { + appendIfNotEmpty(sb, "<", type.typeParamTypes, ">"); + if (isInterface) { + appendIfNotEmpty(sb, " extends ", type.superinterfaceTypes, ""); + } else { + if (type.superclassType != null + && (options.verbose || !type.superclassType.isObject())) { + sb.append(" extends "); + append(sb, type.superclassType); + } + appendIfNotEmpty(sb, " implements ", type.superinterfaceTypes, ""); + } + return sb; + } + + public StringBuilder visitClassType(ClassType type, StringBuilder sb) { + if (type.outerType != null) { + append(sb, type.outerType); + sb.append("."); + } + sb.append(getJavaName(type.name)); + appendIfNotEmpty(sb, "<", type.typeArgs, ">"); + return sb; + } + + public StringBuilder visitTypeParamType(TypeParamType type, StringBuilder sb) { + sb.append(type.name); + String sep = " extends "; + if (type.classBound != null + && (options.verbose || !type.classBound.isObject())) { + sb.append(sep); + append(sb, type.classBound); + sep = " & "; + } + if (type.interfaceBounds != null) { + for (Type bound: type.interfaceBounds) { + sb.append(sep); + append(sb, bound); + sep = " & "; + } + } + return sb; + } + + public StringBuilder visitWildcardType(WildcardType type, StringBuilder sb) { + switch (type.kind) { + case UNBOUNDED: + sb.append("?"); + break; + case EXTENDS: + sb.append("? extends "); + append(sb, type.boundType); + break; + case SUPER: + sb.append("? super "); + append(sb, type.boundType); + break; + default: + throw new AssertionError(); + } + return sb; + } + + private void append(StringBuilder sb, Type t) { + t.accept(this, sb); + } + + private void append(StringBuilder sb, String prefix, List list, String suffix) { + sb.append(prefix); + String sep = ""; + for (Type t: list) { + sb.append(sep); + append(sb, t); + sep = ", "; + } + sb.append(suffix); + } + + private void appendIfNotEmpty(StringBuilder sb, String prefix, List list, String suffix) { + if (!isEmpty(list)) + append(sb, prefix, list, suffix); + } + + private boolean isEmpty(List list) { + return (list == null || list.isEmpty()); + } + } protected void writeFields() { for (Field f: classFile.fields) { @@ -298,7 +426,7 @@ try { methodType = (Type.MethodType) methodSig.getType(constant_pool); methodExceptions = methodType.throwsTypes; - if (methodExceptions != null && methodExceptions.size() == 0) + if (methodExceptions != null && methodExceptions.isEmpty()) methodExceptions = null; } catch (ConstantPoolException e) { // report error? diff -r 5dbb4c781342 -r 06671f24eb6c langtools/test/com/sun/javadoc/testDeprecatedDocs/TestDeprecatedDocs.java --- a/langtools/test/com/sun/javadoc/testDeprecatedDocs/TestDeprecatedDocs.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/test/com/sun/javadoc/testDeprecatedDocs/TestDeprecatedDocs.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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,8 +27,7 @@ * @summary * @author jamieh * @library ../lib/ - * @build JavadocTester - * @build TestDeprecatedDocs + * @build JavadocTester TestDeprecatedDocs * @run main TestDeprecatedDocs */ @@ -77,7 +76,7 @@ {TARGET_FILE, "pkg.DeprecatedClassByAnnotation.field"}, {TARGET_FILE2, "

@Deprecated" + NL +
-                 "public class DeprecatedClassByAnnotation" + NL +
+                 "public class DeprecatedClassByAnnotation" + NL +
                  "extends java.lang.Object
"}, {TARGET_FILE2, "
@Deprecated" + NL +
diff -r 5dbb4c781342 -r 06671f24eb6c langtools/test/com/sun/javadoc/testHref/TestHref.java
--- a/langtools/test/com/sun/javadoc/testHref/TestHref.java	Thu Apr 07 15:21:22 2011 -0700
+++ b/langtools/test/com/sun/javadoc/testHref/TestHref.java	Sun Apr 10 10:25:12 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, 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,8 +27,7 @@
  * @summary  Verify that spaces do not appear in hrefs and anchors.
  * @author   jamieh
  * @library  ../lib/
- * @build    JavadocTester
- * @build    TestHref
+ * @build    JavadocTester TestHref
  * @run main TestHref
  */
 
@@ -81,7 +80,7 @@
 
         //Signature does not link to the page itself.
         {BUG_ID + FS + "pkg" + FS + "C4.html",
-            "public abstract class C4<E extends C4<E>>"
+            "public abstract class C4<E extends C4<E>>"
         },
     };
     private static final String[][] NEGATED_TEST =
diff -r 5dbb4c781342 -r 06671f24eb6c langtools/test/com/sun/javadoc/testHtmlDefinitionListTag/TestHtmlDefinitionListTag.java
--- a/langtools/test/com/sun/javadoc/testHtmlDefinitionListTag/TestHtmlDefinitionListTag.java	Thu Apr 07 15:21:22 2011 -0700
+++ b/langtools/test/com/sun/javadoc/testHtmlDefinitionListTag/TestHtmlDefinitionListTag.java	Sun Apr 10 10:25:12 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,8 +29,7 @@
  * @summary This test verifies the nesting of definition list tags.
  * @author Bhavesh Patel
  * @library ../lib/
- * @build JavadocTester
- * @build TestHtmlDefinitionListTag
+ * @build JavadocTester TestHtmlDefinitionListTag
  * @run main TestHtmlDefinitionListTag
  */
 
@@ -43,7 +42,8 @@
     // Optional Element should print properly nested definition list tags
     // for default value.
     private static final String[][] TEST_ALL = {
-        {BUG_ID + FS + "pkg1" + FS + "C1.html", "
public class C1" + NL +
+        {BUG_ID + FS + "pkg1" + FS + "C1.html", "
public class " +
+                 "C1" + NL +
                  "extends java.lang.Object" + NL + "implements java.io.Serializable
"}, {BUG_ID + FS + "pkg1" + FS + "C4.html", "
" + NL + "
Default:
" + NL + "
true
" + NL + diff -r 5dbb4c781342 -r 06671f24eb6c langtools/test/com/sun/javadoc/testJavascript/TestJavascript.java --- a/langtools/test/com/sun/javadoc/testJavascript/TestJavascript.java Thu Apr 07 15:21:22 2011 -0700 +++ b/langtools/test/com/sun/javadoc/testJavascript/TestJavascript.java Sun Apr 10 10:25:12 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2011, 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 4665566 4855876 + * @bug 4665566 4855876 7025314 * @summary Verify that the output has the right javascript. * @author jamieh * @library ../lib/ @@ -45,9 +45,9 @@ //Input for string search tests. private static final String[][] TEST = { {BUG_ID + FS + "pkg" + FS + "C.html", - "FRAMES"}, + "Frames"}, {BUG_ID + FS + "TestJavascript.html", - "FRAMES"}, + "Frames"}, {BUG_ID + FS + "index.html", "