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

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

Introduction

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

Prototype

@Override
Name getSimpleName();

Source Link

Document

Returns the simple name of this type element.

Usage

From source file:info.archinnov.achilles.internals.parser.FunctionParser.java

public static List<FunctionSignature> parseFunctionRegistryAndValidateTypes(AptUtils aptUtils, TypeElement elm,
        GlobalParsingContext context) {/*www . ja  va2 s.  c o  m*/
    final List<ExecutableElement> methods = ElementFilter.methodsIn(elm.getEnclosedElements());
    final Optional<String> keyspace = AnnotationTree.findKeyspaceForFunctionRegistry(aptUtils, elm);
    final FunctionParamParser paramParser = new FunctionParamParser(aptUtils);

    final TypeName parentType = TypeName.get(aptUtils.erasure(elm));

    //Not allow to declare function in system keyspaces
    if (keyspace.isPresent()) {
        final String keyspaceName = keyspace.get();
        aptUtils.validateFalse(
                FORBIDDEN_KEYSPACES.contains(keyspaceName)
                        || FORBIDDEN_KEYSPACES.contains(keyspaceName.toLowerCase()),
                "The provided keyspace '%s' on function registry class '%s' is forbidden because it is a system keyspace",
                keyspaceName, parentType);
    }

    aptUtils.validateFalse(keyspace.isPresent() && isBlank(keyspace.get()),
            "The declared keyspace for function registry '%s' should not be blank",
            elm.getSimpleName().toString());

    return methods.stream().map(method -> {
        final String methodName = method.getSimpleName().toString();
        final List<AnnotationTree> annotationTrees = AnnotationTree.buildFromMethodForParam(aptUtils, method);
        final List<? extends VariableElement> parameters = method.getParameters();
        final List<FunctionParamSignature> parameterSignatures = new ArrayList<>(parameters.size());
        for (int i = 0; i < parameters.size(); i++) {
            final VariableElement parameter = parameters.get(i);
            context.nestedTypesStrategy.validate(aptUtils, annotationTrees.get(i), method.toString(),
                    parentType);
            final FunctionParamSignature functionParamSignature = paramParser.parseParam(context,
                    annotationTrees.get(i), parentType, methodName, parameter.getSimpleName().toString());
            parameterSignatures.add(functionParamSignature);
        }

        //Validate return type
        final TypeMirror returnType = method.getReturnType();
        aptUtils.validateFalse(returnType.getKind() == TypeKind.VOID,
                "The return type for the method '%s' on class '%s' should not be VOID", method.toString(),
                elm.getSimpleName().toString());

        aptUtils.validateFalse(returnType.getKind().isPrimitive(),
                "Due to internal JDK API limitations, UDF/UDA return types cannot be primitive. "
                        + "Use their Object counterpart instead for method '%s' " + "in function registry '%s'",
                method.toString(), elm.getQualifiedName());

        final FunctionParamSignature returnTypeSignature = paramParser.parseParam(context,
                AnnotationTree.buildFromMethodForReturnType(aptUtils, method), parentType, methodName,
                "returnType");

        // Validate NOT system function comparing only name lowercase
        aptUtils.validateFalse(SYSTEM_FUNCTIONS_NAME.contains(methodName.toLowerCase()),
                "The name of the function '%s' in class '%s' is reserved for system functions", method,
                parentType);

        return new FunctionSignature(keyspace, parentType, methodName, returnTypeSignature,
                parameterSignatures);
    }).collect(toList());
}

From source file:com.github.hackersun.processor.factory.FactoryAnnotatedClass.java

/**
 * @throws ProcessingException if id() from annotation is null
 *//*  w ww .j a  v  a 2s . com*/
public FactoryAnnotatedClass(TypeElement classElement) throws ProcessingException {
    this.annotatedClassElement = classElement;
    Factory annotation = classElement.getAnnotation(Factory.class);
    id = annotation.id();

    if (StringUtils.isEmpty(id)) {
        throw new ProcessingException(classElement,
                "id() in @%s for class %s is null or empty! that's not allowed", Factory.class.getSimpleName(),
                classElement.getQualifiedName().toString());
    }

    // Get the full QualifiedTypeName
    try {
        Class<?> clazz = annotation.type();
        qualifiedGroupClassName = clazz.getCanonicalName();
        simpleFactoryGroupName = clazz.getSimpleName();
    } catch (MirroredTypeException mte) {
        DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror();
        TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
        qualifiedGroupClassName = classTypeElement.getQualifiedName().toString();
        simpleFactoryGroupName = classTypeElement.getSimpleName().toString();
    }
}

From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java

public static TypeElement getXmlRepresentationClass(TypeElement typeElement, String defaultSuffix) {
    List<ExecutableElement> methods = ElementFilter.methodsIn(typeElement.getEnclosedElements());
    for (ExecutableElement method : methods) {
        List<? extends AnnotationMirror> anmirs = method.getAnnotationMirrors();

        AnnotationMirror mirrorHttpMethod = findAnnotation(anmirs, RestConstants.GET);
        if (mirrorHttpMethod != null) {
            TypeMirror tm = method.getReturnType();
            if (tm != null && tm.getKind() == TypeKind.DECLARED) {
                TypeElement returnType = (TypeElement) ((DeclaredType) tm).asElement();
                if (returnType.getSimpleName().toString().endsWith(defaultSuffix)) {
                    return returnType;
                }//from  w w w  . j  a  v a  2 s  .  c  o  m
            }
        }
    }
    return null;
}

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  a  v  a  2s . 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:easymvp.compiler.EasyMVPProcessor.java

private String getSimpleClassName(TypeElement type) {
    return type.getSimpleName().toString();
}

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

private VelocityContext createAndInitializeVelocityContext(TypeElement type) {
    final VelocityContext vc = new VelocityContext();
    vc.put("className", type.getSimpleName().toString());
    vc.put("generationDate", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()));
    vc.put("packageName", getPackage(type).getQualifiedName().toString());
    vc.put("bindable", type.getAnnotation(Buildable.class).bindable());
    vc.put("generateGetters", type.getAnnotation(Buildable.class).generateGetters());
    return vc;//from  www .  j a  v  a2 s  .  c  o  m
}

From source file:ch.rasc.constgen.CodeGenerator.java

public CodeGenerator(TypeElement typeElement, Elements elements, boolean bsoncodecProject) {
    this.typeElement = typeElement;
    this.packageName = elements.getPackageOf(typeElement).getQualifiedName().toString();
    this.className = "C" + typeElement.getSimpleName();
    this.elements = elements;
    this.bsoncodecProject = bsoncodecProject;
}

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

private String buildFactoryFieldName(TypeElement element) {
    return String.format(FACTORY_FIELD_TPL, element.getSimpleName());
}

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//w ww .j a v  a  2 s  . c o m
 * @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:blue.lapis.pore.ap.event.EventVerifierProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
        for (TypeElement anno : annotations) {
            for (Element e : roundEnv.getElementsAnnotatedWith(anno)) {
                if (e.getKind() != ElementKind.CLASS) {
                    processingEnv.getMessager().printMessage(ERROR, "Found @" + anno.getSimpleName()
                            + " annotation on a " + e.getKind().name() + " element instead of a class element",
                            e);/*from   ww  w .j  av  a2s  . com*/
                    continue;
                }

                TypeElement type = (TypeElement) e;

                verifySuperClass(type);
                verifyPackage(type);
                verifyName(type);
                verifyEnclosedElements(type);
            }
        }
    }

    return false;
}