File tree 6 files changed +62
-2
lines changed
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/commands
projects/maven/multimodule3
src/org/eclipse/jdt/ls/core/internal/commands
6 files changed +62
-2
lines changed Original file line number Diff line number Diff line change @@ -271,13 +271,13 @@ public static IJavaProject getJavaProjectFromUri(String uri) throws CoreExceptio
271
271
272
272
// For multi-module scenario
273
273
Arrays .sort (containers , (Comparator <IContainer >) (IContainer a , IContainer b ) -> {
274
- return a .getFullPath ().toPortableString (). length () - b .getFullPath ().toPortableString (). length ();
274
+ return a .getFullPath ().segmentCount () - b .getFullPath ().segmentCount ();
275
275
});
276
276
277
277
IJavaElement targetElement = null ;
278
278
for (IContainer container : containers ) {
279
279
targetElement = JavaCore .create (container .getProject ());
280
- if (targetElement != null ) {
280
+ if (targetElement != null && targetElement . exists () ) {
281
281
break ;
282
282
}
283
283
}
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+ <project xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns =" http://maven.apache.org/POM/4.0.0"
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" >
4
+ <modelVersion >4.0.0</modelVersion >
5
+ <parent >
6
+ <groupId >org.eclipse</groupId >
7
+ <artifactId >multimodule3</artifactId >
8
+ <version >1.0-SNAPSHOT</version >
9
+ </parent >
10
+ <groupId >org.eclipse</groupId >
11
+ <artifactId >this_is_a_very_long_module_name</artifactId >
12
+ <version >1.0-SNAPSHOT</version >
13
+ <name >this_is_a_very_long_module_name</name >
14
+ <properties >
15
+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
16
+ </properties >
17
+ <dependencies >
18
+ <dependency >
19
+ <groupId >junit</groupId >
20
+ <artifactId >junit</artifactId >
21
+ <version >4.13</version >
22
+ <scope >test</scope >
23
+ </dependency >
24
+ </dependencies >
25
+ </project >
Original file line number Diff line number Diff line change
1
+ package org .eclipse ;
2
+
3
+ public class App {
4
+ public static final String GREETING = "Hello World!" ;
5
+
6
+ public static void main (String [] args ) {
7
+ System .out .println (GREETING );
8
+ }
9
+ }
Original file line number Diff line number Diff line change
1
+ package org .eclipse ;
2
+
3
+ import static org .junit .Assert .assertTrue ;
4
+
5
+ import org .junit .Test ;
6
+
7
+ public class AppTest {
8
+ @ Test
9
+ public void testApp () {
10
+ assertTrue (true );
11
+ }
12
+ }
Original file line number Diff line number Diff line change 11
11
<modules >
12
12
<module >module1</module >
13
13
<module >module2</module >
14
+ <module >module3</module >
14
15
</modules >
15
16
16
17
<build >
Original file line number Diff line number Diff line change @@ -130,6 +130,19 @@ public void testGetMavenProjectFromUri() throws Exception {
130
130
assertNotNull ("Can get project from project uri" , javaProject );
131
131
}
132
132
133
+ @ Test
134
+ public void testGetMultiModuleMavenProjectFromUri () throws Exception {
135
+ importProjects ("maven/multimodule3" );
136
+ IProject project = WorkspaceHelper .getProject ("this_is_a_very_long_module_name" );
137
+ String javaSource = project .getFile ("src/main/org/eclipse/App.java" ).getLocationURI ().toString ();
138
+ IJavaProject javaProject = ProjectCommand .getJavaProjectFromUri (javaSource );
139
+ assertEquals ("this_is_a_very_long_module_name" , javaProject .getElementName ());
140
+
141
+ String projectUri = project .getLocationURI ().toString ();
142
+ javaProject = ProjectCommand .getJavaProjectFromUri (projectUri );
143
+ assertEquals ("this_is_a_very_long_module_name" , javaProject .getElementName ());
144
+ }
145
+
133
146
@ Test
134
147
public void testGetInvisibleProjectFromUri () throws Exception {
135
148
IProject project = copyAndImportFolder ("singlefile/simple" , "src/App.java" );
You can’t perform that action at this time.
0 commit comments