home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 1997-1998 - Modelworks Software
- // @Created build 213 (9 September 1998)
- // @Modified build 215 cm19980911 - changed order to match JavaDoc
- // @Modified build 265 cm19990213 - fixed abstract method problem
-
- /**
- @Tool: insertJavadocMethod~inserts a Javadoc method comment.
- To use put the caret at the begining of the method declaration
- then run this script.
- @EndTool:
- @Summary: insertJavadocMethod~inserts a Javadoc method comment
- */
-
- var gOutput = getOutput();
-
- var localCommentHeader =
- "\n/**" +
- "\n* @CaretShort concise description." +
- "\n* Additional verbose description.";
-
- var commentReturns =
- "\n* @return description.";
-
- var commentTrailer =
- "\n* @see package.class" +
- "\n*/\n";
-
- function DoCommand()
- {
- var editor = getActiveEditor();
- if (editor)
- {
- Insert(editor, localCommentHeader, 1);
- editor.setActive("Insert Javadoc Method");
- }
- }
-
- function Insert(editor, commentHeader, adjust)
- {
- var selection = editor.getSelection();
- var indentLevel = editor.getIndentLevel(selection.startLineIndex);
- var delimiterList = editor.findNextDelimiters("(", ")", selection.startLineIndex, selection.startCharIndex);
- if (delimiterList && delimiterList.count > 0)
- {
- var parametersRange = delimiterList.removeHead();
- if (parametersRange)
- {
- var throwsList = GetThrowsList(editor, parametersRange.endLineIndex, parametersRange.endCharIndex);
-
- parametersRange.startCharIndex += 1;
- parametersRange.endCharIndex -= 1;
- var parameters = editor.copy(parametersRange);
-
- var comment = commentHeader;
- if (parameters != null)
- {
- comment += ProcessParameters(parameters);
- }
- comment += commentReturns;
- if (throwsList != null)
- {
- comment += ProcessThrows(throwsList);
- }
- comment += commentTrailer;
-
- var range = editor.insert(selection.startLineIndex, selection.startCharIndex, comment);
-
- CleanupMultilineComment(editor, indentLevel, range.startLineIndex + adjust); // The comment starts in the next line
-
- // Now replace @Caret with the real caret
- var findData = editor.findFirst("@Caret", selection.startLineIndex, 0);
- if (findData && findData.found)
- {
- editor.replace("", findData.range);
- editor.select(findData.range.startLineIndex, findData.range.startCharIndex);
- }
- }
- }
- }
-
- function GetThrowsList(editor, startLineIndex, startCharIndex)
- {
- var throwsList = "";
- var bodyRange = null;
- var delimiterList = editor.findNextDelimiters("{", "}", startLineIndex, startCharIndex);
- if (delimiterList && delimiterList.count > 0)
- {
- bodyRange = delimiterList.removeHead();
- }
-
- var semicolonFindData = editor.findFirst(";", startLineIndex, startCharIndex);
- var throwsFindData = editor.findFirst("throws", startLineIndex, startCharIndex);
-
- if (throwsFindData && throwsFindData.found)
- {
- // cm19990213
- if (semicolonFindData && bodyRange)
- {
- if (semicolonFindData.range.compare(bodyRange) == -1)
- {
- throwsList = editor.copy(throwsFindData.range.endLineIndex,throwsFindData.range.endCharIndex,
- semicolonFindData.range.startLineIndex, semicolonFindData.range.endCharIndex-1);
- }
- else
- {
- throwsList = editor.copy(throwsFindData.range.endLineIndex,throwsFindData.range.endCharIndex,
- bodyRange.startLineIndex, bodyRange.startCharIndex-1);
- }
- }
- else if (semicolonFindData && bodyRange == null)
- {
- throwsList = editor.copy(throwsFindData.range.endLineIndex,throwsFindData.range.endCharIndex,
- semicolonFindData.range.startLineIndex, semicolonFindData.range.endCharIndex-1);
- }
- else if (semicolonFindData == null && bodyRange)
- {
- throwsList = editor.copy(throwsFindData.range.endLineIndex,throwsFindData.range.endCharIndex,
- bodyRange.startLineIndex, bodyRange.startCharIndex-1);
- }
- }
- return throwsList;
- }
-
- function ProcessThrows(throwsList)
- {
- // add "\n* @exception name" for each throw
-
- var insert = "";
- var start = 0;
- var length = throwsList.length;
- var nextWord;
- while (start < length)
- {
- start = skipDelimiters(throwsList, start);
-
- var typeString = searchInString(throwsList, "[^\t\r\n\, ]*", start);
-
- if (typeString == null || typeString.key.length == 0)
- {
- break;
- }
-
- insert += "\n* @exception " + typeString.key + " description.";
- start += typeString.key.length
- }
- return insert;
- }
-
- function skipDelimiters(string, start)
- {
- var nextWord = searchInString(string, "[\t\r\n\, ]*", start);
- if (nextWord)
- {
- return start + nextWord.key.length;
- }
- return start;
- }
-
- var gSplitParam = /\t|\n| /;
- var gTrim = /[\t|\n|\r| ]*([^\t|\n|\r| ]*)/;
-
- function Trim(s)
- {
- if (gTrim.exec(s))
- {
- return RegExp.$1;
- }
- return s;
- }
-
- function ProcessParameters(parameters)
- {
- var insert = "";
- var paramarray = parameters.split(',');
- if (paramarray)
- {
- var count = paramarray.length;
- for (var i = 0; i < count; i++)
- {
- if (paramarray[i].length > 0)
- {
- var entry = paramarray[i];
- gOutput.writeLine(entry);
- // Get last word
- var array = entry.split(gSplitParam);
- if (array)
- {
- var index = array.length - 1;
- while (array[index].length == 0 && index > 0)
- {
- index -= 1;
- }
- insert += "\n* @param " + Trim(array[index]) + " description.";
- }
- }
- }
- }
- return insert;
- }
-
- var gFirstRegExp = /\s*\/\*/;
- var gInnerRegExp = /(\s*\*)/;
-
- function CleanupMultilineComment(editor, indentLevel, startLine)
- {
- var smartReformat = getMapFileValue("Preferences", "Smart reformat multiline comments", true);
- editor.setIndentLevel(startLine, indentLevel);
- var lineData = editor.copy(startLine);
- if (gFirstRegExp.exec(lineData))
- {
- startLine += 1;
- editor.setIndentLevel(startLine, indentLevel);
- lineData = editor.copy(startLine);
- while (gInnerRegExp.exec(lineData))
- {
- if (smartReformat)
- {
- var index = RegExp.$1.length;
- editor.replace(" ", startLine, index-1, startLine, index-1);
- }
- startLine += 1;
- editor.setIndentLevel(startLine, indentLevel);
- lineData = editor.copy(startLine);
- }
- }
- }
-
- !!/Script
-
-