/** * Create a new method that will override the parent. * * @param function The method that you want ot override. */ private void addNewMethod(Function function) { String fnNameFormat = "%s.prototype." + function.getName(); String methodPrototype = String.format(fnNameFormat, finder.getCurrentNamespace()); String parentMethodPrototype = String.format(fnNameFormat, finder.getParentNamespace()); String jsDoc = function.getExtendedJsDoc(); String arguments = function.getArguments(); String callArguments = arguments; if (callArguments.trim().length() > 0) { callArguments = ", " + callArguments; } final String methodTemplate = String.format( "%s\n%s = function(%s) {\n" + " %s.call(this%s);\n" + "};\n", jsDoc, methodPrototype, arguments, parentMethodPrototype, callArguments); runWriteActionInsideCommand( project, "Override method", new Runnable() { @Override public void run() { int offset = editor.getCaretModel().getOffset(); document.replaceString(offset, offset, methodTemplate); } }); }