summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvaage <vaage@google.com>2021-09-27 15:38:32 -0700
committerAaron Vaage <vaage@google.com>2021-10-04 19:40:17 +0000
commite7ef5306ef9259e15cfef0ed5b3aa077a8d0b2b5 (patch)
tree613a1669fc2f7bdc405eec99cd28badaeca9176e
parentc6ec92e954189513cd0d42f87098dd8c0cfb8187 (diff)
downloadidea-e7ef5306ef9259e15cfef0ed5b3aa077a8d0b2b5.tar.gz
Separate Code Navigation From Navigation Source
With code navigation there are two parts, 1. Determining how/where to navigate to 2. Executing on the navigation This change separates the code navigation code into those two parts (they were combined before), making it possible for one code execution but different navigation sources. Bug: 197112399 Test: Manually test Java code navigation. Change-Id: Ie0e868a3532a960a6c143a7e8ff7d7866836ac07
-rw-r--r--app-inspection/inspectors/backgroundtask/ide/src/com/android/tools/idea/appinspection/inspectors/backgroundtask/ide/IntellijUiComponentsProvider.kt5
-rw-r--r--app-inspection/inspectors/backgroundtask/view/testSrc/com/android/tools/idea/appinspection/inspectors/backgroundtask/view/StubUiComponentsProvider.kt5
-rw-r--r--app-inspection/inspectors/network/ide/src/com/android/tools/idea/appinspection/inspectors/network/ide/DefaultCodeNavigationProvider.kt8
-rw-r--r--app-inspection/inspectors/network/ide/testSrc/com/android/tools/idea/appinspection/inspectors/network/ide/CodeNavigationProviderTest.kt4
-rw-r--r--app-inspection/inspectors/network/model/testSrc/com/android/tools/idea/appinspection/inspectors/network/model/FakeCodeNavigationProvider.kt6
-rw-r--r--codenavigation/src/com/android/tools/idea/codenavigation/CodeNavigator.kt95
-rw-r--r--codenavigation/src/com/android/tools/idea/codenavigation/FakeNavSource.kt (renamed from codenavigation/src/com/android/tools/idea/codenavigation/FakeCodeNavigator.kt)20
-rw-r--r--codenavigation/src/com/android/tools/idea/codenavigation/IntellijNavSource.java (renamed from codenavigation/src/com/android/tools/idea/codenavigation/IntellijCodeNavigator.java)72
-rw-r--r--codenavigation/src/com/android/tools/idea/codenavigation/NavSource.kt30
-rw-r--r--inspectors-common/api-ide/testSrc/com/android/tools/inspectors/common/api/ide/stacktrace/IntelliJStackTraceViewTest.java6
-rw-r--r--profilers-android/src/com/android/tools/idea/profilers/AndroidProfilerToolWindow.java7
-rw-r--r--profilers-android/src/com/android/tools/idea/profilers/IntellijProfilerServices.java11
-rw-r--r--profilers/testSrc/com/android/tools/profilers/FakeIdeProfilerServices.java5
13 files changed, 167 insertions, 107 deletions
diff --git a/app-inspection/inspectors/backgroundtask/ide/src/com/android/tools/idea/appinspection/inspectors/backgroundtask/ide/IntellijUiComponentsProvider.kt b/app-inspection/inspectors/backgroundtask/ide/src/com/android/tools/idea/appinspection/inspectors/backgroundtask/ide/IntellijUiComponentsProvider.kt
index e66b589e8e3..bbd89631628 100644
--- a/app-inspection/inspectors/backgroundtask/ide/src/com/android/tools/idea/appinspection/inspectors/backgroundtask/ide/IntellijUiComponentsProvider.kt
+++ b/app-inspection/inspectors/backgroundtask/ide/src/com/android/tools/idea/appinspection/inspectors/backgroundtask/ide/IntellijUiComponentsProvider.kt
@@ -17,7 +17,7 @@ package com.android.tools.idea.appinspection.inspectors.backgroundtask.ide
import com.android.tools.idea.appinspection.inspectors.backgroundtask.view.UiComponentsProvider
import com.android.tools.idea.codenavigation.CodeNavigator
-import com.android.tools.idea.codenavigation.IntellijCodeNavigator
+import com.android.tools.idea.codenavigation.IntellijNavSource
import com.android.tools.inspectors.common.api.ide.stacktrace.IntelliJStackTraceGroup
import com.android.tools.inspectors.common.api.stacktrace.StackTraceModel
import com.android.tools.inspectors.common.ui.stacktrace.StackTraceView
@@ -32,7 +32,8 @@ class IntellijUiComponentsProvider(private val project: Project) : UiComponentsP
init {
val locator = SymbolFilesLocator(ProjectSymbolSource(project))
val symbolizer = createNativeSymbolizer(locator)
- codeNavigator = IntellijCodeNavigator(project, symbolizer)
+ codeNavigator = CodeNavigator(
+ IntellijNavSource(project, symbolizer), CodeNavigator.applicationExecutor)
}
override fun createStackTraceView(model: StackTraceModel): StackTraceView {
diff --git a/app-inspection/inspectors/backgroundtask/view/testSrc/com/android/tools/idea/appinspection/inspectors/backgroundtask/view/StubUiComponentsProvider.kt b/app-inspection/inspectors/backgroundtask/view/testSrc/com/android/tools/idea/appinspection/inspectors/backgroundtask/view/StubUiComponentsProvider.kt
index 96eb8860aa6..192a9bd3d16 100644
--- a/app-inspection/inspectors/backgroundtask/view/testSrc/com/android/tools/idea/appinspection/inspectors/backgroundtask/view/StubUiComponentsProvider.kt
+++ b/app-inspection/inspectors/backgroundtask/view/testSrc/com/android/tools/idea/appinspection/inspectors/backgroundtask/view/StubUiComponentsProvider.kt
@@ -15,7 +15,8 @@
*/
package com.android.tools.idea.appinspection.inspectors.backgroundtask.view
-import com.android.tools.idea.codenavigation.FakeCodeNavigator
+import com.android.tools.idea.codenavigation.CodeNavigator
+import com.android.tools.idea.codenavigation.FakeNavSource
import com.android.tools.inspectors.common.api.stacktrace.StackTraceModel
import com.android.tools.inspectors.common.ui.stacktrace.StackTraceGroup
import com.android.tools.inspectors.common.ui.stacktrace.StackTraceView
@@ -23,7 +24,7 @@ import javax.swing.JComponent
import javax.swing.JPanel
class StubUiComponentsProvider : UiComponentsProvider {
- override val codeNavigator = FakeCodeNavigator()
+ override val codeNavigator = CodeNavigator(FakeNavSource(), CodeNavigator.testExecutor)
override fun createStackTraceView(model: StackTraceModel): StackTraceView {
return StackTraceGroupStub().createStackView(model)
diff --git a/app-inspection/inspectors/network/ide/src/com/android/tools/idea/appinspection/inspectors/network/ide/DefaultCodeNavigationProvider.kt b/app-inspection/inspectors/network/ide/src/com/android/tools/idea/appinspection/inspectors/network/ide/DefaultCodeNavigationProvider.kt
index d2bf6530c4f..bef6b2a32f1 100644
--- a/app-inspection/inspectors/network/ide/src/com/android/tools/idea/appinspection/inspectors/network/ide/DefaultCodeNavigationProvider.kt
+++ b/app-inspection/inspectors/network/ide/src/com/android/tools/idea/appinspection/inspectors/network/ide/DefaultCodeNavigationProvider.kt
@@ -17,7 +17,8 @@ package com.android.tools.idea.appinspection.inspectors.network.ide
import com.android.tools.idea.appinspection.inspectors.network.model.CodeNavigationProvider
import com.android.tools.idea.codenavigation.CodeNavigator
-import com.android.tools.idea.codenavigation.IntellijCodeNavigator
+import com.android.tools.idea.codenavigation.IntellijNavSource
+import com.android.tools.idea.codenavigation.NavSource
import com.android.tools.nativeSymbolizer.ProjectSymbolSource
import com.android.tools.nativeSymbolizer.SymbolFilesLocator
import com.android.tools.nativeSymbolizer.createNativeSymbolizer
@@ -25,11 +26,12 @@ import com.intellij.openapi.project.Project
/**
* The Android Studio implementation of [CodeNavigationProvider] that provides a single
- * instance of [IntellijCodeNavigator].
+ * instance of [IntellijNavSource].
*/
class DefaultCodeNavigationProvider(project: Project) : CodeNavigationProvider {
private val locator = SymbolFilesLocator(ProjectSymbolSource(project))
private val symbolizer = createNativeSymbolizer(locator)
- override val codeNavigator: CodeNavigator = IntellijCodeNavigator(project, symbolizer)
+ override val codeNavigator: CodeNavigator = CodeNavigator(IntellijNavSource(project, symbolizer),
+ CodeNavigator.applicationExecutor)
} \ No newline at end of file
diff --git a/app-inspection/inspectors/network/ide/testSrc/com/android/tools/idea/appinspection/inspectors/network/ide/CodeNavigationProviderTest.kt b/app-inspection/inspectors/network/ide/testSrc/com/android/tools/idea/appinspection/inspectors/network/ide/CodeNavigationProviderTest.kt
index cc9ed2ca54e..67f3181457b 100644
--- a/app-inspection/inspectors/network/ide/testSrc/com/android/tools/idea/appinspection/inspectors/network/ide/CodeNavigationProviderTest.kt
+++ b/app-inspection/inspectors/network/ide/testSrc/com/android/tools/idea/appinspection/inspectors/network/ide/CodeNavigationProviderTest.kt
@@ -16,7 +16,7 @@
package com.android.tools.idea.appinspection.inspectors.network.ide
import com.android.tools.idea.testing.AndroidProjectRule
-import com.android.tools.idea.codenavigation.IntellijCodeNavigator
+import com.android.tools.idea.codenavigation.IntellijNavSource
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -29,6 +29,6 @@ class CodeNavigationProviderTest {
@Test
fun getCodeNavigator() {
val navigator = DefaultCodeNavigationProvider(projectRule.project).codeNavigator
- assertThat(navigator).isInstanceOf(IntellijCodeNavigator::class.java)
+ assertThat(navigator.mySource).isInstanceOf(IntellijNavSource::class.java)
}
} \ No newline at end of file
diff --git a/app-inspection/inspectors/network/model/testSrc/com/android/tools/idea/appinspection/inspectors/network/model/FakeCodeNavigationProvider.kt b/app-inspection/inspectors/network/model/testSrc/com/android/tools/idea/appinspection/inspectors/network/model/FakeCodeNavigationProvider.kt
index 7387d8c65a3..f0d4a026c73 100644
--- a/app-inspection/inspectors/network/model/testSrc/com/android/tools/idea/appinspection/inspectors/network/model/FakeCodeNavigationProvider.kt
+++ b/app-inspection/inspectors/network/model/testSrc/com/android/tools/idea/appinspection/inspectors/network/model/FakeCodeNavigationProvider.kt
@@ -16,8 +16,10 @@
package com.android.tools.idea.appinspection.inspectors.network.model
import com.android.tools.idea.codenavigation.CodeNavigator
-import com.android.tools.idea.codenavigation.FakeCodeNavigator
+import com.android.tools.idea.codenavigation.FakeNavSource
+import com.android.tools.idea.codenavigation.NavSource
class FakeCodeNavigationProvider : CodeNavigationProvider {
- override val codeNavigator: CodeNavigator = FakeCodeNavigator()
+ override val codeNavigator: CodeNavigator = CodeNavigator(FakeNavSource(),
+ CodeNavigator.testExecutor)
} \ No newline at end of file
diff --git a/codenavigation/src/com/android/tools/idea/codenavigation/CodeNavigator.kt b/codenavigation/src/com/android/tools/idea/codenavigation/CodeNavigator.kt
index 220b8533329..46ca7a110c6 100644
--- a/codenavigation/src/com/android/tools/idea/codenavigation/CodeNavigator.kt
+++ b/codenavigation/src/com/android/tools/idea/codenavigation/CodeNavigator.kt
@@ -15,15 +15,67 @@
*/
package com.android.tools.idea.codenavigation
+import com.google.common.annotations.VisibleForTesting
+import com.intellij.openapi.application.ApplicationManager
+import com.intellij.openapi.application.ReadAction
+import com.intellij.openapi.util.ThrowableComputable
+import com.intellij.pom.Navigatable
import java.util.concurrent.CompletableFuture
+import java.util.concurrent.Future
+import java.util.function.Supplier
/**
- * Base class for a service responsible for handling navigations to target [CodeLocation]s,
- * as well as registering and triggering listeners interested in the event.
+ * Base class for a service responsible for handling navigating to [CodeLocation]s, as well as
+ * registering and triggering listeners interested in the event.
*/
-abstract class CodeNavigator {
+class CodeNavigator (source: NavSource, private val executor: Executor) {
+ /**
+ * Interface for where the [CodeNavigator] should execute actions.
+ */
+ interface Executor {
+ fun onForeground(runnable: Runnable)
+ fun onBackground(runnable: Runnable): Future<*>
+ }
+
+ companion object {
+ /**
+ * An executor to be used when using the code navigator within an application to avoid blocking
+ * the UI thread.
+ */
+ val applicationExecutor = object : Executor {
+ override fun onForeground(runnable: Runnable) {
+ ApplicationManager.getApplication().invokeLater(runnable)
+ }
+
+ override fun onBackground(runnable: Runnable): Future<*> {
+ return ApplicationManager.getApplication().executeOnPooledThread(runnable)
+ }
+ }
+
+ /**
+ * An executor to be used in tests to avoid a dependency on an application existing.
+ */
+ val testExecutor = object : Executor {
+ override fun onForeground(runnable: Runnable) {
+ runnable.run()
+ }
+
+ override fun onBackground(runnable: Runnable): Future<*> {
+ return CompletableFuture.runAsync(runnable)
+ }
+ }
+ }
+
+ @VisibleForTesting val mySource = source
+
private val myListeners = mutableListOf<Listener>()
+ /**
+ * Supplier of the target CPU architecture (e.g. arm64, x86, etc) used to build the process
+ * currently being profiled.
+ */
+ var cpuArchSource: Supplier<String?> = Supplier { null }
+
fun addListener(listener: Listener) {
myListeners.add(listener)
}
@@ -32,14 +84,43 @@ abstract class CodeNavigator {
myListeners.remove(listener)
}
- fun navigate(location: CodeLocation): CompletableFuture<Boolean> {
+ fun navigate(location: CodeLocation): CompletableFuture<Boolean>? {
myListeners.forEach{ it.onNavigated(location) }
- return handleNavigate(location)
+
+ return getNavigatableAsync(location).thenApplyAsync(
+ { nav: Navigatable? ->
+ nav?.navigate(true)
+ nav != null
+ }) { runnable: Runnable? -> executor.onForeground(runnable!!)}
}
- abstract fun isNavigatable(location: CodeLocation): CompletableFuture<Boolean>
+ fun isNavigatable(location: CodeLocation): CompletableFuture<Boolean>? {
+ return getNavigatableAsync(location).thenApply { nav: Navigatable? -> nav != null }
+ }
- protected abstract fun handleNavigate(location: CodeLocation): CompletableFuture<Boolean>
+ /**
+ * Gets the navigatable in another thread, so we don't block the UI while potentially performing
+ * heavy operations, such as searching for the java class/method in the PSI tree or using
+ * llvm-symbolizer to get a native function name.
+ *
+ * Note: due to IntelliJ PSI threading rules, read operations performed on a non-UI thread need
+ * to wrap the action in a ReadAction. Hence all PSI-reading code inside getNavigatable() will
+ * need to wrapped in a ReadAction.
+ *
+ * See http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/general_threading_rules.html
+ */
+ private fun getNavigatableAsync(location: CodeLocation): CompletableFuture<Navigatable?> {
+ return CompletableFuture.supplyAsync(
+ {
+ ReadAction.compute(
+ ThrowableComputable<Navigatable, RuntimeException> { getNavigatable(location) })
+ }
+ ) { runnable: Runnable? -> executor.onBackground(runnable!!) }
+ }
+
+ private fun getNavigatable(location: CodeLocation): Navigatable? {
+ return mySource.lookUp(location, cpuArchSource.get())
+ }
interface Listener {
fun onNavigated(location: CodeLocation)
diff --git a/codenavigation/src/com/android/tools/idea/codenavigation/FakeCodeNavigator.kt b/codenavigation/src/com/android/tools/idea/codenavigation/FakeNavSource.kt
index 23112d4863f..16bee332b6d 100644
--- a/codenavigation/src/com/android/tools/idea/codenavigation/FakeCodeNavigator.kt
+++ b/codenavigation/src/com/android/tools/idea/codenavigation/FakeNavSource.kt
@@ -15,23 +15,13 @@
*/
package com.android.tools.idea.codenavigation
-import java.util.concurrent.CompletableFuture
+import com.intellij.pom.Navigatable
/**
- * A test-only [CodeNavigator] that says every [CodeLocation] is navigable but does nothing when
- * asked to navigate to a [CodeLocation]. If a test actually cares about acting on navigation
- * requests, it should add a listener via [addListener].
+ * A test-only [NavSource] that says that no code location is navigable.
*/
-class FakeCodeNavigator : CodeNavigator() {
- override fun isNavigatable(location: CodeLocation): CompletableFuture<Boolean> {
- return noop()
- }
-
- override fun handleNavigate(location: CodeLocation): CompletableFuture<Boolean> {
- return noop()
- }
-
- private fun noop(): CompletableFuture<Boolean> {
- return CompletableFuture.completedFuture(true)
+class FakeNavSource : NavSource {
+ override fun lookUp(location: CodeLocation, arch: String?): Navigatable? {
+ return null
}
} \ No newline at end of file
diff --git a/codenavigation/src/com/android/tools/idea/codenavigation/IntellijCodeNavigator.java b/codenavigation/src/com/android/tools/idea/codenavigation/IntellijNavSource.java
index b0d1f7a606c..85904ccbc59 100644
--- a/codenavigation/src/com/android/tools/idea/codenavigation/IntellijCodeNavigator.java
+++ b/codenavigation/src/com/android/tools/idea/codenavigation/IntellijNavSource.java
@@ -21,8 +21,6 @@ import com.android.tools.nativeSymbolizer.Symbol;
import com.google.common.base.Strings;
import com.intellij.build.FileNavigatable;
import com.intellij.build.FilePosition;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
@@ -38,21 +36,15 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
- * A {@link CodeNavigator} with logic to jump to code inside of an IntelliJ code editor.
+ * A {@link NavSource} that searches for a navigatble within an IntelliJ project.
*/
-public class IntellijCodeNavigator extends CodeNavigator {
+public class IntellijNavSource implements NavSource {
@NotNull
private final Project myProject;
@NotNull
@@ -60,66 +52,21 @@ public class IntellijCodeNavigator extends CodeNavigator {
@NotNull
private final List<LibraryMapping> myLibraryMappings;
- /**
- * Supplier of the target CPU architecture (e.g. arm64, x86, etc) used to build the process currently being profiled. Can be set by
- * {@link #setCpuAbiArchSupplier(Supplier)}. Although it can't be null, it can return null so the result should be handled accordingly.
- */
- @NotNull private Supplier<String> myCpuAbiArchSupplier;
-
- public IntellijCodeNavigator(@NotNull Project project,
- @NotNull NativeSymbolizer nativeSymbolizer) {
+ public IntellijNavSource(@NotNull Project project,
+ @NotNull NativeSymbolizer nativeSymbolizer) {
myProject = project;
myNativeSymbolizer = nativeSymbolizer;
myLibraryMappings = getLibraryMappings(project);
- myCpuAbiArchSupplier = () -> null;
- }
-
- public void setCpuAbiArchSupplier(@NotNull Supplier<String> cpuAbiArch) {
- myCpuAbiArchSupplier = cpuAbiArch;
}
- /**
- * Fetches the CPU architecture from {@link #myCpuAbiArchSupplier}.
- */
@Nullable
- public String fetchCpuAbiArch() {
- return myCpuAbiArchSupplier.get();
- }
-
@Override
- protected CompletableFuture<@NotNull Boolean> handleNavigate(@NotNull CodeLocation location) {
- return getNavigatableAsync(location).thenApplyAsync(nav -> {
- if (nav != null) {
- nav.navigate(true);
- }
-
- return nav != null;
- }, ApplicationManager.getApplication()::invokeLater);
- }
-
- @Override
- public CompletableFuture<@NotNull Boolean> isNavigatable(@NotNull CodeLocation location) {
- return getNavigatableAsync(location).thenApply(nav -> nav != null);
- }
-
- /**
- * Gets the navigatable in another thread, so we don't block the UI while potentially performing
- * heavy operations, such as searching for the java class/method in the PSI tree or using
- * llvm-symbolizer to get a native function name.
- *
- * Note: due to IntelliJ PSI threading rules, read operations performed on a non-UI thread need
- * to wrap the action in a ReadAction. Hence all PSI-reading code inside getNavigatable() will
- * need to wrapped in a ReadAction.
- *
- * See http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/general_threading_rules.html
- */
- private CompletableFuture<Navigatable> getNavigatableAsync(@NotNull CodeLocation location) {
- return CompletableFuture.supplyAsync(() -> ReadAction.compute(() -> getNavigatable(location)),
- ApplicationManager.getApplication()::executeOnPooledThread);
+ public Navigatable lookUp(@NotNull CodeLocation location, @Nullable String arch) {
+ return getNavigatable(location, arch);
}
@Nullable
- private Navigatable getNavigatable(@NotNull CodeLocation location) {
+ private Navigatable getNavigatable(@NotNull CodeLocation location, @Nullable String arch) {
if (!Strings.isNullOrEmpty(location.getFileName()) &&
location.getLineNumber() != CodeLocation.INVALID_LINE_NUMBER) {
Navigatable navigatable = getExplicitLocationNavigable(location);
@@ -134,7 +81,7 @@ public class IntellijCodeNavigator extends CodeNavigator {
}
if (location.isNativeCode()) {
- return getNativeNavigatable(location);
+ return getNativeNavigatable(location, arch);
}
PsiClass psiClass = ClassUtil.findPsiClassByJVMName(PsiManager.getInstance(myProject), location.getClassName());
@@ -206,8 +153,7 @@ public class IntellijCodeNavigator extends CodeNavigator {
* Attempts to symbolize the code location to find and return the functions's corresponding {@link Navigatable} within the project.
*/
@Nullable
- private Navigatable getNativeNavigatable(@NotNull CodeLocation location) {
- String arch = fetchCpuAbiArch();
+ private Navigatable getNativeNavigatable(@NotNull CodeLocation location, @Nullable String arch) {
if (location.getFileName() == null || arch == null) {
return null;
}
diff --git a/codenavigation/src/com/android/tools/idea/codenavigation/NavSource.kt b/codenavigation/src/com/android/tools/idea/codenavigation/NavSource.kt
new file mode 100644
index 00000000000..1f174c0730d
--- /dev/null
+++ b/codenavigation/src/com/android/tools/idea/codenavigation/NavSource.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tools.idea.codenavigation
+
+import com.intellij.pom.Navigatable
+
+/**
+ * An interface to get a [Navigatable] for a given [CodeLocation] using a specific strategy (e.g.
+ * looking at the APK information).
+ */
+interface NavSource {
+ /**
+ * Gets a [Navigatable] for a [CodeLocation] for a specific architecture. [arch] will be CPU
+ * arch as defined in the [Abi] enum. If no [Navigatable] can be found, null will be returned.
+ */
+ fun lookUp(location: CodeLocation, arch: String?): Navigatable?
+} \ No newline at end of file
diff --git a/inspectors-common/api-ide/testSrc/com/android/tools/inspectors/common/api/ide/stacktrace/IntelliJStackTraceViewTest.java b/inspectors-common/api-ide/testSrc/com/android/tools/inspectors/common/api/ide/stacktrace/IntelliJStackTraceViewTest.java
index ef35dc76397..540c849bce9 100644
--- a/inspectors-common/api-ide/testSrc/com/android/tools/inspectors/common/api/ide/stacktrace/IntelliJStackTraceViewTest.java
+++ b/inspectors-common/api-ide/testSrc/com/android/tools/inspectors/common/api/ide/stacktrace/IntelliJStackTraceViewTest.java
@@ -23,7 +23,8 @@ import com.android.tools.adtui.swing.FakeMouse;
import com.android.tools.adtui.swing.FakeUi;
import com.android.tools.adtui.swing.laf.HeadlessListUI;
import com.android.tools.idea.codenavigation.CodeLocation;
-import com.android.tools.idea.codenavigation.FakeCodeNavigator;
+import com.android.tools.idea.codenavigation.CodeNavigator;
+import com.android.tools.idea.codenavigation.FakeNavSource;
import com.android.tools.inspectors.common.api.stacktrace.CodeElement;
import com.android.tools.inspectors.common.api.stacktrace.StackFrameParser;
import com.android.tools.inspectors.common.api.stacktrace.StackTraceModel;
@@ -71,7 +72,8 @@ public class IntelliJStackTraceViewTest {
private IntelliJStackTraceView myStackView;
public static StackTraceModel createStackTraceModel() {
- return new StackTraceModel(new FakeCodeNavigator());
+ return new StackTraceModel(
+ new CodeNavigator(new FakeNavSource(), CodeNavigator.Companion.getTestExecutor()));
}
public static IntelliJStackTraceView createStackTraceView(Project project, StackTraceModel model) {
diff --git a/profilers-android/src/com/android/tools/idea/profilers/AndroidProfilerToolWindow.java b/profilers-android/src/com/android/tools/idea/profilers/AndroidProfilerToolWindow.java
index 5023e01df4a..086143bdab1 100644
--- a/profilers-android/src/com/android/tools/idea/profilers/AndroidProfilerToolWindow.java
+++ b/profilers-android/src/com/android/tools/idea/profilers/AndroidProfilerToolWindow.java
@@ -20,10 +20,11 @@ import static com.android.tools.profilers.ProfilerFonts.STANDARD_FONT;
import com.android.ddmlib.IDevice;
import com.android.tools.adtui.model.AspectObserver;
+import com.android.tools.idea.codenavigation.CodeNavigator;
import com.android.tools.idea.model.AndroidModuleInfo;
import com.android.tools.idea.transport.TransportService;
import com.android.tools.idea.transport.TransportServiceProxy;
-import com.android.tools.idea.codenavigation.IntellijCodeNavigator;
+import com.android.tools.idea.codenavigation.IntellijNavSource;
import com.android.tools.nativeSymbolizer.ProjectSymbolSource;
import com.android.tools.nativeSymbolizer.SymbolFilesLocator;
import com.android.tools.nativeSymbolizer.SymbolSource;
@@ -291,9 +292,9 @@ public class AndroidProfilerToolWindow implements Disposable {
myWindow = window;
ProfilerClient client = new ProfilerClient(TransportService.CHANNEL_NAME);
myProfilers = new StudioProfilers(client, ideProfilerServices);
- IntellijCodeNavigator navigator = (IntellijCodeNavigator)ideProfilerServices.getCodeNavigator();
+ CodeNavigator navigator = ideProfilerServices.getCodeNavigator();
// CPU ABI architecture, when needed by the code navigator, should be retrieved from StudioProfiler selected session.
- navigator.setCpuAbiArchSupplier(() ->
+ navigator.setCpuArchSource(() ->
myProfilers.getSessionsManager().getSelectedSessionMetaData().getProcessAbi()
);
diff --git a/profilers-android/src/com/android/tools/idea/profilers/IntellijProfilerServices.java b/profilers-android/src/com/android/tools/idea/profilers/IntellijProfilerServices.java
index 4d7beac89bf..8147b34da27 100644
--- a/profilers-android/src/com/android/tools/idea/profilers/IntellijProfilerServices.java
+++ b/profilers-android/src/com/android/tools/idea/profilers/IntellijProfilerServices.java
@@ -28,7 +28,7 @@ import com.android.tools.idea.project.AndroidNotification;
import com.android.tools.idea.run.AndroidRunConfigurationBase;
import com.android.tools.idea.run.editor.ProfilerState;
import com.android.tools.idea.run.profiler.CpuProfilerConfigsState;
-import com.android.tools.idea.codenavigation.IntellijCodeNavigator;
+import com.android.tools.idea.codenavigation.IntellijNavSource;
import com.android.tools.nativeSymbolizer.NativeSymbolizer;
import com.android.tools.nativeSymbolizer.NativeSymbolizerKt;
import com.android.tools.nativeSymbolizer.SymbolFilesLocator;
@@ -79,6 +79,7 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.swing.SwingUtilities;
+import org.apache.xmlbeans.impl.xb.ltgfmt.Code;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -89,7 +90,7 @@ public class IntellijProfilerServices implements IdeProfilerServices, Disposable
}
@NotNull private final SymbolFilesLocator mySymbolLocator;
- private final IntellijCodeNavigator myCodeNavigator;
+ private final CodeNavigator myCodeNavigator;
@NotNull private final NativeFrameSymbolizer myNativeSymbolizer;
private final StudioFeatureTracker myFeatureTracker;
@@ -112,7 +113,9 @@ public class IntellijProfilerServices implements IdeProfilerServices, Disposable
myTemporaryPreferences = new TemporaryProfilerPreferences();
myMigrationServices = new AppInspectionIntellijMigrationServices(myPersistentPreferences, project);
- myCodeNavigator = new IntellijCodeNavigator(project, nativeSymbolizer);
+ myCodeNavigator = new CodeNavigator(
+ new IntellijNavSource(project, nativeSymbolizer),
+ CodeNavigator.Companion.getApplicationExecutor());
myCodeNavigator.addListener(location -> myFeatureTracker.trackNavigateToCode());
}
@@ -285,7 +288,7 @@ public class IntellijProfilerServices implements IdeProfilerServices, Disposable
@NotNull
@Override
public List<String> getNativeSymbolsDirectories() {
- String arch = myCodeNavigator.fetchCpuAbiArch();
+ String arch = myCodeNavigator.getCpuArchSource().get();
Collection<File> dirs = mySymbolLocator.getDirectories(arch);
return ContainerUtil.map(dirs, file -> file.getAbsolutePath());
}
diff --git a/profilers/testSrc/com/android/tools/profilers/FakeIdeProfilerServices.java b/profilers/testSrc/com/android/tools/profilers/FakeIdeProfilerServices.java
index feb8ed91827..7df5d06f299 100644
--- a/profilers/testSrc/com/android/tools/profilers/FakeIdeProfilerServices.java
+++ b/profilers/testSrc/com/android/tools/profilers/FakeIdeProfilerServices.java
@@ -17,7 +17,7 @@ package com.android.tools.profilers;
import com.android.sdklib.AndroidVersion;
import com.android.tools.idea.codenavigation.CodeNavigator;
-import com.android.tools.idea.codenavigation.FakeCodeNavigator;
+import com.android.tools.idea.codenavigation.FakeNavSource;
import com.android.tools.profiler.proto.Cpu;
import com.android.tools.profiler.proto.Memory;
import com.android.tools.profilers.analytics.FeatureTracker;
@@ -70,7 +70,8 @@ public final class FakeIdeProfilerServices implements IdeProfilerServices {
public static final ProfilingConfiguration PERFETTO_CONFIG = new PerfettoConfiguration(FAKE_PERFETTO_NAME);
private final FeatureTracker myFakeFeatureTracker = new FakeFeatureTracker();
- private final CodeNavigator myFakeNavigationService = new FakeCodeNavigator();
+ private final CodeNavigator myFakeNavigationService = new CodeNavigator(
+ new FakeNavSource(), CodeNavigator.Companion.getTestExecutor());
private final TracePreProcessor myFakeTracePreProcessor = new FakeTracePreProcessor();
private TraceProcessorService myTraceProcessorService = new FakeTraceProcessorService();
private NativeFrameSymbolizer myFakeSymbolizer = new NativeFrameSymbolizer() {