Package com.strobel.assembler.metadata

Examples of com.strobel.assembler.metadata.TypeReference


                //
                // T t; t = (T)(t + n) => t += n
                //

                final CastExpression castExpression = (CastExpression) right;
                final TypeReference castType = castExpression.getType().toTypeReference();
                final Expression castedValue = castExpression.getExpression();

                if (castType != null &&
                    castType.isPrimitive() &&
                    castedValue instanceof BinaryOperatorExpression) {

                    final ResolveResult leftResult = _resolver.apply(left);

                    if (leftResult != null &&
View Full Code Here


        return null;
    }

    private String getNameForType(final TypeReference type) {

        TypeReference nameSource = type;

        String name;

        if (nameSource.isArray()) {
            name = "array";
        }
        else if (StringUtilities.equals(nameSource.getInternalName(), "java/lang/Throwable")) {
            name = "t";
        }
        else if (StringUtilities.endsWith(nameSource.getName(), "Exception")) {
            name = "ex";
        }
        else if (StringUtilities.endsWith(nameSource.getName(), "List")) {
            name = "list";
        }
        else if (StringUtilities.endsWith(nameSource.getName(), "Set")) {
            name = "set";
        }
        else if (StringUtilities.endsWith(nameSource.getName(), "Collection")) {
            name = "collection";
        }
        else {
            name = BUILT_IN_TYPE_NAMES.get(nameSource.getInternalName());

            if (name != null) {
                return name;
            }

            if (!nameSource.isDefinition()) {
                final TypeDefinition resolvedType = nameSource.resolve();

                if (resolvedType != null) {
                    nameSource = resolvedType;
                }
            }

            name = nameSource.getSimpleName();

            //
            // Remove leading 'I' for interfaces.
            //
            if (name.length() > 2 &&
View Full Code Here

        if (boxedValueResult == null || boxedValueResult.getType() == null) {
            return;
        }

        final TypeReference targetType = ((MethodReference) outerBoxMethod).getReturnType();
        final TypeReference sourceType = boxedValueResult.getType();

        switch (MetadataHelper.getNumericConversionType(targetType, sourceType)) {
            case IDENTITY:
            case IMPLICIT: {
                boxedValue.remove();
                parent.replaceWith(boxedValue);
                break;
            }

            case EXPLICIT_TO_UNBOXED: {
                final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);

                if (astBuilder == null) {
                    return;
                }

                boxedValue.remove();

                final TypeReference castType = ((MethodReference) outerBoxMethod).getParameters().get(0).getParameterType();
                final CastExpression cast = new CastExpression(astBuilder.convertType(castType), boxedValue);

                parent.replaceWith(cast);

                break;
View Full Code Here

    private void removeUnboxingForCast(
        final InvocationExpression e,
        final MemberReferenceExpression target,
        final CastExpression parent) {

        final TypeReference targetType = parent.getType().toTypeReference();

        if (targetType == null || !targetType.isPrimitive()) {
            return;
        }

        final Expression boxedValue = target.getTarget();
        final ResolveResult boxedValueResult = _resolver.apply(boxedValue);

        if (boxedValueResult == null || boxedValueResult.getType() == null) {
            return;
        }

        final TypeReference sourceType = boxedValueResult.getType();
        final ConversionType conversionType = MetadataHelper.getNumericConversionType(targetType, sourceType);

        switch (conversionType) {
            case IMPLICIT: {
                boxedValue.remove();
View Full Code Here

        if (valueResult == null || valueResult.getType() == null) {
            return;
        }

        final TypeReference sourceType = valueResult.getType();
        final TypeReference targetType = ((MethodReference) reference).getReturnType();
        final ConversionType conversionType = MetadataHelper.getNumericConversionType(targetType, sourceType);

        switch (conversionType) {
            case IMPLICIT: {
                underlyingValue.remove();
                node.replaceWith(underlyingValue);
                break;
            }

            case EXPLICIT:
            case EXPLICIT_TO_UNBOXED: {
                final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);

                if (astBuilder == null) {
                    return;
                }

                final TypeReference castType;

                if (conversionType == ConversionType.EXPLICIT_TO_UNBOXED) {
                    castType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(targetType);
                }
                else {
View Full Code Here

    public AstType makeArrayType() {
        final ComposedType composedType = new ComposedType();

        composedType.setBaseType(this);

        final TypeReference typeReference = getUserData(Keys.TYPE_REFERENCE);

        if (typeReference != null) {
            composedType.putUserData(Keys.TYPE_REFERENCE, typeReference);
        }
View Full Code Here

        return false;
    }

    @Override
    public TypeReference toTypeReference() {
        final TypeReference typeReference = super.toTypeReference();
        final AstNodeCollection<AstType> astTypeArguments = getTypeArguments();

        if (astTypeArguments.isEmpty() || !typeReference.isGenericType()) {
            return typeReference;
        }

        final TypeReference[] typeArguments = new TypeReference[astTypeArguments.size()];

        int i = 0;

        for (final AstType astTypeArgument : astTypeArguments) {
            typeArguments[i++] = astTypeArgument.toTypeReference();
        }

        return typeReference.makeGenericType(typeArguments);
    }
View Full Code Here

    @Override
    public Void visitSimpleType(final SimpleType node, final Void _) {
        startNode(node);

        final TypeReference typeReference = node.getUserData(Keys.TYPE_REFERENCE);

        if (typeReference != null && typeReference.isPrimitive()) {
            writeKeyword(typeReference.getSimpleName());
        }
        else {
            writeIdentifier(node.getIdentifier());
        }
View Full Code Here

                if (node.getClassType() == ClassType.ANNOTATION) {
                    interfaceTypes = new ArrayList<>();

                    for (final AstType t : node.getInterfaces()) {
                        final TypeReference r = t.getUserData(Keys.TYPE_REFERENCE);

                        if (r != null && "java/lang/annotation/Annotation".equals(r.getInternalName())) {
                            continue;
                        }

                        interfaceTypes.add(t);
                    }
View Full Code Here

    @Override
    public boolean matches(final INode other, final Match match) {
        if (other instanceof TypeReferenceExpression) {
            final TypeReferenceExpression typeReferenceExpression = (TypeReferenceExpression) other;
            final TypeReference typeReference = typeReferenceExpression.getType().getUserData(Keys.TYPE_REFERENCE);

            return typeReference != null &&
                   StringUtilities.equals(_descriptor, typeReference.getInternalName());
        }
        return false;
    }
View Full Code Here

TOP

Related Classes of com.strobel.assembler.metadata.TypeReference

Copyright © 2018 www.massapicom. 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.