Skip to content

Commit 93cbd4b

Browse files
committed
Merge branch 'master' of https://github.com/hopehadfield/eclipse.jdt.ls into 3686-linked-proposal
2 parents 94dcce9 + 0375248 commit 93cbd4b

File tree

65 files changed

+484
-219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+484
-219
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
# [1.38.0 (August 1st, 2024)](https://github.com/eclipse/eclipse.jdt.ls/milestone/130?closed=1)
4+
* performance - Clean up invalid projects during the initialization. See [#3208](https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3208).
5+
* enhancement - Add `java.diagnostic.filter` to exclude files from diagnostic publishing. See [#3218](https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3218).
6+
* enhancement - Add support for callees based on implementors for call hierarchy. See [#2780](https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/2780).
7+
* bug fix - Call hierarchy should handle lack of classfile content support from client. See [#3206](https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/3206).
8+
* bug fix - Fix package declaration in test file. See [#3223](https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3223).
9+
* bug fix - Fix duplicated content in test class. See [#3219](https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3219).
10+
* dependencies - Target platform update resulting in **loss of support for Java versions older than 1.8**. See [#3227](https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3227).
11+
* dependencies - Bump org.eclipse.cbi.maven.plugins:eclipse-jarsigner-plugin from 1.4.3 to 1.5.0. See [#3217](https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3217).
12+
313
# [1.37.0 (June 27th, 2024)](https://github.com/eclipse/eclipse.jdt.ls/milestone/129?closed=1)
414
* performance - Ensure every null analysis annotation has a value defined when enabled. See [#3196](https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3196).
515
* enhancement - Add `final` to "Extract to local variable" quick assist if requested. See [#3198](https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3198).

org.eclipse.jdt.ls.core/META-INF/MANIFEST.MF

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-SymbolicName: org.eclipse.jdt.ls.core;singleton:=true
5-
Bundle-Version: 1.38.0.qualifier
5+
Bundle-Version: 1.39.0.qualifier
66
Bundle-Activator: org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin
77
Bundle-RequiredExecutionEnvironment: JavaSE-17
88
Bundle-Localization: plugin
@@ -25,8 +25,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0",
2525
org.eclipse.jdt.core.manipulation;bundle-version="1.8.0",
2626
com.google.gson;bundle-version="2.7.0",
2727
org.apache.commons.lang3;bundle-version="3.1.0",
28-
org.eclipse.lsp4j;bundle-version="[0.22.0.0,0.23.0)",
29-
org.eclipse.lsp4j.jsonrpc;bundle-version="[0.22.0,0.23.0)",
28+
org.eclipse.lsp4j;bundle-version="[0.23.0.0,0.24.0)",
29+
org.eclipse.lsp4j.jsonrpc;bundle-version="[0.23.0,0.24.0)",
3030
org.eclipse.xtext.xbase.lib,
3131
org.eclipse.core.filesystem;bundle-version="1.7.0",
3232
org.eclipse.jdt.apt.pluggable.core;bundle-version="1.2.0";resolution:=optional,

org.eclipse.jdt.ls.core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.eclipse.jdt.ls</groupId>
77
<artifactId>parent</artifactId>
8-
<version>1.38.0-SNAPSHOT</version>
8+
<version>1.39.0-SNAPSHOT</version>
99
</parent>
1010
<artifactId>org.eclipse.jdt.ls.core</artifactId>
1111
<packaging>eclipse-plugin</packaging>

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.File;
2121
import java.io.IOException;
22+
import java.net.MalformedURLException;
2223
import java.net.URI;
2324
import java.net.URISyntaxException;
2425
import java.nio.file.FileSystem;
@@ -257,10 +258,13 @@ public static ICompilationUnit getFakeCompilationUnit(String uri) {
257258
}
258259

259260
static ICompilationUnit getFakeCompilationUnit(URI uri, IProgressMonitor monitor) {
260-
if (uri == null || !"file".equals(uri.getScheme()) || !uri.getPath().endsWith(".java")) {
261+
if (uri == null || !"file".equals(uri.getScheme())) {
261262
return null;
262263
}
263264
java.nio.file.Path path = Paths.get(uri);
265+
if (!isJavaFile(path)) {
266+
return null;
267+
}
264268
//Only support existing standalone java files
265269
if (!java.nio.file.Files.isReadable(path)) {
266270
return null;
@@ -275,7 +279,7 @@ static ICompilationUnit getFakeCompilationUnit(URI uri, IProgressMonitor monitor
275279
IProject project = JavaLanguageServerPlugin.getProjectsManager().getDefaultProject();
276280
if (project == null || !project.isAccessible()) {
277281
String fileName = path.getFileName().toString();
278-
if (fileName.endsWith(".java") || fileName.endsWith(".class")) {
282+
if (isJavaFile(fileName) || fileName.endsWith(".class")) {
279283
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
280284
}
281285
WorkingCopyOwner owner = new WorkingCopyOwner() {
@@ -657,6 +661,23 @@ private boolean find(IJavaElement element, final ASTNode[] nodes, SimpleName nod
657661
}
658662
}
659663

664+
public static boolean isJavaFile(java.nio.file.Path path) {
665+
try {
666+
return path != null && isJavaFile(path.toFile().getName());
667+
} catch (Exception e) {
668+
JavaLanguageServerPlugin.logException(e.getMessage(), e);
669+
}
670+
return false;
671+
}
672+
673+
public static boolean isJavaFile(IPath path) {
674+
return path != null && isJavaFile(path.lastSegment());
675+
}
676+
677+
public static boolean isJavaFile(String name) {
678+
return name != null && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name);
679+
}
680+
660681
/**
661682
* Enumeration for determining the location of a Java element. Either returns
662683
* with the name range only, or the extended source range around the name of the
@@ -1095,7 +1116,7 @@ public static IFile findFile(String uriString) {
10951116
}
10961117

10971118
public static ISchedulingRule getRule(String uri) {
1098-
IResource resource = JDTUtils.findFile(uri);
1119+
IResource resource = findFile(uri);
10991120
if (resource != null) {
11001121
return ResourcesPlugin.getWorkspace().getRuleFactory().createRule(resource);
11011122
}
@@ -1749,7 +1770,7 @@ public static List<Location> searchDecompiledSources(IJavaElement element, IClas
17491770
}
17501771
Location location;
17511772
if (node != null) {
1752-
String uriString = JDTUtils.toUri(classFile);
1773+
String uriString = toUri(classFile);
17531774
IDocument document = new Document(contents);
17541775
if (declaration) {
17551776
int offset = node.getStartPosition();
@@ -1793,7 +1814,7 @@ public static List<Location> searchDecompiledSources(IJavaElement element, IClas
17931814
locations.add(location);
17941815
}
17951816
} else {
1796-
location = JDTUtils.toLocation(classFile, 0, 0);
1817+
location = toLocation(classFile, 0, 0);
17971818
locations.add(location);
17981819
}
17991820
} finally {
@@ -1835,14 +1856,24 @@ public static ICompilationUnit getWorkingCopy(IClassFile classFile, String conte
18351856
}
18361857

18371858
public static boolean isExcludedFile(List<String> patterns, String uriString) {
1859+
if (patterns.isEmpty()) {
1860+
return false;
1861+
}
1862+
18381863
URI uri = toURI(uriString);
18391864
if (uri == null) {
18401865
return false;
18411866
}
18421867

1843-
java.nio.file.Path path = Paths.get(uri);
1844-
FileSystem fileSystems = path.getFileSystem();
1845-
return !patterns.stream().filter(pattern -> fileSystems.getPathMatcher("glob:" + pattern).matches(path)).collect(Collectors.toList()).isEmpty();
1868+
// https://github.com/redhat-developer/vscode-java/issues/3735
1869+
java.nio.file.Path[] path = new java.nio.file.Path[1];
1870+
try {
1871+
path[0] = Paths.get(uri.toURL().getPath());
1872+
} catch (MalformedURLException e) {
1873+
path[0] = Paths.get(uri);
1874+
}
1875+
FileSystem fileSystems = path[0].getFileSystem();
1876+
return !patterns.stream().filter(pattern -> fileSystems.getPathMatcher("glob:" + pattern).matches(path[0])).collect(Collectors.toList()).isEmpty();
18461877
}
18471878

18481879
/**

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/TypeMismatchSubProcessor.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
4141
import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels;
4242
import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext;
43-
import org.eclipse.jdt.ui.text.java.IInvocationContext;
44-
import org.eclipse.jdt.ui.text.java.IProblemLocation;
4543
import org.eclipse.jdt.internal.ui.text.correction.IProposalRelevance;
4644
import org.eclipse.jdt.internal.ui.text.correction.TypeMismatchBaseSubProcessor;
4745
import org.eclipse.jdt.internal.ui.text.correction.proposals.CastCorrectionProposalCore;
@@ -55,6 +53,8 @@
5553
import org.eclipse.jdt.ls.core.internal.corrections.CorrectionMessages;
5654
import org.eclipse.jdt.ls.core.internal.corrections.ProposalKindWrapper;
5755
import org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler;
56+
import org.eclipse.jdt.ui.text.java.IInvocationContext;
57+
import org.eclipse.jdt.ui.text.java.IProblemLocation;
5858
import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposalCore;
5959
import org.eclipse.lsp4j.CodeActionKind;
6060

@@ -236,4 +236,12 @@ protected ProposalKindWrapper createIncompatibleForEachTypeProposal(String label
236236
return CodeActionHandler.wrap(proposal, CodeActionKind.QuickFix);
237237
}
238238

239+
/* (non-Javadoc)
240+
* @see org.eclipse.jdt.internal.ui.text.correction.TypeMismatchBaseSubProcessor#createChangeConstructorTypeProposal(org.eclipse.jdt.core.ICompilationUnit, org.eclipse.jdt.core.dom.ASTNode, org.eclipse.jdt.core.dom.CompilationUnit, org.eclipse.jdt.core.dom.ITypeBinding, int)
241+
*/
242+
@Override
243+
protected ProposalKindWrapper createChangeConstructorTypeProposal(ICompilationUnit targetCu, ASTNode callerNode, CompilationUnit astRoot, ITypeBinding castTypeBinding, int relevance) {
244+
return null;
245+
}
246+
239247
}

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/framework/protobuf/ProtobufSupport.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.eclipse.jdt.core.JavaCore;
4040
import org.eclipse.jdt.core.JavaModelException;
4141
import org.eclipse.jdt.ls.core.internal.ActionableNotification;
42+
import org.eclipse.jdt.ls.core.internal.JDTUtils;
4243
import org.eclipse.jdt.ls.core.internal.JavaClientConnection.JavaLanguageClient;
4344
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
4445
import org.eclipse.jdt.ls.core.internal.ProgressReport;
@@ -94,7 +95,7 @@ public void onDidProjectsImported(IProgressMonitor monitor) {
9495
JavaLanguageServerPlugin.getProjectsManager().getConnection().sendActionableNotification(notification);
9596
}
9697
}
97-
98+
9899
/**
99100
* Find all the Protobuf source output directories of the given project.
100101
* @param project project.
@@ -133,7 +134,7 @@ private boolean containsJavaFiles(Set<File> generatedDirectories) {
133134

134135
try (Stream<Path> walkStream = Files.walk(dir.toPath())) {
135136
boolean containsJavaFile = walkStream.filter(p -> p.toFile().isFile()).anyMatch(f -> {
136-
return f.toString().endsWith(".java");
137+
return JDTUtils.isJavaFile(f);
137138
});
138139

139140
if (containsJavaFile) {
@@ -194,7 +195,7 @@ private static void runGenerateProtobufTasks(String projectName, IProgressMonito
194195
try {
195196
build.get().withConnection(connection -> {
196197
connection.newBuild().forTasks("generateProto", "generateTestProto").run();
197-
return null;
198+
return null;
198199
}, monitor);
199200
} catch (Exception e) {
200201
JavaLanguageServerPlugin.logException(e);

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BaseDiagnosticsHandler.java

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
*******************************************************************************/
1414
package org.eclipse.jdt.ls.core.internal.handlers;
1515

16+
import java.io.File;
1617
import java.lang.reflect.Field;
18+
import java.net.URI;
1719
import java.util.ArrayList;
1820
import java.util.Arrays;
1921
import java.util.Collections;
22+
import java.util.HashSet;
2023
import java.util.List;
24+
import java.util.Set;
2125

2226
import org.eclipse.core.resources.IMarker;
27+
import org.eclipse.core.resources.IProject;
2328
import org.eclipse.core.resources.IResource;
2429
import org.eclipse.core.runtime.CoreException;
2530
import org.eclipse.jdt.core.IBuffer;
@@ -33,6 +38,7 @@
3338
import org.eclipse.jdt.ls.core.internal.JDTUtils;
3439
import org.eclipse.jdt.ls.core.internal.JavaClientConnection;
3540
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
41+
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
3642
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
3743
import org.eclipse.jface.text.IDocument;
3844
import org.eclipse.lsp4j.Diagnostic;
@@ -129,12 +135,48 @@ public void beginReporting() {
129135

130136
@Override
131137
public void endReporting() {
132-
JavaLanguageServerPlugin.logInfo(problems.size() + " problems reported for " + this.uri.substring(this.uri.lastIndexOf('/')));
133-
boolean isDiagnosticTagSupported = JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isDiagnosticTagSupported();
134-
List<Diagnostic> diagnostics = toDiagnosticsArray(this.cu, problems, isDiagnosticTagSupported);
135-
collectNonJavaProblems(diagnostics, isDiagnosticTagSupported);
136-
PublishDiagnosticsParams $ = new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), diagnostics);
137-
this.connection.publishDiagnostics($);
138+
if (!matchesDiagnosticFilter(uri, JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getDiagnosticFilter())) {
139+
JavaLanguageServerPlugin.logInfo(problems.size() + " problems reported for " + this.uri.substring(this.uri.lastIndexOf('/')));
140+
boolean isDiagnosticTagSupported = JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isDiagnosticTagSupported();
141+
List<Diagnostic> diagnostics = toDiagnosticsArray(this.cu, problems, isDiagnosticTagSupported);
142+
collectNonJavaProblems(diagnostics, isDiagnosticTagSupported);
143+
PublishDiagnosticsParams $ = new PublishDiagnosticsParams(ResourceUtils.toClientUri(uri), diagnostics);
144+
this.connection.publishDiagnostics($);
145+
}
146+
}
147+
148+
/**
149+
* @param uri the String URI to test
150+
* @param diagnosticFilters a list of patterns to test against
151+
* @return true if the URI matches any of the given patterns.
152+
*/
153+
public static boolean matchesDiagnosticFilter(String uri, List<String> diagnosticFilters) {
154+
return JDTUtils.isExcludedFile(diagnosticFilters, uri);
155+
}
156+
157+
/**
158+
* @param diagnosticFilter a list of patterns to test against
159+
* @return a set of document URI that match any of the given patterns.
160+
*/
161+
public static Set<String> getDocumentsMatchingFilter(List<String> diagnosticFilter) {
162+
Set<String> uris = new HashSet<>();
163+
for (IProject project : ProjectUtils.getAllProjects()) {
164+
try {
165+
IMarker[] markers = project.findMarkers(null, true, IResource.DEPTH_INFINITE);
166+
for (IMarker marker : markers) {
167+
URI locationURI = marker.getResource().getLocationURI();
168+
if (locationURI != null && !new File(locationURI).isDirectory()) {
169+
String uriString = locationURI.toString();
170+
if (BaseDiagnosticsHandler.matchesDiagnosticFilter(uriString, diagnosticFilter)) {
171+
uris.add(uriString);
172+
}
173+
}
174+
}
175+
} catch (CoreException e) {
176+
// continue
177+
}
178+
}
179+
return uris;
138180
}
139181

140182
/**

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BaseDocumentLifeCycleHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,9 @@ public static void handleFileRenameForTypeDeclaration(String documentUri) {
387387
IProblem renameProblem = desiredProblem.get();
388388
String newName = renameProblem.getArguments()[1];
389389
String oldName = cu.getElementName();
390-
String newUri = documentUri.replace(oldName, newName + ".java");
390+
int index = oldName.lastIndexOf(".");
391+
String extension = index > 0 ? oldName.substring(index) : ".java";
392+
String newUri = documentUri.replace(oldName, newName + extension);
391393
WorkspaceEdit edit = new WorkspaceEdit(List.of(Either.forRight(new RenameFile(documentUri, newUri))));
392394
edit.setChanges(Collections.emptyMap());
393395
final boolean applyNow = JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isWorkspaceApplyEditSupported();

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BaseInitHandler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@
1919
import java.util.ArrayList;
2020
import java.util.Collection;
2121
import java.util.Collections;
22+
import java.util.List;
2223
import java.util.Map;
2324

2425
import org.eclipse.core.resources.ResourcesPlugin;
2526
import org.eclipse.core.runtime.CoreException;
2627
import org.eclipse.core.runtime.IPath;
28+
import org.eclipse.core.runtime.Platform;
29+
import org.eclipse.core.runtime.content.IContentType;
2730
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
2831
import org.eclipse.core.runtime.preferences.InstanceScope;
32+
import org.eclipse.jdt.core.JavaCore;
33+
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
2934
import org.eclipse.jdt.ls.core.internal.IConstants;
3035
import org.eclipse.jdt.ls.core.internal.JSONUtility;
3136
import org.eclipse.jdt.ls.core.internal.JVMConfigurator;
@@ -57,7 +62,6 @@ public BaseInitHandler(ProjectsManager projectsManager, PreferenceManager prefer
5762
this.projectsManager = projectsManager;
5863
}
5964

60-
@SuppressWarnings("unchecked")
6165
public InitializeResult initialize(InitializeParams param) {
6266
logInfo("Initializing Java Language Server " + JavaLanguageServerPlugin.getVersion());
6367
InitializeResult result = new InitializeResult();
@@ -70,6 +74,7 @@ public InitializeResult initialize(InitializeParams param) {
7074
return result;
7175
}
7276

77+
@SuppressWarnings("unchecked")
7378
public Map<?, ?> handleInitializationOptions(InitializeParams param) {
7479
Map<?, ?> initializationOptions = this.getInitializationOptions(param);
7580
Map<String, Object> extendedClientCapabilities = getInitializationOption(initializationOptions, "extendedClientCapabilities", Map.class);
@@ -109,7 +114,6 @@ public InitializeResult initialize(InitializeParams param) {
109114
rootPaths.add(workspaceLocation);
110115
}
111116
if (initializationOptions.get(SETTINGS_KEY) instanceof Map<?, ?> settings) {
112-
@SuppressWarnings("unchecked")
113117
Preferences prefs = Preferences.createFrom((Map<String, Object>) settings);
114118
prefs.setRootPaths(rootPaths);
115119
preferenceManager.update(prefs);

0 commit comments

Comments
 (0)