Example usage for javax.lang.model.element ElementKind CLASS

List of usage examples for javax.lang.model.element ElementKind CLASS

Introduction

In this page you can find the example usage for javax.lang.model.element ElementKind CLASS.

Prototype

ElementKind CLASS

To view the source code for javax.lang.model.element ElementKind CLASS.

Click Source Link

Document

A class not described by a more specific kind (like ENUM ).

Usage

From source file:cop.raml.mocks.MockUtils.java

public static TypeElementMock createProject() {
    VariableElementMock id = new VariableElementMock("id", int.class);
    id.setDocComment(TestUtils.joinStrings("Unique project id", "{@name Unique project id}", "{@example 666}"));
    VariableElementMock name = new VariableElementMock("name", String.class);
    name.setDocComment(TestUtils.joinStrings("Name of the project", "{@example The Project}"));

    TypeElementMock typeElement = new TypeElementMock("cop.raml.dto.Project", ElementKind.CLASS);
    typeElement.addEnclosedElement(id);/*from w ww . jav a2s  .com*/
    typeElement.addEnclosedElement(name);

    return typeElement;
}

From source file:info.archinnov.achilles.internals.parser.validator.BeanValidator.java

public static void validateIsAConcreteNonFinalClass(AptUtils aptUtils, TypeElement typeElement) {
    final Name name = typeElement.getQualifiedName();
    aptUtils.validateTrue(typeElement.getKind() == ElementKind.CLASS, "Bean type '%s' should be a class", name);
    final Set<Modifier> modifiers = typeElement.getModifiers();
    aptUtils.validateFalse(modifiers.contains(Modifier.ABSTRACT), "Bean type '%s' should not be abstract",
            name);/*from   w w w . ja  va 2  s  . co m*/
    aptUtils.validateFalse(modifiers.contains(Modifier.FINAL), "Bean type '%s' should not be final", name);
}

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   www.  jav a  2  s.c  om
                    continue;
                }

                TypeElement type = (TypeElement) e;

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

    return false;
}

From source file:cop.raml.mocks.MockUtils.java

private static TypeElementMock createPrimitiveElement(@NotNull Class<?> cls) {
    TypeElementMock element = new TypeElementMock(cls.getName(), ElementKind.CLASS);
    element.setType(new TypeMirrorMock(element, TypeMirrorMock.getTypeKind(cls)));
    return setAnnotations(element, cls);
}

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

void emitCustomMappersFields(JavaWriter writer, boolean assign) throws IOException {
    for (TypeElement customMapperField : customMapperFields) {
        final String field = String.format(CUSTOM_MAPPER_FIELD_TPL,
                customMapperField.getSimpleName().toString());
        if (assign) {
            if (customMapperField.getKind() != ElementKind.INTERFACE
                    && !(customMapperField.getKind() == ElementKind.CLASS
                            && customMapperField.getModifiers().contains(ABSTRACT))) {
                TypeConstructorWrapper constructorWrapper = new TypeConstructorWrapper(context,
                        customMapperField);
                // assign the customMapper field to a newly created instance passing to it the declared source params
                writer.emitStatement("this.%s = new %s(%s)", field,
                        customMapperField.getQualifiedName().toString(),
                        constructorWrapper.hasMatchingSourcesConstructor ? context.newParams() : "");
            }//from  www  .j ava 2 s. c  om
        } 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(customMapperField.asType().toString(),
                    String.format(CUSTOM_MAPPER_FIELD_TPL, customMapperField.getSimpleName().toString()),
                    EnumSet.of(PRIVATE));

            writer.emitEmptyLine();
            writer.emitJavadoc("Custom Mapper setter for " + field);

            EnumSet<Modifier> modifiers = EnumSet.of(PUBLIC, FINAL);
            if (ioC == IoC.CDI) {
                modifiers = EnumSet.of(PUBLIC);
            }
            writer.beginMethod("void", "setCustomMapper" + customMapperField.getSimpleName(), modifiers,
                    customMapperField.asType().toString(), "mapper");
            writer.emitStatement("this.%s = mapper", field);
            writer.endMethod();
            writer.emitEmptyLine();
        }
    }
}

From source file:therian.buildweaver.StandardOperatorsProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    try {/*from  ww  w.  j a  va2  s  .  c o  m*/
        final FileObject resource = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT,
                StringUtils.substringBeforeLast(TARGET_CLASSNAME, ".").replace('.', '/'),
                StringUtils.substringAfterLast(TARGET_CLASSNAME, ".") + ".class");

        if (resource.getLastModified() > 0L) {
            processingEnv.getMessager().printMessage(Kind.NOTE,
                    String.format("%s already generated", TARGET_CLASSNAME));
            return false;
        }
    } catch (IOException e1) {
        // expected, swallow
    }
    try {
        ClassUtils.getClass(TARGET_CLASSNAME);
        processingEnv.getMessager().printMessage(Kind.ERROR,
                String.format("%s exists on classpath", TARGET_CLASSNAME));
        return false;
    } catch (ClassNotFoundException e) {
        // expected, swallow
    }

    if (roundEnv.processingOver()) {
        write();
        return true;
    }
    for (TypeElement ann : annotations) {
        final Set<? extends Element> standardOperatorElements = roundEnv.getElementsAnnotatedWith(ann);
        originatingElements.addAll(standardOperatorElements);

        for (Element element : standardOperatorElements) {
            Validate.validState(isValidStandardOperator(element), "%s is not a valid @StandardOperator",
                    appendTo(new StringBuilder(), element).toString());

            if (element.getKind() == ElementKind.CLASS) {
                operators.add(appendTo(new StringBuilder("new "), element).append("()").toString());
            }
            if (element.getKind() == ElementKind.METHOD) {
                operators.add(appendTo(new StringBuilder(), element).append("()").toString());
            }
            if (element.getKind() == ElementKind.FIELD) {
                operators.add(appendTo(new StringBuilder(), element).toString());
            }
        }
    }
    return true;
}

From source file:cop.raml.mocks.MockUtils.java

private static TypeElementMock createClassElement(@NotNull Class<?> cls) throws ClassNotFoundException {
    TypeElementMock element = new TypeElementMock(cls.getName(), ElementKind.CLASS);
    element.setType(new TypeMirrorMock(element, TypeMirrorMock.getTypeKind(cls)));

    if (cls.getName().startsWith("cop.") || cls.getName().startsWith("spring.")) {
        VariableElementMock var;

        for (Field field : cls.getDeclaredFields())
            if ((var = createVariable(field.getName(), field.getType(),
                    Modifier.isStatic(field.getModifiers()))) != null)
                element.addEnclosedElement(setAnnotations(var, field));

        ExecutableElementMock exe;//from  w  w  w  . j av  a2  s.  c  om

        for (Method method : cls.getDeclaredMethods())
            if ((exe = createExecutable(method)) != null)
                element.addEnclosedElement(setAnnotations(exe, method));
    }

    return setAnnotations(element, cls);
}

From source file:org.kie.workbench.common.forms.adf.processors.FormDefinitionGenerator.java

public void generate() throws Exception {
    TypeElement annotation = context.getElementUtils().getTypeElement(FORM_DEFINITON_ANNOTATION);

    Set<? extends Element> formDefinitions = context.getRoundEnvironment().getElementsAnnotatedWith(annotation);

    context.getMessager().printMessage(Diagnostic.Kind.NOTE,
            "FormDefinitions found:  " + formDefinitions.size());

    // Initializing list type to avoid getting the element each time.
    listType = context.getElementUtils().getTypeElement(List.class.getName()).asType();
    enumType = context.getElementUtils().getTypeElement(Enum.class.getName()).asType();

    for (Element element : formDefinitions) {
        if (element.getKind().equals(ElementKind.CLASS)) {
            processFormDefinition((TypeElement) element);
        }//from   w  w  w .  j  av  a  2  s .  c  o m
    }
}

From source file:cop.raml.processor.rest.SpringRestImpl.java

private static String getClassRequestPath(TypeElement classElement) {
    if (classElement == null || classElement.getKind() != ElementKind.CLASS)
        return null;

    RestController annotation = classElement.getAnnotation(RestController.class);
    return annotation != null && StringUtils.isNoneBlank(annotation.value()) ? annotation.value() : null;
}

From source file:therian.buildweaver.StandardOperatorsProcessor.java

/**
 * Must be a public static concrete class with a default constructor, public static zero-arg method, or public
 * static final field./*from   www .  j a v  a2s  .  c om*/
 *
 * @param e
 * @return boolean
 */
private static boolean isValidStandardOperator(final Element e) {
    if (e.getKind() == ElementKind.FIELD) {
        return e.getModifiers().containsAll(EnumSet.of(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL));
    }
    if (e.getKind() == ElementKind.METHOD) {
        return e.getModifiers().containsAll(EnumSet.of(Modifier.PUBLIC, Modifier.STATIC))
                && ((ExecutableElement) e).getParameters().isEmpty();
    }
    if (e.getKind() == ElementKind.CLASS) {
        if (e.getModifiers().contains(Modifier.ABSTRACT) || findDefaultConstructor((TypeElement) e) == null) {
            return false;
        }
        Element current = e;
        while (current.getKind() == ElementKind.CLASS) {
            final TypeElement t = (TypeElement) current;
            if (t.getNestingKind() == NestingKind.TOP_LEVEL) {
                return true;
            }
            if (t.getNestingKind() == NestingKind.MEMBER && t.getModifiers().contains(Modifier.STATIC)) {
                current = t.getEnclosingElement();
                continue;
            }
            break;
        }
    }
    return false;
}