javadoc_find_params = true
function OnChar(c)
expand = "/**"
if c~="\n" then
return false
end
if editor:textrange(editor.CurrentPos-string.len(expand)-1, editor.CurrentPos-1)==expand then
next_line = editor:GetLine(editor:LineFromPosition(editor.CurrentPos)+1)
if next_line==nil or string.find(next_line, "^%s*%*")==nil then
prev_line = editor:GetLine(editor:LineFromPosition(editor.CurrentPos)-1)
t1,t2,indent = string.find(prev_line, "^(%s*)")
insert = indent.." * \n"
inserted = false
if next_line ~= nil and javadoc_find_params==true then
balance=0
pos=editor:PositionFromLine(editor:LineFromPosition(editor.CurrentPos)+1)
while char_at(pos)~="(" and char_at(pos)~="\n" and pos<editor.Length do
pos = pos+1
end
if char_at(pos)=="(" then
param = ""
pos = pos+1
while (char_at(pos)~=")" or balance~=0) and pos<editor.Length do
if char_at(pos)=="," and balance==0 then
insert = insert..process_param(param, indent)
param = ""
pos=pos+1
while char_at(pos)==" " do
pos=pos+1
end
end
if char_at(pos)=="(" then
balance = balance+1
end
if char_at(pos)==")" then
balance = balance-1
end
param = param..char_at(pos)
pos=pos+1
end
insert=insert..process_param(param, indent)..indent.." * @return \n"..indent.." */"
inserted=true
end
end
if javadoc_find_params==false or inserted==false then
insert = insert..indent.." */"
end
editor:insert(-1, insert)
editor:GotoPos(editor.LineEndPosition[editor:LineFromPosition(editor.CurrentPos)])
return
end
end
i = editor:LineFromPosition(editor.CurrentPos)-1
while i>0 do
line = editor:GetLine(i)
i = i-1
if string.find(line, "^%s*%*/") then
break
end
if string.find(line, "^(%s*)/%*%*")~=nil then
prev_line = editor:GetLine(editor:LineFromPosition(editor.CurrentPos)-1)
t1,t2,indent = string.find(prev_line, "^(%s*)%*")
if indent==nil then
t1,t2,indent=string.find(prev_line, "^(%s*)")
indent = indent .. " "
end
editor:insert(-1, indent.."* ")
editor:GotoPos(editor.LineEndPosition[editor:LineFromPosition(editor.CurrentPos)])
break
end
if string.find(line, "^%s*%*")==nil then
break
end
end
end
function process_param(param, indent)
if param=="" then
return ""
end
default=""
insert=""
t1,t2,t3,param=string.find(param, "^([a-zA-Z_0-9&\*]* )(.*)$")
if string.find(param, "=",0,true)~=nil then
t1,t2,param,default=string.find(param, "^(.-)=(.*)$")
end
insert = insert..indent.." * @param "..param
if default~="" then
insert = insert .. " (default: "..default..")"
end
insert = insert.."\n"
return insert
end
function char_at(p)
return string.char(editor.CharAt[p])
end
RecentChanges · preferences
edit · history
Last edited April 20, 2007 11:36 am GMT (diff)