Symbol constr = (Symbol)constructors.get(fun.symbol()); if (constr != null) return gen.mkApplyTV( tree.pos, gen.Select(fun.pos, gen.This(fun.pos, constr.owner()), constr), transform(targs), transform(args)); break;
if (!fun.symbol().isConstructor()) break; Symbol constr = getConstructor(fun.symbol()); fun = gen.Select(fun.pos, getInitializerQualifier(fun), constr); return gen.mkApplyTV(tree.pos, fun, transform(targs), transform(args));
    public Tree transform(Tree tree) {	final Symbol treeSym = tree.symbol();	switch (tree) {	case ClassDef(_, _, _, _, _, Template impl):	    if (treeSym.isInterface())		return super.transform(tree);	    // expressions that go before the call to the super constructor	    final ArrayList constrBody = new ArrayList();	    // expressions that go after the call to the super constructor	    final ArrayList constrBody2 = new ArrayList();	    // the body of the class after the transformation	    final ArrayList classBody = new ArrayList();	    // the Symbol of the new primary constructor	    final Symbol constrSym =		getConstructor(treeSym.primaryConstructor());	    assert constrSym.owner() == treeSym :		"Wrong owner of the constructor: \n\tfound: " +		Debug.show(constrSym.owner()) + "\n\texpected: " +		Debug.show(treeSym);	    for (int i = 0; i < impl.body.length; i++) {		Tree t = impl.body[i];		if (t.definesSymbol()) {		    Symbol sym = t.symbol();		    switch (t) {		    // for ValDefs move the initialization code to the constructor		    case ValDef(_, _, _, Tree rhs):			if (rhs != Tree.Empty) {			    Tree lhs =			        gen.Select(gen.This(t.pos, treeSym), sym);			    Tree assign =				gen.Assign(t.pos, lhs, transform(rhs));			    t = gen.ValDef(sym, Tree.Empty);			    if (rhs.hasSymbol() && rhs.symbol().isParameter()) {				constrBody.add(assign);			    } else {				constrBody2.add(assign);			    }			}			break;		    // assign new symbols to the alternative constructors		    case DefDef(_, _, _, _, _, Tree rhs):			if (sym.isConstructor()) {                            // add result expression consistent with the                            // result type of the constructor                            Tree result = forINT                                ? gen.This(t.pos, treeSym)                                : gen.mkUnitLit(t.pos);                            rhs = gen.mkBlock(new Tree[] { rhs, result });			    t = gen.DefDef(getConstructor(sym), rhs);			}			break;		    }		    // do not transform(t). It will be done at the end		    classBody.add(t);		} else {		    // move class-level expressions into the constructor		    constrBody2.add(transform(impl.body[i]));		}	    }	    // inline the call to the super constructor            if ( !forINT || !treeSym.parents()[0].symbol().isJava()) {		switch (impl.parents[0]) {		case Apply(TypeApply(Tree fun, Tree[] targs), Tree[] args):		    int pos = impl.parents[0].pos;		    Tree superConstr = gen.Select			(gen.Super(pos, treeSym),			 getConstructor(fun.symbol()));		    constrBody.add(gen.mkApplyTV(superConstr,						 transform(targs),						 transform(args)));		    break;		case Apply(Tree fun, Tree[] args):		    int pos = impl.parents[0].pos;		    Tree superConstr = gen.Select			(gen.Super(pos, treeSym),			 getConstructor(fun.symbol()));		    constrBody.add(gen.mkApply_V(superConstr, transform(args)));		    break;		default:                    throw Debug.abort("illegal case", impl.parents[0]);		}	    }	    // inline initialization of module values            if (forINT && treeSym.isModuleClass()) {                Symbol module = treeSym.module();                if (module.isGlobalModule()) {                    constrBody.add(                        gen.Assign(                            gen.mkRef(tree.pos, module),                            gen.This(tree.pos, treeSym)));                } else {                    Symbol owner = module.owner();                    Name module_eqname = module.name.append(Names._EQ);                    Symbol module_eq = owner.lookup(module_eqname);                    assert module != Symbol.NONE :Debug.show(treeSym.module());                    if (owner.isModuleClass() && owner.module().isStable()) {                        constrBody.add(                            gen.mkApply_V(                                gen.mkRef(tree.pos, module_eq),                                new Tree[] {gen.This(tree.pos, treeSym)}));                    } else {                        // !!! module_eq must be accessed via some outer field                    }                }            }	    // add valdefs and class-level expression to the constructorr body	    constrBody.addAll(constrBody2);	    // add result expression consistent with the	    // result type of the constructor	    constrBody.add(forINT ? gen.This(tree.pos, treeSym)			   : gen.mkUnitLit(tree.pos));            Tree constrTree = constrBody.size() > 1 ?                gen.Block((Tree[])constrBody.			  toArray(new Tree[constrBody.size()])):                (Tree) constrBody.get(0);	    classBody.add(gen.DefDef(constrSym, constrTree));	    Tree[] newBody = (Tree[]) classBody.toArray(Tree.EMPTY_ARRAY);	    // transform the bodies of all members in order to substitute	    // the constructor references with the new ones	    for (int i = 0; i < newBody.length - 1; i ++)		newBody[i] = transform(newBody[i]);	    return gen.ClassDef(treeSym, newBody);	// Substitute the constructor into the 'new' expressions	case New(Template(Tree[] baseClasses, _)):	    Tree base = baseClasses[0];	    switch (base) {	    case Apply(TypeApply(Tree fun, Tree[] targs), Tree[] args):                return gen.New(                    tree.pos,                    gen.mkApplyTV(                        base.pos,                        gen.Ident(fun.pos, getConstructor(fun.symbol())),                        transform(targs),                        transform(args)));	    case Apply(Tree fun, Tree[] args):                return gen.New(                    tree.pos,                    gen.mkApply_V(                        base.pos,                        gen.Ident(fun.pos, getConstructor(fun.symbol())),                        transform(args)));	    default:		assert false;	    }	    break;	// Substitute the constructor aplication;	// this only occurs within constructors that terminate	// by a call to another constructor of the same class	case Apply(TypeApply(Tree fun, Tree[] targs), Tree[] args):	    Symbol constr = (Symbol)constructors.get(fun.symbol());	    if (constr != null)		return gen.mkApplyTV(                    tree.pos,                    gen.Select(fun.pos, gen.This(fun.pos, constr.owner()), constr),                    transform(targs),                    transform(args));	    break;	case Apply(Tree fun, Tree[] args):	    Symbol constr = (Symbol)constructors.get(fun.symbol());	    if (constr != null)		return gen.mkApply_V(                    tree.pos,                    gen.Select(fun.pos, gen.This(fun.pos, constr.owner()), constr),                    transform(args));	    break;	} // switch(tree)	return super.transform(tree);    } // transform()