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

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

Introduction

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

Prototype

ElementKind INTERFACE

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

Click Source Link

Document

An interface not described by a more specific kind (like ANNOTATION_TYPE ).

Usage

From source file:Main.java

private static boolean _isInterface(TypeMirror typeMirror) {
    return typeMirror instanceof DeclaredType
            && ((DeclaredType) typeMirror).asElement().getKind() == ElementKind.INTERFACE;
}

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

private void collectFactories() {
    List<String> factoryClasses = annotationWrapper.getAsStrings(WITH_FACTORIES);
    if (factoryClasses.size() > 0) {
        int factoryMethodCount = 0;

        for (String factoryClass : factoryClasses) {

            final TypeElement element = context.elements
                    .getTypeElement(factoryClass.replaceAll("\\.class$", ""));

            factoryMethodCount += collectFactoryMethods(element, false);

            if (factoryMethodCount == 0) {
                context.error(element, "No valid factory method found in Factory selma class %s\\n "
                        + "A factory method method is public and returns a type not void, it takes a Class object or "
                        + "no parameter at all.", factoryClass);
            } else {

                TypeConstructorWrapper constructorWrapper = new TypeConstructorWrapper(context, element);
                if (!constructorWrapper.hasDefaultConstructor && element.getKind() != ElementKind.INTERFACE) {
                    context.error(element, "No default public constructor found in custom mapping class %s\\n"
                            + " Please add one", factoryClass);
                }//from  w ww.  j av a2s .  co m

                // Here we collect the name of the field to create in the Mapper generated class
                factoryFields.add(element);
            }

        }
    }

}

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 av a 2s.c o  m
        } 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:com.dspot.declex.action.Actions.java

private void addActions(String actions) {

    if (!EXTERNAL_ACTIONS.contains(actions)) {
        TypeElement typeElement = env.getProcessingEnvironment().getElementUtils().getTypeElement(actions);

        CLASSES: for (Element element : typeElement.getEnclosedElements()) {

            if (element.getKind().isClass()) {

                List<? extends TypeMirror> superTypesForGate = env.getProcessingEnvironment().getTypeUtils()
                        .directSupertypes(element.asType());
                for (TypeMirror gate : superTypesForGate) {
                    TypeElement superElementForGate = env.getProcessingEnvironment().getElementUtils()
                            .getTypeElement(gate.toString());
                    if (superElementForGate == null)
                        continue;
                    if (superElementForGate.getKind().equals(ElementKind.INTERFACE))
                        continue;
                    if (superElementForGate.asType().toString().equals(Object.class.getCanonicalName()))
                        continue;

                    //This is the Gate element, its parent it is the Holder
                    List<? extends TypeMirror> superTypesForHolder = env.getProcessingEnvironment()
                            .getTypeUtils().directSupertypes(superElementForGate.asType());
                    for (TypeMirror holder : superTypesForHolder) {
                        TypeElement superElementForHolder = env.getProcessingEnvironment().getElementUtils()
                                .getTypeElement(holder.toString());
                        if (superElementForHolder == null)
                            continue;
                        if (superElementForHolder.getKind().equals(ElementKind.INTERFACE))
                            continue;
                        if (superElementForHolder.asType().toString().equals(Object.class.getCanonicalName()))
                            continue;

                        addActionHolder(superElementForHolder.asType().toString(), true);

                        //This is the Holder element
                        continue CLASSES;
                    }//from  w w w  .j av a  2s. c  o m
                }

            }

        }

        EXTERNAL_ACTIONS.add(actions);
    }

}

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/*from   w w  w  .  j av  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:org.immutables.value.processor.meta.ValueType.java

public String getInheritsKeyword() {
    return element.getKind() == ElementKind.INTERFACE || element.getKind() == ElementKind.ANNOTATION_TYPE
            ? "implements"
            : "extends";
}

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

private void collectCustomMappers() {

    List<String> customClasses = annotationWrapper.getAsStrings(WITH_CUSTOM);
    if (customClasses.size() > 0) {
        int mappingMethodCount = 0;

        for (String customMapper : customClasses) {

            final TypeElement element = context.elements
                    .getTypeElement(customMapper.replaceAll("\\.class$", ""));

            mappingMethodCount += collectCustomMethods(element, false);

            if (mappingMethodCount == 0) {
                context.error(element, "No valid mapping method found in custom selma class %s\\n "
                        + "A custom mapping method is public and returns a type not void, it takes one parameter or"
                        + " more if you specified datasource.", customMapper);
            } else {

                TypeConstructorWrapper constructorWrapper = new TypeConstructorWrapper(context, element);
                if (!constructorWrapper.hasDefaultConstructor && element.getKind() != ElementKind.INTERFACE) {
                    context.error(element, "No default public constructor found in custom mapping class %s\\n"
                            + " Please add one", customMapper);
                }//w w w. j  a v a2  s.co  m

                // Here we collect the name of the field to create in the Mapper generated class
                customMapperFields.add(element);
            }

        }
    }

}

From source file:com.dspot.declex.action.Actions.java

private void createInformationForMethods(Element typeElement, ActionInfo actionInfo,
        List<String> methodsHandled) {

    if (methodsHandled == null) {
        methodsHandled = new LinkedList<>();
    }/*from   ww  w  .ja  v  a 2s .co  m*/

    for (Element elem : typeElement.getEnclosedElements()) {

        if (elem.getKind() == ElementKind.METHOD) {
            if (methodsHandled.contains(elem.toString()))
                continue;

            final ExecutableElement element = (ExecutableElement) elem;

            List<ActionMethodParam> params = new LinkedList<>();
            for (VariableElement param : element.getParameters()) {

                List<Annotation> annotations = new LinkedList<>();
                for (Class<? extends Annotation> annotation : ACTION_ANNOTATION) {
                    Annotation containedAnnotation = param.getAnnotation(annotation);
                    if (containedAnnotation != null) {
                        annotations.add(containedAnnotation);
                    }
                }

                final AbstractJClass paramType = codeModelHelper.elementTypeToJClass(param);

                ActionMethodParam actionMethodParam = new ActionMethodParam(param.getSimpleName().toString(),
                        paramType, annotations);
                params.add(actionMethodParam);
            }

            List<Annotation> annotations = new LinkedList<>();
            for (Class<? extends Annotation> annotation : ACTION_ANNOTATION) {
                Annotation containedAnnotation = element.getAnnotation(annotation);
                if (containedAnnotation != null) {
                    annotations.add(containedAnnotation);
                }
            }

            String javaDoc = env.getProcessingEnvironment().getElementUtils().getDocComment(element);

            final String clazz = element.getReturnType().toString();

            actionInfo.addMethod(element.getSimpleName().toString(), clazz, javaDoc, params, annotations);

            methodsHandled.add(element.toString());
        }
    }

    List<? extends TypeMirror> superTypes = env.getProcessingEnvironment().getTypeUtils()
            .directSupertypes(typeElement.asType());
    for (TypeMirror type : superTypes) {
        TypeElement superElement = env.getProcessingEnvironment().getElementUtils()
                .getTypeElement(type.toString());
        if (superElement == null)
            continue;
        if (superElement.getKind().equals(ElementKind.INTERFACE))
            continue;
        if (superElement.asType().toString().equals(Object.class.getCanonicalName()))
            continue;
        createInformationForMethods(superElement, actionInfo, methodsHandled);
    }

}

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

public static boolean isInjectionTarget(CompilationController controller, TypeElement typeElement) {
    if (ElementKind.INTERFACE != typeElement.getKind()) {
        List<? extends AnnotationMirror> annotations = typeElement.getAnnotationMirrors();
        boolean found = false;

        for (AnnotationMirror m : annotations) {
            Name qualifiedName = ((TypeElement) m.getAnnotationType().asElement()).getQualifiedName();
            if (qualifiedName.contentEquals("javax.jws.WebService")) {
                //NOI18N
                found = true;//from  w  w  w . ja  v  a  2s.  c o  m
                break;
            }
            if (qualifiedName.contentEquals("javax.jws.WebServiceProvider")) {
                //NOI18N
                found = true;
                break;
            }
        }
        if (found) {
            return true;
        }
    }
    return false;
}

From source file:org.ez18n.apt.processor.GwtXmlProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
        return true;
    }/*from w  ww. j  ava2 s .co  m*/

    final List<TypeElement> bundleTypes = new ArrayList<TypeElement>();
    for (Element element : roundEnv.getElementsAnnotatedWith(MessageBundle.class)) {
        if (element.getKind() != ElementKind.INTERFACE) {
            continue;
        }
        final TypeElement bundleType = (TypeElement) element;
        bundleTypes.add(bundleType);
    }

    if (bundleTypes.isEmpty()) {
        return true;
    }

    String packageName = null;
    for (TypeElement typeElement : bundleTypes) {
        String typeElementPackage = typeElement.getEnclosingElement().toString();
        if (packageName == null) {
            packageName = typeElementPackage;
        } else {
            packageName = intersectPackage(packageName, typeElementPackage);
        }
    }

    try {
        final FileObject file = processingEnv.getFiler().createResource(SOURCE_OUTPUT,
                packageName == null ? "net.courtanet.b2c" : packageName, "Generated.gwt.xml");
        final Writer writer = file.openWriter();
        writer.write(getCode(bundleTypes));
        writer.close();
    } catch (FilerException e) {
        return false;
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage());
    }
    return false;
}