// e.g. // void tailCall aka replace(Computable x) {...} // to: // void tailCall(Computable x) {...} // final void replace(Computable x) { tailCall(x); } // (or the other way around) svoid tok_akaFunctionNames(LS tok) { int i; bool useFinal = true; while ((i = jfind(tok, " aka ")) >= 0) { int iName1 = i, _iLastName = i+4; while (eqGet(tok, _iLastName+2, "aka") && isIdentifier(get(tok, _iLastName+4))) _iLastName += 4; int iLastName = _iLastName; // find arguments int iOpening = indexOf(tok, iLastName, "("); int iClosing = findEndOfBracketPart2(tok, iOpening)-1; // find all names new LS names; for (int j = iName1; j <= iLastName; j += 4) names.add(tok.get(j)); // find javax modifiers, return type & modifiers int iType = tok_leftScanJavaxModifiers(tok, iName1); iType = tok_leftScanType(tok, iType); int iStart = leftScanModifiers(tok, tok_leftScanTypeArgsOpt(tok, iType)); // parse argument list LS _args = subList(tok, iOpening+1, iClosing); LS args = tok_parseArgsDeclList2(_args); // analyze return type LS type = subList(tok, iType-1, iName1); // return type bool isVoid = containsOneOf(codeTokens(type), javaxVoidAliases()); // drop all but first name clearTokens(tok, iName1+1, iLastName+1); int iBodyOpen = indexOfAny(tok, iClosing, "{", ";"); bool hasBody = eqGet(tok, iBodyOpen, "{"); // The following logic is nasty, but the tests in test_tok_akaFunctionNames // make it alright // modifiers include return type actually LS tokModifiers = cloneSubList(tok, iStart, iName1-1); bool isAbstract = tokModifiers.remove("abstract"); bool isDefault = tokModifiers.contains("default"); tokModifiers.remove("synchronized"); if (!isDefault && !isAbstract && !hasBody) { set isDefault; tokModifiers.add(0, "default "); } S modifiers = join(tokModifiers); if (isDefault && !hasBody) replaceElementInSubList(tok, iStart, iType, "default", ""); // make synonyms final unless we're in an interface if (!isDefault && !contains(tokModifiers, "final")) modifiers = "final " + modifiers; S _modifiers = modifiers; //S exceptionClauses = joinSubList(tok, iClosing+1, iBodyOpen-1); // add synonyms tokPrepend(tok, iStart, joinMap(dropFirst(names), name -> _modifiers + " " + name // arguments and declared exceptions + joinSubList(tok, iLastName+1, iBodyOpen-1) + "{ " + stringIf(!isVoid, "return ") + first(names) + "(" + joinWithComma(lmap tok_lastIdentifier(args)) + "); }\n")); reTok(tok, iStart, iLastName+1); } }