Merge
This commit is contained in:
commit
0fd34f307d
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
package com.sun.source.tree;
|
package com.sun.source.tree;
|
||||||
|
|
||||||
import com.sun.tools.javac.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A tree node for an expression to create a new instance of an array.
|
* A tree node for an expression to create a new instance of an array.
|
||||||
|
@ -118,6 +118,7 @@ public class TagletWriterImpl extends TagletWriter {
|
|||||||
if (deprs.length > 0) {
|
if (deprs.length > 0) {
|
||||||
Content body = commentTagsToOutput(null, doc,
|
Content body = commentTagsToOutput(null, doc,
|
||||||
deprs[0].inlineTags(), false);
|
deprs[0].inlineTags(), false);
|
||||||
|
if (!body.isEmpty())
|
||||||
result.addContent(HtmlTree.SPAN(HtmlStyle.italic, body));
|
result.addContent(HtmlTree.SPAN(HtmlStyle.italic, body));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -41,8 +41,6 @@ public class ContentBuilder extends Content {
|
|||||||
@Override
|
@Override
|
||||||
public void addContent(Content content) {
|
public void addContent(Content content) {
|
||||||
nullCheck(content);
|
nullCheck(content);
|
||||||
if ((content instanceof ContentBuilder) && content.isEmpty())
|
|
||||||
return;
|
|
||||||
ensureMutableContents();
|
ensureMutableContents();
|
||||||
if (content instanceof ContentBuilder) {
|
if (content instanceof ContentBuilder) {
|
||||||
contents.addAll(((ContentBuilder) content).contents);
|
contents.addAll(((ContentBuilder) content).contents);
|
||||||
|
@ -102,7 +102,12 @@ public class HtmlTree extends Content {
|
|||||||
* @param tagContent tag content to be added
|
* @param tagContent tag content to be added
|
||||||
*/
|
*/
|
||||||
public void addContent(Content tagContent) {
|
public void addContent(Content tagContent) {
|
||||||
if (tagContent == HtmlTree.EMPTY || tagContent.isValid()) {
|
if (tagContent instanceof ContentBuilder) {
|
||||||
|
for (Content content: ((ContentBuilder)tagContent).contents) {
|
||||||
|
addContent(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tagContent == HtmlTree.EMPTY || tagContent.isValid()) {
|
||||||
if (content.isEmpty())
|
if (content.isEmpty())
|
||||||
content = new ArrayList<Content>();
|
content = new ArrayList<Content>();
|
||||||
content.add(tagContent);
|
content.add(tagContent);
|
||||||
|
@ -424,13 +424,14 @@ public class Resolve {
|
|||||||
*/
|
*/
|
||||||
private
|
private
|
||||||
boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) {
|
boolean isProtectedAccessible(Symbol sym, ClassSymbol c, Type site) {
|
||||||
|
Type newSite = site.hasTag(TYPEVAR) ? site.getUpperBound() : site;
|
||||||
while (c != null &&
|
while (c != null &&
|
||||||
!(c.isSubClass(sym.owner, types) &&
|
!(c.isSubClass(sym.owner, types) &&
|
||||||
(c.flags() & INTERFACE) == 0 &&
|
(c.flags() & INTERFACE) == 0 &&
|
||||||
// In JLS 2e 6.6.2.1, the subclass restriction applies
|
// In JLS 2e 6.6.2.1, the subclass restriction applies
|
||||||
// only to instance fields and methods -- types are excluded
|
// only to instance fields and methods -- types are excluded
|
||||||
// regardless of whether they are declared 'static' or not.
|
// regardless of whether they are declared 'static' or not.
|
||||||
((sym.flags() & STATIC) != 0 || sym.kind == TYP || site.tsym.isSubClass(c, types))))
|
((sym.flags() & STATIC) != 0 || sym.kind == TYP || newSite.tsym.isSubClass(c, types))))
|
||||||
c = c.owner.enclClass();
|
c = c.owner.enclClass();
|
||||||
return c != null;
|
return c != null;
|
||||||
}
|
}
|
||||||
@ -2710,11 +2711,6 @@ public class Resolve {
|
|||||||
InferenceContext inferenceContext) {
|
InferenceContext inferenceContext) {
|
||||||
MethodResolutionPhase maxPhase = boxingAllowed ? VARARITY : BASIC;
|
MethodResolutionPhase maxPhase = boxingAllowed ? VARARITY : BASIC;
|
||||||
|
|
||||||
if (site.hasTag(TYPEVAR)) {
|
|
||||||
return resolveMemberReference(pos, env, referenceTree, site.getUpperBound(),
|
|
||||||
name, argtypes, typeargtypes, boxingAllowed, methodCheck, inferenceContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
site = types.capture(site);
|
site = types.capture(site);
|
||||||
|
|
||||||
ReferenceLookupHelper boundLookupHelper;
|
ReferenceLookupHelper boundLookupHelper;
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8026370
|
||||||
|
* @summary This test checks the generated tag output.
|
||||||
|
* @author Bhavesh Patel
|
||||||
|
* @library ../lib/
|
||||||
|
* @build JavadocTester TestTagOutput
|
||||||
|
* @run main TestTagOutput
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class TestTagOutput extends JavadocTester {
|
||||||
|
|
||||||
|
private static final String BUG_ID = "8026370";
|
||||||
|
private static final String[][] TEST = {
|
||||||
|
{BUG_ID + FS + "pkg1" + FS + "DeprecatedTag.html",
|
||||||
|
"<div class=\"block\"><span class=\"strong\">Deprecated.</span> </div>"},
|
||||||
|
{BUG_ID + FS + "pkg1" + FS + "DeprecatedTag.html",
|
||||||
|
"<div class=\"block\"><span class=\"strong\">Deprecated.</span> " +
|
||||||
|
"<span class=\"italic\">Do not use this.</span></div>"}};
|
||||||
|
|
||||||
|
private static final String[][] NEGATED_TEST = {
|
||||||
|
{BUG_ID + FS + "pkg1" + FS + "DeprecatedTag.html",
|
||||||
|
"<div class=\"block\"><span class=\"strong\">Deprecated." +
|
||||||
|
"</span> <span class=\"italic\"></span></div>"}};
|
||||||
|
|
||||||
|
private static final String[] ARGS =
|
||||||
|
new String[] {
|
||||||
|
"-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entry point of the test.
|
||||||
|
* @param args the array of command line arguments.
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
TestTagOutput tester = new TestTagOutput();
|
||||||
|
run(tester, ARGS, TEST, NEGATED_TEST);
|
||||||
|
tester.printSummary();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public String getBugId() {
|
||||||
|
return BUG_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public String getBugName() {
|
||||||
|
return getClass().getName();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pkg1;
|
||||||
|
|
||||||
|
public class DeprecatedTag {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is deprecated.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public void deprecatedMethod() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is also deprecated.
|
||||||
|
*
|
||||||
|
* @deprecated Do not use this.
|
||||||
|
*/
|
||||||
|
public void deprecatedMethodWithDesc() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8025816
|
||||||
|
* @summary Compiler crash when default method call with method reference
|
||||||
|
* @compile CrashMethodReferenceWithSiteTypeVarTest.java
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public class CrashMethodReferenceWithSiteTypeVarTest {
|
||||||
|
public <T> void m1(Collection<T> c, Comparator<T> comp) {}
|
||||||
|
|
||||||
|
public <T extends Comparable> void m2(Collection<T> c) {
|
||||||
|
m1(c, T::compareTo);
|
||||||
|
}
|
||||||
|
}
|
291
langtools/test/tools/javac/tree/NoPrivateTypesExported.java
Normal file
291
langtools/test/tools/javac/tree/NoPrivateTypesExported.java
Normal file
@ -0,0 +1,291 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8026180
|
||||||
|
* @summary Ensuring javax.lang.model.**, javax.tools.**, javax.annotation.processing.**
|
||||||
|
* and com.sun.source.** don't export inappropriate types.
|
||||||
|
* @library /tools/javac/lib
|
||||||
|
* @build JavacTestingAbstractProcessor NoPrivateTypesExported
|
||||||
|
* @compile -processor NoPrivateTypesExported NoPrivateTypesExported.java
|
||||||
|
*/
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.annotation.processing.RoundEnvironment;
|
||||||
|
import javax.lang.model.element.AnnotationMirror;
|
||||||
|
import javax.lang.model.element.AnnotationValue;
|
||||||
|
import javax.lang.model.element.Element;
|
||||||
|
import javax.lang.model.element.ElementKind;
|
||||||
|
import javax.lang.model.element.ExecutableElement;
|
||||||
|
import javax.lang.model.element.PackageElement;
|
||||||
|
import javax.lang.model.element.TypeElement;
|
||||||
|
import javax.lang.model.element.TypeParameterElement;
|
||||||
|
import javax.lang.model.element.VariableElement;
|
||||||
|
import javax.lang.model.type.ArrayType;
|
||||||
|
import javax.lang.model.type.DeclaredType;
|
||||||
|
import javax.lang.model.type.IntersectionType;
|
||||||
|
import javax.lang.model.type.TypeMirror;
|
||||||
|
import javax.lang.model.type.TypeVariable;
|
||||||
|
import javax.lang.model.type.WildcardType;
|
||||||
|
import javax.lang.model.util.ElementScanner8;
|
||||||
|
import javax.lang.model.util.SimpleAnnotationValueVisitor8;
|
||||||
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
|
||||||
|
public class NoPrivateTypesExported extends JavacTestingAbstractProcessor {
|
||||||
|
|
||||||
|
private static final String[] javaxLangModelPackages = new String[] {
|
||||||
|
"javax.lang.model",
|
||||||
|
"javax.lang.model.element",
|
||||||
|
"javax.lang.model.type",
|
||||||
|
"javax.lang.model.util",
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final Set<String> javaxLangModelAcceptable;
|
||||||
|
|
||||||
|
private static final String[] javaxToolsProcessingPackages = new String[] {
|
||||||
|
"javax.annotation.processing",
|
||||||
|
"javax.tools",
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final Set<String> javaxToolsProcessingAcceptable;
|
||||||
|
|
||||||
|
private static final String[] comSunSourcePackages = new String[] {
|
||||||
|
"com.sun.source.doctree",
|
||||||
|
"com.sun.source.tree",
|
||||||
|
"com.sun.source.util"
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final Set<String> comSunSourceAcceptable;
|
||||||
|
|
||||||
|
static {
|
||||||
|
javaxLangModelAcceptable = new HashSet<>(Arrays.asList(
|
||||||
|
"java.io.",
|
||||||
|
"java.lang.",
|
||||||
|
"java.net.",
|
||||||
|
"java.nio.",
|
||||||
|
"java.util.",
|
||||||
|
"javax.lang.model.",
|
||||||
|
"javax.annotation.processing.SupportedSourceVersion",
|
||||||
|
"jdk.Exported"
|
||||||
|
));
|
||||||
|
Set<String> javaxToolsProcessingAcceptableTemp = new HashSet<>();
|
||||||
|
javaxToolsProcessingAcceptableTemp.addAll(javaxLangModelAcceptable);
|
||||||
|
javaxToolsProcessingAcceptableTemp.addAll(Arrays.asList(
|
||||||
|
"javax.annotation.processing.",
|
||||||
|
"javax.tools."
|
||||||
|
));
|
||||||
|
javaxToolsProcessingAcceptable = javaxToolsProcessingAcceptableTemp;
|
||||||
|
Set<String> comSunSourceAcceptableTemp = new HashSet<>();
|
||||||
|
comSunSourceAcceptableTemp.addAll(javaxToolsProcessingAcceptable);
|
||||||
|
comSunSourceAcceptableTemp.addAll(Arrays.asList(
|
||||||
|
"com.sun.source.doctree.",
|
||||||
|
"com.sun.source.tree.",
|
||||||
|
"com.sun.source.util."
|
||||||
|
));
|
||||||
|
comSunSourceAcceptable = comSunSourceAcceptableTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean process(Set<? extends TypeElement> annotations,
|
||||||
|
RoundEnvironment roundEnv) {
|
||||||
|
if (roundEnv.processingOver()) {
|
||||||
|
verifyPackage(javaxLangModelPackages, javaxLangModelAcceptable);
|
||||||
|
verifyPackage(javaxToolsProcessingPackages, javaxToolsProcessingAcceptable);
|
||||||
|
verifyPackage(comSunSourcePackages, comSunSourceAcceptable);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyPackage(String[] packagesToTest, Set<String> acceptable) {
|
||||||
|
for (String packageToTest : packagesToTest) {
|
||||||
|
PackageElement packageElement = processingEnv.getElementUtils()
|
||||||
|
.getPackageElement(packageToTest);
|
||||||
|
|
||||||
|
verifyReferredTypesAcceptable(packageElement, acceptable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyReferredTypesAcceptable(Element rootElement,
|
||||||
|
final Set<String> acceptable) {
|
||||||
|
new ElementScanner8<Void, Void>() {
|
||||||
|
@Override public Void visitType(TypeElement e, Void p) {
|
||||||
|
verifyTypeAcceptable(e.getSuperclass(), acceptable);
|
||||||
|
verifyTypesAcceptable(e.getInterfaces(), acceptable);
|
||||||
|
scan(e.getTypeParameters(), p);
|
||||||
|
scan(e.getEnclosedElements(), p);
|
||||||
|
verifyAnnotations(e.getAnnotationMirrors(), acceptable);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override public Void visitTypeParameter(TypeParameterElement e, Void p) {
|
||||||
|
verifyTypesAcceptable(e.getBounds(), acceptable);
|
||||||
|
scan(e.getEnclosedElements(), p);
|
||||||
|
verifyAnnotations(e.getAnnotationMirrors(), acceptable);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override public Void visitPackage(PackageElement e, Void p) {
|
||||||
|
scan(e.getEnclosedElements(), p);
|
||||||
|
verifyAnnotations(e.getAnnotationMirrors(), acceptable);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override public Void visitVariable(VariableElement e, Void p) {
|
||||||
|
verifyTypeAcceptable(e.asType(), acceptable);
|
||||||
|
scan(e.getEnclosedElements(), p);
|
||||||
|
verifyAnnotations(e.getAnnotationMirrors(), acceptable);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Void visitExecutable(ExecutableElement e, Void p) {
|
||||||
|
scan(e.getTypeParameters(), p);
|
||||||
|
verifyTypeAcceptable(e.getReturnType(), acceptable);
|
||||||
|
scan(e.getParameters(), p);
|
||||||
|
verifyTypesAcceptable(e.getThrownTypes(), acceptable);
|
||||||
|
scan(e.getEnclosedElements(), p);
|
||||||
|
verifyAnnotations(e.getAnnotationMirrors(), acceptable);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}.scan(rootElement, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyAnnotations(Iterable<? extends AnnotationMirror> annotations,
|
||||||
|
Set<String> acceptable) {
|
||||||
|
for (AnnotationMirror mirror : annotations) {
|
||||||
|
Element annotationElement = mirror.getAnnotationType().asElement();
|
||||||
|
|
||||||
|
if (annotationElement.getAnnotation(Documented.class) == null) {
|
||||||
|
note("Ignoring undocumented annotation: " + mirror.getAnnotationType());
|
||||||
|
}
|
||||||
|
|
||||||
|
verifyTypeAcceptable(mirror.getAnnotationType(), acceptable);
|
||||||
|
|
||||||
|
for (AnnotationValue value : mirror.getElementValues().values()) {
|
||||||
|
verifyAnnotationValue(value, acceptable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyAnnotationValue(AnnotationValue value,
|
||||||
|
final Set<String> acceptable) {
|
||||||
|
value.accept(new SimpleAnnotationValueVisitor8<Void, Void>() {
|
||||||
|
@Override public Void visitType(TypeMirror t, Void p) {
|
||||||
|
verifyTypeAcceptable(t, acceptable);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Void visitEnumConstant(VariableElement c, Void p) {
|
||||||
|
verifyReferredTypesAcceptable(c, acceptable);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override public Void visitArray(List<? extends AnnotationValue> vals,
|
||||||
|
Void p) {
|
||||||
|
for (AnnotationValue val : vals) {
|
||||||
|
val.accept(this, p);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override protected Void defaultAction(Object o, Void p) {
|
||||||
|
error("Unexpected AnnotationValue: " + o.toString());
|
||||||
|
return super.defaultAction(o, p);
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyTypesAcceptable(Iterable<? extends TypeMirror> types,
|
||||||
|
Set<String> acceptable) {
|
||||||
|
if (types == null) return ;
|
||||||
|
|
||||||
|
for (TypeMirror type : types) {
|
||||||
|
verifyTypeAcceptable(type, acceptable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyTypeAcceptable(TypeMirror type, Set<String> acceptable) {
|
||||||
|
if (type == null) return ;
|
||||||
|
|
||||||
|
verifyAnnotations(type.getAnnotationMirrors(), acceptable);
|
||||||
|
|
||||||
|
switch (type.getKind()) {
|
||||||
|
case BOOLEAN: case BYTE: case CHAR: case DOUBLE: case FLOAT:
|
||||||
|
case INT: case LONG: case SHORT: case VOID: case NONE: case NULL:
|
||||||
|
return ;
|
||||||
|
case DECLARED:
|
||||||
|
DeclaredType dt = (DeclaredType) type;
|
||||||
|
TypeElement outermostTypeElement = outermostTypeElement(dt.asElement());
|
||||||
|
String outermostType = outermostTypeElement.getQualifiedName().toString();
|
||||||
|
boolean isAcceptable = false;
|
||||||
|
for (String acceptablePackage : acceptable) {
|
||||||
|
if (outermostType.startsWith(acceptablePackage)) {
|
||||||
|
isAcceptable = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isAcceptable) {
|
||||||
|
error("Type not acceptable for this API: " + dt.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TypeMirror bound : dt.getTypeArguments()) {
|
||||||
|
verifyTypeAcceptable(bound, acceptable);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ARRAY:
|
||||||
|
verifyTypeAcceptable(((ArrayType) type).getComponentType(), acceptable);
|
||||||
|
break;
|
||||||
|
case INTERSECTION:
|
||||||
|
for (TypeMirror element : ((IntersectionType) type).getBounds()) {
|
||||||
|
verifyTypeAcceptable(element, acceptable);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TYPEVAR:
|
||||||
|
verifyTypeAcceptable(((TypeVariable) type).getLowerBound(), acceptable);
|
||||||
|
verifyTypeAcceptable(((TypeVariable) type).getUpperBound(), acceptable);
|
||||||
|
break;
|
||||||
|
case WILDCARD:
|
||||||
|
verifyTypeAcceptable(((WildcardType) type).getExtendsBound(), acceptable);
|
||||||
|
verifyTypeAcceptable(((WildcardType) type).getSuperBound(), acceptable);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error("Type not acceptable for this API: " + type.toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private TypeElement outermostTypeElement(Element el) {
|
||||||
|
while (el.getEnclosingElement().getKind() != ElementKind.PACKAGE) {
|
||||||
|
el = el.getEnclosingElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (TypeElement) el;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void error(String text) {
|
||||||
|
processingEnv.getMessager().printMessage(Kind.ERROR, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void note(String text) {
|
||||||
|
processingEnv.getMessager().printMessage(Kind.NOTE, text);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user