diff options
author | Xavier Ducrohet <xav@android.com> | 2011-02-01 19:47:41 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2011-02-01 21:44:00 -0800 |
commit | 0aea2e8d8ebd3b014322c3031893c4f9179be584 (patch) | |
tree | 8b8b246b95d79df2da45202e84605b05b806d3cc | |
parent | c8596f7a4719c2f6aac3e0aec86676da0cd6bbaa (diff) | |
download | sdk-0aea2e8d8ebd3b014322c3031893c4f9179be584.zip sdk-0aea2e8d8ebd3b014322c3031893c4f9179be584.tar.gz sdk-0aea2e8d8ebd3b014322c3031893c4f9179be584.tar.bz2 |
Add support for CTRL+click on the method in Traceview.
This will open the method declaration in an editor.
Change-Id: I79e160bf565ac563e423132e010b7e51ab531673
5 files changed, 97 insertions, 18 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.traceview/.classpath b/eclipse/plugins/com.android.ide.eclipse.traceview/.classpath index 1df80d6..176babf 100644 --- a/eclipse/plugins/com.android.ide.eclipse.traceview/.classpath +++ b/eclipse/plugins/com.android.ide.eclipse.traceview/.classpath @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> - <classpathentry kind="lib" path="libs/traceview.jar"/> + <classpathentry kind="lib" path="libs/traceview.jar" sourcepath="/traceview"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> diff --git a/eclipse/plugins/com.android.ide.eclipse.traceview/META-INF/MANIFEST.MF b/eclipse/plugins/com.android.ide.eclipse.traceview/META-INF/MANIFEST.MF index 623076a..ab9a5c2 100644 --- a/eclipse/plugins/com.android.ide.eclipse.traceview/META-INF/MANIFEST.MF +++ b/eclipse/plugins/com.android.ide.eclipse.traceview/META-INF/MANIFEST.MF @@ -9,7 +9,9 @@ Require-Bundle: org.eclipse.ui, org.eclipse.ui.ide, com.android.ide.eclipse.ddms;bundle-version="10.0.0", org.eclipse.core.filesystem, - org.eclipse.core.resources + org.eclipse.core.resources, + org.eclipse.jdt.core, + org.eclipse.jdt.ui Bundle-ActivationPolicy: lazy Bundle-ClassPath: ., libs/traceview.jar diff --git a/eclipse/plugins/com.android.ide.eclipse.traceview/src/com/android/ide/eclipse/traceview/editors/TraceviewEditor.java b/eclipse/plugins/com.android.ide.eclipse.traceview/src/com/android/ide/eclipse/traceview/editors/TraceviewEditor.java index c0c0963..161f33b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.traceview/src/com/android/ide/eclipse/traceview/editors/TraceviewEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.traceview/src/com/android/ide/eclipse/traceview/editors/TraceviewEditor.java @@ -17,13 +17,25 @@ package com.android.ide.eclipse.traceview.editors; import com.android.traceview.ColorController; import com.android.traceview.DmTraceReader; +import com.android.traceview.MethodData; import com.android.traceview.ProfileView; import com.android.traceview.SelectionController; import com.android.traceview.TimeLineView; import com.android.traceview.TraceReader; import com.android.traceview.TraceUnits; +import com.android.traceview.ProfileView.MethodHandler; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.search.IJavaSearchConstants; +import org.eclipse.jdt.core.search.SearchEngine; +import org.eclipse.jdt.core.search.SearchMatch; +import org.eclipse.jdt.core.search.SearchParticipant; +import org.eclipse.jdt.core.search.SearchPattern; +import org.eclipse.jdt.core.search.SearchRequestor; +import org.eclipse.jdt.ui.JavaUI; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.graphics.Color; @@ -38,7 +50,7 @@ import org.eclipse.ui.ide.FileStoreEditorInput; import org.eclipse.ui.part.EditorPart; import org.eclipse.ui.part.FileEditorInput; -public class TraceviewEditor extends EditorPart { +public class TraceviewEditor extends EditorPart implements MethodHandler { private Composite mParent; private String mFilename; @@ -122,7 +134,7 @@ public class TraceviewEditor extends EditorPart { new TimeLineView(sashForm1, reader, selectionController); // Create the profile view - new ProfileView(sashForm1, reader, selectionController); + new ProfileView(sashForm1, reader, selectionController).setMethodHandler(this); mParent.layout(); } @@ -132,4 +144,52 @@ public class TraceviewEditor extends EditorPart { mParent.setFocus(); } + private static class TraceSearchRequestor extends SearchRequestor { + private MethodData mMethod; + + public TraceSearchRequestor(MethodData method) { + mMethod = method; + } + + @Override + public void acceptSearchMatch(SearchMatch match) throws CoreException { + Object element = match.getElement(); + if (element instanceof IMethod) { + IMethod method = (IMethod) element; + if (method.getSignature().equals(mMethod.getSignature())) { + JavaUI.openInEditor(method); + } + } + } + } + + // ---- MethodHandler methods + + public void handleMethod(MethodData method) { + // it's a bit complicated to convert the signature we have with what the + // search engine require, so we'll search by name only and test the signature + // when we get the result(s). + String methodName = method.getMethodName(); + String className = method.getClassName().replaceAll("/", "."); //$NON-NLS-1$ //$NON-NLS-21$ + String fqmn = className + "." + methodName; //$NON-NLS-1$ + + try { + SearchEngine se = new SearchEngine(); + se.search(SearchPattern.createPattern( + fqmn, + IJavaSearchConstants.METHOD, + IJavaSearchConstants.DECLARATIONS, + SearchPattern.R_EXACT_MATCH + | SearchPattern.R_CASE_SENSITIVE), + new SearchParticipant[] { SearchEngine .getDefaultSearchParticipant() }, + SearchEngine.createWorkspaceScope(), + new TraceSearchRequestor(method), + new NullProgressMonitor()); + } catch (CoreException e) { + + } + } + + // ----- + } diff --git a/traceview/src/com/android/traceview/MethodData.java b/traceview/src/com/android/traceview/MethodData.java index 0bc9853..d54b72b 100644 --- a/traceview/src/com/android/traceview/MethodData.java +++ b/traceview/src/com/android/traceview/MethodData.java @@ -46,10 +46,10 @@ public class MethodData { private Image mFadedImage; private HashMap<Integer, ProfileData> mParents; private HashMap<Integer, ProfileData> mChildren; - + // The parents of this method when this method was in a recursive call private HashMap<Integer, ProfileData> mRecursiveParents; - + // The children of this method when this method was in a recursive call private HashMap<Integer, ProfileData> mRecursiveChildren; @@ -150,7 +150,7 @@ public class MethodData { mParents); } } - + private HashMap<Integer, ProfileData> updateInclusive(long time, MethodData contextMethod, MethodData elementMethod, boolean elementIsParent, HashMap<Integer, ProfileData> map) { @@ -178,15 +178,15 @@ public class MethodData { ProfileData[] sortedChildren; ProfileData[] sortedRecursiveParents; ProfileData[] sortedRecursiveChildren; - + sortedParents = sortProfileData(mParents); sortedChildren = sortProfileData(mChildren); sortedRecursiveParents = sortProfileData(mRecursiveParents); sortedRecursiveChildren = sortProfileData(mRecursiveChildren); - + // Add "self" time to the top of the sorted children sortedChildren = addSelf(sortedChildren); - + // Create the ProfileNode objects that we need ArrayList<ProfileNode> nodes = new ArrayList<ProfileNode>(); ProfileNode profileNode; @@ -212,7 +212,7 @@ public class MethodData { } mProfileNodes = nodes.toArray(new ProfileNode[nodes.size()]); } - + // Create and return a ProfileData[] array that is a sorted copy // of the given HashMap values. private ProfileData[] sortProfileData(HashMap<Integer, ProfileData> map) { @@ -222,12 +222,12 @@ public class MethodData { // Convert the hash values to an array of ProfileData Collection<ProfileData> values = map.values(); ProfileData[] sorted = values.toArray(new ProfileData[values.size()]); - + // Sort the array by elapsed inclusive time Arrays.sort(sorted, mByElapsedInclusive); return sorted; } - + private ProfileData[] addSelf(ProfileData[] children) { ProfileData[] pdata; if (children == null) { @@ -283,12 +283,16 @@ public class MethodData { return mProfileName; } + public String getSignature() { + return mSignature; + } + public void computeProfileName() { if (mRank == -1) { mProfileName = mName; return; } - + StringBuilder sb = new StringBuilder(); sb.append(mRank); sb.append(" "); //$NON-NLS-1$ diff --git a/traceview/src/com/android/traceview/ProfileView.java b/traceview/src/com/android/traceview/ProfileView.java index 71dedfd..506efca 100644 --- a/traceview/src/com/android/traceview/ProfileView.java +++ b/traceview/src/com/android/traceview/ProfileView.java @@ -16,10 +16,6 @@ package com.android.traceview; -import java.util.ArrayList; -import java.util.Observable; -import java.util.Observer; - import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; @@ -48,6 +44,10 @@ import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.swt.widgets.TreeItem; +import java.util.ArrayList; +import java.util.Observable; +import java.util.Observer; + public class ProfileView extends Composite implements Observer { private TreeViewer mTreeViewer; @@ -57,6 +57,11 @@ public class ProfileView extends Composite implements Observer { private Color mColorNoMatch; private Color mColorMatch; private MethodData mCurrentHighlightedMethod; + private MethodHandler mMethodHandler; + + public interface MethodHandler { + void handleMethod(MethodData method); + } public ProfileView(Composite parent, TraceReader reader, SelectionController selectController) { @@ -224,10 +229,18 @@ public class ProfileView extends Composite implements Observer { ArrayList<Selection> selections = new ArrayList<Selection>(); selections.add(Selection.highlight("MethodData", md)); mSelectionController.change(selections, "ProfileView"); + + if (mMethodHandler != null && (event.stateMask & SWT.MOD1) != 0) { + mMethodHandler.handleMethod(md); + } } }); } + public void setMethodHandler(MethodHandler handler) { + mMethodHandler = handler; + } + private void findName(String query) { MethodData md = mProfileProvider.findMatchingName(query); selectMethod(md); |