Search in sources :

Example 1 with SameAsBound

use of com.github.javaparser.symbolsolver.resolution.typeinference.bounds.SameAsBound in project javaparser by javaparser.

the class TypeSameAsType method reduce.

@Override
public ReductionResult reduce(BoundSet currentBoundSet) {
    if (!S.isWildcard() && !T.isWildcard()) {
        if (isProperType(S) && isProperType(T)) {
            if (S.equals(T)) {
                return ReductionResult.trueResult();
            } else {
                return ReductionResult.falseResult();
            }
        }
        if (S.isNull() || T.isNull()) {
            return ReductionResult.falseResult();
        }
        if (isInferenceVariable(S) && !T.isPrimitive()) {
            return ReductionResult.oneBound(new SameAsBound(S, T));
        }
        if (isInferenceVariable(T) && !S.isPrimitive()) {
            return ReductionResult.oneBound(new SameAsBound(S, T));
        }
        if (S.isReferenceType() && T.isReferenceType() && S.asReferenceType().toRawType().equals(T.asReferenceType().toRawType())) {
            ReductionResult res = ReductionResult.empty();
            List<ResolvedType> Bs = S.asReferenceType().typeParametersValues();
            List<ResolvedType> As = T.asReferenceType().typeParametersValues();
            for (int i = 0; i < Bs.size(); i++) {
                res = res.withConstraint(new TypeSameAsType(Bs.get(i), As.get(i)));
            }
            return res;
        }
        if (S.isArray() && T.isArray()) {
            return ReductionResult.oneConstraint(new TypeSameAsType(S.asArrayType().getComponentType(), T.asArrayType().getComponentType()));
        }
        return ReductionResult.falseResult();
    }
    throw new UnsupportedOperationException();
}
Also used : SameAsBound(com.github.javaparser.symbolsolver.resolution.typeinference.bounds.SameAsBound) ResolvedType(com.github.javaparser.resolution.types.ResolvedType)

Aggregations

ResolvedType (com.github.javaparser.resolution.types.ResolvedType)1 SameAsBound (com.github.javaparser.symbolsolver.resolution.typeinference.bounds.SameAsBound)1