List of usage examples for javax.lang.model.element TypeElement getQualifiedName
Name getQualifiedName();
From source file:com.contentful.vault.compiler.Processor.java
private void parseSpace(TypeElement element, Map<TypeElement, SpaceInjection> spaces, Map<TypeElement, ModelInjection> models) { Space annotation = element.getAnnotation(Space.class); String id = annotation.value(); if (id.isEmpty()) { error(element, "@%s id may not be empty. (%s)", Space.class.getSimpleName(), element.getQualifiedName()); return;//from w ww.j a v a 2 s . c o m } TypeMirror spaceMirror = elementUtils.getTypeElement(Space.class.getName()).asType(); List<ModelInjection> includedModels = new ArrayList<>(); for (AnnotationMirror mirror : element.getAnnotationMirrors()) { if (typeUtils.isSameType(mirror.getAnnotationType(), spaceMirror)) { Set<? extends Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>> items = mirror .getElementValues().entrySet(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : items) { if ("models".equals(entry.getKey().getSimpleName().toString())) { List l = (List) entry.getValue().getValue(); if (l.size() == 0) { error(element, "@%s models must not be empty. (%s)", Space.class.getSimpleName(), element.getQualifiedName()); return; } Set<String> modelIds = new LinkedHashSet<>(); for (Object model : l) { TypeElement e = (TypeElement) ((Type) ((Attribute) model).getValue()).asElement(); ModelInjection modelInjection = models.get(e); if (modelInjection == null) { return; } else { String rid = modelInjection.remoteId; if (!modelIds.add(rid)) { error(element, "@%s includes multiple models with the same id \"%s\". (%s)", Space.class.getSimpleName(), rid, element.getQualifiedName()); return; } includedModels.add(modelInjection); } } } } } } List<String> locales = Arrays.asList(annotation.locales()); Set<String> checked = new HashSet<>(); for (int i = locales.size() - 1; i >= 0; i--) { String code = locales.get(i); if (!checked.add(code)) { error(element, "@%s contains duplicate locale code '%s'. (%s)", Space.class.getSimpleName(), code, element.getQualifiedName()); return; } else if (code.contains(" ") || code.isEmpty()) { error(element, "Invalid locale code '%s', must not be empty and may not contain spaces. (%s)", code, element.getQualifiedName()); return; } } if (checked.size() == 0) { error(element, "@%s at least one locale must be configured. (%s)", Space.class.getSimpleName(), element.getQualifiedName()); return; } ClassName injectionClassName = getInjectionClassName(element, SUFFIX_SPACE); String dbName = "space_" + SqliteUtils.hashForId(id); String copyPath = StringUtils.defaultIfBlank(annotation.copyPath(), null); spaces.put(element, new SpaceInjection(id, injectionClassName, element, includedModels, dbName, annotation.dbVersion(), copyPath, locales)); }
From source file:org.kie.workbench.common.forms.adf.processors.FormDefinitionGenerator.java
protected void processFormDefinition(TypeElement formElement) throws Exception { final Messager messager = context.getMessager(); messager.printMessage(Diagnostic.Kind.NOTE, "Discovered FormDefintion class [" + formElement.getSimpleName() + "]"); boolean checkInheritance = false; FormDefinition definition = formElement.getAnnotation(FormDefinition.class); String modelClassName = formElement.getQualifiedName().toString(); String builderClassName = FormGenerationUtils.fixClassName(formElement.getQualifiedName().toString()) + FORM_BUILDER_SUFFIX;/*from ww w . ja v a 2s . c om*/ FormDefinitionData form = new FormDefinitionData(modelClassName, builderClassName); form.setStartElement(definition.startElement()); form.setI18nBundle(StringUtils.isEmpty(definition.i18n().bundle()) ? formElement.asType().toString() : definition.i18n().bundle()); Column[] columns = definition.layout().value(); List<String> layoutColumns = new ArrayList<>(); if (columns.length == 0) { layoutColumns.add(ColSpan.SPAN_12.getName()); } else { for (Column column : columns) { layoutColumns.add(column.value().getName()); } } form.setLayoutColumns(layoutColumns); checkInheritance = definition.allowInheritance(); Map<String, String> defaultFieldSettings = new HashMap<>(); for (FieldParam param : definition.defaultFieldSettings()) { defaultFieldSettings.put(param.name(), param.value()); } List<FormDefinitionFieldData> formElements = new ArrayList<>(); if (checkInheritance) { TypeElement parent = getParent(formElement); formElements.addAll( extractParentFormFields(parent, definition.policy(), definition.i18n(), defaultFieldSettings)); } formElements.addAll( extracFormFields(formElement, definition.policy(), definition.i18n(), defaultFieldSettings)); FormGenerationUtils.sort(definition.startElement(), formElements); messager.printMessage(Diagnostic.Kind.NOTE, "Discovered " + formElements.size() + " elements for form [" + formElement.getQualifiedName().toString() + "]"); form.getElements().addAll(formElements); context.getForms().add(form); }
From source file:org.immutables.value.processor.meta.ValueType.java
private boolean inferJacksonMapped() { List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors(); for (AnnotationMirror annotation : annotationMirrors) { TypeElement annotationElement = (TypeElement) annotation.getAnnotationType().asElement(); if (JACKSON_MAPPING_ANNOTATION_CLASSES.contains(annotationElement.getQualifiedName().toString())) { return true; }/*from w w w . ja v a 2 s . co m*/ } return false; }
From source file:fr.xebia.extras.selma.codegen.FactoryWrapper.java
/** * Generates the code to declare custom factory fields, setter and call default constructor in mapper constructor * * @param writer// ww w . j av a 2 s .c om * @param assign * @throws IOException */ public void emitFactoryFields(JavaWriter writer, boolean assign) throws IOException { for (TypeElement factoryField : factoryFields) { final String field = String.format(FACTORY_FIELD_TPL, factoryField.getSimpleName().toString()); if (assign) { if (factoryField.getKind() != ElementKind.INTERFACE) { TypeConstructorWrapper constructorWrapper = new TypeConstructorWrapper(context, factoryField); // assign the customMapper field to a newly created instance passing to it the declared source params writer.emitStatement("this.%s = new %s(%s)", field, factoryField.getQualifiedName().toString(), constructorWrapper.hasMatchingSourcesConstructor ? context.newParams() : ""); } } else { writer.emitEmptyLine(); writer.emitJavadoc("This field is used for custom Mapping"); if (ioC == IoC.SPRING) { writer.emitAnnotation("org.springframework.beans.factory.annotation.Autowired"); } writer.emitField(factoryField.asType().toString(), String.format(FACTORY_FIELD_TPL, factoryField.getSimpleName().toString()), EnumSet.of(PRIVATE)); writer.emitEmptyLine(); writer.emitJavadoc("Factory setter for " + field); EnumSet<Modifier> modifiers = EnumSet.of(PUBLIC, FINAL); if (ioC == IoC.CDI) { modifiers = EnumSet.of(PUBLIC); } writer.beginMethod("void", "setFactory" + factoryField.getSimpleName(), modifiers, factoryField.asType().toString(), "_factory"); writer.emitStatement("this.%s = _factory", field); writer.endMethod(); writer.emitEmptyLine(); } } }
From source file:fr.xebia.extras.selma.codegen.FactoryWrapper.java
private void pushFactoryMethod(TypeElement element, MethodWrapper method, boolean ignoreAbstract) { MappingBuilder res = null;//w ww . j a v a 2 s. co m String factoryFieldName = ignoreAbstract ? "this" : buildFactoryFieldName(element); TypeMirror returnType = method.returnType(); String methodCall = String.format("%s.%s", factoryFieldName, method.getSimpleName()); Factory factory = new Factory(this.context, method, methodCall); if (method.hasTypeParameter()) { genericFactories.add(factory); } else { staticFactories.add(factory); } unusedFactories.put(factory, String.format("%s.%s", element.getQualifiedName(), method.getSimpleName())); }
From source file:fr.xebia.extras.selma.codegen.CustomMapperWrapper.java
/** * Adds a custom mapping method to the registry for later use at codegen. * * @param method/* w w w . ja v a2s. com*/ * @param immutable * @param ignoreAbstract */ private void pushCustomMapper(final TypeElement element, final MethodWrapper method, Boolean immutable, boolean ignoreAbstract) { MappingBuilder res = null; String customMapperFieldName = ignoreAbstract ? "this" : buildMapperFieldName(element); InOutType inOutType = method.inOutType(); String methodCall = String.format("%s.%s", customMapperFieldName, method.getSimpleName()); if (immutable == null) { res = MappingBuilder.newCustomMapper(inOutType, methodCall); unusedCustomMappers.put(inOutType, String.format("%s.%s", element.getQualifiedName(), method.getSimpleName())); } else if (immutable) { res = MappingBuilder.newCustomMapper(inOutType, methodCall); inOutType = new InOutType(inOutType, true); } else if (!immutable) { res = MappingBuilder.newCustomMapperImmutableForUpdateGraph(inOutType, methodCall); inOutType = new InOutType(inOutType, false); } if (registryMap.containsKey(inOutType)) { MappingBuilder mappingBuilder = registryMap.get(inOutType); context.error(method.element(), "Conflicting custom mapper method " + "conflicts with '%s' For '%s' ", mappingBuilder.toString(), inOutType.toString()); } registryMap.put(inOutType, res); }
From source file:fr.xebia.extras.selma.codegen.CustomMapperWrapper.java
private void pushMappingInterceptor(TypeElement element, MethodWrapper method, boolean ignoreAbstract) { String customMapperFieldName = ignoreAbstract ? "this" : buildMapperFieldName(element); InOutType inOutType = method.inOutArgs(); MappingBuilder res = MappingBuilder.newMappingInterceptor(inOutType, String.format("%s.%s", customMapperFieldName, method.getSimpleName())); // Push IOType for both mutable and immutable mapping interceptorMap.put(inOutType, res);/*from w ww . j a va 2 s.c o m*/ interceptorMap.put(new InOutType(inOutType.in(), inOutType.out(), false), res); unusedInterceptor.put(inOutType, String.format("%s.%s", element.getQualifiedName(), method.getSimpleName())); }
From source file:com.webcohesion.enunciate.modules.java_xml_client.JavaXMLClientModule.java
protected File generateClientSources() { File sourceDir = getSourceDir(); sourceDir.mkdirs();//from w w w . j a va2s . co m Map<String, Object> model = new HashMap<String, Object>(); Map<String, String> conversions = getClientPackageConversions(); EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext(); ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jaxbContext); model.put("packageFor", new ClientPackageForMethod(conversions, this.context)); model.put("classnameFor", classnameFor); model.put("simpleNameFor", new SimpleNameForMethod(classnameFor)); model.put("file", new FileDirective(sourceDir, this.enunciate.getLogger())); model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile()); model.put("annotationValue", new AnnotationValueMethod()); Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes()); facetIncludes.addAll(getFacetIncludes()); Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes()); facetExcludes.addAll(getFacetExcludes()); FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes); model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter)); boolean upToDate = isUpToDateWithSources(sourceDir); if (!upToDate) { try { debug("Generating the Java client classes..."); HashMap<String, WebFault> allFaults = new HashMap<String, WebFault>(); AntPatternMatcher matcher = new AntPatternMatcher(); matcher.setPathSeparator("."); if (this.jaxwsModule != null) { Set<String> seeAlsos = new TreeSet<String>(); // Process the annotations, the request/response beans, and gather the set of web faults // for each endpoint interface. for (WsdlInfo wsdlInfo : this.jaxwsModule.getJaxwsContext().getWsdls().values()) { for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) { if (facetFilter.accept(ei)) { for (WebMethod webMethod : ei.getWebMethods()) { if (facetFilter.accept(webMethod)) { for (WebMessage webMessage : webMethod.getMessages()) { if (webMessage instanceof RequestWrapper) { model.put("message", webMessage); processTemplate(getTemplateURL("client-request-bean.fmt"), model); seeAlsos.add(getBeanName(classnameFor, ((RequestWrapper) webMessage).getRequestBeanName())); } else if (webMessage instanceof ResponseWrapper) { model.put("message", webMessage); processTemplate(getTemplateURL("client-response-bean.fmt"), model); seeAlsos.add(getBeanName(classnameFor, ((ResponseWrapper) webMessage).getResponseBeanName())); } else if (webMessage instanceof WebFault) { WebFault fault = (WebFault) webMessage; allFaults.put(fault.getQualifiedName().toString(), fault); } } } } } } } //gather the annotation information and process the possible beans for each web fault. for (WebFault webFault : allFaults.values()) { boolean implicit = webFault.isImplicitSchemaElement(); String faultBean = implicit ? getBeanName(classnameFor, webFault.getImplicitFaultBeanQualifiedName()) : classnameFor.convert(webFault.getExplicitFaultBeanType()); seeAlsos.add(faultBean); if (implicit) { model.put("fault", webFault); processTemplate(getTemplateURL("client-fault-bean.fmt"), model); } } model.put("seeAlsoBeans", seeAlsos); model.put("baseUri", this.enunciate.getConfiguration().getApplicationRoot()); for (WsdlInfo wsdlInfo : this.jaxwsModule.getJaxwsContext().getWsdls().values()) { if (wsdlInfo.getWsdlFile() == null) { throw new EnunciateException("WSDL " + wsdlInfo.getId() + " doesn't have a filename."); } for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) { if (facetFilter.accept(ei)) { model.put("endpointInterface", ei); model.put("wsdlFileName", wsdlInfo.getFilename()); processTemplate(getTemplateURL("client-endpoint-interface.fmt"), model); processTemplate(getTemplateURL("client-soap-endpoint-impl.fmt"), model); } } } for (WebFault webFault : allFaults.values()) { if (useServerSide(webFault, matcher)) { copyServerSideType(sourceDir, webFault); } else { TypeElement superFault = (TypeElement) ((DeclaredType) webFault.getSuperclass()) .asElement(); if (superFault != null && allFaults.containsKey(superFault.getQualifiedName().toString()) && allFaults.get(superFault.getQualifiedName().toString()) .isImplicitSchemaElement()) { model.put("superFault", allFaults.get(superFault.getQualifiedName().toString())); } else { model.remove("superFault"); } model.put("fault", webFault); processTemplate(getTemplateURL("client-web-fault.fmt"), model); } } } for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) { for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) { if (facetFilter.accept(typeDefinition)) { if (useServerSide(typeDefinition, matcher)) { copyServerSideType(sourceDir, typeDefinition); } else { model.put("rootEl", this.jaxbModule.getJaxbContext().findElementDeclaration(typeDefinition)); model.put("type", typeDefinition); URL template = typeDefinition.isEnum() ? typeDefinition instanceof QNameEnumTypeDefinition ? getTemplateURL("client-qname-enum-type.fmt") : getTemplateURL("client-enum-type.fmt") : typeDefinition.isSimple() ? getTemplateURL("client-simple-type.fmt") : getTemplateURL("client-complex-type.fmt"); processTemplate(template, model); } } } for (Registry registry : schemaInfo.getRegistries()) { model.put("registry", registry); processTemplate(getTemplateURL("client-registry.fmt"), model); } } } catch (IOException e) { throw new EnunciateException(e); } catch (TemplateException e) { throw new EnunciateException(e); } } else { info("Skipping generation of Java client sources as everything appears up-to-date..."); } context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model)); return sourceDir; }
From source file:org.versly.rest.wsdoc.AnnotationProcessor.java
private TypeMirror unwrapReturnType(TypeMirror originalReturnType) { if (originalReturnType.getKind() != TypeKind.DECLARED) { return originalReturnType; }// ww w. j av a 2s .c o m DeclaredType declaredType = (DeclaredType) originalReturnType; if (declaredType.getTypeArguments().size() == 0) { return originalReturnType; } TypeElement element = (TypeElement) declaredType.asElement(); // For Spring's Async Support if ("org.springframework.web.context.request.async.DeferredResult" .equalsIgnoreCase(element.getQualifiedName().toString())) { return declaredType.getTypeArguments().get(0); } // For Spring's Async Support if ("java.util.concurrent.Callable".equalsIgnoreCase(element.getQualifiedName().toString())) { return declaredType.getTypeArguments().get(0); } return originalReturnType; }
From source file:org.kie.workbench.common.forms.adf.processors.FormDefinitionsProcessor.java
private void processFieldDefinition(TypeElement fieldDefinitionElement) throws Exception { final Messager messager = processingEnv.getMessager(); messager.printMessage(Diagnostic.Kind.NOTE, "Discovered FieldDefinition class [" + fieldDefinitionElement.getSimpleName() + "]"); Collection<FieldInfo> fieldInfos = extractFieldInfos(fieldDefinitionElement, null); String modelClassName = fieldDefinitionElement.getQualifiedName().toString(); String fieldModifierName = fixClassName(modelClassName) + "_FieldStatusModifier"; Map<String, String> fieldDefinition = new HashMap<>(); fieldDefinition.put("className", modelClassName); fieldDefinition.put("fieldModifierName", fieldModifierName); Map<String, Object> templateContext = new HashMap<>(); templateContext.put("modelClassName", modelClassName); templateContext.put("fieldModifierName", fieldModifierName); FieldDefinition fieldDefinitionAnnotation = fieldDefinitionElement.getAnnotation(FieldDefinition.class); for (FieldInfo fieldInfo : fieldInfos) { AnnotationMirror annotation = GeneratorUtils.getAnnotation(elementUtils, fieldInfo.fieldElement, FieldValue.class.getName()); if (annotation != null) { if (fieldDefinition.containsKey("value")) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: it should have only one @FieldValue"); }//from w ww. ja va 2 s . c om if (fieldInfo.getter == null || fieldInfo.setter == null) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: field marked as @FieldValue should have setter & getter"); } fieldDefinition.put("value", fieldInfo.fieldElement.getSimpleName().toString()); } else { annotation = GeneratorUtils.getAnnotation(elementUtils, fieldInfo.fieldElement, FieldReadOnly.class.getName()); if (annotation != null) { if (templateContext.containsKey("readOnly")) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: it should have only one @FieldReadOnly"); } if (!fieldInfo.fieldElement.asType().getKind().equals(TypeKind.BOOLEAN) && !fieldInfo.fieldElement.asType().toString().equals(Boolean.class.getName())) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: field marked as @FieldReadOnly must be boolean or Boolean"); } if (fieldInfo.getter == null) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: field marked as @FieldReadOnly should have getter"); } templateContext.put("readOnly", fieldInfo.getter); } annotation = GeneratorUtils.getAnnotation(elementUtils, fieldInfo.fieldElement, FieldRequired.class.getName()); if (annotation != null) { if (templateContext.containsKey("required")) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: it should have only one @FieldRequired"); } if (!fieldInfo.fieldElement.asType().getKind().equals(TypeKind.BOOLEAN) && !fieldInfo.fieldElement.asType().toString().equals(Boolean.class.getName())) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: field marked as @FieldRequired must be boolean or Boolean"); } if (fieldInfo.getter == null) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: field marked as @FieldRequired should have getter"); } templateContext.put("required", fieldInfo.getter); } if (fieldDefinitionAnnotation.labelMode().equals(LabelMode.OVERRIDE)) { annotation = GeneratorUtils.getAnnotation(elementUtils, fieldInfo.fieldElement, FieldLabel.class.getName()); if (annotation != null) { if (templateContext.containsKey("label")) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: it should have only one @FieldLabel"); } if (!fieldInfo.fieldElement.asType().toString().equals(String.class.getName())) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: field marked as @FieldLabel must be a String"); } if (fieldInfo.getter == null) { throw new Exception("Problem processing FieldDefinition [" + modelClassName + "]: field marked as @FieldLabel should have getter"); } templateContext.put("label", fieldInfo.getter); } } } } StringBuffer source = writeTemplate("templates/FieldDefinitionModifier.ftl", templateContext); fieldDefinition.put("sourceCode", source.toString()); context.getFieldDefinitions().add(fieldDefinition); }