Package com.strobel.assembler.metadata

Examples of com.strobel.assembler.metadata.TypeReference


            return super.visitSimpleType(node, data);
        }

        int i;
        String name = node.getIdentifier();
        TypeReference type = node.getUserData(Keys.TYPE_REFERENCE);

        if (type.isGenericParameter()) {
            //
            // Ignore generic parameters.  They cannot be qualified.
            //
            return super.visitSimpleType(node, data);
        }

        while (type.isNested() && (i = name.lastIndexOf('.')) > 0 && i < name.length() - 1) {
            type = type.getDeclaringType();
            name = name.substring(0, i);
        }

        if (type != null && !type.isPrimitive()) {
            final Object resolvedObject = resolveName(node, name, modeForType(node));

            if (resolvedObject == null ||
                !(resolvedObject instanceof TypeReference &&
                  MetadataHelper.isSameType(type, (TypeReference) resolvedObject))) {
View Full Code Here


        }
        else {
            parser = new MetadataParser(IMetadataResolver.EMPTY);
        }

        final TypeReference declaringType = parser.parseTypeDescriptor("java/lang/" + jvmType.name());
        final FieldReference field = parser.parseField(declaringType, fieldName, jvmType.getDescriptorPrefix());

        if (currentType != null &&
            node.getParent() instanceof VariableInitializer &&
            node.getParent().getParent() instanceof FieldDeclaration &&
            StringUtilities.equals(currentType.getInternalName(), declaringType.getInternalName())) {

            final FieldDeclaration declaration = (FieldDeclaration) node.getParent().getParent();
            final FieldDefinition actualField = declaration.getUserData(Keys.FIELD_DEFINITION);

            if (actualField == null || StringUtilities.equals(actualField.getName(), fieldName)) {
                switch (fieldName) {
                    case "POSITIVE_INFINITY": {
                        node.replaceWith(
                            new BinaryOperatorExpression(
                                new PrimitiveExpression(node.getOffset(), jvmType == JvmType.Double ? 1d : 1f),
                                BinaryOperatorType.DIVIDE,
                                new PrimitiveExpression(node.getOffset(), jvmType == JvmType.Double ? 0d : 0f)
                            )
                        );
                        return;
                    }

                    case "NEGATIVE_INFINITY": {
                        node.replaceWith(
                            new BinaryOperatorExpression(
                                new PrimitiveExpression(node.getOffset(), jvmType == JvmType.Double ? -1d : -1f),
                                BinaryOperatorType.DIVIDE,
                                new PrimitiveExpression(node.getOffset(), jvmType == JvmType.Double ? 0d : 0f)
                            )
                        );
                        return;
                    }

                    case "NaN": {
                        node.replaceWith(
                            new BinaryOperatorExpression(
                                new PrimitiveExpression(node.getOffset(), jvmType == JvmType.Double ? 0d : 0f),
                                BinaryOperatorType.DIVIDE,
                                new PrimitiveExpression(node.getOffset(), jvmType == JvmType.Double ? 0d : 0f)
                            )
                        );
                        return;
                    }

                    default: {
                        return;
                    }
                }
            }
        }

        final AstType astType;
        final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);

        if (astBuilder != null) {
            astType = astBuilder.convertType(declaringType);
        }
        else {
            astType = new SimpleType(declaringType.getName());
            astType.putUserData(Keys.TYPE_REFERENCE, declaringType);
        }

        final MemberReferenceExpression memberReference = new MemberReferenceExpression( node.getOffset(),
            new TypeReferenceExpression(node.getOffset(), astType),
View Full Code Here

        return false;
    }

    private Statement canInlineInitializerDeclarations(final ForStatement forLoop) {
        TypeReference variableType = null;

        final BlockStatement tempOuter = new BlockStatement();
        final BlockStatement temp = new BlockStatement();
        final Statement[] initializers = forLoop.getInitializers().toArray(new Statement[forLoop.getInitializers().size()]);
        final Set<String> variableNames = new HashSet<>();

        Statement firstInlinableInitializer = null;

        forLoop.getParent().insertChildBefore(forLoop, tempOuter, BlockStatement.STATEMENT_ROLE);
        forLoop.remove();

        for (final Statement initializer : initializers) {
            initializer.remove();
            temp.getStatements().add(initializer);
        }

        temp.getStatements().add(forLoop);
        tempOuter.getStatements().add(temp);

        try {
            for (final Statement initializer : initializers) {
                final AssignmentExpression assignment = (AssignmentExpression) ((ExpressionStatement) initializer).getExpression();
                final IdentifierExpression variable = (IdentifierExpression) assignment.getLeft();
                final String variableName = variable.getIdentifier();
                final VariableDeclarationStatement declaration = findVariableDeclaration(forLoop, variableName);

                if (declaration == null) {
                    firstInlinableInitializer = null;
                    continue;
                }

                final Variable underlyingVariable = declaration.getUserData(Keys.VARIABLE);

                if (underlyingVariable == null || underlyingVariable.isParameter()) {
                    firstInlinableInitializer = null;
                    continue;
                }

                if (!variableNames.add(underlyingVariable.getName())) {
                    firstInlinableInitializer = null;
                    continue;
                }

                if (variableType == null) {
                    variableType = underlyingVariable.getType();
                }
                else if (!variableType.equals(underlyingVariable.getType())) {
                    variableType = underlyingVariable.getType();
                    firstInlinableInitializer = null;
                }

                if (!(declaration.getParent() instanceof BlockStatement)) {
View Full Code Here

                //
                // 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

                if (mapName == null || !mapName.startsWith("$SwitchMap$") || !(arrayOwner instanceof TypeReferenceExpression)) {
                    return super.visitSwitchStatement(node, data);
                }

                final TypeReferenceExpression enclosingTypeExpression = (TypeReferenceExpression) arrayOwner;
                final TypeReference enclosingType = enclosingTypeExpression.getType().getUserData(Keys.TYPE_REFERENCE);

                if (!isSwitchMapWrapper(enclosingType) || !(argument instanceof InvocationExpression)) {
                    return super.visitSwitchStatement(node, data);
                }

                final InvocationExpression invocation = (InvocationExpression) argument;
                final Expression invocationTarget = invocation.getTarget();

                if (!(invocationTarget instanceof MemberReferenceExpression)) {
                    return super.visitSwitchStatement(node, data);
                }

                final MemberReferenceExpression memberReference = (MemberReferenceExpression) invocationTarget;

                if (!"ordinal".equals(memberReference.getMemberName())) {
                    return super.visitSwitchStatement(node, data);
                }

                final String enclosingTypeName = enclosingType.getInternalName();

                SwitchMapInfo info = _switchMaps.get(enclosingTypeName);

                if (info == null) {
                    _switchMaps.put(enclosingTypeName, info = new SwitchMapInfo(enclosingTypeName));

                    final TypeDefinition resolvedType = enclosingType.resolve();

                    if (resolvedType != null) {
                        AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);

                        if (astBuilder == null) {
View Full Code Here

                            Expression.MYSTERY_OFFSET,
                            new TypeReferenceExpression(Expression.MYSTERY_OFFSET, type.clone().makeArrayType()),
                            "new"
                        );

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

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

            }
            else {
                firstArgument = null;
            }

            final TypeReference typeReference = node.getType().toTypeReference();

            if (typeReference != null &&
                isStringBuilder(typeReference)) {

                convertStringBuilderToConcatenation(node, firstArgument);
View Full Code Here

            return null;
        }

        final ResolveResult valueResult = _resolver.apply(node.getTarget());

        TypeReference declaringType = member.getDeclaringType();

        if (valueResult != null &&
            valueResult.getType() != null) {

            if (MetadataHelper.isAssignableFrom(declaringType, valueResult.getType())) {
                return null;
            }

            if (valueResult.getType().isGenericType() &&
                (declaringType.isGenericType() ||
                 MetadataHelper.isRawType(declaringType))) {

                final TypeReference asSuper = MetadataHelper.asSuper(declaringType, valueResult.getType());

                if (asSuper != null) {
                    declaringType = asSuper;
                }
            }
View Full Code Here

        if (function instanceof MethodDeclaration) {
            left = ((MethodDeclaration) function).getReturnType();
        }
        else {
            final TypeReference expectedType = TypeUtilities.getExpectedTypeByParent(_resolver, (Expression) function);

            if (expectedType == null) {
                return null;
            }
View Full Code Here

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

        final TypeReference unboxedTargetType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(targetResult.getType());
        final TypeReference unboxedValueType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(valueResult.getType());

        if (right instanceof PrimitiveExpression &&
            unboxedTargetType.getSimpleType().isIntegral() &&
            unboxedTargetType.getSimpleType().isSubWordOrInt32() &&
            MetadataHelper.isAssignableFrom(BuiltinTypes.Integer, unboxedValueType, 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.