/** * Returns the component type of the given type if it is an array or an iterable and logs errors with the given logger otherwise. */ @Pure @LogsErrorWhenReturningNull public static @Nullable TypeMirror getComponentType(@Nonnull TypeMirror type, @NonCaptured @Modified @Nonnull ErrorLogger errorLogger) { return getComponentTypes(type, errorLogger) == null ? null : getComponentTypes(type, errorLogger).get(0); }
/** * Returns the component types of the given type if it is an array or an iterable. */ @Pure @LogsErrorWhenReturningNull public static @Nullable List<TypeMirror> getComponentTypes(@Nonnull TypeMirror type) { return getComponentTypes(type, ErrorLogger.INSTANCE); }
/** * Returns the component types of the type of the given element if it is an array or an iterable. */ @Pure @LogsErrorWhenReturningNull public static @Nullable List<TypeMirror> getComponentTypes(@Nonnull Element element) { return getComponentTypes(element, ErrorLogger.INSTANCE); }
/** * Returns the component types of the type of the given element if it is an array or an iterable and logs errors with the given logger otherwise. */ @Pure @LogsErrorWhenReturningNull public static @Nullable List<TypeMirror> getComponentTypes(@Nonnull Element element, @NonCaptured @Modified @Nonnull ErrorLogger errorLogger) { return getComponentTypes(getType(element), errorLogger); }
/** * Returns the custom type for the given representing field. */ public static String getTypeName(@Nonnull TypeMirror representingFieldType, @Nonnull FiniteIterable<@Nonnull AnnotationMirror> annotations, @Nonnull TypeImporter typeImporter) { @Nonnull CustomType customType = CustomType.of(representingFieldType, annotations); // TODO: ProcessingUtility.getTypeElement(representingFieldType) is null for generic types but checking this only here leads to new problems (namely "The name 'TConverter' has to be qualified."). if (customType == CustomType.TUPLE && ProcessingUtility.getTypeElement(representingFieldType).getKind() == ElementKind.ENUM) { return typeImporter.importStaticallyIfPossible(CustomType.class.getCanonicalName() + "." + customType.getTypeName()) + ".of" + Brackets.inRound(typeImporter.importIfPossible("net.digitalid.utility.conversion.converters.StringConverter") + ".INSTANCE"); } else if (customType == CustomType.SET || customType == CustomType.LIST || customType == CustomType.ARRAY) { final @Nonnull TypeMirror componentType = ProcessingUtility.getComponentType(representingFieldType); return typeImporter.importStaticallyIfPossible(CustomType.class.getCanonicalName() + "." + customType.getTypeName()) + ".of" + Brackets.inRound(getTypeName(componentType, FiniteIterable.of(), typeImporter)); } else if (customType == CustomType.MAP) { final @Nullable List<TypeMirror> componentTypes = ProcessingUtility.getComponentTypes(representingFieldType); Require.that(componentTypes.size() == 2).orThrow("Map type does not have 2 component types."); return typeImporter.importStaticallyIfPossible(CustomType.class.getCanonicalName() + "." + customType.getTypeName()) + ".of" + Brackets.inRound(getTypeName(componentTypes.get(0), FiniteIterable.of(), typeImporter) + ", " + getTypeName(componentTypes.get(1), FiniteIterable.of(), typeImporter)); } else if (representingFieldType.getKind().isPrimitive() || customType == BINARY || customType == BINARY128 || customType == BINARY256) { return typeImporter.importStaticallyIfPossible(CustomType.class.getCanonicalName() + "." + customType.getTypeName()); } else { @Nonnull String typeName = customType.getTypeName(); @Nonnull String qualifiedName = ProcessingUtility.getQualifiedName(representingFieldType); if (!qualifiedName.startsWith("net.digitalid")) { typeName = TUPLE.getTypeName(); } return typeImporter.importStaticallyIfPossible(CustomType.class.getCanonicalName() + "." + typeName) + ".of" + Brackets.inRound(importConverterType(representingFieldType, annotations, typeImporter)); } }