Search in sources :

Example 1 with Type

use of es.bsc.compss.types.annotations.parameter.Type in project compss by bsc-wdc.

the class ITAppEditor method processParameterValue.

/**
 * Process the parameter values of a method call
 *
 * @param paramIndex
 * @param formalType
 * @param annotType
 * @param paramDirection
 * @return
 */
private ParameterInformation processParameterValue(int paramIndex, Parameter par, Class<?> formalType) {
    Type annotType = par.type();
    Direction paramDirection = par.direction();
    Stream paramStream = par.stream();
    String paramPrefix = par.prefix();
    StringBuilder infoToAppend = new StringBuilder("");
    StringBuilder infoToPrepend = new StringBuilder("");
    String type = "";
    if (annotType.equals(Type.FILE)) {
        // The File type needs to be specified explicitly, since its formal type is String
        type = DATA_TYPES + ".FILE_T";
        infoToAppend.append('$').append(paramIndex + 1).append(',');
        infoToPrepend.insert(0, itSRVar + ADD_TASK_FILE + "$" + (paramIndex + 1) + ");");
    } else if (annotType.equals(Type.STRING)) {
        /*
             * Mechanism to make a String be treated like a list of chars instead of like another object. Dependencies
             * won't be watched for the string.
             */
        type = DATA_TYPES + ".STRING_T";
        infoToAppend.append('$').append(paramIndex + 1).append(',');
    } else if (formalType.isPrimitive()) {
        if (formalType.equals(boolean.class)) {
            type = DATA_TYPES + ".BOOLEAN_T";
            infoToAppend.append("new Boolean(").append("$").append(paramIndex + 1).append("),");
        } else if (formalType.equals(char.class)) {
            type = DATA_TYPES + ".CHAR_T";
            infoToAppend.append("new Character(").append("$").append(paramIndex + 1).append("),");
        } else if (formalType.equals(byte.class)) {
            type = DATA_TYPES + ".BYTE_T";
            infoToAppend.append("new Byte(").append("$").append(paramIndex + 1).append("),");
        } else if (formalType.equals(short.class)) {
            type = DATA_TYPES + ".SHORT_T";
            infoToAppend.append("new Short(").append("$").append(paramIndex + 1).append("),");
        } else if (formalType.equals(int.class)) {
            type = DATA_TYPES + ".INT_T";
            infoToAppend.append("new Integer(").append("$").append(paramIndex + 1).append("),");
        } else if (formalType.equals(long.class)) {
            type = DATA_TYPES + ".LONG_T";
            infoToAppend.append("new Long(").append("$").append(paramIndex + 1).append("),");
        } else if (formalType.equals(float.class)) {
            type = DATA_TYPES + ".FLOAT_T";
            infoToAppend.append("new Float(").append("$").append(paramIndex + 1).append("),");
        } else if (formalType.equals(double.class)) {
            type = DATA_TYPES + ".DOUBLE_T";
            infoToAppend.append("new Double(").append("$").append(paramIndex + 1).append("),");
        }
    } else {
        // Object or Self-Contained Object or Persistent SCO
        type = CHECK_SCO_TYPE + "$" + (paramIndex + 1) + ")";
        infoToAppend.append("$").append(paramIndex + 1).append(",");
    }
    ParameterInformation infoParam = new ParameterInformation(infoToAppend.toString(), infoToPrepend.toString(), type, paramDirection, paramStream, paramPrefix);
    return infoParam;
}
Also used : DataType(es.bsc.compss.types.annotations.parameter.DataType) Type(es.bsc.compss.types.annotations.parameter.Type) FilterInputStream(java.io.FilterInputStream) PrintStream(java.io.PrintStream) FilterOutputStream(java.io.FilterOutputStream) Stream(es.bsc.compss.types.annotations.parameter.Stream) Direction(es.bsc.compss.types.annotations.parameter.Direction)

Example 2 with Type

use of es.bsc.compss.types.annotations.parameter.Type in project compss by bsc-wdc.

the class ITFParser method checkParameterAnnotation.

/**
 * Treats and display errors and warning related to the annotation of 1 parameter of a method/service
 *
 * @param m
 *            The method or service to be checked for warnings
 * @param par
 *            The parameter to analyse
 * @param i
 *            The position of the parameter (0 for the first parameter, 1 for the second, etc.)
 * @param hasNonNative
 *            Indicates if the method has non-native annotations or not
 */
private static void checkParameterAnnotation(java.lang.reflect.Method m, Parameter par, int i, boolean hasNonNative) {
    final String WARNING_LOCATION = "In parameter number " + (i + 1) + " of method '" + m.getName() + "' in interface '" + m.getDeclaringClass().toString().replace("interface ", "") + "'.";
    Type annotType = par.type();
    Direction annotDirection = par.direction();
    Stream stream = par.stream();
    boolean isOut = annotDirection.equals(Direction.OUT);
    boolean isInOut = annotDirection.equals(Direction.INOUT);
    /*
         * Type checks
         */
    if (annotType.equals(Type.STRING)) {
        // Strings are immutable
        if (isOut || isInOut) {
            ErrorManager.warn("Can't specify a String with direction OUT/INOUT since they are immutable." + ErrorManager.NEWLINE + WARNING_LOCATION + ErrorManager.NEWLINE + "Using direction=IN instead.");
        }
    } else if (m.getParameterTypes()[i].isPrimitive()) {
        // Primitive types are immutable (int, boolean, long, float, char, byte, short, double)
        if (isOut || isInOut) {
            String primType = m.getParameterTypes()[i].getName();
            ErrorManager.warn("Can't specify a primitive type ('" + primType + "') with direction OUT/INOUT, " + "since they are always passed by value. " + ErrorManager.NEWLINE + WARNING_LOCATION + ErrorManager.NEWLINE + "Using direction=IN instead.");
        }
    } else if (annotType.equals(Type.OBJECT)) {
        // Objects are not supported as OUT parameters
        if (isOut) {
            ErrorManager.warn("Can't specify an Object with direction OUT." + ErrorManager.NEWLINE + WARNING_LOCATION + ErrorManager.NEWLINE + "Using direction=INOUT instead.");
        }
    }
    /*
         * Non native tasks only support FILES as INOUT
         */
    if (hasNonNative && !annotType.equals(Type.FILE) && (isOut || isInOut)) {
        ErrorManager.error("Non-Native tasks only supports " + annotType.name() + " types in mode IN" + ErrorManager.NEWLINE + WARNING_LOCATION);
    }
    /*
         * Stream checks
         */
    if (!stream.equals(Stream.UNSPECIFIED)) {
        // Stream parameters can only be files
        if (!annotType.equals(Type.FILE)) {
            ErrorManager.error("Can't specify an Stream with type different than File." + ErrorManager.NEWLINE + WARNING_LOCATION);
        }
        switch(stream) {
            case STDIN:
                if (isOut || isInOut) {
                    ErrorManager.error("Stream STDIN must have direction IN" + ErrorManager.NEWLINE + WARNING_LOCATION);
                }
                break;
            case STDOUT:
                if (!isOut && !isInOut) {
                    ErrorManager.error("Stream STDOUT must have direction OUT or INOUT" + ErrorManager.NEWLINE + WARNING_LOCATION);
                }
                break;
            case STDERR:
                if (!isOut && !isInOut) {
                    ErrorManager.error("Stream STDERR must have direction OUT or INOUT" + ErrorManager.NEWLINE + WARNING_LOCATION);
                }
                break;
            case UNSPECIFIED:
                // We never reach this point since the previous if protects this case
                break;
        }
    }
}
Also used : Type(es.bsc.compss.types.annotations.parameter.Type) Stream(es.bsc.compss.types.annotations.parameter.Stream) Direction(es.bsc.compss.types.annotations.parameter.Direction)

Example 3 with Type

use of es.bsc.compss.types.annotations.parameter.Type in project compss by bsc-wdc.

the class ITFParser method constructSignatureAndCheckParameters.

/**
 * Constructs the signature of method @m and leaves the result in calleeMethodSignature. It also returns if the
 * method has stream parameters or not
 *
 * @param m
 * @param hasNonNative
 * @param calleeMethodSignature
 * @return
 */
private static boolean[] constructSignatureAndCheckParameters(java.lang.reflect.Method m, boolean hasNonNative, StringBuilder calleeMethodSignature) {
    boolean hasStreams = false;
    boolean hasPrefixes = false;
    String methodName = m.getName();
    boolean hasSTDIN = false;
    boolean hasSTDOUT = false;
    boolean hasSTDERR = false;
    int numPars = m.getParameterAnnotations().length;
    if (numPars > 0) {
        for (int i = 0; i < numPars; i++) {
            Parameter par = (Parameter) m.getParameterAnnotations()[i][0];
            Class<?> parType = m.getParameterTypes()[i];
            Type annotType = par.type();
            String type = inferType(parType, annotType);
            // Add to callee
            if (i >= 1) {
                calleeMethodSignature.append(",");
            }
            calleeMethodSignature.append(type);
            // Check parameter stream annotation
            switch(par.stream()) {
                case STDIN:
                    if (hasSTDIN) {
                        ErrorManager.error("Method " + methodName + " has more than one parameter annotated has Stream.STDIN");
                    }
                    hasSTDIN = true;
                    break;
                case STDOUT:
                    if (hasSTDOUT) {
                        ErrorManager.error("Method " + methodName + " has more than one parameter annotated has Stream.STDOUT");
                    }
                    hasSTDOUT = true;
                    break;
                case STDERR:
                    if (hasSTDERR) {
                        ErrorManager.error("Method " + methodName + " has more than one parameter annotated has Stream.STDERR");
                    }
                    hasSTDERR = true;
                    break;
                case UNSPECIFIED:
                    break;
            }
            hasStreams = hasStreams || !par.stream().equals(Stream.UNSPECIFIED);
            hasPrefixes = hasPrefixes || !par.prefix().equals(Constants.PREFIX_EMTPY);
            // Check parameter annotation (warnings and errors)
            checkParameterAnnotation(m, par, i, hasNonNative);
        }
    }
    calleeMethodSignature.append(")");
    boolean[] hasAnnotation = { hasStreams, hasPrefixes };
    return hasAnnotation;
}
Also used : Type(es.bsc.compss.types.annotations.parameter.Type) Parameter(es.bsc.compss.types.annotations.Parameter)

Aggregations

Type (es.bsc.compss.types.annotations.parameter.Type)3 Direction (es.bsc.compss.types.annotations.parameter.Direction)2 Stream (es.bsc.compss.types.annotations.parameter.Stream)2 Parameter (es.bsc.compss.types.annotations.Parameter)1 DataType (es.bsc.compss.types.annotations.parameter.DataType)1 FilterInputStream (java.io.FilterInputStream)1 FilterOutputStream (java.io.FilterOutputStream)1 PrintStream (java.io.PrintStream)1