Compare commits
2 Commits
214e80cfa2
...
a447cd3f39
Author | SHA1 | Date | |
---|---|---|---|
|
a447cd3f39 | ||
|
0173dd86da |
@@ -157,6 +157,17 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
List<InlayHint> typeHint = new ArrayList<>();
|
||||
|
||||
for (var typeOfMethod : typesOfMethods) {
|
||||
|
||||
var paramTypes = typeFinder.infereParameterType(currentTextDocument, typeOfMethod.getName());
|
||||
|
||||
for (var paramType : paramTypes) {
|
||||
InlayHint inlayHint = new InlayHint();
|
||||
inlayHint.setLabel(":" + paramType.getType());
|
||||
inlayHint.setPosition(new Position(paramType.getLine()-1, paramType.getCharPosition()-1));
|
||||
inlayHint.setKind(InlayHintKind.Type);
|
||||
typeHint.add(inlayHint);
|
||||
}
|
||||
|
||||
InlayHint inlayHint = new InlayHint();
|
||||
inlayHint.setLabel(":" + typeOfMethod.getType());
|
||||
inlayHint.setPosition(new Position(typeOfMethod.getLine()-1, typeOfMethod.getCharPosition()+1));
|
||||
|
@@ -18,7 +18,7 @@ public class LanguageServerInterface {
|
||||
* */
|
||||
public LanguageServerTransferObject getResultSetAndAbstractSyntax(String input) throws IOException, ClassNotFoundException {
|
||||
|
||||
//System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||
File tempSourcefile = File.createTempFile("temp", ".java");
|
||||
tempSourcefile.deleteOnExit();
|
||||
|
||||
@@ -28,7 +28,7 @@ public class LanguageServerInterface {
|
||||
|
||||
JavaTXCompiler tx = new JavaTXCompiler(tempSourcefile);
|
||||
var test = tx.getResultSetAndAbstractSyntax(tempSourcefile);
|
||||
//System.setOut(System.out);
|
||||
System.setOut(System.out);
|
||||
return test;
|
||||
}
|
||||
}
|
||||
|
@@ -114,7 +114,7 @@ public class TypeFinder {
|
||||
}
|
||||
|
||||
paramTypes.add(possibleTypes.toString().substring(3));
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
paramTypes.add("java.lang.Object");
|
||||
}
|
||||
} else {
|
||||
@@ -141,7 +141,7 @@ public class TypeFinder {
|
||||
return methodNameWithTypeList;
|
||||
}
|
||||
|
||||
public ArrayList<ParameterNameWithType> infereParameterType(String input) throws IOException, ClassNotFoundException {
|
||||
public ArrayList<ParameterNameWithType> infereParameterType(String input, String methodName) throws IOException, ClassNotFoundException {
|
||||
var transferObj = languageServer.getResultSetAndAbstractSyntax(input);
|
||||
System.out.println(transferObj.getResultSets().toString());
|
||||
System.out.println(transferObj.getPrintedAst());
|
||||
@@ -149,15 +149,17 @@ public class TypeFinder {
|
||||
ArrayList<ParameterNameWithType> ParameterNameWithType = new ArrayList<>();
|
||||
|
||||
for (var method : transferObj.getAst().getAllMethods()) {
|
||||
int index = 0;
|
||||
for (var param : method.getParameterList()) {
|
||||
if (method.name.equals(methodName)) {
|
||||
int index = 0;
|
||||
for (var param : method.getParameterList()) {
|
||||
|
||||
var type = findTypeOfParameter(transferObj, method.name);
|
||||
var type = findTypeOfParameter(transferObj, method.name);
|
||||
|
||||
ParameterNameWithType.add(new ParameterNameWithType(method.name, type.get(index), param.getOffset().getLine(), param.getOffset().getStartIndex()));
|
||||
index++;
|
||||
}
|
||||
|
||||
ParameterNameWithType.add(new ParameterNameWithType(method.name, type.get(index), param.getOffset().getLine(), param.getOffset().getStartIndex()));
|
||||
index++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ParameterNameWithType;
|
||||
|
@@ -57,7 +57,7 @@ public class CompilerInterfaceTest {
|
||||
"String i = \"test\";" +
|
||||
"return i;" +
|
||||
"}" +
|
||||
"}"
|
||||
"}", "main"
|
||||
);
|
||||
|
||||
inferedMethods.forEach(el -> System.out.println(el.getName() + ": " + el.getType()));
|
||||
|
Reference in New Issue
Block a user