Package org.jboss.byteman.rule.type

Examples of org.jboss.byteman.rule.type.Type


    public Type typeCheck(Type expected) throws TypeException {
        if (owner == null && pathList != null) {
            // factor off a typename from the path
            TypeGroup typeGroup = getTypeGroup();
            Type rootType = typeGroup.match(pathList);
            if (rootType == null) {
                throw new TypeException("FieldExpression.typeCheck : invalid path " + getPath(pathList.length) + " to static field " + fieldName + getPos());
            }

            // find out how many of the path elements are included in the type name

            String rootTypeName = rootType.getName();

            int idx = getPathCount(rootTypeName);

            if (idx < pathList.length) {
                // create a static field reference using the type name and the first field name and wrap it with
View Full Code Here


            // e.g. the parameter type may be int and the arg type float
            // or the parameter type may be String and the arg type class Foo
            // reimplement this using type inter-assignability to do the pruning

            Class candidateClass = getCandidateArgClass(candidates, i);
            Type candidateType;
            if (candidateClass != null) {
                candidateType = typeGroup.ensureType(candidateClass);
            } else {
                candidateType = Type.UNDEFINED;
            }
            Type argType = arguments.get(i).typeCheck(candidateType);
            argumentTypes.add(argType);
            if (candidateType == Type.UNDEFINED) {
                // we had several constructors to choose from
                candidates = pruneCandidates(candidates, i, argType.getTargetClass());
            }
        }

        if (candidates.isEmpty()) {
            throw new TypeException("ThrowExpression.typeCheck : invalid constructor for target class " + typeName + getPos());
        }

        if (candidates.size() > 1) {
            throw new TypeException("ThrowExpression.typeCheck : ambiguous constructor signature for target class " + typeName + getPos());
        }

        constructor = candidates.get(0);

        // make sure we know the formal parameter types and have included them in the typegroup

        paramTypes = new ArrayList<Type>();
        Class<?>[] paramClasses = constructor.getParameterTypes();

        for (int i = 0; i < arguments.size() ; i++) {
            paramTypes.add(typeGroup.ensureType(paramClasses[i]));
        }

        // expected type should always be void since throw can only occur as a top level action
        // however, we need to be sure that the trigering method throws this exception type or
        // else that it is a subtype of runtime exception

        if (RuntimeException.class.isAssignableFrom(type.getTargetClass())) {
            return type;
        } else {
            Iterator<Type> iterator = typeGroup.getExceptionTypes().iterator();
            while (iterator.hasNext()) {
                Type exceptionType = iterator.next();
                if (Type.dereference(exceptionType).isAssignableFrom(type)) {
                    // ok we foudn a suitable declaration for the exception
                    return type;
                }
            }
View Full Code Here

        int argCount = arguments.size();

        // stack each of the arguments to the constructor
        for (int i = 0; i < argCount; i++) {
            Type argType = argumentTypes.get(i);
            Type paramType = paramTypes.get(i);
            int paramCount = (paramType.getNBytes() > 4 ? 2 : 1);

            // track extra storage used after type conversion
            extraParams += (paramCount);
            arguments.get(i).compile(mv, compileContext);
            compileTypeConversion(argType, paramType, mv, compileContext);
View Full Code Here

    {
        // time to take an early bath -- the code compield into the trigger method should
        // catch this and return as appropriate
        if (returnValue != null) {
            Object value = returnValue.interpret(helper);
            Type subtype = returnValue.type;
            if (type.isNumeric()) {
                // make sure we produce the expected type of numeric
                if (type == Type.C && subtype != Type.C) {
                    // ok, transform Number to a Character
                    int number = ((Number)value).intValue();
View Full Code Here

        }
    }

    public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException
    {
        Type valueType = (returnValue == null ? Type.VOID : returnValue.getType());
        int currentStack = compileContext.getStackCount();
        int expected = 1;

        // ok, we need to create the EarlyReturnException instance and then
        // initialise it using the appropriate return value or null if no
View Full Code Here

    }

    public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException
    {
        Expression oper = getOperand(0);
        Type operType = oper.getType();

        int currentStack = compileContext.getStackCount();
        int expected = 0;

        // compile code to execute the value then negate it
View Full Code Here

            // if this is not already a numeric type then generate a cast
            if (!fromType.isNumeric()) {
                compileObjectConversion(fromType, Type.NUMBER, mv, compileContext);
            }
            if (box) {
                Type midType = Type.boxType(toType);
                compileUnbox(fromType, midType, mv, compileContext);
                compileBox(midType, mv, compileContext);
            } else {
                compileUnbox(fromType, toType, mv, compileContext);
            }
        } else if (box) {
            Type midType = Type.boxType(toType);
            if (fromType != midType) {
                compilePrimitiveConversion(fromType, midType, mv, compileContext);
            }
            compileBox(toType, mv, compileContext);
        } else {
View Full Code Here

            throws CompileException
    {
        // ensure any primitive type is boxed before we go any further

        if (fromType.isPrimitive()) {
            Type boxType = Type.boxType(fromType);
            compileBox(boxType, mv, compileContext);
            fromType = boxType;
        }

        if (toType.isAssignableFrom(fromType)) {
View Full Code Here

    public Type typeCheck(Type expected) throws TypeException {
        // if the expected type is numeric then we know this must be an arithmetic plus
        // if it is string then this could still be an arithmetic plus so we will
        // have to rely on the type of the first argument to guide us

        Type type1 = getOperand(0).typeCheck((expected.isNumeric() ? expected : Type.UNDEFINED));
        Type type2;

        if (type1.isNumeric()) {
            type2 = getOperand(1).typeCheck(Type.N);
            type = Type.promote(type1, type2);
        } else if (type1.isString()) {
View Full Code Here

                if (child0.getTag() != IDENTIFIER) {
                    throw new TypeException("Event.createBindings : unexpected token type in variable declaration" + child0.getTag() + " for token " + child0.getText() + child0.getPos());
                } else if (child1.getTag() != IDENTIFIER && child1.getTag() != ARRAY) {
                    throw new TypeException("Event.createBindings : unexpected token Type in variable type declaration" + child1.getTag()  + " for token " + child1.getText() + child1.getPos());
                }
                Type type = getBindingType(child1);
                if (type == null) {
                    throw new TypeException("Event.createBindings : incompatible type in declaration of variable " + child1.getText() + child1.getPos());
                }
                return new Binding(rule, child0.getText(), type);
            }
View Full Code Here

TOP

Related Classes of org.jboss.byteman.rule.type.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.