!7 p-experiment { S snippetID = #1015725; S orig = loadSnippet(snippetID); L tok = javaTok(orig); Map bracketMap = getBracketMap(tok); L l = jfindAll(tok, "? ="); for (int i : l) { S type = or2(tok_inferTypeAt(tok, bracketMap, i+6), "?"); //print(tok.get(i+2) + " => " + type); if (nempty(type)) tok.set(i, type); } S text = join(tok); print(); printIndent(text); if (neq(text, orig)) editSnippet(snippetID, text); } sS tok_inferTypeAt(L tok, Map bracketMap, int i) { int j = scanToEndOfInitializer(tok, bracketMap, i); L tok2 = subList(tok, i-1, j+1); //printStruct(tok2); fS fname = pairA(tok_parseFunctionCall(tok2)); if (fname == null) null; //print("fname: " + fname); S snippetID = stdFunctions_cached().get(fname); if (snippetID == null) null; LL defs = findFullFunctionDefs(javaTokSnippet(snippetID), true); //print("Have " + l(defs) + " defs"); defs = filter(func(L def) -> bool { eq(tok_functionName(def), fname) }, defs); //print("Have " + l(defs) + " defs"); new HashSet types; for (L def : defs) { int k = tok_skipModifiers(def, 1); // TODO: skip type args S type = joinSubList(def, k, indexOf(def, k, fname)-1); types.add(type); } ret singletonOpt(types); }