All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jedi.annotation.processor6.model.TypeDeclarationRenderer Maven / Gradle / Ivy

package jedi.annotation.processor6.model;

import static jedi.functional.FunctionalPrimitives.collect;
import static jedi.functional.FunctionalPrimitives.join;

import java.util.Collection;
import java.util.List;

import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.type.TypeMirror;

import jedi.functional.Functor;

class TypeDeclarationRenderer {
	public static String render(Collection collection) {
		return collection.isEmpty() ? "" : "<" + join(collect(collection, createTypeParameterElementRenderer()), ", ") + ">";
	}

	private static Functor createTypeParameterElementRenderer() {
		return new Functor() {
			public String execute(TypeParameterElement value) {
				return value.getSimpleName() + renderBounds(value.getBounds());
			}
		};
	}

	private static String renderBounds(Collection bounds) {
		return bounds.isEmpty() ? "" : " extends " + join(bounds, "&");
	}

	public static String renderWithoutBounds(TypeElement typeElement) {
		return typeElement.getQualifiedName() + renderWithoutBounds(typeElement.getTypeParameters());
	}

	public static String renderWithoutBounds(Collection typeParameters) {
		return typeParameters.isEmpty() ? "" : "<" + join(collectNames(typeParameters), ", ") + ">";
	}

	private static List collectNames(Collection typeParameters) {
		return collect(typeParameters, new Functor() {
			public String execute(TypeParameterElement value) {
				return value.getSimpleName().toString();
			}
		});
	}
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy