Example usage for javax.lang.model.type TypeMirror toString

List of usage examples for javax.lang.model.type TypeMirror toString

Introduction

In this page you can find the example usage for javax.lang.model.type TypeMirror toString.

Prototype

String toString();

Source Link

Document

Returns an informative string representation of this type.

Usage

From source file:org.mule.devkit.apt.model.AnnotationProcessorIdentifiable.java

private boolean isMap(TypeMirror type) {
    if (type.toString().startsWith(Map.class.getName())) {
        return true;
    }/*ww  w  .ja  v a  2 s .c om*/

    List<? extends TypeMirror> inherits = types.directSupertypes(type);
    for (TypeMirror inherit : inherits) {
        if (isMap(inherit)) {
            return true;
        }
    }

    return false;
}

From source file:org.mule.devkit.apt.model.AnnotationProcessorIdentifiable.java

private boolean isEnum(TypeMirror type) {
    if (type.toString().startsWith(Enum.class.getName())) {
        return true;
    }/*  www . ja  v a  2 s .c  o  m*/

    List<? extends TypeMirror> inherits = types.directSupertypes(type);
    for (TypeMirror inherit : inherits) {
        if (isEnum(inherit)) {
            return true;
        }
    }

    return false;
}

From source file:org.mule.devkit.apt.model.AnnotationProcessorIdentifiable.java

private boolean isArrayOrList(TypeMirror type) {
    if (type.toString().equals("byte[]")) {
        return false;
    }/*from w  w w  .  j  a v a  2s. c om*/

    if (type.getKind() == TypeKind.ARRAY) {
        return true;
    }

    if (type.toString().startsWith(List.class.getName())) {
        return true;
    }

    List<? extends TypeMirror> inherits = types.directSupertypes(type);
    for (TypeMirror inherit : inherits) {
        if (isArrayOrList(inherit)) {
            return true;
        }
    }

    return false;
}

From source file:org.androidtransfuse.analysis.ActivityAnalysis.java

public ComponentDescriptor analyze(ASTType input) {

    Activity activityAnnotation = input.getAnnotation(Activity.class);
    PackageClass activityClassName;//from w  w  w. j a  v  a  2s  .  com
    ComponentDescriptor activityDescriptor = null;

    if (input.extendsFrom(astClassFactory.getType(android.app.Activity.class))) {
        //vanilla Android activity
        PackageClass activityPackageClass = input.getPackageClass();
        activityClassName = buildPackageClass(input, activityPackageClass.getClassName());
    } else {
        //generated Android activity
        activityClassName = buildPackageClass(input, activityAnnotation.name());

        Layout layoutAnnotation = input.getAnnotation(Layout.class);
        LayoutHandler layoutHandlerAnnotation = input.getAnnotation(LayoutHandler.class);

        TypeMirror type = getTypeMirror(new ActivityTypeMirrorRunnable(activityAnnotation));

        String activityType = type == null ? android.app.Activity.class.getName() : type.toString();

        Integer layout = layoutAnnotation == null ? null : layoutAnnotation.value();

        AnalysisContext context = analysisContextFactory.buildAnalysisContext(buildVariableBuilderMap(type));

        InjectionNode layoutHandlerInjectionNode = buildLayoutHandlerInjectionNode(layoutHandlerAnnotation,
                context);

        activityDescriptor = new ComponentDescriptor(activityType, activityClassName);

        //application generation profile
        setupActivityProfile(activityType, activityDescriptor, input, context, layout,
                layoutHandlerInjectionNode);
    }

    //add manifest elements
    setupManifest(activityClassName.getFullyQualifiedName(), activityAnnotation, input);

    return activityDescriptor;
}

From source file:org.mule.devkit.module.generation.AbstractMessageGenerator.java

protected Map<String, FieldVariableElement> generateFieldForEachSetter(DefinedClass transferObjectClass,
        TypeElement transferObject) {
    Map<String, AbstractMessageGenerator.FieldVariableElement> fields = new HashMap<String, FieldVariableElement>();
    java.util.List<ExecutableElement> methods = ElementFilter.methodsIn(transferObject.getEnclosedElements());
    for (ExecutableElement method : methods) {
        String methodName = method.getSimpleName().toString();
        if (!methodName.startsWith("set") || method.getReturnType().getKind() != TypeKind.VOID
                || method.getParameters().size() != 1) {
            continue;
        }/* w  ww . j  a  v  a2s .c o m*/

        String fieldName = StringUtils.uncapitalize(methodName.substring(methodName.indexOf("set") + 3));
        TypeMirror fieldTypeMirror = method.getParameters().get(0).asType();
        FieldVariable field = null;
        if (fieldTypeMirror.toString().contains(ProcessorCallback.class.getName())) {
            field = transferObjectClass.field(Modifier.PRIVATE, ref(MessageProcessor.class), fieldName);
        } else {
            field = transferObjectClass.field(Modifier.PRIVATE, ref(Object.class), fieldName);
        }
        FieldVariable fieldType = transferObjectClass.field(Modifier.PRIVATE, ref(fieldTypeMirror),
                fieldName + "Type");
        fields.put(fieldName, new AbstractMessageGenerator.FieldVariableElement(field, fieldType, null));
    }
    return fields;
}

From source file:org.netbeans.jpa.modeler.spec.extend.JavaClass.java

@Override
public void load(EntityMappings entityMappings, TypeElement element, boolean fieldAccess) {
    this.setId(NBModelerUtil.getAutoGeneratedStringId());

    this.clazz = element.getSimpleName().toString();
    if (element.getModifiers().contains(Modifier.ABSTRACT)) {
        this.setAbstract(true);
    }/*from  www . jav a2  s .c om*/
    for (TypeMirror mirror : element.getInterfaces()) {
        if (Serializable.class.getName().equals(mirror.toString())) {
            continue;
        }
        this.addInterface(mirror.toString());
    }
    this.setAnnotation(JavaSourceParserUtil.getNonEEAnnotation(element));
}

From source file:com.contentful.vault.compiler.Processor.java

private void parseContentType(TypeElement element, Map<TypeElement, ModelInjection> models) {
    String id = element.getAnnotation(ContentType.class).value();
    if (id.isEmpty()) {
        error(element, "@%s id may not be empty. (%s)", ContentType.class.getSimpleName(),
                element.getQualifiedName());
        return;// w  w  w .  j a  v  a2 s .  c om
    }

    if (!isSubtypeOfType(element.asType(), Resource.class.getName())) {
        error(element, "Classes annotated with @%s must extend \"" + Resource.class.getName() + "\". (%s)",
                ContentType.class.getSimpleName(), element.getQualifiedName());
        return;
    }

    Set<FieldMeta> fields = new LinkedHashSet<>();
    Set<String> memberIds = new LinkedHashSet<>();
    for (Element enclosedElement : element.getEnclosedElements()) {
        Field field = enclosedElement.getAnnotation(Field.class);
        if (field == null) {
            continue;
        }

        String fieldId = field.value();
        if (fieldId.isEmpty()) {
            fieldId = enclosedElement.getSimpleName().toString();
        }

        Set<Modifier> modifiers = enclosedElement.getModifiers();
        if (modifiers.contains(Modifier.STATIC)) {
            error(element, "@%s elements must not be static. (%s.%s)", Field.class.getSimpleName(),
                    element.getQualifiedName(), enclosedElement.getSimpleName());
            return;
        }
        if (modifiers.contains(Modifier.PRIVATE)) {
            error(element, "@%s elements must not be private. (%s.%s)", Field.class.getSimpleName(),
                    element.getQualifiedName(), enclosedElement.getSimpleName());
            return;
        }

        if (!memberIds.add(fieldId)) {
            error(element, "@%s for the same id (\"%s\") was used multiple times in the same class. (%s)",
                    Field.class.getSimpleName(), fieldId, element.getQualifiedName());
            return;
        }

        FieldMeta.Builder fieldBuilder = FieldMeta.builder();
        if (isList(enclosedElement)) {
            DeclaredType declaredType = (DeclaredType) enclosedElement.asType();
            List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
            if (typeArguments.size() == 0) {
                error(element, "Array fields must have a type parameter specified. (%s.%s)",
                        element.getQualifiedName(), enclosedElement.getSimpleName());
                return;
            }

            TypeMirror arrayType = typeArguments.get(0);
            if (!isValidListType(arrayType)) {
                error(element, "Invalid list type \"%s\" specified. (%s.%s)", arrayType.toString(),
                        element.getQualifiedName(), enclosedElement.getSimpleName());
                return;
            }

            String sqliteType = null;
            if (String.class.getName().equals(arrayType.toString())) {
                sqliteType = SqliteUtils.typeForClass(List.class.getName());
            }

            fieldBuilder.setSqliteType(sqliteType).setArrayType(arrayType.toString());
        } else {
            TypeMirror enclosedType = enclosedElement.asType();
            String linkType = getLinkType(enclosedType);
            String sqliteType = null;
            if (linkType == null) {
                sqliteType = SqliteUtils.typeForClass(enclosedType.toString());
                if (sqliteType == null) {
                    error(element, "@%s specified for unsupported type (\"%s\"). (%s.%s)",
                            Field.class.getSimpleName(), enclosedType.toString(), element.getQualifiedName(),
                            enclosedElement.getSimpleName());
                    return;
                }
            }

            fieldBuilder.setSqliteType(sqliteType).setLinkType(linkType);
        }

        fields.add(fieldBuilder.setId(fieldId).setName(enclosedElement.getSimpleName().toString())
                .setType(enclosedElement.asType()).build());
    }

    if (fields.size() == 0) {
        error(element, "Model must contain at least one @%s element. (%s)", Field.class.getSimpleName(),
                element.getQualifiedName());
        return;
    }

    ClassName injectionClassName = getInjectionClassName(element, SUFFIX_MODEL);
    String tableName = "entry_" + SqliteUtils.hashForId(id);
    models.put(element, new ModelInjection(id, injectionClassName, element, tableName, fields));
}

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  w  ww  . ja  va  2s  .c  o 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: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  a v  a  2s  .com*/
                }

            }

        }

        EXTERNAL_ACTIONS.add(actions);
    }

}

From source file:org.versly.rest.wsdoc.AnnotationProcessor.java

private void scanForWebsocket(ExecutableElement executableElement,
        RestDocumentation.RestApi.Resource.Method doc) {
    for (VariableElement var : executableElement.getParameters()) {
        TypeMirror varType = var.asType();
        if (varType.toString().equalsIgnoreCase("org.atmosphere.cpr.AtmosphereResource")) {
            doc.setWebsocket(true);//  w w w. j a va  2 s .  c o  m
            return;
        }
    }
}