Skip to content

Commit 2a95747

Browse files
fix integration bug (#10)
* fix integration bug * add signoff Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
1 parent 243ba94 commit 2a95747

File tree

4 files changed

+90
-75
lines changed

4 files changed

+90
-75
lines changed

com.microsoft.java.debug.plugin/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?eclipse version="3.4"?>
33
<plugin>
44
<extension point="org.eclipse.jdt.ls.core.delegateCommandHandler">
5-
<delegateCommandHandler class="org.eclipse.jdt.ls.core.internal.DebugDelegateCommandHandlerFactory">
5+
<delegateCommandHandler class="com.microsoft.java.debug.plugin.internal.JavaDebugDelegateCommandHandler">
66
<command id="vscode.java.startDebugSession"/>
77
<command id="vscode.java.resolveClasspath"/>
88
<command id="vscode.java.buildWorkspace"/>

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugDelegateCommandHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public class JavaDebugDelegateCommandHandler implements IDelegateCommandHandler
1616
@Override
1717
public Object executeCommand(String commandId, List<Object> arguments) {
1818
if (DEBUG_STARTSESSION.equals(commandId)) {
19-
19+
IDebugServer debugServer = JavaDebugServer.getInstance();
20+
debugServer.start();
21+
return debugServer.getPort();
2022
} else if (RESOLVE_CLASSPATH.equals(commandId)) {
2123
ResolveClasspathsHandler handler = new ResolveClasspathsHandler();
2224
return handler.resolveClasspaths(arguments);

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JdtSourceLookUpProvider.java

Lines changed: 83 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.microsoft.java.debug.plugin.internal;
22

3+
import java.net.URI;
4+
import java.net.URISyntaxException;
35
import java.util.ArrayList;
46
import java.util.HashMap;
57
import java.util.Map;
@@ -28,17 +30,18 @@
2830
import org.eclipse.jdt.core.search.SearchPattern;
2931
import org.eclipse.jdt.core.search.SearchRequestor;
3032
import org.eclipse.jdt.internal.debug.core.breakpoints.ValidBreakpointLocationLocator;
31-
//import org.eclipse.jdt.ls.core.internal.JDTUtils;
33+
import org.eclipse.jdt.ls.core.internal.JDTUtils;
3234

3335
import com.microsoft.java.debug.core.DebugException;
3436
import com.microsoft.java.debug.core.Logger;
3537
import com.microsoft.java.debug.core.adapter.AdapterUtils;
3638
import com.microsoft.java.debug.core.adapter.Constants;
3739
import com.microsoft.java.debug.core.adapter.ISourceLookUpProvider;
38-
import com.microsoft.java.debug.plugin.internal.JavaDebuggerServerPlugin;
3940

4041
public class JdtSourceLookUpProvider implements ISourceLookUpProvider {
4142
private HashMap<String, Object> context = new HashMap<String, Object>();
43+
private static final String JDT_SCHEME = "jdt";
44+
private static final String PATH_SEPARATOR = "/";
4245

4346
@Override
4447
public void initialize(Map<String, Object> props) {
@@ -72,35 +75,35 @@ public String[] getFullyQualifiedName(String uri, int[] lines, int[] columns) th
7275
}
7376

7477
String[] fqns = new String[lines.length];
75-
// ITypeRoot typeRoot = JDTUtils.resolveCompilationUnit(uri);
76-
// if (typeRoot == null) {
77-
// typeRoot = JDTUtils.resolveClassFile(uri);
78-
// }
79-
//
80-
// if (typeRoot != null && lines.length > 0) {
81-
// // Currently we only support Java SE 8 Edition (JLS8).
82-
// final ASTParser parser = ASTParser.newParser(AST.JLS8);
83-
// parser.setResolveBindings(true);
84-
// parser.setBindingsRecovery(true);
85-
// parser.setStatementsRecovery(true);
86-
// parser.setSource(typeRoot);
87-
// CompilationUnit cunit = (CompilationUnit) parser.createAST(null);
88-
// for (int i = 0; i < lines.length; i++) {
89-
// // TODO
90-
// // The ValidBreakpointLocationLocator will verify if the current line is a valid location or not.
91-
// // If so, it will return the fully qualified name of the class type that contains the current line.
92-
// // Otherwise, it will try to find a valid location from the next lines and return it's fully qualified name.
93-
// // In current stage, we don't support to move the invalid breakpoint down to the next valid location, and just
94-
// // mark it as "unverified".
95-
// // In future, we could consider supporting to update the breakpoint to a valid location.
96-
// ValidBreakpointLocationLocator locator = new ValidBreakpointLocationLocator(cunit, lines[i], true, true);
97-
// cunit.accept(locator);
98-
// // When the final valid line location is same as the original line, that represents it's a valid breakpoint.
99-
// if (lines[i] == locator.getLineLocation()) {
100-
// fqns[i] = locator.getFullyQualifiedTypeName();
101-
// }
102-
// }
103-
// }
78+
ITypeRoot typeRoot = JDTUtils.resolveCompilationUnit(uri);
79+
if (typeRoot == null) {
80+
typeRoot = JDTUtils.resolveClassFile(uri);
81+
}
82+
83+
if (typeRoot != null && lines.length > 0) {
84+
// Currently we only support Java SE 8 Edition (JLS8).
85+
final ASTParser parser = ASTParser.newParser(AST.JLS8);
86+
parser.setResolveBindings(true);
87+
parser.setBindingsRecovery(true);
88+
parser.setStatementsRecovery(true);
89+
parser.setSource(typeRoot);
90+
CompilationUnit cunit = (CompilationUnit) parser.createAST(null);
91+
for (int i = 0; i < lines.length; i++) {
92+
// TODO
93+
// The ValidBreakpointLocationLocator will verify if the current line is a valid location or not.
94+
// If so, it will return the fully qualified name of the class type that contains the current line.
95+
// Otherwise, it will try to find a valid location from the next lines and return it's fully qualified name.
96+
// In current stage, we don't support to move the invalid breakpoint down to the next valid location, and just
97+
// mark it as "unverified".
98+
// In future, we could consider supporting to update the breakpoint to a valid location.
99+
ValidBreakpointLocationLocator locator = new ValidBreakpointLocationLocator(cunit, lines[i], true, true);
100+
cunit.accept(locator);
101+
// When the final valid line location is same as the original line, that represents it's a valid breakpoint.
102+
if (lines[i] == locator.getLineLocation()) {
103+
fqns[i] = locator.getFullyQualifiedTypeName();
104+
}
105+
}
106+
}
104107
return fqns;
105108
}
106109

@@ -124,9 +127,8 @@ public String getSourceContents(String uri) {
124127
if (uri == null) {
125128
throw new IllegalArgumentException("uri is null");
126129
}
127-
// IClassFile cf = JDTUtils.resolveClassFile(uri);
128-
// return getContents(cf);
129-
return "";
130+
IClassFile cf = JDTUtils.resolveClassFile(uri);
131+
return getContents(cf);
130132
}
131133

132134
private String getContents(IClassFile cf) {
@@ -138,7 +140,7 @@ private String getContents(IClassFile cf) {
138140
source = buffer.getContents();
139141
}
140142
if (source == null) {
141-
// source = JDTUtils.disassemble(cf);
143+
source = JDTUtils.disassemble(cf);
142144
}
143145
} catch (JavaModelException e) {
144146
Logger.logException("Failed to parse the source contents of the class file", e);
@@ -164,40 +166,52 @@ private IJavaProject getJavaProjectFromName(String projectName) throws CoreExcep
164166
}
165167

166168
private String searchDeclarationFileByFqn(String fullyQualifiedName) {
167-
// String projectName = (String) context.get(Constants.PROJECTNAME);
168-
// try {
169-
// IJavaSearchScope searchScope = projectName != null
170-
// ? JDTUtils.createSearchScope(getJavaProjectFromName(projectName))
171-
// : SearchEngine.createWorkspaceScope();
172-
// SearchPattern pattern = SearchPattern.createPattern(
173-
// fullyQualifiedName,
174-
// IJavaSearchConstants.TYPE,
175-
// IJavaSearchConstants.DECLARATIONS,
176-
// SearchPattern.R_EXACT_MATCH);
177-
// ArrayList<String> uris = new ArrayList<String>();
178-
// SearchRequestor requestor = new SearchRequestor() {
179-
// @Override
180-
// public void acceptSearchMatch(SearchMatch match) {
181-
// Object element = match.getElement();
182-
// if (element instanceof IType) {
183-
// IType type = (IType) element;
184-
// uris.add(type.isBinary() ? JDTUtils.getFileURI(type.getClassFile()) : JDTUtils.getFileURI(type.getResource()));
185-
// }
186-
// }
187-
// };
188-
// SearchEngine searchEngine = new SearchEngine();
189-
// searchEngine.search(
190-
// pattern,
191-
// new SearchParticipant[]{
192-
// SearchEngine.getDefaultSearchParticipant()
193-
// },
194-
// searchScope,
195-
// requestor,
196-
// null /* progress monitor */);
197-
// return uris.size() == 0 ? null : uris.get(0);
198-
// } catch (CoreException e) {
199-
// Logger.logException("Failed to parse java project", e);
200-
// }
169+
String projectName = (String) context.get(Constants.PROJECTNAME);
170+
try {
171+
IJavaSearchScope searchScope = projectName != null
172+
? JDTUtils.createSearchScope(getJavaProjectFromName(projectName))
173+
: SearchEngine.createWorkspaceScope();
174+
SearchPattern pattern = SearchPattern.createPattern(
175+
fullyQualifiedName,
176+
IJavaSearchConstants.TYPE,
177+
IJavaSearchConstants.DECLARATIONS,
178+
SearchPattern.R_EXACT_MATCH);
179+
ArrayList<String> uris = new ArrayList<String>();
180+
SearchRequestor requestor = new SearchRequestor() {
181+
@Override
182+
public void acceptSearchMatch(SearchMatch match) {
183+
Object element = match.getElement();
184+
if (element instanceof IType) {
185+
IType type = (IType) element;
186+
uris.add(type.isBinary() ? getFileURI(type.getClassFile()) : JDTUtils.getFileURI(type.getResource()));
187+
}
188+
}
189+
};
190+
SearchEngine searchEngine = new SearchEngine();
191+
searchEngine.search(
192+
pattern,
193+
new SearchParticipant[]{
194+
SearchEngine.getDefaultSearchParticipant()
195+
},
196+
searchScope,
197+
requestor,
198+
null /* progress monitor */);
199+
return uris.size() == 0 ? null : uris.get(0);
200+
} catch (CoreException e) {
201+
Logger.logException("Failed to parse java project", e);
202+
}
201203
return null;
202204
}
205+
206+
private static String getFileURI(IClassFile classFile) {
207+
String packageName = classFile.getParent().getElementName();
208+
String jarName = classFile.getParent().getParent().getElementName();
209+
try {
210+
return new URI(JDT_SCHEME, "contents", PATH_SEPARATOR + jarName + PATH_SEPARATOR + packageName + PATH_SEPARATOR + classFile.getElementName(), classFile.getHandleIdentifier(), null).toASCIIString();
211+
} catch (URISyntaxException e) {
212+
e.printStackTrace();
213+
return null;
214+
}
215+
}
216+
203217
}

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveClasspathsHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import java.util.ArrayList;
1616
import java.util.List;
17-
import java.util.concurrent.CompletableFuture;
1817

1918
import org.eclipse.core.resources.IProject;
2019
import org.eclipse.core.resources.IWorkspaceRoot;
@@ -103,15 +102,15 @@ public void acceptSearchMatch(SearchMatch match) {
103102
/**
104103
* Accord to the project name and the main class, compute runtime classpath.
105104
*
105+
* @param mainClass
106+
* fully qualified class name
106107
* @param projectName
107108
* project name
108-
* @param mainClass
109-
* full qualified class name
110109
* @return class path
111110
* @throws CoreException
112111
* CoreException
113112
*/
114-
private static String[] computeClassPath(String projectName, String mainClass) throws CoreException {
113+
private static String[] computeClassPath(String mainClass, String projectName) throws CoreException {
115114
IJavaProject project = null;
116115
// if type exists in multiple projects, debug configuration need provide
117116
// project name.

0 commit comments

Comments
 (0)