List of usage examples for javax.lang.model.type TypeKind NONE
TypeKind NONE
To view the source code for javax.lang.model.type TypeKind NONE.
Click Source Link
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 .jav a2 s. c o m return ElementFilter.fieldsIn(elements); }
From source file:co.touchlab.squeaky.processor.AnnotationProcessor.java
private boolean processTableViewQuery(List<DatabaseTableHolder> tableHolders, Element annotatedElement, EntityType entityType) {// w w w . j av a 2 s .c o m TypeElement typeElement = (TypeElement) annotatedElement; String fromString; switch (entityType) { case Table: case View: fromString = extractTableName(typeElement); break; case Query: fromString = "(" + typeElement.getAnnotation(DatabaseQuery.class).fromQuery() + ")"; break; default: throw new RuntimeException("No type (this will NEVER happen)"); } List<FieldTypeGen> fieldTypeGens = new ArrayList<FieldTypeGen>(); List<ForeignCollectionHolder> foreignCollectionInfos = new ArrayList<ForeignCollectionHolder>(); // walk up the classes finding the fields TypeElement working = typeElement; while (working != null) { for (Element element : working.getEnclosedElements()) { if (element.getKind().isField()) { if (element.getAnnotation(DatabaseField.class) != null) { FieldTypeGen fieldTypeGen = new FieldTypeGen(annotatedElement, element, typeUtils, messager); fieldTypeGens.add(fieldTypeGen); } else if (element.getAnnotation(ForeignCollectionField.class) != null) { ForeignCollectionField foreignCollectionField = element .getAnnotation(ForeignCollectionField.class); foreignCollectionInfos.add(new ForeignCollectionHolder(foreignCollectionField, (VariableElement) element, messager)); } } } if (working.getSuperclass().getKind().equals(TypeKind.NONE)) { break; } working = (TypeElement) typeUtils.asElement(working.getSuperclass()); } if (fieldTypeGens.isEmpty()) { error(typeElement, "Every class annnotated with %s, %s, or %s must have at least 1 field annotated with %s", DatabaseTable.class.getSimpleName(), DatabaseView.class.getSimpleName(), DatabaseQuery.class.getSimpleName(), DatabaseField.class.getSimpleName()); return true; } List<FieldTypeGen> testFields = fieldTypeGens; List<FieldTypeGen> finalFields = new ArrayList<FieldTypeGen>(); for (FieldTypeGen testField : testFields) { if (testField.finalField) finalFields.add(testField); } ExecutableElement finalConstructor = null; if (!finalFields.isEmpty()) { List<ExecutableElement> executableElements = ElementFilter .constructorsIn(annotatedElement.getEnclosedElements()); for (ExecutableElement executableElement : executableElements) { List<FieldTypeGen> finalFieldsCheck = new ArrayList<FieldTypeGen>(finalFields); List<? extends VariableElement> parameters = executableElement.getParameters(); for (VariableElement parameter : parameters) { String fieldName = parameter.getSimpleName().toString(); String fieldClassname = DataTypeManager.findFieldClassname(parameter); Iterator<FieldTypeGen> iterator = finalFieldsCheck.iterator(); boolean found = false; while (iterator.hasNext()) { FieldTypeGen next = iterator.next(); if (next.fieldName.equals(fieldName) && next.dataTypeClassname.equals(fieldClassname)) { found = true; iterator.remove(); } } if (!found) break; } if (finalFieldsCheck.isEmpty()) { finalConstructor = executableElement; break; } } if (finalConstructor == null) { List<String> allFinals = new ArrayList<String>(); for (FieldTypeGen finalField : finalFields) { allFinals.add(finalField.fieldName); } error(annotatedElement, "Final fields need to be set in constructor %s", StringUtils.join(allFinals, ",")); return true; } } DatabaseTableHolder tableHolder = new DatabaseTableHolder(annotatedElement, fieldTypeGens, foreignCollectionInfos, typeElement, fromString, finalFields, finalConstructor, entityType); tableHolders.add(tableHolder); return false; }
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:auto.parse.processor.AutoParseProcessor.java
private void findLocalAndInheritedMethods(TypeElement type, List<ExecutableElement> methods) { note("Looking at methods in " + type); Types typeUtils = processingEnv.getTypeUtils(); Elements elementUtils = processingEnv.getElementUtils(); for (TypeMirror superInterface : type.getInterfaces()) { findLocalAndInheritedMethods((TypeElement) typeUtils.asElement(superInterface), methods); }/*from w w w . j a v a 2 s. c o m*/ 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()); eclipseHack().sortMethodsIfSimulatingEclipse(theseMethods); 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) { methods.add(method); } } } }
From source file:auto.parse.processor.AutoParseProcessor.java
private boolean ancestorIsAndroidAutoParse(TypeElement type) { while (true) { TypeMirror parentMirror = type.getSuperclass(); if (parentMirror.getKind() == TypeKind.NONE) { return false; }//from w w w . j a v a2 s .c o m Types typeUtils = processingEnv.getTypeUtils(); TypeElement parentElement = (TypeElement) typeUtils.asElement(parentMirror); if (parentElement.getAnnotation(AutoParse.class) != null) { return true; } type = parentElement; } }