Java Code Examples for javax.lang.model.element.ExecutableElement#getReceiverType()

The following examples show how to use javax.lang.model.element.ExecutableElement#getReceiverType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeBackedExecutableElementTest.java    From buck with Apache License 2.0 5 votes vote down vote up
/** 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);
}
 
Example 2
Source File: TreeBackedExecutableElementTest.java    From buck with Apache License 2.0 5 votes vote down vote up
/** 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);
}
 
Example 3
Source File: TreeBackedExecutableElementTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: TreeBackedExecutableElementTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: TreeBackedExecutableElementTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: TreeBackedExecutableElementTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: HtmlDocletWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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);
}