diff --git a/src/org/ntlab/traceDebugger/CallStackModels.java b/src/org/ntlab/traceDebugger/CallStackModels.java index 5a1efb2..545c2dd 100644 --- a/src/org/ntlab/traceDebugger/CallStackModels.java +++ b/src/org/ntlab/traceDebugger/CallStackModels.java @@ -1,136 +1,144 @@ -package org.ntlab.traceDebugger; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.viewers.TreeNode; -import org.ntlab.traceAnalysisPlatform.tracer.trace.IStatementVisitor; -import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; -import org.ntlab.traceAnalysisPlatform.tracer.trace.Statement; -import org.ntlab.traceAnalysisPlatform.tracer.trace.ThreadInstance; -import org.ntlab.traceAnalysisPlatform.tracer.trace.TraceJSON; -import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; - -public class CallStackModels { - private String debuggingThreadId = ""; - private List debuggingThreadCallStacks = new ArrayList<>(); - private Map> allCallStacks = new HashMap<>(); - - public List getDebuggingThreadCallStacks() { - return debuggingThreadCallStacks; - } - - public Map> getAllCallStacks() { - return allCallStacks; - } - - public TreeNode[] getAllCallStacksTree() { - if (allCallStacks.isEmpty()) return new TreeNode[1]; - TreeNode[] roots = new TreeNode[allCallStacks.size()]; - int rootIndex = 0; - for (String threadId : allCallStacks.keySet()) { - TreeNode node = getCallStackModelsTree(threadId); - roots[rootIndex++] = node; - } - return roots; - } - - public TreeNode getCallStackModelsTree(String threadId) { - List callStackModelsInThread = allCallStacks.get(threadId); - if (callStackModelsInThread.isEmpty()) return null; - TreeNode root = new TreeNode(threadId); - TreeNode parentNode = root; - TreeNode[] childrenNode = new TreeNode[callStackModelsInThread.size()]; - parentNode.setChildren(childrenNode); - for (int i = 0; i < callStackModelsInThread.size(); i++) { - TreeNode childNode = new TreeNode(callStackModelsInThread.get(i)); - childNode.setParent(parentNode); - childrenNode[i] = childNode; - } - return root; - } - - public TreeNode[] getDebugingThreadCallStacksTree() { - TreeNode[] roots = new TreeNode[1]; - roots[0] = getCallStackModelsTree(debuggingThreadId); - return roots; - } - - public void reset() { - debuggingThreadId = ""; - debuggingThreadCallStacks.clear(); - allCallStacks.clear(); - } - - public void updateByTracePoint(TracePoint tp) { - if (tp == null) return; - int lineNo = tp.getStatement().getLineNo(); - updateInAllThreads(tp, lineNo); - } - - private void updateInAllThreads(TracePoint tp, int topMethodCallLineNo) { - Statement tpStatement = tp.getStatement(); - reset(); - debuggingThreadId = tpStatement.getThreadNo(); - debuggingThreadCallStacks = update(tp); - allCallStacks.put(debuggingThreadId, debuggingThreadCallStacks); - IStatementVisitor visitor = new CallStackVisitor(tp); -// updateOtherThreadCallStacks(visitor); - } - - private List update(TracePoint tp) { - List list = new ArrayList<>(); - TracePoint tmpTp = tp; - while (tmpTp != null) { - CallStackModel callStackModel = new CallStackModel(tmpTp); - list.add(callStackModel); - tmpTp = tmpTp.getMethodExecution().getCallerTracePoint(); - } - return list; - } - - private void updateOtherThreadCallStacks(IStatementVisitor visitor) { - TraceJSON traceJSON = (TraceJSON)TraceDebuggerPlugin.getAnalyzer().getTrace(); - Map allThreads = traceJSON.getAllThreads(); - for (String threadId : allThreads.keySet()) { - if (threadId.equals(debuggingThreadId)) continue; - TracePoint[] start = new TracePoint[1]; - start[0] = allThreads.get(threadId).getCurrentTracePoint(); - traceJSON.getLastStatementInThread(threadId, start, visitor); - TracePoint resultTp = start[0]; - allCallStacks.put(threadId, update(resultTp)); - } - } - - public void highlight(MethodExecution methodExecution) { - String signature1 = methodExecution.getSignature(); - for (List callStackModels : allCallStacks.values()) { - for (CallStackModel callStackModel : callStackModels) { - String signature2 = callStackModel.getMethodExecution().getSignature(); - callStackModel.setHighlighting(signature1.equals(signature2)); - } - } - } - -// public IStatementVisitor tmp(TracePoint tp) { -//// return new CallStackVisitor(tp); -// try { -// Class classClass = Class.forName("java.lang.Class"); -// Class[] classClassArray = (Class[])Array.newInstance(classClass, 1); -// Class tpClass = tp.getClass(); -// Array.set(classClassArray, 0, tpClass); -// Class visitorClass = Class.forName("org.ntlab.reverseDebugger.CallStackVisitor"); -// Constructor constructor = visitorClass.getConstructor(classClassArray); -// Class[] tpClassArray = (Class[])Array.newInstance(tpClass, 1); -// Array.set(tpClassArray, 0, tp); -// IStatementVisitor visitor = (IStatementVisitor)constructor.newInstance(tpClassArray); -// return visitor; -// } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException -// | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { -// e.printStackTrace(); -// } -// return null; -// } -} +package org.ntlab.traceDebugger; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.viewers.TreeNode; +import org.ntlab.traceAnalysisPlatform.tracer.trace.IStatementVisitor; +import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; +import org.ntlab.traceAnalysisPlatform.tracer.trace.Statement; +import org.ntlab.traceAnalysisPlatform.tracer.trace.ThreadInstance; +import org.ntlab.traceAnalysisPlatform.tracer.trace.TraceJSON; +import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; + +public class CallStackModels { + private String debuggingThreadId = ""; + private List debuggingThreadCallStacks = new ArrayList<>(); + private Map> allCallStacks = new HashMap<>(); + + public List getDebuggingThreadCallStacks() { + return debuggingThreadCallStacks; + } + + public Map> getAllCallStacks() { + return allCallStacks; + } + + public TreeNode[] getAllCallStacksTree() { + if (allCallStacks.isEmpty()) return new TreeNode[1]; + TreeNode[] roots = new TreeNode[allCallStacks.size()]; + int rootIndex = 0; + for (String threadId : allCallStacks.keySet()) { + TreeNode node = getCallStackModelsTree(threadId); + roots[rootIndex++] = node; + } + return roots; + } + + public TreeNode getCallStackModelsTree(String threadId) { + List callStackModelsInThread = allCallStacks.get(threadId); + if (callStackModelsInThread.isEmpty()) return null; + TreeNode root = new TreeNode(threadId); + TreeNode parentNode = root; + TreeNode[] childrenNode = new TreeNode[callStackModelsInThread.size()]; + parentNode.setChildren(childrenNode); + for (int i = 0; i < callStackModelsInThread.size(); i++) { + TreeNode childNode = new TreeNode(callStackModelsInThread.get(i)); + childNode.setParent(parentNode); + childrenNode[i] = childNode; + } + return root; + } + + public TreeNode[] getDebugingThreadCallStacksTree() { + TreeNode[] roots = new TreeNode[1]; + roots[0] = getCallStackModelsTree(debuggingThreadId); + return roots; + } + + public void reset() { + debuggingThreadId = ""; + debuggingThreadCallStacks.clear(); + allCallStacks.clear(); + } + + public void updateByTracePoint(TracePoint tp) { + if (tp == null) return; + int lineNo = tp.getStatement().getLineNo(); + updateInAllThreads(tp, lineNo); + } + + private void updateInAllThreads(TracePoint tp, int topMethodCallLineNo) { + Statement tpStatement = tp.getStatement(); + reset(); + debuggingThreadId = tpStatement.getThreadNo(); + debuggingThreadCallStacks = update(tp); + allCallStacks.put(debuggingThreadId, debuggingThreadCallStacks); + IStatementVisitor visitor = new CallStackVisitor(tp); +// updateOtherThreadCallStacks(visitor); + } + + private List update(TracePoint tp) { + List list = new ArrayList<>(); + TracePoint tmpTp = tp; + while (tmpTp != null) { + CallStackModel callStackModel = new CallStackModel(tmpTp); + list.add(callStackModel); + tmpTp = tmpTp.getMethodExecution().getCallerTracePoint(); + } + return list; + } + + private void updateOtherThreadCallStacks(IStatementVisitor visitor) { + TraceJSON traceJSON = (TraceJSON)TraceDebuggerPlugin.getAnalyzer().getTrace(); + Map allThreads = traceJSON.getAllThreads(); + for (String threadId : allThreads.keySet()) { + if (threadId.equals(debuggingThreadId)) continue; + TracePoint[] start = new TracePoint[1]; + start[0] = allThreads.get(threadId).getCurrentTracePoint(); + traceJSON.getLastStatementInThread(threadId, start, visitor); + TracePoint resultTp = start[0]; + allCallStacks.put(threadId, update(resultTp)); + } + } + + public void highlight(MethodExecution methodExecution) { + String signature1 = methodExecution.getSignature(); + for (List callStackModels : allCallStacks.values()) { + for (CallStackModel callStackModel : callStackModels) { + String signature2 = callStackModel.getMethodExecution().getSignature(); + callStackModel.setHighlighting(signature1.equals(signature2)); + } + } + } + + public void removeHighlight() { + for (List callStackModels : allCallStacks.values()) { + for (CallStackModel callStackModel : callStackModels) { + callStackModel.setHighlighting(false); + } + } + } + +// public IStatementVisitor tmp(TracePoint tp) { +//// return new CallStackVisitor(tp); +// try { +// Class classClass = Class.forName("java.lang.Class"); +// Class[] classClassArray = (Class[])Array.newInstance(classClass, 1); +// Class tpClass = tp.getClass(); +// Array.set(classClassArray, 0, tpClass); +// Class visitorClass = Class.forName("org.ntlab.reverseDebugger.CallStackVisitor"); +// Constructor constructor = visitorClass.getConstructor(classClassArray); +// Class[] tpClassArray = (Class[])Array.newInstance(tpClass, 1); +// Array.set(tpClassArray, 0, tp); +// IStatementVisitor visitor = (IStatementVisitor)constructor.newInstance(tpClassArray); +// return visitor; +// } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException +// | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { +// e.printStackTrace(); +// } +// return null; +// } +} diff --git a/src/org/ntlab/traceDebugger/CallStackView.java b/src/org/ntlab/traceDebugger/CallStackView.java index 84ffb23..29fa785 100644 --- a/src/org/ntlab/traceDebugger/CallStackView.java +++ b/src/org/ntlab/traceDebugger/CallStackView.java @@ -1,144 +1,149 @@ -package org.ntlab.traceDebugger; - -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TreeNode; -import org.eclipse.jface.viewers.TreeNodeContentProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.part.ViewPart; -import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; -import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; - -public class CallStackView extends ViewPart { - protected TreeViewer viewer; - protected CallStackModel selectionCallStackModel; - protected CallStackModels callStackModels = new CallStackModels(); - public static final String ID = "org.ntlab.traceDebugger.callStackView"; - - public CallStackView() { - // TODO Auto-generated constructor stub - System.out.println("callStackView�N���X���������ꂽ��"); - } - - @Override - public void createPartControl(Composite parent) { - // TODO Auto-generated method stub - System.out.println("CallStackView#createPartControl(Composite)���Ă΂ꂽ��!"); - viewer = new TreeViewer(parent); - viewer.setContentProvider(new TreeNodeContentProvider()); - viewer.setLabelProvider(new CallStackLabelProvider()); - viewer.expandAll(); - - // �I�������J�����ɑΉ����郁�\�b�h���s�̃\�[�X�t�@�C�����J�����郊�X�i�[��o�^���� - viewer.addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection sel = (IStructuredSelection)event.getSelection(); - Object element = sel.getFirstElement(); - if (element instanceof TreeNode) { - Object value = ((TreeNode)element).getValue(); - if (value instanceof CallStackModel) { - CallStackModel callStackModel = (CallStackModel)value; - selectionCallStackModel = callStackModel; - MethodExecution methodExecution = callStackModel.getMethodExecution(); - JavaEditorOperator.openSrcFileOfMethodExecution(methodExecution, callStackModel.getCallLineNo()); - additonalActionOnSelectionChanged(callStackModel); - } - } - } - }); - createActions(); - createToolBar(); - createMenuBar(); - createPopupMenu(); - TraceDebuggerPlugin.setActiveView(ID, this); - } - - @Override - public String getTitle() { - return TraceDebuggerPlugin.isJapanese() ? "�Ăяo���X�^�b�N" : "CallStack"; - } - - @Override - public void setFocus() { - // TODO Auto-generated method stub - TraceDebuggerPlugin.setActiveView(ID, this); - viewer.getControl().setFocus(); - } - - protected void createActions() { - - } - - protected void createToolBar() { - IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager(); - } - - protected void createMenuBar() { - IMenuManager mgr = getViewSite().getActionBars().getMenuManager(); - } - - protected void createPopupMenu() { - - } - - protected void additonalActionOnSelectionChanged(CallStackModel selectedCallStackModel) { - TracePoint tp = selectedCallStackModel.getTracePoint(); - TracePoint debuggingTp = DebuggingController.getInstance().getCurrentTp(); - VariableView variableView = (VariableView)TraceDebuggerPlugin.getActiveView(VariableView.ID); - variableView.updateVariablesByTracePoint(tp, false, debuggingTp); - } - - public void updateByTracePoint(TracePoint tp) { - callStackModels.updateByTracePoint(tp); - refresh(); - selectionCallStackModel = null; - } - - public void refresh() { - TreeNode[] nodes = callStackModels.getAllCallStacksTree(); - if (nodes == null || nodes[0] == null) { - viewer.setInput(null); - viewer.expandAll(); - return; - } - viewer.setInput(nodes); - viewer.expandAll(); - } - - public void reset() { - callStackModels.reset(); - refresh(); - } - - public CallStackModel getSelectionCallStackModel() { - return selectionCallStackModel; - } - - public boolean isSelectionOnTop() { - if (selectionCallStackModel == null) return false; - TreeNode[] nodes = callStackModels.getAllCallStacksTree(); - if (nodes == null || nodes[0] == null) return false; - TreeNode[] children = nodes[0].getChildren(); - Object obj = children[0].getValue(); - if (!(obj instanceof CallStackModel)) return false; - CallStackModel topCallStackModel = (CallStackModel)obj; - return topCallStackModel.equals(selectionCallStackModel); - } - - public Map> getCallStackModels() { - return callStackModels.getAllCallStacks(); - } - - public void highlight(MethodExecution methodExecution) { - callStackModels.highlight(methodExecution); - viewer.refresh(); - } -} +package org.ntlab.traceDebugger; + +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeNode; +import org.eclipse.jface.viewers.TreeNodeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.ViewPart; +import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; +import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; + +public class CallStackView extends ViewPart { + protected TreeViewer viewer; + protected CallStackModel selectionCallStackModel; + protected CallStackModels callStackModels = new CallStackModels(); + public static final String ID = "org.ntlab.traceDebugger.callStackView"; + + public CallStackView() { + // TODO Auto-generated constructor stub + System.out.println("callStackView�N���X���������ꂽ��"); + } + + @Override + public void createPartControl(Composite parent) { + // TODO Auto-generated method stub + System.out.println("CallStackView#createPartControl(Composite)���Ă΂ꂽ��!"); + viewer = new TreeViewer(parent); + viewer.setContentProvider(new TreeNodeContentProvider()); + viewer.setLabelProvider(new CallStackLabelProvider()); + viewer.expandAll(); + + // �I�������J�����ɑΉ����郁�\�b�h���s�̃\�[�X�t�@�C�����J�����郊�X�i�[��o�^���� + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection sel = (IStructuredSelection)event.getSelection(); + Object element = sel.getFirstElement(); + if (element instanceof TreeNode) { + Object value = ((TreeNode)element).getValue(); + if (value instanceof CallStackModel) { + CallStackModel callStackModel = (CallStackModel)value; + selectionCallStackModel = callStackModel; + MethodExecution methodExecution = callStackModel.getMethodExecution(); + JavaEditorOperator.openSrcFileOfMethodExecution(methodExecution, callStackModel.getCallLineNo()); + additonalActionOnSelectionChanged(callStackModel); + } + } + } + }); + createActions(); + createToolBar(); + createMenuBar(); + createPopupMenu(); + TraceDebuggerPlugin.setActiveView(ID, this); + } + + @Override + public String getTitle() { + return TraceDebuggerPlugin.isJapanese() ? "�Ăяo���X�^�b�N" : "CallStack"; + } + + @Override + public void setFocus() { + // TODO Auto-generated method stub + TraceDebuggerPlugin.setActiveView(ID, this); + viewer.getControl().setFocus(); + } + + protected void createActions() { + + } + + protected void createToolBar() { + IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager(); + } + + protected void createMenuBar() { + IMenuManager mgr = getViewSite().getActionBars().getMenuManager(); + } + + protected void createPopupMenu() { + + } + + protected void additonalActionOnSelectionChanged(CallStackModel selectedCallStackModel) { + TracePoint tp = selectedCallStackModel.getTracePoint(); + TracePoint debuggingTp = DebuggingController.getInstance().getCurrentTp(); + VariableView variableView = (VariableView)TraceDebuggerPlugin.getActiveView(VariableView.ID); + variableView.updateVariablesByTracePoint(tp, false, debuggingTp); + } + + public void updateByTracePoint(TracePoint tp) { + callStackModels.updateByTracePoint(tp); + refresh(); + selectionCallStackModel = null; + } + + public void refresh() { + TreeNode[] nodes = callStackModels.getAllCallStacksTree(); + if (nodes == null || nodes[0] == null) { + viewer.setInput(null); + viewer.expandAll(); + return; + } + viewer.setInput(nodes); + viewer.expandAll(); + } + + public void reset() { + callStackModels.reset(); + refresh(); + } + + public CallStackModel getSelectionCallStackModel() { + return selectionCallStackModel; + } + + public boolean isSelectionOnTop() { + if (selectionCallStackModel == null) return false; + TreeNode[] nodes = callStackModels.getAllCallStacksTree(); + if (nodes == null || nodes[0] == null) return false; + TreeNode[] children = nodes[0].getChildren(); + Object obj = children[0].getValue(); + if (!(obj instanceof CallStackModel)) return false; + CallStackModel topCallStackModel = (CallStackModel)obj; + return topCallStackModel.equals(selectionCallStackModel); + } + + public Map> getCallStackModels() { + return callStackModels.getAllCallStacks(); + } + + public void highlight(MethodExecution methodExecution) { + callStackModels.highlight(methodExecution); + viewer.refresh(); + } + + public void removeHighlight() { + callStackModels.removeHighlight(); + viewer.refresh(); + } +} diff --git a/src/org/ntlab/traceDebugger/DeltaMarkerView.java b/src/org/ntlab/traceDebugger/DeltaMarkerView.java index 04cd525..0dbc9e3 100644 --- a/src/org/ntlab/traceDebugger/DeltaMarkerView.java +++ b/src/org/ntlab/traceDebugger/DeltaMarkerView.java @@ -1,210 +1,214 @@ -package org.ntlab.traceDebugger; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TreeNode; -import org.eclipse.jface.viewers.TreeNodeContentProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeColumn; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.part.ViewPart; -import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; -import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; -import org.ntlab.traceDebugger.analyzerProvider.AbstractAnalyzer; -import org.ntlab.traceDebugger.analyzerProvider.Alias; -import org.ntlab.traceDebugger.analyzerProvider.Alias.AliasType; -import org.ntlab.traceDebugger.analyzerProvider.DeltaExtractionAnalyzer; -import org.ntlab.traceDebugger.analyzerProvider.DeltaMarkerManager; - -public class DeltaMarkerView extends ViewPart { - private TreeViewer viewer; - private Shell shell; - private IMarker selectionMarker; - private boolean doNotUpdateCallTreeView; - private DeltaMarkerManager deltaMarkerManager; - public static String ID = "org.ntlab.traceDebugger.deltaMarkerView"; - - @Override - public void createPartControl(Composite parent) { - // TODO Auto-generated method stub - System.out.println("DeltaMarkerView#createPartControl(Composite)���Ă΂ꂽ��!"); - shell = parent.getShell(); - viewer = new TreeViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); - Tree tree = viewer.getTree(); - tree.setHeaderVisible(true); - tree.setLinesVisible(true); - - // �e�[�u���̃J�������쐬 - String[] tableColumnTexts = TraceDebuggerPlugin.isJapanese() ? new String[]{"���s���_", "id", "�^", "�o���`��", "�\�[�X", "�s"} - : new String[]{"ExecutionPoint", "id", "Type", "Occurrence", "Source", "Line"}; - int[] tableColumnWidth = {120, 100, 120, 120, 100, 80}; - TreeColumn[] tableColumns = new TreeColumn[tableColumnTexts.length]; - for (int i = 0; i < tableColumns.length; i++) { - tableColumns[i] = new TreeColumn(tree, SWT.NULL); - tableColumns[i].setText(tableColumnTexts[i]); - tableColumns[i].setWidth(tableColumnWidth[i]); - } - viewer.setContentProvider(new TreeNodeContentProvider()); - viewer.setLabelProvider(new DeltaMarkerLabelProvider()); - viewer.addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection sel = (IStructuredSelection)event.getSelection(); - Object element = sel.getFirstElement(); - if (!(element instanceof TreeNode)) return; - Object value = ((TreeNode)element).getValue(); - if (!(value instanceof IMarker)) return; - selectionMarker = (IMarker)value; - updateOtherViewsByMarker(selectionMarker); - doNotUpdateCallTreeView = true; - viewer.getControl().setFocus(); - } - }); - viewer.refresh(); - - createActions(); - createToolBar(); - createMenuBar(); - createPopupMenu(); - TraceDebuggerPlugin.setActiveView(ID, this); - } - - @Override - public String getTitle() { - return TraceDebuggerPlugin.isJapanese() ? "�I�u�W�F�N�g�̐ڋ߉ߒ�" : "Process to Relate"; - } - - private void createActions() { - // TODO Auto-generated method stub - } - - private void createToolBar() { - IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager(); - } - - private void createMenuBar() { - IMenuManager mgr = getViewSite().getActionBars().getMenuManager(); - } - - private void createPopupMenu() { - // TODO Auto-generated method stub - } - - @Override - public void setFocus() { - // TODO Auto-generated method stub - TraceDebuggerPlugin.setActiveView(ID, this); - if (!doNotUpdateCallTreeView) { - CallTreeView callTreeView = (CallTreeView)TraceDebuggerPlugin.getActiveView(CallTreeView.ID); - callTreeView.update(deltaMarkerManager); - } - doNotUpdateCallTreeView = false; - viewer.getControl().setFocus(); - } - - public DeltaMarkerManager getDeltaMarkerManager() { - return deltaMarkerManager; - } - - public TracePoint getCreationPoint() { - IMarker creationPointMarker = deltaMarkerManager.getBottomDeltaMarker(); - return DeltaMarkerManager.getTracePoint(creationPointMarker); - } - - public TracePoint getCoordinatorPoint() { - IMarker coordinatorMarker = deltaMarkerManager.getCoordinatorDeltaMarker(); - return DeltaMarkerManager.getTracePoint(coordinatorMarker); - } - - @Override - public void dispose() { - deltaMarkerManager.clearAllMarkers(); - CallTreeView callTreeView = ((CallTreeView)TraceDebuggerPlugin.getActiveView(CallTreeView.ID)); - callTreeView.reset(); - super.dispose(); - } - - private void updateOtherViewsByMarker(IMarker marker) { - DebuggingController controller = DebuggingController.getInstance(); - IMarker coordinator = deltaMarkerManager.getCoordinatorDeltaMarker(); - TracePoint coordinatorPoint = DeltaMarkerManager.getTracePoint(coordinator); - if (marker != null) { - try { - Object obj = marker.getAttribute(DeltaMarkerManager.DELTA_MARKER_ATR_DATA); - TracePoint jumpPoint; - boolean isReturned = false; - if (obj instanceof Alias) { - Alias alias = (Alias)obj; - jumpPoint = alias.getOccurrencePoint(); - Alias.AliasType type = alias.getAliasType(); - isReturned = type.equals(AliasType.METHOD_INVOCATION) || type.equals(AliasType.CONSTRACTOR_INVOCATION); - } else if (obj instanceof TracePoint) { - jumpPoint = (TracePoint)obj; - } else { - jumpPoint = coordinatorPoint; - } - controller.jumpToTheTracePoint(jumpPoint, isReturned); - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IDE.openEditor(page, marker); - CallStackView callStackView = (CallStackView)TraceDebuggerPlugin.getActiveView(CallStackView.ID); - callStackView.highlight(coordinatorPoint.getMethodExecution()); - VariableViewRelatedDelta variableView = (VariableViewRelatedDelta)TraceDebuggerPlugin.getActiveView(VariableViewRelatedDelta.ID); - variableView.markAndExpandVariablesByDeltaMarkers(deltaMarkerManager.getMarkers()); - } catch (CoreException e) { - e.printStackTrace(); - } - } - } - - public void extractDeltaForContainerToComponent(Variable variable) { - AbstractAnalyzer analyzer = TraceDebuggerPlugin.getAnalyzer(); - if (analyzer instanceof DeltaExtractionAnalyzer) { - DeltaExtractionAnalyzer deltaAnalyzer = (DeltaExtractionAnalyzer)analyzer; - deltaMarkerManager = deltaAnalyzer.extractDeltaForContainerToComponent(variable); - deltaMarkerManager.createMarkerAndOpenJavaFileForAll(); // �f���^���o�̌��ʂ����Ƀ\�[�X�R�[�h�𔽓]�\������ - updateAfterExtractingDelta(); - } - } - - public void extractDeltaForThisToAnother(String thisId, String thisClassName, String anotherId, String anotherClassName, TracePoint before) { - AbstractAnalyzer analyzer = TraceDebuggerPlugin.getAnalyzer(); - if (analyzer instanceof DeltaExtractionAnalyzer) { - DeltaExtractionAnalyzer deltaAnalyzer = (DeltaExtractionAnalyzer)analyzer; - deltaMarkerManager = deltaAnalyzer.extractDeltaForThisToAnother(thisId, thisClassName, anotherId, anotherClassName, before); - deltaMarkerManager.createMarkerAndOpenJavaFileForAll(); // �f���^���o�̌��ʂ����Ƀ\�[�X�R�[�h�𔽓]�\������ - updateAfterExtractingDelta(); - } - } - - private void updateAfterExtractingDelta() { - viewer.setInput(deltaMarkerManager.getMarkerTreeNodes()); - viewer.expandAll(); - viewer.refresh(); - TracePoint coordinatorPoint = getCoordinatorPoint(); - TracePoint creationPoint = getCreationPoint(); - MethodExecution coordinatorME = coordinatorPoint.getMethodExecution(); - MethodExecution bottomME = creationPoint.getMethodExecution(); - DebuggingController controller = DebuggingController.getInstance(); - controller.jumpToTheTracePoint(creationPoint, false); - VariableViewRelatedDelta variableView = (VariableViewRelatedDelta)(TraceDebuggerPlugin.getActiveView(VariableViewRelatedDelta.ID)); - variableView.markAndExpandVariablesByDeltaMarkers(deltaMarkerManager.getMarkers()); - CallStackView callStackView = (CallStackView)TraceDebuggerPlugin.getActiveView(CallStackView.ID); - callStackView.highlight(coordinatorME); - CallTreeView callTreeView = (CallTreeView)TraceDebuggerPlugin.getActiveView(CallTreeView.ID); - callTreeView.update(deltaMarkerManager); - callTreeView.highlight(bottomME); - TracePointsView tracePointsView = (TracePointsView)TraceDebuggerPlugin.getActiveView(TracePointsView.ID); - tracePointsView.addTracePoint(creationPoint); - } -} +package org.ntlab.traceDebugger; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeNode; +import org.eclipse.jface.viewers.TreeNodeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.part.ViewPart; +import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; +import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; +import org.ntlab.traceDebugger.analyzerProvider.AbstractAnalyzer; +import org.ntlab.traceDebugger.analyzerProvider.Alias; +import org.ntlab.traceDebugger.analyzerProvider.Alias.AliasType; +import org.ntlab.traceDebugger.analyzerProvider.DeltaExtractionAnalyzer; +import org.ntlab.traceDebugger.analyzerProvider.DeltaMarkerManager; + +public class DeltaMarkerView extends ViewPart { + private TreeViewer viewer; + private Shell shell; + private IMarker selectionMarker; + private boolean doNotUpdateCallTreeView; + private DeltaMarkerManager deltaMarkerManager; + public static String ID = "org.ntlab.traceDebugger.deltaMarkerView"; + + @Override + public void createPartControl(Composite parent) { + // TODO Auto-generated method stub + System.out.println("DeltaMarkerView#createPartControl(Composite)���Ă΂ꂽ��!"); + shell = parent.getShell(); + viewer = new TreeViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); + Tree tree = viewer.getTree(); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + + // �e�[�u���̃J�������쐬 + String[] tableColumnTexts = TraceDebuggerPlugin.isJapanese() ? new String[]{"���s���_", "id", "�^", "�o���`��", "�\�[�X", "�s"} + : new String[]{"ExecutionPoint", "id", "Type", "Occurrence", "Source", "Line"}; + int[] tableColumnWidth = {120, 100, 120, 120, 100, 80}; + TreeColumn[] tableColumns = new TreeColumn[tableColumnTexts.length]; + for (int i = 0; i < tableColumns.length; i++) { + tableColumns[i] = new TreeColumn(tree, SWT.NULL); + tableColumns[i].setText(tableColumnTexts[i]); + tableColumns[i].setWidth(tableColumnWidth[i]); + } + viewer.setContentProvider(new TreeNodeContentProvider()); + viewer.setLabelProvider(new DeltaMarkerLabelProvider()); + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection sel = (IStructuredSelection)event.getSelection(); + Object element = sel.getFirstElement(); + if (!(element instanceof TreeNode)) return; + Object value = ((TreeNode)element).getValue(); + if (!(value instanceof IMarker)) return; + selectionMarker = (IMarker)value; + updateOtherViewsByMarker(selectionMarker); + doNotUpdateCallTreeView = true; + viewer.getControl().setFocus(); + } + }); + viewer.refresh(); + + createActions(); + createToolBar(); + createMenuBar(); + createPopupMenu(); + TraceDebuggerPlugin.setActiveView(ID, this); + } + + @Override + public String getTitle() { + return TraceDebuggerPlugin.isJapanese() ? "�I�u�W�F�N�g�̐ڋ߉ߒ�" : "Process to Relate"; + } + + private void createActions() { + // TODO Auto-generated method stub + } + + private void createToolBar() { + IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager(); + } + + private void createMenuBar() { + IMenuManager mgr = getViewSite().getActionBars().getMenuManager(); + } + + private void createPopupMenu() { + // TODO Auto-generated method stub + } + + @Override + public void setFocus() { + // TODO Auto-generated method stub + TraceDebuggerPlugin.setActiveView(ID, this); + if (!doNotUpdateCallTreeView) { + CallTreeView callTreeView = (CallTreeView)TraceDebuggerPlugin.getActiveView(CallTreeView.ID); + callTreeView.update(deltaMarkerManager); + } + doNotUpdateCallTreeView = false; + viewer.getControl().setFocus(); + } + + public DeltaMarkerManager getDeltaMarkerManager() { + return deltaMarkerManager; + } + + public TracePoint getCreationPoint() { + IMarker creationPointMarker = deltaMarkerManager.getBottomDeltaMarker(); + return DeltaMarkerManager.getTracePoint(creationPointMarker); + } + + public TracePoint getCoordinatorPoint() { + IMarker coordinatorMarker = deltaMarkerManager.getCoordinatorDeltaMarker(); + return DeltaMarkerManager.getTracePoint(coordinatorMarker); + } + + @Override + public void dispose() { + CallTreeView callTreeView = ((CallTreeView)TraceDebuggerPlugin.getActiveView(CallTreeView.ID)); + callTreeView.reset(); + VariableViewRelatedDelta variableView = ((VariableViewRelatedDelta)TraceDebuggerPlugin.getActiveView(VariableViewRelatedDelta.ID)); + variableView.removeDeltaMarkers(deltaMarkerManager.getMarkers()); + CallStackViewRelatedDelta callStackView = ((CallStackViewRelatedDelta)TraceDebuggerPlugin.getActiveView(CallStackViewRelatedDelta.ID)); + callStackView.removeHighlight(); + deltaMarkerManager.clearAllMarkers(); + super.dispose(); + } + + private void updateOtherViewsByMarker(IMarker marker) { + DebuggingController controller = DebuggingController.getInstance(); + IMarker coordinator = deltaMarkerManager.getCoordinatorDeltaMarker(); + TracePoint coordinatorPoint = DeltaMarkerManager.getTracePoint(coordinator); + if (marker != null) { + try { + Object obj = marker.getAttribute(DeltaMarkerManager.DELTA_MARKER_ATR_DATA); + TracePoint jumpPoint; + boolean isReturned = false; + if (obj instanceof Alias) { + Alias alias = (Alias)obj; + jumpPoint = alias.getOccurrencePoint(); + Alias.AliasType type = alias.getAliasType(); + isReturned = type.equals(AliasType.METHOD_INVOCATION) || type.equals(AliasType.CONSTRACTOR_INVOCATION); + } else if (obj instanceof TracePoint) { + jumpPoint = (TracePoint)obj; + } else { + jumpPoint = coordinatorPoint; + } + controller.jumpToTheTracePoint(jumpPoint, isReturned); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IDE.openEditor(page, marker); + CallStackView callStackView = (CallStackView)TraceDebuggerPlugin.getActiveView(CallStackView.ID); + callStackView.highlight(coordinatorPoint.getMethodExecution()); + VariableViewRelatedDelta variableView = (VariableViewRelatedDelta)TraceDebuggerPlugin.getActiveView(VariableViewRelatedDelta.ID); + variableView.markAndExpandVariablesByDeltaMarkers(deltaMarkerManager.getMarkers()); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + + public void extractDeltaForContainerToComponent(Variable variable) { + AbstractAnalyzer analyzer = TraceDebuggerPlugin.getAnalyzer(); + if (analyzer instanceof DeltaExtractionAnalyzer) { + DeltaExtractionAnalyzer deltaAnalyzer = (DeltaExtractionAnalyzer)analyzer; + deltaMarkerManager = deltaAnalyzer.extractDeltaForContainerToComponent(variable); + deltaMarkerManager.createMarkerAndOpenJavaFileForAll(); // �f���^���o�̌��ʂ����Ƀ\�[�X�R�[�h�𔽓]�\������ + updateAfterExtractingDelta(); + } + } + + public void extractDeltaForThisToAnother(String thisId, String thisClassName, String anotherId, String anotherClassName, TracePoint before) { + AbstractAnalyzer analyzer = TraceDebuggerPlugin.getAnalyzer(); + if (analyzer instanceof DeltaExtractionAnalyzer) { + DeltaExtractionAnalyzer deltaAnalyzer = (DeltaExtractionAnalyzer)analyzer; + deltaMarkerManager = deltaAnalyzer.extractDeltaForThisToAnother(thisId, thisClassName, anotherId, anotherClassName, before); + deltaMarkerManager.createMarkerAndOpenJavaFileForAll(); // �f���^���o�̌��ʂ����Ƀ\�[�X�R�[�h�𔽓]�\������ + updateAfterExtractingDelta(); + } + } + + private void updateAfterExtractingDelta() { + viewer.setInput(deltaMarkerManager.getMarkerTreeNodes()); + viewer.expandAll(); + viewer.refresh(); + TracePoint coordinatorPoint = getCoordinatorPoint(); + TracePoint creationPoint = getCreationPoint(); + MethodExecution coordinatorME = coordinatorPoint.getMethodExecution(); + MethodExecution bottomME = creationPoint.getMethodExecution(); + DebuggingController controller = DebuggingController.getInstance(); + controller.jumpToTheTracePoint(creationPoint, false); + VariableViewRelatedDelta variableView = (VariableViewRelatedDelta)(TraceDebuggerPlugin.getActiveView(VariableViewRelatedDelta.ID)); + variableView.markAndExpandVariablesByDeltaMarkers(deltaMarkerManager.getMarkers()); + CallStackView callStackView = (CallStackView)TraceDebuggerPlugin.getActiveView(CallStackView.ID); + callStackView.highlight(coordinatorME); + CallTreeView callTreeView = (CallTreeView)TraceDebuggerPlugin.getActiveView(CallTreeView.ID); + callTreeView.update(deltaMarkerManager); + callTreeView.highlight(bottomME); + TracePointsView tracePointsView = (TracePointsView)TraceDebuggerPlugin.getActiveView(TracePointsView.ID); + tracePointsView.addTracePoint(creationPoint); + } +} diff --git a/src/org/ntlab/traceDebugger/TraceBreakPoints.java b/src/org/ntlab/traceDebugger/TraceBreakPoints.java index 0981f6f..2fd08bf 100644 --- a/src/org/ntlab/traceDebugger/TraceBreakPoints.java +++ b/src/org/ntlab/traceDebugger/TraceBreakPoints.java @@ -1,247 +1,248 @@ -package org.ntlab.traceDebugger; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint; -import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; -import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodInvocation; -import org.ntlab.traceAnalysisPlatform.tracer.trace.Statement; -import org.ntlab.traceAnalysisPlatform.tracer.trace.Trace; -import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; - -public class TraceBreakPoints { - private Trace trace; - private Map> traceBreakPoints = new HashMap<>(); - private List histories = new ArrayList<>(); - private TracePoint lastReferencePoint; - - public TraceBreakPoints(Trace trace) { - this.trace = trace; - } - - public List getAllTraceBreakPoints() { - List list = new ArrayList<>(); - for (Map innerMap : traceBreakPoints.values()) { - list.addAll(innerMap.values()); - } - Collections.sort(list, new Comparator() { - @Override - public int compare(TraceBreakPoint arg0, TraceBreakPoint arg1) { - if (arg0.getMethodSignature().equals(arg1.getMethodSignature())) { - return (arg0.getLineNo() < arg1.getLineNo()) ? -1 : 1; - } - return arg0.getMethodSignature().compareTo(arg1.getMethodSignature()); - } - }); - return list; - } - - public boolean addTraceBreakPoint(String inputSignature, int lineNo) { - boolean isSuccess = addTraceBreakPoint(inputSignature, lineNo, true); - return isSuccess; - } - - public boolean addTraceBreakPoint(String inputSignature, int lineNo, boolean isAvailable) { - String methodSignature = findMethodSignaureOnTrace(inputSignature); - if (methodSignature == null) return false; - Map innerMap = traceBreakPoints.get(methodSignature); - if (innerMap == null) { - innerMap = new HashMap<>(); - traceBreakPoints.put(methodSignature, innerMap); - } - try { - TraceBreakPoint tbp = TraceBreakPoint.createNewTraceBreakPoint(methodSignature, lineNo, isAvailable, inputSignature); - innerMap.put(lineNo, tbp); - addHistories(tbp); - return true; - } catch (IllegalArgumentException e) { - return false; - } - } - - private void removeTraceBreakPoint(String methodSignature, int lineNo) { - Map innerMap = traceBreakPoints.get(methodSignature); - if (innerMap == null) return; - TraceBreakPoint tbp = innerMap.remove(lineNo); - if (tbp != null) removeHistories(tbp); - if (innerMap.isEmpty()) traceBreakPoints.remove(methodSignature); - } - - public void removeTraceBreakPoint(TraceBreakPoint traceBreakPoint) { - String methodSignature = traceBreakPoint.getMethodSignature(); - int lineNo = traceBreakPoint.getLineNo(); - removeTraceBreakPoint(methodSignature, lineNo); - } - - public void importBreakpointFromEclipse() { - IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(); - for (IBreakpoint breakpoint : breakpoints) { - if (!(breakpoint instanceof JavaLineBreakpoint)) continue; - try { - IMarker breakpointMarker = breakpoint.getMarker(); - Map attributes = breakpointMarker.getAttributes(); - String type = (String)attributes.get("org.eclipse.jdt.debug.core.typeName"); - type = type.substring(type.lastIndexOf(".") + 1); - int lineNo = (int)attributes.get(IMarker.LINE_NUMBER); - boolean available = (boolean)attributes.get(IBreakpoint.ENABLED); - String message = (String)attributes.get(IMarker.MESSAGE); - String methodName = message.substring(message.indexOf("-") + 2); - methodName = methodName.replace(" ", ""); - String signature; - if (methodName.startsWith(type + "(")) { - signature = methodName; // �R���X�g���N�^���̏ꍇ - } else { - signature = type + "." + methodName; - } - signature = signature.replace("$", "."); // �����N���X�� $ �̓��\�b�h�V�O�j�`����ł̓h�b�g�ɂȂ� - signature = signature.replaceAll("<.*>", ""); // �e�����̃W�F�l���N�X�̏��̓g���[�X��ɋL�^����Ă��Ȃ��̂ň�v�����邽�߂ɏ��� - addTraceBreakPoint(signature, lineNo, available); - } catch (CoreException e) { - e.printStackTrace(); - } - } - } - - private String findMethodSignaureOnTrace(String inputSignature) { - HashSet methodSignatures = trace.getAllMethodSignatures(); - for (String signature : methodSignatures) { - String signatureFront = signature.substring(0, signature.indexOf("(") + 1); - String inputSignatureFront = inputSignature.substring(0, inputSignature.indexOf("(") + 1); - if (!(signatureFront.endsWith(inputSignatureFront))) continue; - String signatureBack = signature.substring(signature.indexOf("(") + 1); - String[] signatureArgs = signatureBack.split(","); - String inputSignatureBack = inputSignature.substring(inputSignature.indexOf("(") + 1); - String[] inputSignatureArgs = inputSignatureBack.split(","); - if (signatureArgs.length != inputSignatureArgs.length) continue; - boolean isMatch = true; - for (int i = 0; i < signatureArgs.length; i++) { - if (!(signatureArgs[i].endsWith(inputSignatureArgs[i]))) { - isMatch = false; - break; - } - } - if (isMatch) return signature; - } - return null; - } - - private void addHistories(TraceBreakPoint tbp) { - for (TracePoint tp : tbp.getTracePoints()) { - histories.add(tp); - } - Collections.sort(histories, new Comparator() { - @Override - public int compare(TracePoint o1, TracePoint o2) { - long o1Time = getTime(o1); - long o2Time = getTime(o2); - return (o1Time < o2Time) ? -1 : 1; - } - private long getTime(TracePoint tp) { - Statement statement = tp.getStatement(); - if (statement instanceof MethodInvocation) { - return ((MethodInvocation)statement).getCalledMethodExecution().getEntryTime(); - } - return statement.getTimeStamp(); - } - }); - confirm(); - } - - private void removeHistories(TraceBreakPoint tbp) { - List removedPoints = tbp.getTracePoints(); - Iterator it = histories.iterator(); - while (it.hasNext()) { - TracePoint tp = it.next(); - if (removedPoints.contains(tp)) it.remove(); - } - confirm(); - } - - public TracePoint getFirstTracePoint() { - return getNextTracePoint(0L); - } - - public TracePoint getNextTracePoint(long time) { - for (TracePoint tp : histories) { - if (!(checkAvailable(tp))) continue; - if (getTime(tp) > time) { - lastReferencePoint = tp; - confirm(); - return tp.duplicate(); - } - } - lastReferencePoint = null; - confirm(); - return null; - } - - public TracePoint getPreviousTracePoint(long time) { - TracePoint tmp = null; - for (TracePoint tp : histories) { - if (!(checkAvailable(tp))) continue; - if (getTime(tp) >= time) { - lastReferencePoint = tmp; - confirm(); - return (tmp != null) ? tmp.duplicate() : null; - } - tmp = tp; - } - lastReferencePoint = tmp; - confirm(); - return (tmp != null) ? tmp.duplicate() : null; - } - - private TraceBreakPoint getTraceBreakPoint(TracePoint tp) { - String signature = tp.getMethodExecution().getSignature(); - int lineNo = tp.getStatement().getLineNo(); - Map innerMap = traceBreakPoints.get(signature); - return (innerMap != null) ? innerMap.get(lineNo) : null; - } - - private boolean checkAvailable(TracePoint tp) { - TraceBreakPoint tbp = getTraceBreakPoint(tp); - return (tbp != null) ? tbp.isAvailable() : false; - } - - public void clear() { - traceBreakPoints.clear(); - } - - private long getTime(TracePoint tp) { - Statement statement = tp.getStatement(); - if (statement instanceof MethodInvocation) { - return ((MethodInvocation)statement).getCalledMethodExecution().getEntryTime(); - } - return statement.getTimeStamp(); - } - - private void confirm() { - System.out.println(); - if (lastReferencePoint == null) { - System.out.println("cur: " + "Not Exist"); - } else { - System.out.println("cur: " + getTime(lastReferencePoint)); - } - for (TracePoint tp : histories) { - String signature = tp.getMethodExecution().getSignature(); - int lineNo = tp.getStatement().getLineNo(); - long time = getTime(tp); - StringBuilder msg = new StringBuilder(); - msg.append(time + " " + signature + " line: " + lineNo); - if (tp.equals(lastReferencePoint)) msg.append(" ����������"); - System.out.println(msg); - } - System.out.println(); - } -} +package org.ntlab.traceDebugger; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint; +import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; +import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodInvocation; +import org.ntlab.traceAnalysisPlatform.tracer.trace.Statement; +import org.ntlab.traceAnalysisPlatform.tracer.trace.Trace; +import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; + +public class TraceBreakPoints { + private Trace trace; + private Map> traceBreakPoints = new HashMap<>(); + private List histories = new ArrayList<>(); + private TracePoint lastReferencePoint; + + public TraceBreakPoints(Trace trace) { + this.trace = trace; + } + + public List getAllTraceBreakPoints() { + List list = new ArrayList<>(); + for (Map innerMap : traceBreakPoints.values()) { + list.addAll(innerMap.values()); + } + Collections.sort(list, new Comparator() { + @Override + public int compare(TraceBreakPoint arg0, TraceBreakPoint arg1) { + if (arg0.getMethodSignature().equals(arg1.getMethodSignature())) { + return (arg0.getLineNo() < arg1.getLineNo()) ? -1 : 1; + } + return arg0.getMethodSignature().compareTo(arg1.getMethodSignature()); + } + }); + return list; + } + + public boolean addTraceBreakPoint(String inputSignature, int lineNo) { + boolean isSuccess = addTraceBreakPoint(inputSignature, lineNo, true); + return isSuccess; + } + + public boolean addTraceBreakPoint(String inputSignature, int lineNo, boolean isAvailable) { + String methodSignature = findMethodSignaureOnTrace(inputSignature); + if (methodSignature == null) return false; + Map innerMap = traceBreakPoints.get(methodSignature); + if (innerMap == null) { + innerMap = new HashMap<>(); + traceBreakPoints.put(methodSignature, innerMap); + } + if (innerMap.containsKey(lineNo)) return false; + try { + TraceBreakPoint tbp = TraceBreakPoint.createNewTraceBreakPoint(methodSignature, lineNo, isAvailable, inputSignature); + innerMap.put(lineNo, tbp); + addHistories(tbp); + return true; + } catch (IllegalArgumentException e) { + return false; + } + } + + private void removeTraceBreakPoint(String methodSignature, int lineNo) { + Map innerMap = traceBreakPoints.get(methodSignature); + if (innerMap == null) return; + TraceBreakPoint tbp = innerMap.remove(lineNo); + if (tbp != null) removeHistories(tbp); + if (innerMap.isEmpty()) traceBreakPoints.remove(methodSignature); + } + + public void removeTraceBreakPoint(TraceBreakPoint traceBreakPoint) { + String methodSignature = traceBreakPoint.getMethodSignature(); + int lineNo = traceBreakPoint.getLineNo(); + removeTraceBreakPoint(methodSignature, lineNo); + } + + public void importBreakpointFromEclipse() { + IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(); + for (IBreakpoint breakpoint : breakpoints) { + if (!(breakpoint instanceof JavaLineBreakpoint)) continue; + try { + IMarker breakpointMarker = breakpoint.getMarker(); + Map attributes = breakpointMarker.getAttributes(); + String type = (String)attributes.get("org.eclipse.jdt.debug.core.typeName"); + type = type.substring(type.lastIndexOf(".") + 1); + int lineNo = (int)attributes.get(IMarker.LINE_NUMBER); + boolean available = (boolean)attributes.get(IBreakpoint.ENABLED); + String message = (String)attributes.get(IMarker.MESSAGE); + String methodName = message.substring(message.indexOf("-") + 2); + methodName = methodName.replace(" ", ""); + String signature; + if (methodName.startsWith(type + "(")) { + signature = methodName; // �R���X�g���N�^���̏ꍇ + } else { + signature = type + "." + methodName; + } + signature = signature.replace("$", "."); // �����N���X�� $ �̓��\�b�h�V�O�j�`����ł̓h�b�g�ɂȂ� + signature = signature.replaceAll("<.*>", ""); // �e�����̃W�F�l���N�X�̏��̓g���[�X��ɋL�^����Ă��Ȃ��̂ň�v�����邽�߂ɏ��� + addTraceBreakPoint(signature, lineNo, available); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + + private String findMethodSignaureOnTrace(String inputSignature) { + HashSet methodSignatures = trace.getAllMethodSignatures(); + for (String signature : methodSignatures) { + String signatureFront = signature.substring(0, signature.indexOf("(") + 1); + String inputSignatureFront = inputSignature.substring(0, inputSignature.indexOf("(") + 1); + if (!(signatureFront.endsWith(inputSignatureFront))) continue; + String signatureBack = signature.substring(signature.indexOf("(") + 1); + String[] signatureArgs = signatureBack.split(","); + String inputSignatureBack = inputSignature.substring(inputSignature.indexOf("(") + 1); + String[] inputSignatureArgs = inputSignatureBack.split(","); + if (signatureArgs.length != inputSignatureArgs.length) continue; + boolean isMatch = true; + for (int i = 0; i < signatureArgs.length; i++) { + if (!(signatureArgs[i].endsWith(inputSignatureArgs[i]))) { + isMatch = false; + break; + } + } + if (isMatch) return signature; + } + return null; + } + + private void addHistories(TraceBreakPoint tbp) { + for (TracePoint tp : tbp.getTracePoints()) { + histories.add(tp); + } + Collections.sort(histories, new Comparator() { + @Override + public int compare(TracePoint o1, TracePoint o2) { + long o1Time = getTime(o1); + long o2Time = getTime(o2); + return (o1Time < o2Time) ? -1 : 1; + } + private long getTime(TracePoint tp) { + Statement statement = tp.getStatement(); + if (statement instanceof MethodInvocation) { + return ((MethodInvocation)statement).getCalledMethodExecution().getEntryTime(); + } + return statement.getTimeStamp(); + } + }); + confirm(); + } + + private void removeHistories(TraceBreakPoint tbp) { + List removedPoints = tbp.getTracePoints(); + Iterator it = histories.iterator(); + while (it.hasNext()) { + TracePoint tp = it.next(); + if (removedPoints.contains(tp)) it.remove(); + } + confirm(); + } + + public TracePoint getFirstTracePoint() { + return getNextTracePoint(0L); + } + + public TracePoint getNextTracePoint(long time) { + for (TracePoint tp : histories) { + if (!(checkAvailable(tp))) continue; + if (getTime(tp) > time) { + lastReferencePoint = tp; + confirm(); + return tp.duplicate(); + } + } + lastReferencePoint = null; + confirm(); + return null; + } + + public TracePoint getPreviousTracePoint(long time) { + TracePoint tmp = null; + for (TracePoint tp : histories) { + if (!(checkAvailable(tp))) continue; + if (getTime(tp) >= time) { + lastReferencePoint = tmp; + confirm(); + return (tmp != null) ? tmp.duplicate() : null; + } + tmp = tp; + } + lastReferencePoint = tmp; + confirm(); + return (tmp != null) ? tmp.duplicate() : null; + } + + private TraceBreakPoint getTraceBreakPoint(TracePoint tp) { + String signature = tp.getMethodExecution().getSignature(); + int lineNo = tp.getStatement().getLineNo(); + Map innerMap = traceBreakPoints.get(signature); + return (innerMap != null) ? innerMap.get(lineNo) : null; + } + + private boolean checkAvailable(TracePoint tp) { + TraceBreakPoint tbp = getTraceBreakPoint(tp); + return (tbp != null) ? tbp.isAvailable() : false; + } + + public void clear() { + traceBreakPoints.clear(); + } + + private long getTime(TracePoint tp) { + Statement statement = tp.getStatement(); + if (statement instanceof MethodInvocation) { + return ((MethodInvocation)statement).getCalledMethodExecution().getEntryTime(); + } + return statement.getTimeStamp(); + } + + private void confirm() { + System.out.println(); + if (lastReferencePoint == null) { + System.out.println("cur: " + "Not Exist"); + } else { + System.out.println("cur: " + getTime(lastReferencePoint)); + } + for (TracePoint tp : histories) { + String signature = tp.getMethodExecution().getSignature(); + int lineNo = tp.getStatement().getLineNo(); + long time = getTime(tp); + StringBuilder msg = new StringBuilder(); + msg.append(time + " " + signature + " line: " + lineNo); + if (tp.equals(lastReferencePoint)) msg.append(" ����������"); + System.out.println(msg); + } + System.out.println(); + } +} diff --git a/src/org/ntlab/traceDebugger/VariableViewRelatedDelta.java b/src/org/ntlab/traceDebugger/VariableViewRelatedDelta.java index 4303f63..df46068 100644 --- a/src/org/ntlab/traceDebugger/VariableViewRelatedDelta.java +++ b/src/org/ntlab/traceDebugger/VariableViewRelatedDelta.java @@ -1,305 +1,321 @@ -package org.ntlab.traceDebugger; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.TreeNode; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkbenchPage; -import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; -import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodInvocation; -import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; -import org.ntlab.traceDebugger.Variable.VariableType; -import org.ntlab.traceDebugger.analyzerProvider.Alias; -import org.ntlab.traceDebugger.analyzerProvider.DeltaMarkerManager; -import org.ntlab.traceDebugger.analyzerProvider.VariableUpdatePointFinder; - -public class VariableViewRelatedDelta extends VariableView { - protected IAction jumpAction; - private IAction deltaActionForContainerToComponent; - private IAction deltaActionForThisToAnother; - public static final String ID = "org.ntlab.traceDebugger.variableViewRelatedDelta"; - - public VariableViewRelatedDelta() { - // TODO Auto-generated constructor stub - System.out.println("VariableViewRelatedDelta�N���X���������ꂽ��!"); - } - - @Override - public void createPartControl(Composite parent) { - // TODO Auto-generated method stub - System.out.println("VariableViewRelatedDelta#createPartControl(Composite)���Ă΂ꂽ��!"); - super.createPartControl(parent); - TraceDebuggerPlugin.setActiveView(ID, this); - } - - @Override - public void setFocus() { - // TODO Auto-generated method stub - TraceDebuggerPlugin.setActiveView(ID, this); - viewer.getControl().setFocus(); - } - - @Override - protected void createActions() { - super.createActions(); - jumpAction = new Action() { - public void run() { - TracePoint before = DebuggingController.getInstance().getCurrentTp(); - TracePoint jumpPoint = findJumpPoint(selectedVariable, before); - if (jumpPoint == null) return; - DebuggingController controller = DebuggingController.getInstance(); - controller.jumpToTheTracePoint(jumpPoint, false); - } - }; - - deltaActionForContainerToComponent = new Action() { - @Override - public void run() { - DeltaMarkerView newDeltaMarkerView = (DeltaMarkerView)TraceDebuggerPlugin.createNewView(DeltaMarkerView.ID, IWorkbenchPage.VIEW_ACTIVATE); - newDeltaMarkerView.extractDeltaForContainerToComponent(selectedVariable); - } - }; - - deltaActionForThisToAnother = new Action() { - @Override - public void run() { - TracePoint before = selectedVariable.getBeforeTracePoint(); - String thisId = before.getMethodExecution().getThisObjId(); - String thisClassName = before.getMethodExecution().getThisClassName(); - String anotherId; - String anotherClassName; - if (selectedVariable.getVariableType().isContainerSide()) { - anotherId = selectedVariable.getContainerId(); - anotherClassName = selectedVariable.getContainerClassName(); - } else { - anotherId = selectedVariable.getValueId(); - anotherClassName = selectedVariable.getValueClassName(); - } - DeltaMarkerView newDeltaMarkerView = (DeltaMarkerView)TraceDebuggerPlugin.createNewView(DeltaMarkerView.ID, IWorkbenchPage.VIEW_ACTIVATE); - newDeltaMarkerView.extractDeltaForThisToAnother(thisId, thisClassName, anotherId, anotherClassName, before); - } - }; - } - - private TracePoint findJumpPoint(Variable variable, TracePoint before) { - VariableType variableType = selectedVariable.getVariableType(); - if (variableType.equals(VariableType.USE_VALUE)) { - String containerId = selectedVariable.getContainerId(); - String fieldName = selectedVariable.getFullyQualifiedVariableName(); - return VariableUpdatePointFinder.getInstance().getPoint(containerId, fieldName, before); - } else if (variableType.equals(VariableType.USE_RETURN)) { - return findJumpPointWithReturnValue(variable, before); - } - return null; - } - - private TracePoint findJumpPointWithReturnValue(Variable variable, TracePoint before) { - TracePoint tp = null; - String receiverId = selectedVariable.getContainerId(); - String valueId = selectedVariable.getValueId(); - String receiverClassName = selectedVariable.getContainerClassName(); - VariableUpdatePointFinder finder = VariableUpdatePointFinder.getInstance(); - - // note: �C�e���[�^�̏ꍇ�͂��̃C�e���[�^�̎擾���̃R���N�V������ID�����ɂ��� - if (receiverClassName.contains("Iterator") || receiverClassName.contains("Itr") - || receiverClassName.contains("Collections$UnmodifiableCollection$1")) { - tp = finder.getIteratorPoint(receiverId); // �C�e���[�^�擾���̃|�C���g���擾 - if (tp == null) return null; - MethodInvocation mi = ((MethodInvocation)tp.getStatement()); - receiverId = mi.getCalledMethodExecution().getThisObjId(); // �C�e���[�^�̎擾���̃R���N�V������ID - receiverClassName = mi.getCalledMethodExecution().getThisClassName(); // �C�e���[�^�̎擾���̃R���N�V�����̃N���X�� - } - - // note: �W�����v��ƂȂ� �I�u�W�F�N�g�̑���|�C���g�������̓R���N�V�����ւ̒lj��|�C���g���擾 - tp = finder.getDefinitionInvocationPoint(receiverId, valueId, before); - - // note: �W�����v��̃|�C���g�����‚���Ȃ������ꍇ�ŁA���ƒR���N�V�����ւ̒lj��|�C���g��T���Ă���ꍇ�̓R���N�V�����̏悹�������Œlj����Ă��Ȃ�����T���ɍs�� - if (tp == null && receiverClassName.startsWith("java.util.")) { - String afterCollectionId = receiverId; - while (true) { - tp = finder.getTransferCollectionPoint(afterCollectionId, before); - if (tp == null) break; // �R���N�V�����̏悹������������ȏ�Ȃ��ꍇ - MethodInvocation mi = ((MethodInvocation)tp.getStatement()); - String fromCollectionId = mi.getCalledMethodExecution().getArguments().get(0).getId(); - tp = finder.getDefinitionInvocationPoint(fromCollectionId, valueId, before); - if (tp != null) break; // �R���N�V�����̏悹�������ŃI�u�W�F�N�g�̒lj������‚������ꍇ - afterCollectionId = fromCollectionId; - } - } - return tp; - } - - @Override - protected void createPopupMenu() { - MenuManager menuMgr = new MenuManager("#PopupMenu"); - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() { - @Override - public void menuAboutToShow(IMenuManager manager) { - // �E�N���b�N����x�ɌĂяo����� - VariableType variableType = selectedVariable.getVariableType(); - if (variableType.equals(VariableType.USE_VALUE)) { - manager.add(jumpAction); - String msg = TraceDebuggerPlugin.isJapanese() ? "�l�̑�����_�ɔ��" : "Back to Value Stored Moment"; - jumpAction.setText(msg); - jumpAction.setToolTipText(msg); - } else if (variableType.equals(VariableType.USE_RETURN)) { - manager.add(jumpAction); - if (updateDeltaActionForThisToAnotherTexts(selectedVariable)) { - manager.add(deltaActionForThisToAnother); - } - String msg = TraceDebuggerPlugin.isJapanese() ? "�I�u�W�F�N�g�̒lj����_�ɔ��" : "Back to Object Added Moment"; - jumpAction.setText(msg); - jumpAction.setToolTipText(msg); - } else if (variableType.isDef()) { - if (updateDeltaActionForContainerToComponentTexts(selectedVariable)) { - manager.add(deltaActionForContainerToComponent); - } - if (updateDeltaActionForThisToAnotherTexts(selectedVariable)) { - String text1 = deltaActionForThisToAnother.getText(); - String text2 = deltaActionForContainerToComponent.getText(); - if (!(text1.equals(text2))) { - manager.add(deltaActionForThisToAnother); - } - } - } else if (variableType.equals(VariableType.PARAMETER)) { - if (updateDeltaActionForThisToAnotherTexts(selectedVariable)) { - manager.add(deltaActionForThisToAnother); - } - } - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - } - }); - Menu menu = menuMgr.createContextMenu(viewer.getControl()); - viewer.getControl().setMenu(menu); - getSite().registerContextMenu(menuMgr, viewer); - } - - private boolean updateDeltaActionForContainerToComponentTexts(Variable variable) { - String valueId = selectedVariable.getValueId(); - String valueClassName = selectedVariable.getValueClassName(); - valueClassName = valueClassName.substring(valueClassName.lastIndexOf(".") + 1); - if (!(valueId.isEmpty()) && !(valueClassName.isEmpty())) { - String containerId = selectedVariable.getContainerId(); - String containerClassName = selectedVariable.getContainerClassName(); - if (containerId != null && containerClassName != null) { - containerClassName = containerClassName.substring(containerClassName.lastIndexOf(".") + 1); - String msg = TraceDebuggerPlugin.isJapanese() ? "�I�u�W�F�N�g�̐ڋ߉ߒ����o" : "Extract Process to Relate"; - String textForContainerToComponent = String.format("%s [ %s (id = %s) -> %s (id = %s) ]", msg, containerClassName, containerId, valueClassName, valueId); - deltaActionForContainerToComponent.setText(textForContainerToComponent); - deltaActionForContainerToComponent.setToolTipText(textForContainerToComponent); - return true; - } - } - deltaActionForContainerToComponent.setText(""); - deltaActionForContainerToComponent.setToolTipText(""); - return false; - } - - private boolean updateDeltaActionForThisToAnotherTexts(Variable variable) { - VariableType variableType = variable.getVariableType(); - String anotherId; - String anotherClassName; - if (variableType.isContainerSide()) { - anotherId = selectedVariable.getContainerId(); - anotherClassName = selectedVariable.getContainerClassName(); - } else { - anotherId = selectedVariable.getValueId(); - anotherClassName = selectedVariable.getValueClassName(); - } - anotherClassName = anotherClassName.substring(anotherClassName.lastIndexOf(".") + 1); - TracePoint before = selectedVariable.getBeforeTracePoint(); - String thisId = before.getMethodExecution().getThisObjId(); - String thisClassName = before.getMethodExecution().getThisClassName(); - if (thisId != null && thisClassName != null) { - thisClassName = thisClassName.substring(thisClassName.lastIndexOf(".") + 1); - String msg = TraceDebuggerPlugin.isJapanese() ? "�I�u�W�F�N�g�̐ڋ߉ߒ����o" : "Extract Process to Relate"; - String textForThisToAnother = String.format("%s [ %s (id = %s) -> %s (id = %s) ]", msg, thisClassName, thisId, anotherClassName, anotherId); - deltaActionForThisToAnother.setText(textForThisToAnother); - deltaActionForThisToAnother.setToolTipText(textForThisToAnother); - return true; - } else { - deltaActionForThisToAnother.setText(""); - deltaActionForThisToAnother.setToolTipText(""); - return false; - } - } - - public void markAndExpandVariablesByDeltaMarkers(Map> markers) { - List srcSideDeltaMarkers = markers.get(DeltaMarkerManager.SRC_SIDE_DELTA_MARKER); - List dstSideDeltaMarkers = markers.get(DeltaMarkerManager.DST_SIDE_DELTA_MARKER); - List coordinatorMarker = markers.get(DeltaMarkerManager.COORDINATOR_DELTA_MARKER); - if (srcSideDeltaMarkers != null) { - markVariables(DeltaMarkerManager.SRC_SIDE_DELTA_MARKER, srcSideDeltaMarkers); - } - if (dstSideDeltaMarkers != null) { - markVariables(DeltaMarkerManager.DST_SIDE_DELTA_MARKER, dstSideDeltaMarkers); - } - if (coordinatorMarker != null) { - markVariables(DeltaMarkerManager.COORDINATOR_DELTA_MARKER, coordinatorMarker); - } - viewer.refresh(); - expandAllMarkedNodes(); - } - - private void markVariables(String markerId, List markerList) { - Set idSet = new HashSet<>(); - Map additionalAttributesForVariables = new HashMap<>(); - additionalAttributesForVariables.put("markerId", markerId); - for (IMarker marker : markerList) { - try { - Object data = marker.getAttribute(DeltaMarkerManager.DELTA_MARKER_ATR_DATA); - if (data instanceof Alias) { - idSet.add(((Alias)data).getObjectId()); - } else if (data instanceof MethodExecution) { - idSet.add(((MethodExecution)data).getThisObjId()); - } - } catch (CoreException e) { - e.printStackTrace(); - } - } - variables.addAdditionalAttributes(idSet, additionalAttributesForVariables); - } - - private void expandAllMarkedNodes() { - Set expandedNodes = new HashSet<>(); - for (TreeItem item : viewer.getTree().getItems()) { - Object obj = item.getData(); - if (!(obj instanceof TreeNode)) continue; - collectNodes((TreeNode)obj, expandedNodes); - } - viewer.setExpandedElements(expandedNodes.toArray(new Object[expandedNodes.size()])); - } - - private void collectNodes(TreeNode node, final Set expandedNodes) { - Object value = node.getValue(); - if (!(value instanceof Variable)) return; - Variable variable = (Variable)value; - if (variable.getAdditionalAttribute("markerId") != null) { - TreeNode parent = node.getParent(); - if (parent != null) { - expandedNodes.add(parent); - } - } - TreeNode[] children = node.getChildren(); - if (children == null) return; - for (TreeNode child : children) { - collectNodes(child, expandedNodes); - } - } -} +package org.ntlab.traceDebugger; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.TreeNode; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchPage; +import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; +import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodInvocation; +import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; +import org.ntlab.traceDebugger.Variable.VariableType; +import org.ntlab.traceDebugger.analyzerProvider.Alias; +import org.ntlab.traceDebugger.analyzerProvider.DeltaMarkerManager; +import org.ntlab.traceDebugger.analyzerProvider.VariableUpdatePointFinder; + +public class VariableViewRelatedDelta extends VariableView { + protected IAction jumpAction; + private IAction deltaActionForContainerToComponent; + private IAction deltaActionForThisToAnother; + public static final String ID = "org.ntlab.traceDebugger.variableViewRelatedDelta"; + + public VariableViewRelatedDelta() { + // TODO Auto-generated constructor stub + System.out.println("VariableViewRelatedDelta�N���X���������ꂽ��!"); + } + + @Override + public void createPartControl(Composite parent) { + // TODO Auto-generated method stub + System.out.println("VariableViewRelatedDelta#createPartControl(Composite)���Ă΂ꂽ��!"); + super.createPartControl(parent); + TraceDebuggerPlugin.setActiveView(ID, this); + } + + @Override + public void setFocus() { + // TODO Auto-generated method stub + TraceDebuggerPlugin.setActiveView(ID, this); + viewer.getControl().setFocus(); + } + + @Override + protected void createActions() { + super.createActions(); + jumpAction = new Action() { + public void run() { + TracePoint before = DebuggingController.getInstance().getCurrentTp(); + TracePoint jumpPoint = findJumpPoint(selectedVariable, before); + if (jumpPoint == null) return; + DebuggingController controller = DebuggingController.getInstance(); + controller.jumpToTheTracePoint(jumpPoint, false); + } + }; + + deltaActionForContainerToComponent = new Action() { + @Override + public void run() { + DeltaMarkerView newDeltaMarkerView = (DeltaMarkerView)TraceDebuggerPlugin.createNewView(DeltaMarkerView.ID, IWorkbenchPage.VIEW_ACTIVATE); + newDeltaMarkerView.extractDeltaForContainerToComponent(selectedVariable); + } + }; + + deltaActionForThisToAnother = new Action() { + @Override + public void run() { + TracePoint before = selectedVariable.getBeforeTracePoint(); + String thisId = before.getMethodExecution().getThisObjId(); + String thisClassName = before.getMethodExecution().getThisClassName(); + String anotherId; + String anotherClassName; + if (selectedVariable.getVariableType().isContainerSide()) { + anotherId = selectedVariable.getContainerId(); + anotherClassName = selectedVariable.getContainerClassName(); + } else { + anotherId = selectedVariable.getValueId(); + anotherClassName = selectedVariable.getValueClassName(); + } + DeltaMarkerView newDeltaMarkerView = (DeltaMarkerView)TraceDebuggerPlugin.createNewView(DeltaMarkerView.ID, IWorkbenchPage.VIEW_ACTIVATE); + newDeltaMarkerView.extractDeltaForThisToAnother(thisId, thisClassName, anotherId, anotherClassName, before); + } + }; + } + + private TracePoint findJumpPoint(Variable variable, TracePoint before) { + VariableType variableType = selectedVariable.getVariableType(); + if (variableType.equals(VariableType.USE_VALUE)) { + String containerId = selectedVariable.getContainerId(); + String fieldName = selectedVariable.getFullyQualifiedVariableName(); + return VariableUpdatePointFinder.getInstance().getPoint(containerId, fieldName, before); + } else if (variableType.equals(VariableType.USE_RETURN)) { + return findJumpPointWithReturnValue(variable, before); + } + return null; + } + + private TracePoint findJumpPointWithReturnValue(Variable variable, TracePoint before) { + TracePoint tp = null; + String receiverId = selectedVariable.getContainerId(); + String valueId = selectedVariable.getValueId(); + String receiverClassName = selectedVariable.getContainerClassName(); + VariableUpdatePointFinder finder = VariableUpdatePointFinder.getInstance(); + + // note: �C�e���[�^�̏ꍇ�͂��̃C�e���[�^�̎擾���̃R���N�V������ID�����ɂ��� + if (receiverClassName.contains("Iterator") || receiverClassName.contains("Itr") + || receiverClassName.contains("Collections$UnmodifiableCollection$1")) { + tp = finder.getIteratorPoint(receiverId); // �C�e���[�^�擾���̃|�C���g���擾 + if (tp == null) return null; + MethodInvocation mi = ((MethodInvocation)tp.getStatement()); + receiverId = mi.getCalledMethodExecution().getThisObjId(); // �C�e���[�^�̎擾���̃R���N�V������ID + receiverClassName = mi.getCalledMethodExecution().getThisClassName(); // �C�e���[�^�̎擾���̃R���N�V�����̃N���X�� + } + + // note: �W�����v��ƂȂ� �I�u�W�F�N�g�̑���|�C���g�������̓R���N�V�����ւ̒lj��|�C���g���擾 + tp = finder.getDefinitionInvocationPoint(receiverId, valueId, before); + + // note: �W�����v��̃|�C���g�����‚���Ȃ������ꍇ�ŁA���ƒR���N�V�����ւ̒lj��|�C���g��T���Ă���ꍇ�̓R���N�V�����̏悹�������Œlj����Ă��Ȃ�����T���ɍs�� + if (tp == null && receiverClassName.startsWith("java.util.")) { + String afterCollectionId = receiverId; + while (true) { + tp = finder.getTransferCollectionPoint(afterCollectionId, before); + if (tp == null) break; // �R���N�V�����̏悹������������ȏ�Ȃ��ꍇ + MethodInvocation mi = ((MethodInvocation)tp.getStatement()); + String fromCollectionId = mi.getCalledMethodExecution().getArguments().get(0).getId(); + tp = finder.getDefinitionInvocationPoint(fromCollectionId, valueId, before); + if (tp != null) break; // �R���N�V�����̏悹�������ŃI�u�W�F�N�g�̒lj������‚������ꍇ + afterCollectionId = fromCollectionId; + } + } + return tp; + } + + @Override + protected void createPopupMenu() { + MenuManager menuMgr = new MenuManager("#PopupMenu"); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + @Override + public void menuAboutToShow(IMenuManager manager) { + // �E�N���b�N����x�ɌĂяo����� + VariableType variableType = selectedVariable.getVariableType(); + if (variableType.equals(VariableType.USE_VALUE)) { + manager.add(jumpAction); + String msg = TraceDebuggerPlugin.isJapanese() ? "�l�̑�����_�ɔ��" : "Back to Value Stored Moment"; + jumpAction.setText(msg); + jumpAction.setToolTipText(msg); + } else if (variableType.equals(VariableType.USE_RETURN)) { + manager.add(jumpAction); + if (updateDeltaActionForThisToAnotherTexts(selectedVariable)) { + manager.add(deltaActionForThisToAnother); + } + String msg = TraceDebuggerPlugin.isJapanese() ? "�I�u�W�F�N�g�̒lj����_�ɔ��" : "Back to Object Added Moment"; + jumpAction.setText(msg); + jumpAction.setToolTipText(msg); + } else if (variableType.isDef()) { + if (updateDeltaActionForContainerToComponentTexts(selectedVariable)) { + manager.add(deltaActionForContainerToComponent); + } + if (updateDeltaActionForThisToAnotherTexts(selectedVariable)) { + String text1 = deltaActionForThisToAnother.getText(); + String text2 = deltaActionForContainerToComponent.getText(); + if (!(text1.equals(text2))) { + manager.add(deltaActionForThisToAnother); + } + } + } else if (variableType.equals(VariableType.PARAMETER)) { + if (updateDeltaActionForThisToAnotherTexts(selectedVariable)) { + manager.add(deltaActionForThisToAnother); + } + } + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + }); + Menu menu = menuMgr.createContextMenu(viewer.getControl()); + viewer.getControl().setMenu(menu); + getSite().registerContextMenu(menuMgr, viewer); + } + + private boolean updateDeltaActionForContainerToComponentTexts(Variable variable) { + String valueId = selectedVariable.getValueId(); + String valueClassName = selectedVariable.getValueClassName(); + valueClassName = valueClassName.substring(valueClassName.lastIndexOf(".") + 1); + if (!(valueId.isEmpty()) && !(valueClassName.isEmpty())) { + String containerId = selectedVariable.getContainerId(); + String containerClassName = selectedVariable.getContainerClassName(); + if (containerId != null && containerClassName != null) { + containerClassName = containerClassName.substring(containerClassName.lastIndexOf(".") + 1); + String msg = TraceDebuggerPlugin.isJapanese() ? "�I�u�W�F�N�g�̐ڋ߉ߒ����o" : "Extract Process to Relate"; + String textForContainerToComponent = String.format("%s [ %s (id = %s) -> %s (id = %s) ]", msg, containerClassName, containerId, valueClassName, valueId); + deltaActionForContainerToComponent.setText(textForContainerToComponent); + deltaActionForContainerToComponent.setToolTipText(textForContainerToComponent); + return true; + } + } + deltaActionForContainerToComponent.setText(""); + deltaActionForContainerToComponent.setToolTipText(""); + return false; + } + + private boolean updateDeltaActionForThisToAnotherTexts(Variable variable) { + VariableType variableType = variable.getVariableType(); + String anotherId; + String anotherClassName; + if (variableType.isContainerSide()) { + anotherId = selectedVariable.getContainerId(); + anotherClassName = selectedVariable.getContainerClassName(); + } else { + anotherId = selectedVariable.getValueId(); + anotherClassName = selectedVariable.getValueClassName(); + } + anotherClassName = anotherClassName.substring(anotherClassName.lastIndexOf(".") + 1); + TracePoint before = selectedVariable.getBeforeTracePoint(); + String thisId = before.getMethodExecution().getThisObjId(); + String thisClassName = before.getMethodExecution().getThisClassName(); + if (thisId != null && thisClassName != null) { + thisClassName = thisClassName.substring(thisClassName.lastIndexOf(".") + 1); + String msg = TraceDebuggerPlugin.isJapanese() ? "�I�u�W�F�N�g�̐ڋ߉ߒ����o" : "Extract Process to Relate"; + String textForThisToAnother = String.format("%s [ %s (id = %s) -> %s (id = %s) ]", msg, thisClassName, thisId, anotherClassName, anotherId); + deltaActionForThisToAnother.setText(textForThisToAnother); + deltaActionForThisToAnother.setToolTipText(textForThisToAnother); + return true; + } else { + deltaActionForThisToAnother.setText(""); + deltaActionForThisToAnother.setToolTipText(""); + return false; + } + } + + public void markAndExpandVariablesByDeltaMarkers(Map> markers) { + List srcSideDeltaMarkers = markers.get(DeltaMarkerManager.SRC_SIDE_DELTA_MARKER); + List dstSideDeltaMarkers = markers.get(DeltaMarkerManager.DST_SIDE_DELTA_MARKER); + List coordinatorMarker = markers.get(DeltaMarkerManager.COORDINATOR_DELTA_MARKER); + if (srcSideDeltaMarkers != null) { + markVariables(DeltaMarkerManager.SRC_SIDE_DELTA_MARKER, srcSideDeltaMarkers); + } + if (dstSideDeltaMarkers != null) { + markVariables(DeltaMarkerManager.DST_SIDE_DELTA_MARKER, dstSideDeltaMarkers); + } + if (coordinatorMarker != null) { + markVariables(DeltaMarkerManager.COORDINATOR_DELTA_MARKER, coordinatorMarker); + } + viewer.refresh(); + expandAllMarkedNodes(); + } + + private void markVariables(String markerId, List markerList) { + Set idSet = new HashSet<>(); + Map additionalAttributesForVariables = new HashMap<>(); + additionalAttributesForVariables.put("markerId", markerId); + for (IMarker marker : markerList) { + try { + Object data = marker.getAttribute(DeltaMarkerManager.DELTA_MARKER_ATR_DATA); + if (data instanceof Alias) { + idSet.add(((Alias)data).getObjectId()); + } else if (data instanceof MethodExecution) { + idSet.add(((MethodExecution)data).getThisObjId()); + } + } catch (CoreException e) { + e.printStackTrace(); + } + } + variables.addAdditionalAttributes(idSet, additionalAttributesForVariables); + } + + private void expandAllMarkedNodes() { + Set expandedNodes = new HashSet<>(); + for (TreeItem item : viewer.getTree().getItems()) { + Object obj = item.getData(); + if (!(obj instanceof TreeNode)) continue; + collectNodes((TreeNode)obj, expandedNodes); + } + viewer.setExpandedElements(expandedNodes.toArray(new Object[expandedNodes.size()])); + } + + private void collectNodes(TreeNode node, final Set expandedNodes) { + Object value = node.getValue(); + if (!(value instanceof Variable)) return; + Variable variable = (Variable)value; + if (variable.getAdditionalAttribute("markerId") != null) { + TreeNode parent = node.getParent(); + if (parent != null) { + expandedNodes.add(parent); + } + } + TreeNode[] children = node.getChildren(); + if (children == null) return; + for (TreeNode child : children) { + collectNodes(child, expandedNodes); + } + } + + public void removeDeltaMarkers(Map> markers) { + List srcSideDeltaMarkers = markers.get(DeltaMarkerManager.SRC_SIDE_DELTA_MARKER); + List dstSideDeltaMarkers = markers.get(DeltaMarkerManager.DST_SIDE_DELTA_MARKER); + List coordinatorMarker = markers.get(DeltaMarkerManager.COORDINATOR_DELTA_MARKER); + if (srcSideDeltaMarkers != null) { + markVariables("", srcSideDeltaMarkers); + } + if (dstSideDeltaMarkers != null) { + markVariables("", dstSideDeltaMarkers); + } + if (coordinatorMarker != null) { + markVariables("", coordinatorMarker); + } + viewer.refresh(); + } +} diff --git a/src/org/ntlab/traceDebugger/analyzerProvider/DeltaMarkerManager.java b/src/org/ntlab/traceDebugger/analyzerProvider/DeltaMarkerManager.java index 52039b2..cd2ecaf 100644 --- a/src/org/ntlab/traceDebugger/analyzerProvider/DeltaMarkerManager.java +++ b/src/org/ntlab/traceDebugger/analyzerProvider/DeltaMarkerManager.java @@ -1,1028 +1,1049 @@ -package org.ntlab.traceDebugger.analyzerProvider; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.ASTParser; -import org.eclipse.jdt.core.dom.ASTVisitor; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.Javadoc; -import org.eclipse.jdt.core.dom.MethodDeclaration; -import org.eclipse.jdt.core.dom.SingleVariableDeclaration; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.viewers.TreeNode; -import org.eclipse.ui.editors.text.FileDocumentProvider; -import org.eclipse.ui.part.FileEditorInput; -import org.ntlab.traceAnalysisPlatform.tracer.trace.ArrayAccess; -import org.ntlab.traceAnalysisPlatform.tracer.trace.ArrayCreate; -import org.ntlab.traceAnalysisPlatform.tracer.trace.FieldAccess; -import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; -import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodInvocation; -import org.ntlab.traceAnalysisPlatform.tracer.trace.Reference; -import org.ntlab.traceAnalysisPlatform.tracer.trace.Statement; -import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; -import org.ntlab.traceDebugger.JavaEditorOperator; -import org.ntlab.traceDebugger.JavaElementFinder; -import org.ntlab.traceDebugger.TraceDebuggerPlugin; - -public class DeltaMarkerManager { - private Map> markerIdToMarkers = new HashMap<>(); - private List orderedMarkers = new ArrayList<>(); - private MethodExecution coordinator; - private TracePoint relatedPoint; - private Reference relatedPointReference; - private DeltaRelatedAliasCollector aliasCollector; - public static final String BOTTOM_DELTA_MARKER = "org.ntlab.traceDebugger.bottomDeltaMarker"; - public static final String COORDINATOR_DELTA_MARKER = "org.ntlab.traceDebugger.coordinatorDeltaMarker"; - public static final String SRC_SIDE_DELTA_MARKER = "org.ntlab.traceDebugger.srcSideDeltaMarker"; - public static final String DST_SIDE_DELTA_MARKER = "org.ntlab.traceDebugger.dstSideDeltaMarker"; - public static final String DELTA_MARKER_ATR_DATA = "data"; - public static final String DELTA_MARKER_ATR_OBJECT_ID = "objectId"; - public static final String DELTA_MARKER_ATR_OBJECT_TYPE = "objectType"; - public static final String DELTA_MARKER_ATR_ALIAS_TYPE = "aliasType"; - - public DeltaMarkerManager(MethodExecution coordinator, TracePoint relatedPoint, Reference relatedPointReference, DeltaRelatedAliasCollector aliasCollector) { - this.coordinator = coordinator; - this.relatedPoint = relatedPoint; - this.relatedPointReference = relatedPointReference; - this.aliasCollector = aliasCollector; - } - - public Map> getMarkers() { - return markerIdToMarkers; - } - - public List getMarkersByOrder() { - return orderedMarkers; - } - - public TreeNode[] getMarkerTreeNodes() { - TreeNode[] roots = new TreeNode[] { - new TreeNode(""), - new TreeNode(TraceDebuggerPlugin.isJapanese() ? "�ڋ߉ߒ�" : "Approach"), - new TreeNode("") - }; - List markers; - markers = markerIdToMarkers.get(COORDINATOR_DELTA_MARKER); - roots[0] = new TreeNode(markers.get(0)); - List dstSideMarkers = markerIdToMarkers.get(DST_SIDE_DELTA_MARKER); - List srcSideMarkers = markerIdToMarkers.get(SRC_SIDE_DELTA_MARKER); - int dstSideMarkersSize = (dstSideMarkers != null) ? dstSideMarkers.size() : 0; - int srcSideMarkersSize = (srcSideMarkers != null) ? srcSideMarkers.size() : 0; - TreeNode[] children = new TreeNode[dstSideMarkersSize + srcSideMarkersSize]; - if (dstSideMarkers != null) { - for (int i = 0; i < dstSideMarkers.size(); i++) { - children[i] = new TreeNode(dstSideMarkers.get(i)); - } - } - if (srcSideMarkers != null) { - for (int i = 0; i < srcSideMarkers.size(); i++) { - children[dstSideMarkersSize + i] = new TreeNode(srcSideMarkers.get(i)); - } - } - roots[1].setChildren(children); - markers = markerIdToMarkers.get(BOTTOM_DELTA_MARKER); - roots[2] = new TreeNode(markers.get(0)); - return roots; - } - - public IMarker getCoordinatorDeltaMarker() { - List markers = markerIdToMarkers.get(COORDINATOR_DELTA_MARKER); - if (markers == null || markers.isEmpty()) return null; - return markers.get(0); - } - - public IMarker getBottomDeltaMarker() { - List markers = markerIdToMarkers.get(BOTTOM_DELTA_MARKER); - if (markers == null || markers.isEmpty()) return null; - return markers.get(0); - } - - public static MethodExecution getMethodExecution(IMarker deltaMarker) { - try { - Object data = deltaMarker.getAttribute(DELTA_MARKER_ATR_DATA); - if (data instanceof MethodExecution) { - return (MethodExecution) data; - } else if (data instanceof TracePoint) { - TracePoint tp = (TracePoint)data; - return tp.getMethodExecution(); - } else if (data instanceof Alias) { - Alias alias = (Alias)data; - return alias.getMethodExecution(); - } - } catch (CoreException e) { - e.printStackTrace(); - } - return null; - } - - public static TracePoint getTracePoint(IMarker deltaMarker) { - try { - Object data = deltaMarker.getAttribute(DELTA_MARKER_ATR_DATA); - if (data instanceof MethodExecution) { - return ((MethodExecution)data).getEntryPoint(); - } else if (data instanceof TracePoint) { - return (TracePoint)data; - } else if (data instanceof Alias) { - return ((Alias)data).getOccurrencePoint(); - } - } catch (CoreException e) { - e.printStackTrace(); - } - return null; - } - - public void createMarkerAndOpenJavaFileForAll() { - String msg = TraceDebuggerPlugin.isJapanese() ? "�J�n���_" : "InitialPoint"; - markAndOpenJavaFileForCoordinator(coordinator, msg, DeltaMarkerManager.COORDINATOR_DELTA_MARKER); - List dstSideAliases = new ArrayList<>(aliasCollector.getDstSideRelatedAliases()); - List srcSideAliases = new ArrayList<>(aliasCollector.getSrcSideRelatedAliases()); - List> relatedAliasesList = new ArrayList<>(); - relatedAliasesList.add(dstSideAliases); - relatedAliasesList.add(srcSideAliases); - String[] messagesTemplates = TraceDebuggerPlugin.isJapanese() ? new String[]{"�Q�Ɛ摤%03d", "�Q�ƌ���%03d"} - : new String[]{"ReferredSide%03d", "ReferringSide%03d"}; - String[] markerIDList = {DST_SIDE_DELTA_MARKER, SRC_SIDE_DELTA_MARKER}; - for (int i = 0; i < relatedAliasesList.size(); i++) { - List relatedAliases = relatedAliasesList.get(i); - Collections.reverse(relatedAliases); - int cnt = 1; - for (Alias alias : relatedAliases) { - String message = String.format(messagesTemplates[i], cnt++); - markAndOpenJavaFileForAlias(alias, message, markerIDList[i]); - } - } - msg = TraceDebuggerPlugin.isJapanese() ? "�Q�Ǝ��_" : "RelatedPoint"; - markAndOpenJavaFileForCreationPoint(relatedPoint, relatedPointReference, msg, DeltaMarkerManager.BOTTOM_DELTA_MARKER); - createMarkerListOrdered(); - } - - private void createMarkerListOrdered() { - orderedMarkers.clear(); - IMarker coordinatorMarker = getCoordinatorDeltaMarker(); - if (coordinatorMarker != null) orderedMarkers.add(coordinatorMarker); - List aliasMarkers = new ArrayList<>(); - List srcSideMarkers = markerIdToMarkers.get(SRC_SIDE_DELTA_MARKER); - if (srcSideMarkers != null) aliasMarkers.addAll(srcSideMarkers); - List dstSideMarkers = markerIdToMarkers.get(DST_SIDE_DELTA_MARKER); - if (dstSideMarkers != null) aliasMarkers.addAll(dstSideMarkers); - Collections.sort(aliasMarkers, new Comparator() { - @Override - public int compare(IMarker o1, IMarker o2) { - TracePoint tp1 = DeltaMarkerManager.getTracePoint(o1); - TracePoint tp2 = DeltaMarkerManager.getTracePoint(o2); - long time1 = tp1.getMethodExecution().getEntryTime(); - long time2 = tp2.getMethodExecution().getEntryTime(); - return (time1 < time2) ? -1 : 1; - } - }); - orderedMarkers.addAll(aliasMarkers); - IMarker bottomMarker = getBottomDeltaMarker(); - if (bottomMarker != null) orderedMarkers.add(bottomMarker); - } - - private void markAndOpenJavaFileForAlias(Alias alias, String message, String markerId) { - IFile file = JavaElementFinder.findIFile(alias.getMethodExecution()); - if (file != null) { - IMarker marker = addMarkerForAlias(alias, file, message, markerId); - JavaEditorOperator.markAndOpenJavaFile(marker); - } - } - - private void markAndOpenJavaFileForCreationPoint(TracePoint creationPoint, Reference reference, String message, String markerId) { - MethodExecution me = creationPoint.getMethodExecution(); - String objectId = reference.getSrcObjectId() + " -> " + reference.getDstObjectId(); - String objectType = reference.getSrcClassName() + " -> " + reference.getDstClassName(); - IFile file = JavaElementFinder.findIFile(me); - if (file != null) { - IMarker marker = addMarkerForCreationPoint(creationPoint, file, message, objectId, objectType, markerId); - JavaEditorOperator.markAndOpenJavaFile(marker); - } - } - - private void markAndOpenJavaFileForCoordinator(MethodExecution methodExecution, String message, String markerId) { - IFile file = JavaElementFinder.findIFile(methodExecution); - if (file != null) { - String objectId = methodExecution.getThisObjId(); - String objectType = methodExecution.getThisClassName(); - IMarker marker = addMarkerForCoordinator(methodExecution, file, message, objectId, objectType, markerId); - JavaEditorOperator.markAndOpenJavaFile(marker); - } - } - - private IMarker addMarkerForAlias(Alias alias, IFile file, String message, String markerId) { - try { - IMarker marker = file.createMarker(markerId); - Map attributes = new HashMap<>(); - setAttributesForAlias(attributes, alias, file, markerId); - if (!(attributes.containsKey(IMarker.LINE_NUMBER))) { - attributes.put(IMarker.LINE_NUMBER, alias.getLineNo() + " (no marker)"); - } - attributes.put(IMarker.MESSAGE, message); - attributes.put(IMarker.TRANSIENT, true); - attributes.put(DELTA_MARKER_ATR_DATA, alias); - attributes.put(DELTA_MARKER_ATR_OBJECT_ID, alias.getObjectId()); - attributes.put(DELTA_MARKER_ATR_OBJECT_TYPE, alias.getObjectType()); - attributes.put(DELTA_MARKER_ATR_ALIAS_TYPE, alias.getAliasType()); - marker.setAttributes(attributes); - addMarker(markerId, marker); - return marker; - } catch (CoreException e) { - e.printStackTrace(); - } - return null; - } - - private IMarker addMarkerForCreationPoint(TracePoint tp, IFile file, String message, String objectId, String objectType, String markerId) { - try { - MethodExecution me = tp.getMethodExecution(); - int lineNo = tp.getStatement().getLineNo(); - IMarker marker = file.createMarker(markerId); - Map attributes = new HashMap<>(); - setAttributesForCreationPoint(attributes, me, file, lineNo, markerId); - if (!(attributes.containsKey(IMarker.LINE_NUMBER))) attributes.put(IMarker.LINE_NUMBER, tp.getStatement().getLineNo()); - attributes.put(IMarker.MESSAGE, message); - attributes.put(IMarker.TRANSIENT, true); - attributes.put(DELTA_MARKER_ATR_DATA, tp); - attributes.put(DELTA_MARKER_ATR_OBJECT_ID, objectId); - attributes.put(DELTA_MARKER_ATR_OBJECT_TYPE, objectType); - marker.setAttributes(attributes); - addMarker(markerId, marker); - return marker; - } catch (CoreException e) { - e.printStackTrace(); - } - return null; - } - - private IMarker addMarkerForCoordinator(MethodExecution me, IFile file, String message, String objectId, String objectType, String markerId) { - try { - IMarker marker = file.createMarker(markerId); - Map attributes = new HashMap<>(); - setAttributesForCoordinator(attributes, me, file); - attributes.put(IMarker.MESSAGE, message); - attributes.put(IMarker.TRANSIENT, true); - attributes.put("data", me); - attributes.put("objectId", objectId); - attributes.put("objectType", objectType); - marker.setAttributes(attributes); - addMarker(markerId, marker); - return marker; - } catch (CoreException e) { - e.printStackTrace(); - } - return null; - } - - private void addMarker(String markerId, IMarker marker) { - List markerList = markerIdToMarkers.get(markerId); - if (markerList == null) { - markerList = new ArrayList(); - markerIdToMarkers.put(markerId, markerList); - } - markerList.add(marker); -// orderedMarkers.add(marker); - } - - private void setAttributesForAlias(final Map attributes, Alias alias, IFile file, String markerId) { - try { - FileEditorInput input = new FileEditorInput(file); - FileDocumentProvider provider = new FileDocumentProvider(); - provider.connect(input); - ASTParser parser = ASTParser.newParser(AST.JLS10); - MethodExecution methodExecution = alias.getMethodExecution(); - IType type = JavaElementFinder.findIType(methodExecution); - IMethod method = JavaElementFinder.findIMethod(methodExecution, type); - if (method != null) { - ICompilationUnit unit = method.getCompilationUnit(); - parser.setSource(unit); - ASTNode node = parser.createAST(new NullProgressMonitor()); - if (node instanceof CompilationUnit) { - CompilationUnit cUnit = (CompilationUnit)node; - ASTVisitor visitor = createVisitor(alias, method, cUnit, attributes); - if (visitor != null) { - node.accept(visitor); - } - } - } - } catch (CoreException e) { - e.printStackTrace(); - } - } - - private ASTVisitor createVisitor(final Alias alias, final IMethod method, final CompilationUnit cUnit, final Map attributes) { - class MyASTVisitor extends ASTVisitor { - public boolean preVisit2(ASTNode node) { - if (attributes.containsKey(IMarker.LINE_NUMBER)) return false; - if (node instanceof org.eclipse.jdt.core.dom.MethodDeclaration) { - try { - // note: �Y�����郁�\�b�h�Ăяo���̏ꍇ�̂ݎq�m�[�h�̒T���𑱍s - String src1 = node.toString().replaceAll(" ", ""); - src1 = src1.substring(0, src1.lastIndexOf("\n")); - String src1Head = src1.substring(0, src1.indexOf(")") + 1); - src1Head = src1Head.replaceAll(" |\t|\r|\n", ""); - src1Head = src1Head.substring(src1Head.indexOf("*/") + 2); // note: �擪�̃R�����g�����O�� - String src2 = method.getSource().replaceAll(" |\t|\r|\n", ""); - return src2.contains(src1Head); - } catch (JavaModelException e) { - e.printStackTrace(); - return false; - } - } - return true; - } - } - ASTVisitor visitor = new MyASTVisitor(); - try { - Statement statement = alias.getOccurrencePoint().getStatement(); - final String source = method.getCompilationUnit().getSource(); - switch (alias.getAliasType()) { - // note: ���\�b�h�ւ̓��� - case FORMAL_PARAMETER: { - final int index = alias.getIndex(); - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.MethodDeclaration node) { - Object obj = node.parameters().get(index); - if (obj instanceof SingleVariableDeclaration) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - SingleVariableDeclaration parameter = (SingleVariableDeclaration)obj; - int start = parameter.getStartPosition(); - int end = start + parameter.getLength(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - } - return false; - } - }; - return visitor; - } - case THIS: { - if (statement instanceof FieldAccess) { - final FieldAccess fa = (FieldAccess)statement; - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.FieldAccess node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.getName().toString(); - String name2 = fa.getFieldName(); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - int start = node.getStartPosition(); - int end = start; - if (source.startsWith("this.", start)) { - end = start + "this".length(); - } - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.ArrayAccess node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - int start = node.getStartPosition(); - int end = start; - if (source.startsWith("this.", start)) { - end = start + "this".length(); - } - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return true; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.SimpleName node) { - // note: ���\�b�h�Ăяo���̃��V�[�o��this�̏ꍇ - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - if (!(node.getParent() instanceof org.eclipse.jdt.core.dom.MethodInvocation)) return true; - String name1 = node.toString(); - String name2 = fa.getFieldName(); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - int start = node.getStartPosition(); - int end = start; - int index = node.toString().indexOf("this."); - if (index != -1) { - start += index; - end = start + "this".length(); - } - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { - // note: �R���X�g���N�^�Ăяo���̈�����this������ꍇ - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.toString(); - name1 = name1.substring(name1.indexOf("(")); - name1 = name1.replaceAll("<.*>", ""); - String name2 = fa.getFieldName(); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.contains(name2))) return true; - int start = node.getStartPosition(); - int end = start; - int index = node.toString().indexOf("this"); - if (index != -1) { - start += index; - end = start + "this".length(); - } - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.ReturnStatement node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - int start = node.getStartPosition(); - int end = start; - int index = node.toString().indexOf("this"); - if (index != -1) { - start += index; - end = start + "this".length(); - } - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.IfStatement node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String fieldName = fa.getFieldName(); - fieldName = fieldName.substring(fieldName.lastIndexOf(".") + 1); - int start = node.getStartPosition(); - int end = start; - Expression expression = node.getExpression(); - if (expression != null) { - start = expression.getStartPosition(); - start += expression.toString().indexOf(fieldName); - end = start; - if (source.startsWith("this.", start - "this.".length())) { - start -= "this.".length(); - end = start + "this".length(); - } - } - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - } else if (statement instanceof MethodInvocation) { - final MethodInvocation mi = (MethodInvocation)statement; - final MethodExecution calledMe = mi.getCalledMethodExecution(); - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.MethodInvocation node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.getName().toString() + "("; - String name2 = calledMe.getCallerSideSignature(); - name2 = name2.substring(0, name2.indexOf("(") + 1); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - String receiverName = node.getExpression().toString(); - int start = node.getStartPosition(); - attributes.put(IMarker.CHAR_START, start); - if (source.startsWith("this.", start)) { - attributes.put(IMarker.CHAR_END, start + "this".length()); - } else { - attributes.put(IMarker.CHAR_END, start + receiverName.length()); - } - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.toString(); - name1 = name1.substring("new ".length(), name1.indexOf("(") + 1); - name1 = name1.replaceAll("<.*>", ""); - String name2 = calledMe.getCallerSideSignature(); - name2 = name2.substring(0, name2.indexOf("(") + 1); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - int start = node.getStartPosition(); - int end = start; // note: �R���X�g���N�^�Ăяo���ɑΉ�����this�̓R�[�h���ɂ͏o�Ă��Ȃ����ߒ���0�̃}�[�J�[�ɂ��� - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - } - return visitor; - } - case METHOD_INVOCATION: { - if (statement instanceof MethodInvocation) { - final MethodInvocation mi = (MethodInvocation)statement; - final MethodExecution calledMe = mi.getCalledMethodExecution(); - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.MethodInvocation node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.getName().toString() + "("; - String name2 = calledMe.getCallerSideSignature(); - name2 = name2.substring(0, name2.indexOf("(") + 1); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - Expression expression = node.getExpression(); - String receiverName = ""; - if (expression != null) { - receiverName = expression.toString(); - } - int start = node.getStartPosition(); - if (source.startsWith("this.", start)) { - start += ("this." + receiverName + ".").length(); - } else if (source.startsWith("super.", start)) { - start += ("super." + receiverName + ".").length(); - } else if (!(receiverName.isEmpty())) { - start += (receiverName + ".").length(); - } - int end = node.getStartPosition() + node.getLength(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.toString(); - name1 = name1.substring("new ".length(), name1.indexOf("(") + 1); - name1 = name1.replaceAll("<.*>", ""); - String name2 = calledMe.getCallerSideSignature(); - name2 = name2.substring(name2.lastIndexOf(".") + 1, name2.indexOf("(") + 1); - if (!(name1.equals(name2))) return true; - int start = node.getStartPosition(); - int end = start + node.getLength(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - } - return visitor; - } - case CONSTRACTOR_INVOCATION: { - if (statement instanceof MethodInvocation) { - final MethodInvocation mi = (MethodInvocation)statement; - final MethodExecution calledMe = mi.getCalledMethodExecution(); - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.toString(); - name1 = name1.substring("new ".length(), name1.indexOf("(") + 1); - name1 = name1.replaceAll("<.*>", ""); - String name2 = calledMe.getCallerSideSignature(); - name2 = name2.substring(0, name2.indexOf("(") + 1); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - int start = node.getStartPosition(); - int end = start + node.getLength(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - } - return visitor; - } - // note: �ǐՃI�u�W�F�N�g�̐؂�ւ� - case FIELD: { - if (statement instanceof FieldAccess) { - final FieldAccess fa = (FieldAccess)statement; - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.FieldAccess node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.getName().toString(); - String name2 = fa.getFieldName(); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - int start = node.getStartPosition(); - int end = start + node.getLength(); - if (source.startsWith("this.", start)) { - attributes.put(IMarker.CHAR_START, start + "this.".length()); - } else { - attributes.put(IMarker.CHAR_START, start); - } - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.ArrayAccess node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - int start = node.getStartPosition(); - int end = start + node.getArray().toString().length(); - if (source.startsWith("this.", start)) { - attributes.put(IMarker.CHAR_START, start + "this.".length()); - } else { - attributes.put(IMarker.CHAR_START, start); - } - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.SimpleName node) { - // note: ���\�b�h�Ăяo���̃��V�[�o���t�B�[���h�̏ꍇ�̓t�B�[���h�A�N�Z�X�̃m�[�h���Ɨ��Ȃ�������ɂ���Œʂ� - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - if (!(node.getParent() instanceof org.eclipse.jdt.core.dom.MethodInvocation)) return true; - String name1 = node.toString(); - String name2 = fa.getFieldName(); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - int start = node.getStartPosition(); - int end = start + node.getLength(); - if (source.startsWith("this.", start)) { - attributes.put(IMarker.CHAR_START, start + "this.".length()); - } else { - attributes.put(IMarker.CHAR_START, start); - } - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { - // note: �R���X�g���N�^�Ăяo���̈����Ƀt�B�[���h������ꍇ - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.toString(); - name1 = name1.substring(name1.indexOf("(")); - name1 = name1.replaceAll("<.*>", ""); - String name2 = fa.getFieldName(); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.contains(name2))) return true; - int start = node.getStartPosition(); - start += (node.toString().indexOf("(") + name1.indexOf(name2)); - int end = start + name2.length(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.ReturnStatement node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String fieldName = fa.getFieldName(); - fieldName = fieldName.substring(fieldName.lastIndexOf(".") + 1); - int start = node.getStartPosition(); - start += node.toString().indexOf(fieldName); - int end = start + fieldName.length(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.IfStatement node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String fieldName = fa.getFieldName(); - fieldName = fieldName.substring(fieldName.lastIndexOf(".") + 1); - int start = node.getStartPosition(); - int end = start + node.getLength(); - Expression expression = node.getExpression(); - if (expression != null) { - start = expression.getStartPosition(); - start += expression.toString().indexOf(fieldName); - end = start + fieldName.length(); - } - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - } - return visitor; - } - case CONTAINER: { - if (statement instanceof FieldAccess) { - final FieldAccess fa = (FieldAccess)statement; - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.QualifiedName node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.getName().toString(); - String name2 = fa.getFieldName(); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - int start = node.getStartPosition(); - int end = start + node.getLength(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - } - return visitor; - } - case ARRAY_ELEMENT: { - // note: �z��̃Z�b�g�ƃQ�b�g�̃g���[�X�ɂ͍s�ԍ���z�񖼂��L�^����Ă��Ȃ� - if (statement instanceof ArrayAccess) { - final ArrayAccess aa = (ArrayAccess)statement; - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.ArrayAccess node) { - int index = Integer.parseInt(node.getIndex().toString()); - if (index != aa.getIndex()) return true; - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - int start = node.getStartPosition(); - int end = start + node.getLength(); - if (source.startsWith("this.", start)) { - attributes.put(IMarker.CHAR_START, start + "this.".length()); - } else { - attributes.put(IMarker.CHAR_START, start); - } - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - } - return visitor; - } - case ARRAY: { - // note: �z��̃Z�b�g�ƃQ�b�g�̃g���[�X�ɂ͍s�ԍ���z�񖼂��L�^����Ă��Ȃ� - if (statement instanceof ArrayAccess) { - final ArrayAccess aa = (ArrayAccess)statement; - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.ArrayAccess node) { - int index = Integer.parseInt(node.getIndex().toString()); - if (index != aa.getIndex()) return true; - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - int start = node.getStartPosition(); - int end = start + node.getArray().toString().length(); - if (source.startsWith("this.", start)) { - attributes.put(IMarker.CHAR_START, start + "this.".length()); - } else { - attributes.put(IMarker.CHAR_START, start); - } - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - } - return visitor; - } - case ARRAY_CREATE: { - if (statement instanceof ArrayCreate) { - final ArrayCreate ac = (ArrayCreate)statement; - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.ArrayCreation node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != ac.getLineNo()) return true; - int start = node.getStartPosition(); - int end = start + node.getLength(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - } - return visitor; - } - // note: ���\�b�h����̏o�� - case ACTUAL_ARGUMENT: { - if (statement instanceof MethodInvocation) { - final MethodInvocation mi = (MethodInvocation)statement; - final MethodExecution calledMe = mi.getCalledMethodExecution(); - final int index = alias.getIndex(); - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.MethodInvocation node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.getName().toString(); - String name2 = calledMe.getCallerSideSignature(); - name2 = name2.substring(0, name2.indexOf("(")); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - Object obj = node.arguments().get(index); - if (obj instanceof Expression) { - Expression argument = (Expression)obj; - int start = argument.getStartPosition(); - int end = start + argument.getLength(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - } - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.SuperMethodInvocation node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.getName().toString(); - String name2 = calledMe.getCallerSideSignature(); - name2 = name2.substring(0, name2.indexOf("(")); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - Object obj = node.arguments().get(index); - if (obj instanceof Expression) { - Expression argument = (Expression)obj; - int start = argument.getStartPosition(); - int end = start + argument.getLength(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - } - return false; - } - }; - } - return visitor; - } - case RECEIVER: { - if (statement instanceof MethodInvocation) { - final MethodInvocation mi = (MethodInvocation)statement; - final MethodExecution calledMe = mi.getCalledMethodExecution(); - visitor = new MyASTVisitor() { - @Override - public boolean visit(org.eclipse.jdt.core.dom.MethodInvocation node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.getName().toString(); - String name2 = calledMe.getCallerSideSignature(); - name2 = name2.substring(0, name2.indexOf("(")); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - int start = node.getStartPosition(); - int end = start; - Expression expression = node.getExpression(); // note: ���\�b�h�Ăяo���̃��V�[�o�����擾 - if (expression != null) { - String receiverName = expression.toString(); // note: ���\�b�h�Ăяo���̃��V�[�o���܂� - end = start + receiverName.length(); - } - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - @Override - public boolean visit(org.eclipse.jdt.core.dom.SuperMethodInvocation node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - if (lineNo != alias.getLineNo()) return true; - String name1 = node.getName().toString(); - String name2 = calledMe.getCallerSideSignature(); - name2 = name2.substring(0, name2.indexOf("(")); - name2 = name2.substring(name2.lastIndexOf(".") + 1); - if (!(name1.equals(name2))) return true; - int start = node.getStartPosition(); - int end = start + "super".length(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - } - return visitor; - } - case RETURN_VALUE: - // note: �ǂ��Ń��^�[���������̏��(�s�ԍ���)���g���[�X�ɂ͋L�^����Ă��Ȃ� - visitor = new MyASTVisitor(){ - public boolean visit(org.eclipse.jdt.core.dom.ReturnStatement node) { - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - int aliasLineNo = alias.getLineNo(); - if (lineNo < aliasLineNo) return true; // ���ۂɃ��^�[�������ꏊ�̒��O�ɂ���ŏI�X�e�[�g�����g�����O�̃��^�[���͔�΂� - int start = node.getStartPosition(); - int end = start + node.getLength(); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - return false; - } - }; - return visitor; - } - } catch (JavaModelException e) { - e.printStackTrace(); - } - return visitor; - } - - private void setAttributesForCoordinator(final Map attributes, MethodExecution methodExecution, IFile file) { - // note: ���\�b�h�V�O�l�`�����n�C���C�g - IType type = JavaElementFinder.findIType(methodExecution); - final IMethod method = JavaElementFinder.findIMethod(methodExecution, type); - if (method == null) return; - ASTParser parser = ASTParser.newParser(AST.JLS10); - ICompilationUnit unit = method.getCompilationUnit(); - parser.setSource(unit); - ASTNode node = parser.createAST(new NullProgressMonitor()); - if (node instanceof CompilationUnit) { - final CompilationUnit cUnit = (CompilationUnit)node; - node.accept(new ASTVisitor() { - @Override - public boolean visit(MethodDeclaration node) { - try { - if (attributes.containsKey(IMarker.LINE_NUMBER)) return false; - String src1 = node.toString().replaceAll(" ", ""); - src1 = src1.substring(0, src1.lastIndexOf("\n")); - String src1Head = src1.substring(0, src1.indexOf(")") + 1); - String src2 = method.getSource().replaceAll(" |\t|\r|\n", ""); - if (!(src2.contains(src1Head))) return false; - int start = node.getStartPosition(); - int end = start + node.toString().indexOf(")") + 1; - Javadoc javadoc = node.getJavadoc(); - if (javadoc != null) { - start += javadoc.getLength(); - start += 5; // note: node.toString()�Ǝ��ۂ̃R�[�h�̃X�y�[�X���̍��������l�߂鉼���� - String tmp = node.toString().replace(javadoc.toString(), ""); - end = start + tmp.indexOf(")") + 1; - } - int lineNo = cUnit.getLineNumber(node.getStartPosition()); - attributes.put(IMarker.CHAR_START, start); - attributes.put(IMarker.CHAR_END, end); - attributes.put(IMarker.LINE_NUMBER, lineNo); - } catch (JavaModelException e) { - e.printStackTrace(); - } - return false; - } - }); - } - } - - private void setAttributesForCreationPoint(final Map attributes, MethodExecution methodExecution, IFile file, int lineNo, String markerId) { - try { - FileEditorInput input = new FileEditorInput(file); - FileDocumentProvider provider = new FileDocumentProvider(); - provider.connect(input); - IDocument document = provider.getDocument(input); - IRegion lineRegion = document.getLineInformation(lineNo - 1); - attributes.put(IMarker.CHAR_START, lineRegion.getOffset()); - attributes.put(IMarker.CHAR_END, lineRegion.getOffset() + lineRegion.getLength()); - attributes.put(IMarker.LINE_NUMBER, lineNo); - } catch (CoreException | BadLocationException e) { - e.printStackTrace(); - } - } - - private void deleteMarkers(List markerList) { - for (IMarker marker : markerList) { - try { - marker.delete(); - } catch (CoreException e) { - e.printStackTrace(); - } - } - } - - public void clearAllMarkers() { - for (List markerList: markerIdToMarkers.values()) { - deleteMarkers(markerList); - } - markerIdToMarkers.clear(); - orderedMarkers.clear(); - } -} +package org.ntlab.traceDebugger.analyzerProvider; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.ASTVisitor; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.Javadoc; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.SingleVariableDeclaration; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.viewers.TreeNode; +import org.eclipse.ui.editors.text.FileDocumentProvider; +import org.eclipse.ui.part.FileEditorInput; +import org.ntlab.traceAnalysisPlatform.tracer.trace.ArrayAccess; +import org.ntlab.traceAnalysisPlatform.tracer.trace.ArrayCreate; +import org.ntlab.traceAnalysisPlatform.tracer.trace.FieldAccess; +import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodExecution; +import org.ntlab.traceAnalysisPlatform.tracer.trace.MethodInvocation; +import org.ntlab.traceAnalysisPlatform.tracer.trace.Reference; +import org.ntlab.traceAnalysisPlatform.tracer.trace.Statement; +import org.ntlab.traceAnalysisPlatform.tracer.trace.TracePoint; +import org.ntlab.traceDebugger.JavaEditorOperator; +import org.ntlab.traceDebugger.JavaElementFinder; +import org.ntlab.traceDebugger.TraceDebuggerPlugin; + +public class DeltaMarkerManager { + private Map> markerIdToMarkers = new HashMap<>(); + private List orderedMarkers = new ArrayList<>(); + private MethodExecution coordinator; + private TracePoint relatedPoint; + private Reference relatedPointReference; + private DeltaRelatedAliasCollector aliasCollector; + public static final String BOTTOM_DELTA_MARKER = "org.ntlab.traceDebugger.bottomDeltaMarker"; + public static final String COORDINATOR_DELTA_MARKER = "org.ntlab.traceDebugger.coordinatorDeltaMarker"; + public static final String SRC_SIDE_DELTA_MARKER = "org.ntlab.traceDebugger.srcSideDeltaMarker"; + public static final String DST_SIDE_DELTA_MARKER = "org.ntlab.traceDebugger.dstSideDeltaMarker"; + public static final String DELTA_MARKER_ATR_DATA = "data"; + public static final String DELTA_MARKER_ATR_OBJECT_ID = "objectId"; + public static final String DELTA_MARKER_ATR_OBJECT_TYPE = "objectType"; + public static final String DELTA_MARKER_ATR_ALIAS_TYPE = "aliasType"; + + public DeltaMarkerManager(MethodExecution coordinator, TracePoint relatedPoint, Reference relatedPointReference, DeltaRelatedAliasCollector aliasCollector) { + this.coordinator = coordinator; + this.relatedPoint = relatedPoint; + this.relatedPointReference = relatedPointReference; + this.aliasCollector = aliasCollector; + } + + public Map> getMarkers() { + return markerIdToMarkers; + } + + public List getMarkersByOrder() { + return orderedMarkers; + } + + public TreeNode[] getMarkerTreeNodes() { + TreeNode[] roots = new TreeNode[] { + new TreeNode(""), + new TreeNode(TraceDebuggerPlugin.isJapanese() ? "�ڋ߉ߒ�" : "Approach"), + new TreeNode("") + }; + List markers; + markers = markerIdToMarkers.get(COORDINATOR_DELTA_MARKER); + roots[0] = new TreeNode(markers.get(0)); + List dstSideMarkers = markerIdToMarkers.get(DST_SIDE_DELTA_MARKER); + List srcSideMarkers = markerIdToMarkers.get(SRC_SIDE_DELTA_MARKER); + int dstSideMarkersSize = (dstSideMarkers != null) ? dstSideMarkers.size() : 0; + int srcSideMarkersSize = (srcSideMarkers != null) ? srcSideMarkers.size() : 0; + TreeNode[] children = new TreeNode[dstSideMarkersSize + srcSideMarkersSize]; + if (dstSideMarkers != null) { + for (int i = 0; i < dstSideMarkers.size(); i++) { + children[i] = new TreeNode(dstSideMarkers.get(i)); + } + } + if (srcSideMarkers != null) { + for (int i = 0; i < srcSideMarkers.size(); i++) { + children[dstSideMarkersSize + i] = new TreeNode(srcSideMarkers.get(i)); + } + } + roots[1].setChildren(children); + markers = markerIdToMarkers.get(BOTTOM_DELTA_MARKER); + roots[2] = new TreeNode(markers.get(0)); + return roots; + } + + public IMarker getCoordinatorDeltaMarker() { + List markers = markerIdToMarkers.get(COORDINATOR_DELTA_MARKER); + if (markers == null || markers.isEmpty()) return null; + return markers.get(0); + } + + public IMarker getBottomDeltaMarker() { + List markers = markerIdToMarkers.get(BOTTOM_DELTA_MARKER); + if (markers == null || markers.isEmpty()) return null; + return markers.get(0); + } + + public static MethodExecution getMethodExecution(IMarker deltaMarker) { + try { + Object data = deltaMarker.getAttribute(DELTA_MARKER_ATR_DATA); + if (data instanceof MethodExecution) { + return (MethodExecution) data; + } else if (data instanceof TracePoint) { + TracePoint tp = (TracePoint)data; + return tp.getMethodExecution(); + } else if (data instanceof Alias) { + Alias alias = (Alias)data; + return alias.getMethodExecution(); + } + } catch (CoreException e) { + e.printStackTrace(); + } + return null; + } + + public static TracePoint getTracePoint(IMarker deltaMarker) { + try { + Object data = deltaMarker.getAttribute(DELTA_MARKER_ATR_DATA); + if (data instanceof MethodExecution) { + return ((MethodExecution)data).getEntryPoint(); + } else if (data instanceof TracePoint) { + return (TracePoint)data; + } else if (data instanceof Alias) { + return ((Alias)data).getOccurrencePoint(); + } + } catch (CoreException e) { + e.printStackTrace(); + } + return null; + } + + public void createMarkerAndOpenJavaFileForAll() { + String msg = TraceDebuggerPlugin.isJapanese() ? "�J�n���_" : "InitialPoint"; + markAndOpenJavaFileForCoordinator(coordinator, msg, DeltaMarkerManager.COORDINATOR_DELTA_MARKER); + List dstSideAliases = new ArrayList<>(aliasCollector.getDstSideRelatedAliases()); + List srcSideAliases = new ArrayList<>(aliasCollector.getSrcSideRelatedAliases()); + List> relatedAliasesList = new ArrayList<>(); + relatedAliasesList.add(dstSideAliases); + relatedAliasesList.add(srcSideAliases); +// String[] messagesTemplates = TraceDebuggerPlugin.isJapanese() ? new String[]{"�Q�Ɛ摤%03d", "�Q�ƌ���%03d"} +// : new String[]{"ReferredSide%03d", "ReferringSide%03d"}; + String[] markerIDList = {DST_SIDE_DELTA_MARKER, SRC_SIDE_DELTA_MARKER}; + for (int i = 0; i < relatedAliasesList.size(); i++) { + List relatedAliases = relatedAliasesList.get(i); + Collections.reverse(relatedAliases); +// int cnt = 1; + for (Alias alias : relatedAliases) { +// String message = String.format(messagesTemplates[i], cnt++); + markAndOpenJavaFileForAlias(alias, "", markerIDList[i]); + } + } + msg = TraceDebuggerPlugin.isJapanese() ? "�Q�Ǝ��_" : "RelatedPoint"; + markAndOpenJavaFileForCreationPoint(relatedPoint, relatedPointReference, msg, DeltaMarkerManager.BOTTOM_DELTA_MARKER); + + List srcSideMarkers = markerIdToMarkers.get(SRC_SIDE_DELTA_MARKER); + if (srcSideMarkers != null) setDescriptionForAliases(srcSideMarkers, true); + List dstSideMarkers = markerIdToMarkers.get(DST_SIDE_DELTA_MARKER); + if (dstSideMarkers != null) setDescriptionForAliases(dstSideMarkers, false); + createMarkerListOrdered(); + } + + private void setDescriptionForAliases(List markers, boolean isSrcSide) { + String[] messagesTemplates = TraceDebuggerPlugin.isJapanese() ? new String[]{"�Q�Ɛ摤%03d", "�Q�ƌ���%03d"} + : new String[]{"ReferredSide%03d", "ReferringSide%03d"}; + String messageTemplate = (isSrcSide) ? messagesTemplates[1] : messagesTemplates[0]; + int cnt = 1; + for (IMarker marker : markers) { + try { + String message = String.format(messageTemplate, cnt++); + marker.setAttribute(IMarker.MESSAGE, message); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + + private void createMarkerListOrdered() { + orderedMarkers.clear(); + IMarker coordinatorMarker = getCoordinatorDeltaMarker(); + if (coordinatorMarker != null) orderedMarkers.add(coordinatorMarker); + List aliasMarkers = new ArrayList<>(); + List srcSideMarkers = markerIdToMarkers.get(SRC_SIDE_DELTA_MARKER); + if (srcSideMarkers != null) aliasMarkers.addAll(srcSideMarkers); + List dstSideMarkers = markerIdToMarkers.get(DST_SIDE_DELTA_MARKER); + if (dstSideMarkers != null) aliasMarkers.addAll(dstSideMarkers); + Collections.sort(aliasMarkers, new Comparator() { + @Override + public int compare(IMarker o1, IMarker o2) { + TracePoint tp1 = DeltaMarkerManager.getTracePoint(o1); + TracePoint tp2 = DeltaMarkerManager.getTracePoint(o2); + long time1 = tp1.getMethodExecution().getEntryTime(); + long time2 = tp2.getMethodExecution().getEntryTime(); + return (time1 < time2) ? -1 : 1; + } + }); + orderedMarkers.addAll(aliasMarkers); + IMarker bottomMarker = getBottomDeltaMarker(); + if (bottomMarker != null) orderedMarkers.add(bottomMarker); + } + + private void markAndOpenJavaFileForAlias(Alias alias, String message, String markerId) { + IFile file = JavaElementFinder.findIFile(alias.getMethodExecution()); + if (file != null) { + IMarker marker = addMarkerForAlias(alias, file, message, markerId); + JavaEditorOperator.markAndOpenJavaFile(marker); + } + } + + private void markAndOpenJavaFileForCreationPoint(TracePoint creationPoint, Reference reference, String message, String markerId) { + MethodExecution me = creationPoint.getMethodExecution(); + String objectId = reference.getSrcObjectId() + " -> " + reference.getDstObjectId(); + String objectType = reference.getSrcClassName() + " -> " + reference.getDstClassName(); + IFile file = JavaElementFinder.findIFile(me); + if (file != null) { + IMarker marker = addMarkerForCreationPoint(creationPoint, file, message, objectId, objectType, markerId); + JavaEditorOperator.markAndOpenJavaFile(marker); + } + } + + private void markAndOpenJavaFileForCoordinator(MethodExecution methodExecution, String message, String markerId) { + IFile file = JavaElementFinder.findIFile(methodExecution); + if (file != null) { + String objectId = methodExecution.getThisObjId(); + String objectType = methodExecution.getThisClassName(); + IMarker marker = addMarkerForCoordinator(methodExecution, file, message, objectId, objectType, markerId); + JavaEditorOperator.markAndOpenJavaFile(marker); + } + } + + private IMarker addMarkerForAlias(Alias alias, IFile file, String message, String markerId) { + try { + IMarker marker = file.createMarker(markerId); + Map attributes = new HashMap<>(); + setAttributesForAlias(attributes, alias, file, markerId); + if (!(attributes.containsKey(IMarker.LINE_NUMBER))) { +// attributes.put(IMarker.LINE_NUMBER, alias.getLineNo() + " (no marker)"); + attributes.put(IMarker.LINE_NUMBER, alias.getLineNo()); + } + attributes.put(IMarker.MESSAGE, message); + attributes.put(IMarker.TRANSIENT, true); + attributes.put(DELTA_MARKER_ATR_DATA, alias); + attributes.put(DELTA_MARKER_ATR_OBJECT_ID, alias.getObjectId()); + attributes.put(DELTA_MARKER_ATR_OBJECT_TYPE, alias.getObjectType()); + attributes.put(DELTA_MARKER_ATR_ALIAS_TYPE, alias.getAliasType()); + marker.setAttributes(attributes); + addMarker(markerId, marker); + return marker; + } catch (CoreException e) { + e.printStackTrace(); + } + return null; + } + + private IMarker addMarkerForCreationPoint(TracePoint tp, IFile file, String message, String objectId, String objectType, String markerId) { + try { + MethodExecution me = tp.getMethodExecution(); + int lineNo = tp.getStatement().getLineNo(); + IMarker marker = file.createMarker(markerId); + Map attributes = new HashMap<>(); + setAttributesForCreationPoint(attributes, me, file, lineNo, markerId); + if (!(attributes.containsKey(IMarker.LINE_NUMBER))) attributes.put(IMarker.LINE_NUMBER, tp.getStatement().getLineNo()); + attributes.put(IMarker.MESSAGE, message); + attributes.put(IMarker.TRANSIENT, true); + attributes.put(DELTA_MARKER_ATR_DATA, tp); + attributes.put(DELTA_MARKER_ATR_OBJECT_ID, objectId); + attributes.put(DELTA_MARKER_ATR_OBJECT_TYPE, objectType); + marker.setAttributes(attributes); + addMarker(markerId, marker); + return marker; + } catch (CoreException e) { + e.printStackTrace(); + } + return null; + } + + private IMarker addMarkerForCoordinator(MethodExecution me, IFile file, String message, String objectId, String objectType, String markerId) { + try { + IMarker marker = file.createMarker(markerId); + Map attributes = new HashMap<>(); + setAttributesForCoordinator(attributes, me, file); + attributes.put(IMarker.MESSAGE, message); + attributes.put(IMarker.TRANSIENT, true); + attributes.put("data", me); + attributes.put("objectId", objectId); + attributes.put("objectType", objectType); + marker.setAttributes(attributes); + addMarker(markerId, marker); + return marker; + } catch (CoreException e) { + e.printStackTrace(); + } + return null; + } + + private void addMarker(String markerId, IMarker marker) { + List markerList = markerIdToMarkers.get(markerId); + if (markerList == null) { + markerList = new ArrayList(); + markerIdToMarkers.put(markerId, markerList); + } + markerList.add(marker); +// orderedMarkers.add(marker); + } + + private void setAttributesForAlias(final Map attributes, Alias alias, IFile file, String markerId) { + try { + FileEditorInput input = new FileEditorInput(file); + FileDocumentProvider provider = new FileDocumentProvider(); + provider.connect(input); + ASTParser parser = ASTParser.newParser(AST.JLS10); + MethodExecution methodExecution = alias.getMethodExecution(); + IType type = JavaElementFinder.findIType(methodExecution); + IMethod method = JavaElementFinder.findIMethod(methodExecution, type); + if (method != null) { + ICompilationUnit unit = method.getCompilationUnit(); + parser.setSource(unit); + ASTNode node = parser.createAST(new NullProgressMonitor()); + if (node instanceof CompilationUnit) { + CompilationUnit cUnit = (CompilationUnit)node; + ASTVisitor visitor = createVisitor(alias, method, cUnit, attributes); + if (visitor != null) { + node.accept(visitor); + } + } + } + } catch (CoreException e) { + e.printStackTrace(); + } + } + + private ASTVisitor createVisitor(final Alias alias, final IMethod method, final CompilationUnit cUnit, final Map attributes) { + class MyASTVisitor extends ASTVisitor { + public boolean preVisit2(ASTNode node) { + if (attributes.containsKey(IMarker.LINE_NUMBER)) return false; + if (node instanceof org.eclipse.jdt.core.dom.MethodDeclaration) { + try { + // note: �Y�����郁�\�b�h�Ăяo���̏ꍇ�̂ݎq�m�[�h�̒T���𑱍s + String src1 = node.toString().replaceAll(" ", ""); + src1 = src1.substring(0, src1.lastIndexOf("\n")); + String src1Head = src1.substring(0, src1.indexOf(")") + 1); + src1Head = src1Head.replaceAll(" |\t|\r|\n", ""); + src1Head = src1Head.substring(src1Head.indexOf("*/") + 2); // note: �擪�̃R�����g�����O�� + String src2 = method.getSource().replaceAll(" |\t|\r|\n", ""); + return src2.contains(src1Head); + } catch (JavaModelException e) { + e.printStackTrace(); + return false; + } + } + return true; + } + } + ASTVisitor visitor = new MyASTVisitor(); + try { + Statement statement = alias.getOccurrencePoint().getStatement(); + final String source = method.getCompilationUnit().getSource(); + switch (alias.getAliasType()) { + // note: ���\�b�h�ւ̓��� + case FORMAL_PARAMETER: { + final int index = alias.getIndex(); + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.MethodDeclaration node) { + Object obj = node.parameters().get(index); + if (obj instanceof SingleVariableDeclaration) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + SingleVariableDeclaration parameter = (SingleVariableDeclaration)obj; + int start = parameter.getStartPosition(); + int end = start + parameter.getLength(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + } + return false; + } + }; + return visitor; + } + case THIS: { + if (statement instanceof FieldAccess) { + final FieldAccess fa = (FieldAccess)statement; + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.FieldAccess node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.getName().toString(); + String name2 = fa.getFieldName(); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + int start = node.getStartPosition(); + int end = start; + if (source.startsWith("this.", start)) { + end = start + "this".length(); + } + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.ArrayAccess node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + int start = node.getStartPosition(); + int end = start; + if (source.startsWith("this.", start)) { + end = start + "this".length(); + } + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return true; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.SimpleName node) { + // note: ���\�b�h�Ăяo���̃��V�[�o��this�̏ꍇ + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + if (!(node.getParent() instanceof org.eclipse.jdt.core.dom.MethodInvocation)) return true; + String name1 = node.toString(); + String name2 = fa.getFieldName(); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + int start = node.getStartPosition(); + int end = start; + int index = node.toString().indexOf("this."); + if (index != -1) { + start += index; + end = start + "this".length(); + } + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { + // note: �R���X�g���N�^�Ăяo���̈�����this������ꍇ + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.toString(); + name1 = name1.substring(name1.indexOf("(")); + name1 = name1.replaceAll("<.*>", ""); + String name2 = fa.getFieldName(); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.contains(name2))) return true; + int start = node.getStartPosition(); + int end = start; + int index = node.toString().indexOf("this"); + if (index != -1) { + start += index; + end = start + "this".length(); + } + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.ReturnStatement node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + int start = node.getStartPosition(); + int end = start; + int index = node.toString().indexOf("this"); + if (index != -1) { + start += index; + end = start + "this".length(); + } + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.IfStatement node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String fieldName = fa.getFieldName(); + fieldName = fieldName.substring(fieldName.lastIndexOf(".") + 1); + int start = node.getStartPosition(); + int end = start; + Expression expression = node.getExpression(); + if (expression != null) { + start = expression.getStartPosition(); + start += expression.toString().indexOf(fieldName); + end = start; + if (source.startsWith("this.", start - "this.".length())) { + start -= "this.".length(); + end = start + "this".length(); + } + } + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + } else if (statement instanceof MethodInvocation) { + final MethodInvocation mi = (MethodInvocation)statement; + final MethodExecution calledMe = mi.getCalledMethodExecution(); + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.MethodInvocation node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.getName().toString() + "("; + String name2 = calledMe.getCallerSideSignature(); + name2 = name2.substring(0, name2.indexOf("(") + 1); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + String receiverName = node.getExpression().toString(); + int start = node.getStartPosition(); + attributes.put(IMarker.CHAR_START, start); + if (source.startsWith("this.", start)) { + attributes.put(IMarker.CHAR_END, start + "this".length()); + } else { + attributes.put(IMarker.CHAR_END, start + receiverName.length()); + } + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.toString(); + name1 = name1.substring("new ".length(), name1.indexOf("(") + 1); + name1 = name1.replaceAll("<.*>", ""); + String name2 = calledMe.getCallerSideSignature(); + name2 = name2.substring(0, name2.indexOf("(") + 1); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + int start = node.getStartPosition(); + int end = start; // note: �R���X�g���N�^�Ăяo���ɑΉ�����this�̓R�[�h���ɂ͏o�Ă��Ȃ����ߒ���0�̃}�[�J�[�ɂ��� + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + } + return visitor; + } + case METHOD_INVOCATION: { + if (statement instanceof MethodInvocation) { + final MethodInvocation mi = (MethodInvocation)statement; + final MethodExecution calledMe = mi.getCalledMethodExecution(); + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.MethodInvocation node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.getName().toString() + "("; + String name2 = calledMe.getCallerSideSignature(); + name2 = name2.substring(0, name2.indexOf("(") + 1); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + Expression expression = node.getExpression(); + String receiverName = ""; + if (expression != null) { + receiverName = expression.toString(); + } + int start = node.getStartPosition(); + if (source.startsWith("this.", start)) { + start += ("this." + receiverName + ".").length(); + } else if (source.startsWith("super.", start)) { + start += ("super." + receiverName + ".").length(); + } else if (!(receiverName.isEmpty())) { + start += (receiverName + ".").length(); + } + int end = node.getStartPosition() + node.getLength(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.toString(); + name1 = name1.substring("new ".length(), name1.indexOf("(") + 1); + name1 = name1.replaceAll("<.*>", ""); + String name2 = calledMe.getCallerSideSignature(); + name2 = name2.substring(name2.lastIndexOf(".") + 1, name2.indexOf("(") + 1); + if (!(name1.equals(name2))) return true; + int start = node.getStartPosition(); + int end = start + node.getLength(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + } + return visitor; + } + case CONSTRACTOR_INVOCATION: { + if (statement instanceof MethodInvocation) { + final MethodInvocation mi = (MethodInvocation)statement; + final MethodExecution calledMe = mi.getCalledMethodExecution(); + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.toString(); + name1 = name1.substring("new ".length(), name1.indexOf("(") + 1); + name1 = name1.replaceAll("<.*>", ""); + String name2 = calledMe.getCallerSideSignature(); + name2 = name2.substring(0, name2.indexOf("(") + 1); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + int start = node.getStartPosition(); + int end = start + node.getLength(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + } + return visitor; + } + // note: �ǐՃI�u�W�F�N�g�̐؂�ւ� + case FIELD: { + if (statement instanceof FieldAccess) { + final FieldAccess fa = (FieldAccess)statement; + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.FieldAccess node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.getName().toString(); + String name2 = fa.getFieldName(); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + int start = node.getStartPosition(); + int end = start + node.getLength(); + if (source.startsWith("this.", start)) { + attributes.put(IMarker.CHAR_START, start + "this.".length()); + } else { + attributes.put(IMarker.CHAR_START, start); + } + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.ArrayAccess node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + int start = node.getStartPosition(); + int end = start + node.getArray().toString().length(); + if (source.startsWith("this.", start)) { + attributes.put(IMarker.CHAR_START, start + "this.".length()); + } else { + attributes.put(IMarker.CHAR_START, start); + } + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.SimpleName node) { + // note: ���\�b�h�Ăяo���̃��V�[�o���t�B�[���h�̏ꍇ�̓t�B�[���h�A�N�Z�X�̃m�[�h���Ɨ��Ȃ�������ɂ���Œʂ� + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + if (!(node.getParent() instanceof org.eclipse.jdt.core.dom.MethodInvocation)) return true; + String name1 = node.toString(); + String name2 = fa.getFieldName(); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + int start = node.getStartPosition(); + int end = start + node.getLength(); + if (source.startsWith("this.", start)) { + attributes.put(IMarker.CHAR_START, start + "this.".length()); + } else { + attributes.put(IMarker.CHAR_START, start); + } + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.ClassInstanceCreation node) { + // note: �R���X�g���N�^�Ăяo���̈����Ƀt�B�[���h������ꍇ + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.toString(); + name1 = name1.substring(name1.indexOf("(")); + name1 = name1.replaceAll("<.*>", ""); + String name2 = fa.getFieldName(); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.contains(name2))) return true; + int start = node.getStartPosition(); + start += (node.toString().indexOf("(") + name1.indexOf(name2)); + int end = start + name2.length(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.ReturnStatement node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String fieldName = fa.getFieldName(); + fieldName = fieldName.substring(fieldName.lastIndexOf(".") + 1); + int start = node.getStartPosition(); + start += node.toString().indexOf(fieldName); + int end = start + fieldName.length(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.IfStatement node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String fieldName = fa.getFieldName(); + fieldName = fieldName.substring(fieldName.lastIndexOf(".") + 1); + int start = node.getStartPosition(); + int end = start + node.getLength(); + Expression expression = node.getExpression(); + if (expression != null) { + start = expression.getStartPosition(); + start += expression.toString().indexOf(fieldName); + end = start + fieldName.length(); + } + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + } + return visitor; + } + case CONTAINER: { + if (statement instanceof FieldAccess) { + final FieldAccess fa = (FieldAccess)statement; + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.QualifiedName node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.getName().toString(); + String name2 = fa.getFieldName(); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + int start = node.getStartPosition(); + int end = start + node.getLength(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + } + return visitor; + } + case ARRAY_ELEMENT: { + // note: �z��̃Z�b�g�ƃQ�b�g�̃g���[�X�ɂ͍s�ԍ���z�񖼂��L�^����Ă��Ȃ� + if (statement instanceof ArrayAccess) { + final ArrayAccess aa = (ArrayAccess)statement; + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.ArrayAccess node) { + int index = Integer.parseInt(node.getIndex().toString()); + if (index != aa.getIndex()) return true; + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + int start = node.getStartPosition(); + int end = start + node.getLength(); + if (source.startsWith("this.", start)) { + attributes.put(IMarker.CHAR_START, start + "this.".length()); + } else { + attributes.put(IMarker.CHAR_START, start); + } + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + } + return visitor; + } + case ARRAY: { + // note: �z��̃Z�b�g�ƃQ�b�g�̃g���[�X�ɂ͍s�ԍ���z�񖼂��L�^����Ă��Ȃ� + if (statement instanceof ArrayAccess) { + final ArrayAccess aa = (ArrayAccess)statement; + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.ArrayAccess node) { + int index = Integer.parseInt(node.getIndex().toString()); + if (index != aa.getIndex()) return true; + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + int start = node.getStartPosition(); + int end = start + node.getArray().toString().length(); + if (source.startsWith("this.", start)) { + attributes.put(IMarker.CHAR_START, start + "this.".length()); + } else { + attributes.put(IMarker.CHAR_START, start); + } + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + } + return visitor; + } + case ARRAY_CREATE: { + if (statement instanceof ArrayCreate) { + final ArrayCreate ac = (ArrayCreate)statement; + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.ArrayCreation node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != ac.getLineNo()) return true; + int start = node.getStartPosition(); + int end = start + node.getLength(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + } + return visitor; + } + // note: ���\�b�h����̏o�� + case ACTUAL_ARGUMENT: { + if (statement instanceof MethodInvocation) { + final MethodInvocation mi = (MethodInvocation)statement; + final MethodExecution calledMe = mi.getCalledMethodExecution(); + final int index = alias.getIndex(); + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.MethodInvocation node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.getName().toString(); + String name2 = calledMe.getCallerSideSignature(); + name2 = name2.substring(0, name2.indexOf("(")); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + Object obj = node.arguments().get(index); + if (obj instanceof Expression) { + Expression argument = (Expression)obj; + int start = argument.getStartPosition(); + int end = start + argument.getLength(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + } + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.SuperMethodInvocation node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.getName().toString(); + String name2 = calledMe.getCallerSideSignature(); + name2 = name2.substring(0, name2.indexOf("(")); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + Object obj = node.arguments().get(index); + if (obj instanceof Expression) { + Expression argument = (Expression)obj; + int start = argument.getStartPosition(); + int end = start + argument.getLength(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + } + return false; + } + }; + } + return visitor; + } + case RECEIVER: { + if (statement instanceof MethodInvocation) { + final MethodInvocation mi = (MethodInvocation)statement; + final MethodExecution calledMe = mi.getCalledMethodExecution(); + visitor = new MyASTVisitor() { + @Override + public boolean visit(org.eclipse.jdt.core.dom.MethodInvocation node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.getName().toString(); + String name2 = calledMe.getCallerSideSignature(); + name2 = name2.substring(0, name2.indexOf("(")); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + int start = node.getStartPosition(); + int end = start; + Expression expression = node.getExpression(); // note: ���\�b�h�Ăяo���̃��V�[�o�����擾 + if (expression != null) { + String receiverName = expression.toString(); // note: ���\�b�h�Ăяo���̃��V�[�o���܂� + end = start + receiverName.length(); + } + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + @Override + public boolean visit(org.eclipse.jdt.core.dom.SuperMethodInvocation node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + if (lineNo != alias.getLineNo()) return true; + String name1 = node.getName().toString(); + String name2 = calledMe.getCallerSideSignature(); + name2 = name2.substring(0, name2.indexOf("(")); + name2 = name2.substring(name2.lastIndexOf(".") + 1); + if (!(name1.equals(name2))) return true; + int start = node.getStartPosition(); + int end = start + "super".length(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + } + return visitor; + } + case RETURN_VALUE: + // note: �ǂ��Ń��^�[���������̏��(�s�ԍ���)���g���[�X�ɂ͋L�^����Ă��Ȃ� + visitor = new MyASTVisitor(){ + public boolean visit(org.eclipse.jdt.core.dom.ReturnStatement node) { + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + int aliasLineNo = alias.getLineNo(); + if (lineNo < aliasLineNo) return true; // ���ۂɃ��^�[�������ꏊ�̒��O�ɂ���ŏI�X�e�[�g�����g�����O�̃��^�[���͔�΂� + int start = node.getStartPosition(); + int end = start + node.getLength(); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + return false; + } + }; + return visitor; + } + } catch (JavaModelException e) { + e.printStackTrace(); + } + return visitor; + } + + private void setAttributesForCoordinator(final Map attributes, MethodExecution methodExecution, IFile file) { + // note: ���\�b�h�V�O�l�`�����n�C���C�g + IType type = JavaElementFinder.findIType(methodExecution); + final IMethod method = JavaElementFinder.findIMethod(methodExecution, type); + if (method == null) return; + ASTParser parser = ASTParser.newParser(AST.JLS10); + ICompilationUnit unit = method.getCompilationUnit(); + parser.setSource(unit); + ASTNode node = parser.createAST(new NullProgressMonitor()); + if (node instanceof CompilationUnit) { + final CompilationUnit cUnit = (CompilationUnit)node; + node.accept(new ASTVisitor() { + @Override + public boolean visit(MethodDeclaration node) { + try { + if (attributes.containsKey(IMarker.LINE_NUMBER)) return false; + String src1 = node.toString().replaceAll(" ", ""); + src1 = src1.substring(0, src1.lastIndexOf("\n")); + String src1Head = src1.substring(0, src1.indexOf(")") + 1); + String src2 = method.getSource().replaceAll(" |\t|\r|\n", ""); + if (!(src2.contains(src1Head))) return false; + int start = node.getStartPosition(); + int end = start + node.toString().indexOf(")") + 1; + Javadoc javadoc = node.getJavadoc(); + if (javadoc != null) { + start += javadoc.getLength(); + start += 5; // note: node.toString()�Ǝ��ۂ̃R�[�h�̃X�y�[�X���̍��������l�߂鉼���� + String tmp = node.toString().replace(javadoc.toString(), ""); + end = start + tmp.indexOf(")") + 1; + } + int lineNo = cUnit.getLineNumber(node.getStartPosition()); + attributes.put(IMarker.CHAR_START, start); + attributes.put(IMarker.CHAR_END, end); + attributes.put(IMarker.LINE_NUMBER, lineNo); + } catch (JavaModelException e) { + e.printStackTrace(); + } + return false; + } + }); + } + } + + private void setAttributesForCreationPoint(final Map attributes, MethodExecution methodExecution, IFile file, int lineNo, String markerId) { + try { + FileEditorInput input = new FileEditorInput(file); + FileDocumentProvider provider = new FileDocumentProvider(); + provider.connect(input); + IDocument document = provider.getDocument(input); + IRegion lineRegion = document.getLineInformation(lineNo - 1); + attributes.put(IMarker.CHAR_START, lineRegion.getOffset()); + attributes.put(IMarker.CHAR_END, lineRegion.getOffset() + lineRegion.getLength()); + attributes.put(IMarker.LINE_NUMBER, lineNo); + } catch (CoreException | BadLocationException e) { + e.printStackTrace(); + } + } + + private void deleteMarkers(List markerList) { + for (IMarker marker : markerList) { + try { + marker.delete(); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + + public void clearAllMarkers() { + for (List markerList: markerIdToMarkers.values()) { + deleteMarkers(markerList); + } + markerIdToMarkers.clear(); + orderedMarkers.clear(); + } +}