📄 rmidebuggerservice.java
字号:
{
insertDebugBreak(t, breakpoint);
}
}
}
}
}
private static void insertDebugBreak(Template t, Breakpoint breakpoint)
{
TemplateElement te = findTemplateElement(t.getRootTreeNode(), breakpoint.getLine());
if(te == null)
{
return;
}
TemplateElement parent = (TemplateElement)te.getParent();
DebugBreak db = new DebugBreak(te);
// TODO: Ensure there always is a parent by making sure
// that the root element in the template is always a MixedContent
// Also make sure it doesn't conflict with anyone's code.
parent.setChildAt(parent.getIndex(te), db);
}
private static TemplateElement findTemplateElement(TemplateElement te, int line)
{
if(te.getBeginLine() > line || te.getEndLine() < line)
{
return null;
}
// Find the narrowest match
for(Enumeration children = te.children(); children.hasMoreElements();)
{
TemplateElement child = (TemplateElement)children.nextElement();
TemplateElement childmatch = findTemplateElement(child, line);
if(childmatch != null)
{
return childmatch;
}
}
// If no child provides narrower match, return this
return te;
}
private TemplateDebugInfo findTemplateDebugInfo(String templateName)
{
processRefQueue();
return (TemplateDebugInfo)templateDebugInfos.get(templateName);
}
private TemplateDebugInfo createTemplateDebugInfo(String templateName)
{
TemplateDebugInfo tdi = findTemplateDebugInfo(templateName);
if(tdi == null)
{
tdi = new TemplateDebugInfo();
templateDebugInfos.put(templateName, tdi);
}
return tdi;
}
void removeBreakpoint(Breakpoint breakpoint)
{
String templateName = breakpoint.getTemplateName();
synchronized(templateDebugInfos)
{
TemplateDebugInfo tdi = findTemplateDebugInfo(templateName);
if(tdi != null)
{
List breakpoints = tdi.breakpoints;
int pos = Collections.binarySearch(breakpoints, breakpoint);
if(pos >= 0)
{
breakpoints.remove(pos);
for (Iterator iter = tdi.templates.iterator(); iter.hasNext();)
{
TemplateReference ref = (TemplateReference) iter.next();
Template t = ref.getTemplate();
if(t == null)
{
iter.remove();
}
else
{
removeDebugBreak(t, breakpoint);
}
}
}
if(tdi.isEmpty())
{
templateDebugInfos.remove(templateName);
}
}
}
}
private void removeDebugBreak(Template t, Breakpoint breakpoint)
{
TemplateElement te = findTemplateElement(t.getRootTreeNode(), breakpoint.getLine());
if(te == null)
{
return;
}
DebugBreak db = null;
while(te != null)
{
if(te instanceof DebugBreak)
{
db = (DebugBreak)te;
break;
}
te = (TemplateElement)te.getParent();
}
if(db == null)
{
return;
}
TemplateElement parent = (TemplateElement)db.getParent();
parent.setChildAt(parent.getIndex(db), (TemplateElement)db.getChildAt(0));
}
void removeBreakpoints(String templateName)
{
synchronized(templateDebugInfos)
{
TemplateDebugInfo tdi = findTemplateDebugInfo(templateName);
if(tdi != null)
{
removeBreakpoints(tdi);
if(tdi.isEmpty())
{
templateDebugInfos.remove(templateName);
}
}
}
}
void removeBreakpoints()
{
synchronized(templateDebugInfos)
{
for (Iterator iter = templateDebugInfos.values().iterator(); iter.hasNext();)
{
TemplateDebugInfo tdi = (TemplateDebugInfo) iter.next();
removeBreakpoints(tdi);
if(tdi.isEmpty())
{
iter.remove();
}
}
}
}
private void removeBreakpoints(TemplateDebugInfo tdi)
{
tdi.breakpoints.clear();
for (Iterator iter = tdi.templates.iterator(); iter.hasNext();)
{
TemplateReference ref = (TemplateReference) iter.next();
Template t = ref.getTemplate();
if(t == null)
{
iter.remove();
}
else
{
removeDebugBreaks(t.getRootTreeNode());
}
}
}
private void removeDebugBreaks(TemplateElement te)
{
int count = te.getChildCount();
for(int i = 0; i < count; ++i)
{
TemplateElement child = (TemplateElement)te.getChildAt(i);
while(child instanceof DebugBreak)
{
TemplateElement dbchild = (TemplateElement)child.getChildAt(0);
te.setChildAt(i, dbchild);
child = dbchild;
}
removeDebugBreaks(child);
}
}
private static final class TemplateDebugInfo
{
final List templates = new ArrayList();
final List breakpoints = new ArrayList();
boolean isEmpty()
{
return templates.isEmpty() && breakpoints.isEmpty();
}
}
private static final class TemplateReference extends WeakReference
{
final String templateName;
TemplateReference(String templateName, Template template, ReferenceQueue queue)
{
super(template, queue);
this.templateName = templateName;
}
Template getTemplate()
{
return (Template)get();
}
}
private void processRefQueue()
{
for(;;)
{
TemplateReference ref = (TemplateReference)refQueue.poll();
if(ref == null)
{
break;
}
TemplateDebugInfo tdi = findTemplateDebugInfo(ref.templateName);
if(tdi != null)
{
tdi.templates.remove(ref);
if(tdi.isEmpty())
{
templateDebugInfos.remove(ref.templateName);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -