From 6b85dfa59b3937b5a20e0f5d50ed05e2b3c5d0a4 Mon Sep 17 00:00:00 2001 From: snpe Date: Sun, 23 Jan 2011 16:41:03 +0100 Subject: [PATCH] Fixing Android Source attachements Steps to reproduce: - add Android Source code to android.jar (you can install Android Sources plugin from http://code.google.com/p/adt-addons/) - ensure that android.app.ActivityThread exists in the source attachement (if you use Sources plugin, it exists) - create an Android application and add the next code to onCreate method: super.onCreate(savedInstanceState); Object obj = null; System.out.println(obj.toString()); setContentView(R.layout.main); - set breakpoint at line System.out.println(obj.toString()); (NPE) - debug the application - wait that apps stop on breakpoint - click Step Over The procces will proceed in ActivityThread, but source is not shown. The problem happens because the Android source locator introduced in https://review.source.android.com/#change,16569 isn't correct. ActivityThread.java isn't included to android.jar, but can be included in the source attachement. This change adds source to Android launch configuration too. Change-Id: Id13ef9acac9a901a704ae79d3e3db3be5e09d929 --- .../plugins/com.android.ide.eclipse.adt/plugin.xml | 2 +- .../sourcelookup/AdtSourceLookupDirector.java | 34 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml b/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml index 551e6be85..07c59b102 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml +++ b/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml @@ -146,7 +146,7 @@ modes="debug, run" name="Android Application" public="true" - sourceLocatorId="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector" + sourceLocatorId="com.android.ide.eclipse.adt.internal.sourcelookup.AdtSourceLookupDirector" sourcePathComputerId="org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer"> diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sourcelookup/AdtSourceLookupDirector.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sourcelookup/AdtSourceLookupDirector.java index 612ef76aa..e0e236bc0 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sourcelookup/AdtSourceLookupDirector.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sourcelookup/AdtSourceLookupDirector.java @@ -17,7 +17,9 @@ package com.android.ide.eclipse.adt.internal.sourcelookup; -import com.android.ide.eclipse.adt.internal.project.AndroidClasspathContainerInitializer; +import com.android.ide.eclipse.adt.internal.sdk.ProjectState; +import com.android.ide.eclipse.adt.internal.sdk.Sdk; +import com.android.sdklib.IAndroidTarget; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; @@ -32,6 +34,7 @@ import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.internal.launching.JavaSourceLookupDirector; +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; import java.io.File; @@ -41,20 +44,35 @@ public class AdtSourceLookupDirector extends JavaSourceLookupDirector { public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException { dispose(); setLaunchConfiguration(configuration); - String projectName = configuration.getAttribute("org.eclipse.jdt.launching.PROJECT_ATTR", //$NON-NLS-1$ + String projectName = + configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ if (projectName != null && projectName.length() > 0) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (project != null && project.isOpen()) { + ProjectState state = Sdk.getProjectState(project); + if (state == null) { + initDefaults(); + return; + } + IAndroidTarget target = state.getTarget(); + if (target == null) { + initDefaults(); + return; + } + String path = target.getPath(IAndroidTarget.ANDROID_JAR); + if (path == null) { + initDefaults(); + return; + } IJavaProject javaProject = JavaCore.create(project); if (javaProject != null && javaProject.isOpen()) { - IClasspathEntry[] entries = javaProject.getRawClasspath(); + IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); IClasspathEntry androidEntry = null; for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; - if (entry.getPath() != null - && AndroidClasspathContainerInitializer.CONTAINER_ID.equals(entry - .getPath().toString())) { + if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY + && path.equals(entry.getPath().toString())) { androidEntry = entry; break; } @@ -88,6 +106,10 @@ public class AdtSourceLookupDirector extends JavaSourceLookupDirector { } } } + initDefaults(); + } + + private void initDefaults() { setSourceContainers(new ISourceContainer[] { new DefaultSourceContainer() }); -- 2.11.0