Package com.strobel.reflection

Examples of com.strobel.reflection.Type


        if (node.getNodeType() == ExpressionType.TypeEqual) {
            emitExpression(node.reduceTypeEqual());
            return;
        }

        final Type type = node.getTypeOperand();

        //
        // Try to determine the result statically
        //
        final AnalyzeTypeIsResult result = ConstantCheck.analyzeInstanceOf(node);

        if (result == AnalyzeTypeIsResult.KnownTrue ||
            result == AnalyzeTypeIsResult.KnownFalse) {
            //
            // Result is known statically, so just emit the expression for
            // its side effects and return the result.
            //
            emitExpressionAsVoid(node.getOperand());
            generator.emitBoolean(result == AnalyzeTypeIsResult.KnownTrue);
            return;
        }

        if (result == AnalyzeTypeIsResult.KnownAssignable) {
            //
            // We know the type can be assigned, but still need to check
            // for null at runtime.
            //
            assert !type.isPrimitive();

            final Label ifNull = generator.defineLabel();
            final Label exit = generator.defineLabel();

            emitExpression(node.getOperand());
View Full Code Here


                generator.markLabel(exit);
                return;
            }
        }

        final Type unboxedType = TypeUtils.getUnderlyingPrimitiveOrSelf(operandType);

        if (operandIsBoxed) {
            generator.emitUnbox(operandType);
        }

        switch (op) {
            case Not:
            case OnesComplement: {
                switch (unboxedType.getKind()) {
                    case BOOLEAN: {
                        final Label ifTrue = generator.defineLabel();
                        final Label exit = generator.defineLabel();

                        generator.emitBoolean(false);
                        generator.emit(OpCode.IF_ICMPNE, ifTrue);
                        generator.emitBoolean(true);
                        generator.emitGoto(exit);

                        generator.markLabel(ifTrue);
                        generator.emitBoolean(false);

                        generator.markLabel(exit);

                        break;
                    }

                    case BYTE:
                    case SHORT:
                    case INT: {
                        generator.emitInteger(-1);
                        generator.emit(OpCode.IXOR);
                        break;
                    }

                    case LONG: {
                        generator.emitLong(-1L);
                        generator.emit(OpCode.LXOR);
                        break;
                    }

                    case CHAR: {
                        generator.emitInteger(-1);
                        generator.emit(OpCode.IXOR);
                        break;
                    }

                    default: {
                        throw Error.unaryOperatorNotDefined(op, unboxedType);
                    }
                }
                break;
            }

            case IsFalse: {
                final Label ifTrue = generator.defineLabel();
                final Label exit = generator.defineLabel();

                generator.emitBoolean(false);
                generator.emit(OpCode.IF_ICMPNE, ifTrue);
                generator.emitBoolean(true);
                generator.emitGoto(exit);

                generator.markLabel(ifTrue);
                generator.emitBoolean(false);

                generator.markLabel(exit);

                // Not an arithmetic operation -> no conversion
                return;
            }

            case IsTrue: {
                final Label ifFalse = generator.defineLabel();
                final Label exit = generator.defineLabel();

                generator.emitBoolean(false);
                generator.emit(OpCode.IF_ICMPEQ, ifFalse);
                generator.emitBoolean(true);
                generator.emitGoto(exit);

                generator.markLabel(ifFalse);
                generator.emitBoolean(false);

                generator.markLabel(exit);

                // Not an arithmetic operation -> no conversion
                return;
            }

            case UnaryPlus: {
                generator.emit(OpCode.NOP);
                break;
            }

            case Negate: {
                switch (unboxedType.getKind()) {
                    case BYTE:
                    case SHORT:
                    case INT: {
                        generator.emit(OpCode.INEG);
                        break;
                    }

                    case LONG: {
                        generator.emit(OpCode.LNEG);
                        break;
                    }

                    case CHAR: {
                        generator.emit(OpCode.INEG);
                        break;
                    }

                    case FLOAT: {
                        generator.emit(OpCode.FNEG);
                        break;
                    }

                    case DOUBLE: {
                        generator.emit(OpCode.DNEG);
                        break;
                    }

                    default: {
                        throw Error.unaryOperatorNotDefined(op, unboxedType);
                    }
                }
                break;
            }

            case Increment: {
                switch (unboxedType.getKind()) {
                    case BYTE:
                    case SHORT:
                    case INT: {
                        generator.emitInteger(1);
                        generator.emit(OpCode.IADD);
                        break;
                    }

                    case LONG: {
                        generator.emitLong(1L);
                        generator.emit(OpCode.LADD);
                        break;
                    }

                    case CHAR: {
                        generator.emitInteger(1);
                        generator.emit(OpCode.IADD);
                        break;
                    }

                    case FLOAT: {
                        generator.emitFloat(1f);
                        generator.emit(OpCode.FADD);
                        break;
                    }

                    case DOUBLE: {
                        generator.emitDouble(1d);
                        generator.emit(OpCode.DADD);
                        break;
                    }

                    default: {
                        throw Error.unaryOperatorNotDefined(op, unboxedType);
                    }
                }
                break;
            }

            case Decrement: {
                switch (unboxedType.getKind()) {
                    case BYTE:
                    case SHORT:
                    case INT: {
                        generator.emitInteger(1);
                        generator.emit(OpCode.ISUB);
View Full Code Here

        emitExpression(node.getBody());

        generator.endTryBlock();

        final Expression finallyBlock = node.getFinallyBlock();
        final Type tryType = expr.getType();
        final LocalBuilder value;

        if (tryType != PrimitiveTypes.Void) {
            //
            // Store the value of the try body.
View Full Code Here

                    if (body == null) {
                        return;
                    }

                    final Type nodeType = node.getType();

                    if (nodeType == PrimitiveTypes.Void) {
                        emitExpressionAsVoid(body, flags);
                    }
                    else {
                        emitExpressionAsType(body, nodeType, flags);
                    }

                    generator.emitGoto(breakTarget);
                }

                @Override
                public void emitDefault(final Label breakTarget) throws Exception {
                    final Expression defaultBody = node.getDefaultBody();

                    if (defaultBody == null) {
                        return;
                    }

                    final Type nodeType = node.getType();

                    if (nodeType == PrimitiveTypes.Void) {
                        emitExpressionAsVoid(defaultBody, flags);
                    }
                    else {
View Full Code Here

                    if (body == null) {
                        return;
                    }

                    final Type nodeType = node.getType();

                    if (nodeType == PrimitiveTypes.Void) {
                        emitExpressionAsVoid(body, flags);
                    }
                    else {
                        emitExpressionAsType(body, nodeType, flags);
                    }

                    generator.emitGoto(breakTarget);
                }

                @Override
                public void emitDefault(final Label breakTarget) throws Exception {
                    final Expression defaultBody = node.getDefaultBody();

                    if (defaultBody == null) {
                        return;
                    }

                    final Type nodeType = node.getType();

                    if (nodeType == PrimitiveTypes.Void) {
                        emitExpressionAsVoid(defaultBody, flags);
                    }
                    else {
View Full Code Here

        for (final ParameterExpression v : _hoistedLocals.variables) {
            // array[i] = new StrongBox<T>(...);
            lc.generator.dup();
            lc.generator.emitInteger(i++);

            final Type boxType = getBoxType(v.getType());
            final ConstructorInfo constructor = boxType.getConstructor(v.getType());

            if (isMethod && lc.getParameters().contains(v)) {
                // array[i] = new StrongBox<T>(argument);
                final int index = lc.getParameters().indexOf(v);
                lc.generator.emitNew(boxType);
                lc.generator.dup();
                lc.emitLambdaArgument(index);
                lc.generator.call(constructor);
            }
            else if (v == _hoistedLocals.getParentVariable()) {
                // array[i] = new StrongBox<T>(closure.Locals);
                lc.generator.emitNew(boxType);
                lc.generator.dup();
                resolveVariable(v, _closureHoistedLocals).emitLoad();
                lc.generator.call(constructor);
            }
            else {
                // array[i] = new StrongBox<T>();
                lc.generator.emitNew(boxType);
                lc.generator.dup();
                lc.generator.call(boxType.getConstructor());
            }

            // If we want to cache this into a local, do it now.
            if (shouldCache(v)) {
                lc.generator.dup();
View Full Code Here

        );

        final MethodInfo invokeMethod = Expression.getInvokeMethod(e);
        final Type<?> returnType = invokeMethod.getReturnType();
        final TypeList parameterTypes = invokeMethod.getParameters().getParameterTypes();
        final Type delegateType = invokeMethod.getDeclaringType();

        assertTrue(delegateType.isGenericType());
        assertEquals(Types.String, delegateType.getTypeArguments().get(0));

        assertEquals(PrimitiveTypes.Boolean, returnType);
        assertEquals(PrimitiveTypes.Integer, parameterTypes.get(0));
        assertEquals(PrimitiveTypes.Long, parameterTypes.get(1));
        assertEquals(Types.String, parameterTypes.get(2));
View Full Code Here

        if (method == null) {
            return 0;
        }

        final int enclosingMethodStart = writeAttribute("EnclosingMethod");
        final Type declaringType = method.getDeclaringType();

        _dataBuffer.putShort(declaringType != null ? t.getTypeToken(declaringType) : 0);
        _dataBuffer.putShort(t.getMethodToken(method));

        endAttribute(enclosingMethodStart);
View Full Code Here

        return 1;
    }

    private void writeInnerTypeInfo(final Type<?> type) {
        final Type declaringType = type.getDeclaringType();
        final MethodBase declaringMethod = type.getDeclaringMethod();

        _dataBuffer.putShort(_typeBuilder.getTypeToken(type));

        if (declaringType != null) {
            _dataBuffer.putShort(_typeBuilder.getTypeToken(declaringType));
        }
        else if (declaringMethod != null) {
            final Type methodDeclaringType = declaringMethod.getDeclaringType();

            if (methodDeclaringType != null) {
                _dataBuffer.putShort(_typeBuilder.getTypeToken(methodDeclaringType));
            }
            else {
View Full Code Here

        final int attributeCountPosition = beginAttributes();

        int attributeCount = 0;

        if (constantValue != null) {
            final Type constantType = TypeUtils.getUnderlyingPrimitiveOrSelf(
                Type.of(constantValue.getClass())
            );

            final int attributeLengthIndex = writeAttribute("ConstantValue");

            switch (constantType.getKind()) {
                case BOOLEAN:
                    _dataBuffer.putShort(t.getConstantToken((Boolean) constantValue ? 1 : 0));
                    break;

                case BYTE:
View Full Code Here

TOP

Related Classes of com.strobel.reflection.Type

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.