package de.dhbwstuttgart.typeinference.assumptions;

import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.TypeScope;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.constraints.GenericsResolver;
import de.dhbwstuttgart.typeinference.typeAlgo.TYPEStmt;

import java.util.ArrayList;
import java.util.List;

public class MethodAssumption extends Assumption{
    private ClassOrInterface receiver;
    private RefTypeOrTPHOrWildcardOrGeneric retType;
    List<? extends RefTypeOrTPHOrWildcardOrGeneric> params;
    private final boolean isInherited;
    private final boolean isOverridden;

    public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType,
                            List<? extends RefTypeOrTPHOrWildcardOrGeneric> params, TypeScope scope, boolean isInherited, boolean isOverridden){
        super(scope);
        this.receiver = receiver;
        this.retType = retType;
        this.params = params;
        this.isInherited = isInherited;
        this.isOverridden = isOverridden;
    }

    /*
    public RefType getReceiverType() {

        return receiver;
    }
 */

    public ClassOrInterface getReceiver(){
        return receiver;
    }
    
    public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
    	return retType;
    }
    
    public List<? extends RefTypeOrTPHOrWildcardOrGeneric> getArgTypes(){
    	return params;
    }

    public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) {
        return resolver.resolve(retType);
    }

    public List<RefTypeOrTPHOrWildcardOrGeneric> getArgTypes(GenericsResolver resolver) {
        List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
        for(RefTypeOrTPHOrWildcardOrGeneric param : params){
            param = resolver.resolve(param);
            ret.add(param);
        }
        return ret;
    }

    /**
     *
     * @param resolver
     * @return
     */
    public RefTypeOrTPHOrWildcardOrGeneric getReceiverType(GenericsResolver resolver) {
        return TYPEStmt.getReceiverType(receiver, resolver);
    }
    
    public boolean isInherited() {
    	return isInherited;
    }
    
    public boolean isOverridden() {
    	return isOverridden;
    }
}
