提交 e9481e87 编写于 作者: B bpatel

8005091: javadoc should be able to return the receiver type

Reviewed-by: jjg
上级 ab779287
......@@ -87,6 +87,14 @@ public interface ExecutableMemberDoc extends MemberDoc {
*/
Parameter[] parameters();
/**
* Get the receiver type of this executable element.
*
* @return the receiver type of this executable element.
* @since 1.8
*/
Type receiverType();
/**
* Get the receiver annotations of this executable element.
* Return an empty array if there are none.
......
......@@ -139,12 +139,24 @@ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWrite
}
}
protected void addReceiverAnnotations(ExecutableMemberDoc member,
Content tree) {
if (member.receiverAnnotations().length > 0) {
tree.addContent(writer.getSpace());
writer.addReceiverAnnotationInfo(member, tree);
}
/**
* Add the receiver annotations information.
*
* @param member the member to write receiver annotations for.
* @param rcvrType the receiver type.
* @param descList list of annotation description.
* @param tree the content tree to which the information will be added.
*/
protected void addReceiverAnnotations(ExecutableMemberDoc member, Type rcvrType,
AnnotationDesc[] descList, Content tree) {
writer.addReceiverAnnotationInfo(member, descList, tree);
tree.addContent(writer.getSpace());
tree.addContent(rcvrType.typeName());
LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, rcvrType);
tree.addContent(new RawHtml(writer.getTypeParameterLinks(linkInfo)));
tree.addContent(writer.getSpace());
tree.addContent("this");
}
......@@ -168,14 +180,24 @@ public abstract class AbstractExecutableMemberWriter extends AbstractMemberWrite
protected void addParameters(ExecutableMemberDoc member,
boolean includeAnnotations, Content htmltree) {
htmltree.addContent("(");
String sep = "";
Parameter[] params = member.parameters();
String indent = makeSpace(writer.displayLength);
if (configuration.linksource) {
//add spaces to offset indentation changes caused by link.
indent+= makeSpace(member.name().length());
}
Type rcvrType = member.receiverType();
if (includeAnnotations && rcvrType instanceof AnnotatedType) {
AnnotationDesc[] descList = rcvrType.asAnnotatedType().annotations();
if (descList.length > 0) {
addReceiverAnnotations(member, rcvrType, descList, htmltree);
sep = "," + DocletConstants.NL + indent;
}
}
int paramstart;
for (paramstart = 0; paramstart < params.length; paramstart++) {
htmltree.addContent(sep);
Parameter param = params[paramstart];
if (!param.name().startsWith("this$")) {
if (includeAnnotations) {
......
......@@ -137,7 +137,6 @@ public class ConstructorWriterImpl extends AbstractExecutableMemberWriter
addName(constructor.name(), pre);
}
addParameters(constructor, pre);
writer.addReceiverAnnotationInfo(constructor, pre);
addExceptions(constructor, pre);
return pre;
}
......
......@@ -1860,11 +1860,13 @@ public class HtmlDocletWriter extends HtmlDocWriter {
* Add the annotation types of the executable receiver.
*
* @param method the executable to write the receiver annotations for.
* @param descList list of annotation description.
* @param htmltree the documentation tree to which the annotation info will be
* added
*/
public void addReceiverAnnotationInfo(ExecutableMemberDoc method, Content htmltree) {
addAnnotationInfo(method, method.receiverAnnotations(), htmltree);
public void addReceiverAnnotationInfo(ExecutableMemberDoc method, AnnotationDesc[] descList,
Content htmltree) {
addAnnotationInfo(0, method, descList, false, htmltree);
}
/**
......@@ -1915,13 +1917,16 @@ public class HtmlDocletWriter extends HtmlDocWriter {
private boolean addAnnotationInfo(int indent, Doc doc,
AnnotationDesc[] descList, boolean lineBreak, Content htmltree) {
List<String> annotations = getAnnotations(indent, descList, lineBreak);
String sep ="";
if (annotations.size() == 0) {
return false;
}
Content annotationContent;
for (Iterator<String> iter = annotations.iterator(); iter.hasNext();) {
htmltree.addContent(sep);
annotationContent = new RawHtml(iter.next());
htmltree.addContent(annotationContent);
sep = " ";
}
return true;
}
......
......@@ -130,7 +130,6 @@ public class MethodWriterImpl extends AbstractExecutableMemberWriter
addName(method.name(), pre);
}
addParameters(method, pre);
addReceiverAnnotations(method, pre);
addExceptions(method, pre);
return pre;
}
......
......@@ -199,6 +199,17 @@ public abstract class ExecutableMemberDocImpl
return result;
}
/**
* Get the receiver type of this executable element.
*
* @return the receiver type of this executable element.
* @since 1.8
*/
public com.sun.javadoc.Type receiverType() {
Type recvtype = sym.type.asMethodType().recvtype;
return (recvtype != null) ? TypeMaker.getType(env, recvtype, false, true) : null;
}
public AnnotationDesc[] receiverAnnotations() {
// TODO: change how receiver annotations are output!
Type recvtype = sym.type.asMethodType().recvtype;
......
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8005091
* @summary Make sure that type annotations are displayed correctly
* @author Bhavesh Patel
* @library ../lib/
* @build JavadocTester TestTypeAnnotations
* @run main TestTypeAnnotations
*/
public class TestTypeAnnotations extends JavadocTester {
//Test information.
private static final String BUG_ID = "8005091";
//Javadoc arguments.
private static final String[] ARGS = new String[] {
"-d", BUG_ID, "-sourcepath", SRC_DIR, "-private", "typeannos"
};
//Input for string search tests.
private static final String[][] NEGATED_TEST = NO_TEST;
private static final String[][] TEST = {
// Test for type annotations on Class Extends (ClassExtends.java).
{BUG_ID + FS + "typeannos" + FS + "MyClass.html",
"implements <a href=\"../typeannos/ClassExtB.html\" title=\"" +
"annotation in typeannos\">@ClassExtB</a> java.lang.CharSequence, " +
"<a href=\"../typeannos/ParameterizedInterface.html\" title=\"" +
"interface in typeannos\">ParameterizedInterface</a>&lt;java.lang.String&gt;</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "MyInterface.html",
"extends <a href=\"../typeannos/ParameterizedInterface.html\" title" +
"=\"interface in typeannos\">ParameterizedInterface</a>&lt;java." +
"lang.String&gt;, <a href=\"../typeannos/ClassExtB.html\" title=\"" +
"annotation in typeannos\">@ClassExtB</a> java.lang.CharSequence</pre>"
},
// Test for type annotations on Class Parameters (ClassParameters.java).
{BUG_ID + FS + "typeannos" + FS + "ExtendsBound.html",
"class <span class=\"strong\">ExtendsBound&lt;K extends <a " +
"href=\"../typeannos/ClassParamA.html\" title=\"annotation in " +
"typeannos\">@ClassParamA</a> java.lang.String&gt;</span>"
},
{BUG_ID + FS + "typeannos" + FS + "TwoBounds.html",
"class <span class=\"strong\">TwoBounds&lt;K extends <a href=\"" +
"../typeannos/ClassParamA.html\" title=\"annotation in typeannos\">" +
"@ClassParamA</a> java.lang.String,V extends <a href=\"../typeannos" +
"/ClassParamB.html\" title=\"annotation in typeannos\">@ClassParamB" +
"</a> java.lang.String&gt;</span>"
},
{BUG_ID + FS + "typeannos" + FS + "Complex1.html",
"class <span class=\"strong\">Complex1&lt;K extends <a href=\"../" +
"typeannos/ClassParamA.html\" title=\"annotation in typeannos\">" +
"@ClassParamA</a> java.lang.String & java.lang.Runnable&gt;</span>"
},
{BUG_ID + FS + "typeannos" + FS + "Complex2.html",
"class <span class=\"strong\">Complex2&lt;K extends java.lang." +
"String & <a href=\"../typeannos/ClassParamB.html\" title=\"" +
"annotation in typeannos\">@ClassParamB</a> java.lang.Runnable&gt;</span>"
},
{BUG_ID + FS + "typeannos" + FS + "ComplexBoth.html",
"class <span class=\"strong\">ComplexBoth&lt;K extends <a href=\"" +
"../typeannos/ClassParamA.html\" title=\"annotation in typeannos\"" +
">@ClassParamA</a> java.lang.String & <a href=\"../typeannos/" +
"ClassParamA.html\" title=\"annotation in typeannos\">@ClassParamA" +
"</a> java.lang.Runnable&gt;</span>"
},
// Test for type annotations on method return types (MethodReturnType.java).
{BUG_ID + FS + "typeannos" + FS + "MtdDefaultScope.html",
"<pre>public&nbsp;&lt;T&gt;&nbsp;<a href=\"../typeannos/MRtnA.html\" " +
"title=\"annotation in typeannos\">@MRtnA</a> java.lang.String" +
"&nbsp;method()</pre>"
},
// Test for type annotations on method type parameters (MethodTypeParameters.java).
{BUG_ID + FS + "typeannos" + FS + "UnscopedUnmodified.html",
"<pre>&lt;K extends <a href=\"../typeannos/MTyParamA.html\" title=\"" +
"annotation in typeannos\">@MTyParamA</a> java.lang.String&gt;" +
"&nbsp;void&nbsp;methodExtends()</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "PublicModifiedMethods.html",
"<pre>public final&nbsp;&lt;K extends <a href=\"../typeannos/" +
"MTyParamA.html\" title=\"annotation in typeannos\">@MTyParamA</a> " +
"java.lang.String&gt;&nbsp;void&nbsp;methodExtends()</pre>"
},
// Test for type annotations on throws (Throws.java).
{BUG_ID + FS + "typeannos" + FS + "ThrDefaultUnmodified.html",
"<pre>void&nbsp;oneException()" + NL +
" throws <a href=\"../typeannos/ThrA.html\" title=\"" +
"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "ThrDefaultUnmodified.html",
"<pre>void&nbsp;twoExceptions()" + NL +
" throws <a href=\"../typeannos/ThrA.html\" title=\"" +
"annotation in typeannos\">@ThrA</a> java.lang.RuntimeException," + NL +
" <a href=\"../typeannos/ThrA.html\" title=\"" +
"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "ThrPublicModified.html",
"<pre>public final&nbsp;void&nbsp;oneException(java.lang.String&nbsp;a)" + NL +
" throws <a href=\"../typeannos/ThrA.html\" " +
"title=\"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "ThrPublicModified.html",
"<pre>public final&nbsp;void&nbsp;twoExceptions(java.lang.String&nbsp;a)" + NL +
" throws <a href=\"../typeannos/ThrA.html\" " +
"title=\"annotation in typeannos\">@ThrA</a> java.lang.RuntimeException," + NL +
" <a href=\"../typeannos/ThrA.html\" " +
"title=\"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "ThrWithValue.html",
"<pre>void&nbsp;oneException()" + NL +
" throws <a href=\"../typeannos/ThrB.html\" title=\"" +
"annotation in typeannos\">@ThrB</a>(<a href=\"../typeannos/" +
"ThrB.html#value()\">value</a>=\"m\") java.lang.Exception</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "ThrWithValue.html",
"<pre>void&nbsp;twoExceptions()" + NL +
" throws <a href=\"../typeannos/ThrB.html\" title=\"" +
"annotation in typeannos\">@ThrB</a>(<a href=\"../typeannos/" +
"ThrB.html#value()\">value</a>=\"m\") java.lang.RuntimeException," + NL +
" <a href=\"../typeannos/ThrA.html\" title=\"" +
"annotation in typeannos\">@ThrA</a> java.lang.Exception</pre>"
},
// Test for type annotations on wildcard type (Wildcards.java).
{BUG_ID + FS + "typeannos" + FS + "BoundTest.html",
"<pre>void&nbsp;wcExtends(<a href=\"../typeannos/MyList.html\" " +
"title=\"class in typeannos\">MyList</a>&lt;? extends <a href=\"" +
"../typeannos/WldA.html\" title=\"annotation in typeannos\">@WldA" +
"</a> java.lang.String&gt;&nbsp;l)</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "BoundTest.html",
"<pre><a href=\"../typeannos/MyList.html\" title=\"class in " +
"typeannos\">MyList</a>&lt;? super <a href=\"../typeannos/WldA.html\" " +
"title=\"annotation in typeannos\">@WldA</a> java.lang.String&gt;" +
"&nbsp;returnWcSuper()</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "BoundWithValue.html",
"<pre>void&nbsp;wcSuper(<a href=\"../typeannos/MyList.html\" title=\"" +
"class in typeannos\">MyList</a>&lt;? super <a href=\"../typeannos/" +
"WldB.html\" title=\"annotation in typeannos\">@WldB</a>(<a href=\"" +
"../typeannos/WldB.html#value()\">value</a>=\"m\") java.lang." +
"String&gt;&nbsp;l)</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "BoundWithValue.html",
"<pre><a href=\"../typeannos/MyList.html\" title=\"class in " +
"typeannos\">MyList</a>&lt;? extends <a href=\"../typeannos/WldB." +
"html\" title=\"annotation in typeannos\">@WldB</a>(<a href=\"../" +
"typeannos/WldB.html#value()\">value</a>=\"m\") java.lang.String" +
"&gt;&nbsp;returnWcExtends()</pre>"
},
// Test for receiver annotations (Receivers.java).
{BUG_ID + FS + "typeannos" + FS + "DefaultUnmodified.html",
"<pre>void&nbsp;withException(<a href=\"../typeannos/RcvrA.html\" " +
"title=\"annotation in typeannos\">@RcvrA</a>&nbsp;" +
"DefaultUnmodified&nbsp;this)" + NL + " throws java." +
"lang.Exception</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "DefaultUnmodified.html",
"<pre>java.lang.String&nbsp;nonVoid(<a href=\"../typeannos/RcvrA." +
"html\" title=\"annotation in typeannos\">@RcvrA</a> <a href=\"../" +
"typeannos/RcvrB.html\" title=\"annotation in typeannos\">@RcvrB" +
"</a>(<a href=\"../typeannos/RcvrB.html#value()\">value</a>=\"m\")" +
"&nbsp;DefaultUnmodified&nbsp;this)</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "DefaultUnmodified.html",
"<pre>&lt;T extends java.lang.Runnable&gt;&nbsp;void&nbsp;accept(" +
"<a href=\"../typeannos/RcvrA.html\" title=\"annotation in " +
"typeannos\">@RcvrA</a>&nbsp;DefaultUnmodified&nbsp;this," + NL +
" T&nbsp;r)" + NL +
" throws java.lang.Exception</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "PublicModified.html",
"<pre>public final&nbsp;java.lang.String&nbsp;nonVoid(<a href=\"" +
"../typeannos/RcvrA.html\" title=\"annotation in typeannos\">" +
"@RcvrA</a>&nbsp;PublicModified&nbsp;this)</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "PublicModified.html",
"<pre>public final&nbsp;&lt;T extends java.lang.Runnable&gt;&nbsp;" +
"void&nbsp;accept(<a href=\"../typeannos/RcvrA.html\" title=\"" +
"annotation in typeannos\">@RcvrA</a>&nbsp;PublicModified&nbsp;this," + NL +
" T&nbsp;r)" + NL +
" throws java.lang.Exception</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "WithValue.html",
"<pre>&lt;T extends java.lang.Runnable&gt;&nbsp;void&nbsp;accept(" +
"<a href=\"../typeannos/RcvrB.html\" title=\"annotation in " +
"typeannos\">@RcvrB</a>(<a href=\"../typeannos/RcvrB.html#value()\">" +
"value</a>=\"m\")&nbsp;WithValue&nbsp;this," + NL +
" T&nbsp;r)" + NL +
" throws java.lang.Exception</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "WithFinal.html",
"<pre>java.lang.String&nbsp;nonVoid(<a href=\"../typeannos/RcvrB." +
"html\" title=\"annotation in typeannos\">@RcvrB</a>(<a href=\"../" +
"typeannos/RcvrB.html#value()\">value</a>=\"m\")&nbsp;WithFinal" +
"&nbsp;this)</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "WithBody.html",
"<pre>void&nbsp;field(<a href=\"../typeannos/RcvrA.html\" title=\"" +
"annotation in typeannos\">@RcvrA</a>&nbsp;WithBody&nbsp;this)</pre>"
},
{BUG_ID + FS + "typeannos" + FS + "Generic2.html",
"<pre>void&nbsp;test2(<a href=\"../typeannos/RcvrA.html\" title=\"" +
"annotation in typeannos\">@RcvrA</a>&nbsp;Generic2&lt;X&gt;&nbsp;this)</pre>"
}
};
/**
* The entry point of the test.
* @param args the array of command line arguments.
*/
public static void main(String[] args) {
TestTypeAnnotations tester = new TestTypeAnnotations();
run(tester, ARGS, TEST, NEGATED_TEST);
tester.printSummary();
}
/**
* {@inheritDoc}
*/
public String getBugId() {
return BUG_ID;
}
/**
* {@inheritDoc}
*/
public String getBugName() {
return getClass().getName();
}
}
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
abstract class MyClass extends @ClassExtA ParameterizedClass<@ClassExtB String>
implements @ClassExtB CharSequence, @ClassExtA ParameterizedInterface<@ClassExtB String> { }
interface MyInterface extends @ClassExtA ParameterizedInterface<@ClassExtA String>,
@ClassExtB CharSequence { }
class ParameterizedClass<K> {}
interface ParameterizedInterface<K> {}
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface ClassExtA {}
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface ClassExtB {}
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
class Unannotated<K> { }
class ExtendsBound<K extends @ClassParamA String> { }
class ExtendsGeneric<K extends @ClassParamA Unannotated<@ClassParamB String>> { }
class TwoBounds<K extends @ClassParamA String, V extends @ClassParamB String> { }
class Complex1<K extends @ClassParamA String&Runnable> { }
class Complex2<K extends String & @ClassParamB Runnable> { }
class ComplexBoth<K extends @ClassParamA String & @ClassParamA Runnable> { }
class ClassParamOuter {
void inner() {
class LUnannotated<K> { }
class LExtendsBound<K extends @ClassParamA String> { }
class LExtendsGeneric<K extends @ClassParamA LUnannotated<@ClassParamB String>> { }
class LTwoBounds<K extends @ClassParamA String, V extends @ClassParamB String> { }
class LComplex1<K extends @ClassParamA String&Runnable> { }
class LComplex2<K extends String & @ClassParamB Runnable> { }
class LComplexBoth<K extends @ClassParamA String & @ClassParamA Runnable> { }
}
}
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface ClassParamA { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface ClassParamB { }
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
class DefaultScope {
Parameterized<String, String> unannotated;
Parameterized<@FldA String, String> firstTypeArg;
Parameterized<String, @FldA String> secondTypeArg;
Parameterized<@FldA String, @FldB String> bothTypeArgs;
Parameterized<@FldA Parameterized<@FldA String, @FldB String>, @FldB String>
nestedParameterized;
@FldA String [] array1;
@FldA String @FldB [] array1Deep;
@FldA String [] [] array2;
@FldA String @FldA [] @FldB [] array2Deep;
String @FldA [] [] array2First;
String [] @FldB [] array2Second;
// Old-style array syntax
String array2FirstOld @FldA [];
String array2SecondOld [] @FldB [];
}
class ModifiedScoped {
public final Parameterized<String, String> unannotated = null;
public final Parameterized<@FldA String, String> firstTypeArg = null;
public final Parameterized<String, @FldA String> secondTypeArg = null;
public final Parameterized<@FldA String, @FldB String> bothTypeArgs = null;
public final Parameterized<@FldA Parameterized<@FldA String, @FldB String>, @FldB String>
nestedParameterized = null;
public final @FldA String [] array1 = null;
public final @FldA String @FldB [] array1Deep = null;
public final @FldA String [] [] array2 = null;
public final @FldA String @FldA [] @FldB [] array2Deep = null;
public final String @FldA [] [] array2First = null;
public final String [] @FldB [] array2Second = null;
}
class Parameterized<K, V> { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface FldA { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface FldB { }
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
class MtdDefaultScope {
MtdParameterized<String, String> unannotated() { return null; }
MtdParameterized<@MRtnA String, String> firstTypeArg() { return null; }
MtdParameterized<String, @MRtnA String> secondTypeArg() { return null; }
MtdParameterized<@MRtnA String, @MRtnB String> bothTypeArgs() { return null; }
MtdParameterized<@MRtnA MtdParameterized<@MRtnA String, @MRtnB String>, @MRtnB String>
nestedMtdParameterized() { return null; }
public <T> @MRtnA String method() { return null; }
@MRtnA String [] array1() { return null; }
@MRtnA String @MRtnB [] array1Deep() { return null; }
@MRtnA String [] [] array2() { return null; }
@MRtnA String @MRtnA [] @MRtnB [] array2Deep() { return null; }
String @MRtnA [] [] array2First() { return null; }
String [] @MRtnB [] array2Second() { return null; }
// Old-style array syntax
String array2FirstOld() @MRtnA [] { return null; }
String array2SecondOld() [] @MRtnB [] { return null; }
}
class MtdModifiedScoped {
public final MtdParameterized<String, String> unannotated() { return null; }
public final MtdParameterized<@MRtnA String, String> firstTypeArg() { return null; }
public final MtdParameterized<String, @MRtnA String> secondTypeArg() { return null; }
public final MtdParameterized<@MRtnA String, @MRtnB String> bothTypeArgs() { return null; }
public final MtdParameterized<@MRtnA MtdParameterized<@MRtnA String, @MRtnB String>, @MRtnB String>
nestedMtdParameterized() { return null; }
public final @MRtnA String [] array1() { return null; }
public final @MRtnA String @MRtnB [] array1Deep() { return null; }
public final @MRtnA String [] [] array2() { return null; }
public final @MRtnA String @MRtnA [] @MRtnB [] array2Deep() { return null; }
public final String @MRtnA [] [] array2First() { return null; }
public final String [] @MRtnB [] array2Second() { return null; }
}
class MtdParameterized<K, V> { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface MRtnA { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface MRtnB { }
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
class UnscopedUnmodified {
<K extends @MTyParamA String> void methodExtends() {}
<K extends @MTyParamA MtdTyParameterized<@MTyParamB String>> void nestedExtends() {}
<K extends @MTyParamA String, V extends @MTyParamA MtdTyParameterized<@MTyParamB String>> void dual() {}
<K extends String, V extends MtdTyParameterized<@MTyParamB String>> void dualOneAnno() {}
}
class PublicModifiedMethods {
public final <K extends @MTyParamA String> void methodExtends() {}
public final <K extends @MTyParamA MtdTyParameterized<@MTyParamB String>> void nestedExtends() {}
public final <K extends @MTyParamA String, V extends @MTyParamA MtdTyParameterized<@MTyParamB String>> void dual() {}
public final <K extends String, V extends MtdTyParameterized<@MTyParamB String>> void dualOneAnno() {}
}
class MtdTyParameterized<K> { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface MTyParamA { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface MTyParamB { }
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
class Parameters {
void unannotated(ParaParameterized<String, String> a) {}
void firstTypeArg(ParaParameterized<@ParamA String, String> a) {}
void secondTypeArg(ParaParameterized<String, @ParamA String> a) {}
void bothTypeArgs(ParaParameterized<@ParamA String, @ParamB String> both) {}
void nestedParaParameterized(ParaParameterized<@ParamA ParaParameterized<@ParamA String, @ParamB String>, @ParamB String> a) {}
void array1(@ParamA String [] a) {}
void array1Deep(@ParamA String @ParamB [] a) {}
void array2(@ParamA String [] [] a) {}
void array2Deep(@ParamA String @ParamA [] @ParamB [] a) {}
void array2First(String @ParamA [] [] a) {}
void array2Second(String [] @ParamB [] a) {}
}
class ParaParameterized<K, V> { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface ParamA { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface ParamB { }
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
class DefaultUnmodified {
void plain(@RcvrA DefaultUnmodified this) { }
<T> void generic(@RcvrA DefaultUnmodified this) { }
void withException(@RcvrA DefaultUnmodified this) throws Exception { }
String nonVoid(@RcvrA @RcvrB("m") DefaultUnmodified this) { return null; }
<T extends Runnable> void accept(@RcvrA DefaultUnmodified this, T r) throws Exception { }
}
class PublicModified {
public final void plain(@RcvrA PublicModified this) { }
public final <T> void generic(@RcvrA PublicModified this) { }
public final void withException(@RcvrA PublicModified this) throws Exception { }
public final String nonVoid(@RcvrA PublicModified this) { return null; }
public final <T extends Runnable> void accept(@RcvrA PublicModified this, T r) throws Exception { }
}
class WithValue {
void plain(@RcvrB("m") WithValue this) { }
<T> void generic(@RcvrB("m") WithValue this) { }
void withException(@RcvrB("m") WithValue this) throws Exception { }
String nonVoid(@RcvrB("m") WithValue this) { return null; }
<T extends Runnable> void accept(@RcvrB("m") WithValue this, T r) throws Exception { }
}
class WithFinal {
void plain(final @RcvrB("m") WithFinal this) { }
<T> void generic(final @RcvrB("m") WithFinal this) { }
void withException(final @RcvrB("m") WithFinal this) throws Exception { }
String nonVoid(final @RcvrB("m") WithFinal this) { return null; }
<T extends Runnable> void accept(final @RcvrB("m") WithFinal this, T r) throws Exception { }
}
class WithBody {
Object f;
void field(@RcvrA WithBody this) {
this.f = null;
}
void meth(@RcvrA WithBody this) {
this.toString();
}
}
class Generic1<X> {
void test1(Generic1<X> this) {}
void test2(@RcvrA Generic1<X> this) {}
void test3(Generic1<@RcvrA X> this) {}
void test4(@RcvrA Generic1<@RcvrA X> this) {}
}
class Generic2<@RcvrA X> {
void test1(Generic2<X> this) {}
void test2(@RcvrA Generic2<X> this) {}
void test3(Generic2<@RcvrA X> this) {}
void test4(@RcvrA Generic2<@RcvrA X> this) {}
}
class Generic3<X extends @RcvrA Object> {
void test1(Generic3<X> this) {}
void test2(@RcvrA Generic3<X> this) {}
void test3(Generic3<@RcvrA X> this) {}
void test4(@RcvrA Generic3<@RcvrA X> this) {}
}
class Generic4<X extends @RcvrA Object> {
<Y> void test1(Generic4<X> this) {}
<Y> void test2(@RcvrA Generic4<X> this) {}
<Y> void test3(Generic4<@RcvrA X> this) {}
<Y> void test4(@RcvrA Generic4<@RcvrA X> this) {}
}
class Outer {
class Inner {
void none(Outer.Inner this) {}
void outer(@RcvrA Outer.Inner this) {}
void inner(Outer. @RcvrB("i") Inner this) {}
void both(@RcvrA Outer.@RcvrB("i") Inner this) {}
void innerOnlyNone(Inner this) {}
void innerOnly(@RcvrA Inner this) {}
}
}
class GenericOuter<S, T> {
class GenericInner<U, V> {
void none(GenericOuter<S, T>.GenericInner<U, V> this) {}
void outer(@RcvrA GenericOuter<S, T>.GenericInner<U, V> this) {}
void inner(GenericOuter<S, T>. @RcvrB("i") GenericInner<U, V> this) {}
void both(@RcvrA GenericOuter<S, T>.@RcvrB("i") GenericInner<U, V> this) {}
void innerOnlyNone(GenericInner<U, V> this) {}
void innerOnly(@RcvrA GenericInner<U, V> this) {}
}
}
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface RcvrA {}
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface RcvrB { String value(); }
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
class ThrDefaultUnmodified {
void oneException() throws @ThrA Exception {}
void twoExceptions() throws @ThrA RuntimeException, @ThrA Exception {}
}
class ThrPublicModified {
public final void oneException(String a) throws @ThrA Exception {}
public final void twoExceptions(String a) throws @ThrA RuntimeException, @ThrA Exception {}
}
class ThrWithValue {
void oneException() throws @ThrB("m") Exception {}
void twoExceptions() throws @ThrB(value="m") RuntimeException, @ThrA Exception {}
}
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface ThrA {}
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface ThrB { String value(); }
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
class TypUnannotated<K> { }
class OneAnnotated<@TyParaA K> { }
class TwoAnnotated<@TyParaA K, @TyParaA V> { }
class SecondAnnotated<K, @TyParaA V extends String> { }
class TestMethods {
<K> void unannotated() { }
<@TyParaA K> void oneAnnotated() { }
<@TyParaA K, @TyParaB("m") V> void twoAnnotated() { }
<K, @TyParaA V extends @TyParaA String> void secondAnnotated() { }
}
class UnannotatedB<K> { }
class OneAnnotatedB<@TyParaB("m") K> { }
class TwoAnnotatedB<@TyParaB("m") K, @TyParaB("m") V> { }
class SecondAnnotatedB<K, @TyParaB("m") V extends @TyParaB("m") String> { }
class OneAnnotatedC<@TyParaC K> { }
class TwoAnnotatedC<@TyParaC K, @TyParaC V> { }
class SecondAnnotatedC<K, @TyParaC V extends String> { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface TyParaA { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface TyParaB { String value(); }
@Target(ElementType.TYPE_USE)
@Documented
@interface TyParaC { }
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface VarArgA {}
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
class Varargs {
// Handle annotations on a varargs element type
void varargPlain(Object @VarArgA... objs) {
}
void varargGeneric(Class<?> @VarArgA ... clz) {
}
}
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package typeannos;
import java.lang.annotation.*;
/*
* This class is replicated from test/tools/javac/annotations/typeAnnotations/newlocations.
*/
class BoundTest {
void wcExtends(MyList<? extends @WldA String> l) { }
void wcSuper(MyList<? super @WldA String> l) { }
MyList<? extends @WldA String> returnWcExtends() { return null; }
MyList<? super @WldA String> returnWcSuper() { return null; }
MyList<? extends @WldA MyList<? super @WldB("m") String>> complex() { return null; }
}
class BoundWithValue {
void wcExtends(MyList<? extends @WldB("m") String> l) { }
void wcSuper(MyList<? super @WldB(value="m") String> l) { }
MyList<? extends @WldB("m") String> returnWcExtends() { return null; }
MyList<? super @WldB(value="m") String> returnWcSuper() { return null; }
MyList<? extends @WldB("m") MyList<? super @WldB("m") String>> complex() { return null; }
}
class SelfTest {
void wcExtends(MyList<@WldA ?> l) { }
void wcSuper(MyList<@WldA ?> l) { }
MyList<@WldA ?> returnWcExtends() { return null; }
MyList<@WldA ?> returnWcSuper() { return null; }
MyList<@WldA ? extends @WldA MyList<@WldB("m") ?>> complex() { return null; }
}
class SelfWithValue {
void wcExtends(MyList<@WldB("m") ?> l) { }
void wcSuper(MyList<@WldB(value="m") ?> l) { }
MyList<@WldB("m") ?> returnWcExtends() { return null; }
MyList<@WldB(value="m") ?> returnWcSuper() { return null; }
MyList<@WldB("m") ? extends MyList<@WldB("m") ? super String>> complex() { return null; }
}
class MyList<K> { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface WldA { }
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@Documented
@interface WldB { String value(); }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册