1717import org .eclipse .core .resources .IFile ;
1818import org .eclipse .core .resources .ResourcesPlugin ;
1919import org .eclipse .core .runtime .IProgressMonitor ;
20+ import org .eclipse .jdt .core .ICompilationUnit ;
2021import org .eclipse .jdt .core .IJavaProject ;
2122import org .eclipse .jdt .ls .core .internal .IDelegateCommandHandler ;
23+ import org .eclipse .jdt .ls .core .internal .JDTUtils ;
2224import org .eclipse .jdt .ls .core .internal .ProjectUtils ;
2325import org .eclipse .jdt .ls .core .internal .ResourceUtils ;
2426
27+ import com .microsoft .java .debug .core .DebugException ;
2528import com .microsoft .java .debug .core .UsageDataStore ;
2629import com .microsoft .java .debug .core .protocol .JsonUtils ;
2730import com .microsoft .java .debug .core .protocol .Requests .LaunchArguments ;
@@ -39,6 +42,7 @@ public class JavaDebugDelegateCommandHandler implements IDelegateCommandHandler
3942 public static final String CHECK_PROJECT_SETTINGS = "vscode.java.checkProjectSettings" ;
4043 public static final String RESOLVE_ELEMENT_AT_SELECTION = "vscode.java.resolveElementAtSelection" ;
4144 public static final String RESOLVE_BUILD_FILES = "vscode.java.resolveBuildFiles" ;
45+ public static final String IS_ON_CLASSPATH = "vscode.java.isOnClasspath" ;
4246
4347 @ Override
4448 public Object executeCommand (String commandId , List <Object > arguments , IProgressMonitor progress ) throws Exception {
@@ -72,6 +76,8 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
7276 return ResolveElementHandler .resolveElementAtSelection (arguments , progress );
7377 case RESOLVE_BUILD_FILES :
7478 return getBuildFiles ();
79+ case IS_ON_CLASSPATH :
80+ return isOnClasspath (arguments );
7581 default :
7682 break ;
7783 }
@@ -97,4 +103,19 @@ private List<String> getBuildFiles() {
97103
98104 return result ;
99105 }
106+
107+ private boolean isOnClasspath (List <Object > arguments ) throws DebugException {
108+ if (arguments .size () < 1 ) {
109+ throw new DebugException ("No file uri is specified." );
110+ }
111+
112+ String uri = (String ) arguments .get (0 );
113+ final ICompilationUnit unit = JDTUtils .resolveCompilationUnit (uri );
114+ if (unit == null || unit .getResource () == null || !unit .getResource ().exists ()) {
115+ throw new DebugException ("The compilation unit " + uri + " doesn't exist." );
116+ }
117+
118+ IJavaProject javaProject = unit .getJavaProject ();
119+ return javaProject == null || javaProject .isOnClasspath (unit );
120+ }
100121}
0 commit comments