private String elementName(Element elem) { return elem.getSimpleName().toString(); }
private boolean isObject(TypeMirror t) { if (t instanceof DeclaredType) { DeclaredType dt = (DeclaredType) t; return ((TypeElement) dt.asElement()).getQualifiedName().toString().equals("java.lang.Object"); } return false; }
private List<String> getSuperclasses(TypeElement type, List<String> superclasses) { TypeElement superclass = type; while ((superclass = (TypeElement) getTypeUtils().asElement(superclass.getSuperclass())) != null) { String qualifiedName = superclass.getQualifiedName().toString(); if ("java.lang.Object".equals(qualifiedName)) { break; } superclasses.add(qualifiedName); } return superclasses; }
private String getTypeString(TypeMirror type) { TypeElement typeElement = (TypeElement) getTypeUtils().asElement(type); if (typeElement != null) { // this returns raw parameterized types return typeElement.getQualifiedName().toString(); } // this deals with primitive and array types return type.toString(); }
private String getTypeString(TypeMirror type) { TypeElement typeElement = (TypeElement) getTypeUtils().asElement(type); if (typeElement != null) { // this returns raw parameterized types return typeElement.getQualifiedName().toString(); } // this deals with primitive and array types return type.toString(); }
protected void writeAggregatableType(TypeElement type, String suffix) throws IOException { writeAggregatableType(type, suffix, type.getQualifiedName().toString() + "\n"); }
private List<String> getSuperclasses(TypeElement type, List<String> superclasses) { TypeElement superclass = type; while ((superclass = (TypeElement) getTypeUtils().asElement(superclass.getSuperclass())) != null) { String qualifiedName = superclass.getQualifiedName().toString(); if ("java.lang.Object".equals(qualifiedName)) { break; } superclasses.add(qualifiedName); } return superclasses; }
private String getPackageName(Element elem) { return getPackage(elem).getQualifiedName().toString(); }
@Override protected String createMetadata(TypeElement type, Element element, TypeElement annType, AnnotationMirror annotation) { return elementUtils.getBinaryName(type).toString(); }
private Stream<ExecutableElement> filterAndSortMethods(Collection<ExecutableElement> methods) { boolean diffIncludePresent = methods.stream().anyMatch(m -> m.getAnnotation(DiffInclude.class) != null); return methods.stream() .filter(method -> !diffIncludePresent || method.getAnnotation(DiffInclude.class) != null) .sorted(Comparator.comparing(e -> e.getSimpleName().toString())); }
private Map<Element, Set<Element>> packageMissingElements(Map<String, Element> packageElements, Map<Element, Set<TypeMirror>> requiredTypes) { return requiredTypes.entrySet().stream() .flatMap(entry -> (Stream<Pair<Element, TypeMirror>>) entry.getValue().stream().map(value -> Pair.of(entry.getKey(), value))) .filter(refAndType -> !isPrimitiveOrSimilar(refAndType.getRight())) .flatMap(this::extractTypeArguments) .map(refAndType -> pairOfValue(refAndType, extractSpecificType(refAndType.getRight()))) .filter(refAndType -> !isPrimitiveOrSimilar(refAndType.getRight())) // Again, maybe arrived from map/collection generics .map(refAndType -> pairOfValue(refAndType, typeUtils.asElement(refAndType.getRight()))) .filter(refAndElement -> !packageElements.containsKey(refAndElement.getRight().getSimpleName().toString())) .collect(Collectors.toMap(Pair::getRight, pair -> ImmutableSet.of(pair.getLeft()), (pair1, pair2) -> ImmutableSet.<Element>builder().addAll(pair1).addAll(pair2).build())); }
private TypeMirror extractSpecificType(TypeMirror type) { TypeMirror specificType = removeWildcard(type); return typeUtils.asElement(specificType).getAnnotationMirrors().stream() .filter(a -> a.getAnnotationType().toString().equals(GenerateDiffFunction.class.getName())) .findFirst() .map(annotation -> annotation.getElementValues().entrySet().stream() .filter(entry -> "defaultImpl".equals(entry.getKey().getSimpleName().toString())) .map(Map.Entry::getValue) .map(AnnotationValue::getValue) .filter(val -> !val.equals(Object.class.getName())) .findFirst() .map(val -> elementUtils.getTypeElement(val.toString()).asType()) .orElse(specificType)) .orElse(specificType); }
private TreeMap<String, Object> translate(List<? extends AnnotationMirror> mirrors, TypeElement ann) { TreeMap<String, Object> values = new TreeMap<String, Object>(); for (AnnotationMirror mirror : mirrors) { if (processingEnv.getTypeUtils().isSameType(mirror.getAnnotationType(), ann.asType())) { for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : mirror.getElementValues() .entrySet()) { values.put(entry.getKey().getSimpleName().toString(), translate(entry.getValue().getValue())); } } } return values; }
private Set<ExecutableElement> relevantMethodsInElement(Element element) { return notDistinctMethodsInElement(element).stream() .filter(method -> method.getAnnotation(DiffIgnore.class) == null) .filter(distinctByKey(e -> e.getSimpleName().toString())) .collect(Collectors.toSet()); }
@Override public void add(TypeElement e, String key, T value) { String name = e.getQualifiedName().toString(); Use o = output.get(name); if (o == null) { output.put(name, o = new Use(e)); } o.add(key, value); } });
@Override public void add(String contract, TypeElement provider) { metadata.add(provider, contract, elementUtils.getBinaryName(provider).toString()); } });
private String findKeyExtractorMethod(TypeMirror type) { TypeMirror extractedType = isCollection(type) ? extractSpecificType(findErasure(type)) : type; return relevantMethodsInElement(typeUtils.asElement(extractedType)).stream() .filter(method -> method.getAnnotation(DiffKey.class) != null) .map(method -> method.getSimpleName().toString()) .findFirst() .orElseThrow(() -> new FailWithError("Classes that are referenced as List or by @" + DiffReference.class.getSimpleName() + " must define a method with @" + DiffKey.class.getSimpleName() + ". [" + type + "]", typeUtils.asElement(type))); }
private Pair<String, String> methodToLocalDiffMethod(String packageName, ExecutableElement method) { TypeMirror returnType = method.getReturnType(); String methodName = method.getSimpleName().toString(); if (isPrimitiveOrSimilar(returnType) || method.getAnnotation(DiffAtomic.class) != null || method.getAnnotation(DiffReference.class) != null || isCollectionOrMapOfPrimitive(returnType)) { return simpleAppend(method, DiffUtils.toFieldName(methodName), methodName); } else { return diffMethodForComplexClass(packageName, method); } }
private MojoRequirement toComponentDescriptor(VariableElement field, Component component) { MojoRequirement result = new MojoRequirement(); result.setFieldName(field.getSimpleName().toString()); result.setRole(getComponentRole(field, component)); result.setRoleHint(component.hint()); return result; }
private MojoRequirement toComponentDescriptor(VariableElement field, Component component) { MojoRequirement result = new MojoRequirement(); result.setFieldName(field.getSimpleName().toString()); result.setRole(getComponentRole(field, component)); result.setRoleHint(component.hint()); return result; }