Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 200
Expose a command to resolve the source mapping for the specified stacktrace#354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2020 Microsoft Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| * | ||
| * Contributors: | ||
| * Microsoft Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
| package com.microsoft.java.debug.plugin.internal; | ||
| import java.io.File; | ||
| import java.util.List; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| public class ResolveSourceMappingHandler { | ||
| private static final Pattern SOURCE_PATTERN = Pattern.compile("([\\w$\\.]+\\/)?(([\\w$]+\\.)+[<\\w$>]+)\\(([\\w-$]+\\.java:\\d+)\\)"); | ||
| private static final JdtSourceLookUpProvider sourceProvider = new JdtSourceLookUpProvider(); | ||
| public static String resolveSourceUri(List<Object> arguments) { | ||
| if (arguments == null || arguments.isEmpty()) { | ||
| return null; | ||
| } | ||
| return resolveSourceUri((String) arguments.get(0)); | ||
| } | ||
| public static String resolveSourceUri(String lineText) { | ||
| if (lineText == null) { | ||
| return null; | ||
| } | ||
| Matcher matcher = SOURCE_PATTERN.matcher(lineText); | ||
| if (matcher.find()) { | ||
| String methodField = matcher.group(2); | ||
| String locationField = matcher.group(matcher.groupCount()); | ||
| String fullyQualifiedName = methodField.substring(0, methodField.lastIndexOf(".")); | ||
| String packageName = fullyQualifiedName.lastIndexOf(".") > -1 ? fullyQualifiedName.substring(0, fullyQualifiedName.lastIndexOf(".")) : ""; | ||
| String[] locations = locationField.split(":"); | ||
| String sourceName = locations[0]; | ||
| String sourcePath = StringUtils.isBlank(packageName) ? sourceName | ||
| : packageName.replace('.', File.separatorChar) + File.separatorChar + sourceName; | ||
| return sourceProvider.getSourceFileURI(fullyQualifiedName, sourcePath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs to apply user source mappings like the code in StackTraceRequestHandler does. That way, the additional source paths can be used to find the actual source locations rather than jdt:// stuff. | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The effect of this change is that getSourceFileURI always returns an (arguably invalid) jdt:// path now (as this method always returns a value), and so the code in StackTraceRequestHandler no longer actually checks user-specified source locations.
It's always better to use user-specified source locations (that contain the actual source) than returning a jdt uri which requires another server round-trip and somehow the server to (hopefully) find the source associated with the .class file.