/** * Gets the element representing the {@linkplain TypeElement#getSuperclass() super class} of a * given type element. */ public static TypeElement getSuperType(TypeElement element) { if (element.getSuperclass() != null) { return fromTypeMirror(element.getSuperclass()); } return null; }
/** * Gets the element representing the {@linkplain TypeElement#getSuperclass() super class} of a * given type element. */ public static TypeElement getSuperType(TypeElement element) { if (element.getSuperclass() != null) { return fromTypeMirror(element.getSuperclass()); } return null; }
public static TypeElement fromTypeMirror(TypeMirror mirror) { switch (mirror.getKind()) { case DECLARED: return (TypeElement) ((DeclaredType) mirror).asElement(); case ARRAY: return fromTypeMirror(((ArrayType) mirror).getComponentType()); default: return null; } }
private static List<TypeElement> collectSuperClasses(List<TypeElement> collection, TypeElement element) { if (element != null) { collection.add(element); if (element.getSuperclass() != null) { collectSuperClasses(collection, ElementUtils.fromTypeMirror(element.getSuperclass())); } } return collection; }
public static TypeElement fromTypeMirror(TypeMirror mirror) { switch (mirror.getKind()) { case DECLARED: return (TypeElement) ((DeclaredType) mirror).asElement(); case ARRAY: return fromTypeMirror(((ArrayType) mirror).getComponentType()); default: return null; } }
private Set<String> getCachedSuperTypes(TypeMirror e) { if (e == null) { return Collections.emptySet(); } Set<String> superTypes = cachedQualifiedNames.get(e); if (superTypes == null) { superTypes = new HashSet<>(ElementUtils.getQualifiedSuperTypeNames(ElementUtils.fromTypeMirror(e))); cachedQualifiedNames.put(e, superTypes); } return superTypes; } });
private int calculateVarArgsThreshold() { TypeMirror specialization = context.getType(SpecializationNode.class); TypeElement specializationType = fromTypeMirror(specialization); int maxParameters = 0; for (ExecutableElement element : ElementFilter.methodsIn(specializationType.getEnclosedElements())) { if (element.getSimpleName().contentEquals("acceptAndExecute")) { maxParameters = Math.max(maxParameters, element.getParameters().size()); } } return maxParameters; }
private static List<TypeElement> collectSuperClasses(List<TypeElement> collection, TypeElement element) { if (element != null) { collection.add(element); if (element.getSuperclass() != null) { collectSuperClasses(collection, ElementUtils.fromTypeMirror(element.getSuperclass())); } } return collection; }
private static boolean isRuntimeException(TypeMirror type) { Set<String> typeSuperSet = new HashSet<>(getQualifiedSuperTypeNames(fromTypeMirror(type))); return typeSuperSet.contains(RuntimeException.class.getCanonicalName()) || getQualifiedName(type).equals(RuntimeException.class.getCanonicalName()); }
private static boolean isRuntimeException(TypeMirror type) { Set<String> typeSuperSet = new HashSet<>(getQualifiedSuperTypeNames(fromTypeMirror(type))); return typeSuperSet.contains(RuntimeException.class.getCanonicalName()) || getQualifiedName(type).equals(RuntimeException.class.getCanonicalName()); }
public Template getTemplate(TypeMirror templateTypeMirror, boolean invokeCallback) { String qualifiedName = ElementUtils.getQualifiedName(templateTypeMirror); Template model = models.get(qualifiedName); if (model == null && invokeCallback) { callback.callback(ElementUtils.fromTypeMirror(templateTypeMirror)); model = models.get(qualifiedName); } return model; }
public Template getTemplate(TypeMirror templateTypeMirror, boolean invokeCallback) { String qualifiedName = ElementUtils.getQualifiedName(templateTypeMirror); Template model = models.get(qualifiedName); if (model == null && invokeCallback) { callback.callback(ElementUtils.fromTypeMirror(templateTypeMirror)); model = models.get(qualifiedName); } return model; }
public static int compareByTypeHierarchy(TypeMirror t1, TypeMirror t2) { if (typeEquals(t1, t2)) { return 0; } Set<String> t1SuperSet = new HashSet<>(getQualifiedSuperTypeNames(fromTypeMirror(t1))); if (t1SuperSet.contains(getQualifiedName(t2))) { return -1; } Set<String> t2SuperSet = new HashSet<>(getQualifiedSuperTypeNames(fromTypeMirror(t2))); if (t2SuperSet.contains(getQualifiedName(t1))) { return 1; } return 0; }
public static boolean isTopLevelClass(TypeMirror importType) { TypeElement type = fromTypeMirror(importType); if (type != null && type.getEnclosingElement() != null) { return !type.getEnclosingElement().getKind().isClass(); } return true; }
public static boolean isTopLevelClass(TypeMirror importType) { TypeElement type = fromTypeMirror(importType); if (type != null && type.getEnclosingElement() != null) { return !type.getEnclosingElement().getKind().isClass(); } return true; }
static CodeExecutableElement createConstructorUsingFields(Set<Modifier> modifiers, CodeTypeElement clazz) { TypeElement superClass = fromTypeMirror(clazz.getSuperclass()); ExecutableElement constructor = findConstructor(superClass); return createConstructorUsingFields(modifiers, clazz, constructor); }
public static CodeExecutableElement createConstructorUsingFields(Set<Modifier> modifiers, CodeTypeElement clazz) { TypeElement superClass = fromTypeMirror(clazz.getSuperclass()); ExecutableElement constructor = findConstructor(superClass); return createConstructorUsingFields(modifiers, clazz, constructor); }
public static boolean canThrowType(List<? extends TypeMirror> thrownTypes, TypeMirror exceptionType) { if (ElementUtils.containsType(thrownTypes, exceptionType)) { return true; } if (isRuntimeException(exceptionType)) { return true; } // search for any super types for (TypeElement typeElement : getSuperTypes(fromTypeMirror(exceptionType))) { if (ElementUtils.containsType(thrownTypes, typeElement.asType())) { return true; } } return false; }
private CodeExecutableElement createCreateGetNodeClass() { TypeMirror returnValue = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getType(Class.class)), node.getNodeType()); CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnValue, "getNodeClass"); method.createBuilder().startReturn().typeLiteral(node.getNodeType()).end(); return method; }
private CodeExecutableElement createCreateGetExecutionSignature() { TypeMirror returnValue = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getType(List.class))); CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnValue, "getExecutionSignature"); CodeTreeBuilder builder = method.createBuilder(); builder.startReturn(); builder.startStaticCall(context.getType(Arrays.class), "asList"); for (NodeExecutionData execution : node.getChildExecutions()) { builder.typeLiteral(execution.getNodeType()); } builder.end(); builder.end(); return method; }