Refactorings. Bean methods not public.
This commit is contained in:
@@ -21,6 +21,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SpringProjectUtil {
|
||||
|
||||
public static final String SPRING_BOOT = "spring-boot";
|
||||
|
||||
private static final String VERION_PATTERN_STR = "(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?";
|
||||
|
||||
public static final Logger log = LoggerFactory.getLogger(SpringProjectUtil.class);
|
||||
@@ -37,7 +39,7 @@ public class SpringProjectUtil {
|
||||
}
|
||||
|
||||
public static boolean isBootProject(IJavaProject jp) {
|
||||
return hasSpecificLibraryOnClasspath(jp, "spring-boot", true);
|
||||
return hasSpecificLibraryOnClasspath(jp, SPRING_BOOT, true);
|
||||
}
|
||||
|
||||
public static boolean hasBootActuators(IJavaProject jp) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Set;
|
||||
|
||||
import org.eclipse.lsp4j.CodeAction;
|
||||
import org.eclipse.lsp4j.CodeActionCapabilities;
|
||||
import org.eclipse.lsp4j.CodeActionContext;
|
||||
import org.eclipse.lsp4j.Command;
|
||||
import org.eclipse.lsp4j.Hover;
|
||||
import org.eclipse.lsp4j.HoverParams;
|
||||
@@ -105,16 +106,16 @@ public class CompositeLanguageServerComponents implements LanguageServerComponen
|
||||
this.codeActionHandler = new CodeActionHandler() {
|
||||
|
||||
@Override
|
||||
public List<Either<Command, CodeAction>> handle(CancelChecker cancelToken, CodeActionCapabilities capabilities, TextDocument doc,
|
||||
IRegion region) {
|
||||
public List<Either<Command, CodeAction>> handle(CancelChecker cancelToken,
|
||||
CodeActionCapabilities capabilities, CodeActionContext context, TextDocument doc, IRegion region) {
|
||||
LanguageId language = doc.getLanguageId();
|
||||
LanguageServerComponents subComponents = componentsByLanguageId.get(language);
|
||||
if (subComponents != null) {
|
||||
return subComponents.getCodeActionProvider()
|
||||
.map(subEngine -> subEngine.handle(cancelToken, capabilities, doc, region))
|
||||
.map(subEngine -> subEngine.handle(cancelToken, capabilities, context, doc, region))
|
||||
.orElse(Collections.emptyList());
|
||||
}
|
||||
//No applicable subEngine...
|
||||
// No applicable subEngine...
|
||||
return Collections.emptyList();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2022 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
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* VMware, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.languageserver.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.CodeAction;
|
||||
import org.eclipse.lsp4j.CodeActionCapabilities;
|
||||
import org.eclipse.lsp4j.CodeActionContext;
|
||||
import org.eclipse.lsp4j.Command;
|
||||
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
@@ -12,6 +23,6 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
public interface CodeActionHandler {
|
||||
|
||||
List<Either<Command, CodeAction>> handle(CancelChecker cancelToken, CodeActionCapabilities capabilities, TextDocument doc, IRegion region);
|
||||
List<Either<Command, CodeAction>> handle(CancelChecker cancelToken, CodeActionCapabilities capabilities, CodeActionContext context, TextDocument doc, IRegion region);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ import java.util.stream.Collectors;
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.CodeAction;
|
||||
import org.eclipse.lsp4j.CodeActionCapabilities;
|
||||
import org.eclipse.lsp4j.CodeActionContext;
|
||||
import org.eclipse.lsp4j.CodeActionKind;
|
||||
import org.eclipse.lsp4j.CodeActionParams;
|
||||
import org.eclipse.lsp4j.CodeLens;
|
||||
import org.eclipse.lsp4j.CodeLensParams;
|
||||
@@ -82,6 +84,7 @@ import org.springframework.ide.vscode.commons.util.text.Region;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
|
||||
public class SimpleTextDocumentService implements TextDocumentService, DocumentEventListenerManager {
|
||||
|
||||
@@ -425,23 +428,27 @@ public class SimpleTextDocumentService implements TextDocumentService, DocumentE
|
||||
}
|
||||
|
||||
private List<Either<Command, CodeAction>> computeCodeActions(CancelChecker cancelToken, CodeActionCapabilities capabilities, TrackedDocument doc, CodeActionParams params) {
|
||||
List<Either<Command,CodeAction>> list = doc.getQuickfixes().stream()
|
||||
.filter((fix) -> fix.appliesTo(params.getRange(), params.getContext()))
|
||||
.map(f -> f.getCodeAction(params.getContext()))
|
||||
.map(command -> Either.<Command, CodeAction>forRight(command))
|
||||
.collect(Collectors.toList());
|
||||
Builder<Either<Command,CodeAction>> listBuilder = ImmutableList.builder();
|
||||
CodeActionContext context = params.getContext();
|
||||
if (!context.getDiagnostics().isEmpty() || (context.getOnly() != null && context.getOnly().contains(CodeActionKind.QuickFix))) {
|
||||
doc.getQuickfixes().stream()
|
||||
.filter((fix) -> fix.appliesTo(params.getRange(), context))
|
||||
.map(f -> f.getCodeAction(params.getContext()))
|
||||
.map(command -> Either.<Command, CodeAction>forRight(command))
|
||||
.forEach(listBuilder::add);
|
||||
}
|
||||
|
||||
if (codeActionHandler != null) {
|
||||
try {
|
||||
int start = doc.getDocument().toOffset(params.getRange().getStart());
|
||||
int end = doc.getDocument().toOffset(params.getRange().getEnd());
|
||||
list.addAll(codeActionHandler.handle(cancelToken, capabilities, doc.getDocument(), new Region(start, end - start)));
|
||||
listBuilder.addAll(codeActionHandler.handle(cancelToken, capabilities, context, doc.getDocument(), new Region(start, end - start)));
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to compute quick refactorings", e);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
private static CodeActionCapabilities getCodeActionCapabilities(ClientCapabilities capabilities) {
|
||||
|
||||
Reference in New Issue
Block a user