List of usage examples for javax.lang.model.element PackageElement getQualifiedName
Name getQualifiedName();
From source file:org.commonjava.vertx.vabr.anno.proc.AbstractTemplateInfo.java
protected AbstractTemplateInfo(final Element elem, final Handles handles, final int priority, final Method method, final String path, final String defPath, final String[] routeVersions, final boolean fork) { this.priority = priority; this.httpMethod = method; this.fork = fork; this.httpPath = AnnotationUtils.pathOf(handles, path, defPath); this.routePathFragment = isEmpty(path) ? defPath : path; this.handlerPathFragment = isEmpty(handles.prefix()) ? handles.value() : handles.prefix(); // it only applies to methods... final ExecutableElement eelem = (ExecutableElement) elem; methodname = eelem.getSimpleName().toString(); final TypeElement cls = (TypeElement) eelem.getEnclosingElement(); Element parent = cls.getEnclosingElement(); while (parent.getKind() != ElementKind.PACKAGE) { parent = parent.getEnclosingElement(); }/*from w ww. j a va2 s . com*/ final PackageElement pkg = (PackageElement) parent; qualifiedClassname = cls.getQualifiedName().toString(); classname = cls.getSimpleName().toString(); packagename = pkg.getQualifiedName().toString(); this.handlerKey = AnnotationUtils.getHandlerKey(handles, qualifiedClassname); this.versions = new ArrayList<>(); if (routeVersions != null && routeVersions.length > 0) { for (final String rv : routeVersions) { this.versions.add(rv); } } else { final String[] handlerVersions = handles.versions(); if (handlerVersions != null) { for (final String rv : handlerVersions) { this.versions.add(rv); } } } }
From source file:org.androidtransfuse.adapter.element.ASTElementFactory.java
private PackageClass buildPackageClass(TypeElement typeElement) { PackageElement packageElement = elements.getPackageOf(typeElement); String pkg = packageElement.getQualifiedName().toString(); String qualifiedName = typeElement.getQualifiedName().toString(); String name;//w ww. j ava2s . c o m if (!pkg.isEmpty() && pkg.length() < qualifiedName.length()) { name = qualifiedName.substring(pkg.length() + 1); } else { name = qualifiedName; } return new PackageClass(pkg, name); }
From source file:com.github.cchacin.JsonSchemaProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (final Element element : roundEnv.getElementsAnnotatedWith(JsonSchema.class)) { final TypeElement classElement = (TypeElement) element; final PackageElement packageElement = (PackageElement) classElement.getEnclosingElement(); processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "annotated class: " + classElement.getQualifiedName(), element); final String fqClassName = classElement.getQualifiedName().toString(); final String className = classElement.getSimpleName().toString(); final String packageName = packageElement.getQualifiedName().toString(); final JsonSchema jsonSchema = element.getAnnotation(JsonSchema.class); try {/*from ww w .j ava 2 s . c o m*/ final JsonNode node = new ObjectMapper().readTree( Thread.currentThread().getContextClassLoader().getResourceAsStream(jsonSchema.path())); vc.put("display", new DisplayTool()); vc.put("json", node); vc.put("className", className); vc.put("packageName", packageName); final JavaFileObject jfo = filer.createSourceFile(fqClassName + "JsonSchema"); processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "creating source file: " + jfo.toUri()); final Writer writer = jfo.openWriter(); processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "applying velocity template: " + vt.getName()); vt.merge(vc, writer); writer.close(); } catch (IOException e) { e.printStackTrace(); } } return false; }
From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java
private String getTypeName(final Element e) { TypeElement classElement = (TypeElement) e; PackageElement packageElement = (PackageElement) classElement.getEnclosingElement(); return packageElement.getQualifiedName().toString() + "." + classElement.getSimpleName(); }
From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java
private void generateRuleCode(final AbstractGenerator generator, final Messager messager, final TypeElement classElement, final PackageElement packageElement, final String classNameActivity) { try {/*from w ww. ja v a2 s .com*/ final String packageName = packageElement.getQualifiedName().toString(); //Try generating code for each required class messager.printMessage(Diagnostic.Kind.NOTE, "Generating ryke code for [" + classNameActivity + "]"); generator.generate(packageName, packageElement, classNameActivity, classElement, processingEnv); } catch (GenerationException ge) { final String msg = ge.getMessage(); processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, msg, classElement); } }
From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java
private boolean processPropertySets(final Set<? extends TypeElement> set, final Element e, final RoundEnvironment roundEnv) throws Exception { final boolean isClass = e.getKind() == ElementKind.CLASS; if (isClass) { TypeElement classElement = (TypeElement) e; PackageElement packageElement = (PackageElement) classElement.getEnclosingElement(); String propertyClassName = packageElement.getQualifiedName().toString() + "." + classElement.getSimpleName(); // Name fields. processFieldName(classElement, propertyClassName, ANNOTATION_NAME, processingContext.getPropertySetAnnotations().getNameFieldNames(), true); // Properties fields. Map<String, Element> propertyElements = getFieldNames(classElement, ANNOTATION_PROPERTY); if (null != propertyElements) { processingContext.getPropertyElements().addAll(propertyElements.values()); processingContext.getPropertySetAnnotations().getPropertiesFieldNames().put(propertyClassName, new LinkedHashSet<>(propertyElements.keySet())); if (propertyElements.isEmpty()) { note("Property Set for tye [" + propertyClassName + "] have no Property members."); }/*from www. jav a 2 s.com*/ } } return false; }
From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java
private boolean processProperties(final Set<? extends TypeElement> set, final Element e, final RoundEnvironment roundEnv) throws Exception { final boolean isClass = e.getKind() == ElementKind.CLASS; if (isClass) { TypeElement classElement = (TypeElement) e; PackageElement packageElement = (PackageElement) classElement.getEnclosingElement(); String propertyClassName = packageElement.getQualifiedName().toString() + "." + classElement.getSimpleName(); // Meta-properties Property metaProperty = e.getAnnotation(Property.class); if (null != metaProperty) { PropertyMetaTypes type = metaProperty.meta(); if (!PropertyMetaTypes.NONE.equals(type)) { processingContext.getMetaPropertyTypes().put(type, propertyClassName + ".class"); }//from w w w . j av a 2s. c o m } // Value fields. processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_VALUE, processingContext.getPropertyAnnotations().getValueFieldNames(), true); // Default Value fields. processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_DEFAULT_VALUE, processingContext.getPropertyAnnotations().getDefaultValueFieldNames(), true); // Allowed Values fields. processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_ALLOWED_VALUES, processingContext.getPropertyAnnotations().getAllowedValuesFieldNames(), false); // Caption fields. processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_CAPTION, processingContext.getPropertyAnnotations().getCaptionFieldNames(), true); // Description fields. processFieldName(classElement, propertyClassName, ANNOTATION_DESCRIPTION, processingContext.getPropertyAnnotations().getDescriptionFieldNames(), true); // Type fields. processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_TYPE, processingContext.getPropertyAnnotations().getTypeFieldNames(), true); // Read only fields. processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_READONLY, processingContext.getPropertyAnnotations().getReadOnlyFieldNames(), true); // Optional fields. processFieldName(classElement, propertyClassName, ANNOTATION_PROPERTY_OPTIONAL, processingContext.getPropertyAnnotations().getOptionalFieldNames(), true); } return false; }
From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java
private boolean processDefinitions(final Set<? extends TypeElement> set, final Element e, final RoundEnvironment roundEnv) throws Exception { final boolean isClass = e.getKind() == ElementKind.CLASS; if (isClass) { TypeElement classElement = (TypeElement) e; PackageElement packageElement = (PackageElement) classElement.getEnclosingElement(); String defintionClassName = packageElement.getQualifiedName().toString() + "." + classElement.getSimpleName(); Map<String, String> baseTypes = processingContext.getDefinitionAnnotations().getBaseTypes(); TypeElement parentElement = getDefinitionInheritedType(classElement); if (null != parentElement && !baseTypes.containsKey(defintionClassName)) { PackageElement basePackageElement = (PackageElement) parentElement.getEnclosingElement(); String baseClassName = basePackageElement.getQualifiedName().toString() + "." + parentElement.getSimpleName(); baseTypes.put(defintionClassName, baseClassName); }//from w w w . j a va 2s . co m // Category fields. processFieldName(classElement, defintionClassName, ANNOTATION_DEFINITION_CATEGORY, processingContext.getDefinitionAnnotations().getCategoryFieldNames(), true); // Title fields. processFieldName(classElement, defintionClassName, ANNOTATION_DEFINITION_TITLE, processingContext.getDefinitionAnnotations().getTitleFieldNames(), true); // Description fields. processFieldName(classElement, defintionClassName, ANNOTATION_DESCRIPTION, processingContext.getDefinitionAnnotations().getDescriptionFieldNames(), true); // Labels fields. processFieldName(classElement, defintionClassName, ANNOTATION_DEFINITION_LABELS, processingContext.getDefinitionAnnotations().getLabelsFieldNames(), true); // Builder class. processDefinitionModelBuilder(e, defintionClassName, processingContext.getDefinitionAnnotations().getBuilderFieldNames()); // Graph element. Definition definitionAnn = e.getAnnotation(Definition.class); TypeMirror mirror = null; try { Class<?> graphClass = definitionAnn.graphFactory(); } catch (MirroredTypeException mte) { mirror = mte.getTypeMirror(); } if (null == mirror) { throw new RuntimeException("No graph factory class specified for the @Definition."); } String fqcn = mirror.toString(); processingContext.getDefinitionAnnotations().getGraphFactoryFieldNames().put(defintionClassName, fqcn); // PropertySets fields. Map<String, Element> propertySetElements = getFieldNames(classElement, ANNOTATION_PROPERTY_SET); if (null != propertySetElements && !propertySetElements.isEmpty()) { processingContext.getPropertySetElements().addAll(propertySetElements.values()); processingContext.getDefinitionAnnotations().getPropertySetFieldNames().put(defintionClassName, new LinkedHashSet<>(propertySetElements.keySet())); } else { note("Definition for tye [" + defintionClassName + "] have no Property Set members."); } // Properties fields. Map<String, Element> propertyElements = getFieldNames(classElement, ANNOTATION_PROPERTY); if (null != propertyElements && !propertyElements.isEmpty()) { processingContext.getPropertyElements().addAll(propertyElements.values()); processingContext.getDefinitionAnnotations().getPropertyFieldNames().put(defintionClassName, new LinkedHashSet<>(propertyElements.keySet())); } else { note("Definition for tye [" + defintionClassName + "] have no Property members."); } // -- Morphing annotations -- MorphBase morphBaseAnn = e.getAnnotation(MorphBase.class); Morph morphAnn = e.getAnnotation(Morph.class); if (null != morphBaseAnn && null != morphAnn) { TypeElement superElement = getAnnotationInTypeInheritance(classElement, MorphBase.class.getName()); final String packageName = packageElement.getQualifiedName().toString(); String morphBaseClassName = packageName + "." + superElement.getSimpleName().toString(); Map<String, String> defaultTypesMap = processingContext.getMorphingAnnotations() .getBaseDefaultTypes(); if (null == defaultTypesMap.get(morphBaseClassName)) { TypeMirror morphDefaultTypeMirror = null; try { Class<?> defaultTypeClass = morphBaseAnn.defaultType(); } catch (MirroredTypeException mte) { morphDefaultTypeMirror = mte.getTypeMirror(); } if (null == morphDefaultTypeMirror) { throw new RuntimeException("No default type class specifyed for the @MorphBase."); } String morphDefaultTypeClassName = morphDefaultTypeMirror.toString(); processingContext.getMorphingAnnotations().getBaseDefaultTypes().put(morphBaseClassName, morphDefaultTypeClassName); // MorphBase - targets List<? extends TypeMirror> morphTargetMirrors = null; try { Class<?>[] defsClasses = morphBaseAnn.targets(); } catch (MirroredTypesException mte) { morphTargetMirrors = mte.getTypeMirrors(); } if (null != morphTargetMirrors) { Set<String> morphTargetMirrorClasses = new LinkedHashSet<>(); for (TypeMirror morphTargetMirror : morphTargetMirrors) { String morphTargetMirrorClassName = morphTargetMirror.toString(); morphTargetMirrorClasses.add(morphTargetMirrorClassName); } processingContext.getMorphingAnnotations().getBaseTargets().put(morphBaseClassName, morphTargetMirrorClasses); } // Morph Properties. processMorphProperties(superElement, morphBaseClassName); } TypeMirror morphBaseTypeMirror = null; try { Class<?> defaultTypeClass = morphAnn.base(); } catch (MirroredTypeException mte) { morphBaseTypeMirror = mte.getTypeMirror(); } if (null == morphBaseTypeMirror) { throw new RuntimeException("No base type class specifyed for the @MorphBase."); } String morphBaseTypeClassName = morphBaseTypeMirror.toString(); Set<String> currentTargets = processingContext.getMorphingAnnotations().getBaseTargets() .get(morphBaseTypeClassName); if (null == currentTargets) { currentTargets = new LinkedHashSet<>(); processingContext.getMorphingAnnotations().getBaseTargets().put(morphBaseTypeClassName, currentTargets); } currentTargets.add(defintionClassName); } } return false; }
From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java
private boolean processDefinitionSets(final Set<? extends TypeElement> set, final Element e, final RoundEnvironment roundEnv) throws Exception { final Messager messager = processingEnv.getMessager(); final boolean isClass = e.getKind() == ElementKind.CLASS; if (isClass) { TypeElement classElement = (TypeElement) e; PackageElement packageElement = (PackageElement) classElement.getEnclosingElement(); messager.printMessage(Diagnostic.Kind.NOTE, "Discovered definition set class [" + classElement.getSimpleName() + "]"); final String packageName = packageElement.getQualifiedName().toString(); final String className = classElement.getSimpleName().toString(); processingContext.setDefinitionSet(packageName, className); String defSetClassName = packageName + "." + className; // Description fields. processFieldName(classElement, defSetClassName, ANNOTATION_DESCRIPTION, processingContext.getDefSetAnnotations().getDescriptionFieldNames(), true); // Definitions identifiers. DefinitionSet definitionSetAnn = e.getAnnotation(DefinitionSet.class); List<? extends TypeMirror> mirrors = null; try {//from www.j a va 2s .co m Class<?>[] defsClasses = definitionSetAnn.definitions(); } catch (MirroredTypesException mte) { mirrors = mte.getTypeMirrors(); } if (null == mirrors) { throw new RuntimeException("No graph class class specifyed for the @DefinitionSet."); } Set<String> defIds = new LinkedHashSet<>(); for (TypeMirror mirror : mirrors) { if (mirror.getKind().equals(TypeKind.DECLARED)) { final TypeElement t = (TypeElement) ((DeclaredType) mirror).asElement(); processingContext.getDefinitionElements().add(t); } String fqcn = mirror.toString(); defIds.add(fqcn); } processingContext.getDefSetAnnotations().getDefinitionIds().addAll(defIds); // Builder class. processDefinitionSetModelBuilder(e, defSetClassName, processingContext.getDefSetAnnotations().getBuilderFieldNames()); // Graph factory type. TypeMirror mirror = null; try { Class<?> graphClass = definitionSetAnn.graphFactory(); } catch (MirroredTypeException mte) { mirror = mte.getTypeMirror(); } if (null == mirror) { throw new RuntimeException("No graph factory class specifyed for the @DefinitionSet."); } String fqcn = mirror.toString(); processingContext.getDefSetAnnotations().getGraphFactoryTypes().put(defSetClassName, fqcn); // Definition Set's qualifier. try { Class<?> qualifierClass = definitionSetAnn.qualifier(); } catch (MirroredTypeException mte) { mirror = mte.getTypeMirror(); } if (null == mirror) { throw new RuntimeException("No qualifier class specifyed for the @DefinitionSet."); } processingContext.getDefSetAnnotations().getQualifiers().put(defSetClassName, mirror.toString()); } return true; }
From source file:org.jraf.android.prefs.compiler.PrefsProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (TypeElement te : annotations) { for (Element element : roundEnv.getElementsAnnotatedWith(te)) { TypeElement classElement = (TypeElement) element; PackageElement packageElement = (PackageElement) classElement.getEnclosingElement(); String classComment = processingEnv.getElementUtils().getDocComment(classElement); List<Pref> prefList = new ArrayList<Pref>(); // Iterate over the fields of the class for (VariableElement variableElement : ElementFilter.fieldsIn(classElement.getEnclosedElements())) { if (variableElement.getModifiers().contains(Modifier.STATIC)) { // Ignore constants continue; }//from ww w . j a va 2 s . co m TypeMirror fieldType = variableElement.asType(); boolean isAllowedType = PrefType.isAllowedType(fieldType); if (!isAllowedType) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, fieldType + " is not allowed here, only these types are allowed: " + PrefType.getAllowedTypes(), variableElement); // Problem detected: halt return true; } String fieldName = variableElement.getSimpleName().toString(); org.jraf.android.prefs.Name fieldNameAnnot = variableElement .getAnnotation(org.jraf.android.prefs.Name.class); String prefName = getPrefName(fieldName, fieldNameAnnot); String prefDefaultValue = getDefaultValue(variableElement, fieldType); if (prefDefaultValue == null) { // Problem detected: halt return true; } String fieldComment = processingEnv.getElementUtils().getDocComment(variableElement); Pref pref = new Pref(fieldName, prefName, PrefType.from(fieldType), prefDefaultValue, fieldComment); prefList.add(pref); } Map<String, Object> args = new HashMap<String, Object>(); // File name (optional - also use 'value' for this) org.jraf.android.prefs.Prefs prefsAnnot = classElement .getAnnotation(org.jraf.android.prefs.Prefs.class); String fileName = prefsAnnot.value(); if (fileName.isEmpty()) { fileName = prefsAnnot.fileName(); } if (!fileName.isEmpty()) args.put("fileName", fileName); // File mode (must only appear if fileName is defined) int fileMode = prefsAnnot.fileMode(); if (fileMode != -1) { if (fileName.isEmpty()) { // File mode set, but not file name (which makes no sense) processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "fileMode must only be set if fileName (or value) is also set", classElement); // Problem detected: halt return true; } args.put("fileMode", fileMode); } // Disable @Nullable generation args.put("disableNullable", prefsAnnot.disableNullable()); JavaFileObject javaFileObject = null; try { // SharedPreferencesWrapper javaFileObject = processingEnv.getFiler() .createSourceFile(classElement.getQualifiedName() + SUFFIX_PREF_WRAPPER); Template template = getFreemarkerConfiguration().getTemplate("prefwrapper.ftl"); args.put("package", packageElement.getQualifiedName()); args.put("comment", classComment); args.put("prefWrapperClassName", classElement.getSimpleName() + SUFFIX_PREF_WRAPPER); args.put("editorWrapperClassName", classElement.getSimpleName() + SUFFIX_EDITOR_WRAPPER); args.put("prefList", prefList); Writer writer = javaFileObject.openWriter(); template.process(args, writer); IOUtils.closeQuietly(writer); // EditorWrapper javaFileObject = processingEnv.getFiler() .createSourceFile(classElement.getQualifiedName() + "EditorWrapper"); template = getFreemarkerConfiguration().getTemplate("editorwrapper.ftl"); writer = javaFileObject.openWriter(); template.process(args, writer); IOUtils.closeQuietly(writer); } catch (Exception e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "En error occurred while generating Prefs code " + e.getClass() + e.getMessage(), element); e.printStackTrace(); // Problem detected: halt return true; } } } return true; }