private Set<String> typeVariablesOf(TypeSignature typeSignature) { if (typeVariableConstraints.containsKey(typeSignature.getBase())) { return ImmutableSet.of(typeSignature.getBase()); } Set<String> variables = new HashSet<>(); for (TypeSignatureParameter parameter : typeSignature.getParameters()) { switch (parameter.getKind()) { case TYPE: variables.addAll(typeVariablesOf(parameter.getTypeSignature())); break; case NAMED_TYPE: variables.addAll(typeVariablesOf(parameter.getNamedTypeSignature().getTypeSignature())); break; case LONG: break; case VARIABLE: break; default: throw new UnsupportedOperationException(); } } return variables; }
private Set<String> typeVariablesOf(TypeSignature typeSignature) { if (typeVariableConstraints.containsKey(typeSignature.getBase())) { return ImmutableSet.of(typeSignature.getBase()); } Set<String> variables = new HashSet<>(); for (TypeSignatureParameter parameter : typeSignature.getParameters()) { switch (parameter.getKind()) { case TYPE: variables.addAll(typeVariablesOf(parameter.getTypeSignature())); break; case NAMED_TYPE: variables.addAll(typeVariablesOf(parameter.getNamedTypeSignature().getTypeSignature())); break; case LONG: break; case VARIABLE: break; default: throw new UnsupportedOperationException(); } } return variables; }
private boolean appendTypeRelationshipConstraintSolver( ImmutableList.Builder<TypeConstraintSolver> resultBuilder, TypeSignature formalTypeSignature, TypeSignatureProvider actualTypeSignatureProvider, boolean allowCoercion) { if (actualTypeSignatureProvider.hasDependency()) { // Fail if the formal type is not function. // Otherwise do nothing because FunctionConstraintSolver will handle type relationship constraint directly return FunctionType.NAME.equals(formalTypeSignature.getBase()); } Set<String> typeVariables = typeVariablesOf(formalTypeSignature); Set<String> longVariables = longVariablesOf(formalTypeSignature); resultBuilder.add(new TypeRelationshipConstraintSolver( formalTypeSignature, typeVariables, longVariables, typeManager.getType(actualTypeSignatureProvider.getTypeSignature()), allowCoercion)); return true; }
private boolean appendTypeRelationshipConstraintSolver( ImmutableList.Builder<TypeConstraintSolver> resultBuilder, TypeSignature formalTypeSignature, TypeSignatureProvider actualTypeSignatureProvider, boolean allowCoercion) { if (actualTypeSignatureProvider.hasDependency()) { // Fail if the formal type is not function. // Otherwise do nothing because FunctionConstraintSolver will handle type relationship constraint directly return FunctionType.NAME.equals(formalTypeSignature.getBase()); } Set<String> typeVariables = typeVariablesOf(formalTypeSignature); Set<String> longVariables = longVariablesOf(formalTypeSignature); resultBuilder.add(new TypeRelationshipConstraintSolver( formalTypeSignature, typeVariables, longVariables, typeManager.getType(actualTypeSignatureProvider.getTypeSignature()), allowCoercion)); return true; }