Merge

Tue, 15 Oct 2013 20:47:55 +0100

author
chegar
date
Tue, 15 Oct 2013 20:47:55 +0100
changeset 2131
90c9ae4bc756
parent 2130
46feacb99698
parent 2117
70a301b35e71
child 2132
dd073728085d

Merge

     1.1 --- a/src/share/classes/com/sun/source/tree/NewArrayTree.java	Tue Oct 15 14:17:11 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/source/tree/NewArrayTree.java	Tue Oct 15 20:47:55 2013 +0100
     1.3 @@ -25,7 +25,7 @@
     1.4  
     1.5  package com.sun.source.tree;
     1.6  
     1.7 -import com.sun.tools.javac.util.List;
     1.8 +import java.util.List;
     1.9  
    1.10  /**
    1.11   * A tree node for an expression to create a new instance of an array.
     2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Tue Oct 15 14:17:11 2013 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java	Tue Oct 15 20:47:55 2013 +0100
     2.3 @@ -118,7 +118,8 @@
     2.4                  if (deprs.length > 0) {
     2.5                      Content body = commentTagsToOutput(null, doc,
     2.6                          deprs[0].inlineTags(), false);
     2.7 -                    result.addContent(HtmlTree.SPAN(HtmlStyle.italic, body));
     2.8 +                    if (!body.isEmpty())
     2.9 +                        result.addContent(HtmlTree.SPAN(HtmlStyle.italic, body));
    2.10                  }
    2.11              } else {
    2.12                  if (Util.isDeprecated(member.containingClass())) {
     3.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/ContentBuilder.java	Tue Oct 15 14:17:11 2013 +0100
     3.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/ContentBuilder.java	Tue Oct 15 20:47:55 2013 +0100
     3.3 @@ -41,8 +41,6 @@
     3.4      @Override
     3.5      public void addContent(Content content) {
     3.6          nullCheck(content);
     3.7 -        if ((content instanceof ContentBuilder) && content.isEmpty())
     3.8 -            return;
     3.9          ensureMutableContents();
    3.10          if (content instanceof ContentBuilder) {
    3.11              contents.addAll(((ContentBuilder) content).contents);
     4.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java	Tue Oct 15 14:17:11 2013 +0100
     4.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java	Tue Oct 15 20:47:55 2013 +0100
     4.3 @@ -102,7 +102,12 @@
     4.4       * @param tagContent tag content to be added
     4.5       */
     4.6      public void addContent(Content tagContent) {
     4.7 -        if (tagContent == HtmlTree.EMPTY || tagContent.isValid()) {
     4.8 +        if (tagContent instanceof ContentBuilder) {
     4.9 +            for (Content content: ((ContentBuilder)tagContent).contents) {
    4.10 +                addContent(content);
    4.11 +            }
    4.12 +        }
    4.13 +        else if (tagContent == HtmlTree.EMPTY || tagContent.isValid()) {
    4.14              if (content.isEmpty())
    4.15                  content = new ArrayList<Content>();
    4.16              content.add(tagContent);
     5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Oct 15 14:17:11 2013 +0100
     5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Oct 15 20:47:55 2013 +0100
     5.3 @@ -424,13 +424,14 @@
     5.4           */
     5.5          private
     5.6          boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) {
     5.7 +            Type newSite = site.hasTag(TYPEVAR) ? site.getUpperBound() : site;
     5.8              while (c != null &&
     5.9                     !(c.isSubClass(sym.owner, types) &&
    5.10                       (c.flags() & INTERFACE) == 0 &&
    5.11                       // In JLS 2e 6.6.2.1, the subclass restriction applies
    5.12                       // only to instance fields and methods -- types are excluded
    5.13                       // regardless of whether they are declared 'static' or not.
    5.14 -                     ((sym.flags() & STATIC) != 0 || sym.kind == TYP || site.tsym.isSubClass(c, types))))
    5.15 +                     ((sym.flags() & STATIC) != 0 || sym.kind == TYP || newSite.tsym.isSubClass(c, types))))
    5.16                  c = c.owner.enclClass();
    5.17              return c != null;
    5.18          }
    5.19 @@ -2710,11 +2711,6 @@
    5.20                                    InferenceContext inferenceContext) {
    5.21          MethodResolutionPhase maxPhase = boxingAllowed ? VARARITY : BASIC;
    5.22  
    5.23 -        if (site.hasTag(TYPEVAR)) {
    5.24 -            return resolveMemberReference(pos, env, referenceTree, site.getUpperBound(),
    5.25 -                    name, argtypes, typeargtypes, boxingAllowed, methodCheck, inferenceContext);
    5.26 -        }
    5.27 -
    5.28          site = types.capture(site);
    5.29  
    5.30          ReferenceLookupHelper boundLookupHelper;
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/com/sun/javadoc/testTagOutput/TestTagOutput.java	Tue Oct 15 20:47:55 2013 +0100
     6.3 @@ -0,0 +1,78 @@
     6.4 +/*
     6.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.  Oracle designates this
    6.11 + * particular file as subject to the "Classpath" exception as provided
    6.12 + * by Oracle in the LICENSE file that accompanied this code.
    6.13 + *
    6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.17 + * version 2 for more details (a copy is included in the LICENSE file that
    6.18 + * accompanied this code).
    6.19 + *
    6.20 + * You should have received a copy of the GNU General Public License version
    6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.23 + *
    6.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.25 + * or visit www.oracle.com if you need additional information or have any
    6.26 + * questions.
    6.27 + */
    6.28 +
    6.29 +/*
    6.30 + * @test
    6.31 + * @bug 8026370
    6.32 + * @summary This test checks the generated tag output.
    6.33 + * @author Bhavesh Patel
    6.34 + * @library ../lib/
    6.35 + * @build JavadocTester TestTagOutput
    6.36 + * @run main TestTagOutput
    6.37 + */
    6.38 +
    6.39 +public class TestTagOutput extends JavadocTester {
    6.40 +
    6.41 +    private static final String BUG_ID = "8026370";
    6.42 +    private static final String[][] TEST = {
    6.43 +        {BUG_ID + FS + "pkg1" + FS + "DeprecatedTag.html",
    6.44 +            "<div class=\"block\"><span class=\"strong\">Deprecated.</span>&nbsp;</div>"},
    6.45 +        {BUG_ID + FS + "pkg1" + FS + "DeprecatedTag.html",
    6.46 +            "<div class=\"block\"><span class=\"strong\">Deprecated.</span>&nbsp;" +
    6.47 +            "<span class=\"italic\">Do not use this.</span></div>"}};
    6.48 +
    6.49 +    private static final String[][] NEGATED_TEST = {
    6.50 +        {BUG_ID + FS + "pkg1" + FS + "DeprecatedTag.html",
    6.51 +            "<div class=\"block\"><span class=\"strong\">Deprecated." +
    6.52 +            "</span>&nbsp;<span class=\"italic\"></span></div>"}};
    6.53 +
    6.54 +    private static final String[] ARGS =
    6.55 +        new String[] {
    6.56 +            "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1"};
    6.57 +
    6.58 +    /**
    6.59 +     * The entry point of the test.
    6.60 +     * @param args the array of command line arguments.
    6.61 +     */
    6.62 +    public static void main(String[] args) {
    6.63 +        TestTagOutput tester = new TestTagOutput();
    6.64 +        run(tester, ARGS, TEST, NEGATED_TEST);
    6.65 +        tester.printSummary();
    6.66 +    }
    6.67 +
    6.68 +    /**
    6.69 +     * {@inheritDoc}
    6.70 +     */
    6.71 +    public String getBugId() {
    6.72 +        return BUG_ID;
    6.73 +    }
    6.74 +
    6.75 +    /**
    6.76 +     * {@inheritDoc}
    6.77 +     */
    6.78 +    public String getBugName() {
    6.79 +        return getClass().getName();
    6.80 +    }
    6.81 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/com/sun/javadoc/testTagOutput/pkg1/DeprecatedTag.java	Tue Oct 15 20:47:55 2013 +0100
     7.3 @@ -0,0 +1,44 @@
     7.4 +/*
     7.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.
    7.11 + *
    7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.15 + * version 2 for more details (a copy is included in the LICENSE file that
    7.16 + * accompanied this code).
    7.17 + *
    7.18 + * You should have received a copy of the GNU General Public License version
    7.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.21 + *
    7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    7.23 + * or visit www.oracle.com if you need additional information or have any
    7.24 + * questions.
    7.25 + */
    7.26 +
    7.27 +package pkg1;
    7.28 +
    7.29 +public class DeprecatedTag {
    7.30 +
    7.31 +    /**
    7.32 +     * This method is deprecated.
    7.33 +     *
    7.34 +     * @deprecated
    7.35 +     */
    7.36 +    public void deprecatedMethod() {
    7.37 +    }
    7.38 +
    7.39 +    /**
    7.40 +     * This method is also deprecated.
    7.41 +     *
    7.42 +     * @deprecated Do not use this.
    7.43 +     */
    7.44 +    public void deprecatedMethodWithDesc() {
    7.45 +    }
    7.46 +}
    7.47 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/tools/javac/lambda/T8025816/CrashMethodReferenceWithSiteTypeVarTest.java	Tue Oct 15 20:47:55 2013 +0100
     8.3 @@ -0,0 +1,40 @@
     8.4 +/*
     8.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + *
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.
    8.11 + *
    8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.15 + * version 2 for more details (a copy is included in the LICENSE file that
    8.16 + * accompanied this code).
    8.17 + *
    8.18 + * You should have received a copy of the GNU General Public License version
    8.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.21 + *
    8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.23 + * or visit www.oracle.com if you need additional information or have any
    8.24 + * questions.
    8.25 + */
    8.26 +
    8.27 +/*
    8.28 + * @test
    8.29 + * @bug 8025816
    8.30 + * @summary Compiler crash when default method call with method reference
    8.31 + * @compile CrashMethodReferenceWithSiteTypeVarTest.java
    8.32 + */
    8.33 +
    8.34 +import java.util.Collection;
    8.35 +import java.util.Comparator;
    8.36 +
    8.37 +public class CrashMethodReferenceWithSiteTypeVarTest {
    8.38 +    public <T> void m1(Collection<T> c, Comparator<T> comp) {}
    8.39 +
    8.40 +    public <T extends Comparable> void m2(Collection<T> c) {
    8.41 +        m1(c, T::compareTo);
    8.42 +    }
    8.43 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/tools/javac/tree/NoPrivateTypesExported.java	Tue Oct 15 20:47:55 2013 +0100
     9.3 @@ -0,0 +1,291 @@
     9.4 +/*
     9.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.
    9.11 + *
    9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.15 + * version 2 for more details (a copy is included in the LICENSE file that
    9.16 + * accompanied this code).
    9.17 + *
    9.18 + * You should have received a copy of the GNU General Public License version
    9.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.21 + *
    9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.23 + * or visit www.oracle.com if you need additional information or have any
    9.24 + * questions.
    9.25 + */
    9.26 +
    9.27 +/*
    9.28 + * @test
    9.29 + * @bug 8026180
    9.30 + * @summary Ensuring javax.lang.model.**, javax.tools.**, javax.annotation.processing.**
    9.31 + *          and com.sun.source.** don't export inappropriate types.
    9.32 + * @library /tools/javac/lib
    9.33 + * @build JavacTestingAbstractProcessor NoPrivateTypesExported
    9.34 + * @compile -processor NoPrivateTypesExported NoPrivateTypesExported.java
    9.35 + */
    9.36 +import java.lang.annotation.Documented;
    9.37 +import java.util.Arrays;
    9.38 +import java.util.HashSet;
    9.39 +import java.util.List;
    9.40 +import java.util.Set;
    9.41 +import javax.annotation.processing.RoundEnvironment;
    9.42 +import javax.lang.model.element.AnnotationMirror;
    9.43 +import javax.lang.model.element.AnnotationValue;
    9.44 +import javax.lang.model.element.Element;
    9.45 +import javax.lang.model.element.ElementKind;
    9.46 +import javax.lang.model.element.ExecutableElement;
    9.47 +import javax.lang.model.element.PackageElement;
    9.48 +import javax.lang.model.element.TypeElement;
    9.49 +import javax.lang.model.element.TypeParameterElement;
    9.50 +import javax.lang.model.element.VariableElement;
    9.51 +import javax.lang.model.type.ArrayType;
    9.52 +import javax.lang.model.type.DeclaredType;
    9.53 +import javax.lang.model.type.IntersectionType;
    9.54 +import javax.lang.model.type.TypeMirror;
    9.55 +import javax.lang.model.type.TypeVariable;
    9.56 +import javax.lang.model.type.WildcardType;
    9.57 +import javax.lang.model.util.ElementScanner8;
    9.58 +import javax.lang.model.util.SimpleAnnotationValueVisitor8;
    9.59 +import javax.tools.Diagnostic.Kind;
    9.60 +
    9.61 +public class NoPrivateTypesExported extends JavacTestingAbstractProcessor {
    9.62 +
    9.63 +    private static final String[] javaxLangModelPackages = new String[] {
    9.64 +        "javax.lang.model",
    9.65 +        "javax.lang.model.element",
    9.66 +        "javax.lang.model.type",
    9.67 +        "javax.lang.model.util",
    9.68 +    };
    9.69 +
    9.70 +    private static final Set<String> javaxLangModelAcceptable;
    9.71 +
    9.72 +    private static final String[] javaxToolsProcessingPackages = new String[] {
    9.73 +        "javax.annotation.processing",
    9.74 +        "javax.tools",
    9.75 +    };
    9.76 +
    9.77 +    private static final Set<String> javaxToolsProcessingAcceptable;
    9.78 +
    9.79 +    private static final String[] comSunSourcePackages = new String[] {
    9.80 +        "com.sun.source.doctree",
    9.81 +        "com.sun.source.tree",
    9.82 +        "com.sun.source.util"
    9.83 +    };
    9.84 +
    9.85 +    private static final Set<String> comSunSourceAcceptable;
    9.86 +
    9.87 +    static {
    9.88 +        javaxLangModelAcceptable = new HashSet<>(Arrays.asList(
    9.89 +            "java.io.",
    9.90 +            "java.lang.",
    9.91 +            "java.net.",
    9.92 +            "java.nio.",
    9.93 +            "java.util.",
    9.94 +            "javax.lang.model.",
    9.95 +            "javax.annotation.processing.SupportedSourceVersion",
    9.96 +            "jdk.Exported"
    9.97 +        ));
    9.98 +        Set<String> javaxToolsProcessingAcceptableTemp = new HashSet<>();
    9.99 +        javaxToolsProcessingAcceptableTemp.addAll(javaxLangModelAcceptable);
   9.100 +        javaxToolsProcessingAcceptableTemp.addAll(Arrays.asList(
   9.101 +                "javax.annotation.processing.",
   9.102 +                "javax.tools."
   9.103 +        ));
   9.104 +        javaxToolsProcessingAcceptable = javaxToolsProcessingAcceptableTemp;
   9.105 +        Set<String> comSunSourceAcceptableTemp = new HashSet<>();
   9.106 +        comSunSourceAcceptableTemp.addAll(javaxToolsProcessingAcceptable);
   9.107 +        comSunSourceAcceptableTemp.addAll(Arrays.asList(
   9.108 +                "com.sun.source.doctree.",
   9.109 +                "com.sun.source.tree.",
   9.110 +                "com.sun.source.util."
   9.111 +        ));
   9.112 +        comSunSourceAcceptable = comSunSourceAcceptableTemp;
   9.113 +    }
   9.114 +
   9.115 +    @Override
   9.116 +    public boolean process(Set<? extends TypeElement> annotations,
   9.117 +                           RoundEnvironment roundEnv) {
   9.118 +        if (roundEnv.processingOver()) {
   9.119 +            verifyPackage(javaxLangModelPackages, javaxLangModelAcceptable);
   9.120 +            verifyPackage(javaxToolsProcessingPackages, javaxToolsProcessingAcceptable);
   9.121 +            verifyPackage(comSunSourcePackages, comSunSourceAcceptable);
   9.122 +        }
   9.123 +        return true;
   9.124 +    }
   9.125 +
   9.126 +    private void verifyPackage(String[] packagesToTest, Set<String> acceptable) {
   9.127 +        for (String packageToTest : packagesToTest) {
   9.128 +            PackageElement packageElement = processingEnv.getElementUtils()
   9.129 +                    .getPackageElement(packageToTest);
   9.130 +
   9.131 +            verifyReferredTypesAcceptable(packageElement, acceptable);
   9.132 +        }
   9.133 +    }
   9.134 +
   9.135 +    private void verifyReferredTypesAcceptable(Element rootElement,
   9.136 +                                               final Set<String> acceptable) {
   9.137 +        new ElementScanner8<Void, Void>() {
   9.138 +            @Override public Void visitType(TypeElement e, Void p) {
   9.139 +                verifyTypeAcceptable(e.getSuperclass(), acceptable);
   9.140 +                verifyTypesAcceptable(e.getInterfaces(), acceptable);
   9.141 +                scan(e.getTypeParameters(), p);
   9.142 +                scan(e.getEnclosedElements(), p);
   9.143 +                verifyAnnotations(e.getAnnotationMirrors(), acceptable);
   9.144 +                return null;
   9.145 +            }
   9.146 +            @Override public Void visitTypeParameter(TypeParameterElement e, Void p) {
   9.147 +                verifyTypesAcceptable(e.getBounds(), acceptable);
   9.148 +                scan(e.getEnclosedElements(), p);
   9.149 +                verifyAnnotations(e.getAnnotationMirrors(), acceptable);
   9.150 +                return null;
   9.151 +            }
   9.152 +            @Override public Void visitPackage(PackageElement e, Void p) {
   9.153 +                scan(e.getEnclosedElements(), p);
   9.154 +                verifyAnnotations(e.getAnnotationMirrors(), acceptable);
   9.155 +                return null;
   9.156 +            }
   9.157 +            @Override public Void visitVariable(VariableElement e, Void p) {
   9.158 +                verifyTypeAcceptable(e.asType(), acceptable);
   9.159 +                scan(e.getEnclosedElements(), p);
   9.160 +                verifyAnnotations(e.getAnnotationMirrors(), acceptable);
   9.161 +                return null;
   9.162 +            }
   9.163 +            @Override
   9.164 +            public Void visitExecutable(ExecutableElement e, Void p) {
   9.165 +                scan(e.getTypeParameters(), p);
   9.166 +                verifyTypeAcceptable(e.getReturnType(), acceptable);
   9.167 +                scan(e.getParameters(), p);
   9.168 +                verifyTypesAcceptable(e.getThrownTypes(), acceptable);
   9.169 +                scan(e.getEnclosedElements(), p);
   9.170 +                verifyAnnotations(e.getAnnotationMirrors(), acceptable);
   9.171 +                return null;
   9.172 +            }
   9.173 +        }.scan(rootElement, null);
   9.174 +    }
   9.175 +
   9.176 +    private void verifyAnnotations(Iterable<? extends AnnotationMirror> annotations,
   9.177 +                                   Set<String> acceptable) {
   9.178 +        for (AnnotationMirror mirror : annotations) {
   9.179 +            Element annotationElement = mirror.getAnnotationType().asElement();
   9.180 +
   9.181 +            if (annotationElement.getAnnotation(Documented.class) == null) {
   9.182 +                note("Ignoring undocumented annotation: " + mirror.getAnnotationType());
   9.183 +            }
   9.184 +
   9.185 +            verifyTypeAcceptable(mirror.getAnnotationType(), acceptable);
   9.186 +
   9.187 +            for (AnnotationValue value : mirror.getElementValues().values()) {
   9.188 +                verifyAnnotationValue(value, acceptable);
   9.189 +            }
   9.190 +        }
   9.191 +    }
   9.192 +
   9.193 +    private void verifyAnnotationValue(AnnotationValue value,
   9.194 +                                       final Set<String> acceptable) {
   9.195 +        value.accept(new SimpleAnnotationValueVisitor8<Void, Void>() {
   9.196 +            @Override public Void visitType(TypeMirror t, Void p) {
   9.197 +                verifyTypeAcceptable(t, acceptable);
   9.198 +                return null;
   9.199 +            }
   9.200 +            @Override
   9.201 +            public Void visitEnumConstant(VariableElement c, Void p) {
   9.202 +                verifyReferredTypesAcceptable(c, acceptable);
   9.203 +                return null;
   9.204 +            }
   9.205 +            @Override public Void visitArray(List<? extends AnnotationValue> vals,
   9.206 +                                             Void p) {
   9.207 +                for (AnnotationValue val : vals) {
   9.208 +                    val.accept(this, p);
   9.209 +                }
   9.210 +                return null;
   9.211 +            }
   9.212 +            @Override protected Void defaultAction(Object o, Void p) {
   9.213 +                error("Unexpected AnnotationValue: " + o.toString());
   9.214 +                return super.defaultAction(o, p);
   9.215 +            }
   9.216 +        }, null);
   9.217 +    }
   9.218 +
   9.219 +    private void verifyTypesAcceptable(Iterable<? extends TypeMirror> types,
   9.220 +                                       Set<String> acceptable) {
   9.221 +        if (types == null) return ;
   9.222 +
   9.223 +        for (TypeMirror type : types) {
   9.224 +            verifyTypeAcceptable(type, acceptable);
   9.225 +        }
   9.226 +    }
   9.227 +
   9.228 +    private void verifyTypeAcceptable(TypeMirror type, Set<String> acceptable) {
   9.229 +        if (type == null) return ;
   9.230 +
   9.231 +        verifyAnnotations(type.getAnnotationMirrors(), acceptable);
   9.232 +
   9.233 +        switch (type.getKind()) {
   9.234 +            case BOOLEAN: case BYTE: case CHAR: case DOUBLE: case FLOAT:
   9.235 +            case INT: case LONG: case SHORT: case VOID: case NONE: case NULL:
   9.236 +                return ;
   9.237 +            case DECLARED:
   9.238 +                DeclaredType dt = (DeclaredType) type;
   9.239 +                TypeElement outermostTypeElement = outermostTypeElement(dt.asElement());
   9.240 +                String outermostType = outermostTypeElement.getQualifiedName().toString();
   9.241 +                boolean isAcceptable = false;
   9.242 +                for (String acceptablePackage : acceptable) {
   9.243 +                    if (outermostType.startsWith(acceptablePackage)) {
   9.244 +                        isAcceptable = true;
   9.245 +                        break;
   9.246 +                    }
   9.247 +                }
   9.248 +                if (!isAcceptable) {
   9.249 +                    error("Type not acceptable for this API: " + dt.toString());
   9.250 +                }
   9.251 +
   9.252 +                for (TypeMirror bound : dt.getTypeArguments()) {
   9.253 +                    verifyTypeAcceptable(bound, acceptable);
   9.254 +                }
   9.255 +                break;
   9.256 +            case ARRAY:
   9.257 +                verifyTypeAcceptable(((ArrayType) type).getComponentType(), acceptable);
   9.258 +                break;
   9.259 +            case INTERSECTION:
   9.260 +                for (TypeMirror element : ((IntersectionType) type).getBounds()) {
   9.261 +                    verifyTypeAcceptable(element, acceptable);
   9.262 +                }
   9.263 +                break;
   9.264 +            case TYPEVAR:
   9.265 +                verifyTypeAcceptable(((TypeVariable) type).getLowerBound(), acceptable);
   9.266 +                verifyTypeAcceptable(((TypeVariable) type).getUpperBound(), acceptable);
   9.267 +                break;
   9.268 +            case WILDCARD:
   9.269 +                verifyTypeAcceptable(((WildcardType) type).getExtendsBound(), acceptable);
   9.270 +                verifyTypeAcceptable(((WildcardType) type).getSuperBound(), acceptable);
   9.271 +                break;
   9.272 +            default:
   9.273 +                error("Type not acceptable for this API: " + type.toString());
   9.274 +                break;
   9.275 +
   9.276 +        }
   9.277 +    }
   9.278 +
   9.279 +    private TypeElement outermostTypeElement(Element el) {
   9.280 +        while (el.getEnclosingElement().getKind() != ElementKind.PACKAGE) {
   9.281 +            el = el.getEnclosingElement();
   9.282 +        }
   9.283 +
   9.284 +        return (TypeElement) el;
   9.285 +    }
   9.286 +
   9.287 +    private void error(String text) {
   9.288 +        processingEnv.getMessager().printMessage(Kind.ERROR, text);
   9.289 +    }
   9.290 +
   9.291 +    private void note(String text) {
   9.292 +        processingEnv.getMessager().printMessage(Kind.NOTE, text);
   9.293 +    }
   9.294 +}

mercurial