From 0fd69241f1e427696b68eff97d4f6e5a9c9c1a1b Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Fri, 12 Sep 2014 21:37:24 +0400 Subject: [PATCH] When class got from maven repository, automatically open source file for it when debugging --- .../TeaVMSourcePathComputerDelegate.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMSourcePathComputerDelegate.java b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMSourcePathComputerDelegate.java index 6ec83f61c..a8e3239e1 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMSourcePathComputerDelegate.java +++ b/teavm-eclipse/teavm-eclipse-plugin/src/main/java/org/teavm/eclipse/debugger/TeaVMSourcePathComputerDelegate.java @@ -18,13 +18,24 @@ package org.teavm.eclipse.debugger; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.sourcelookup.ISourceContainer; import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate; +import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer; +import org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer; +import org.eclipse.debug.core.sourcelookup.containers.FolderSourceContainer; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.launching.IRuntimeClasspathEntry; import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jdt.launching.sourcelookup.containers.ClasspathContainerSourceContainer; /** * @@ -35,7 +46,7 @@ public class TeaVMSourcePathComputerDelegate implements ISourcePathComputerDeleg public ISourceContainer[] computeSourceContainers(ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException { List sourceContainers = new ArrayList<>(); - /*IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); + IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (IProject project : projects) { if (!project.isOpen()) { continue; @@ -47,8 +58,28 @@ public class TeaVMSourcePathComputerDelegate implements ISourcePathComputerDeleg sourceContainers.add(new FolderSourceContainer((IFolder)fragmentRoot.getResource(), true)); } } + for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { + switch (entry.getEntryKind()) { + case IClasspathEntry.CPE_CONTAINER: + sourceContainers.add(new ClasspathContainerSourceContainer(entry.getPath())); + break; + case IClasspathEntry.CPE_LIBRARY:; + sourceContainers.add(new ExternalArchiveSourceContainer(entry.getPath().toString(), true)); + if (entry.getSourceAttachmentPath() != null) { + System.out.println(entry.getSourceAttachmentPath()); + sourceContainers.add(new ExternalArchiveSourceContainer( + entry.getSourceAttachmentPath().toString(), true)); + sourceContainers.add(new DirectorySourceContainer(entry.getSourceAttachmentPath(), + true)); + } + break; + case IClasspathEntry.CPE_SOURCE: + sourceContainers.add(new DirectorySourceContainer(entry.getPath(), true)); + break; + } + } } - }*/ + } IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedSourceLookupPath(config); IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(entries, config); sourceContainers.addAll(Arrays.asList(JavaRuntime.getSourceContainers(resolved)));