Skip to content

Looking up the stack frame's associated source file from source containers directly to improve searching perf and bugs#127

Merged
testforstephen merged 12 commits intomasterfrom
jinbo_sourcelookup
Dec 11, 2017
Merged

Looking up the stack frame's associated source file from source containers directly to improve searching perf and bugs#127
testforstephen merged 12 commits intomasterfrom
jinbo_sourcelookup

Conversation

@testforstephen
Copy link
Copy Markdown
Contributor

@testforstephen testforstephen commented Dec 7, 2017

See the feature description microsoft/vscode-java-debug#121

Previous debugger use jdt search engine to look up the associated source file for the stack frame, but it has several issues:

@testforstephen testforstephen changed the title Looking up the stack frame's associated source file from source containers directly to improve search perf and bugs Looking up the stack frame's associated source file from source containers directly to improve searching perf and bugs Dec 7, 2017
@@ -164,17 +170,32 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th

@Override
public String getSourceFileURI(String fullyQualifiedName, String sourcePath) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the fullyQualifiedName is never used. Shall we just delete it?

Copy link
Copy Markdown
Contributor Author

@testforstephen testforstephen Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different provider implementation may have different source lookup mechanism. I prefer to keep current interface design.
If there is user compliant, i'd like to change the interface to public String getSourceFileURI(StackFrame stackFrame).
From the stack frame, the provider could get more info for accurate searching, such as class name, source name, source path, even source info for the specified stratum (like scala).

// But because the inner class and anonymous class have the same java file as the enclosing type,
// search their enclosing type instead.
if (fullyQualifiedName.indexOf("$") >= 0) {
return searchDeclarationFileByFqn(AdapterUtils.parseEnclosingType(fullyQualifiedName));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete the obsolete method searchDeclarationFileByFqn and searchDeclarationFileByFqn. And even AdapterUtils.parseEnclosingType.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.

* the current project name.
* @return the possible source container list.
*/
public static ISourceContainer[] getSourceContainers(String currentProject) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A static function is typically stateless. So it usually does not have the knowledge of the "current" project. Suggest using the more stateless name "projectName".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.


List<IProject> workspaceProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
projects.addAll(workspaceProjects.stream().filter((project) -> {
return !project.equals(targetProject);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can just use whatever returned by getProjects() instead of filtering out the targetProject. The logic seems redundant. The project collection should already have the target project. So this function can have no parameter.

Copy link
Copy Markdown
Contributor Author

@testforstephen testforstephen Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original purpose is "If the project name is specified, it will put the source containers from the specified project in the front of the result. "

The filter logic is to remove duplicated project to avoid duplicated computation.

Yes, it's unnecessary, because the final source container result is a set object, it'll remove the duplicated source container. Will change it as follows.

        IProject targetProject = JdtUtils.getProject(projectName);
        if (targetProject != null) {
            projects.add(targetProject);
        }

        List workspaceProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
        projects.addAll(workspaceProjects);

}

private static ISourceContainer[] getSourceContainers(IJavaProject project, Set<IRuntimeClasspathEntry> calculated) {
if (project != null && project.exists()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use early return.

if (project == null || !project.exists()) {
return empty;
}

In this way we avoid indenting large chunk of code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.

projects.addAll(workspaceProjects.stream().filter((project) -> {
return !project.equals(targetProject);
}).collect(Collectors.toList()));
projects.addAll(workspaceProjects);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There can be duplicated entries inside the projects collection. The targetProject is already inside.

ResourcesPlugin.getWorkspace().getRoot().getProjects()
JdtUtils.getProject(projectName)

Does the return value of the first call contain the return value of the second call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES, it contains the second result.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's OK to have duplicated projects because the later computation code has logic to avoid repeated calculation on the duplicated classpath entries.

List<IProject> workspaceProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
projects.addAll(workspaceProjects);

Set<IRuntimeClasspathEntry> calculated = new LinkedHashSet<>();
Copy link
Copy Markdown
Contributor

@yaohaizh yaohaizh Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Java.Stream to optimize the coding logic below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. fixed.


Set<IRuntimeClasspathEntry> calculated = new LinkedHashSet<>();

projects.stream().map(project -> JdtUtils.getJavaProject(project))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest using distinct() to avoid duplicates.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Copy link
Copy Markdown
Member

@akaroml akaroml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants