aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins/com.android.ide.eclipse.ddms
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2011-08-16 17:33:17 -0700
committerSiva Velusamy <vsiva@google.com>2011-08-17 11:20:12 -0700
commit50192fe103eacf358a399358f9945944fc142e44 (patch)
tree269fbdb36dfa362201570682a3c77eb51eeed11c /eclipse/plugins/com.android.ide.eclipse.ddms
parent4106ac0477c4bfe2bed77e4709afe2f611bf1916 (diff)
downloadsdk-50192fe103eacf358a399358f9945944fc142e44.zip
sdk-50192fe103eacf358a399358f9945944fc142e44.tar.gz
sdk-50192fe103eacf358a399358f9945944fc142e44.tar.bz2
Goto source when user double clicks on stack trace.
Change-Id: Ia2693424f0106fb3aa1724c211a8e1273f3a0c28
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.ddms')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/LogCatView.java169
1 files changed, 169 insertions, 0 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/LogCatView.java b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/LogCatView.java
index 9000cad..1f758bb 100644
--- a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/LogCatView.java
+++ b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/views/LogCatView.java
@@ -15,19 +15,50 @@
*/
package com.android.ide.eclipse.ddms.views;
+import com.android.ddmuilib.logcat.ILogCatMessageSelectionListener;
+import com.android.ddmuilib.logcat.LogCatMessage;
import com.android.ddmuilib.logcat.LogCatPanel;
import com.android.ddmuilib.logcat.LogCatReceiver;
+import com.android.ddmuilib.logcat.LogCatStackTraceParser;
import com.android.ide.eclipse.ddms.DdmsPlugin;
+import com.android.ide.eclipse.ddms.preferences.PreferenceInitializer;
+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.core.runtime.Status;
+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.jface.preference.IPreferenceStore;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IPerspectiveRegistry;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.ide.IDE;
+
+import java.util.HashMap;
+import java.util.Map;
public class LogCatView extends SelectionDependentViewPart {
/** LogCatView ID as defined in plugin.xml. */
public static final String ID = "com.android.ide.eclipse.ddms.views.LogCatView"; //$NON-NLS-1$
+ /** Constant indicating that double clicking on a stack trace should
+ * open the method declaration. */
public static final String CHOICE_METHOD_DECLARATION =
DdmsPlugin.PLUGIN_ID + ".logcat.MethodDeclaration"; //$NON-NLS-1$
+
+ /** Constant indicating that double clicking on a stack trace should
+ * open the line at which error occurred. */
public static final String CHOICE_ERROR_LINE =
DdmsPlugin.PLUGIN_ID + ".logcat.ErrorLine"; //$NON-NLS-1$
@@ -39,6 +70,7 @@ public class LogCatView extends SelectionDependentViewPart {
"org.eclipse.jdt.ui.JavaPerspective"; //$NON-NLS-1$
private LogCatPanel mLogCatPanel;
+ private LogCatStackTraceParser mStackTraceParser = new LogCatStackTraceParser();
@Override
public void createPartControl(Composite parent) {
@@ -48,9 +80,146 @@ public class LogCatView extends SelectionDependentViewPart {
DdmsPlugin.getDefault().getPreferenceStore());
mLogCatPanel.createPanel(parent);
setSelectionDependentPanel(mLogCatPanel);
+
+ mLogCatPanel.addLogCatMessageSelectionListener(new ILogCatMessageSelectionListener() {
+ public void messageDoubleClicked(LogCatMessage m) {
+ onDoubleClick(m);
+ }
+ });
}
@Override
public void setFocus() {
}
+
+ /**
+ * This class defines what to do with the search match returned by a
+ * double-click or by the Go to Problem action.
+ */
+ private class LogCatViewSearchRequestor extends SearchRequestor {
+ private boolean mFoundFirstMatch = false;
+ private String mChoice;
+ private int mLineNumber;
+
+ public LogCatViewSearchRequestor(String choice, int lineNumber) {
+ super();
+ mChoice = choice;
+ mLineNumber = lineNumber;
+ }
+
+ IMarker createMarkerFromSearchMatch(IFile file, SearchMatch match) {
+ IMarker marker = null;
+ try {
+ if (CHOICE_METHOD_DECLARATION.equals(mChoice)) {
+ Map<String, Object> attrs = new HashMap<String, Object>();
+ attrs.put(IMarker.CHAR_START, Integer.valueOf(match.getOffset()));
+ attrs.put(IMarker.CHAR_END, Integer.valueOf(match.getOffset()
+ + match.getLength()));
+ marker = file.createMarker(IMarker.TEXT);
+ marker.setAttributes(attrs);
+ } else if (CHOICE_ERROR_LINE.equals(mChoice)) {
+ marker = file.createMarker(IMarker.TEXT);
+ marker.setAttribute(IMarker.LINE_NUMBER, mLineNumber);
+ }
+ } catch (CoreException e) {
+ Status s = new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID, e.getMessage(), e);
+ DdmsPlugin.getDefault().getLog().log(s);
+ }
+ return marker;
+ }
+
+ @Override
+ public void acceptSearchMatch(SearchMatch match) throws CoreException {
+ if (match.getResource() instanceof IFile && !mFoundFirstMatch) {
+ mFoundFirstMatch = true;
+ IFile matchedFile = (IFile) match.getResource();
+ IMarker marker = createMarkerFromSearchMatch(matchedFile, match);
+ // There should only be one exact match,
+ // so we go immediately to that one.
+ if (marker != null) {
+ switchPerspective();
+ showMarker(marker);
+ }
+ }
+ }
+ }
+
+ /**
+ * Switch to perspective specified by user when opening a source file.
+ * User preferences control whether the perspective should be switched,
+ * and if so, what the target perspective is.
+ */
+ private void switchPerspective() {
+ IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
+ if (store.getBoolean(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE)) {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ IPerspectiveRegistry perspectiveRegistry = workbench.getPerspectiveRegistry();
+ String perspectiveId = store.getString(PreferenceInitializer.ATTR_PERSPECTIVE_ID);
+ if (perspectiveId != null
+ && perspectiveId.length() > 0
+ && perspectiveRegistry.findPerspectiveWithId(perspectiveId) != null) {
+ try {
+ workbench.showPerspective(perspectiveId, window);
+ } catch (WorkbenchException e) {
+ Status s = new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID, e.getMessage(), e);
+ DdmsPlugin.getDefault().getLog().log(s);
+ }
+ }
+ }
+ }
+
+ private void showMarker(IMarker marker) {
+ try {
+ IWorkbenchPage page = getViewSite().getWorkbenchWindow()
+ .getActivePage();
+ if (page != null) {
+ IDE.openEditor(page, marker);
+ marker.delete();
+ }
+ } catch (CoreException e) {
+ Status s = new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID, e.getMessage(), e);
+ DdmsPlugin.getDefault().getLog().log(s);
+ }
+ }
+
+ private void onDoubleClick(LogCatMessage m) {
+ String msg = m.getMessage();
+ if (!mStackTraceParser.isValidExceptionTrace(msg)) {
+ return;
+ }
+
+ String methodName = mStackTraceParser.getMethodName(msg);
+ String fileName = mStackTraceParser.getFileName(msg);
+ int lineNumber = mStackTraceParser.getLineNumber(msg);
+
+ IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
+ String jumpToLocation = store.getString(PreferenceInitializer.ATTR_LOGCAT_GOTO_PROBLEM);
+
+ String stringPattern = methodName;
+ LogCatViewSearchRequestor requestor =
+ new LogCatViewSearchRequestor(CHOICE_METHOD_DECLARATION, 0);
+ int searchFor = IJavaSearchConstants.METHOD;
+ if (jumpToLocation.equals(CHOICE_ERROR_LINE)) {
+ searchFor = IJavaSearchConstants.CLASS;
+ stringPattern = fileName;
+ requestor = new LogCatViewSearchRequestor(CHOICE_ERROR_LINE, lineNumber);
+ }
+
+ SearchEngine se = new SearchEngine();
+ SearchPattern searchPattern = SearchPattern.createPattern(stringPattern,
+ searchFor,
+ IJavaSearchConstants.DECLARATIONS,
+ SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
+ try {
+ se.search(searchPattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ SearchEngine.createWorkspaceScope(),
+ requestor,
+ new NullProgressMonitor());
+ } catch (CoreException e) {
+ Status s = new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID, e.getMessage(), e);
+ DdmsPlugin.getDefault().getLog().log(s);
+ }
+ }
}