Examples of TypeMirror


Examples of com.redhat.ceylon.compiler.loader.mirror.TypeMirror

                paramName = paramMirror.getName();
           
            Parameter parameter = new Parameter();
            parameter.setName(paramName);
           
            TypeMirror typeMirror = paramMirror.getType();
            Module module = Decl.getModuleContainer((Scope) decl);

            ProducedType type;
            if(isVariadic){
                // possibly make it optional
                TypeMirror variadicType = typeMirror.getComponentType();
                // we pretend it's toplevel because we want to get magic string conversion for variadic methods
                type = obtainType(Decl.getModuleContainer((Scope)decl), variadicType, (Scope)decl, TypeLocation.TOPLEVEL, VarianceLocation.CONTRAVARIANT);
                if(!isCeylon && !variadicType.isPrimitive()){
                    // Java parameters are all optional unless primitives
                    ProducedType optionalType = getOptionalType(type, module);
                    optionalType.setUnderlyingType(type.getUnderlyingType());
                    type = optionalType;
                }
View Full Code Here

Examples of com.sun.mirror.type.TypeMirror

    }
    return result_param;
  }

  public static TypeMirror getMethodReturnType(MethodDeclaration method) {
    TypeMirror result_type;
    ParameterDeclaration result_param = getResultParameter(method);
    if (result_param != null) {
      result_type = result_param.getType();
    } else
      result_type = method.getReturnType();
View Full Code Here

Examples of com.sun.mirror.type.TypeMirror

         || !modifiers.contains(Modifier.FINAL) ) {
      throw new RuntimeException("Field " + field.getSimpleName() + " is not declared public static final");
    }

    // Check suported types (int, long, float, String)
    TypeMirror field_type = field.getType();
    if ( field_type instanceof PrimitiveType ) {
      PrimitiveType field_type_prim = (PrimitiveType)field_type;
      PrimitiveType.Kind field_kind = field_type_prim.getKind();
      if ( field_kind != PrimitiveType.Kind.INT
           && field_kind != PrimitiveType.Kind.LONG
           && field_kind != PrimitiveType.Kind.FLOAT ) {
        throw new RuntimeException("Field " + field.getSimpleName() + " is not of type 'int', 'long' or 'float'");
      }
    } else if ( "java.lang.String".equals(field_type.toString()) ) {
    } else {
      throw new RuntimeException("Field " + field.getSimpleName() + " is not a primitive type or String");
    }

    Object field_value = field.getConstantValue();
View Full Code Here

Examples of javax.lang.model.type.TypeMirror

        writer.println("<h1>" + title + "</h1>");

        showDocumentationAndFieldInjections(writer, roundEnv, classElement, "");

        // This code is not my fault, it seems to honestly be the hacky way to find a class name in APT :)
        TypeMirror consumerType = null;
        try {
            uriEndpoint.consumerClass();
        } catch (MirroredTypeException mte) {
            consumerType = mte.getTypeMirror();
        }

        boolean found = false;
        String consumerClassName = null;
        String consumerPrefix = Strings.getOrElse(uriEndpoint.consumerPrefix(), "");
        if (consumerType != null) {
            consumerClassName = consumerType.toString();
            TypeElement consumerElement = findTypeElement(roundEnv, consumerClassName);
            if (consumerElement != null) {
                writer.println("<h2>" + scheme + " consumer" + "</h2>");
                showDocumentationAndFieldInjections(writer, roundEnv, consumerElement, consumerPrefix);
                found = true;
View Full Code Here

Examples of javax.lang.model.type.TypeMirror

                    String defaultValue = param.defaultValue();
                    String defaultValueNote = param.defaultValueNote();

                    // if the field type is a nested parameter then iterate through its fields
                    TypeMirror fieldType = fieldElement.asType();
                    String fieldTypeName = fieldType.toString();
                    TypeElement fieldTypeElement = findTypeElement(roundEnv, fieldTypeName);
                    UriParams fieldParams = null;
                    if (fieldTypeElement != null) {
                        fieldParams = fieldTypeElement.getAnnotation(UriParams.class);
                    }
                    if (fieldParams != null) {
                        String nestedPrefix = prefix;
                        String extraPrefix = fieldParams.prefix();
                        if (!isNullOrEmpty(extraPrefix)) {
                            nestedPrefix += extraPrefix;
                        }
                        findClassProperties(roundEnv, endpointOptions, fieldTypeElement, nestedPrefix);
                    } else {
                        String docComment = elementUtils.getDocComment(fieldElement);
                        if (isNullOrEmpty(docComment)) {
                            String setter = "set" + fieldName.substring(0, 1).toUpperCase();
                            if (fieldName.length() > 1) {
                                setter += fieldName.substring(1);
                            }
                            //  lets find the setter
                            List<ExecutableElement> methods = ElementFilter.methodsIn(classElement.getEnclosedElements());
                            for (ExecutableElement method : methods) {
                                String methodName = method.getSimpleName().toString();
                                if (setter.equals(methodName) && method.getParameters().size() == 1) {
                                    String doc = elementUtils.getDocComment(method);
                                    if (!isNullOrEmpty(doc)) {
                                        docComment = doc;
                                        break;
                                    }
                                }
                            }
                        }
                        if (docComment == null) {
                            docComment = "";
                        }

                        // gather enums
                        Set<String> enums = new LinkedHashSet<>();
                        boolean isEnum = fieldTypeElement != null && fieldTypeElement.getKind() == ElementKind.ENUM;
                        if (isEnum) {
                            TypeElement enumClass = findTypeElement(roundEnv, fieldTypeElement.asType().toString());
                            // find all the enum constants which has the possible enum value that can be used
                            List<VariableElement> fields = ElementFilter.fieldsIn(enumClass.getEnclosedElements());
                            for (VariableElement var : fields) {
                                if (var.getKind() == ElementKind.ENUM_CONSTANT) {
                                    String val = var.toString();
                                    enums.add(val);
                                }
                            }
                        }

                        EndpointOption option = new EndpointOption(name, fieldTypeName, defaultValue, defaultValueNote,  docComment.trim(), isEnum, enums);
                        endpointOptions.add(option);
                    }
                }
            }
            TypeElement baseTypeElement = null;
            TypeMirror superclass = classElement.getSuperclass();
            if (superclass != null) {
                String superClassName = canonicalClassName(superclass.toString());
                baseTypeElement = findTypeElement(roundEnv, superClassName);
            }
            if (baseTypeElement != null) {
                classElement = baseTypeElement;
            } else {
View Full Code Here

Examples of javax.lang.model.type.TypeMirror

            return false;
        }
        if (isKindMatched(environment, type) == false) {
            return false;
        }
        TypeMirror datamodel = environment.getDeclaredType(DataModel.class);
        return environment.getTypeUtils().isSubtype(type, datamodel);
    }
View Full Code Here

Examples of javax.lang.model.type.TypeMirror

     * @throws IllegalArgumentException if some parameters were {@code null}
     */
    public Expression toMetaData(OperatorPortDeclaration var, int position) {
        Precondition.checkMustNotBeNull(var, "var"); //$NON-NLS-1$
        NamedType type;
        TypeMirror representation = var.getType().getRepresentation();
        List<AnnotationElement> members = Lists.create();
        members.add(factory.newAnnotationElement(
                factory.newSimpleName("name"),
                Models.toLiteral(factory, var.getName())));
        members.add(factory.newAnnotationElement(
View Full Code Here

Examples of javax.lang.model.type.TypeMirror

        works.add(type);
        Set<TypeMirror> saw = Sets.create();
        List<TypeElement> types = Lists.create();
        int countDown = 100; // avoid infinite loop
        while (works.isEmpty() == false && --countDown >= 0) {
            TypeMirror target = works.removeFirst();
            if (saw.contains(target)) {
                continue;
            }
            saw.add(target);
            Element element = environment.getTypeUtils().asElement(target);
View Full Code Here

Examples of javax.lang.model.type.TypeMirror

            ModelFactory f = context.environment.getFactory();
            ImportBuilder ib = context.importer;
            Jsr269 conv = new Jsr269(f);
            List<Expression> parameterTypeLiterals = Lists.create();
            for (VariableElement parameter : helperMethod.getParameters()) {
                TypeMirror type = context.environment.getErasure(parameter.asType());
                parameterTypeLiterals.add(new TypeBuilder(f, ib.resolve(conv.convert(type)))
                    .dotClass()
                    .toExpression());
            }
            Expression attribute = new TypeBuilder(f, ib.toType(OperatorHelper.class))
View Full Code Here

Examples of javax.lang.model.type.TypeMirror

            List<OperatorPortDeclaration> parameters) {
        assert output != null;
        assert inputPorts != null;
        assert parameters != null;
        Types types = environment.getTypeUtils();
        TypeMirror outputType = output.getType().getRepresentation();
        for (OperatorPortDeclaration input : inputPorts) {
            if (types.isSameType(outputType, input.getType().getRepresentation())) {
                return new OperatorPortDeclaration(
                        output.getKind(),
                        output.getDocumentation(),
                        output.getName(),
                        PortTypeDescription.reference(outputType, input.getName()),
                        output.getParameterPosition(),
                        null);
            }
        }
        DeclaredType classType = environment.getDeclaredType(Class.class);
        for (OperatorPortDeclaration param : parameters) {
            // check is form of M<T>
            TypeMirror paramType = param.getType().getRepresentation();
            if (paramType.getKind() != TypeKind.DECLARED) {
                continue;
            }
            DeclaredType declParamType = (DeclaredType) paramType;
            if (declParamType.getTypeArguments().size() != 1) {
                continue;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.