@Test public void packageNameOf() throws Exception { String NAME = "test.package"; Name packageName = Mockito.mock(Name.class); Mockito.when(packageName.toString()).thenReturn(NAME); PackageElement packageElement = Mockito.mock(PackageElement.class); Mockito.when(packageElement.getQualifiedName()).thenReturn(packageName); Element element = Mockito.mock(TypeElement.class); Mockito.when(element.getEnclosingElement()).thenReturn(packageElement); TypeElement type = Mockito.mock(TypeElement.class); Mockito.when(type.getEnclosingElement()).thenReturn(element); MatcherAssert.assertThat(TypeElementUtils.packageNameOf(type), Is.is(NAME)); }
public static String packageNameOf(final TypeElement type) { TypeElement searchedType = type; while (true) { Element enclosing = searchedType.getEnclosingElement(); if (enclosing instanceof PackageElement) { return ((PackageElement) enclosing).getQualifiedName().toString(); } searchedType = (TypeElement) enclosing; } }
TypeElementUtils { public static String packageNameOf(final TypeElement type) { TypeElement searchedType = type; while (true) { Element enclosing = searchedType.getEnclosingElement(); if (enclosing instanceof PackageElement) { return ((PackageElement) enclosing).getQualifiedName().toString(); } searchedType = (TypeElement) enclosing; } } }
TypeElementUtils { public static String packageNameOf(final TypeElement type) { TypeElement searchedType = type; while (true) { Element enclosing = searchedType.getEnclosingElement(); if (enclosing instanceof PackageElement) { return ((PackageElement) enclosing).getQualifiedName().toString(); } searchedType = (TypeElement) enclosing; } } private  TypeElementUtils(); }
TypeElementUtils { public static String packageNameOf(final TypeElement type) { TypeElement searchedType = type; while (true) { Element enclosing = searchedType.getEnclosingElement(); if (enclosing instanceof PackageElement) { return ((PackageElement) enclosing).getQualifiedName().toString(); } searchedType = (TypeElement) enclosing; } } private  TypeElementUtils(); static boolean isAbstract(@NonNull TypeElement element); static ImmutableList<ExecutableElement> getConstructors(@NonNull TypeElement element); static ImmutableList<ExecutableElement> getConstructorsWithAnnotation(
      List<ExecutableElement> constructors, Class<? extends Annotation> annotation); static String packageNameOf(final TypeElement type); static String simpleNameOf(String s); }
TypeElementUtils { public static String packageNameOf(final TypeElement type) { TypeElement searchedType = type; while (true) { Element enclosing = searchedType.getEnclosingElement(); if (enclosing instanceof PackageElement) { return ((PackageElement) enclosing).getQualifiedName().toString(); } searchedType = (TypeElement) enclosing; } } private  TypeElementUtils(); static boolean isAbstract(@NonNull TypeElement element); static ImmutableList<ExecutableElement> getConstructors(@NonNull TypeElement element); static ImmutableList<ExecutableElement> getConstructorsWithAnnotation(
      List<ExecutableElement> constructors, Class<? extends Annotation> annotation); static String packageNameOf(final TypeElement type); static String simpleNameOf(String s);  }