Example usage for javax.lang.model.element TypeElement getQualifiedName

List of usage examples for javax.lang.model.element TypeElement getQualifiedName

Introduction

In this page you can find the example usage for javax.lang.model.element TypeElement getQualifiedName.

Prototype

Name getQualifiedName();

Source Link

Document

Returns the fully qualified name of this type element.

Usage

From source file:blue.lapis.pore.ap.event.EventVerifierProcessor.java

private void verifyName(TypeElement type) {
    TypeElement bukkitEvent = (TypeElement) ((DeclaredType) type.getSuperclass()).asElement();

    String poreName = StringUtils.removeStart(type.getQualifiedName().toString(), PORE_PREFIX);
    String porePackage = StringUtils.substringBeforeLast(poreName, ".");
    poreName = StringUtils.substringAfterLast(poreName, ".");

    String bukkitName = StringUtils.removeStart(bukkitEvent.getQualifiedName().toString(), BUKKIT_PREFIX);
    String bukkitPackage = StringUtils.substringBeforeLast(bukkitName, ".");
    bukkitName = StringUtils.substringAfterLast(bukkitName, ".");

    String expectedName = "Pore" + bukkitName;

    if (!poreName.equals(expectedName)) {
        processingEnv.getMessager().printMessage(SEVERITY, poreName + " should be called " + expectedName,
                type);/*ww  w .  j  av  a2  s  .c o  m*/
    }
    if (!porePackage.equals(bukkitPackage)) {
        processingEnv.getMessager().printMessage(SEVERITY,
                poreName + " is in wrong package: should be in " + PORE_PREFIX + bukkitPackage, type);
    }
}

From source file:org.mule.devkit.validation.JavaDocValidator.java

protected boolean exampleDoesNotExist(GeneratorContext context, ExecutableElement method)
        throws ValidationException {

    if (!context.getJavaDocUtils().hasTag("sample.xml", method)) {
        throw new ValidationException(method, "Method " + method.getSimpleName().toString()
                + " does not contain an example using {@sample.xml} tag.");
    }/*from   w  w  w. j av  a2  s.  co m*/

    boolean found = false;
    String sample = context.getJavaDocUtils().getTagContent("sample.xml", method);
    String[] split = sample.split(" ");

    if (split.length != 2) {
        throw new ValidationException(method,
                "Check @sample.xml javadoc tag because is not well formed for method: "
                        + method.getSimpleName());
    }

    String pathToExamplesFile = split[0];
    String exampleName = split[1];

    TypeElement typeElement = (TypeElement) method.getEnclosingElement();
    String sourcePath = context.getSourceUtils().getPath(typeElement);
    int packageCount = StringUtils.countMatches(typeElement.getQualifiedName().toString(), ".") + 1;
    while (packageCount > 0) {
        sourcePath = sourcePath.substring(0, sourcePath.lastIndexOf("/"));
        packageCount--;
    }

    try {
        File docFile = new File(sourcePath, pathToExamplesFile);
        String examplesFileContent = IOUtils.toString(new FileInputStream(docFile));
        if (examplesFileContent.contains("BEGIN_INCLUDE(" + exampleName + ")")) {
            found = true;
        }
    } catch (IOException e) {
        // do nothing
    }

    return !found;
}

From source file:easymvp.compiler.EasyMVPProcessor.java

private ClassName getClassName(TypeElement typeElement) {
    return ClassName.bestGuess(typeElement.getQualifiedName().toString());
}

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   www  .  j a  v  a2s . co  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:com.spotify.docgenerator.JacksonJerseyAnnotationProcessor.java

/**
 * If we see one of these, just create an entry that the class exists (with it's javadoc),
 * but don't try to do anything fancy.// w  ww. j ava 2  s. co m
 */
private void processJsonSerializeAnnotations(final RoundEnvironment roundEnv) {
    final Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(JsonSerialize.class);
    for (final Element e : elements) {
        if (e.getKind() != ElementKind.CLASS) {
            debugMessages.add("kind for " + e + " is not CLASS, but " + e.getKind());
            continue;
        }

        final TypeElement te = (TypeElement) e;
        final String className = te.getQualifiedName().toString();
        if (jsonClasses.containsKey(className)) {
            // it has already been processed by other means
            continue;
        }

        getOrCreateTransferClass(className, processingEnv.getElementUtils().getDocComment(te));
    }
}

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 w  ww. ja v  a 2 s  .c  om

    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:ch.rasc.extclassgenerator.ModelAnnotationProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,
            "Running " + getClass().getSimpleName());

    if (roundEnv.processingOver() || annotations.size() == 0) {
        return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
    }//from   w ww  . j av  a  2 s. c  o  m

    if (roundEnv.getRootElements() == null || roundEnv.getRootElements().isEmpty()) {
        this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "No sources to process");
        return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
    }

    OutputConfig outputConfig = new OutputConfig();

    outputConfig.setDebug(!"false".equals(this.processingEnv.getOptions().get(OPTION_DEBUG)));
    boolean createBaseAndSubclass = "true"
            .equals(this.processingEnv.getOptions().get(OPTION_CREATEBASEANDSUBCLASS));

    String outputFormatString = this.processingEnv.getOptions().get(OPTION_OUTPUTFORMAT);
    outputConfig.setOutputFormat(OutputFormat.EXTJS4);
    if (StringUtils.hasText(outputFormatString)) {
        if (OutputFormat.TOUCH2.name().equalsIgnoreCase(outputFormatString)) {
            outputConfig.setOutputFormat(OutputFormat.TOUCH2);
        } else if (OutputFormat.EXTJS5.name().equalsIgnoreCase(outputFormatString)) {
            outputConfig.setOutputFormat(OutputFormat.EXTJS5);
        }
    }

    String includeValidationString = this.processingEnv.getOptions().get(OPTION_INCLUDEVALIDATION);
    outputConfig.setIncludeValidation(IncludeValidation.NONE);
    if (StringUtils.hasText(includeValidationString)) {
        if (IncludeValidation.ALL.name().equalsIgnoreCase(includeValidationString)) {
            outputConfig.setIncludeValidation(IncludeValidation.ALL);
        } else if (IncludeValidation.BUILTIN.name().equalsIgnoreCase(includeValidationString)) {
            outputConfig.setIncludeValidation(IncludeValidation.BUILTIN);
        }
    }

    outputConfig.setUseSingleQuotes("true".equals(this.processingEnv.getOptions().get(OPTION_USESINGLEQUOTES)));
    outputConfig.setSurroundApiWithQuotes(
            "true".equals(this.processingEnv.getOptions().get(OPTION_SURROUNDAPIWITHQUOTES)));

    for (TypeElement annotation : annotations) {
        Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation);
        for (Element element : elements) {

            try {
                TypeElement typeElement = (TypeElement) element;

                String qualifiedName = typeElement.getQualifiedName().toString();
                Class<?> modelClass = Class.forName(qualifiedName);

                String code = ModelGenerator.generateJavascript(modelClass, outputConfig);

                Model modelAnnotation = element.getAnnotation(Model.class);
                String modelName = modelAnnotation.value();
                String fileName;
                String packageName = "";
                if (StringUtils.hasText(modelName)) {
                    int lastDot = modelName.lastIndexOf('.');
                    if (lastDot != -1) {
                        fileName = modelName.substring(lastDot + 1);
                        int firstDot = modelName.indexOf('.');
                        if (firstDot < lastDot) {
                            packageName = modelName.substring(firstDot + 1, lastDot);
                        }
                    } else {
                        fileName = modelName;
                    }
                } else {
                    fileName = typeElement.getSimpleName().toString();
                }

                if (createBaseAndSubclass) {
                    code = code.replaceFirst("(Ext.define\\([\"'].+?)([\"'],)", "$1Base$2");
                    FileObject fo = this.processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT,
                            packageName, fileName + "Base.js");
                    OutputStream os = fo.openOutputStream();
                    os.write(code.getBytes(ModelGenerator.UTF8_CHARSET));
                    os.close();

                    try {
                        fo = this.processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT,
                                packageName, fileName + ".js");
                        InputStream is = fo.openInputStream();
                        is.close();
                    } catch (FileNotFoundException e) {
                        String subClassCode = generateSubclassCode(modelClass, outputConfig);
                        fo = this.processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT,
                                packageName, fileName + ".js");
                        os = fo.openOutputStream();
                        os.write(subClassCode.getBytes(ModelGenerator.UTF8_CHARSET));
                        os.close();
                    }

                } else {
                    FileObject fo = this.processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT,
                            packageName, fileName + ".js");
                    OutputStream os = fo.openOutputStream();
                    os.write(code.getBytes(ModelGenerator.UTF8_CHARSET));
                    os.close();
                }

            } catch (ClassNotFoundException e) {
                this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
            } catch (IOException e) {
                this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
            }

        }
    }

    return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}

From source file:info.archinnov.achilles.internals.apt.processors.meta.AchillesProcessor.java

private void validateEntityNames(List<TypeElement> entityTypes) {
    Map<String, String> entities = new HashedMap();
    for (TypeElement entityType : entityTypes) {
        final String className = entityType.getSimpleName().toString();
        final String FQCN = entityType.getQualifiedName().toString();
        if (entities.containsKey(className)) {
            final String existingFQCN = entities.get(className);
            aptUtils.printError("%s and %s both share the same class name, it is forbidden by Achilles", FQCN,
                    existingFQCN);//from  w  w  w .j  av a 2  s .  c o m
            throw new IllegalStateException(
                    format("%s and %s both share the same class name, it is forbidden by Achilles", FQCN,
                            existingFQCN));
        } else {
            entities.put(className, FQCN);
        }
    }
}

From source file:net.pkhsolutions.ceres.common.builder.processor.BuildableAP.java

private void createFieldBuilder(TypeElement type) {
    VelocityContext vc = createAndInitializeVelocityContext(type);
    vc.put("properties", createPropertyList(getFields(type)));
    createSourceFile(type.getQualifiedName() + "Builder", fieldBuilderTemplate, vc);
}

From source file:fr.xebia.extras.selma.codegen.MapperClassGenerator.java

public void build() throws IOException {

    boolean firstMethod = true;
    JavaWriter writer = null;/*from w  w w . j  a v  a 2 s . com*/
    JavaFileObject sourceFile = null;

    final TypeElement type = processingEnv.getElementUtils().getTypeElement(origClasse);
    final String packageName = getPackage(type).getQualifiedName().toString();
    final String strippedTypeName = strippedTypeName(type.getQualifiedName().toString(), packageName);

    final String adapterName = new StringBuilder(packageName).append('.')
            .append(strippedTypeName.replace('.', '_')).append(SelmaConstants.MAPPER_CLASS_SUFFIX).toString();

    for (MethodWrapper mapperMethod : methodWrappers) {

        if (firstMethod) {
            sourceFile = processingEnv.getFiler().createSourceFile(adapterName, type);
            writer = new JavaWriter(sourceFile.openWriter());

            writer.emitSingleLineComment(GENERATED_BY_SELMA);
            writer.emitPackage(packageName);
            writer.emitEmptyLine();

            switch (mapper.ioC) {
            case SPRING:
                if (mapper.ioCServiceName != "") {
                    writer.emitAnnotation("org.springframework.stereotype.Service",
                            "\"" + mapper.ioCServiceName + "\"");
                } else {
                    writer.emitAnnotation("org.springframework.stereotype.Service");
                }
                break;
            case CDI:
                writer.emitAnnotation("javax.enterprise.context.ApplicationScoped");
                break;
            default:
                break;
            }

            openClassBlock(writer, adapterName, strippedTypeName);
            writer.emitEmptyLine();
            firstMethod = false;
        }
        // Write mapping method
        MapperMethodGenerator mapperMethodGenerator = new MapperMethodGenerator(writer, mapperMethod, mapper);
        mapperMethodGenerator.build();

        mapper.collectMaps(mapperMethodGenerator.maps());

        writer.emitEmptyLine();
    }

    buildConstructor(writer, adapterName);

    writer.endType();
    writer.close();

    mapper.reportUnused();
}