Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1cc679afb4 | |||
| 40e5549062 | |||
| 4e4eb45842 | |||
| c0a30af6ef |
Binary file not shown.
+106
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "java-tx-language-extension",
|
"name": "java-tx-language-extension",
|
||||||
"version": "0.0.19",
|
"version": "0.0.21",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "java-tx-language-extension",
|
"name": "java-tx-language-extension",
|
||||||
"version": "0.0.19",
|
"version": "0.0.21",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vscode/vsce": "^3.6.1",
|
"@vscode/vsce": "^3.6.1",
|
||||||
"vscode-languageclient": "^9.0.1"
|
"vscode-languageclient": "^9.0.1"
|
||||||
@@ -1054,6 +1054,32 @@
|
|||||||
"@vscode/vsce-sign-win32-x64": "2.0.6"
|
"@vscode/vsce-sign-win32-x64": "2.0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@vscode/vsce-sign-alpine-arm64": {
|
||||||
|
"version": "2.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vscode/vsce-sign-alpine-arm64/-/vsce-sign-alpine-arm64-2.0.6.tgz",
|
||||||
|
"integrity": "sha512-wKkJBsvKF+f0GfsUuGT0tSW0kZL87QggEiqNqK6/8hvqsXvpx8OsTEc3mnE1kejkh5r+qUyQ7PtF8jZYN0mo8Q==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"alpine"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@vscode/vsce-sign-alpine-x64": {
|
||||||
|
"version": "2.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vscode/vsce-sign-alpine-x64/-/vsce-sign-alpine-x64-2.0.6.tgz",
|
||||||
|
"integrity": "sha512-YoAGlmdK39vKi9jA18i4ufBbd95OqGJxRvF3n6ZbCyziwy3O+JgOpIUPxv5tjeO6gQfx29qBivQ8ZZTUF2Ba0w==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"alpine"
|
||||||
|
]
|
||||||
|
},
|
||||||
"node_modules/@vscode/vsce-sign-darwin-arm64": {
|
"node_modules/@vscode/vsce-sign-darwin-arm64": {
|
||||||
"version": "2.0.6",
|
"version": "2.0.6",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
@@ -1065,6 +1091,84 @@
|
|||||||
"darwin"
|
"darwin"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"node_modules/@vscode/vsce-sign-darwin-x64": {
|
||||||
|
"version": "2.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vscode/vsce-sign-darwin-x64/-/vsce-sign-darwin-x64-2.0.6.tgz",
|
||||||
|
"integrity": "sha512-25GsUbTAiNfHSuRItoQafXOIpxlYj+IXb4/qarrXu7kmbH94jlm5sdWSCKrrREs8+GsXF1b+l3OB7VJy5jsykw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"darwin"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@vscode/vsce-sign-linux-arm": {
|
||||||
|
"version": "2.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vscode/vsce-sign-linux-arm/-/vsce-sign-linux-arm-2.0.6.tgz",
|
||||||
|
"integrity": "sha512-UndEc2Xlq4HsuMPnwu7420uqceXjs4yb5W8E2/UkaHBB9OWCwMd3/bRe/1eLe3D8kPpxzcaeTyXiK3RdzS/1CA==",
|
||||||
|
"cpu": [
|
||||||
|
"arm"
|
||||||
|
],
|
||||||
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@vscode/vsce-sign-linux-arm64": {
|
||||||
|
"version": "2.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vscode/vsce-sign-linux-arm64/-/vsce-sign-linux-arm64-2.0.6.tgz",
|
||||||
|
"integrity": "sha512-cfb1qK7lygtMa4NUl2582nP7aliLYuDEVpAbXJMkDq1qE+olIw/es+C8j1LJwvcRq1I2yWGtSn3EkDp9Dq5FdA==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@vscode/vsce-sign-linux-x64": {
|
||||||
|
"version": "2.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vscode/vsce-sign-linux-x64/-/vsce-sign-linux-x64-2.0.6.tgz",
|
||||||
|
"integrity": "sha512-/olerl1A4sOqdP+hjvJ1sbQjKN07Y3DVnxO4gnbn/ahtQvFrdhUi0G1VsZXDNjfqmXw57DmPi5ASnj/8PGZhAA==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@vscode/vsce-sign-win32-arm64": {
|
||||||
|
"version": "2.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vscode/vsce-sign-win32-arm64/-/vsce-sign-win32-arm64-2.0.6.tgz",
|
||||||
|
"integrity": "sha512-ivM/MiGIY0PJNZBoGtlRBM/xDpwbdlCWomUWuLmIxbi1Cxe/1nooYrEQoaHD8ojVRgzdQEUzMsRbyF5cJJgYOg==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@vscode/vsce-sign-win32-x64": {
|
||||||
|
"version": "2.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vscode/vsce-sign-win32-x64/-/vsce-sign-win32-x64-2.0.6.tgz",
|
||||||
|
"integrity": "sha512-mgth9Kvze+u8CruYMmhHw6Zgy3GRX2S+Ed5oSokDEK5vPEwGGKnmuXua9tmFhomeAnhgJnL4DCna3TiNuGrBTQ==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
]
|
||||||
|
},
|
||||||
"node_modules/@vscode/vsce/node_modules/brace-expansion": {
|
"node_modules/@vscode/vsce/node_modules/brace-expansion": {
|
||||||
"version": "1.1.12",
|
"version": "1.1.12",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"name": "java-tx-language-extension",
|
"name": "java-tx-language-extension",
|
||||||
"displayName": "Java-TX Language Extension",
|
"displayName": "Java-TX Language Extension",
|
||||||
"description": "The Language Extension for Java-TX with Typehints and Syntax Checks",
|
"description": "The Language Extension for Java-TX with Typehints and Syntax Checks",
|
||||||
"version": "0.0.19",
|
"version": "0.0.21",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.94.0"
|
"vscode": "^1.94.0"
|
||||||
},
|
},
|
||||||
|
|||||||
+28
-1
@@ -14,6 +14,11 @@
|
|||||||
<version>4.11</version>
|
<version>4.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.antlr</groupId>
|
||||||
|
<artifactId>antlr4</artifactId>
|
||||||
|
<version>4.13.2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
@@ -67,7 +72,6 @@
|
|||||||
<release>21</release>
|
<release>21</release>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
@@ -91,6 +95,29 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-fat-jar</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<target>
|
||||||
|
<mkdir dir="${project.basedir}/../Clients/VisualStudioCode"/>
|
||||||
|
<copy
|
||||||
|
file="${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar"
|
||||||
|
todir="${project.basedir}/../Clients/VisualStudioCode"
|
||||||
|
overwrite="true"/>
|
||||||
|
</target>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@@ -3,6 +3,7 @@ package de.dhbw.handler;
|
|||||||
import com.google.common.base.Stopwatch;
|
import com.google.common.base.Stopwatch;
|
||||||
import de.dhbw.helper.ConversionHelper;
|
import de.dhbw.helper.ConversionHelper;
|
||||||
import de.dhbw.helper.TypeResolver;
|
import de.dhbw.helper.TypeResolver;
|
||||||
|
import de.dhbw.helper.TypeResolver.InferenceResult;
|
||||||
import de.dhbw.model.*;
|
import de.dhbw.model.*;
|
||||||
import de.dhbw.service.*;
|
import de.dhbw.service.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
@@ -107,105 +108,101 @@ public class ChangeHandler {
|
|||||||
|
|
||||||
logService.log("Should Calculate is: " + shouldCalculate);
|
logService.log("Should Calculate is: " + shouldCalculate);
|
||||||
|
|
||||||
if (false) {
|
|
||||||
try {
|
/*try {
|
||||||
File tempDir = new File(System.getProperty("java.io.tmpdir"));
|
File tempDir = new File(System.getProperty("java.io.tmpdir"));
|
||||||
File tempFile = File.createTempFile("newText", ".tmp", tempDir);
|
File tempFile = File.createTempFile("newText", ".tmp", tempDir);
|
||||||
FileWriter fileWriter = new FileWriter(tempFile, true);
|
FileWriter fileWriter = new FileWriter(tempFile, true);
|
||||||
System.out.println(tempFile.getAbsolutePath());
|
System.out.println(tempFile.getAbsolutePath());
|
||||||
BufferedWriter bw = new BufferedWriter(fileWriter);
|
BufferedWriter bw = new BufferedWriter(fileWriter);
|
||||||
bw.write(summedUp.get());
|
bw.write(summedUp.get());
|
||||||
bw.close();
|
bw.close();
|
||||||
typeResolver.updateAst(tempFile.toURI().getPath());
|
typeResolver.updateAst(tempFile.toURI().getPath());
|
||||||
tempFile.delete();
|
tempFile.delete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logService.log(e.getMessage());
|
logService.log(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
var sWatch = Stopwatch.createUnstarted();
|
||||||
|
sWatch.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereChangeInput();
|
||||||
|
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(typesOfMethodAndParameters, params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
||||||
|
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
||||||
|
|
||||||
|
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logService.log("[didChange] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||||
|
for (var stackTrace : e.getStackTrace()) {
|
||||||
|
logService.log(stackTrace.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
var sWatch = Stopwatch.createUnstarted();
|
clientService.showMessage(MessageType.Error, e.getMessage());
|
||||||
sWatch.start();
|
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
sWatch.stop();
|
||||||
|
logService.log("[didChange] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Diagnostic> typeDiagnostics = cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri());
|
||||||
|
ArrayList<Diagnostic> allDiagnostics = new ArrayList<>(typeDiagnostics);
|
||||||
|
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);*/
|
||||||
|
|
||||||
|
logService.log("Calculating again.");
|
||||||
|
var sWatch = Stopwatch.createUnstarted();
|
||||||
|
sWatch.start();
|
||||||
|
|
||||||
|
try {
|
||||||
try {
|
try {
|
||||||
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereChangeInput();
|
File tempDir2 = Path.of(new URI(params.getTextDocument().getUri())).getParent().toFile();
|
||||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(typesOfMethodAndParameters, params.getTextDocument().getUri());
|
File tempFile2 = File.createTempFile("jtx_temp", ".tmp", tempDir2);
|
||||||
|
FileWriter fileWriter = new FileWriter(tempFile2, true);
|
||||||
|
BufferedWriter bw = new BufferedWriter(fileWriter);
|
||||||
|
bw.write(input);
|
||||||
|
bw.close();
|
||||||
|
|
||||||
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
try {
|
||||||
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
InferenceResult inferenceResult = typeResolver.infereInput(tempFile2.toURI().toString(), input);
|
||||||
|
cacheService.setVariables(inferenceResult.variables());
|
||||||
|
|
||||||
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehintsWithInput(inferenceResult, input);
|
||||||
|
|
||||||
} catch (Exception e) {
|
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
||||||
logService.log("[didChange] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
||||||
for (var stackTrace : e.getStackTrace()) {
|
|
||||||
logService.log(stackTrace.toString());
|
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
||||||
|
|
||||||
|
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
|
||||||
|
|
||||||
|
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
|
||||||
|
} catch (Exception | VerifyError f) {
|
||||||
|
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + f.getMessage(), MessageType.Error);
|
||||||
|
|
||||||
|
for (StackTraceElement elem : f.getStackTrace()) {
|
||||||
|
logService.log(elem.toString());
|
||||||
|
}
|
||||||
|
clientService.showMessage(MessageType.Error, f.getMessage() == null ? "null" : f.getMessage());
|
||||||
|
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||||
}
|
}
|
||||||
|
tempFile2.delete();
|
||||||
clientService.showMessage(MessageType.Error, e.getMessage());
|
} catch (Exception e) {
|
||||||
|
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
||||||
|
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
||||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
sWatch.stop();
|
sWatch.stop();
|
||||||
logService.log("[didChange] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
||||||
}
|
|
||||||
|
|
||||||
List<Diagnostic> typeDiagnostics = cacheService.getGlobalDiagnosticsMap().get(params.getTextDocument().getUri());
|
|
||||||
ArrayList<Diagnostic> allDiagnostics = new ArrayList<>(typeDiagnostics);
|
|
||||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
|
|
||||||
} else {
|
|
||||||
logService.log("Calculating again.");
|
|
||||||
var sWatch = Stopwatch.createUnstarted();
|
|
||||||
sWatch.start();
|
|
||||||
|
|
||||||
try {
|
|
||||||
try {
|
|
||||||
File tempDir2 = Path.of(new URI(params.getTextDocument().getUri())).getParent().toFile();
|
|
||||||
File tempFile2 = File.createTempFile("jtx_temp", ".tmp", tempDir2);
|
|
||||||
FileWriter fileWriter = new FileWriter(tempFile2, true);
|
|
||||||
BufferedWriter bw = new BufferedWriter(fileWriter);
|
|
||||||
bw.write(input);
|
|
||||||
bw.close();
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString(), input);
|
|
||||||
cacheService.setVariables(variables);
|
|
||||||
|
|
||||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehintsWithInput(variables, input);
|
|
||||||
|
|
||||||
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
|
||||||
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
|
||||||
|
|
||||||
cacheService.updateGlobalMaps(diagnostics, typeHint, params.getTextDocument().getUri());
|
|
||||||
|
|
||||||
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
|
|
||||||
|
|
||||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
|
|
||||||
} catch (Exception | VerifyError f) {
|
|
||||||
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + f.getMessage(), MessageType.Error);
|
|
||||||
|
|
||||||
for (StackTraceElement elem : f.getStackTrace()) {
|
|
||||||
logService.log(elem.toString());
|
|
||||||
}
|
|
||||||
clientService.showMessage(MessageType.Error, f.getMessage() == null ? "null" : f.getMessage());
|
|
||||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
|
||||||
}
|
|
||||||
tempFile2.delete();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
|
||||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
|
||||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), params.getTextDocument().getUri());
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
sWatch.stop();
|
|
||||||
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logService.log(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logService.log(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package de.dhbw.handler;
|
package de.dhbw.handler;
|
||||||
|
|
||||||
|
import de.dhbw.helper.ASTTransformationHelper;
|
||||||
import de.dhbw.helper.ConversionHelper;
|
import de.dhbw.helper.ConversionHelper;
|
||||||
|
import de.dhbw.helper.InsertPoint;
|
||||||
import de.dhbw.helper.TextHelper;
|
import de.dhbw.helper.TextHelper;
|
||||||
import de.dhbw.helper.TypeResolver;
|
import de.dhbw.helper.TypeResolver;
|
||||||
import de.dhbw.service.CacheService;
|
import de.dhbw.service.CacheService;
|
||||||
@@ -68,8 +70,8 @@ public class CodeActionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static <V> Map<String, V> getOverlapping(
|
public static <V> Map<InsertPoint, V> getOverlapping(
|
||||||
Map<String, V> map,
|
Map<InsertPoint, V> map,
|
||||||
int line,
|
int line,
|
||||||
int startChar,
|
int startChar,
|
||||||
int endChar
|
int endChar
|
||||||
@@ -83,20 +85,13 @@ public class CodeActionHandler {
|
|||||||
final int s = startChar, e = endChar;
|
final int s = startChar, e = endChar;
|
||||||
|
|
||||||
return map.entrySet().stream()
|
return map.entrySet().stream()
|
||||||
.filter(entry -> {
|
.filter(entry -> {
|
||||||
String key = entry.getKey();
|
InsertPoint key = entry.getKey();
|
||||||
String[] parts = key.split("\\s+");
|
int kLine = key.line();
|
||||||
if (parts.length != 2) return false;
|
int kChar = key.character();
|
||||||
try {
|
return kLine == line && kChar >= s && kChar <= e;
|
||||||
int kLine = Integer.parseInt(parts[0]);
|
})
|
||||||
int kChar = Integer.parseInt(parts[1]);
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
return kLine == line && kChar >= s && kChar <= e;
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
// Key nicht im erwarteten Format
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -107,9 +102,9 @@ public class CodeActionHandler {
|
|||||||
|
|
||||||
if (typeResolver.getInserts() != null) {
|
if (typeResolver.getInserts() != null) {
|
||||||
//All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
|
//All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
|
||||||
Map<String, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter());
|
Map<InsertPoint, List<PlaceholderVariable>> typeInsertsOverlapping = getOverlapping(typeResolver.getInserts(), rangeOfInsert.getStart().getLine() + 1, rangeOfInsert.getStart().getCharacter(), rangeOfInsert.getEnd().getCharacter());
|
||||||
logService.log("Inserts are:");
|
logService.log("Inserts are:");
|
||||||
typeResolver.getInserts().forEach((key, value) -> logService.log(key));
|
typeResolver.getInserts().forEach((key, value) -> logService.log(key.toString()));
|
||||||
logService.log("Size is: " + typeInsertsOverlapping.size());
|
logService.log("Size is: " + typeInsertsOverlapping.size());
|
||||||
logService.log("Range is: " + rangeOfInsert.getStart().getLine() + " -> " + rangeOfInsert.getStart().getCharacter() + " - " + rangeOfInsert.getEnd().getCharacter());
|
logService.log("Range is: " + rangeOfInsert.getStart().getLine() + " -> " + rangeOfInsert.getStart().getCharacter() + " - " + rangeOfInsert.getEnd().getCharacter());
|
||||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
||||||
@@ -125,15 +120,18 @@ public class CodeActionHandler {
|
|||||||
|
|
||||||
listOfChanges.add(new TextEdit(wholeDocumentRange(textDocumentService.getFileOfUri(documentUri)), typeWithReplacedVariable));
|
listOfChanges.add(new TextEdit(wholeDocumentRange(textDocumentService.getFileOfUri(documentUri)), typeWithReplacedVariable));
|
||||||
|
|
||||||
var isTypeImported = false;
|
|
||||||
|
|
||||||
Map<String, List<TextEdit>> changes = new HashMap<>();
|
Map<String, List<TextEdit>> changes = new HashMap<>();
|
||||||
changes.put(documentUri, listOfChanges);
|
changes.put(documentUri, listOfChanges);
|
||||||
|
|
||||||
WorkspaceEdit edit = new WorkspaceEdit();
|
WorkspaceEdit edit = new WorkspaceEdit();
|
||||||
edit.setChanges(changes);
|
edit.setChanges(changes);
|
||||||
|
|
||||||
CodeAction action = new CodeAction("Insert " + conversionHelper.cleanType(typeInsert.getInsertString()));
|
var constraints = typeInsert.getConstraints();
|
||||||
|
var genericsString = "";
|
||||||
|
if (constraints != null && !constraints.isEmpty()) {
|
||||||
|
genericsString = ASTTransformationHelper.createConstraintsString(constraints);
|
||||||
|
}
|
||||||
|
CodeAction action = new CodeAction("Insert " + ConversionHelper.cleanType(typeInsert.getInsertString()) + genericsString);
|
||||||
action.setKind(CodeActionKind.QuickFix);
|
action.setKind(CodeActionKind.QuickFix);
|
||||||
action.setEdit(edit);
|
action.setEdit(edit);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import de.dhbw.model.DiagnosticsAndTypehints;
|
|||||||
import de.dhbw.service.*;
|
import de.dhbw.service.*;
|
||||||
import de.dhbw.helper.ConversionHelper;
|
import de.dhbw.helper.ConversionHelper;
|
||||||
import de.dhbw.helper.TypeResolver;
|
import de.dhbw.helper.TypeResolver;
|
||||||
|
import de.dhbw.helper.TypeResolver.InferenceResult;
|
||||||
import de.dhbw.model.LSPVariable;
|
import de.dhbw.model.LSPVariable;
|
||||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
||||||
@@ -65,10 +66,10 @@ public class SaveHandler {
|
|||||||
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
InferenceResult inferenceResult = typeResolver.infereInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
||||||
cacheService.setVariables(variables);
|
cacheService.setVariables(inferenceResult.variables());
|
||||||
|
|
||||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(variables, didSaveTextDocumentParams.getTextDocument().getUri());
|
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(inferenceResult, didSaveTextDocumentParams.getTextDocument().getUri());
|
||||||
|
|
||||||
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
||||||
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
||||||
|
|||||||
@@ -15,12 +15,13 @@ import de.dhbwstuttgart.typeinference.result.*;
|
|||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ASTTransformationHelper {
|
public class ASTTransformationHelper {
|
||||||
|
|
||||||
public static Set<PlaceholderVariable> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults, GenericsResult generics) {
|
public static Set<PlaceholderVariable> createTypeInsertPoints(SourceFile forSourcefile, GenericsResult generics) {
|
||||||
return new PlaceholderPlacer().getTypeInserts(forSourcefile, withResults, generics);
|
return new PlaceholderPlacer(forSourcefile, generics).getTypeInserts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlaceholderVariable createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
|
public static PlaceholderVariable createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
|
||||||
@@ -29,27 +30,20 @@ public class ASTTransformationHelper {
|
|||||||
ResolvedType resolvedType = resultSet.resolveType(type);
|
ResolvedType resolvedType = resultSet.resolveType(type);
|
||||||
PlaceholderPoint insertPoint = new PlaceholderPoint(offset,
|
PlaceholderPoint insertPoint = new PlaceholderPoint(offset,
|
||||||
new PlaceholderToInsertString(resolvedType.resolvedType, constraints, classConstraints).insert, PlaceholderType.NORMAL_INSERT);
|
new PlaceholderToInsertString(resolvedType.resolvedType, constraints, classConstraints).insert, PlaceholderType.NORMAL_INSERT);
|
||||||
return new PlaceholderVariable(insertPoint, createGenericInsert(constraints, classConstraints, cl, m, resultSet, offset), resolvedType.getResultPair());
|
return new PlaceholderVariable(insertPoint, createGenericInsert(constraints, classConstraints, cl, m, offset), resolvedType.getResultPair(), constraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized Set<PlaceholderPoint> createGenericInsert(GenericsResultSet methodConstraints, GenericsResultSet classConstraints, ClassOrInterface cl, Method m, ResultSet resultSet, Token mOffset){
|
private static synchronized Set<PlaceholderPoint> createGenericInsert(GenericsResultSet methodConstraints, GenericsResultSet classConstraints, ClassOrInterface cl, Method m, Token mOffset){
|
||||||
Set<PlaceholderPoint> result = createGenericClassInserts(classConstraints, cl);
|
Set<PlaceholderPoint> result = createGenericClassInserts(classConstraints, cl);
|
||||||
|
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
result.addAll(createMethodConstraints(methodConstraints, m.getOffset() != null ? m.getOffset() : mOffset));
|
createMethodConstraints(methodConstraints, m.getOffset() != null ? m.getOffset() : mOffset).ifPresent(result::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<PlaceholderPoint> createMethodConstraints(GenericsResultSet constraints, Token mOffset) {
|
|
||||||
Set<PlaceholderPoint> result = new HashSet<>();
|
|
||||||
Token offset = mOffset;
|
|
||||||
|
|
||||||
if (constraints.size() == 0) {
|
public static String createConstraintsString(GenericsResultSet constraints) {
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
String insert = " <";
|
String insert = " <";
|
||||||
|
|
||||||
for (var genericInsertConstraint : constraints) {
|
for (var genericInsertConstraint : constraints) {
|
||||||
@@ -63,9 +57,16 @@ public class ASTTransformationHelper {
|
|||||||
|
|
||||||
insert = insert.substring(0, insert.length() -2);
|
insert = insert.substring(0, insert.length() -2);
|
||||||
insert += ">";
|
insert += ">";
|
||||||
|
|
||||||
result.add(new PlaceholderPoint(offset, insert, PlaceholderType.GENERERIC_METHOD_INSERT));
|
return insert;
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
private static Optional<PlaceholderPoint> createMethodConstraints(GenericsResultSet constraints, Token mOffset) {
|
||||||
|
Token offset = mOffset;
|
||||||
|
if (constraints.size() == 0) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return Optional.of(new PlaceholderPoint(offset, createConstraintsString(constraints), PlaceholderType.GENERERIC_METHOD_INSERT));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<PlaceholderPoint> createGenericClassInserts(GenericsResultSet classConstraints, ClassOrInterface cl) {
|
private static Set<PlaceholderPoint> createGenericClassInserts(GenericsResultSet classConstraints, ClassOrInterface cl) {
|
||||||
@@ -75,23 +76,7 @@ public class ASTTransformationHelper {
|
|||||||
if (classConstraints == null || classConstraints.size() == 0) {
|
if (classConstraints == null || classConstraints.size() == 0) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
result.add(new PlaceholderPoint(offset, createConstraintsString(classConstraints), PlaceholderType.GENERIC_CLASS_INSERT));
|
||||||
String insert = " <";
|
|
||||||
|
|
||||||
for (var genericInsertConstraint : classConstraints) {
|
|
||||||
if (genericInsertConstraint instanceof GenerateGenerics.PairEQ peq) {
|
|
||||||
insert += peq.left.resolve().getName();
|
|
||||||
} else if (genericInsertConstraint instanceof GenerateGenerics.PairLT psm) {
|
|
||||||
insert += psm.left.resolve().getName() + " extends " + psm.right.resolve().getName();
|
|
||||||
}
|
|
||||||
insert += ", ";
|
|
||||||
}
|
|
||||||
|
|
||||||
insert = insert.substring(0, insert.length() -2);
|
|
||||||
insert += ">";
|
|
||||||
|
|
||||||
result.add(new PlaceholderPoint(offset, insert, PlaceholderType.GENERIC_CLASS_INSERT));
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package de.dhbw.helper;
|
package de.dhbw.helper;
|
||||||
|
|
||||||
|
import de.dhbw.helper.TypeResolver.InferenceResult;
|
||||||
import de.dhbw.model.DiagnosticsAndTypehints;
|
import de.dhbw.model.DiagnosticsAndTypehints;
|
||||||
import de.dhbw.service.TextDocumentService;
|
import de.dhbw.service.TextDocumentService;
|
||||||
import de.dhbw.model.LSPVariable;
|
import de.dhbw.model.LSPVariable;
|
||||||
import de.dhbw.model.Type;
|
import de.dhbw.model.Type;
|
||||||
|
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
||||||
import org.eclipse.lsp4j.*;
|
import org.eclipse.lsp4j.*;
|
||||||
|
|
||||||
@@ -20,8 +22,9 @@ public class ConversionHelper {
|
|||||||
this.textDocumentService = textDocumentService;
|
this.textDocumentService = textDocumentService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String cleanType(String type){
|
public static String cleanType(String type) {
|
||||||
return type.replaceAll("java.lang.", "").replaceAll("java.util.", "");
|
// Strip package from type string for better readability in diagnostics and inlay hints
|
||||||
|
return type.replaceAll("\\b(?:[A-Za-z_]\\w*\\.)+(\\w+)\\b", "$1");
|
||||||
}
|
}
|
||||||
|
|
||||||
public InlayHint getInlayHint(LSPVariable variable) {
|
public InlayHint getInlayHint(LSPVariable variable) {
|
||||||
@@ -29,7 +32,7 @@ public class ConversionHelper {
|
|||||||
|
|
||||||
String typeDisplay = "";
|
String typeDisplay = "";
|
||||||
for (Type type : variable.getPossibleTypes()) {
|
for (Type type : variable.getPossibleTypes()) {
|
||||||
typeDisplay += " | " + cleanType(type.getType().replaceAll("GTV ", ""));
|
typeDisplay += "| " + cleanType(type.getType().replaceAll("GTV ", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,11 +93,35 @@ public class ConversionHelper {
|
|||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehints(ArrayList<LSPVariable> typesOfMethodAndParameters, String uri) {
|
public DiagnosticsAndTypehints addWarningsToDiagnostics(DiagnosticsAndTypehints diagnosticsAndTypehints, List<CompilerWarning> warnings) {
|
||||||
|
List<Diagnostic> diagnostics = new ArrayList<>(diagnosticsAndTypehints.getDiagnostics());
|
||||||
|
for (var warning : warnings) {
|
||||||
|
var offset = warning.getOffset();
|
||||||
|
Range warningRange = new Range(
|
||||||
|
new Position(offset.getLine() - 1, offset.getCharPositionInLine()),
|
||||||
|
new Position(offset.getLine() - 1, offset.getCharPositionInLine() + offset.getText().length())
|
||||||
|
);
|
||||||
|
Diagnostic diagnostic = new Diagnostic(
|
||||||
|
warningRange,
|
||||||
|
warning.getMessage(),
|
||||||
|
DiagnosticSeverity.Warning,
|
||||||
|
"JavaTX Language Server"
|
||||||
|
);
|
||||||
|
diagnostics.add(diagnostic);
|
||||||
|
}
|
||||||
|
return new DiagnosticsAndTypehints(diagnostics, diagnosticsAndTypehints.getInlayHints());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehints(InferenceResult inferenceResult, String uri) {
|
||||||
|
var diagnosticsAndTypehints = variablesToDiagnosticsAndTypehints(inferenceResult.variables(), uri);
|
||||||
|
return addWarningsToDiagnostics(diagnosticsAndTypehints, inferenceResult.warnings());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehints(ArrayList<LSPVariable> variables, String uri) {
|
||||||
List<InlayHint> typeHint = new ArrayList<>();
|
List<InlayHint> typeHint = new ArrayList<>();
|
||||||
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||||
|
|
||||||
for (var variable : typesOfMethodAndParameters) {
|
for (var variable : variables) {
|
||||||
|
|
||||||
InlayHint inlayHint = getInlayHint(variable);
|
InlayHint inlayHint = getInlayHint(variable);
|
||||||
typeHint.add(inlayHint);
|
typeHint.add(inlayHint);
|
||||||
@@ -108,11 +135,11 @@ public class ConversionHelper {
|
|||||||
return new DiagnosticsAndTypehints(diagnostics, typeHint);
|
return new DiagnosticsAndTypehints(diagnostics, typeHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehintsWithInput(ArrayList<LSPVariable> typesOfMethodAndParameters, String input) {
|
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehintsWithInput(InferenceResult inferenceResult, String input) {
|
||||||
List<InlayHint> typeHint = new ArrayList<>();
|
List<InlayHint> typeHint = new ArrayList<>();
|
||||||
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||||
|
|
||||||
for (var variable : typesOfMethodAndParameters) {
|
for (var variable : inferenceResult.variables()) {
|
||||||
|
|
||||||
InlayHint inlayHint = getInlayHint(variable);
|
InlayHint inlayHint = getInlayHint(variable);
|
||||||
typeHint.add(inlayHint);
|
typeHint.add(inlayHint);
|
||||||
@@ -123,6 +150,6 @@ public class ConversionHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DiagnosticsAndTypehints(diagnostics, typeHint);
|
return addWarningsToDiagnostics(new DiagnosticsAndTypehints(diagnostics, typeHint), inferenceResult.warnings());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package de.dhbw.helper;
|
||||||
|
|
||||||
|
public record InsertPoint(int line, int character) {}
|
||||||
@@ -3,29 +3,32 @@ package de.dhbw.helper;
|
|||||||
import de.dhbw.model.PlaceholderVariable;
|
import de.dhbw.model.PlaceholderVariable;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class PlaceholderPlacer extends AbstractASTWalker {
|
public class PlaceholderPlacer extends AbstractASTWalker {
|
||||||
Set<PlaceholderVariable> inserts = new HashSet<>();
|
Set<PlaceholderVariable> inserts = new HashSet<>();
|
||||||
private ResultSet withResults;
|
|
||||||
String pkgName;
|
String pkgName;
|
||||||
private GenericsResult genericsResult;
|
private GenericsResult genericsResult;
|
||||||
|
private SourceFile forSourceFile;
|
||||||
|
|
||||||
public Set<PlaceholderVariable> getTypeInserts(SourceFile forSourceFile, ResultSet withResults, GenericsResult genericsResult){
|
public PlaceholderPlacer(SourceFile forSourceFile, GenericsResult genericsResult) {
|
||||||
this.withResults = withResults;
|
this.forSourceFile = forSourceFile;
|
||||||
this.genericsResult = genericsResult;
|
this.genericsResult = genericsResult;
|
||||||
pkgName = forSourceFile.getPkgName();
|
this.pkgName = forSourceFile.getPkgName();
|
||||||
forSourceFile.accept(this);
|
}
|
||||||
inserts.forEach(el -> el.reducePackage());
|
|
||||||
return inserts;
|
public Set<PlaceholderVariable> getTypeInserts() {
|
||||||
|
this.inserts = new HashSet<>();
|
||||||
|
this.forSourceFile.accept(this);
|
||||||
|
this.inserts.forEach(el -> el.reducePackage());
|
||||||
|
return this.inserts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ClassOrInterface classOrInterface) {
|
public void visit(ClassOrInterface classOrInterface) {
|
||||||
de.dhbw.helper.PlaceholderPlacerClass cl = new de.dhbw.helper.PlaceholderPlacerClass(classOrInterface, withResults, genericsResult);
|
de.dhbw.helper.PlaceholderPlacerClass cl = new de.dhbw.helper.PlaceholderPlacerClass(classOrInterface, genericsResult);
|
||||||
this.inserts.addAll(cl.inserts);
|
this.inserts.addAll(cl.inserts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ class PlaceholderPlacerClass extends AbstractASTWalker{
|
|||||||
GenericsResultSet constraints;
|
GenericsResultSet constraints;
|
||||||
GenericsResultSet classConstraints;
|
GenericsResultSet classConstraints;
|
||||||
|
|
||||||
PlaceholderPlacerClass(ClassOrInterface forClass, ResultSet withResults, GenericsResult generatedGenerics){
|
PlaceholderPlacerClass(ClassOrInterface forClass, GenericsResult generatedGenerics) {
|
||||||
this.cl = forClass;
|
this.cl = forClass;
|
||||||
this.method = null;
|
this.method = null;
|
||||||
this.results = withResults;
|
this.results = generatedGenerics.getGenerics().getResultSet();
|
||||||
this.generatedGenerics = generatedGenerics;
|
this.generatedGenerics = generatedGenerics;
|
||||||
forClass.accept(this);
|
forClass.accept(this);
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ class PlaceholderPlacerClass extends AbstractASTWalker{
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
constraints = generatedGenerics.get(method);
|
constraints = generatedGenerics.get(cl, method);
|
||||||
classConstraints = generatedGenerics.get(cl);
|
classConstraints = generatedGenerics.get(cl);
|
||||||
if(method.getReturnType() instanceof TypePlaceholder)
|
if(method.getReturnType() instanceof TypePlaceholder)
|
||||||
inserts.add(ASTTransformationHelper.createInsertPoints(
|
inserts.add(ASTTransformationHelper.createInsertPoints(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package de.dhbw.helper;
|
package de.dhbw.helper;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
|
import de.dhbwstuttgart.target.generate.GenerateGenerics;
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
||||||
import de.dhbwstuttgart.typeinference.result.*;
|
import de.dhbwstuttgart.typeinference.result.*;
|
||||||
|
|
||||||
@@ -60,14 +61,14 @@ public class PlaceholderToInsertString implements ResultSetVisitor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(TypePlaceholder typePlaceholder) {
|
public void visit(TypePlaceholder typePlaceholder) {
|
||||||
ResultPair<?, ?> resultPair = null;
|
GenerateGenerics.Pair resultPair = null;
|
||||||
if (constraints != null)
|
if (constraints != null)
|
||||||
resultPair = constraints.getResultPairFor(typePlaceholder).orElse(null);
|
resultPair = constraints.getResultPairFor(typePlaceholder).orElse(null);
|
||||||
if (resultPair == null)
|
if (resultPair == null)
|
||||||
resultPair = classConstraints.getResultPairFor(typePlaceholder).orElse(null);
|
resultPair = classConstraints.getResultPairFor(typePlaceholder).orElse(null);
|
||||||
|
|
||||||
if (resultPair != null)
|
if (resultPair != null)
|
||||||
insert += ((TypePlaceholder)resultPair.getLeft()).getName();
|
insert += resultPair.left.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,30 +3,21 @@ package de.dhbw.helper;
|
|||||||
|
|
||||||
import de.dhbw.model.*;
|
import de.dhbw.model.*;
|
||||||
import de.dhbw.model.PlaceholderVariable;
|
import de.dhbw.model.PlaceholderVariable;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
||||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
import org.apache.log4j.LogManager;
|
import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper-Class for finding the Type of a selected Word
|
* Helper-Class for finding the Type of a selected Word
|
||||||
*/
|
*/
|
||||||
@@ -37,10 +28,10 @@ public class TypeResolver {
|
|||||||
private final DuplicationUtils duplicationUtils;
|
private final DuplicationUtils duplicationUtils;
|
||||||
private final boolean ENABLE_GENERICS = true;
|
private final boolean ENABLE_GENERICS = true;
|
||||||
private List<GenericsResult> generatedGenerics = null;
|
private List<GenericsResult> generatedGenerics = null;
|
||||||
private HashMap<String, List<PlaceholderVariable>> inserts;
|
private HashMap<InsertPoint, List<PlaceholderVariable>> inserts;
|
||||||
|
|
||||||
|
|
||||||
public HashMap<String, List<PlaceholderVariable>> getInserts() {
|
public HashMap<InsertPoint, List<PlaceholderVariable>> getInserts() {
|
||||||
return inserts;
|
return inserts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,9 +41,7 @@ public class TypeResolver {
|
|||||||
private LanguageServerTransferObject current;
|
private LanguageServerTransferObject current;
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
HashMap<String, List<TypeInsert>> inserts = null;
|
this.current = null;
|
||||||
List<GenericsResult> generatedGenerics = null;
|
|
||||||
current = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -82,7 +71,7 @@ public class TypeResolver {
|
|||||||
|
|
||||||
public void getCompilerInput(String path, String input) throws IOException, URISyntaxException, ClassNotFoundException {
|
public void getCompilerInput(String path, String input) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||||
var transferObj = languageServer.getResultSetAndAbastractSyntax(path, RESET_TO_LETTER);
|
var transferObj = languageServer.getResultSetAndAbstractSyntax(path, RESET_TO_LETTER);
|
||||||
current = transferObj;
|
current = transferObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,25 +88,37 @@ public class TypeResolver {
|
|||||||
|
|
||||||
Set<PlaceholderVariable> tips = new HashSet<>();
|
Set<PlaceholderVariable> tips = new HashSet<>();
|
||||||
|
|
||||||
for (int i = 0; i < current.getResultSets().size(); i++) {
|
for (var results : generatedGenerics) {
|
||||||
ResultSet tiResult = current.getResultSets().get(i);
|
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(current.getAst(), results));
|
||||||
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(current.getAst(), tiResult, generatedGenerics.get(i)));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
|
HashMap<InsertPoint, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
|
||||||
|
|
||||||
for (PlaceholderVariable insert : tips) {
|
for (PlaceholderVariable insert : tips) {
|
||||||
if (!insertsOnLines.containsKey(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine())) {
|
var insertPoint = new InsertPoint(insert.point.point.getLine(), insert.point.point.getCharPositionInLine());
|
||||||
insertsOnLines.put(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine(), new ArrayList<>(List.of(insert)));
|
if (!insertsOnLines.containsKey(insertPoint)) {
|
||||||
|
insertsOnLines.put(insertPoint, new ArrayList<>(List.of(insert)));
|
||||||
} else {
|
} else {
|
||||||
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
|
insertsOnLines.get(insertPoint).add(insert);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inserts = insertsOnLines;
|
inserts = insertsOnLines;
|
||||||
|
|
||||||
ArrayList<LSPVariable> variables = new ArrayList<>(insertsOnLines.entrySet().stream().map(el -> new LSPVariable("test", new ArrayList<>(el.getValue().stream().map(typeinsert -> new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint())).toList()), el.getValue().getFirst().point.point.getLine(), el.getValue().getFirst().point.point.getCharPositionInLine(), el.getValue().get(0).point.point.getStopIndex(), el.getValue().get(0).getResultPair().getLeft())).toList());
|
ArrayList<LSPVariable> variables = new ArrayList<>(
|
||||||
|
insertsOnLines.entrySet().stream().map(el -> {
|
||||||
|
var v = el.getValue().getFirst();
|
||||||
|
return new LSPVariable("test",
|
||||||
|
new ArrayList<>(el.getValue().stream()
|
||||||
|
.map(typeinsert -> new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint()))
|
||||||
|
.toList()),
|
||||||
|
v.point.point.getLine(),
|
||||||
|
v.point.point.getCharPositionInLine(),
|
||||||
|
v.point.point.getStopIndex(),
|
||||||
|
v.getResultPair().getLeft());
|
||||||
|
}
|
||||||
|
).toList()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
for (var variable : variables) {
|
for (var variable : variables) {
|
||||||
@@ -140,31 +141,32 @@ public class TypeResolver {
|
|||||||
return variables;
|
return variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<LSPVariable> infereInput(String pathString, String input) throws IOException, ClassNotFoundException, URISyntaxException {
|
public record InferenceResult(ArrayList<LSPVariable> variables, List<CompilerWarning> warnings) {}
|
||||||
|
|
||||||
|
public InferenceResult infereInput(String pathString, String input) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||||
|
|
||||||
LanguageServerInterface languageServerInterface = new LanguageServerInterface();
|
LanguageServerInterface languageServerInterface = new LanguageServerInterface();
|
||||||
LanguageServerTransferObject lsTransfer = languageServerInterface.getResultSetAndAbstractSyntax(pathString);
|
LanguageServerTransferObject lsTransfer = languageServerInterface.getResultSetAndAbstractSyntax(pathString);
|
||||||
|
|
||||||
var parsedSource = lsTransfer.getAst();
|
var parsedSource = lsTransfer.getAst();
|
||||||
var tiResults = lsTransfer.getResultSets();
|
|
||||||
Set<PlaceholderVariable> tips = new HashSet<>();
|
Set<PlaceholderVariable> tips = new HashSet<>();
|
||||||
|
|
||||||
generatedGenerics = lsTransfer.getGeneratedGenerics().get(lsTransfer.getAst());
|
generatedGenerics = lsTransfer.getGeneratedGenerics().get(lsTransfer.getAst());
|
||||||
for (int i = 0; i < tiResults.size(); i++) {
|
for (var generics : generatedGenerics) {
|
||||||
ResultSet tiResult = tiResults.get(i);
|
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(parsedSource, generics));
|
||||||
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(parsedSource, tiResult, lsTransfer.getGeneratedGenerics().get(lsTransfer.getAst()).get(i)));
|
|
||||||
}
|
}
|
||||||
System.setOut(System.out);
|
System.setOut(System.out);
|
||||||
this.current = lsTransfer;
|
this.current = lsTransfer;
|
||||||
|
|
||||||
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
|
HashMap<InsertPoint, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
|
||||||
|
|
||||||
for (PlaceholderVariable insert : tips) {
|
for (PlaceholderVariable insert : tips) {
|
||||||
if (!insertsOnLines.containsKey(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine())) {
|
var insertPoint = new InsertPoint(insert.point.point.getLine(), insert.point.point.getCharPositionInLine());
|
||||||
insertsOnLines.put(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine(), new ArrayList<>(List.of(insert)));
|
if (!insertsOnLines.containsKey(insertPoint)) {
|
||||||
|
insertsOnLines.put(insertPoint, new ArrayList<>(List.of(insert)));
|
||||||
} else {
|
} else {
|
||||||
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
|
insertsOnLines.get(insertPoint).add(insert);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +183,13 @@ public class TypeResolver {
|
|||||||
for(PlaceholderVariable typeinsert : entrySet.getValue()){
|
for(PlaceholderVariable typeinsert : entrySet.getValue()){
|
||||||
typesOfVariable.add(new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint()));
|
typesOfVariable.add(new Type(typeinsert.getInsertString(), typeinsert.point.isGenericClassInsertPoint()));
|
||||||
}
|
}
|
||||||
|
|
||||||
variables.add(new LSPVariable("test",typesOfVariable , entrySet.getValue().getFirst().point.point.getLine(), entrySet.getValue().getFirst().point.point.getCharPositionInLine(), entrySet.getValue().get(0).point.point.getStopIndex(), entrySet.getValue().get(0).getResultPair().getLeft()));
|
var variable = entrySet.getValue().getFirst();
|
||||||
|
variables.add(new LSPVariable("test", typesOfVariable,
|
||||||
|
variable.point.point.getLine(),
|
||||||
|
variable.point.point.getCharPositionInLine(),
|
||||||
|
variable.point.point.getStopIndex(),
|
||||||
|
variable.getResultPair().getLeft()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -203,26 +210,7 @@ public class TypeResolver {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return variables;
|
return new InferenceResult(variables, lsTransfer.getWarnings());
|
||||||
}
|
|
||||||
|
|
||||||
public void reduceCurrent(HashMap<LineCharPosition, String> combinedList, List<LSPVariable> variables) {
|
|
||||||
|
|
||||||
for (var lines : combinedList.entrySet()) {
|
|
||||||
var contentChange = lines.getValue();
|
|
||||||
for (LSPVariable variable : variables) {
|
|
||||||
for (Type typeOfVariable : variable.getPossibleTypes()) {
|
|
||||||
|
|
||||||
if (typeOfVariable.getType().equalsIgnoreCase(contentChange.replaceAll(" ", ""))) {
|
|
||||||
if (variable.getLine() - 1 == lines.getKey().line && variable.getCharPosition() == lines.getKey().charPosition) {
|
|
||||||
current.getResultSets().removeIf(el -> !el.resolveType(variable.getOriginalTphName()).resolvedType.toString().equalsIgnoreCase(contentChange.replaceAll(" ", "")));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SourceFile getNewAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
|
public SourceFile getNewAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||||
@@ -233,7 +221,7 @@ public class TypeResolver {
|
|||||||
public void updateAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
|
public void updateAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||||
logger.info("Old AST:");
|
logger.info("Old AST:");
|
||||||
logger.info(ASTPrinter.print(this.current.getAst()));
|
logger.info(ASTPrinter.print(this.current.getAst()));
|
||||||
this.current = new LanguageServerTransferObject(current.getResultSets(), getNewAst(uri), "", current.getGeneratedGenerics());
|
this.current = new LanguageServerTransferObject(getNewAst(uri), "", current.getGeneratedGenerics(), current.getWarnings());
|
||||||
|
|
||||||
logger.info("NEW AST:");
|
logger.info("NEW AST:");
|
||||||
logger.info(ASTPrinter.print(current.getAst()));
|
logger.info(ASTPrinter.print(current.getAst()));
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.dhbw.model;
|
package de.dhbw.model;
|
||||||
|
|
||||||
|
import de.dhbw.helper.ConversionHelper;
|
||||||
|
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -11,10 +13,11 @@ public class PlaceholderVariable {
|
|||||||
public final PlaceholderPoint point;
|
public final PlaceholderPoint point;
|
||||||
Set<PlaceholderPoint> inserts;
|
Set<PlaceholderPoint> inserts;
|
||||||
ResultPair<?, ?> resultPair;
|
ResultPair<?, ?> resultPair;
|
||||||
|
private final GenericsResultSet constraints;
|
||||||
|
|
||||||
|
public PlaceholderVariable(PlaceholderPoint point, Set<PlaceholderPoint> additionalPoints, ResultPair<?, ?> resultPair, GenericsResultSet constraints) {
|
||||||
public PlaceholderVariable(PlaceholderPoint point, Set<PlaceholderPoint> additionalPoints, ResultPair<?, ?> resultPair) {
|
|
||||||
this.point = point;
|
this.point = point;
|
||||||
|
this.constraints = constraints;
|
||||||
inserts = additionalPoints;
|
inserts = additionalPoints;
|
||||||
this.resultPair = resultPair;
|
this.resultPair = resultPair;
|
||||||
}
|
}
|
||||||
@@ -43,7 +46,7 @@ public class PlaceholderVariable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reducePackage() {
|
public void reducePackage() {
|
||||||
point.setInsertString(point.getInsertString().replaceAll("java\\.lang\\.", "").replaceAll("java\\.util\\.", ""));
|
point.setInsertString(ConversionHelper.cleanType(point.getInsertString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultPair<?, ?> getResultPair() {
|
public ResultPair<?, ?> getResultPair() {
|
||||||
@@ -73,4 +76,8 @@ public class PlaceholderVariable {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return point.toString();
|
return point.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GenericsResultSet getConstraints() {
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user