javax.lang.model.util.SimpleTypeVisitor6 Java Examples

The following examples show how to use javax.lang.model.util.SimpleTypeVisitor6. 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 Project: doma   Author: domaframework   File:    License: Apache License 2.0 5 votes vote down vote up
public ArrayType toArrayType(TypeMirror typeMirror) {
  return typeMirror.accept(
      new SimpleTypeVisitor6<ArrayType, Void>() {

        public ArrayType visitArray(ArrayType t, Void p) {
          return t;
Example #2
Source Project: litho   Author: facebook   File:    License: Apache License 2.0 4 votes vote down vote up
 * This method will "expand" the typeArguments of the given type, only if the type is a {@link
 * ClassNames#DIFF} or a {@link java.util.Collection}. Otherwise the typeArguments won't be
 * traversed and recorded.
public static TypeSpec generateTypeSpec(TypeMirror type) {
  final TypeSpec defaultValue =
      new TypeSpec(safelyGetTypeName(type), type.getKind() != TypeKind.ERROR);

  return type.accept(
      new SimpleTypeVisitor6<TypeSpec, Void>(defaultValue) {
        public TypeSpec visitDeclared(DeclaredType t, Void aVoid) {
          final TypeElement typeElement = (TypeElement) t.asElement();
          final String qualifiedName = typeElement.getQualifiedName().toString();
          final Supplier<TypeSpec> superclass =
              new SimpleMemoizingSupplier<>(
                  () -> {
                    final TypeMirror mirror = typeElement.getSuperclass();
                    return mirror.getKind() != TypeKind.DECLARED
                        ? null
                        : generateTypeSpec(mirror);

          final Supplier<ImmutableList<TypeSpec>> superinterfaces =
              new SimpleMemoizingSupplier<>(
                  () -> {
                    final List<? extends TypeMirror> mirrors = typeElement.getInterfaces();
                    return ImmutableList.copyOf(
                        mirrors != null && !mirrors.isEmpty()
                                .filter(mirror -> mirror.getKind() == TypeKind.DECLARED)
                            : Collections.emptyList());

          final Supplier<ImmutableList<TypeSpec>> typeArguments =
              new SimpleMemoizingSupplier<>(
                  () ->
                                  || superinterfaces.get().stream()
                                          typeSpec ->
                              ? ((DeclaredType) type)
                              : Collections.emptyList()));

          return new TypeSpec.DeclaredTypeSpec(
              safelyGetTypeName(t), qualifiedName, superclass, superinterfaces, typeArguments);