diff options
6 files changed, 95 insertions, 49 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/SourceRevealer.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/SourceRevealer.java index 0283b87..a42d024 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/SourceRevealer.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/SourceRevealer.java @@ -33,7 +33,11 @@ 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.ui.IPerspectiveRegistry; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.WorkbenchException; import org.eclipse.ui.ide.IDE; /** @@ -52,14 +56,14 @@ public class SourceRevealer implements ISourceRevealer { } @Override - public boolean revealLine(String fileName, int lineNumber) { + public boolean revealLine(String fileName, int lineNumber, String perspective) { SearchEngine se = new SearchEngine(); SearchPattern searchPattern = SearchPattern.createPattern( fileName, IJavaSearchConstants.CLASS, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); - LineSearchRequestor requestor = new LineSearchRequestor(lineNumber); + LineSearchRequestor requestor = new LineSearchRequestor(lineNumber, perspective); try { se.search(searchPattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, @@ -75,14 +79,14 @@ public class SourceRevealer implements ISourceRevealer { } @Override - public boolean revealMethod(String fqmn) { + public boolean revealMethod(String fqmn, String perspective) { SearchEngine se = new SearchEngine(); SearchPattern searchPattern = SearchPattern.createPattern( fqmn, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); - MethodSearchRequestor requestor = new MethodSearchRequestor(); + MethodSearchRequestor requestor = new MethodSearchRequestor(perspective); try { se.search(searchPattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, @@ -100,9 +104,11 @@ public class SourceRevealer implements ISourceRevealer { private static class LineSearchRequestor extends SearchRequestor { private boolean mFoundMatch = false; private int mLineNumber; + private final String mPerspective; - public LineSearchRequestor(int lineNumber) { + public LineSearchRequestor(int lineNumber, String perspective) { mLineNumber = lineNumber; + mPerspective = perspective; } public boolean didMatch() { @@ -112,6 +118,10 @@ public class SourceRevealer implements ISourceRevealer { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getResource() instanceof IFile && !mFoundMatch) { + if (mPerspective != null) { + SourceRevealer.switchToPerspective(mPerspective); + } + IFile matchedFile = (IFile) match.getResource(); IMarker marker = matchedFile.createMarker(IMarker.TEXT); marker.setAttribute(IMarker.LINE_NUMBER, mLineNumber); @@ -126,6 +136,11 @@ public class SourceRevealer implements ISourceRevealer { private static class MethodSearchRequestor extends SearchRequestor { private boolean mFoundMatch = false; + private final String mPerspective; + + public MethodSearchRequestor(String perspective) { + mPerspective = perspective; + } public boolean didMatch() { return mFoundMatch; @@ -135,10 +150,29 @@ public class SourceRevealer implements ISourceRevealer { public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IMethod && !mFoundMatch) { + if (mPerspective != null) { + SourceRevealer.switchToPerspective(mPerspective); + } + IMethod method = (IMethod) element; JavaUI.openInEditor(method); mFoundMatch = true; } } } + + public static void switchToPerspective(String perspectiveId) { + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); + IPerspectiveRegistry perspectiveRegistry = workbench.getPerspectiveRegistry(); + if (perspectiveId != null + && perspectiveId.length() > 0 + && perspectiveRegistry.findPerspectiveWithId(perspectiveId) != null) { + try { + workbench.showPerspective(perspectiveId, window); + } catch (WorkbenchException e) { + AdtPlugin.printErrorToConsole(e.getMessage()); + } + } + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/ISourceRevealer.java b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/ISourceRevealer.java index 7e88d21..8c5971f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/ISourceRevealer.java +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/ISourceRevealer.java @@ -32,14 +32,18 @@ public interface ISourceRevealer { /** * Reveal a particular line given the file name and line number. + * @param perspective If not null, switch to this perspective before + * revealing the source * @return true if the source was revealed. */ - boolean revealLine(String fileName, int lineNumber); + boolean revealLine(String fileName, int lineNumber, String perspective); /** * Reveal a particular Java method. * @param fqmn fully qualified method name + * @param perspective If not null, switch to this perspective before + * revealing the source * @return true if the source was revealed. */ - boolean revealMethod(String fqmn); + boolean revealMethod(String fqmn, String perspective); } diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/JavaSourceRevealer.java b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/JavaSourceRevealer.java index a756edc..d0d582c 100644 --- a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/JavaSourceRevealer.java +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/JavaSourceRevealer.java @@ -66,10 +66,10 @@ public class JavaSourceRevealer { return false; } - public static boolean revealLine(String fileName, int lineNumber) { + public static boolean revealLine(String fileName, int lineNumber, String perspective) { for (ISourceRevealer revealer : sSourceRevealers) { try { - if (revealer.revealLine(fileName, lineNumber)) { + if (revealer.revealLine(fileName, lineNumber, perspective)) { return true; } } catch (Throwable t) { @@ -80,10 +80,10 @@ public class JavaSourceRevealer { return false; } - public static boolean revealMethod(String fqmn) { + public static boolean revealMethod(String fqmn, String perspective) { for (ISourceRevealer revealer : sSourceRevealers) { try { - if (revealer.revealMethod(fqmn)) { + if (revealer.revealMethod(fqmn, perspective)) { return true; } } catch (Throwable t) { 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 878d0b6..9b917c2 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 @@ -112,46 +112,22 @@ public class LogCatView extends SelectionDependentViewPart { IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore(); String jumpToLocation = store.getString(PreferenceInitializer.ATTR_LOGCAT_GOTO_PROBLEM); - boolean revealed = false; + String perspectiveId = null; + if (store.getBoolean(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE)) { + perspectiveId = store.getString(PreferenceInitializer.ATTR_PERSPECTIVE_ID); + } + + if (jumpToLocation.equals(CHOICE_ERROR_LINE)) { String fileName = mStackTraceParser.getFileName(msg); int lineNumber = mStackTraceParser.getLineNumber(msg); - revealed = JavaSourceRevealer.revealLine(fileName, lineNumber); + JavaSourceRevealer.revealLine(fileName, lineNumber, perspectiveId); } else { String methodName = mStackTraceParser.getMethodName(msg); - revealed = JavaSourceRevealer.revealMethod(methodName); - } - - if (revealed) { - switchPerspective(); + JavaSourceRevealer.revealMethod(methodName, perspectiveId); } } - /** - * 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); - } - } - } - } - public void selectTransientAppFilter(String appName) { mLogCatPanel.selectTransientAppFilter(appName); } diff --git a/eclipse/plugins/com.android.ide.eclipse.pdt/src/com/android/ide/eclipse/pdt/internal/SourceRevealer.java b/eclipse/plugins/com.android.ide.eclipse.pdt/src/com/android/ide/eclipse/pdt/internal/SourceRevealer.java index 159e89f..84e6ce4 100644 --- a/eclipse/plugins/com.android.ide.eclipse.pdt/src/com/android/ide/eclipse/pdt/internal/SourceRevealer.java +++ b/eclipse/plugins/com.android.ide.eclipse.pdt/src/com/android/ide/eclipse/pdt/internal/SourceRevealer.java @@ -41,11 +41,13 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IPerspectiveRegistry; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.WorkbenchException; import org.eclipse.ui.ide.IDE; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; @@ -115,14 +117,14 @@ public class SourceRevealer extends DevTreeProjectProvider implements ISourceRev } @Override - public boolean revealLine(String fileName, int lineNumber) { + public boolean revealLine(String fileName, int lineNumber, String perspective) { SearchEngine se = new SearchEngine(); SearchPattern searchPattern = SearchPattern.createPattern( fileName, IJavaSearchConstants.CLASS, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); - LineSearchRequestor requestor = new LineSearchRequestor(lineNumber); + LineSearchRequestor requestor = new LineSearchRequestor(lineNumber, perspective); try { se.search(searchPattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, @@ -137,14 +139,14 @@ public class SourceRevealer extends DevTreeProjectProvider implements ISourceRev } @Override - public boolean revealMethod(String fqmn) { + public boolean revealMethod(String fqmn, String perspective) { SearchEngine se = new SearchEngine(); SearchPattern searchPattern = SearchPattern.createPattern( fqmn, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); - MethodSearchRequestor requestor = new MethodSearchRequestor(); + MethodSearchRequestor requestor = new MethodSearchRequestor(perspective); try { se.search(searchPattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, @@ -161,9 +163,11 @@ public class SourceRevealer extends DevTreeProjectProvider implements ISourceRev private static class LineSearchRequestor extends SearchRequestor { private boolean mFoundMatch = false; private int mLineNumber; + private final String mPerspective; - public LineSearchRequestor(int lineNumber) { + public LineSearchRequestor(int lineNumber, String perspective) { mLineNumber = lineNumber; + mPerspective = perspective; } public boolean didMatch() { @@ -173,6 +177,10 @@ public class SourceRevealer extends DevTreeProjectProvider implements ISourceRev @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getResource() instanceof IFile && !mFoundMatch) { + if (mPerspective != null) { + SourceRevealer.switchToPerspective(mPerspective); + } + IFile matchedFile = (IFile) match.getResource(); IMarker marker = matchedFile.createMarker(IMarker.TEXT); marker.setAttribute(IMarker.LINE_NUMBER, mLineNumber); @@ -187,6 +195,11 @@ public class SourceRevealer extends DevTreeProjectProvider implements ISourceRev private static class MethodSearchRequestor extends SearchRequestor { private boolean mFoundMatch = false; + private final String mPerspective; + + public MethodSearchRequestor(String perspective) { + mPerspective = perspective; + } public boolean didMatch() { return mFoundMatch; @@ -196,6 +209,10 @@ public class SourceRevealer extends DevTreeProjectProvider implements ISourceRev public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IMethod && !mFoundMatch) { + if (mPerspective != null) { + SourceRevealer.switchToPerspective(mPerspective); + } + IMethod method = (IMethod) element; JavaUI.openInEditor(method); mFoundMatch = true; @@ -203,4 +220,19 @@ public class SourceRevealer extends DevTreeProjectProvider implements ISourceRev } } + public static void switchToPerspective(String perspectiveId) { + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); + IPerspectiveRegistry perspectiveRegistry = workbench.getPerspectiveRegistry(); + if (perspectiveId != null + && perspectiveId.length() > 0 + && perspectiveRegistry.findPerspectiveWithId(perspectiveId) != null) { + try { + workbench.showPerspective(perspectiveId, window); + } catch (WorkbenchException e) { + // ignore exception, perspective won't be switched + } + } + } + } 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 449faec..09497e2 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 @@ -311,6 +311,6 @@ public class TraceviewEditor extends EditorPart implements MethodHandler { String className = method.getClassName().replaceAll("/", "."); //$NON-NLS-1$ //$NON-NLS-2$ String fqmn = className + "." + methodName; //$NON-NLS-1$ - JavaSourceRevealer.revealMethod(fqmn); + JavaSourceRevealer.revealMethod(fqmn, null); } } |