package accrue.analysis.ast;

import java.util.List;

import polyglot.ast.Block;
import polyglot.ast.Call;
import polyglot.ast.Catch;
import polyglot.ast.ClassBody;
import polyglot.ast.ConstructorCall;
import polyglot.ast.ConstructorCall.Kind;
import polyglot.ast.DelFactory;
import polyglot.ast.Expr;
import polyglot.ast.ExtFactory;
import polyglot.ast.Formal;
import polyglot.ast.Id;
import polyglot.ast.New;
import polyglot.ast.NodeFactory_c;
import polyglot.ast.Receiver;
import polyglot.ast.Try;
import polyglot.ast.TypeNode;
import polyglot.util.CollectionUtil;
import polyglot.util.Position;
import accrue.analysis.ext.AnalysisExtFactory_c;

public class AccrueNodeFactory_c extends NodeFactory_c implements
        AccrueNodeFactory {
    public AccrueNodeFactory_c(ExtFactory extFactory) {
        super(extFactory);
    }

    public AccrueNodeFactory_c(ExtFactory extFactory, DelFactory delFactory) {
        super(extFactory, delFactory);
    }

    @Override
    public Call Call(Position pos, Receiver target, Id name, List<Expr> args) {
        Call n =
                new AccrueCall_c(pos,
                                 target,
                                 name,
                                 CollectionUtil.nonNullList(args));
        n = (Call) n.ext(extFactory().extCall());
        n = (Call) n.del(delFactory().delCall());
        return n;
    }

    @Override
    public ConstructorCall ConstructorCall(Position pos, Kind kind, Expr outer,
            List<Expr> args) {
        ConstructorCall n =
                new AccrueConstructorCall_c(pos,
                                            kind,
                                            outer,
                                            CollectionUtil.nonNullList(args));
        n = (ConstructorCall) n.ext(extFactory().extConstructorCall());
        n = (ConstructorCall) n.del(delFactory().delConstructorCall());
        return n;
    }

    @Override
    public New New(Position pos, Expr outer, TypeNode objectType,
            List<Expr> args, ClassBody body) {
        New n =
                new AccrueNew_c(pos,
                                outer,
                                objectType,
                                CollectionUtil.nonNullList(args),
                                body);
        n = (New) n.ext(extFactory().extNew());
        n = (New) n.del(delFactory().delNew());
        return n;
    }

    @Override
    public Try Try(Position pos, Block tryBlock, List<Catch> catchBlocks,
            Block finallyBlock) {
        Try n =
                new AccrueTry_c(pos,
                                tryBlock,
                                CollectionUtil.nonNullList(catchBlocks),
                                finallyBlock);
        n = (Try) n.ext(extFactory().extTry());
        n = (Try) n.del(delFactory().delTry());
        return n;
    }

    @Override
    public Catch Catch(Position pos, Formal formal, Block body) {
        Catch n = new AccrueCatch_c(pos, formal, body);
        n = (Catch) n.ext(extFactory().extCatch());
        n = (Catch) n.del(delFactory().delCatch());
        return n;
    }

    @Override
    public Suppress Suppress(Position pos, List<TypeNode> suppressExs, Expr expr) {
        Suppress n = new Suppress_c(pos, suppressExs, expr);

        n =
                (Suppress) n.ext(((AnalysisExtFactory_c) extFactory()).extSuppress());

        return n;
    }

}
