Package com.strobel.assembler.metadata

Examples of com.strobel.assembler.metadata.TypeReference


                if (result != null &&
                    result.getType() != null &&
                    !TypeUtilities.isBoolean(result.getType()) &&
                    MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType()).getSimpleType().isNumeric()) {

                    final TypeReference comparandType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(result.getType());

                    operand.replaceWith(
                        new Function<AstNode, AstNode>() {
                            @Override
                            public AstNode apply(final AstNode input) {
                                return new BinaryOperatorExpression(
                                    operand,
                                    BinaryOperatorType.INEQUALITY,
                                    new PrimitiveExpression(Expression.MYSTERY_OFFSET, JavaPrimitiveCast.cast(comparandType.getSimpleType(), 0))
                                );
                            }
                        }
                    );
                }
View Full Code Here


                    TypeUtilities.isBoolean(leftResult.getType()) ^ TypeUtilities.isBoolean(rightResult.getType())) {

                    if (TypeUtilities.isBoolean(leftResult.getType()) &&
                        TypeUtilities.isArithmetic(rightResult.getType())) {

                        final TypeReference comparandType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(rightResult.getType());

                        if (TRUE_NODE.matches(left)) {
                            ((PrimitiveExpression) left).setValue(JavaPrimitiveCast.cast(comparandType.getSimpleType(), 1));
                        }
                        else if (FALSE_NODE.matches(left)) {
                            ((PrimitiveExpression) left).setValue(JavaPrimitiveCast.cast(comparandType.getSimpleType(), 0));
                        }
                        else {
                            convertBooleanToNumeric(left);
                        }
                    }
                    else if (TypeUtilities.isArithmetic(leftResult.getType())) {
                        final TypeReference comparandType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(leftResult.getType());

                        if (TRUE_NODE.matches(right)) {
                            ((PrimitiveExpression) right).setValue(JavaPrimitiveCast.cast(comparandType.getSimpleType(), 1));
                        }
                        else if (FALSE_NODE.matches(right)) {
                            ((PrimitiveExpression) right).setValue(JavaPrimitiveCast.cast(comparandType.getSimpleType(), 0));
                        }
                        else {
                            convertBooleanToNumeric(right);
                        }
                    }
                }
                else {
                    final TypeReference expectedType = TypeUtilities.getExpectedTypeByParent(_resolver, node);

                    if (expectedType != null && TypeUtilities.isBoolean(expectedType)) {
                        final ResolveResult result = _resolver.apply(node);

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

        if (!arguments.isEmpty()) {
            final Expression firstArgument = arguments.firstOrNullObject();
            final ResolveResult resolvedArgument = _resolver.apply(firstArgument);

            if (resolvedArgument != null) {
                final TypeReference createdType = node.getType().getUserData(Keys.TYPE_REFERENCE);
                final TypeReference argumentType = resolvedArgument.getType();

                if (createdType != null && argumentType != null) {
                    final TypeDefinition resolvedCreatedType = createdType.resolve();

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

            if (!parent.getArguments().isEmpty()) {
                final Expression firstArgument = parent.getArguments().firstOrNullObject();
                final ResolveResult resolvedArgument = _resolver.apply(firstArgument);

                if (resolvedArgument != null) {
                    final TypeReference superType = node.getUserData(Keys.TYPE_REFERENCE);
                    final TypeReference argumentType = resolvedArgument.getType();

                    if (superType != null && argumentType != null) {
                        final TypeDefinition resolvedSuperType = superType.resolve();

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

            if (resolvedMethod != null && resolvedMethod.isStatic()) {
                return false;
            }
        }

        final TypeReference scope = context.getCurrentType();

        for (TypeReference current = scope;
             current != null;
             current = current.getDeclaringType()) {
View Full Code Here

        if (resolvedField == null || !resolvedField.isSynthetic()) {
            return;
        }

        final TypeReference typeReference = type.getType().getUserData(Keys.TYPE_REFERENCE);

        if (typeReference != null &&
            (MetadataResolver.areEquivalent(context.getCurrentType(), typeReference) ||
             MetadataHelper.isEnclosedBy(context.getCurrentType(), typeReference))) {
View Full Code Here

                if (rValue instanceof CastExpression) {
                    final CastExpression cast = (CastExpression) rValue;
                    final AstType castType = cast.getType();

                    if (castType != null && !castType.isNull()) {
                        final TypeReference typeReference = castType.getUserData(Keys.TYPE_REFERENCE);

                        if (typeReference != null) {
                            final JvmType jvmType = typeReference.getSimpleType();

                            switch (jvmType) {
                                case Byte:
                                case Short:
                                case Character:
View Full Code Here

    private static boolean referencesType(final TypeReference reference, final TypeReference localType) {
        if (reference == null || localType  == null) {
            return false;
        }

        TypeReference type = reference;

        while (type.isArray()) {
            type = type.getElementType();
        }

        TypeReference target = localType;

        while (target.isArray()) {
            target = target.getElementType();
        }

        if (StringUtilities.equals(type.getInternalName(), target.getInternalName())) {
            return true;
        }

        if (type.hasExtendsBound()) {
            final TypeReference bound = type.getExtendsBound();

            if (!bound.isGenericParameter() && !MetadataHelper.isSameType(bound, type) && referencesType(bound, localType)) {
                return true;
            }
        }

        if (type.hasSuperBound()) {
            final TypeReference bound = type.getSuperBound();

            if (!bound.isGenericParameter() && !MetadataHelper.isSameType(bound, type) && referencesType(bound, localType)) {
                return true;
            }
        }

        if (type.isGenericType()) {
View Full Code Here

            // ForStatement is a special case: we can move the variable declarations into the initializer.
            //

            if (!forStatement.getInitializers().isEmpty()) {
                boolean result = false;
                TypeReference lastInitializerType = null;
                StrongBox<Statement> declarationPoint = null;

                final Set<String> variableNames = new HashSet<>();

                for (final Statement initializer : forStatement.getInitializers()) {
                    if (initializer instanceof ExpressionStatement &&
                        ((ExpressionStatement) initializer).getExpression() instanceof AssignmentExpression) {

                        final Expression e = ((ExpressionStatement) initializer).getExpression();

                        if (e instanceof AssignmentExpression &&
                            ((AssignmentExpression) e).getOperator() == AssignmentOperatorType.ASSIGN &&
                            ((AssignmentExpression) e).getLeft() instanceof IdentifierExpression) {

                            final IdentifierExpression identifier = (IdentifierExpression) ((AssignmentExpression) e).getLeft();
                            final boolean usedByInitializer = usesVariable(((AssignmentExpression) e).getRight(), variableName);

                            if (usedByInitializer) {
                                return false;
                            }

                            final Variable variable = identifier.getUserData(Keys.VARIABLE);

                            if (variable == null || variable.isParameter()) {
                                return false;
                            }

                            final TypeReference variableType = variable.getType();

                            if (lastInitializerType == null) {
                                lastInitializerType = variableType;
                            }
                            else if (!MetadataHelper.isSameType(lastInitializerType, variableType)) {
View Full Code Here

  }
 
  @Override
  public Void visitSimpleType( SimpleType node, SourceIndex index )
  {
    TypeReference ref = node.getUserData( Keys.TYPE_REFERENCE );
    if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY )
    {
      ClassEntry classEntry = new ClassEntry( ref.getInternalName() );
      index.addReference( node.getIdentifierToken(), classEntry, m_behaviorEntry );
    }
   
    return recurse( node, index );
  }
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.