// pattern, replacement, index of following token static L> tok_quicknew2_patterns = ll( t3("new ", "new $2()", 5), t3("new .", "new $2.$4()", 9), t3("new <>", "new $2<>()", 9), t3("new < >", "new $2<$4>()", 11), ); svoid tok_quicknew2(L tok) { tok_quicknew(tok); bool needFix; // [abandoned, confusing, looks like a function definition] with arguments - new A a(...); => A a = new A(...); //jreplace(tok, "new (", "$2 $3 = new $2("); jreplace(tok, "for args " + "{", "for (int i = 0; i < args.length; i++) { final String arg = args[i];"); // Constructor calls without parentheses // So you can say something like: predictors.add(new P1); for (T3 t : tok_quicknew2_patterns) jreplace1(tok, t.a, t.b, tokcondition { ret eqOneOf(_get(tok, i+t.c), "{", ",", ")", ";", ":", "!"); }); jreplace(tok, "new Collection(", "new List("); jreplace(tok, "new List(", "new ArrayList("); jreplace(tok, "new Map(", "new HashMap("); jreplace(tok, "new Set(", "new HashSet("); jreplace(tok, "new (Hash)Set", "new HashSet"); // rough jreplace(tok, "new (Tree)Set", "new TreeSet"); jreplace(tok, "new (Hash)Map", "new HashMap"); jreplace(tok, "new (Tree)Map", "new TreeMap"); jreplace(tok, "\\*[] ;", "$2[] $6 = new $2[$4];"); // X x = new(...) => X x = new X(...) // X x = new {...} => X x = new X {...} // X x = new => X x = new jreplace(tok, ". = new", "$1.$3 $4 = new $1.$3", tokcondition { ret tokCondition_shortNew(tok, i+13); }); jreplace(tok, " = new", "$1 $2 = new $1", tokcondition { ret tokCondition_shortNew(tok, i+9); }); jreplace(tok, " = new \\*", "$1 $2 = new $1"); jreplace(tok, "\\* = new ", "$5 $2 = new $5"); // TODO: use backward type scanning needFix |= jreplace(tok, "<> = new", "$1 $2 $3 $4 $5 = new $1<>", tokcondition { ret tokCondition_shortNew(tok, i+9+3*2); }); needFix |= jreplace(tok, "<,> = new", "$1 $2 $3 $4 $5 $6 $7 = new $1<>", tokcondition { ret tokCondition_shortNew(tok, i+9+5*2); }); needFix |= jreplace(tok, "<<>> = new", "$1 $2 $3 $4 $5 $6 $7 $8 = new $1<>", tokcondition { ret tokCondition_shortNew(tok, i+9+6*2); }); needFix |= jreplace(tok, "<<>,> = new", "$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 = new $1<>", tokcondition { ret tokCondition_shortNew(tok, i+9+8*2); }); // fix if (needFix) jreplace(tok, "<><>", "<>"); }