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

The following examples show how to use javax.lang.model.element.ExecutableElement#getReceiverType() . These examples are extracted from open source projects. 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
/** 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
/** 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
@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
@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
@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
@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
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);
}