Compare commits
2 Commits
d9177cbdf2
...
cabb7258aa
Author | SHA1 | Date | |
---|---|---|---|
|
cabb7258aa | ||
|
25a1876b8f |
Binary file not shown.
@@ -152,8 +152,8 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
|
public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
|
||||||
|
|
||||||
logger.debug("INLAYHINT-EVENT");
|
logger.debug("INLAYHINT-EVENT");
|
||||||
|
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
@@ -163,13 +163,10 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
for (var variable : typesOfMethodAndParameters) {
|
for (var variable : typesOfMethodAndParameters) {
|
||||||
|
|
||||||
|
|
||||||
InlayHint inlayHint = new InlayHint();
|
InlayHint inlayHint = new InlayHint();
|
||||||
|
|
||||||
AtomicReference<String> typeDisplay = new AtomicReference<String>();
|
AtomicReference<String> typeDisplay = new AtomicReference<>();
|
||||||
variable.getPossibleTypes().forEach(el -> {
|
variable.getPossibleTypes().forEach(el -> typeDisplay.getAndSet("| " + el));
|
||||||
typeDisplay.getAndSet("| " + el);
|
|
||||||
});
|
|
||||||
|
|
||||||
inlayHint.setLabel(typeDisplay.get().substring(2));
|
inlayHint.setLabel(typeDisplay.get().substring(2));
|
||||||
inlayHint.setPosition(new Position(variable.getLine() - 1, variable.getCharPosition()));
|
inlayHint.setPosition(new Position(variable.getLine() - 1, variable.getCharPosition()));
|
||||||
@@ -177,6 +174,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
typeHint.add(inlayHint);
|
typeHint.add(inlayHint);
|
||||||
|
|
||||||
|
|
||||||
|
//Diagnostics of Types
|
||||||
for (var typ : variable.getPossibleTypes()) {
|
for (var typ : variable.getPossibleTypes()) {
|
||||||
Range errorRange = new Range(
|
Range errorRange = new Range(
|
||||||
new Position(variable.getLine() - 1, variable.getCharPosition()), // Startposition
|
new Position(variable.getLine() - 1, variable.getCharPosition()), // Startposition
|
||||||
@@ -345,30 +343,37 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
|
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
|
||||||
logger.debug("INSERT-EVENT");
|
logger.debug("INSERT-EVENT");
|
||||||
List<Diagnostic> diagnostics = params.getContext().getDiagnostics();
|
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
List<Diagnostic> diagnosticInCurrentDocument = params.getContext().getDiagnostics();
|
||||||
Range requestedRange = params.getRange();
|
Range requestedRange = params.getRange();
|
||||||
|
|
||||||
List<Diagnostic> relevantDiagnostics = diagnostics.stream()
|
//All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
|
||||||
|
List<Diagnostic> diagnosticsOverlappingHover = diagnosticInCurrentDocument.stream()
|
||||||
.filter(diagnostic -> rangesOverlap(diagnostic.getRange(), requestedRange)).toList();
|
.filter(diagnostic -> rangesOverlap(diagnostic.getRange(), requestedRange)).toList();
|
||||||
|
|
||||||
Range range = params.getRange();
|
Range rangeOfInsert = params.getRange();
|
||||||
String documentUri = params.getTextDocument().getUri();
|
String documentUri = params.getTextDocument().getUri();
|
||||||
|
|
||||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
|
||||||
for (Diagnostic typeDiagnostic : relevantDiagnostics) {
|
for (Diagnostic typeDiagnostic : diagnosticsOverlappingHover) {
|
||||||
try {
|
try {
|
||||||
String typeWithReplacedVariable = typeDiagnostic.getMessage() +
|
String typeWithReplacedVariable = typeDiagnostic.getMessage() +
|
||||||
" " +
|
" " +
|
||||||
textHelper.getTextOfChars(
|
textHelper.getTextOfChars(
|
||||||
textDocuments.get(params.getTextDocument().getUri()),
|
textDocuments.get(params.getTextDocument().getUri()),
|
||||||
range.getStart().getLine(),
|
rangeOfInsert.getStart().getLine(),
|
||||||
range.getStart().getCharacter(),
|
rangeOfInsert.getStart().getCharacter(),
|
||||||
range.getEnd().getCharacter()
|
rangeOfInsert.getEnd().getCharacter()
|
||||||
);
|
);
|
||||||
|
|
||||||
var listOfChanges = new ArrayList<>(List.of(new TextEdit(range, typeWithReplacedVariable)));
|
ArrayList<TextEdit> listOfChanges = new ArrayList<>();
|
||||||
|
|
||||||
|
listOfChanges.add(new TextEdit(rangeOfInsert, typeWithReplacedVariable));
|
||||||
|
|
||||||
var isTypeImported = typeResolver.isTypeImported(textDocuments.get(params.getTextDocument().getUri()), typeDiagnostic.getMessage());
|
var isTypeImported = typeResolver.isTypeImported(textDocuments.get(params.getTextDocument().getUri()), typeDiagnostic.getMessage());
|
||||||
|
|
||||||
if (!isTypeImported) {
|
if (!isTypeImported) {
|
||||||
Range importRange = new Range(new Position(0, 0), new Position(0, 0));
|
Range importRange = new Range(new Position(0, 0), new Position(0, 0));
|
||||||
|
|
||||||
@@ -377,6 +382,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Returning " + listOfChanges.size() + " Changes for the Document.");
|
logger.debug("Returning " + listOfChanges.size() + " Changes for the Document.");
|
||||||
|
|
||||||
Map<String, List<TextEdit>> changes = new HashMap<>();
|
Map<String, List<TextEdit>> changes = new HashMap<>();
|
||||||
changes.put(documentUri, listOfChanges);
|
changes.put(documentUri, listOfChanges);
|
||||||
|
|
||||||
@@ -387,8 +393,8 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
action.setKind(CodeActionKind.QuickFix);
|
action.setKind(CodeActionKind.QuickFix);
|
||||||
action.setEdit(edit);
|
action.setEdit(edit);
|
||||||
actions.add(Either.forRight(action));
|
actions.add(Either.forRight(action));
|
||||||
} catch (Exception ignored) {
|
} catch (Exception e) {
|
||||||
|
logger.error("Error creating Actions, returning empty List. The Error was: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,38 @@ public class TypeResolver {
|
|||||||
languageServer = new LanguageServerInterface();
|
languageServer = new LanguageServerInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private LanguageServerTransferObject getCacheOrCalculate(String input) throws IOException, ClassNotFoundException {
|
||||||
|
if(dataCache.containsKey(input)){
|
||||||
|
logger.debug("Returning Cache instead of calculating Types.");
|
||||||
|
return dataCache.get(input);
|
||||||
|
}else{
|
||||||
|
var transferObject = languageServer.getResultSetAndAbstractSyntax(input);
|
||||||
|
dataCache.put(input, transferObject);
|
||||||
|
return transferObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTypeImported(String input, String type){
|
||||||
|
try {
|
||||||
|
var transferObject = getCacheOrCalculate(input);
|
||||||
|
var abstractSyntax = transferObject.getAst();
|
||||||
|
|
||||||
|
var isAlreadyImported = false;
|
||||||
|
for(var importStatement : abstractSyntax.getImports()){
|
||||||
|
logger.debug(importStatement.toString() + "<>" + type);
|
||||||
|
isAlreadyImported = !isAlreadyImported && importStatement.toString().equals(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
return isAlreadyImported;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error creating Transferobject: " + Arrays.toString(e.getStackTrace()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find the concrete Type of all TPHs and return the outcome as Hashmap.
|
* find the concrete Type of all TPHs and return the outcome as Hashmap.
|
||||||
*/
|
*/
|
||||||
@@ -79,36 +111,6 @@ public class TypeResolver {
|
|||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private LanguageServerTransferObject getCacheOrCalculate(String input) throws IOException, ClassNotFoundException {
|
|
||||||
if(dataCache.containsKey(input)){
|
|
||||||
logger.debug("Returning Cache instead of calculating Types.");
|
|
||||||
return dataCache.get(input);
|
|
||||||
}else{
|
|
||||||
var transferObject = languageServer.getResultSetAndAbstractSyntax(input);
|
|
||||||
dataCache.put(input, transferObject);
|
|
||||||
return transferObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTypeImported(String input, String type){
|
|
||||||
try {
|
|
||||||
var transferObject = getCacheOrCalculate(input);
|
|
||||||
var abstractSyntax = transferObject.getAst();
|
|
||||||
|
|
||||||
var isAlreadyImported = false;
|
|
||||||
for(var importStatement : abstractSyntax.getImports()){
|
|
||||||
logger.debug(importStatement.toString() + "<>" + type);
|
|
||||||
isAlreadyImported = !isAlreadyImported && importStatement.toString().equals(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
return isAlreadyImported;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Error creating Transferobject: " + Arrays.toString(e.getStackTrace()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<ArrayList<String>> findTypesOfAllParameters(LanguageServerTransferObject transferObj, Method method) throws IOException, ClassNotFoundException {
|
public ArrayList<ArrayList<String>> findTypesOfAllParameters(LanguageServerTransferObject transferObj, Method method) throws IOException, ClassNotFoundException {
|
||||||
|
|
||||||
@@ -142,13 +144,13 @@ public class TypeResolver {
|
|||||||
public ArrayList<LSPVariable> infereMethodsWithParameters(String input) throws IOException, ClassNotFoundException {
|
public ArrayList<LSPVariable> infereMethodsWithParameters(String input) throws IOException, ClassNotFoundException {
|
||||||
var transferObj = getCacheOrCalculate(input);
|
var transferObj = getCacheOrCalculate(input);
|
||||||
|
|
||||||
ArrayList<LSPVariable> methodLSPVariableList = new ArrayList<>();
|
ArrayList<LSPVariable> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||||
|
|
||||||
for (var method : transferObj.getAst().getAllMethods()) {
|
for (var method : transferObj.getAst().getAllMethods()) {
|
||||||
|
|
||||||
var type = findTypeOfMethod(transferObj, method);
|
var type = findTypeOfMethod(transferObj, method);
|
||||||
if (!type.isEmpty()) {
|
if (!type.isEmpty()) {
|
||||||
methodLSPVariableList.add(new LSPMethod(method.name, type, method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, type, method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
var paramType = findTypesOfAllParameters(transferObj, method);
|
var paramType = findTypesOfAllParameters(transferObj, method);
|
||||||
@@ -157,20 +159,19 @@ public class TypeResolver {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
for (var param : method.getParameterList()) {
|
for (var param : method.getParameterList()) {
|
||||||
if (paramType.get(index) != null && !paramType.get(index).isEmpty()) {
|
if (paramType.get(index) != null && !paramType.get(index).isEmpty()) {
|
||||||
methodLSPVariableList.add(new LSPParameter(method.name, paramType.get(index), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, paramType.get(index), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return methodLSPVariableList;
|
return methodsWithParametersLSPVariableList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public ArrayList<LSPMethod> infereMethodType(String input) throws IOException, ClassNotFoundException {
|
public ArrayList<LSPMethod> infereMethodType(String input) throws IOException, ClassNotFoundException {
|
||||||
var transferObj = getCacheOrCalculate(input);
|
var transferObj = getCacheOrCalculate(input);
|
||||||
//Für RefTypes und so dann entsprechend InstanceOf durch den Syntaxbaum denke ich
|
|
||||||
ArrayList<LSPMethod> methodNameWithTypeList = new ArrayList<>();
|
ArrayList<LSPMethod> methodNameWithTypeList = new ArrayList<>();
|
||||||
|
|
||||||
for (var method : transferObj.getAst().getAllMethods()) {
|
for (var method : transferObj.getAst().getAllMethods()) {
|
||||||
|
Reference in New Issue
Block a user