List of usage examples for javax.lang.model.element TypeElement getSuperclass
TypeMirror getSuperclass();
From source file:org.lambdamatic.mongodb.apt.template.ElementUtils.java
/** * Checks if the given {@link Element} is, implements or extends the given target type. * /*ww w. j av a 2s . c o m*/ * @param type the element to analyze * @param targetType the type to check * @return <code>true</code> if the given {@link Element} corresponds to a type that implements * {@link List}, <code>false</code> otherwise. */ public static boolean isAssignable(final DeclaredType type, final Class<?> targetType) { if (type instanceof NoType) { return false; } if (type.asElement().toString().equals(targetType.getName())) { return true; } final TypeElement element = (TypeElement) type.asElement(); final boolean implementation = element.getInterfaces().stream() .filter(interfaceMirror -> interfaceMirror.getKind() == TypeKind.DECLARED) .map(interfaceMirror -> (DeclaredType) interfaceMirror) .map(declaredInterface -> declaredInterface.asElement()) .anyMatch(declaredElement -> declaredElement.toString().equals(targetType.getName())); if (implementation) { return true; } if (element.getSuperclass().getKind() == TypeKind.DECLARED) { return isAssignable((DeclaredType) (element.getSuperclass()), targetType); } return false; }
From source file:com.vimeo.stag.processor.utils.TypeUtils.java
/** * Determines whether the element is of the enum type or not. * * @param element the element to check.//from ww w . j av a 2 s .c om * @return true if the element inherits from an enum, false otherwise. */ public static boolean isEnum(@Nullable TypeElement element) { TypeMirror typeMirror = element != null ? element.getSuperclass() : null; String className = typeMirror != null ? getClassNameFromTypeMirror(typeMirror) : null; return Enum.class.getName().equals(className); }
From source file:com.vimeo.stag.processor.utils.TypeUtils.java
/** * Gets the inherited type from the element. If * the inherited type is {@link Object} or {@link Enum}, * then this method will return null./*from w w w . j a va 2 s . co m*/ * * @param element the element to get the inherited type. * @return the inherited type, or null if the element * inherits from Object or Enum. */ @Nullable public static TypeMirror getInheritedType(@Nullable TypeElement element) { TypeMirror typeMirror = element != null ? element.getSuperclass() : null; String className = typeMirror != null ? getClassNameFromTypeMirror(typeMirror) : null; if (!Object.class.getName().equals(className) && !Enum.class.getName().equals(className)) { return typeMirror; } return null; }
From source file:auto.parse.processor.AutoParseProcessor.java
private static boolean isJavaLangObject(TypeElement type) { return type.getSuperclass().getKind() == TypeKind.NONE && type.getKind() == ElementKind.CLASS; }
From source file:org.leandreck.endpoints.processor.model.EndpointNodeFactory.java
private List<MethodNode> defineMethods(final TypeElement typeElement, final DeclaredType containingType) { final TypeMirror superclass = typeElement.getSuperclass(); final List<MethodNode> superclassMethods; if (DECLARED.equals(superclass.getKind()) && !"java.lang.Object".equals(superclass.toString())) { superclassMethods = defineMethods((TypeElement) ((DeclaredType) superclass).asElement(), containingType);/*from w ww . j ava 2 s .c o m*/ } else { superclassMethods = new ArrayList<>(20); } //Implemented Interfaces: typeElement.getInterfaces().stream() .flatMap( it -> defineMethods((TypeElement) ((DeclaredType) it).asElement(), containingType).stream()) .forEach(superclassMethods::add); //Own enclosed Methods ElementFilter.methodsIn(typeElement.getEnclosedElements()).stream() .map(methodElement -> methodNodeFactory.createMethodNode(methodElement, containingType)) .filter(method -> !method.isIgnored()).forEach(superclassMethods::add); return superclassMethods; }
From source file:blue.lapis.pore.ap.event.EventVerifierProcessor.java
private void verifyName(TypeElement type) { TypeElement bukkitEvent = (TypeElement) ((DeclaredType) type.getSuperclass()).asElement(); String poreName = StringUtils.removeStart(type.getQualifiedName().toString(), PORE_PREFIX); String porePackage = StringUtils.substringBeforeLast(poreName, "."); poreName = StringUtils.substringAfterLast(poreName, "."); String bukkitName = StringUtils.removeStart(bukkitEvent.getQualifiedName().toString(), BUKKIT_PREFIX); String bukkitPackage = StringUtils.substringBeforeLast(bukkitName, "."); bukkitName = StringUtils.substringAfterLast(bukkitName, "."); String expectedName = "Pore" + bukkitName; if (!poreName.equals(expectedName)) { processingEnv.getMessager().printMessage(SEVERITY, poreName + " should be called " + expectedName, type);/*from www . j a v a 2 s . c om*/ } if (!porePackage.equals(bukkitPackage)) { processingEnv.getMessager().printMessage(SEVERITY, poreName + " is in wrong package: should be in " + PORE_PREFIX + bukkitPackage, type); } }
From source file:easymvp.compiler.EasyMVPProcessor.java
private TypeElement getSuperClass(TypeElement typeElement) { if (!(typeElement.getSuperclass() instanceof DeclaredType)) return null; DeclaredType declaredAncestor = (DeclaredType) typeElement.getSuperclass(); return (TypeElement) declaredAncestor.asElement(); }
From source file:net.pkhsolutions.ceres.common.builder.processor.BuildableAP.java
private Collection<VariableElement> getFields(TypeElement type) { final Set<Element> elements = new HashSet<Element>(); elements.addAll(type.getEnclosedElements()); TypeMirror supertype = type.getSuperclass(); while (supertype.getKind() != TypeKind.NONE) { final TypeElement element = (TypeElement) processingEnv.getTypeUtils().asElement(supertype); elements.addAll(element.getEnclosedElements()); supertype = element.getSuperclass(); }//from w w w . j a v a 2 s.c o m return ElementFilter.fieldsIn(elements); }
From source file:easymvp.compiler.EasyMVPProcessor.java
private String findViewTypeOfPresenter(TypeElement presenterElement) { TypeElement currentClass = presenterElement; while (currentClass != null) { if (currentClass.getSuperclass() instanceof DeclaredType) { List<? extends TypeMirror> superClassParameters = ((DeclaredType) currentClass.getSuperclass()) .getTypeArguments(); if (superClassParameters.size() == 1) { String type = superClassParameters.get(0).toString(); if (!"V".equals(type)) return type; }//ww w . ja va 2 s . c o m } currentClass = getSuperClass(currentClass); } return ""; }
From source file:com.contentful.vault.compiler.Processor.java
private boolean isSubtypeOfType(TypeMirror typeMirror, String otherType) { if (otherType.equals(typeMirror.toString())) { return true; }//from ww w . j av a 2 s .com if (!(typeMirror instanceof DeclaredType)) { return false; } DeclaredType declaredType = (DeclaredType) typeMirror; 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++) { if (i > 0) { typeString.append(','); } typeString.append('?'); } typeString.append('>'); if (typeString.toString().equals(otherType)) { return true; } } Element element = declaredType.asElement(); if (!(element instanceof TypeElement)) { return false; } TypeElement typeElement = (TypeElement) element; TypeMirror superType = typeElement.getSuperclass(); if (isSubtypeOfType(superType, otherType)) { return true; } for (TypeMirror interfaceType : typeElement.getInterfaces()) { if (isSubtypeOfType(interfaceType, otherType)) { return true; } } return false; }