Refine search
/** Finds the parent binder type in the supplied set, if any. */ private @Nullable TypeElement findParentType(TypeElement typeElement, Set<TypeElement> parents) { TypeMirror type; while (true) { type = typeElement.getSuperclass(); if (type.getKind() == TypeKind.NONE) { return null; } typeElement = (TypeElement) ((DeclaredType) type).asElement(); if (parents.contains(typeElement)) { return typeElement; } } }
private TypeElement getSuperclass(TypeElement type) { if (type.getSuperclass().getKind() == TypeKind.DECLARED) { TypeElement superclass = (TypeElement) processingEnv.getTypeUtils().asElement(type.getSuperclass()); String name = superclass.getQualifiedName().toString(); if (name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("android.")) { // Skip system classes, this just degrades performance return null; } else { return superclass; } } else { return null; } }
/** * Finds superclasses until reaching the Object class */ private void addAncestorsElements(Set<TypeElement> elements, TypeElement typeElement) { TypeMirror ancestorTypeMirror = typeElement.getSuperclass(); if (!isRootObjectClass(ancestorTypeMirror) && !isAndroidClass(ancestorTypeMirror) && ancestorTypeMirror instanceof DeclaredType) { DeclaredType ancestorDeclaredType = (DeclaredType) ancestorTypeMirror; Element ancestorElement = ancestorDeclaredType.asElement(); if (ancestorElement instanceof TypeElement) { addAncestorsElements(elements, (TypeElement) ancestorElement); elements.add((TypeElement) ancestorElement); } } }
public static TypeElement getSuperclassTypeElement(TypeElement element) { final TypeMirror superClass = element.getSuperclass(); //superclass of Object is of NoType which returns some other kind if ( superClass.getKind() == TypeKind.DECLARED ) { //F..king Ch...t Have those people used their horrible APIs even once? final Element superClassElement = ( (DeclaredType) superClass ).asElement(); return (TypeElement) superClassElement; } else { return null; } }
private static boolean extendsClass(Types types, TypeElement element, String className) { if (namesEqual(element, className)) { return true; } // check super types TypeMirror superType = element.getSuperclass(); while (superType != null && superType.getKind() != TypeKind.NONE) { TypeElement superTypeElement = (TypeElement) types.asElement(superType); if (namesEqual(superTypeElement, className)) { return true; } superType = superTypeElement.getSuperclass(); } return false; }
final TypeMirror superType = element.getSuperclass(); final TypeElement superTypeElement = (TypeElement) ((DeclaredType) superType).asElement();
/** * Obtains the super type element for a given type element. * * @param element The type element * @return The super type element or null if none exists */ static TypeElement superClassFor(TypeElement element) { TypeMirror superclass = element.getSuperclass(); if (superclass.getKind() == TypeKind.NONE) { return null; } logger.finest(format("Superclass of %s is %s (of kind %s)", element, superclass, superclass.getKind())); DeclaredType kind = (DeclaredType) superclass; return (TypeElement) kind.asElement(); }
static boolean overridesMethod(Types types, TypeElement element, String methodName) { while (element != null) { if (ElementFilter.methodsIn(element.getEnclosedElements()).stream() .anyMatch(method -> method.getSimpleName().contentEquals(methodName))) { return true; } TypeMirror superType = element.getSuperclass(); if (superType.getKind() == TypeKind.NONE) { break; } else { element = (TypeElement) types.asElement(superType); } if (namesEqual(element, Object.class.getCanonicalName())) { break; } } return false; }
TypeMirror superType = typeElement.getSuperclass(); TypeElement superTypeElement = null; if (superType instanceof DeclaredType) { superTypeElement = (TypeElement) ((DeclaredType) superType).asElement();
private TypeMirror createStringTypeMirror() { TypeElement element = typeElement; while (element.getSuperclass().getKind() != TypeKind.NONE) { logger.finest("finding toString in " + element); element = (TypeElement) ((DeclaredType) element.getSuperclass()).asElement(); } for (Element enclosed : typeElement.getEnclosedElements()) { if (enclosed.getKind() == ElementKind.METHOD) { ExecutableElement method = (ExecutableElement) enclosed; if (method.getSimpleName().contentEquals("toString")) { return method.getReturnType(); } } } throw new IllegalStateException("Cannot find toString method in Object"); } private static boolean find(String interfaceName, TypeElement typeElement) {
if (clazz.getSuperclass().getKind() != TypeKind.DECLARED) { return null; DeclaredType superclass = (DeclaredType) clazz.getSuperclass(); TypeMirror recursiveResult = getEpoxyObjectType((TypeElement) typeUtils.asElement(superclass), typeUtils); if (recursiveResult != null && recursiveResult.getKind() != TypeKind.TYPEVAR) {
private TypeElement getSuperclassElement(Element element) { if (element instanceof TypeElement) { TypeMirror superclass = ((TypeElement) element).getSuperclass(); if (superclass instanceof DeclaredType) { return ((TypeElement) ((DeclaredType) superclass).asElement()); } } return null; }
return true; if (typeMirror.getKind() != TypeKind.DECLARED) { return false; List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments(); if (typeArguments.size() > 0) { StringBuilder typeString = new StringBuilder(declaredType.asElement().toString()); typeString.append('<'); for (int i = 0; i < typeArguments.size(); i++) { Element element = declaredType.asElement(); if (!(element instanceof TypeElement)) { return false; TypeMirror superType = typeElement.getSuperclass(); if (isSubtypeOfType(superType, otherType)) { return true;
/** * Get information about methods returning class type of the original class so we can duplicate * them in the generated class for chaining purposes */ protected void collectMethodsReturningClassType(TypeElement modelClass, Types typeUtils) { TypeElement clazz = modelClass; while (clazz.getSuperclass().getKind() != TypeKind.NONE) { for (Element subElement : clazz.getEnclosedElements()) { Set<Modifier> modifiers = subElement.getModifiers(); if (subElement.getKind() == ElementKind.METHOD && !modifiers.contains(Modifier.PRIVATE) && !modifiers.contains(Modifier.FINAL) && !modifiers.contains(Modifier.STATIC)) { TypeMirror methodReturnType = ((ExecutableType) subElement.asType()).getReturnType(); if (methodReturnType.equals(clazz.asType()) || typeUtils.isSubtype(clazz.asType(), methodReturnType)) { ExecutableElement castedSubElement = ((ExecutableElement) subElement); List<? extends VariableElement> params = castedSubElement.getParameters(); String methodName = subElement.getSimpleName().toString(); if (methodName.equals(RESET_METHOD) && params.isEmpty()) { continue; } methodsReturningClassType.add(new MethodInfo(methodName, modifiers, buildParamSpecs(params), castedSubElement.isVarArgs())); } } } clazz = (TypeElement) typeUtils.asElement(clazz.getSuperclass()); } }
private String getMatchingSuperClass(Element elementToValidate, String[] superClassNames) { TypeMirror superType = ((TypeElement) elementToValidate).getSuperclass(); String superClass = null; // Looping the inheritance hierarchy to check if the element inherits at least one of the super // classes specified. while (!"none".equals(superType.toString())) { Element superTypeElement = ((DeclaredType) superType).asElement(); if (Arrays.asList(superClassNames).contains(superTypeElement.toString())) { superClass = superTypeElement.toString(); break; } superType = ((TypeElement) superTypeElement).getSuperclass(); } return superClass; }
private static String findMappedSuperClass(MetaEntity entity, Context context) { TypeMirror superClass = entity.getTypeElement().getSuperclass(); //superclass of Object is of NoType which returns some other kind while ( superClass.getKind() == TypeKind.DECLARED ) { //F..king Ch...t Have those people used their horrible APIs even once? final Element superClassElement = ( (DeclaredType) superClass ).asElement(); String superClassName = ( (TypeElement) superClassElement ).getQualifiedName().toString(); if ( extendsSuperMetaModel( superClassElement, entity.isMetaComplete(), context ) ) { return superClassName; } superClass = ( (TypeElement) superClassElement ).getSuperclass(); } return null; }
private static boolean implementsInterface(Types types, TypeElement element, String interfaceName) { // check name or interfaces if (namesEqual(element, interfaceName)) { return true; } TypeMirror type = element.asType(); while (type != null && type.getKind() != TypeKind.NONE) { TypeElement currentElement = (TypeElement) types.asElement(type); if (currentElement == null) { break; } List<? extends TypeMirror> interfaces = element.getInterfaces(); for (TypeMirror interfaceType : interfaces) { interfaceType = types.erasure(interfaceType); TypeElement typeElement = (TypeElement) types.asElement(interfaceType); if (typeElement != null && implementsInterface(types, typeElement, interfaceName)) { return true; } } type = currentElement.getSuperclass(); } return false; }
public static List<TypeMirror> getSuperClassGenerics(TypeElement type, Class superClass, ProcessingEnvironment processingEnvironment) { TypeElement superClassTypeElement = processingEnvironment.getElementUtils().getTypeElement(superClass.getName()); TypeElement objectType = processingEnvironment.getElementUtils().getTypeElement(Object.class.getName()); TypeMirror superClassTypeMirror = processingEnvironment.getTypeUtils().erasure(superClassTypeElement.asType()); if (!processingEnvironment.getTypeUtils().isAssignable(type.asType(), superClassTypeMirror)) { throw new IllegalArgumentException( format("Class '%s' does not extend the '%s' class", type.getQualifiedName(), superClass.getSimpleName())); } DeclaredType searchClass = (DeclaredType) type.asType(); while (!processingEnvironment.getTypeUtils().isAssignable(objectType.asType(), searchClass)) { if (processingEnvironment.getTypeUtils().isSameType(superClassTypeMirror, processingEnvironment.getTypeUtils().erasure(searchClass))) { List<TypeMirror> typeArguments = (List<TypeMirror>) searchClass.getTypeArguments(); return typeArguments; } TypeMirror superclass = ((TypeElement) searchClass.asElement()).getSuperclass(); if (superclass instanceof DeclaredType) { searchClass = (DeclaredType) superclass; } else { searchClass = (DeclaredType) objectType.asType(); } } return emptyList(); }
private TypeElement findClosestAncestorWithNavigationModelBinder(TypeElement element) { while (true) { final TypeMirror superType = element.getSuperclass(); if (superType.getKind() == TypeKind.NONE) { // Got to the oldest ancestor and none contains NavigationModelModelBinder return null; } element = (TypeElement) ((DeclaredType) superType).asElement(); // ancestor contains a NavigationModel field if (getNavigationModelBinder(element) != null) { return element; } } }
TypeMirror currentClassSuperclass = currentClass.getSuperclass(); if (currentClassSuperclass == null || currentClassSuperclass.getKind() == TypeKind.NONE) { TypeMirror superClass = problemClass.getSuperclass(); TypeElement superClassElement = null; && superClass.getKind() != TypeKind.NONE && (superClassElement = (TypeElement) typeUtils.asElement(superClass)) != null) { break; superClass = superClassElement.getSuperclass();