下面列出了javax.lang.model.element.ExecutableElement#getReceiverType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** The docs claim this should be a NoType of TypeKind.NONE. The docs lie. */
@Test
public void testGetReceiverTypeOfStaticIsNull() throws IOException {
compile(Joiner.on('\n').join("class Foo {", " static void foo() { }", "}"));
ExecutableElement element = findMethod("foo", elements.getTypeElement("Foo"));
TypeMirror receiverType = element.getReceiverType();
assertNull(receiverType);
}
/** The docs claim this should be a NoType of TypeKind.NONE. The docs lie. */
@Test
public void testGetReceiverTypeOfTopLevelConstructorIsNull() throws IOException {
compile(Joiner.on('\n').join("class Foo {", " Foo () { }", "}"));
ExecutableElement element = findDefaultConstructor(elements.getTypeElement("Foo"));
TypeMirror receiverType = element.getReceiverType();
assertNull(receiverType);
}
@Test
public void testGetReceiverTypeOfInnerConstructorIsEnclosingType() throws IOException {
compile(
Joiner.on('\n')
.join("class Foo {", " class Bar {", " Bar (Foo Foo.this) { }", " }", "}"));
ExecutableElement element = findDefaultConstructor(elements.getTypeElement("Foo.Bar"));
TypeMirror receiverType = element.getReceiverType();
assertSameType(elements.getTypeElement("Foo").asType(), receiverType);
}
@Test
public void testGetReceiverTypeOfInnerConstructorIsEnclosingTypeGeneric() throws IOException {
compile(
Joiner.on('\n')
.join("class Foo<T> {", " class Bar {", " Bar (Foo<T> Foo.this) { }", " }", "}"));
ExecutableElement element = findDefaultConstructor(elements.getTypeElement("Foo.Bar"));
TypeMirror receiverType = element.getReceiverType();
assertSameType(elements.getTypeElement("Foo").asType(), receiverType);
}
@Test
public void testGetReceiverTypeOfInstanceMethodIsEnclosingType() throws IOException {
compile(Joiner.on('\n').join("class Foo {", " void foo(Foo this) { }", "}"));
TypeElement fooClass = elements.getTypeElement("Foo");
ExecutableElement fooMethod = findMethod("foo", fooClass);
TypeMirror receiverType = fooMethod.getReceiverType();
assertSameType(fooClass.asType(), receiverType);
}
@Test
public void testGetReceiverTypeOfInstanceMethodIsEnclosingTypeGeneric() throws IOException {
compile(Joiner.on('\n').join("class Foo<T> {", " void foo(Foo<T> this) { }", "}"));
TypeElement fooClass = elements.getTypeElement("Foo");
ExecutableElement fooMethod = findMethod("foo", fooClass);
TypeMirror receiverType = fooMethod.getReceiverType();
assertSameType(fooClass.asType(), receiverType);
}
public void addReceiverAnnotationInfo(ExecutableElement method, TypeMirror rcvrTypeMirror,
List<? extends AnnotationMirror> annotationMirrors, Content htmltree) {
TypeMirror rcvrType = method.getReceiverType();
List<? extends AnnotationMirror> annotationMirrors1 = rcvrType.getAnnotationMirrors();
addAnnotationInfo(0, method, annotationMirrors1, false, htmltree);
}