List of usage examples for javax.lang.model.element TypeElement getSuperclass
TypeMirror getSuperclass();
From source file:com.predic8.membrane.annot.SpringConfigurationXSDGeneratingAnnotationProcessor.java
private void scan(Model m, MainInfo main, ElementInfo ii, TypeElement te) { TypeMirror superclass = te.getSuperclass(); if (superclass instanceof DeclaredType) scan(m, main, ii, (TypeElement) ((DeclaredType) superclass).asElement()); for (Element e2 : te.getEnclosedElements()) { MCAttribute a = e2.getAnnotation(MCAttribute.class); if (a != null) { AttributeInfo ai = new AttributeInfo(); ai.setAnnotation(a);/*from w w w. j ava2 s. co m*/ ai.setE((ExecutableElement) e2); ai.setRequired(isRequired(e2)); ii.getAis().add(ai); ii.setHasIdField(ii.isHasIdField() || ai.getXMLName().equals("id")); } MCOtherAttributes d = e2.getAnnotation(MCOtherAttributes.class); if (d != null) { OtherAttributesInfo oai = new OtherAttributesInfo(); oai.setOtherAttributesSetter((ExecutableElement) e2); ii.setOai(oai); } MCChildElement b = e2.getAnnotation(MCChildElement.class); if (b != null) { ChildElementInfo cei = new ChildElementInfo(); cei.setEi(ii); cei.setAnnotation(b); cei.setE((ExecutableElement) e2); TypeMirror setterArgType = cei.getE().getParameters().get(0).asType(); if (!(setterArgType instanceof DeclaredType)) throw new ProcessingException("Setter argument must be of an @MCElement-annotated type.", cei.getE().getParameters().get(0)); cei.setTypeDeclaration((TypeElement) ((DeclaredType) setterArgType).asElement()); cei.setPropertyName(AnnotUtils.dejavaify(e2.getSimpleName().toString().substring(3))); cei.setRequired(isRequired(e2)); ii.getCeis().add(cei); // unwrap "java.util.List<?>" and "java.util.Collection<?>" if (cei.getTypeDeclaration().getQualifiedName().toString().startsWith("java.util.List") || cei .getTypeDeclaration().getQualifiedName().toString().startsWith("java.util.Collection")) { cei.setTypeDeclaration( (TypeElement) ((DeclaredType) ((DeclaredType) setterArgType).getTypeArguments().get(0)) .asElement()); cei.setList(true); } ChildElementDeclarationInfo cedi; if (!main.getChildElementDeclarations().containsKey(cei.getTypeDeclaration())) { cedi = new ChildElementDeclarationInfo(); cedi.setTarget(cei.getTypeDeclaration()); cedi.setRaiseErrorWhenNoSpecimen(!cei.getAnnotation().allowForeign()); main.getChildElementDeclarations().put(cei.getTypeDeclaration(), cedi); } else { cedi = main.getChildElementDeclarations().get(cei.getTypeDeclaration()); cedi.setRaiseErrorWhenNoSpecimen( cedi.isRaiseErrorWhenNoSpecimen() || !cei.getAnnotation().allowForeign()); } cedi.addUsedBy(cei); } MCTextContent c = e2.getAnnotation(MCTextContent.class); if (c != null) { TextContentInfo tci = new TextContentInfo(); tci.setPropertyName(AnnotUtils.dejavaify(e2.getSimpleName().toString().substring(3))); ii.setTci(tci); } } HashSet<Integer> childOrders = new HashSet<Integer>(); for (ChildElementInfo cei : ii.getCeis()) { if (!childOrders.add(cei.getAnnotation().order())) throw new ProcessingException("@MCChildElement(order=...) must be unique.", cei.getE()); } Collections.sort(ii.getCeis()); }
From source file:org.kie.workbench.common.forms.adf.processors.FormDefinitionGenerator.java
private TypeElement getParent(TypeElement classElement) { return (TypeElement) context.getProcessingEnvironment().getTypeUtils() .asElement(classElement.getSuperclass()); }
From source file:org.kie.workbench.common.forms.adf.processors.FormDefinitionsProcessor.java
private TypeElement getParent(TypeElement classElement) { return (TypeElement) processingEnv.getTypeUtils().asElement(classElement.getSuperclass()); }
From source file:org.androidtransfuse.adapter.element.ASTElementFactory.java
private ASTType buildType(TypeElement typeElement) { log.debug("ASTElementType building: " + typeElement.getQualifiedName()); //build placeholder for ASTElementType and contained data structures to allow for children population //while avoiding back link loops PackageClass packageClass = buildPackageClass(typeElement); if (blacklist.containsKey(packageClass)) { return blacklist.get(packageClass); }//from ww w. j a v a 2s .co m ASTTypeVirtualProxy astTypeProxy = new ASTTypeVirtualProxy(packageClass); typeCache.put(typeElement, astTypeProxy); ASTType superClass = null; if (typeElement.getSuperclass() != null) { superClass = typeElement.getSuperclass().accept(astTypeBuilderVisitor, null); } ImmutableSet<ASTType> interfaces = FluentIterable.from(typeElement.getInterfaces()) .transform(astTypeBuilderVisitor).toSet(); ImmutableSet.Builder<ASTAnnotation> annotations = ImmutableSet.builder(); ImmutableSet.Builder<ASTConstructor> constructors = ImmutableSet.builder(); ImmutableSet.Builder<ASTField> fields = ImmutableSet.builder(); ImmutableSet.Builder<ASTMethod> methods = ImmutableSet.builder(); //iterate and build the contained elements within this TypeElement annotations.addAll(getAnnotations(typeElement)); constructors.addAll(transformAST(typeElement.getEnclosedElements(), ASTConstructor.class)); fields.addAll(transformAST(typeElement.getEnclosedElements(), ASTField.class)); methods.addAll(transformAST(typeElement.getEnclosedElements(), ASTMethod.class)); ASTType astType = new ASTElementType(buildAccessModifier(typeElement), packageClass, typeElement, constructors.build(), methods.build(), fields.build(), superClass, interfaces, annotations.build()); astTypeProxy.load(astType); return astType; }
From source file:org.mule.module.extension.internal.capability.xml.schema.SchemaDocumenter.java
private void documentConfigurationParameters(Collection<ParameterDeclaration> parameters, final TypeElement element) { final Map<String, VariableElement> variableElements = getFieldsAnnotatedWith(element, Parameter.class); TypeElement traversingElement = element; while (traversingElement != null && !Object.class.getName().equals(traversingElement.getQualifiedName().toString())) { Class<?> declaringClass = AnnotationProcessorUtils.classFor(traversingElement, processingEnv); for (ParameterDeclaration parameter : parameters) { Field field = IntrospectionUtils.getField(declaringClass, parameter); if (field != null && variableElements.containsKey(field.getName())) { parameter.setDescription( getJavaDocSummary(processingEnv, variableElements.get(field.getName()))); }/*from w ww. j av a2s . co m*/ } traversingElement = (TypeElement) processingEnv.getTypeUtils() .asElement(traversingElement.getSuperclass()); } for (VariableElement variableElement : getFieldsAnnotatedWith(element, ParameterGroup.class).values()) { TypeElement typeElement = (TypeElement) processingEnv.getTypeUtils() .asElement(variableElement.asType()); documentConfigurationParameters(parameters, typeElement); } }
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; }/* w ww . j a va 2 s . c o m*/ Types typeUtils = processingEnv.getTypeUtils(); TypeElement parentElement = (TypeElement) typeUtils.asElement(parentMirror); if (parentElement.getAnnotation(AutoParse.class) != null) { return true; } type = parentElement; } }
From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java
private TypeElement getParent(final TypeElement classElement) { return (TypeElement) processingEnv.getTypeUtils().asElement(classElement.getSuperclass()); }
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 . ja va 2s .c om*/ 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:co.touchlab.squeaky.processor.AnnotationProcessor.java
private boolean processTableViewQuery(List<DatabaseTableHolder> tableHolders, Element annotatedElement, EntityType entityType) {/*from ww w .j a v a 2s.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; }