Skip to content

Commit

Permalink
Switch to URI#toASCIIString()
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Jan 19, 2023
1 parent c1accd1 commit 8db3165
Show file tree
Hide file tree
Showing 72 changed files with 166 additions and 158 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 Pivotal, Inc.
* Copyright (c) 2017, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -119,6 +119,6 @@ private static FileEvent createFileEventFromDelta(IResourceDelta delta) {
throw new IllegalStateException("Unsupported resource delta kind: " + delta.getKind()); //$NON-NLS-1$
}

return new FileEvent(locationURI.toString(), changeType);
return new FileEvent(locationURI.toASCIIString(), changeType);
}
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 VMware, Inc.
* Copyright (c) 2022, 2023 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -109,7 +109,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
Assert.isLegal(def != null, "No definition found for Boot Language Server");
LanguageServerWrapper wrapper = LanguageServiceAccessor.getLSWrapper(project, def);

final String uri = project.getLocationURI().toString();
final String uri = project.getLocationURI().toASCIIString();
ExecuteCommandParams commandParams = new ExecuteCommandParams();
commandParams.setCommand(REWRITE_REFACTORINGS_LIST);
commandParams.setArguments(List.of(uri, recipeFilter.toString()));
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2019 Pivotal, Inc.
* Copyright (c) 2018, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -79,7 +79,7 @@ public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextVi
List<LSPDocumentInfo> docInfos = LanguageServiceAccessor.getLSPDocumentInfosFor(document, (x) -> true);
if (!docInfos.isEmpty()) {
LSPDocumentInfo info = docInfos.get(0);
HighlightParams highlights = STS4LanguageClientImpl.currentHighlights.get(info.getFileUri().toString());
HighlightParams highlights = STS4LanguageClientImpl.currentHighlights.get(info.getFileUri().toASCIIString());
if (highlights != null) {
return highlights.getCodeLenses().stream()
.filter(codeLens -> codeLens.getCommand() != null)
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Pivotal, Inc.
* Copyright (c) 2017, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -213,7 +213,7 @@ protected void updateSourceViewer(IEditorPart editor) {
} else {
URI uri = Utils.findDocUri(doc);
if (uri != null) {
updateHighlightAnnotations(editor, sourceViewer, annotationModel, uri.toString(), updateCodeMinings);
updateHighlightAnnotations(editor, sourceViewer, annotationModel, uri.toASCIIString(), updateCodeMinings);
}
}
}
Expand Down Expand Up @@ -472,7 +472,7 @@ public CompletableFuture<Object> moveCursor(CursorMovement cursorMovement) {
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
if (doc!=null) {
URI uri = Utils.findDocUri(doc);
if (cursorMovement.getUri().equals(uri.toString())) {
if (cursorMovement.getUri().equals(uri.toASCIIString())) {
org.eclipse.lsp4j.Position pos = cursorMovement.getPosition();
int offset = LSPEclipseUtils.toOffset(pos, doc);
Display.getDefault().asyncExec(() -> {
Expand Down Expand Up @@ -520,7 +520,7 @@ public CompletableFuture<Location> javaLocation(JavaDataParams params) {
if (project != null) {
Location location = new Location();
String label = javaLabelProvider.getText(element);
location.setUri(Utils.eclipseIntroUri(project.getElementName(), params.getBindingKey(), label).toString());
location.setUri(Utils.eclipseIntroUri(project.getElementName(), params.getBindingKey(), label).toASCIIString());
// Set the range because LocationLink needs it to be non-null. The target range
// would highlighted by the eclipse intro URL navigation anyway
location.setRange(new Range());
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2020 Pivotal, Inc.
* Copyright (c) 2018, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -78,7 +78,7 @@ public static boolean isProperDocumentIdFor(IDocument doc, VersionedTextDocument
for (LSPDocumentInfo info : LanguageServiceAccessor.getLSPDocumentInfosFor(doc, (x) -> true)) {
if (info.getVersion() == id.getVersion()) {
URI uri = info.getFileUri();
if (uri != null && uri.toString().equals(id.getUri())) {
if (uri != null && uri.toASCIIString().equals(id.getUri())) {
return true;
}
}
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Pivotal, Inc.
* Copyright (c) 2017, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -74,7 +74,7 @@ private String getUri() {
if (this.info != null) {
LSPDocumentInfo info = this.info.get();
if (info != null) {
return info.getFileUri().toString();
return info.getFileUri().toASCIIString();
}
}
return null;
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Pivotal, Inc.
* Copyright (c) 2019, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -88,7 +88,7 @@ public List<SymbolContainer> fetchFor(String query) throws Exception {
IProject project = this.project.get();

if (project != null) {
String projectLocationPrefix = LSPEclipseUtils.toUri(project).toString();
String projectLocationPrefix = LSPEclipseUtils.toUri(project).toASCIIString();
query = "locationPrefix:" + projectLocationPrefix + "?" + query;

WorkspaceSymbolParams params = new WorkspaceSymbolParams(query);
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Pivotal, Inc.
* Copyright (c) 2017, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -124,18 +124,18 @@ public void deleted(IJavaProject project) {
List<File> nonSystemClasspathEntries = IClasspathUtil.getBinaryRoots(cachedProject.getClasspath(), (cpe) -> !cpe.isSystem());
assertEquals(69, nonSystemClasspathEntries.size());

fileObserver.notifyFileChanged(gradleFile.toURI().toString());
fileObserver.notifyFileChanged(gradleFile.toURI().toASCIIString());
assertNull(projectChanged[0]);

writeContent(gradleFile, Files.contentOf(testProjectPath.resolve("build.newgradle").toFile(), Charset.defaultCharset()));
fileObserver.notifyFileChanged(gradleFile.toURI().toString());
fileObserver.notifyFileChanged(gradleFile.toURI().toASCIIString());
assertNotNull(projectChanged[0]);
assertEquals(cachedProject, projectChanged[0]);
nonSystemClasspathEntries = IClasspathUtil.getBinaryRoots(cachedProject.getClasspath(), (cpe) -> !cpe.isSystem());
assertEquals(70, nonSystemClasspathEntries.size());


fileObserver.notifyFileDeleted(gradleFile.toURI().toString());
fileObserver.notifyFileDeleted(gradleFile.toURI().toASCIIString());
assertEquals(cachedProject, projectDeleted[0]);
} finally {
writeContent(gradleFile, gradelFileContents);
Expand Down
Expand Up @@ -28,7 +28,7 @@ public JavaProject(FileObserver fileObserver, URI uri, IClasspath classpath, Jav
this.fileObserver = fileObserver;
this.javadocProviderFactory = (classpathResource) -> {
CPE cpe = IClasspathUtil.findEntryForBinaryRoot(classpath, classpathResource);
return javadocService.javadocProvider(uri.toString(), cpe);
return javadocService.javadocProvider(uri, cpe);
};
}

Expand Down
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.springframework.ide.vscode.commons.javadoc;

import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand All @@ -33,9 +34,9 @@ public class JdtLsJavadocProvider implements IJavadocProvider {
private static final Logger log = LoggerFactory.getLogger(JdtLsJavadocProvider.class);

private STS4LanguageClient client;
private String projectUri;
private URI projectUri;

public JdtLsJavadocProvider(STS4LanguageClient client, String projectUri) {
public JdtLsJavadocProvider(STS4LanguageClient client, URI projectUri) {
super();
this.client = client;
this.projectUri = projectUri;
Expand All @@ -60,7 +61,7 @@ private IJavadoc javadoc(IJavaElement element) {
long start = System.currentTimeMillis();
try {
log.info("Fetching javadoc {}", element.getBindingKey());
MarkupContent md = client.javadoc(new JavaDataParams(projectUri, element.getBindingKey(), false)).get(10, TimeUnit.SECONDS);
MarkupContent md = client.javadoc(new JavaDataParams(projectUri.toASCIIString(), element.getBindingKey(), false)).get(10, TimeUnit.SECONDS);
log.info("Fetching javadoc {} took {} ms", element.getBindingKey(), System.currentTimeMillis()-start);
return produceJavadocFromMd(md == null ? null : md.getValue());
} catch (InterruptedException | ExecutionException | TimeoutException e) {
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Pivotal, Inc.
* Copyright (c) 2019, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -71,7 +71,7 @@ public JdtLsIndex(STS4LanguageClient client, URI projectUri, ProjectObserver pro
this.client = client;
this.projectUri = projectUri;
this.projectObserver = projectObserver;
this.javadocProvider = new JdtLsJavadocProvider(client, projectUri.toString());
this.javadocProvider = new JdtLsJavadocProvider(client, projectUri);

this.projectListener = ProjectObserver.onAny(project -> {
if (Objects.equals(project.getLocationUri(), projectUri)) {
Expand Down Expand Up @@ -103,7 +103,7 @@ private IType toTypeFromDescriptor(TypeDescriptorData data) {
}

private TypeData findTypeData(String fqName) throws InterruptedException, ExecutionException {
JavaDataParams params = new JavaDataParams(projectUri.toString(), "L" + fqName.replace('.', '/') + ";", false);
JavaDataParams params = new JavaDataParams(projectUri.toASCIIString(), "L" + fqName.replace('.', '/') + ";", false);
return client.javaType(params).get();
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public IType findType(String fqName) {

@Override
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, boolean includeBinaries, boolean includeSystemLibs) {
JavaSearchParams searchParams = new JavaSearchParams(projectUri.toString(), searchTerm, SearchType.FUZZY, includeBinaries, includeSystemLibs, SEARCH_TIMEOUT);
JavaSearchParams searchParams = new JavaSearchParams(projectUri.toASCIIString(), searchTerm, SearchType.FUZZY, includeBinaries, includeSystemLibs, SEARCH_TIMEOUT);
return Mono.fromFuture(client.javaSearchTypes(searchParams))
.flatMapMany(results -> Flux.fromIterable(results).publishOn(Schedulers.parallel()))
.filter(Objects::nonNull)
Expand All @@ -148,7 +148,7 @@ public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, boolean i

@Override
public Flux<Tuple2<String, Double>> fuzzySearchPackages(String searchTerm, boolean includeBinaries, boolean includeSystemLibs) {
JavaSearchParams searchParams = new JavaSearchParams(projectUri.toString(), searchTerm, SearchType.FUZZY, includeBinaries, includeSystemLibs, SEARCH_TIMEOUT);
JavaSearchParams searchParams = new JavaSearchParams(projectUri.toASCIIString(), searchTerm, SearchType.FUZZY, includeBinaries, includeSystemLibs, SEARCH_TIMEOUT);
return Mono.fromFuture(client.javaSearchPackages(searchParams))
.flatMapMany(results -> Flux.fromIterable(results).publishOn(Schedulers.parallel()))
.filter(Objects::nonNull)
Expand All @@ -159,7 +159,7 @@ public Flux<Tuple2<String, Double>> fuzzySearchPackages(String searchTerm, boole
@Override
public Flux<Tuple2<IType, Double>> camelcaseSearchTypes(String searchTerm, boolean includeBinaries,
boolean includeSystemLibs) {
JavaSearchParams searchParams = new JavaSearchParams(projectUri.toString(), searchTerm, SearchType.CAMELCASE, includeBinaries, includeSystemLibs, SEARCH_TIMEOUT);
JavaSearchParams searchParams = new JavaSearchParams(projectUri.toASCIIString(), searchTerm, SearchType.CAMELCASE, includeBinaries, includeSystemLibs, SEARCH_TIMEOUT);
return Mono.fromFuture(client.javaSearchTypes(searchParams))
.flatMapMany(results -> Flux.fromIterable(results).publishOn(Schedulers.parallel()))
.filter(Objects::nonNull)
Expand All @@ -169,7 +169,7 @@ public Flux<Tuple2<IType, Double>> camelcaseSearchTypes(String searchTerm, boole

@Override
public Flux<IType> allSubtypesOf(String fqName, boolean includeFocusType, boolean detailed) {
JavaTypeHierarchyParams searchParams = new JavaTypeHierarchyParams(projectUri.toString(), fqName, includeFocusType, detailed);
JavaTypeHierarchyParams searchParams = new JavaTypeHierarchyParams(projectUri.toASCIIString(), fqName, includeFocusType, detailed);
try {
CompletableFuture<List<IType>> future = subtypesCache.get(searchParams, () -> client
.javaSubTypes(searchParams)
Expand All @@ -184,7 +184,7 @@ public Flux<IType> allSubtypesOf(String fqName, boolean includeFocusType, boolea

@Override
public Flux<IType> allSuperTypesOf(String fqName, boolean includeFocusType, boolean detailed) {
JavaTypeHierarchyParams searchParams = new JavaTypeHierarchyParams(projectUri.toString(), fqName, includeFocusType, detailed);
JavaTypeHierarchyParams searchParams = new JavaTypeHierarchyParams(projectUri.toASCIIString(), fqName, includeFocusType, detailed);
try {
CompletableFuture<List<IType>> future = supertypesCache.get(searchParams, () -> client
.javaSuperTypes(searchParams)
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 VMware, Inc.
* Copyright (c) 2021, 2023 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -65,7 +65,7 @@ public FutureProjectFinder(JavaProjectFinder projectFinder, Optional<ProjectObse
private void resolveAllPendingRquests() {
synchronized(LOCK) {
for (Map.Entry<URI, CompletableFuture<IJavaProject>> e : pendingFindProjectRequests.entrySet()) {
Optional<IJavaProject> jp = projectFinder.find(new TextDocumentIdentifier(e.getKey().toString()));
Optional<IJavaProject> jp = projectFinder.find(new TextDocumentIdentifier(e.getKey().toASCIIString()));
e.getValue().complete(jp.orElse(null));
pendingFindProjectRequests.remove(e.getKey());
}
Expand All @@ -75,7 +75,7 @@ private void resolveAllPendingRquests() {
private void resolvePendingRequests(IJavaProject project) {
synchronized(LOCK) {
for (Map.Entry<URI, CompletableFuture<IJavaProject>> e : pendingFindProjectRequests.entrySet()) {
Optional<IJavaProject> jp = projectFinder.find(new TextDocumentIdentifier(e.getKey().toString()));
Optional<IJavaProject> jp = projectFinder.find(new TextDocumentIdentifier(e.getKey().toASCIIString()));
if (jp.isPresent()) {
e.getValue().complete(jp.get());
pendingFindProjectRequests.remove(e.getKey());
Expand All @@ -92,7 +92,7 @@ public void destroy() throws Exception {
}

public CompletableFuture<IJavaProject> findFuture(URI uri) {
TextDocumentIdentifier id = new TextDocumentIdentifier(uri.toString());
TextDocumentIdentifier id = new TextDocumentIdentifier(uri.toASCIIString());
Optional<IJavaProject> jp = projectFinder.find(id);
if (jp.isPresent()) {
return CompletableFuture.completedFuture(jp.get());
Expand Down
Expand Up @@ -10,11 +10,13 @@
*******************************************************************************/
package org.springframework.ide.vscode.commons.languageserver.java;

import java.net.URI;

import org.springframework.ide.vscode.commons.java.IJavadocProvider;
import org.springframework.ide.vscode.commons.protocol.java.Classpath.CPE;

public interface JavadocService {

IJavadocProvider javadocProvider(String projectUri, CPE classpathEntry);
IJavadocProvider javadocProvider(URI projectUri, CPE classpathEntry);

}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2019 Pivotal, Inc.
* Copyright (c) 2018, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -57,7 +57,7 @@ void createClass(String fqName) throws Exception {
File target = new File(outputFolder, relativePath);
target.getParentFile().mkdirs();
Files.copy(classFile, target);
fileObserver.notifyFileCreated(target.toURI().toString());
fileObserver.notifyFileCreated(target.toURI().toASCIIString());
}

ClasspathData getClasspath() {
Expand All @@ -74,7 +74,7 @@ public void deleteClass(String fqName, BiConsumer<BasicFileObserver, String> eve
String relativePath = fqName.replace('.', '/')+".class";
File classFile = new File(outputFolder, relativePath);
classFile.delete();
eventNoficator.accept(fileObserver, classFile.toURI().toString());
eventNoficator.accept(fileObserver, classFile.toURI().toASCIIString());
}

public void deleteClass(String fqName) {
Expand Down

0 comments on commit 8db3165

Please sign in to comment.