Java Code Examples for javax.lang.model.type.TypeKind#NONE
The following examples show how to use
javax.lang.model.type.TypeKind#NONE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityMetaFactory.java From doma with Apache License 2.0 | 6 votes |
List<VariableElement> getFieldElements(TypeElement classElement) { List<VariableElement> results = new LinkedList<>(); for (TypeElement t = classElement; t != null && t.asType().getKind() != TypeKind.NONE; t = ctx.getMoreTypes().toTypeElement(t.getSuperclass())) { if (t.getAnnotation(Entity.class) == null) { continue; } List<VariableElement> fields = new LinkedList<>(ElementFilter.fieldsIn(t.getEnclosedElements())); Collections.reverse(fields); results.addAll(fields); } Collections.reverse(results); List<VariableElement> hiderFields = new LinkedList<>(results); for (Iterator<VariableElement> it = results.iterator(); it.hasNext(); ) { VariableElement hidden = it.next(); for (VariableElement hider : hiderFields) { if (ctx.getMoreElements().hides(hider, hidden)) { it.remove(); } } } return results; }
Example 2
Source File: TypeAnnotations.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private void locateNestedTypes(Type type, TypeAnnotationPosition p) { // The number of "steps" to get from the full type to the // left-most outer type. ListBuffer<TypePathEntry> depth = new ListBuffer<>(); Type encl = type.getEnclosingType(); while (encl != null && encl.getKind() != TypeKind.NONE && encl.getKind() != TypeKind.ERROR) { depth = depth.append(TypePathEntry.INNER_TYPE); encl = encl.getEnclosingType(); } if (depth.nonEmpty()) { p.location = p.location.prependList(depth.toList()); } }
Example 3
Source File: EmbeddableMetaFactory.java From doma with Apache License 2.0 | 6 votes |
List<VariableElement> getFieldElements(TypeElement embeddableElement) { List<VariableElement> results = new LinkedList<>(); for (TypeElement t = embeddableElement; t != null && t.asType().getKind() != TypeKind.NONE; t = ctx.getMoreTypes().toTypeElement(t.getSuperclass())) { if (t.getAnnotation(Embeddable.class) == null) { continue; } List<VariableElement> fields = new LinkedList<>(ElementFilter.fieldsIn(t.getEnclosedElements())); Collections.reverse(fields); results.addAll(fields); } Collections.reverse(results); List<VariableElement> hiderFields = new LinkedList<>(results); for (Iterator<VariableElement> it = results.iterator(); it.hasNext(); ) { VariableElement hidden = it.next(); for (VariableElement hider : hiderFields) { if (ctx.getMoreElements().hides(hider, hidden)) { it.remove(); } } } return results; }
Example 4
Source File: TypeAnnotations.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private void locateNestedTypes(Type type, TypeAnnotationPosition p) { // The number of "steps" to get from the full type to the // left-most outer type. ListBuffer<TypePathEntry> depth = new ListBuffer<>(); Type encl = type.getEnclosingType(); while (encl != null && encl.getKind() != TypeKind.NONE && encl.getKind() != TypeKind.ERROR) { depth = depth.append(TypePathEntry.INNER_TYPE); encl = encl.getEnclosingType(); } if (depth.nonEmpty()) { p.location = p.location.prependList(depth.toList()); } }
Example 5
Source File: ChangeMethodReturnType.java From netbeans with Apache License 2.0 | 5 votes |
private TypeMirror purify(CompilationInfo info, TypeMirror targetType) { if (targetType != null && targetType.getKind() == TypeKind.ERROR) { targetType = info.getTrees().getOriginalType((ErrorType) targetType); } if (targetType == null || targetType.getKind() == /*XXX:*/TypeKind.ERROR || targetType.getKind() == TypeKind.NONE || targetType.getKind() == TypeKind.NULL) return null; return Utilities.resolveTypeForDeclaration(info, targetType); }
Example 6
Source File: RetroFacebookProcessor.java From RetroFacebook with Apache License 2.0 | 5 votes |
private boolean ancestorIsRetroFacebook(TypeElement type) { while (true) { TypeMirror parentMirror = type.getSuperclass(); if (parentMirror.getKind() == TypeKind.NONE) { return false; } Types typeUtils = processingEnv.getTypeUtils(); TypeElement parentElement = (TypeElement) typeUtils.asElement(parentMirror); if (parentElement.getAnnotation(RetroFacebook.class) != null) { return true; } type = parentElement; } }
Example 7
Source File: ModelNode.java From featured with Apache License 2.0 | 5 votes |
public void detectInheritance(ProcessingEnvironment env) { Collection<FeatureNode> featureNodes = getFeatureNodes(); for (FeatureNode featureNode : featureNodes) { // feature has inheriting features if it is parametrized with generics List<? extends TypeParameterElement> typeParams = featureNode.getElement().getTypeParameters(); if (typeParams.size() > 0) { featureNode.setHasInheritingFeatureNodes(true); continue; } // look up for super-features within collected nodes TypeMirror superType = featureNode.getElement().getSuperclass(); while (superType.getKind() != TypeKind.NONE) { for (FeatureNode otherFeatureNode : featureNodes) { if (featureNode == otherFeatureNode) { continue; } Name otherName = otherFeatureNode.getElement().getQualifiedName(); Name superName = ((TypeElement) env.getTypeUtils() .asElement(superType)).getQualifiedName(); if (otherName.equals(superName)) { featureNode.setSuperFeatureNode(otherFeatureNode); break; } } superType = ((TypeElement) env.getTypeUtils().asElement(superType)).getSuperclass(); } } }
Example 8
Source File: AbstractTestGenerator.java From netbeans with Apache License 2.0 | 5 votes |
/** * Checks whether the given type object represents type * {@code java.lang.Object}. * * @param type type to be checked * @return {@code true} if the passed type object represents type * {@code java.lang.Object}, {@code false} otherwise */ private static boolean isRootObjectType(DeclaredType type) { if (type.getKind() != TypeKind.DECLARED) { return false; } TypeElement elem = (TypeElement) type.asElement(); return (elem.getKind() == ElementKind.CLASS) && (elem.getSuperclass().getKind() == TypeKind.NONE); }
Example 9
Source File: LightCycleProcessor.java From lightcycle with Apache License 2.0 | 5 votes |
private LightCycleBinder findParent(Set<String> erasedTargetNames, TypeMirror type) { if (type.getKind() == TypeKind.NONE) { return LightCycleBinder.EMPTY; } final TypeElement typeElement = (TypeElement) ((DeclaredType) type).asElement(); if (erasedTargetNames.contains(typeElement.toString())) { final String parentWithLightCycle = elementUtils.getBinaryName(typeElement).toString(); return LightCycleBinder.forParent(binderName(parentWithLightCycle)); } return findParent(erasedTargetNames, typeElement.getSuperclass()); }
Example 10
Source File: ComponentDescriptor.java From dagger2-sample with Apache License 2.0 | 5 votes |
private static void findLocalAndInheritedMethods(Elements elements, TypeElement type, List<ExecutableElement> methods) { for (TypeMirror superInterface : type.getInterfaces()) { findLocalAndInheritedMethods( elements, MoreElements.asType(MoreTypes.asElement(superInterface)), methods); } if (type.getSuperclass().getKind() != TypeKind.NONE) { // Visit the superclass after superinterfaces so we will always see the implementation of a // method after any interfaces that declared it. findLocalAndInheritedMethods( elements, MoreElements.asType(MoreTypes.asElement(type.getSuperclass())), methods); } // Add each method of this class, and in so doing remove any inherited method it overrides. // This algorithm is quadratic in the number of methods but it's hard to see how to improve // that while still using Elements.overrides. List<ExecutableElement> theseMethods = ElementFilter.methodsIn(type.getEnclosedElements()); for (ExecutableElement method : theseMethods) { if (!method.getModifiers().contains(Modifier.PRIVATE)) { boolean alreadySeen = false; for (Iterator<ExecutableElement> methodIter = methods.iterator(); methodIter.hasNext();) { ExecutableElement otherMethod = methodIter.next(); if (elements.overrides(method, otherMethod, type)) { methodIter.remove(); } else if (method.getSimpleName().equals(otherMethod.getSimpleName()) && method.getParameters().equals(otherMethod.getParameters())) { // If we inherit this method on more than one path, we don't want to add it twice. alreadySeen = true; } } if (!alreadySeen) { methods.add(method); } } } }
Example 11
Source File: JavaBeanAttributesCollector.java From immutables with Apache License 2.0 | 5 votes |
/** * For some reason {@link Elements#getAllMembers(TypeElement)} does not * return fields from parent class. Collecting them manually in this method. */ private <C extends Collection<VariableElement>> C collectFields(@Nullable Element element, C collection) { if (element == null || !element.getKind().isClass() || element.getKind() == ElementKind.ENUM) { return collection; } collection.addAll(ElementFilter.fieldsIn(element.getEnclosedElements())); TypeMirror parent = MoreElements.asType(element).getSuperclass(); if (parent.getKind() != TypeKind.NONE) { collectFields(MoreTypes.asDeclared(parent).asElement(), collection); } return collection; }
Example 12
Source File: Type.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
@Override public TypeKind getKind() { switch (tag) { case VOID: return TypeKind.VOID; case NONE: return TypeKind.NONE; default: throw new AssertionError("Unexpected tag: " + tag); } }
Example 13
Source File: MoreElements.java From auto with Apache License 2.0 | 5 votes |
private static void getAllMethods( TypeElement type, SetMultimap<String, ExecutableElement> methods) { for (TypeMirror superInterface : type.getInterfaces()) { getAllMethods(MoreTypes.asTypeElement(superInterface), methods); } if (type.getSuperclass().getKind() != TypeKind.NONE) { // Visit the superclass after superinterfaces so we will always see the implementation of a // method after any interfaces that declared it. getAllMethods(MoreTypes.asTypeElement(type.getSuperclass()), methods); } for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) { methods.put(method.getSimpleName().toString(), method); } }
Example 14
Source File: MountSpecModelFactory.java From litho with Apache License 2.0 | 4 votes |
private static TypeName getMountType( Elements elements, TypeElement element, EnumSet<RunMode> runMode) { TypeElement viewType = elements.getTypeElement(ClassNames.VIEW_NAME); TypeElement drawableType = elements.getTypeElement(ClassNames.DRAWABLE_NAME); for (Element enclosedElement : element.getEnclosedElements()) { if (enclosedElement.getKind() != ElementKind.METHOD) { continue; } OnCreateMountContent annotation = enclosedElement.getAnnotation(OnCreateMountContent.class); if (annotation != null) { if (annotation.mountingType() == MountingType.VIEW) { return ClassNames.COMPONENT_LIFECYCLE_MOUNT_TYPE_VIEW; } if (annotation.mountingType() == MountingType.DRAWABLE) { return ClassNames.COMPONENT_LIFECYCLE_MOUNT_TYPE_DRAWABLE; } TypeMirror initialReturnType = ((ExecutableElement) enclosedElement).getReturnType(); if (runMode.contains(RunMode.ABI)) { // We can't access the supertypes of the return type, so let's guess, and we'll verify // that our guess was correct when we do a full build later. if (initialReturnType.toString().contains("Drawable")) { return ClassNames.COMPONENT_LIFECYCLE_MOUNT_TYPE_DRAWABLE; } else { return ClassNames.COMPONENT_LIFECYCLE_MOUNT_TYPE_VIEW; } } TypeMirror returnType = initialReturnType; while (returnType.getKind() != TypeKind.NONE && returnType.getKind() != TypeKind.VOID) { final TypeElement returnElement = (TypeElement) ((DeclaredType) returnType).asElement(); if (returnElement.equals(viewType)) { if (initialReturnType.toString().contains("Drawable")) { throw new ComponentsProcessingException( "Mount type cannot be correctly inferred from the name of " + element + ". Please specify `@OnCreateMountContent(mountingType = MountingType.VIEW)`."); } return ClassNames.COMPONENT_LIFECYCLE_MOUNT_TYPE_VIEW; } else if (returnElement.equals(drawableType)) { if (!initialReturnType.toString().contains("Drawable")) { throw new ComponentsProcessingException( "Mount type cannot be correctly inferred from the name of " + element + ". Please specify `@OnCreateMountContent(mountingType = MountingType.DRAWABLE)`."); } return ClassNames.COMPONENT_LIFECYCLE_MOUNT_TYPE_DRAWABLE; } try { returnType = returnElement.getSuperclass(); } catch (RuntimeException e) { throw new ComponentsProcessingException( "Failed to get mount type for " + element + ". Try specifying `@OnCreateMountContent(mountingType = MountingType.VIEW)` (or DRAWABLE)."); } } } } return ClassNames.COMPONENT_LIFECYCLE_MOUNT_TYPE_NONE; }
Example 15
Source File: Environment.java From sqlitemagic with Apache License 2.0 | 4 votes |
public boolean isJavaBaseObject(TypeMirror type) { return typeUtils.isSameType(type, Const.OBJECT_TYPE) || type.getKind() == TypeKind.NONE; }
Example 16
Source File: InternalDomainMetaFactory.java From doma with Apache License 2.0 | 4 votes |
@Override public void validateAccessorMethod(TypeElement classElement, InternalDomainMeta domainMeta) { TypeElement typeElement = classElement; TypeMirror typeMirror = classElement.asType(); for (; typeElement != null && typeMirror.getKind() != TypeKind.NONE; ) { for (ExecutableElement method : ElementFilter.methodsIn(typeElement.getEnclosedElements())) { if (!method.getSimpleName().contentEquals(domainMeta.getAccessorMethod())) { continue; } if (method.getModifiers().contains(Modifier.PRIVATE)) { continue; } if (!method.getParameters().isEmpty()) { continue; } TypeMirror returnType = method.getReturnType(); if (ctx.getMoreTypes() .isAssignableWithErasure( ctx.getMoreTypes().erasure(returnType), domainMeta.getValueType())) { return; } TypeVariable typeVariable = ctx.getMoreTypes().toTypeVariable(returnType); if (typeVariable != null) { TypeMirror inferredReturnType = inferType(typeVariable, typeElement, typeMirror); if (inferredReturnType != null) { if (ctx.getMoreTypes() .isAssignableWithErasure(inferredReturnType, domainMeta.getValueType())) { return; } } } } typeMirror = typeElement.getSuperclass(); typeElement = ctx.getMoreTypes().toTypeElement(typeMirror); } throw new AptException( Message.DOMA4104, classElement, new Object[] {domainMeta.getAccessorMethod(), domainMeta.getValueType()}); }
Example 17
Source File: TypeDeclaration.java From doma with Apache License 2.0 | 4 votes |
public boolean isUnknownType() { return type.getKind() == TypeKind.NONE; }
Example 18
Source File: RetroFacebookProcessor.java From RetroFacebook with Apache License 2.0 | 4 votes |
private void findLocalAndInheritedMethods(TypeElement type, List<ExecutableElement> methods) { Types typeUtils = processingEnv.getTypeUtils(); Elements elementUtils = processingEnv.getElementUtils(); for (TypeMirror superInterface : type.getInterfaces()) { findLocalAndInheritedMethods((TypeElement) typeUtils.asElement(superInterface), methods); } if (type.getSuperclass().getKind() != TypeKind.NONE) { // Visit the superclass after superinterfaces so we will always see the implementation of a // method after any interfaces that declared it. findLocalAndInheritedMethods( (TypeElement) typeUtils.asElement(type.getSuperclass()), methods); } // Add each method of this class, and in so doing remove any inherited method it overrides. // This algorithm is quadratic in the number of methods but it's hard to see how to improve // that while still using Elements.overrides. List<ExecutableElement> theseMethods = ElementFilter.methodsIn(type.getEnclosedElements()); for (ExecutableElement method : theseMethods) { if (!method.getModifiers().contains(Modifier.PRIVATE)) { boolean alreadySeen = false; for (Iterator<ExecutableElement> methodIter = methods.iterator(); methodIter.hasNext(); ) { ExecutableElement otherMethod = methodIter.next(); if (elementUtils.overrides(method, otherMethod, type)) { methodIter.remove(); } else if (method.getSimpleName().equals(otherMethod.getSimpleName()) && method.getParameters().equals(otherMethod.getParameters())) { // If we inherit this method on more than one path, we don't want to add it twice. alreadySeen = true; } } if (!alreadySeen) { /* retrofacebook.RetroFacebook.GET action = method.getAnnotation(retrofacebook.RetroFacebook.GET.class); System.out.printf( "%s Action value = %s\n", method.getSimpleName(), action == null ? null : action.value() ); */ methods.add(method); } } } }
Example 19
Source File: J2clAstProcessor.java From j2cl with Apache License 2.0 | 4 votes |
private static boolean isVisitable(TypeMirror typeMirror) { return typeMirror != null && typeMirror.getKind() != TypeKind.NONE && MoreTypes.asElement(typeMirror).getAnnotationsByType(Visitable.class).length != 0; }
Example 20
Source File: NodeIntrinsicVerifier.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static boolean needsErasure(TypeMirror typeMirror) { return typeMirror.getKind() != TypeKind.NONE && typeMirror.getKind() != TypeKind.VOID && !typeMirror.getKind().isPrimitive() && typeMirror.getKind() != TypeKind.OTHER && typeMirror.getKind() != TypeKind.NULL; }