Package edu.umd.cs.findbugs.ba.generic

Examples of edu.umd.cs.findbugs.ba.generic.GenericObjectType


                }
            }

            if (aRef instanceof GenericObjectType && bRef instanceof GenericObjectType
                    && aRef.getSignature().equals(bRef.getSignature())) {
                GenericObjectType aG = (GenericObjectType) aRef;
                GenericObjectType bG = (GenericObjectType) bRef;
                if (aG.getTypeCategory() == bG.getTypeCategory()) {
                    switch (aG.getTypeCategory()) {
                    case PARAMETERIZED:
                        List<? extends ReferenceType> aP = aG.getParameters();
                        List<? extends ReferenceType> bP = bG.getParameters();
                        assert aP != null;
                        assert bP != null;
                        if (aP.size() != bP.size()) {
                            break;
                        }
                        ArrayList<ReferenceType> result = new ArrayList<ReferenceType>(aP.size());
                        for (int i = 0; i < aP.size(); i++) {
                            result.add(mergeReferenceTypes(aP.get(i), bP.get(i)));
                        }

                        GenericObjectType rOT = GenericUtilities.getType(aG.getClassName(), result);
                        return rOT;

                    }

                }
View Full Code Here


    private boolean getResultTypeFromGenericType(TypeFrame frame, int index, int expectedParameters) {
        try {
            Type mapType = frame.getStackValue(0);
            if (mapType instanceof GenericObjectType) {
                GenericObjectType genericMapType = (GenericObjectType) mapType;
                List<? extends ReferenceType> parameters = genericMapType.getParameters();
                if (parameters != null && parameters.size() == expectedParameters) {
                    ReferenceType resultType = parameters.get(index);
                    if (resultType instanceof GenericObjectType) {
                        resultType = ((GenericObjectType) resultType).produce();
                    }
View Full Code Here

    private boolean handleGetMapView(TypeFrame frame, String typeName, int index, int expectedNumberOfTypeParameters) {
        try {
            Type mapType = frame.getStackValue(0);
            if (mapType instanceof GenericObjectType) {
                GenericObjectType genericMapType = (GenericObjectType) mapType;
                List<? extends ReferenceType> parameters = genericMapType.getParameters();
                if (parameters == null) {
                    return false;
                }
                if (parameters.size() == expectedNumberOfTypeParameters) {
                    ReferenceType keyType = parameters.get(index);
                    frame.popValue();
                    typesComputedFromGenerics.add(keyType);
                    GenericObjectType keySetType = GenericUtilities.getType(typeName, Collections.singletonList(keyType));
                    typesComputedFromGenerics.add(keySetType);
                    frame.pushValue(keySetType);
                    return true;
                }
            }
View Full Code Here

                && className.endsWith("Map") && Subtypes2.instanceOf(className, "java.util.Map")
                && frame.getStackDepth() >= 2) {
            try {
                Type mapType = frame.getStackValue(1);
                if (mapType instanceof GenericObjectType) {
                    GenericObjectType genericMapType = (GenericObjectType) mapType;
                    List<? extends ReferenceType> parameters = genericMapType.getParameters();
                    if (parameters == null || parameters.size() != 2) {
                        break mapGetCheck;
                    }

                    ClassDescriptor c = DescriptorFactory.getClassDescriptor(genericMapType);
                    if (!Subtypes2.instanceOf(c, Map.class)) {
                        break mapGetCheck;
                    }
                    if (!isStraightGenericMap(c)) {
                        break mapGetCheck;
                    }

                    ReferenceType valueType = parameters.get(1);
                    consumeStack(obj);
                    frame.pushValue(valueType);
                    return;

                }
            } catch (DataflowAnalysisException e) {
                AnalysisContext.logError("oops", e);
            }

        }

        if (className.equals("java.util.Map$Entry")) {
            if (methodName.equals("getKey") && getResultTypeFromGenericType(frame, 0, 2) || methodName.equals("getValue")
                    && getResultTypeFromGenericType(frame, 1, 2)) {
                return;
            }
        }

        if (methodName.equals("entrySet") && signature.equals("()Ljava/util/Set;") && className.startsWith("java.util")
                && className.endsWith("Map")) {
            Type argType;
            try {
                argType = frame.popValue();
            } catch (DataflowAnalysisException e) {
                AnalysisContext.logError("oops", e);
                return;
            }
            ObjectType mapType = (ObjectType) Type.getType("Ljava/util/Map$Entry;");

            if (argType instanceof GenericObjectType) {
                GenericObjectType genericArgType = (GenericObjectType) argType;
                List<? extends ReferenceType> parameters = genericArgType.getParameters();
                if (parameters != null && parameters.size() == 2) {
                    mapType = GenericUtilities.getType("java.util.Map$Entry", parameters);
                }
            }
            GenericObjectType entrySetType = GenericUtilities.getType("java.util.Set", Collections.singletonList(mapType));
            frame.pushValue(entrySetType);
            return;

        }
        if (className.startsWith("java.util") && className.endsWith("Map")) {
View Full Code Here

                boolean isExact = isTopOfStackExact();
                TypeFrame frame = getFrame();
                Type value = frame.popValue();
                int index = obj.getIndex();
                if (value instanceof ReferenceType && !(value instanceof GenericObjectType)) {
                    GenericObjectType gType = getLocalVariable(index,
                            getLocation().getHandle().getPosition());
                    value = GenericUtilities.merge(gType, value);
                }
                frame.setValue(index, value);
                frame.setExact(index, isExact);
View Full Code Here

        }
        int index = obj.getIndex();
        TypeFrame frame = getFrame();
        Type value = frame.getValue(index);
        if (value instanceof ReferenceType && !(value instanceof GenericObjectType)) {
            GenericObjectType gType = getLocalVariable(index,
                    getLocation().getHandle().getPosition());
            value = GenericUtilities.merge(gType, value);
        }
        boolean isExact = frame.isExact(index);
        frame.pushValue(value);
View Full Code Here

                return 1.0;
            }
        }
        double result =  isDeepSerializable(type.getSignature());
        if (type instanceof GenericObjectType && Subtypes2.isContainer(type)) {
            GenericObjectType gt = (GenericObjectType) type;
            List<? extends ReferenceType> parameters = gt.getParameters();
            if (parameters != null) {
                for(ReferenceType t : parameters) {
                    double r = isDeepSerializable(t);
                    if (result > r) {
                        result = r;
View Full Code Here

        }

        ReferenceType result = type;
        double value =  isDeepSerializable(type.getSignature());
        if (type instanceof GenericObjectType && Subtypes2.isContainer(type)) {
            GenericObjectType gt = (GenericObjectType) type;
            List<? extends ReferenceType> parameters = gt.getParameters();
            if (parameters != null) {
                for(ReferenceType t : parameters) {
                    double r = isDeepSerializable(t);
                    if (value > r) {
                        value = r;
View Full Code Here

                Type objectType = frame.getStackValue(lhsPos);
                if (!(objectType instanceof GenericObjectType)) {
                    continue;
                }

                GenericObjectType operand = (GenericObjectType) objectType;

                int expectedTypeParameters = 1;
                String simpleName = info.interfaceForCall.getSimpleName();
                if ( simpleName.toLowerCase().endsWith("map") || simpleName.equals("Hashtable")) {
                    expectedTypeParameters = 2;
                } else if (simpleName.equals("Table")) {
                    expectedTypeParameters = 3;
                }

                // ... containers
                if (!operand.hasParameters()) {
                    continue;
                }
                if (operand.getNumParameters() != expectedTypeParameters) {
                    continue;
                }
                ClassDescriptor operandClass = DescriptorFactory.getClassDescriptor(operand);
                if (!isGenericCollection(operandClass)) {
                    continue;
                }

                if (expectedTypeParameters == 2 &&
                        Subtypes2.instanceOf(operandClass, Map.class)
                        && !TypeFrameModelingVisitor.isStraightGenericMap(operandClass)) {
                    continue;
                }
                Type expectedType;
                if (allMethod) {
                    expectedType = operand;
                } else {
                    expectedType = operand.getParameterAt(typeArgument);
                }
                Type actualType = frame.getStackValue(stackPos);
                Type equalsType = actualType;
                if (allMethod) {
                    if (!(actualType instanceof GenericObjectType)) {
                        continue;
                    }
                    equalsType = ((GenericObjectType)actualType).getParameterAt(typeArgument);
                }


                IncompatibleTypes matchResult = compareTypes(expectedType, actualType, allMethod);

                boolean parmIsObject = expectedType.getSignature().equals("Ljava/lang/Object;");
                boolean selfOperation = !allMethod && operand.equals(actualType) && !parmIsObject;
                if (!allMethod && !parmIsObject && actualType instanceof GenericObjectType) {

                    GenericObjectType p2 = (GenericObjectType) actualType;
                    List<? extends ReferenceType> parameters = p2.getParameters();
                    if (parameters != null && parameters.equals(operand.getParameters())) {
                        selfOperation = true;
                    }
                }
View Full Code Here

        if (actualString.equals(objString) && expectedCat == TypeCategory.TYPE_VARIABLE) {
            return IncompatibleTypes.SEEMS_OK;
        }
        if (ignoreBaseType) {
            if (expectedCat == TypeCategory.PARAMETERIZED && argCat == TypeCategory.PARAMETERIZED) {
                GenericObjectType parmGeneric = (GenericObjectType) expectedType;
                GenericObjectType argGeneric = (GenericObjectType) actualType;
                return compareTypeParameters(parmGeneric, argGeneric);
            }
            return IncompatibleTypes.SEEMS_OK;
        }

        if (actualType.equals(Type.OBJECT) && expectedCat == TypeCategory.ARRAY_TYPE) {
            return IncompatibleTypes.ARRAY_AND_OBJECT;
        }

        // -~- plain objects are easy
        if (expectedCat == TypeCategory.PLAIN_OBJECT_TYPE && argCat == TypeCategory.PLAIN_OBJECT_TYPE) {
            return IncompatibleTypes.getPriorityForAssumingCompatible(expectedType, actualType, false);
        }

        if (expectedCat == TypeCategory.PARAMETERIZED && argCat == TypeCategory.PLAIN_OBJECT_TYPE) {
            return IncompatibleTypes.getPriorityForAssumingCompatible((GenericObjectType) expectedType, actualType);
        }
        if (expectedCat == TypeCategory.PLAIN_OBJECT_TYPE && argCat == TypeCategory.PARAMETERIZED) {
            return IncompatibleTypes.getPriorityForAssumingCompatible((GenericObjectType) actualType, expectedType);
        }

        // -~- parmType is: "? extends Another Type" OR "? super Another Type"
        if (expectedCat == TypeCategory.WILDCARD_EXTENDS || expectedCat == TypeCategory.WILDCARD_SUPER) {
            return compareTypes(((GenericObjectType) expectedType).getExtension(), actualType, ignoreBaseType);
        }

        // -~- Not handling type variables
        if (expectedCat == TypeCategory.TYPE_VARIABLE || argCat == TypeCategory.TYPE_VARIABLE) {
            return IncompatibleTypes.SEEMS_OK;
        }

        // -~- Array Types: compare dimensions, then base type
        if (expectedCat == TypeCategory.ARRAY_TYPE && argCat == TypeCategory.ARRAY_TYPE) {
            ArrayType parmArray = (ArrayType) expectedType;
            ArrayType argArray = (ArrayType) actualType;

            if (parmArray.getDimensions() != argArray.getDimensions()) {
                return IncompatibleTypes.ARRAY_AND_NON_ARRAY;
            }

            return compareTypes(parmArray.getBasicType(), argArray.getBasicType(), ignoreBaseType);
        }
        // If one is an Array Type and the other is not, then they
        // are incompatible. (We already know neither is java.lang.Object)
        if (expectedCat == TypeCategory.ARRAY_TYPE ^ argCat == TypeCategory.ARRAY_TYPE) {
            return IncompatibleTypes.ARRAY_AND_NON_ARRAY;
        }

        // -~- Parameter Types: compare base type then parameters
        if (expectedCat == TypeCategory.PARAMETERIZED && argCat == TypeCategory.PARAMETERIZED) {
            GenericObjectType parmGeneric = (GenericObjectType) expectedType;
            GenericObjectType argGeneric = (GenericObjectType) actualType;

            // base types should be related
            {
                IncompatibleTypes result = compareTypes(parmGeneric.getObjectType(), argGeneric.getObjectType(), ignoreBaseType);
                if (!result.equals(IncompatibleTypes.SEEMS_OK)) {
                    return result;
                }
            }
            return compareTypeParameters(parmGeneric, argGeneric);
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.generic.GenericObjectType

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.