Compare commits
1 Commits
async-comp
...
onlySyntac
Author | SHA1 | Date | |
---|---|---|---|
|
f5cdda7625 |
2
Clients/Intellij/.idea/misc.xml
generated
2
Clients/Intellij/.idea/misc.xml
generated
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
28
Clients/Intellij/build.gradle
Normal file
28
Clients/Intellij/build.gradle
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'org.jetbrains.intellij.platform' version '2.2.1'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'org.example'
|
||||||
|
version = '1.0-SNAPSHOT'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven { url "https://jitpack.io" }
|
||||||
|
|
||||||
|
intellijPlatform {
|
||||||
|
defaultRepositories()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||||
|
implementation "com.github.Ballerina-Platform.lsp4intellij:lsp4intellij:master-SNAPSHOT"
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
@@ -1,41 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("org.jetbrains.intellij") version "1.17.3"
|
|
||||||
kotlin("jvm") version "1.9.0"
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "com.example"
|
|
||||||
version = "1.0.0"
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
maven { url = uri("https://jitpack.io") }
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation(kotlin("stdlib"))
|
|
||||||
implementation("com.github.ballerina-platform:lsp4intellij:0.9.0")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
java {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "17"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
intellij {
|
|
||||||
version.set("2023.3")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
|
||||||
patchPluginXml {
|
|
||||||
sinceBuild.set("233")
|
|
||||||
untilBuild.set("233.*")
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,13 +0,0 @@
|
|||||||
# Installation des Intellij Language Clients
|
|
||||||
|
|
||||||
Um den Language Client für Intellij installieren zu können, kann die Erweiterung
|
|
||||||
[LSP4IJ](https://plugins.jetbrains.com/plugin/23257-lsp4ij) installiert werden.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
1. Installiere [LSP4IJ](https://plugins.jetbrains.com/plugin/23257-lsp4ij)
|
|
||||||
2. Öffne den Language Server Tab
|
|
||||||
3. Füge einen neuen Language-Server hinzu
|
|
||||||
4. Vergebe einen Namen und füge folgenden Command hinzu: `java -jar "<path/to/LanguageServer.jar>`
|
|
||||||
5. Füge unter Mappings -> File name patterns *.jav und Language ID java_tx hinzu
|
|
||||||
6. öffne eine Datei mit Dateiendung .jav
|
|
||||||
7. Fertig
|
|
@@ -1,14 +0,0 @@
|
|||||||
package kotlin.com.example.lsp;
|
|
||||||
|
|
||||||
import com.intellij.openapi.application.PreloadingActivity;
|
|
||||||
import com.intellij.openapi.progress.ProgressIndicator;
|
|
||||||
import org.wso2.lsp4intellij.IntellijLanguageClient;
|
|
||||||
import org.wso2.lsp4intellij.client.languageserver.serverdefinition.RawCommandServerDefinition;
|
|
||||||
|
|
||||||
public class PreloadActivityTX extends PreloadingActivity {
|
|
||||||
@Override
|
|
||||||
public void preload(ProgressIndicator indicator) {
|
|
||||||
String[] command = new String[]{"java", "-jar", "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"};
|
|
||||||
IntellijLanguageClient.addServerDefinition(new RawCommandServerDefinition("jav", command));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -13,7 +13,7 @@ see also jetbrains documentation: https://plugins.jetbrains.com/docs/intellij/pl
|
|||||||
|
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
<!-- register a preloading activity. You need to init IntellijLanguageClient with your config, see readme -->
|
<!-- register a preloading activity. You need to init IntellijLanguageClient with your config, see readme -->
|
||||||
<preloadingActivity implementation="kotlin.com.example.lsp.PreloadActivityTX" id="kotlin.com.example.lsp.PreloadActivityTX"/>
|
<preloadingActivity implementation="your.plugin.MyPreloadingActivity" id="your.plugin.MyPreloadingActivity"/>
|
||||||
|
|
||||||
<!-- register intellijLanguageClient as a Service OR as a plugin component (see readme)... -->
|
<!-- register intellijLanguageClient as a Service OR as a plugin component (see readme)... -->
|
||||||
<applicationService serviceImplementation="org.wso2.lsp4intellij.IntellijLanguageClient"/>
|
<applicationService serviceImplementation="org.wso2.lsp4intellij.IntellijLanguageClient"/>
|
||||||
|
@@ -9,7 +9,3 @@ vsc-extension-quickstart.md
|
|||||||
**/*.map
|
**/*.map
|
||||||
**/*.ts
|
**/*.ts
|
||||||
**/.vscode-test.*
|
**/.vscode-test.*
|
||||||
|
|
||||||
!JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar
|
|
||||||
|
|
||||||
!JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 902 KiB |
@@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
"icon": "TX.png",
|
"name": "lspclient",
|
||||||
"name": "java-tx-language-extension",
|
"displayName": "LSPClient",
|
||||||
"displayName": "Java-TX Language Extension",
|
"description": "",
|
||||||
"description": "The Language Extension for Java-TX with Typehints and Syntax Checks",
|
"version": "0.0.1",
|
||||||
"version": "0.0.5",
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.94.0"
|
"vscode": "^1.94.0"
|
||||||
},
|
},
|
||||||
@@ -17,8 +16,8 @@
|
|||||||
"contributes": {
|
"contributes": {
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "tx.restartLanguageServer",
|
"command": "lspclient.helloWorld",
|
||||||
"title": "TX: Restart Language Server"
|
"title": "Hello World"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@@ -1,30 +1,39 @@
|
|||||||
|
// The module 'vscode' contains the VS Code extensibility API
|
||||||
|
// Import the module and reference it with the alias vscode in your code below
|
||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
import { workspace, ExtensionContext } from 'vscode';
|
||||||
import {
|
import {
|
||||||
LanguageClient,
|
LanguageClient,
|
||||||
LanguageClientOptions,
|
LanguageClientOptions,
|
||||||
ServerOptions
|
ServerOptions,
|
||||||
|
TransportKind
|
||||||
} from 'vscode-languageclient/node';
|
} from 'vscode-languageclient/node';
|
||||||
|
|
||||||
let client: LanguageClient | undefined; // <— global, damit wir neu starten können
|
|
||||||
|
|
||||||
function createClient(context: vscode.ExtensionContext): LanguageClient {
|
|
||||||
|
|
||||||
|
// This method is called when your extension is activated
|
||||||
|
// Your extension is activated the very first time the command is executed
|
||||||
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const workspaceFolder = context.extensionPath;
|
const workspaceFolder = context.extensionPath;
|
||||||
|
|
||||||
const serverOptions: ServerOptions = {
|
const serverOptions: ServerOptions = {
|
||||||
run: {
|
run: {
|
||||||
command: 'java',
|
command: 'java',
|
||||||
args: ['-Xss2m', '-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"],
|
args: ['-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"], // Absolute Pfadangabe
|
||||||
},
|
},
|
||||||
debug: {
|
debug: {
|
||||||
command: 'java',
|
command: 'java',
|
||||||
args: [
|
args: ['-jar', workspaceFolder + "/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar"], // Absolute Pfadangabe für Debug
|
||||||
'-Xss2m',
|
|
||||||
'-jar',
|
|
||||||
workspaceFolder + '/JavaTXLanguageServer-1.0-SNAPSHOT-jar-with-dependencies.jar',
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("SERVER CREATED.")
|
||||||
|
console.log(workspaceFolder)
|
||||||
|
// Clientoptionen: definiere, welche Dateitypen der Client unterstützt
|
||||||
const clientOptions: LanguageClientOptions = {
|
const clientOptions: LanguageClientOptions = {
|
||||||
documentSelector: [{ scheme: 'file', language: 'java' }],
|
documentSelector: [{ scheme: 'file', language: 'java' }],
|
||||||
synchronize: {
|
synchronize: {
|
||||||
@@ -33,53 +42,37 @@ function createClient(context: vscode.ExtensionContext): LanguageClient {
|
|||||||
revealOutputChannelOn: 4
|
revealOutputChannelOn: 4
|
||||||
};
|
};
|
||||||
|
|
||||||
return new LanguageClient(
|
|
||||||
'javaTxLanguageServer',
|
// Language Client erstellen und starten
|
||||||
'Java-TX Language Server',
|
const client = new LanguageClient(
|
||||||
|
'javaTxLanguageServer', // ID des Clients
|
||||||
|
'Java-TX Language Server', // Name des Clients
|
||||||
serverOptions,
|
serverOptions,
|
||||||
clientOptions
|
clientOptions
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
export async function activate(context: vscode.ExtensionContext) {
|
// Client starten
|
||||||
client = createClient(context);
|
client.start().then(() => {
|
||||||
|
console.log("Language Client erfolgreich gestartet");
|
||||||
client.start()
|
}).catch(error => {
|
||||||
.then(() => console.log("Language Client erfolgreich gestartet"))
|
console.error("Fehler beim Starten des Language Clients:", error);
|
||||||
.catch(err => console.error("Fehler beim Starten des Language Clients:", err));
|
});
|
||||||
|
|
||||||
|
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
||||||
|
// This line of code will only be executed once when your extension is activated
|
||||||
console.log('Congratulations, your extension "tx" is now active!');
|
console.log('Congratulations, your extension "tx" is now active!');
|
||||||
|
|
||||||
// Beispiel-Command aus deinem Code bleibt
|
// The command has been defined in the package.json file
|
||||||
const hello = vscode.commands.registerCommand('lspclient.helloWorld', () => {
|
// Now provide the implementation of the command with registerCommand
|
||||||
|
// The commandId parameter must match the command field in package.json
|
||||||
|
const disposable = vscode.commands.registerCommand('lspclient.helloWorld', () => {
|
||||||
|
// The code you place here will be executed every time your command is executed
|
||||||
|
// Display a message box to the user
|
||||||
vscode.window.showInformationMessage('Hello World from TX!');
|
vscode.window.showInformationMessage('Hello World from TX!');
|
||||||
});
|
});
|
||||||
context.subscriptions.push(hello);
|
|
||||||
|
|
||||||
// *** NEU: Restart-Command ***
|
context.subscriptions.push(disposable);
|
||||||
const restart = vscode.commands.registerCommand('tx.restartLanguageServer', async () => {
|
|
||||||
if (!client) {
|
|
||||||
vscode.window.showWarningMessage('Language Client ist nicht initialisiert.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await client.stop(); // stoppt den Serverprozess
|
|
||||||
client.dispose(); // räumt Ressourcen auf
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Fehler beim Stoppen des Language Clients:', e);
|
|
||||||
}
|
|
||||||
client = createClient(context); // komplett neu erzeugen
|
|
||||||
try {
|
|
||||||
await client.start();
|
|
||||||
vscode.window.showInformationMessage('Java-TX Language Server neu gestartet.');
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Fehler beim Neustarten des Language Clients:', e);
|
|
||||||
vscode.window.showErrorMessage('Neustart des Language Servers fehlgeschlagen – Details in der Konsole.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
context.subscriptions.push(restart);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deactivate(): Thenable<void> | undefined {
|
// This method is called when your extension is deactivated
|
||||||
return client?.stop();
|
export function deactivate() { }
|
||||||
}
|
|
||||||
|
@@ -20,11 +20,6 @@
|
|||||||
<artifactId>antlr4</artifactId>
|
<artifactId>antlr4</artifactId>
|
||||||
<version>4.11.1</version>
|
<version>4.11.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.java-diff-utils</groupId>
|
|
||||||
<artifactId>java-diff-utils</artifactId>
|
|
||||||
<version>4.12</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
@@ -80,12 +75,6 @@
|
|||||||
<version>0.1</version>
|
<version>0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
|
||||||
<!-- Setzt Java 21 als globale Version -->
|
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
|
||||||
<maven.compiler.release>21</maven.compiler.release>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -107,7 +96,6 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<source>21</source>
|
<source>21</source>
|
||||||
<target>21</target>
|
<target>21</target>
|
||||||
<release>21</release>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ import org.eclipse.lsp4j.services.TextDocumentService;
|
|||||||
import org.eclipse.lsp4j.services.WorkspaceService;
|
import org.eclipse.lsp4j.services.WorkspaceService;
|
||||||
import org.eclipse.lsp4j.services.LanguageServer;
|
import org.eclipse.lsp4j.services.LanguageServer;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
/**
|
/**
|
||||||
|
@@ -1,76 +1,50 @@
|
|||||||
package de.dhbw;
|
package de.dhbw;
|
||||||
|
|
||||||
import de.dhbw.handler.*;
|
import com.google.common.base.Stopwatch;
|
||||||
import de.dhbw.service.CacheService;
|
|
||||||
import de.dhbw.service.ClientService;
|
|
||||||
import de.dhbw.service.LogService;
|
|
||||||
import de.dhbw.helper.CodeSnippetOptions;
|
import de.dhbw.helper.CodeSnippetOptions;
|
||||||
import de.dhbw.helper.ConversionHelper;
|
|
||||||
import de.dhbw.helper.TextHelper;
|
import de.dhbw.helper.TextHelper;
|
||||||
import de.dhbw.helper.TypeResolver;
|
import de.dhbw.helper.TypeResolver;
|
||||||
|
import de.dhbw.model.LSPVariable;
|
||||||
import de.dhbw.model.SnippetWithName;
|
import de.dhbw.model.SnippetWithName;
|
||||||
import de.dhbw.service.ParserService;
|
import de.dhbw.model.Type;
|
||||||
|
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
||||||
|
import de.dhbwstuttgart.languageServerInterface.ParserInterface;
|
||||||
|
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
||||||
|
import org.apache.log4j.LogManager;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.eclipse.lsp4j.*;
|
import org.eclipse.lsp4j.*;
|
||||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||||
import org.eclipse.lsp4j.services.LanguageClient;
|
import org.eclipse.lsp4j.services.LanguageClient;
|
||||||
import org.eclipse.lsp4j.services.TextDocumentService;
|
import org.eclipse.lsp4j.services.TextDocumentService;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles Actions in Documents, such as Autocompletion, Change-Events and Syntax-Checks
|
* Handles Actions in Documents, such as Autocompletion, Change-Events and Syntax-Checks
|
||||||
*/
|
*/
|
||||||
public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.TextDocumentService {
|
public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.TextDocumentService {
|
||||||
|
|
||||||
private final FormattingHandler formattingHandler;
|
|
||||||
private final SaveHandler saveHandler;
|
|
||||||
private final ParserService parserService;
|
|
||||||
private final TypeResolver typeResolver;
|
|
||||||
private final de.dhbw.service.TextDocumentService textDocumentService;
|
|
||||||
private final LogService logService;
|
|
||||||
private final ClientService clientService;
|
|
||||||
private final CacheService cacheService;
|
|
||||||
private final ConversionHelper conversionHelper;
|
|
||||||
private final ChangeHandler changeHandler;
|
|
||||||
private final TextHelper textHelper;
|
|
||||||
private final CodeActionHandler codeActionHandler;
|
|
||||||
|
|
||||||
|
private static final Logger logger = LogManager.getLogger(JavaTXTextDocumentService.class);
|
||||||
LanguageClient client;
|
LanguageClient client;
|
||||||
HashMap<String, String> textDocuments = new HashMap<>();
|
HashMap<String, String> textDocuments = new HashMap<>();
|
||||||
CodeSnippetOptions codeSnippetOptions = new CodeSnippetOptions();
|
CodeSnippetOptions codeSnippetOptions = new CodeSnippetOptions();
|
||||||
Boolean dontShowHints = false;
|
|
||||||
Path fileRoot = null;
|
Path fileRoot = null;
|
||||||
Boolean singleFileOpened = false;
|
|
||||||
|
|
||||||
public JavaTXTextDocumentService() {
|
|
||||||
this.textHelper = new TextHelper();
|
|
||||||
this.cacheService = new CacheService();
|
|
||||||
this.clientService = new ClientService(null);
|
|
||||||
this.typeResolver = new TypeResolver();
|
|
||||||
this.textDocumentService = new de.dhbw.service.TextDocumentService();
|
|
||||||
this.conversionHelper = new ConversionHelper(textHelper, textDocumentService);
|
|
||||||
this.logService = new LogService(clientService);
|
|
||||||
this.formattingHandler = new FormattingHandler(textDocumentService);
|
|
||||||
this.parserService = new ParserService(conversionHelper, clientService, cacheService);
|
|
||||||
this.codeActionHandler = new CodeActionHandler(textHelper, textDocumentService, cacheService, typeResolver, logService);
|
|
||||||
this.saveHandler = new SaveHandler(typeResolver, textDocumentService, logService, cacheService, conversionHelper, clientService, parserService);
|
|
||||||
this.changeHandler = new ChangeHandler(textDocumentService, parserService, conversionHelper, clientService, typeResolver, cacheService, logService);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClient(LanguageClient client) {
|
public void setClient(LanguageClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
clientService.setClient(client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFileRoot(List<WorkspaceFolder> root) {
|
public void setFileRoot(List<WorkspaceFolder> root) {
|
||||||
|
|
||||||
if (root == null) {
|
|
||||||
singleFileOpened = true;
|
|
||||||
}
|
|
||||||
//TODO: Nicht nur das erste Element nehmen sondern alle beachten
|
|
||||||
fileRoot = Path.of(URI.create(root.get(0).getUri()));
|
fileRoot = Path.of(URI.create(root.get(0).getUri()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,19 +81,9 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void didOpen(DidOpenTextDocumentParams params) {
|
public void didOpen(DidOpenTextDocumentParams params) {
|
||||||
cacheService.reset();
|
|
||||||
typeResolver.reset();
|
|
||||||
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(params.getTextDocument().getText(), params.getTextDocument().getUri());
|
|
||||||
if (!syntaxErrors.isEmpty()) {
|
|
||||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors);
|
|
||||||
}
|
|
||||||
client.refreshDiagnostics();
|
|
||||||
client.refreshInlayHints();
|
|
||||||
textDocuments.put(params.getTextDocument().getUri(), params.getTextDocument().getText());
|
textDocuments.put(params.getTextDocument().getUri(), params.getTextDocument().getText());
|
||||||
textDocumentService.saveFileWithUri(params.getTextDocument().getUri(), params.getTextDocument().getText());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles didChange-Event.
|
* Handles didChange-Event.
|
||||||
* updates textDocument-State on Server and run Syntax-Check. If an Error is found it will get displayed as a Diagnostic.
|
* updates textDocument-State on Server and run Syntax-Check. If an Error is found it will get displayed as a Diagnostic.
|
||||||
@@ -128,12 +92,35 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void didChange(DidChangeTextDocumentParams params) {
|
public void didChange(DidChangeTextDocumentParams params) {
|
||||||
logService.log("[didChange] Client triggered didChange Event.", MessageType.Info);
|
client.logMessage(new MessageParams(MessageType.Info,"[didChange] Client triggered didChange Event."));
|
||||||
cacheService.reset();
|
|
||||||
String fileInput = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
|
AtomicReference<String> summedUp = new AtomicReference<>("");
|
||||||
textDocuments.put(params.getTextDocument().getUri(), fileInput);
|
params.getContentChanges().forEach(el -> summedUp.set(summedUp.get() + el.getText()));
|
||||||
textDocumentService.saveFileWithUri(params.getTextDocument().getUri(), fileInput);
|
textDocuments.put(params.getTextDocument().getUri(), summedUp.get());
|
||||||
changeHandler.didChange(params);
|
|
||||||
|
String input = summedUp.get();
|
||||||
|
|
||||||
|
ParserInterface parserInterface = new ParserInterface();
|
||||||
|
|
||||||
|
List<ParserError> parserErrors = parserInterface.getParseErrors(input);
|
||||||
|
|
||||||
|
List<Diagnostic> diagnostics = parserErrors.stream().map(el -> {
|
||||||
|
Range errorRange = new Range(
|
||||||
|
new Position(el.getLine() - 1, el.getCharPositionInLine()), // Startposition
|
||||||
|
new Position(el.getLine() - 1, el.getEndCharPosition()) // Endposition
|
||||||
|
);
|
||||||
|
return new Diagnostic(
|
||||||
|
errorRange,
|
||||||
|
el.getMsg(),
|
||||||
|
DiagnosticSeverity.Error,
|
||||||
|
"JavaTX Language Server"
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
|
||||||
|
PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(params.getTextDocument().getUri(), diagnostics);
|
||||||
|
client.publishDiagnostics(diagnosticsParams);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,8 +130,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
|
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
|
||||||
logService.log("[formatting] Client requested formatting.", MessageType.Info);
|
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||||
return CompletableFuture.completedFuture(formattingHandler.handleFormat(params));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -153,18 +139,11 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void didSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
public void didSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
||||||
logService.log("[didSave] Client triggered didSave-Event.");
|
|
||||||
clientService.startLoading("compile-task", "Inferring types...", client);
|
|
||||||
saveHandler.asyncHandle(didSaveTextDocumentParams);
|
|
||||||
clientService.stopLoading("compile-task", "Types successfully inferred", client);
|
|
||||||
clientService.updateClient(client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
|
public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
|
||||||
logService.log("[inlayHint] The Client requested Inlay-Hints.", MessageType.Info);
|
return CompletableFuture.completedFuture(Collections.emptyList());}
|
||||||
return CompletableFuture.supplyAsync(() -> dontShowHints ? Collections.emptyList() : cacheService.getGlobalInlayHintMap().get(params.getTextDocument().getUri()) == null ? Collections.emptyList() : cacheService.getGlobalInlayHintMap().get(params.getTextDocument().getUri()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void willSave(WillSaveTextDocumentParams params) {
|
public void willSave(WillSaveTextDocumentParams params) {
|
||||||
@@ -295,14 +274,7 @@ 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) {
|
||||||
|
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||||
logService.log("[codeAction] Client requested Insert at Line [" + params.getRange().getStart().getLine() + "] and from Char [" + params.getRange().getStart().getCharacter() + "] to [" + params.getRange().getEnd().getCharacter() + "].", MessageType.Info);
|
|
||||||
|
|
||||||
logService.log("Code-Action Context was: " + params.getContext().getTriggerKind().name(), MessageType.Info);
|
|
||||||
|
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
|
||||||
return codeActionHandler.handleNewCodeAction(params);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -3,8 +3,13 @@ package de.dhbw;
|
|||||||
import org.apache.log4j.LogManager;
|
import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.eclipse.lsp4j.*;
|
import org.eclipse.lsp4j.*;
|
||||||
|
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||||
import org.eclipse.lsp4j.services.WorkspaceService;
|
import org.eclipse.lsp4j.services.WorkspaceService;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Handles Actions in Workspace
|
* Handles Actions in Workspace
|
||||||
|
@@ -1,203 +0,0 @@
|
|||||||
package de.dhbw.handler;
|
|
||||||
|
|
||||||
import com.google.common.base.Stopwatch;
|
|
||||||
import de.dhbw.helper.ConversionHelper;
|
|
||||||
import de.dhbw.helper.TypeResolver;
|
|
||||||
import de.dhbw.model.*;
|
|
||||||
import de.dhbw.service.*;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
|
|
||||||
import org.eclipse.lsp4j.*;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class ChangeHandler {
|
|
||||||
|
|
||||||
private final TextDocumentService textDocumentService;
|
|
||||||
private final ParserService parserService;
|
|
||||||
private final ConversionHelper conversionHelper;
|
|
||||||
private final ClientService clientService;
|
|
||||||
private final TypeResolver typeResolver;
|
|
||||||
private final CacheService cacheService;
|
|
||||||
private final LogService logService;
|
|
||||||
|
|
||||||
public ChangeHandler(TextDocumentService textDocumentService, ParserService parserService, ConversionHelper conversionHelper, ClientService clientService, TypeResolver typeResolver, CacheService cacheService, LogService logService) {
|
|
||||||
this.textDocumentService = textDocumentService;
|
|
||||||
this.parserService = parserService;
|
|
||||||
this.conversionHelper = conversionHelper;
|
|
||||||
this.clientService = clientService;
|
|
||||||
this.typeResolver = typeResolver;
|
|
||||||
this.cacheService = cacheService;
|
|
||||||
this.logService = logService;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static String findAddedWord(String str1, String str2) {
|
|
||||||
int i = 0, j = 0;
|
|
||||||
|
|
||||||
// Suche den ersten Unterschied
|
|
||||||
while (i < str1.length() && j < str2.length() && str1.charAt(i) == str2.charAt(j)) {
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Falls alles gleich ist, gibt es nichts Neues
|
|
||||||
if (i == str1.length() && j == str2.length()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Suche ab Ende rückwärts, um den gemeinsamen Suffix zu finden
|
|
||||||
int iEnd = str1.length() - 1;
|
|
||||||
int jEnd = str2.length() - 1;
|
|
||||||
while (iEnd >= i && jEnd >= j && str1.charAt(iEnd) == str2.charAt(jEnd)) {
|
|
||||||
iEnd--;
|
|
||||||
jEnd--;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Der Unterschied liegt nun zwischen j und jEnd in str2
|
|
||||||
return str2.substring(j, jEnd + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void didChange(DidChangeTextDocumentParams params) {
|
|
||||||
String currentText = textDocumentService.getFileOfUri(params.getTextDocument().getUri());
|
|
||||||
|
|
||||||
AtomicReference<String> summedUp = new AtomicReference<>("");
|
|
||||||
params.getContentChanges().forEach(el -> summedUp.set(summedUp.get() + el.getText()));
|
|
||||||
textDocumentService.saveFileWithUri(params.getTextDocument().getUri(), summedUp.get());
|
|
||||||
|
|
||||||
|
|
||||||
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(summedUp.get(), params.getTextDocument().getUri());
|
|
||||||
|
|
||||||
if (!syntaxErrors.isEmpty()) {
|
|
||||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), syntaxErrors);
|
|
||||||
}
|
|
||||||
logService.log("Found [" + syntaxErrors.size() + "] Syntax Errors in Document.");
|
|
||||||
|
|
||||||
if (syntaxErrors.isEmpty()) {
|
|
||||||
|
|
||||||
String type = findAddedWord(currentText, summedUp.get());
|
|
||||||
String input = summedUp.get();
|
|
||||||
|
|
||||||
logService.log("Variables are: " + cacheService.getVariables().size());
|
|
||||||
|
|
||||||
boolean shouldCalculate = false;
|
|
||||||
|
|
||||||
logService.log("Type is here: " + type);
|
|
||||||
for (LSPVariable variable : cacheService.getVariables()) {
|
|
||||||
for (Type variableType : variable.getPossibleTypes()) {
|
|
||||||
logService.log(variableType.getType() + " <> "+ type.replaceAll(" ", "") + ": " + type.replaceAll(" ", "").contains(variableType.getType().replaceAll(" ", "")));
|
|
||||||
shouldCalculate = shouldCalculate || type.replaceAll(" ", "").contains(variableType.getType().replaceAll(" ", ""));
|
|
||||||
if (shouldCalculate) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logService.log("Should Calculate is: " + shouldCalculate);
|
|
||||||
|
|
||||||
if (false) {
|
|
||||||
try {
|
|
||||||
File tempDir = new File(System.getProperty("java.io.tmpdir"));
|
|
||||||
File tempFile = File.createTempFile("newText", ".tmp", tempDir);
|
|
||||||
FileWriter fileWriter = new FileWriter(tempFile, true);
|
|
||||||
System.out.println(tempFile.getAbsolutePath());
|
|
||||||
BufferedWriter bw = new BufferedWriter(fileWriter);
|
|
||||||
bw.write(summedUp.get());
|
|
||||||
bw.close();
|
|
||||||
typeResolver.updateAst(tempFile.toURI().getPath());
|
|
||||||
tempFile.delete();
|
|
||||||
} catch (Exception e) {
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
clientService.showMessage(MessageType.Error, e.getMessage());
|
|
||||||
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);
|
|
||||||
} else {
|
|
||||||
logService.log("Calculating again.");
|
|
||||||
var sWatch = Stopwatch.createUnstarted();
|
|
||||||
sWatch.start();
|
|
||||||
|
|
||||||
try {
|
|
||||||
try {
|
|
||||||
File tempDir2 = new File(System.getProperty("java.io.tmpdir"));
|
|
||||||
File tempFile2 = File.createTempFile("newText", ".tmp", tempDir2);
|
|
||||||
FileWriter fileWriter = new FileWriter(tempFile2, true);
|
|
||||||
BufferedWriter bw = new BufferedWriter(fileWriter);
|
|
||||||
bw.write(input);
|
|
||||||
bw.close();
|
|
||||||
|
|
||||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(tempFile2.toURI().toString(), input, false);
|
|
||||||
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);
|
|
||||||
allDiagnostics.addAll(parserService.getDiagnosticsOfErrors(input, params.getTextDocument().getUri()));
|
|
||||||
|
|
||||||
clientService.publishDiagnostics(params.getTextDocument().getUri(), allDiagnostics);
|
|
||||||
|
|
||||||
tempFile2.delete();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
|
||||||
|
|
||||||
for (StackTraceElement elem : e.getStackTrace()) {
|
|
||||||
logService.log(elem.toString());
|
|
||||||
}
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -1,217 +0,0 @@
|
|||||||
package de.dhbw.handler;
|
|
||||||
|
|
||||||
import de.dhbw.helper.TextHelper;
|
|
||||||
import de.dhbw.helper.TypeResolver;
|
|
||||||
import de.dhbw.service.CacheService;
|
|
||||||
import de.dhbw.service.LogService;
|
|
||||||
import de.dhbw.service.TextDocumentService;
|
|
||||||
import de.dhbw.model.PlaceholderVariable;
|
|
||||||
import org.eclipse.lsp4j.*;
|
|
||||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class CodeActionHandler {
|
|
||||||
|
|
||||||
private final TextHelper textHelper;
|
|
||||||
private final TextDocumentService textDocumentService;
|
|
||||||
private final CacheService cacheService;
|
|
||||||
private final TypeResolver typeResolver;
|
|
||||||
private final LogService logService;
|
|
||||||
|
|
||||||
public CodeActionHandler(TextHelper textHelper, TextDocumentService textDocumentService, CacheService cacheService, TypeResolver typeResolver, LogService logService) {
|
|
||||||
this.textHelper = textHelper;
|
|
||||||
this.textDocumentService = textDocumentService;
|
|
||||||
this.cacheService = cacheService;
|
|
||||||
this.typeResolver = typeResolver;
|
|
||||||
this.logService = logService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Range wholeDocumentRange(String text) {
|
|
||||||
if (text == null || text.isEmpty()) {
|
|
||||||
return new Range(new Position(0, 0), new Position(0, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
int lastLine = 0;
|
|
||||||
int lastBreak = -1; // Index des letzten Zeilenumbruchszeichens, das zum Zeilenende gehört
|
|
||||||
|
|
||||||
final int n = text.length();
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
char c = text.charAt(i);
|
|
||||||
if (c == '\n') {
|
|
||||||
lastLine++;
|
|
||||||
lastBreak = i;
|
|
||||||
} else if (c == '\r') {
|
|
||||||
// Unterscheide \r\n von alleine stehendem \r
|
|
||||||
if (i + 1 < n && text.charAt(i + 1) == '\n') {
|
|
||||||
lastLine++;
|
|
||||||
lastBreak = i + 1;
|
|
||||||
i++; // \n überspringen
|
|
||||||
} else {
|
|
||||||
lastLine++;
|
|
||||||
lastBreak = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int lastLineStart = lastBreak + 1;
|
|
||||||
int endChar = n - lastLineStart; // Länge der letzten Zeile in UTF-16 Code Units
|
|
||||||
|
|
||||||
return new Range(new Position(0, 0), new Position(lastLine, endChar));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static <V> Map<String, V> getOverlapping(
|
|
||||||
Map<String, V> map,
|
|
||||||
int line,
|
|
||||||
int startChar,
|
|
||||||
int endChar
|
|
||||||
) {
|
|
||||||
if (startChar > endChar) {
|
|
||||||
int t = startChar;
|
|
||||||
startChar = endChar;
|
|
||||||
endChar = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int s = startChar, e = endChar;
|
|
||||||
|
|
||||||
return map.entrySet().stream()
|
|
||||||
.filter(entry -> {
|
|
||||||
String key = entry.getKey();
|
|
||||||
String[] parts = key.split("\\s+");
|
|
||||||
if (parts.length != 2) return false;
|
|
||||||
try {
|
|
||||||
int kLine = Integer.parseInt(parts[0]);
|
|
||||||
int kChar = Integer.parseInt(parts[1]);
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<Either<Command, CodeAction>> handleNewCodeAction(CodeActionParams params) {
|
|
||||||
|
|
||||||
String documentUri = params.getTextDocument().getUri();
|
|
||||||
Range rangeOfInsert = params.getRange();
|
|
||||||
|
|
||||||
//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());
|
|
||||||
logService.log("Inserts are:");
|
|
||||||
typeResolver.getInserts().forEach((key, value) -> logService.log(key));
|
|
||||||
logService.log("Size is: " + typeInsertsOverlapping.size());
|
|
||||||
logService.log("Range is: " + rangeOfInsert.getStart().getLine() + " -> " + rangeOfInsert.getStart().getCharacter() + " - " + rangeOfInsert.getEnd().getCharacter());
|
|
||||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
|
||||||
|
|
||||||
for (var typeInsertList : typeInsertsOverlapping.values()) {
|
|
||||||
for (var typeInsert : typeInsertList) {
|
|
||||||
try {
|
|
||||||
String typeWithReplacedVariable = typeInsert.insert(textDocumentService.getFileOfUri(documentUri));
|
|
||||||
|
|
||||||
ArrayList<TextEdit> listOfChanges = new ArrayList<>();
|
|
||||||
|
|
||||||
listOfChanges.add(new TextEdit(wholeDocumentRange(textDocumentService.getFileOfUri(documentUri)), typeWithReplacedVariable));
|
|
||||||
|
|
||||||
var isTypeImported = false;
|
|
||||||
|
|
||||||
Map<String, List<TextEdit>> changes = new HashMap<>();
|
|
||||||
changes.put(documentUri, listOfChanges);
|
|
||||||
|
|
||||||
WorkspaceEdit edit = new WorkspaceEdit();
|
|
||||||
edit.setChanges(changes);
|
|
||||||
|
|
||||||
CodeAction action = new CodeAction("Insert " + typeInsert.getInsertString());
|
|
||||||
action.setKind(CodeActionKind.QuickFix);
|
|
||||||
action.setEdit(edit);
|
|
||||||
actions.add(Either.forRight(action));
|
|
||||||
} catch (Exception e) {
|
|
||||||
logService.log("Error creating Actions, returning empty List. The Error was: " + e.getMessage(), MessageType.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return actions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Either<Command, CodeAction>> handleCodeAction(CodeActionParams params) {
|
|
||||||
|
|
||||||
String documentUri = params.getTextDocument().getUri();
|
|
||||||
|
|
||||||
|
|
||||||
List<Diagnostic> diagnosticInCurrentDocument = params.getContext().getDiagnostics();
|
|
||||||
Range rangeOfInsert = params.getRange();
|
|
||||||
|
|
||||||
//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 -> textDocumentService.rangesOverlap(diagnostic.getRange(), rangeOfInsert)).toList();
|
|
||||||
|
|
||||||
|
|
||||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Diagnostic typeDiagnostic : diagnosticsOverlappingHover) {
|
|
||||||
try {
|
|
||||||
String typeWithReplacedVariable = typeDiagnostic.getMessage() +
|
|
||||||
" " +
|
|
||||||
textHelper.getTextOfChars(
|
|
||||||
textDocumentService.getFileOfUri(documentUri),
|
|
||||||
rangeOfInsert.getStart().getLine(),
|
|
||||||
rangeOfInsert.getStart().getCharacter(),
|
|
||||||
rangeOfInsert.getEnd().getCharacter()
|
|
||||||
);
|
|
||||||
|
|
||||||
ArrayList<TextEdit> listOfChanges = new ArrayList<>();
|
|
||||||
|
|
||||||
if (typeDiagnostic.getCode().getLeft().equals("GENERIC")) {
|
|
||||||
for (var diagnostic : cacheService.getGlobalDiagnosticsMap().get(documentUri)) {
|
|
||||||
|
|
||||||
if (diagnostic.getCode().getLeft().equals("GENERIC")) {
|
|
||||||
String genericType = diagnostic.getMessage() +
|
|
||||||
" " +
|
|
||||||
textHelper.getTextOfChars(
|
|
||||||
textDocumentService.getFileOfUri(params.getTextDocument().getUri()),
|
|
||||||
diagnostic.getRange().getStart().getLine(),
|
|
||||||
diagnostic.getRange().getStart().getCharacter(),
|
|
||||||
diagnostic.getRange().getEnd().getCharacter()
|
|
||||||
);
|
|
||||||
listOfChanges.add(new TextEdit(diagnostic.getRange(), genericType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
listOfChanges.add(new TextEdit(rangeOfInsert, typeWithReplacedVariable));
|
|
||||||
}
|
|
||||||
|
|
||||||
var isTypeImported = false;
|
|
||||||
|
|
||||||
if (!typeDiagnostic.getCode().getLeft().equalsIgnoreCase("generic")) {
|
|
||||||
isTypeImported = typeResolver.isTypeImported(textDocumentService.getFileOfUri(params.getTextDocument().getUri()), typeDiagnostic.getMessage());
|
|
||||||
}
|
|
||||||
if (!isTypeImported && !typeDiagnostic.getMessage().equals("void") && !typeDiagnostic.getCode().getLeft().equals("GENERIC")) {
|
|
||||||
Range importRange = new Range(new Position(0, 0), new Position(0, 0));
|
|
||||||
|
|
||||||
var typeWithoutGenerics = typeDiagnostic.getMessage().contains("<") ? typeDiagnostic.getMessage().substring(0, typeDiagnostic.getMessage().indexOf('<')) : typeDiagnostic.getMessage();
|
|
||||||
listOfChanges.add(new TextEdit(importRange, "import " + typeWithoutGenerics + ";\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, List<TextEdit>> changes = new HashMap<>();
|
|
||||||
changes.put(documentUri, listOfChanges);
|
|
||||||
|
|
||||||
WorkspaceEdit edit = new WorkspaceEdit();
|
|
||||||
edit.setChanges(changes);
|
|
||||||
|
|
||||||
CodeAction action = new CodeAction("Insert " + typeDiagnostic.getMessage());
|
|
||||||
action.setKind(CodeActionKind.QuickFix);
|
|
||||||
action.setEdit(edit);
|
|
||||||
actions.add(Either.forRight(action));
|
|
||||||
} catch (Exception e) {
|
|
||||||
logService.log("Error creating Actions, returning empty List. The Error was: " + e.getMessage(), MessageType.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return actions;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,38 +0,0 @@
|
|||||||
package de.dhbw.handler;
|
|
||||||
|
|
||||||
import de.dhbw.service.TextDocumentService;
|
|
||||||
import org.eclipse.lsp4j.DocumentFormattingParams;
|
|
||||||
import org.eclipse.lsp4j.Position;
|
|
||||||
import org.eclipse.lsp4j.Range;
|
|
||||||
import org.eclipse.lsp4j.TextEdit;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FormattingHandler {
|
|
||||||
|
|
||||||
private final TextDocumentService textDocumentService;
|
|
||||||
|
|
||||||
public FormattingHandler(TextDocumentService textDocumentService) {
|
|
||||||
this.textDocumentService = textDocumentService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TextEdit> handleFormat(DocumentFormattingParams params){
|
|
||||||
List<TextEdit> edits = new ArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
String[] lines = textDocumentService.getFileOfUri(params.getTextDocument().getUri()).split("\n");
|
|
||||||
StringBuilder formattedText = new StringBuilder();
|
|
||||||
|
|
||||||
for (String line : lines) {
|
|
||||||
formattedText.append(line.stripTrailing()).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEdit edit = new TextEdit();
|
|
||||||
edit.setRange(new Range(new Position(0, 0), new Position(lines.length, 0)));
|
|
||||||
edit.setNewText(formattedText.toString().trim());
|
|
||||||
|
|
||||||
edits.add(edit);
|
|
||||||
return edits;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,131 +0,0 @@
|
|||||||
package de.dhbw.handler;
|
|
||||||
|
|
||||||
import com.google.common.base.Stopwatch;
|
|
||||||
import de.dhbw.helper.ResultListener;
|
|
||||||
import de.dhbw.model.DiagnosticsAndTypehints;
|
|
||||||
import de.dhbw.service.*;
|
|
||||||
import de.dhbw.helper.ConversionHelper;
|
|
||||||
import de.dhbw.helper.TypeResolver;
|
|
||||||
import de.dhbw.model.LSPVariable;
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
import de.dhbwstuttgart.languageServerInterface.LanguageServerInterface;
|
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenerateGenerics;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
|
||||||
import org.eclipse.lsp4j.*;
|
|
||||||
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SaveHandler {
|
|
||||||
|
|
||||||
private final TypeResolver typeResolver;
|
|
||||||
private final TextDocumentService textDocumentService;
|
|
||||||
private final LogService logService;
|
|
||||||
private final CacheService cacheService;
|
|
||||||
private final ConversionHelper conversionHelper;
|
|
||||||
private final ClientService clientService;
|
|
||||||
private final ParserService parserService;
|
|
||||||
|
|
||||||
public SaveHandler(TypeResolver typeResolver, TextDocumentService textDocumentService, LogService logService, CacheService cacheService, ConversionHelper conversionHelper, ClientService clientService, ParserService parserService) {
|
|
||||||
this.typeResolver = typeResolver;
|
|
||||||
this.textDocumentService = textDocumentService;
|
|
||||||
this.logService = logService;
|
|
||||||
this.cacheService = cacheService;
|
|
||||||
this.conversionHelper = conversionHelper;
|
|
||||||
this.clientService = clientService;
|
|
||||||
this.parserService = parserService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
|
||||||
|
|
||||||
cacheService.reset();
|
|
||||||
typeResolver.reset();
|
|
||||||
var sWatch = Stopwatch.createUnstarted();
|
|
||||||
sWatch.start();
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
String fileInput = textDocumentService.getFileOfUri(didSaveTextDocumentParams.getTextDocument().getUri());
|
|
||||||
|
|
||||||
List<Diagnostic> syntaxErrors = parserService.getDiagnosticsOfErrors(fileInput, didSaveTextDocumentParams.getTextDocument().getUri());
|
|
||||||
if (!syntaxErrors.isEmpty()) {
|
|
||||||
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), syntaxErrors);
|
|
||||||
}
|
|
||||||
logService.log("Found [" + syntaxErrors.size() + "] Syntax Errors in Document.");
|
|
||||||
|
|
||||||
if (syntaxErrors.isEmpty()) {
|
|
||||||
|
|
||||||
cacheService.getLastSavedFiles().put(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
|
||||||
//typeResolver.getCompilerInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput);
|
|
||||||
|
|
||||||
if (fileInput == null) {
|
|
||||||
logService.log("[didSave] Input of Text Document is null in TextDocument-Hashmap.", MessageType.Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<LSPVariable> variables = typeResolver.infereInput(didSaveTextDocumentParams.getTextDocument().getUri(), fileInput, false);
|
|
||||||
cacheService.setVariables(variables);
|
|
||||||
|
|
||||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(variables, didSaveTextDocumentParams.getTextDocument().getUri());
|
|
||||||
|
|
||||||
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
|
||||||
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
|
||||||
|
|
||||||
cacheService.updateGlobalMaps(diagnostics, typeHint, didSaveTextDocumentParams.getTextDocument().getUri());
|
|
||||||
|
|
||||||
List<Diagnostic> allDiagnostics = new ArrayList<>(diagnostics);
|
|
||||||
|
|
||||||
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), allDiagnostics);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
|
||||||
|
|
||||||
for (StackTraceElement elem : e.getStackTrace()) {
|
|
||||||
logService.log(elem.toString());
|
|
||||||
}
|
|
||||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
|
||||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
sWatch.stop();
|
|
||||||
logService.log("[didSave] Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]", MessageType.Info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void asyncHandle(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
|
||||||
var sWatch = Stopwatch.createUnstarted();
|
|
||||||
sWatch.start();
|
|
||||||
|
|
||||||
try {
|
|
||||||
ResultListener resultListener = new ResultListener(typeResolver, didSaveTextDocumentParams, cacheService, conversionHelper, clientService);
|
|
||||||
resultListener.init(didSaveTextDocumentParams);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logService.log("[didSave] Error trying to get Inlay-Hints and Diagnostics for Client: " + e.getMessage(), MessageType.Error);
|
|
||||||
|
|
||||||
for (StackTraceElement elem : e.getStackTrace()) {
|
|
||||||
logService.log(elem.toString());
|
|
||||||
}
|
|
||||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
|
||||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,98 +0,0 @@
|
|||||||
package de.dhbw.helper;
|
|
||||||
|
|
||||||
import de.dhbw.model.PlaceholderPoint;
|
|
||||||
import de.dhbw.model.PlaceholderType;
|
|
||||||
import de.dhbw.model.PlaceholderVariable;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenerateGenerics;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.result.*;
|
|
||||||
import org.antlr.v4.runtime.Token;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ASTTransformationHelper {
|
|
||||||
|
|
||||||
public static Set<PlaceholderVariable> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults, GenericsResult generics) {
|
|
||||||
return new PlaceholderPlacer().getTypeInserts(forSourcefile, withResults, generics);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PlaceholderVariable createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
|
|
||||||
ResultSet resultSet, GenericsResultSet constraints, GenericsResultSet classConstraints) {
|
|
||||||
|
|
||||||
ResolvedType resolvedType = resultSet.resolveType(type);
|
|
||||||
PlaceholderPoint insertPoint = new PlaceholderPoint(offset,
|
|
||||||
new PlaceholderToInsertString(resolvedType.resolvedType, constraints, classConstraints).insert, PlaceholderType.NORMAL_INSERT);
|
|
||||||
return new PlaceholderVariable(insertPoint, createGenericInsert(constraints, classConstraints, cl, m, resultSet, offset), resolvedType.getResultPair());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static synchronized Set<PlaceholderPoint> createGenericInsert(GenericsResultSet methodConstraints, GenericsResultSet classConstraints, ClassOrInterface cl, Method m, ResultSet resultSet, Token mOffset){
|
|
||||||
Set<PlaceholderPoint> result = createGenericClassInserts(classConstraints, cl);
|
|
||||||
|
|
||||||
if (m != null) {
|
|
||||||
result.addAll(createMethodConstraints(methodConstraints, m.getOffset() != null ? m.getOffset() : mOffset));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Set<PlaceholderPoint> createMethodConstraints(GenericsResultSet constraints, Token mOffset) {
|
|
||||||
Set<PlaceholderPoint> result = new HashSet<>();
|
|
||||||
Token offset = mOffset;
|
|
||||||
|
|
||||||
if (constraints.size() == 0) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
String insert = " <";
|
|
||||||
|
|
||||||
for (var genericInsertConstraint : constraints) {
|
|
||||||
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.GENERERIC_METHOD_INSERT));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Set<PlaceholderPoint> createGenericClassInserts(GenericsResultSet classConstraints, ClassOrInterface cl) {
|
|
||||||
Set<PlaceholderPoint> result = new HashSet<>();
|
|
||||||
Token offset = cl.getGenerics().getOffset();
|
|
||||||
|
|
||||||
if (classConstraints == null || classConstraints.size() == 0) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@@ -1,123 +0,0 @@
|
|||||||
package de.dhbw.helper;
|
|
||||||
|
|
||||||
import de.dhbw.model.DiagnosticsAndTypehints;
|
|
||||||
import de.dhbw.service.TextDocumentService;
|
|
||||||
import de.dhbw.model.LSPVariable;
|
|
||||||
import de.dhbw.model.Type;
|
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
|
||||||
import org.eclipse.lsp4j.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ConversionHelper {
|
|
||||||
|
|
||||||
private final TextHelper textHelper;
|
|
||||||
private final TextDocumentService textDocumentService;
|
|
||||||
|
|
||||||
public ConversionHelper(TextHelper textHelper, TextDocumentService textDocumentService) {
|
|
||||||
this.textHelper = textHelper;
|
|
||||||
this.textDocumentService = textDocumentService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InlayHint getInlayHint(LSPVariable variable) {
|
|
||||||
InlayHint inlayHint = new InlayHint();
|
|
||||||
|
|
||||||
String typeDisplay = "";
|
|
||||||
for (Type type : variable.getPossibleTypes()) {
|
|
||||||
typeDisplay += " | " + type.getType().replaceAll("GTV ", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inlayHint.setLabel(typeDisplay.length() > 2 ? typeDisplay.substring(2) : typeDisplay);
|
|
||||||
inlayHint.setPosition(new Position(variable.getLine() - 1, variable.getCharPosition()));
|
|
||||||
inlayHint.setKind(InlayHintKind.Parameter);
|
|
||||||
inlayHint.setPaddingRight(true);
|
|
||||||
inlayHint.setPaddingRight(true);
|
|
||||||
return inlayHint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Diagnostic getDiagnostic(LSPVariable variable, String fileUri, Type type) {
|
|
||||||
Range errorRange = new Range(
|
|
||||||
new Position(variable.getLine() - 1, variable.getCharPosition()), // Startposition
|
|
||||||
new Position(variable.getLine() - 1, textHelper.getEndingCharOfStartingChar(variable.getLine() - 1, variable.getCharPosition(), textDocumentService.getFileOfUri(fileUri))) // Endposition
|
|
||||||
);
|
|
||||||
Diagnostic diagnostic = new Diagnostic(
|
|
||||||
errorRange,
|
|
||||||
//TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver
|
|
||||||
type.getType().replaceAll("GTV ", ""),
|
|
||||||
DiagnosticSeverity.Hint,
|
|
||||||
"JavaTX Language Server"
|
|
||||||
);
|
|
||||||
diagnostic.setCode(type.isGeneric() ? "GENERIC" : "TYPE");
|
|
||||||
|
|
||||||
return diagnostic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Diagnostic getDiagnosticWithInput(LSPVariable variable, String input, Type type) {
|
|
||||||
Range errorRange = new Range(
|
|
||||||
new Position(variable.getLine() - 1, variable.getCharPosition()), // Startposition
|
|
||||||
new Position(variable.getLine() - 1, textHelper.getEndingCharOfStartingChar(variable.getLine() - 1, variable.getCharPosition(), input)) // Endposition
|
|
||||||
);
|
|
||||||
Diagnostic diagnostic = new Diagnostic(
|
|
||||||
errorRange,
|
|
||||||
//TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver
|
|
||||||
type.getType().replaceAll("GTV ", ""),
|
|
||||||
DiagnosticSeverity.Hint,
|
|
||||||
"JavaTX Language Server"
|
|
||||||
);
|
|
||||||
diagnostic.setCode(type.isGeneric() ? "GENERIC" : "TYPE");
|
|
||||||
|
|
||||||
return diagnostic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Diagnostic> parseErrorToDiagnostic(List<ParserError> parserErrors){
|
|
||||||
return parserErrors.stream().map(el -> {
|
|
||||||
Range errorRange = new Range(
|
|
||||||
new Position(el.getLine() - 1, el.getCharPositionInLine()), // Startposition
|
|
||||||
new Position(el.getLine() - 1, el.getEndCharPosition()) // Endposition
|
|
||||||
);
|
|
||||||
return new Diagnostic(
|
|
||||||
errorRange,
|
|
||||||
el.getMsg(),
|
|
||||||
DiagnosticSeverity.Error,
|
|
||||||
"JavaTX Language Server"
|
|
||||||
);
|
|
||||||
}).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehints(ArrayList<LSPVariable> typesOfMethodAndParameters, String uri){
|
|
||||||
List<InlayHint> typeHint = new ArrayList<>();
|
|
||||||
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
|
||||||
|
|
||||||
for (var variable : typesOfMethodAndParameters) {
|
|
||||||
|
|
||||||
InlayHint inlayHint = getInlayHint(variable);
|
|
||||||
typeHint.add(inlayHint);
|
|
||||||
|
|
||||||
for (var type : variable.getPossibleTypes()) {
|
|
||||||
Diagnostic diagnostic = getDiagnostic(variable, uri, type);
|
|
||||||
diagnostics.add(diagnostic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DiagnosticsAndTypehints(diagnostics, typeHint);
|
|
||||||
}
|
|
||||||
public DiagnosticsAndTypehints variablesToDiagnosticsAndTypehintsWithInput(ArrayList<LSPVariable> typesOfMethodAndParameters, String input){
|
|
||||||
List<InlayHint> typeHint = new ArrayList<>();
|
|
||||||
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
|
||||||
|
|
||||||
for (var variable : typesOfMethodAndParameters) {
|
|
||||||
|
|
||||||
InlayHint inlayHint = getInlayHint(variable);
|
|
||||||
typeHint.add(inlayHint);
|
|
||||||
|
|
||||||
for (var type : variable.getPossibleTypes()) {
|
|
||||||
Diagnostic diagnostic = getDiagnosticWithInput(variable, input, type);
|
|
||||||
diagnostics.add(diagnostic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DiagnosticsAndTypehints(diagnostics, typeHint);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
package de.dhbw.helper;
|
|
||||||
|
|
||||||
import de.dhbw.model.Type;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DuplicationUtils {
|
|
||||||
public ArrayList<Type> filterOutDuplicates(List<Type> typeListOne, List<Type> typeListTwo) {
|
|
||||||
|
|
||||||
ArrayList<Type> filteredArrayList = new ArrayList<>();
|
|
||||||
|
|
||||||
typeListOne.forEach(el -> {
|
|
||||||
boolean found = false;
|
|
||||||
for (Type typeInListTwo : typeListTwo) {
|
|
||||||
found = found || typeInListTwo.getType().equals(el.getType());
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
filteredArrayList.add(el);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return filteredArrayList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Type> filterOutDuplicates(List<Type> typeListOne) {
|
|
||||||
HashMap<String, Type> hashMap = new HashMap<>();
|
|
||||||
typeListOne.forEach(el -> {
|
|
||||||
hashMap.put(el.getType(), el);
|
|
||||||
});
|
|
||||||
return new ArrayList<>(hashMap.values());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,31 +0,0 @@
|
|||||||
package de.dhbw.helper;
|
|
||||||
|
|
||||||
import de.dhbw.model.PlaceholderVariable;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class PlaceholderPlacer extends AbstractASTWalker {
|
|
||||||
Set<PlaceholderVariable> inserts = new HashSet<>();
|
|
||||||
private ResultSet withResults;
|
|
||||||
String pkgName;
|
|
||||||
private GenericsResult genericsResult;
|
|
||||||
|
|
||||||
public Set<PlaceholderVariable> getTypeInserts(SourceFile forSourceFile, ResultSet withResults, GenericsResult genericsResult){
|
|
||||||
this.withResults = withResults;
|
|
||||||
this.genericsResult = genericsResult;
|
|
||||||
pkgName = forSourceFile.getPkgName();
|
|
||||||
forSourceFile.accept(this);
|
|
||||||
return inserts;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(ClassOrInterface classOrInterface) {
|
|
||||||
de.dhbw.helper.PlaceholderPlacerClass cl = new de.dhbw.helper.PlaceholderPlacerClass(classOrInterface, withResults, genericsResult);
|
|
||||||
this.inserts.addAll(cl.inserts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@@ -1,65 +0,0 @@
|
|||||||
package de.dhbw.helper;
|
|
||||||
|
|
||||||
import de.dhbw.model.PlaceholderVariable;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
class PlaceholderPlacerClass extends AbstractASTWalker{
|
|
||||||
protected final ResultSet results;
|
|
||||||
private GenericsResult generatedGenerics;
|
|
||||||
protected final ClassOrInterface cl;
|
|
||||||
public final Set<PlaceholderVariable> inserts = new HashSet<>();
|
|
||||||
private Method method;
|
|
||||||
|
|
||||||
GenericsResultSet constraints;
|
|
||||||
GenericsResultSet classConstraints;
|
|
||||||
|
|
||||||
PlaceholderPlacerClass(ClassOrInterface forClass, ResultSet withResults, GenericsResult generatedGenerics){
|
|
||||||
this.cl = forClass;
|
|
||||||
this.method = null;
|
|
||||||
this.results = withResults;
|
|
||||||
this.generatedGenerics = generatedGenerics;
|
|
||||||
forClass.accept(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(Method method) {
|
|
||||||
this.method = method;
|
|
||||||
constraints = generatedGenerics.get(method);
|
|
||||||
classConstraints = generatedGenerics.get(cl);
|
|
||||||
if(method.getReturnType() instanceof TypePlaceholder)
|
|
||||||
inserts.add(ASTTransformationHelper.createInsertPoints(
|
|
||||||
method.getReturnType(), method.getReturnType().getOffset(), cl, method, results, constraints, classConstraints));
|
|
||||||
super.visit(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(Field field) {
|
|
||||||
if(field.getType() instanceof TypePlaceholder){
|
|
||||||
classConstraints = generatedGenerics.get(cl);
|
|
||||||
inserts.add(ASTTransformationHelper.createInsertPoints(
|
|
||||||
field.getType(), field.getType().getOffset(), cl, method, results, null, classConstraints));
|
|
||||||
}
|
|
||||||
super.visit(field);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(FormalParameter param) {
|
|
||||||
if(param.getType() instanceof TypePlaceholder)
|
|
||||||
inserts.add(ASTTransformationHelper.createInsertPoints(
|
|
||||||
param.getType(), param.getType().getOffset(), cl, method, results, constraints, classConstraints));
|
|
||||||
super.visit(param);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(LambdaExpression lambdaExpression) {
|
|
||||||
//Lambda-Ausdrücke brauchen keine Typeinsetzungen
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,77 +0,0 @@
|
|||||||
package de.dhbw.helper;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResultSet;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.*;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
public class PlaceholderToInsertString implements ResultSetVisitor{
|
|
||||||
public String insert = "";
|
|
||||||
private GenericsResultSet constraints;
|
|
||||||
private GenericsResultSet classConstraints;
|
|
||||||
|
|
||||||
|
|
||||||
public PlaceholderToInsertString(RefTypeOrTPHOrWildcardOrGeneric type, GenericsResultSet constraints, GenericsResultSet classConstraints){
|
|
||||||
this.constraints = constraints;
|
|
||||||
this.classConstraints = classConstraints;
|
|
||||||
type.accept(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(PairTPHsmallerTPH p) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(PairTPHequalRefTypeOrWildcardType p) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(PairTPHEqualTPH p) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(RefType resolved) {
|
|
||||||
insert = resolved.getName().toString();
|
|
||||||
if(resolved.getParaList().size() > 0){
|
|
||||||
insert += "<";
|
|
||||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> iterator = resolved.getParaList().iterator();
|
|
||||||
while(iterator.hasNext()){
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric typeParam = iterator.next();
|
|
||||||
insert += new PlaceholderToInsertString(typeParam, constraints, classConstraints).insert;
|
|
||||||
if(iterator.hasNext())insert += ", ";
|
|
||||||
}
|
|
||||||
insert += ">";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(GenericRefType genericRefType) {
|
|
||||||
insert += genericRefType.getParsedName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(SuperWildcardType superWildcardType) {
|
|
||||||
insert += "? super " + new PlaceholderToInsertString(superWildcardType.getInnerType(), constraints, classConstraints).insert;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(TypePlaceholder typePlaceholder) {
|
|
||||||
ResultPair<?, ?> resultPair = null;
|
|
||||||
if (constraints != null)
|
|
||||||
resultPair = constraints.getResultPairFor(typePlaceholder).orElse(null);
|
|
||||||
if (resultPair == null)
|
|
||||||
resultPair = classConstraints.getResultPairFor(typePlaceholder).orElse(null);
|
|
||||||
|
|
||||||
if (resultPair != null)
|
|
||||||
insert += ((TypePlaceholder)resultPair.getLeft()).getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(ExtendsWildcardType extendsWildcardType) {
|
|
||||||
insert += "? extends " + new PlaceholderToInsertString(extendsWildcardType.getInnerType(), constraints, classConstraints).insert;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,6 +0,0 @@
|
|||||||
package de.dhbw.helper;
|
|
||||||
|
|
||||||
public class Recalculator {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -1,123 +0,0 @@
|
|||||||
package de.dhbw.helper;
|
|
||||||
|
|
||||||
import com.google.common.base.Stopwatch;
|
|
||||||
import de.dhbw.handler.SaveHandler;
|
|
||||||
import de.dhbw.model.DiagnosticsAndTypehints;
|
|
||||||
import de.dhbw.model.LSPVariable;
|
|
||||||
import de.dhbw.service.CacheService;
|
|
||||||
import de.dhbw.service.ClientService;
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultEvent;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
|
||||||
import org.eclipse.lsp4j.Diagnostic;
|
|
||||||
import org.eclipse.lsp4j.DidSaveTextDocumentParams;
|
|
||||||
import org.eclipse.lsp4j.InlayHint;
|
|
||||||
import org.eclipse.lsp4j.MessageType;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ResultListener implements UnifyResultListener {
|
|
||||||
|
|
||||||
TypeResolver typeResolver;
|
|
||||||
SourceFile ast;
|
|
||||||
DidSaveTextDocumentParams didSaveTextDocumentParams;
|
|
||||||
CacheService cacheService;
|
|
||||||
ConversionHelper conversionHelper;
|
|
||||||
ClientService clientService;
|
|
||||||
JavaTXCompiler compiler;
|
|
||||||
SourceFile sourceFile;
|
|
||||||
|
|
||||||
|
|
||||||
public ResultListener(TypeResolver saveHandler, DidSaveTextDocumentParams didSaveTextDocumentParams, CacheService cacheService, ConversionHelper conversionHelper, ClientService clientService){
|
|
||||||
this.typeResolver = saveHandler;
|
|
||||||
this.didSaveTextDocumentParams = didSaveTextDocumentParams;
|
|
||||||
this.cacheService = cacheService;
|
|
||||||
this.conversionHelper = conversionHelper;
|
|
||||||
this.clientService = clientService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(DidSaveTextDocumentParams didSaveTextDocumentParams){
|
|
||||||
var sWatch = Stopwatch.createUnstarted();
|
|
||||||
sWatch.start();
|
|
||||||
|
|
||||||
try {
|
|
||||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
|
||||||
|
|
||||||
var uri = new URI(didSaveTextDocumentParams.getTextDocument().getUri());
|
|
||||||
var path = Path.of(uri);
|
|
||||||
|
|
||||||
var file = path.toFile();
|
|
||||||
Files.createDirectories(path.getParent().resolve("out"));
|
|
||||||
|
|
||||||
this.compiler = new JavaTXCompiler(file, false);
|
|
||||||
sourceFile = compiler.sourceFiles.get(file);
|
|
||||||
|
|
||||||
compiler.typeInferenceAsync(this, new OutputStreamWriter(new NullOutputStream()));
|
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
clientService.sendClientLog("KRITISCHE");
|
|
||||||
clientService.showMessage(MessageType.Error, e.getMessage() == null ? "null" : e.getMessage());
|
|
||||||
for (StackTraceElement stack : e.getStackTrace()){
|
|
||||||
clientService.sendClientLog(stack.toString());
|
|
||||||
}
|
|
||||||
cacheService.updateGlobalMaps(new ArrayList<>(), new ArrayList<>(), didSaveTextDocumentParams.getTextDocument().getUri());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNewTypeResultFound(UnifyResultEvent unifyResultEvent) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
clientService.sendClientLog("YEEEEEEEEEEEP: " + (unifyResultEvent.getNewTypeResult() == null ? "Null" : "Nicht null"));
|
|
||||||
List<LSPVariable> lspVariables = typeResolver.infereIncremental(unifyResultEvent.getNewTypeResult(), this.compiler.getGeneratedGenerics().get(sourceFile), ast);
|
|
||||||
|
|
||||||
if(cacheService.getVariables() == null){
|
|
||||||
clientService.sendClientLog("Variablen null");
|
|
||||||
cacheService.setVariables(new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
cacheService.getVariables().addAll(lspVariables);
|
|
||||||
|
|
||||||
|
|
||||||
DiagnosticsAndTypehints diagnosticsAndTypehints = conversionHelper.variablesToDiagnosticsAndTypehints(new ArrayList<>(lspVariables), didSaveTextDocumentParams.getTextDocument().getUri());
|
|
||||||
clientService.sendClientLog("Diagnostiken erstellt");
|
|
||||||
List<InlayHint> typeHint = diagnosticsAndTypehints.getInlayHints();
|
|
||||||
List<Diagnostic> diagnostics = diagnosticsAndTypehints.getDiagnostics();
|
|
||||||
|
|
||||||
cacheService.getGlobalInlayHintMap().computeIfAbsent(didSaveTextDocumentParams.getTextDocument().getUri(), k -> new ArrayList<>());
|
|
||||||
cacheService.getGlobalDiagnosticsMap().computeIfAbsent(didSaveTextDocumentParams.getTextDocument().getUri(), k -> new ArrayList<>());
|
|
||||||
|
|
||||||
|
|
||||||
cacheService.getGlobalInlayHintMap().get(didSaveTextDocumentParams.getTextDocument().getUri()).addAll(typeHint);
|
|
||||||
cacheService.getGlobalDiagnosticsMap().get(didSaveTextDocumentParams.getTextDocument().getUri()).addAll(diagnostics);
|
|
||||||
clientService.sendClientLog("paaaaaaaaaaaaast");
|
|
||||||
clientService.publishDiagnostics(didSaveTextDocumentParams.getTextDocument().getUri(), cacheService.getGlobalDiagnosticsMap().get(didSaveTextDocumentParams.getTextDocument().getUri()));
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
clientService.sendClientLog("KOMISCHER FEHLER!");
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
clientService.sendClientLog("KOMISCHER FEHLER!");
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
clientService.sendClientLog("KOMISCHER FEHLER!");
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -2,6 +2,8 @@ package de.dhbw.helper;
|
|||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TextHelper {
|
public class TextHelper {
|
||||||
@@ -57,7 +59,7 @@ public class TextHelper {
|
|||||||
|
|
||||||
if(lines.length < line){
|
if(lines.length < line){
|
||||||
log.warn("Returning hardcoded Value because the requested Line [" + line + "] does not exist in Text Document.");
|
log.warn("Returning hardcoded Value because the requested Line [" + line + "] does not exist in Text Document.");
|
||||||
return startChar;
|
return startChar+3;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] linesInChar = lines[line].split("");
|
String[] linesInChar = lines[line].split("");
|
||||||
|
@@ -2,66 +2,66 @@ package de.dhbw.helper;
|
|||||||
|
|
||||||
|
|
||||||
import de.dhbw.model.*;
|
import de.dhbw.model.*;
|
||||||
import de.dhbw.model.PlaceholderVariable;
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
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.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
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 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.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.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper-Class for finding the Type of a selected Word
|
* Helper-Class for finding the Type of a selected Word
|
||||||
*/
|
*/
|
||||||
public class TypeResolver {
|
public class TypeResolver {
|
||||||
|
|
||||||
|
HashMap<Integer, LanguageServerTransferObject> dataCache = new HashMap<>();
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(TypeResolver.class);
|
private static final Logger logger = LogManager.getLogger(TypeResolver.class);
|
||||||
|
|
||||||
private final TypeUtils typeUtils;
|
|
||||||
private final DuplicationUtils duplicationUtils;
|
|
||||||
private final boolean ENABLE_GENERICS = true;
|
|
||||||
private List<GenericsResult> generatedGenerics = null;
|
|
||||||
private HashMap<String, List<PlaceholderVariable>> inserts;
|
|
||||||
|
|
||||||
|
private List<ResultSet> currentResults = new ArrayList<>();
|
||||||
|
|
||||||
public HashMap<String, List<PlaceholderVariable>> getInserts() {
|
public List<ResultSet> getCurrentResults() {
|
||||||
return inserts;
|
return currentResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Somehow you have to reset to the Letter N to keep the naming of the TPHs consistent
|
public void setCurrentResults(List<ResultSet> currentResults) {
|
||||||
private final String RESET_TO_LETTER = "A";
|
this.currentResults = currentResults;
|
||||||
|
|
||||||
private LanguageServerTransferObject current;
|
|
||||||
|
|
||||||
public void reset() {
|
|
||||||
HashMap<String, List<TypeInsert>> inserts = null;
|
|
||||||
List<GenericsResult> generatedGenerics = null;
|
|
||||||
current = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addToCurrentResults(List<ResultSet> additionalResults) {
|
||||||
|
this.currentResults.addAll(additionalResults);
|
||||||
|
}
|
||||||
|
|
||||||
public TypeResolver() {
|
public TypeResolver() {
|
||||||
this.typeUtils = new TypeUtils();
|
|
||||||
this.duplicationUtils = new DuplicationUtils();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private LanguageServerTransferObject getCacheOrCalculate(String input, String path) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
|
logger.info("Trying to find cached Compiler-Answer for input with key [" + input.hashCode() + "].");
|
||||||
|
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||||
|
if (dataCache.containsKey(input.hashCode())) {
|
||||||
|
logger.info("Found Cache for the Input with key [" + input.hashCode() + "].");
|
||||||
|
return dataCache.get(input.hashCode());
|
||||||
|
} else {
|
||||||
|
logger.info("Could not find Cache for Input with key [" + input.hashCode() + "]. Using Compiler Interface and Saving the Answer in Cache.");
|
||||||
|
var transferObject = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||||
|
dataCache.put(input.hashCode(), transferObject);
|
||||||
|
return transferObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isTypeImported(String input, String type) {
|
public boolean isTypeImported(String input, String type) {
|
||||||
// try {
|
// try {
|
||||||
// var transferObject = getCacheOrCalculate(input);
|
// var transferObject = getCacheOrCalculate(input);
|
||||||
@@ -80,249 +80,176 @@ public class TypeResolver {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getCompilerInput(String path, String input) throws IOException, URISyntaxException, ClassNotFoundException {
|
public ArrayList<Type> getAvailableTypes(List<ResultSet> resultSets, Method method) {
|
||||||
|
logger.info("Searching for resulting Types of Placeholder [" + method.getReturnType().toString() + "].");
|
||||||
|
ArrayList<String> normalType = new ArrayList<>();
|
||||||
|
|
||||||
|
resultSets.forEach(conSet -> {
|
||||||
|
if (method.getReturnType().toString().toLowerCase().contains("tph ")) {
|
||||||
|
normalType.add(conSet.resolveType(method.getReturnType()).resolvedType.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return new ArrayList<>(normalType.stream().filter(el -> !el.contains("TPH ")).map(el -> new Type(el, false)).toList());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Type> getAvailableGenericTypes(List<GenericsResult> genericsResult, Method method) {
|
||||||
|
logger.info("Searching for resulting Types of Placeholder [" + method.getReturnType().toString() + "].");
|
||||||
|
ArrayList<String> genericTypes = new ArrayList<>();
|
||||||
|
|
||||||
|
genericsResult.forEach(conSet -> {
|
||||||
|
if (method.getReturnType().toString().toLowerCase().contains("tph ")) {
|
||||||
|
genericTypes.add(conSet.resolveTarget(method.getReturnType()).name().replaceAll("GTV ", ""));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return new ArrayList<>(genericTypes.stream().filter(el -> !el.contains("TPH ")).map(el -> new Type(el, true)).toList());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Type> getAvailableGenericTypes(List<GenericsResult> genericsResult, RefTypeOrTPHOrWildcardOrGeneric parameter) {
|
||||||
|
logger.info("Searching for resulting Types of Placeholder [" + parameter.toString() + "].");
|
||||||
|
|
||||||
|
ArrayList<String> paramTypes = new ArrayList<>();
|
||||||
|
genericsResult.forEach(conSet -> {
|
||||||
|
if (parameter.toString().toLowerCase().contains("tph ")) {
|
||||||
|
paramTypes.add(conSet.resolveTarget(parameter).name());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return new ArrayList<>(paramTypes.stream().filter(el -> !el.contains("TPH ")).map(el -> new Type(el, true)).toList());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Type> getAvailableTypes(List<ResultSet> resultSets, RefTypeOrTPHOrWildcardOrGeneric parameter) {
|
||||||
|
logger.info("Searching for resulting Types of Placeholder [" + parameter.toString() + "].");
|
||||||
|
|
||||||
|
ArrayList<String> paramTypes = new ArrayList<>();
|
||||||
|
resultSets.forEach(conSet -> {
|
||||||
|
if (parameter.toString().toLowerCase().contains("tph ")) {
|
||||||
|
paramTypes.add(conSet.resolveType(parameter).resolvedType.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return new ArrayList<>(paramTypes.stream().filter(el -> !el.contains("TPH ")).map(el -> new Type(el, false)).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Type> filterOutDuplicates(List<Type> typeListOne, List<Type> typeListTwo) {
|
||||||
|
|
||||||
|
ArrayList<Type> filteredArrayList = new ArrayList<>();
|
||||||
|
|
||||||
|
typeListOne.forEach(el -> {
|
||||||
|
boolean found = false;
|
||||||
|
for (Type typeInListTwo : typeListTwo) {
|
||||||
|
found = found || typeInListTwo.getType().equals(el.getType());
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
filteredArrayList.add(el);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return filteredArrayList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Type> filterOutDuplicates(List<Type> typeListOne) {
|
||||||
|
HashMap<String, Type> hashMap = new HashMap<>();
|
||||||
|
typeListOne.forEach(el -> {
|
||||||
|
hashMap.put(el.getType(), el);
|
||||||
|
});
|
||||||
|
return new ArrayList<>(hashMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Type> getClassGenerics(Map<SourceFile, List<GenericsResult>> genericsResult, Method method, ClassOrInterface clazz) {
|
||||||
|
ArrayList<Type> genericTypes = new ArrayList<>();
|
||||||
|
|
||||||
|
genericsResult.forEach(((key, value) -> value.forEach(genericResultSet -> {
|
||||||
|
|
||||||
|
var result = genericResultSet.resolveTarget(method.getReturnType());
|
||||||
|
|
||||||
|
|
||||||
|
var genericResult = genericResultSet.getBounds(method.getReturnType(), clazz, method);
|
||||||
|
if (result != null && genericResult != null) {
|
||||||
|
genericResult.forEach(res -> {
|
||||||
|
if (res != null && !res.isOnMethod()) {
|
||||||
|
genericTypes.add(new Type("<" + result.name() + (res.bound().toString().equals("java.lang.Object") ? ">" : " extends " + res.bound().toString() + ">"), true));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
})));
|
||||||
|
|
||||||
|
return genericTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zum Erhalt für sowohl Parameter als auch Methoden.
|
||||||
|
*/
|
||||||
|
public ArrayList<LSPVariable> infereInput(String input, String path) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
|
logger.info("Infering Types for Input.");
|
||||||
|
|
||||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||||
var transferObj = languageServer.getResultSetAndAbastractSyntax(path, RESET_TO_LETTER);
|
var transferObj = languageServer.getResultSetAndAbstractSyntax(path, input);
|
||||||
current = transferObj;
|
ArrayList<LSPVariable> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Hier noch irgendwie die Klasse rausfinden oder durchgehen.
|
||||||
|
//GENERICS OF CLASS
|
||||||
|
for (var method : transferObj.getAst().getAllMethods()) {
|
||||||
|
|
||||||
|
|
||||||
|
for (var clazz : transferObj.getAst().getClasses()) {
|
||||||
|
ArrayList<Type> genericTypes = getClassGenerics(transferObj.getGeneratedGenerics(), method, clazz);
|
||||||
|
TextHelper helper = new TextHelper();
|
||||||
|
if (!genericTypes.isEmpty()) {
|
||||||
|
methodsWithParametersLSPVariableList.add(new LSPClass("test", genericTypes, clazz.getOffset().getLine(), helper.getClassPositionForGeneric(clazz.getOffset().getLine() - 1, input, clazz.getOffset().getStopIndex()), clazz.getOffset().getStopIndex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public LanguageServerTransferObject updateIfNotPresent(String path, String input) throws IOException, URISyntaxException, ClassNotFoundException {
|
|
||||||
if (current == null) {
|
|
||||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
|
||||||
LanguageServerTransferObject transferObj = languageServer.getResultSetAndAbstractSyntax(path);
|
|
||||||
return transferObj;
|
|
||||||
}
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<LSPVariable> infereChangeInput() throws IOException, ClassNotFoundException, URISyntaxException {
|
|
||||||
|
|
||||||
Set<PlaceholderVariable> tips = new HashSet<>();
|
|
||||||
|
|
||||||
for (int i = 0; i < current.getResultSets().size(); i++) {
|
|
||||||
ResultSet tiResult = current.getResultSets().get(i);
|
|
||||||
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(current.getAst(), tiResult, generatedGenerics.get(i)));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
|
|
||||||
|
|
||||||
for (PlaceholderVariable insert : tips) {
|
|
||||||
if (!insertsOnLines.containsKey(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine())) {
|
|
||||||
insertsOnLines.put(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine(), new ArrayList<>(List.of(insert)));
|
|
||||||
} else {
|
|
||||||
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
|
|
||||||
for (var variable : variables) {
|
|
||||||
|
|
||||||
HashMap<String, Type> uniqueType = new HashMap<>();
|
|
||||||
|
|
||||||
for (var type : variable.getPossibleTypes()) {
|
|
||||||
if (!uniqueType.containsKey(type.getType().replaceAll(" ", ""))) {
|
|
||||||
uniqueType.put(type.getType(), type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
variable.setPossibleTypes(new ArrayList<>(uniqueType.values()));
|
|
||||||
logger.info(variable.getLine() + ":" + variable.getCharPosition());
|
|
||||||
for (Type t : variable.getPossibleTypes()) {
|
|
||||||
logger.info(t.getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return variables;
|
for (var method : transferObj.getAst().getAllMethods()) {
|
||||||
|
var types = getAvailableTypes(transferObj.getResultSets(), method);
|
||||||
|
var generics = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), method);
|
||||||
|
|
||||||
|
if (!filterOutDuplicates(types).isEmpty()) {
|
||||||
|
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(types), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
||||||
}
|
}
|
||||||
|
if (!generics.isEmpty()) {
|
||||||
public ArrayList<LSPVariable> infereInput(String pathString, String input, boolean a) throws IOException, ClassNotFoundException, URISyntaxException {
|
ArrayList<Type> typesThatAreGeneric = filterOutDuplicates(generics, types);
|
||||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
typesThatAreGeneric.forEach(el -> el.setType("<" + el.getType() + "> " + el.getType()));
|
||||||
|
//TODO: Muss Global und wird mehrmals so gemacht. Das if hier ist eigentlich falsch wegen unnötiger Berechnungszeit
|
||||||
var uri = new URI(pathString);
|
if (!filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
||||||
var path = Path.of(uri);
|
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
||||||
|
|
||||||
logger.info("Path is for calculation: " + path.toString());
|
|
||||||
var file = path.toFile();
|
|
||||||
Files.createDirectories(path.getParent().resolve("out"));
|
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(List.of(file), List.of(path.getParent().toFile()), path.getParent().resolve("out").toFile());
|
|
||||||
var parsedSource = compiler.sourceFiles.get(file);
|
|
||||||
var tiResults = compiler.typeInference(file);
|
|
||||||
Set<PlaceholderVariable> tips = new HashSet<>();
|
|
||||||
|
|
||||||
// for (var sf : compiler.sourceFiles.values()) {
|
|
||||||
// Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(sf, tiResults);
|
|
||||||
// logger.info("Path for Class-File is: " + path.getParent().resolve("out").toFile());
|
|
||||||
// Files.createDirectories(path.getParent().resolve("out"));
|
|
||||||
// compiler.writeClassFile(bytecode, path.getParent().resolve("out").toFile(), false);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(parsedSource, tiResults);
|
|
||||||
logger.info("Path for Class-File is: " + path.getParent().resolve("out").toFile());
|
|
||||||
Files.createDirectories(path.getParent().resolve("out"));
|
|
||||||
compiler.writeClassFile(bytecode, path.getParent().resolve("out").toFile(), false);
|
|
||||||
|
|
||||||
generatedGenerics = compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file));
|
|
||||||
for (int i = 0; i < tiResults.size(); i++) {
|
|
||||||
ResultSet tiResult = tiResults.get(i);
|
|
||||||
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(parsedSource, tiResult, compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file)).get(i)));
|
|
||||||
}
|
|
||||||
System.setOut(System.out);
|
|
||||||
this.current = new LanguageServerTransferObject(tiResults, parsedSource, "", compiler.getGeneratedGenerics());
|
|
||||||
|
|
||||||
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
|
|
||||||
|
|
||||||
for (PlaceholderVariable insert : tips) {
|
|
||||||
if (!insertsOnLines.containsKey(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine())) {
|
|
||||||
insertsOnLines.put(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine(), new ArrayList<>(List.of(insert)));
|
|
||||||
} else {
|
|
||||||
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inserts = insertsOnLines;
|
for (var param : method.getParameterList()) {
|
||||||
|
ArrayList<Type> typeParam = getAvailableTypes(transferObj.getResultSets(), param.getType());
|
||||||
|
ArrayList<Type> genericParam = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), param.getType());
|
||||||
|
|
||||||
logger.info("TYPES ARE:");
|
if (!typeParam.isEmpty()) {
|
||||||
insertsOnLines.forEach((key, value) -> value.forEach(type -> logger.info(type.point.getInsertString())));
|
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typeParam), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
||||||
ArrayList<LSPVariable> variables = new ArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
for(var entrySet : insertsOnLines.entrySet()){
|
|
||||||
ArrayList<Type> typesOfVariable = new ArrayList<>();
|
|
||||||
|
|
||||||
for(PlaceholderVariable typeinsert : entrySet.getValue()){
|
|
||||||
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()));
|
if (!genericParam.isEmpty()) {
|
||||||
}
|
ArrayList<Type> typesThatAreGeneric = filterOutDuplicates(genericParam, typeParam);
|
||||||
|
|
||||||
|
|
||||||
for (var variable : variables) {
|
if (!filterOutDuplicates(typesThatAreGeneric).isEmpty()) {
|
||||||
|
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
||||||
HashMap<String, Type> uniqueType = new HashMap<>();
|
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, new ArrayList<>(filterOutDuplicates(typesThatAreGeneric).stream().map(el -> new Type("<" + el.getType() + ">", true)).toList()), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
||||||
|
|
||||||
for (var type : variable.getPossibleTypes()) {
|
|
||||||
if (!uniqueType.containsKey(type.getType().replaceAll(" ", ""))) {
|
|
||||||
uniqueType.put(type.getType(), type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
variable.setPossibleTypes(new ArrayList<>(uniqueType.values()));
|
|
||||||
logger.info(variable.getLine() + ":" + variable.getCharPosition());
|
|
||||||
for (Type t : variable.getPossibleTypes()) {
|
|
||||||
logger.info(t.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return variables;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<LSPVariable> infereIncremental(List<ResultSet> newResultSet, List<GenericsResult> generatedGenerics, SourceFile ast) throws IOException, ClassNotFoundException, URISyntaxException {
|
|
||||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
|
||||||
logger.info("HMMMMMMMMMMMMM");
|
|
||||||
var parsedSource = ast;
|
|
||||||
var tiResults = newResultSet;
|
|
||||||
Set<PlaceholderVariable> tips = new HashSet<>();
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < tiResults.size(); i++) {
|
|
||||||
ResultSet tiResult = tiResults.get(i);
|
|
||||||
tips.addAll(ASTTransformationHelper.createTypeInsertPoints(parsedSource, tiResult, null));
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("OKI DOKI ALLES ERSTELLT");
|
|
||||||
System.setOut(System.out);
|
|
||||||
|
|
||||||
HashMap<String, List<PlaceholderVariable>> insertsOnLines = new HashMap<>();
|
|
||||||
|
|
||||||
for (PlaceholderVariable insert : tips) {
|
|
||||||
if (!insertsOnLines.containsKey(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine())) {
|
|
||||||
insertsOnLines.put(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine(), new ArrayList<>(List.of(insert)));
|
|
||||||
} else {
|
|
||||||
insertsOnLines.get(insert.point.point.getLine() + " " + insert.point.point.getCharPositionInLine()).add(insert);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inserts = insertsOnLines;
|
|
||||||
|
|
||||||
logger.info("TYPES ARE:");
|
|
||||||
insertsOnLines.forEach((key, value) -> value.forEach(type -> logger.info(type.point.getInsertString())));
|
|
||||||
ArrayList<LSPVariable> variables = new ArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
for(var entrySet : insertsOnLines.entrySet()){
|
|
||||||
ArrayList<Type> typesOfVariable = new ArrayList<>();
|
|
||||||
|
|
||||||
for(PlaceholderVariable typeinsert : entrySet.getValue()){
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for (var variable : variables) {
|
|
||||||
|
|
||||||
HashMap<String, Type> uniqueType = new HashMap<>();
|
|
||||||
|
|
||||||
for (var type : variable.getPossibleTypes()) {
|
|
||||||
if (!uniqueType.containsKey(type.getType().replaceAll(" ", ""))) {
|
|
||||||
uniqueType.put(type.getType(), type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
variable.setPossibleTypes(new ArrayList<>(uniqueType.values()));
|
|
||||||
logger.info(variable.getLine() + ":" + variable.getCharPosition());
|
|
||||||
for (Type t : variable.getPossibleTypes()) {
|
|
||||||
logger.info(t.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return variables;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return methodsWithParametersLSPVariableList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SourceFile getNewAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
|
|
||||||
LanguageServerInterface languageServerInterface = new LanguageServerInterface();
|
|
||||||
return languageServerInterface.getAst(uri, RESET_TO_LETTER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateAst(String uri) throws IOException, URISyntaxException, ClassNotFoundException {
|
|
||||||
logger.info("Old AST:");
|
|
||||||
logger.info(ASTPrinter.print(this.current.getAst()));
|
|
||||||
this.current = new LanguageServerTransferObject(current.getResultSets(), getNewAst(uri), "", current.getGeneratedGenerics());
|
|
||||||
|
|
||||||
logger.info("NEW AST:");
|
|
||||||
logger.info(ASTPrinter.print(current.getAst()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateCurrent(List<ResultSet> resultSets){
|
|
||||||
current.getResultSets().addAll(resultSets);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@@ -1,39 +0,0 @@
|
|||||||
package de.dhbw.helper;
|
|
||||||
|
|
||||||
import de.dhbw.model.Type;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TypeUtils {
|
|
||||||
|
|
||||||
public ArrayList<Type> getAvailableTypes(List<ResultSet> resultSets, RefTypeOrTPHOrWildcardOrGeneric parameter) {
|
|
||||||
|
|
||||||
ArrayList<String> paramTypes = new ArrayList<>();
|
|
||||||
resultSets.forEach(conSet -> {
|
|
||||||
if (parameter.toString().toLowerCase().contains("tph ")) {
|
|
||||||
paramTypes.add(conSet.resolveType(parameter).resolvedType.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return new ArrayList<>(paramTypes.stream().filter(el -> !el.contains("TPH ")).map(el -> new Type(el, false)).toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Type> getAvailableTypes(List<ResultSet> resultSets, Method method) {
|
|
||||||
ArrayList<String> normalType = new ArrayList<>();
|
|
||||||
|
|
||||||
resultSets.forEach(conSet -> {
|
|
||||||
if (method.getReturnType().toString().toLowerCase().contains("tph ")) {
|
|
||||||
normalType.add(conSet.resolveType(method.getReturnType()).resolvedType.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
return new ArrayList<>(normalType.stream().filter(el -> !el.contains("TPH ")).map(el -> new Type(el, false)).toList());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,33 +0,0 @@
|
|||||||
package de.dhbw.model;
|
|
||||||
|
|
||||||
import org.eclipse.lsp4j.Diagnostic;
|
|
||||||
import org.eclipse.lsp4j.InlayHint;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DiagnosticsAndTypehints {
|
|
||||||
private List<Diagnostic> diagnostics;
|
|
||||||
private List<InlayHint> inlayHints;
|
|
||||||
|
|
||||||
public List<Diagnostic> getDiagnostics() {
|
|
||||||
return diagnostics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<InlayHint> getInlayHints() {
|
|
||||||
return inlayHints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDiagnostics(List<Diagnostic> diagnostics) {
|
|
||||||
this.diagnostics = diagnostics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInlayHints(List<InlayHint> inlayHints) {
|
|
||||||
this.inlayHints = inlayHints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DiagnosticsAndTypehints(List<Diagnostic> diagnostics, List<InlayHint> inlayHints){
|
|
||||||
this.diagnostics = diagnostics;
|
|
||||||
this.inlayHints = inlayHints;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
package de.dhbw.model;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DocumentChanges {
|
|
||||||
HashMap<LineCharPosition, String> preciseChanges = new HashMap<>();
|
|
||||||
ArrayList<Integer> offsetPerLine = new ArrayList<>();
|
|
||||||
HashMap<Integer, List<String>> textChanges = new HashMap<>();
|
|
||||||
|
|
||||||
public ArrayList<Integer> getOffsetPerLine() {
|
|
||||||
return offsetPerLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<Integer, List<String>> getTextChanges() {
|
|
||||||
return textChanges;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<LineCharPosition, String> getPreciseChanges() {
|
|
||||||
return preciseChanges;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOffsetPerLine(ArrayList<Integer> offsetPerLine) {
|
|
||||||
this.offsetPerLine = offsetPerLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPreciseChanges(HashMap<LineCharPosition, String> preciseChanges) {
|
|
||||||
this.preciseChanges = preciseChanges;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTextChanges(HashMap<Integer, List<String>> textChanges) {
|
|
||||||
this.textChanges = textChanges;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DocumentChanges(HashMap<LineCharPosition, String> preciseChanges, ArrayList<Integer> offsetPerLine, HashMap<Integer, List<String>> textChanges){
|
|
||||||
this.preciseChanges = preciseChanges;
|
|
||||||
this.offsetPerLine = offsetPerLine;
|
|
||||||
this.textChanges = textChanges;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,11 +1,9 @@
|
|||||||
package de.dhbw.model;
|
package de.dhbw.model;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class LSPClass extends LSPVariable{
|
public class LSPClass extends LSPVariable{
|
||||||
public LSPClass(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
public LSPClass(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition) {
|
||||||
super(name, possibleTypes, line, charPosition, endPosition, originalTphName);
|
super(name, possibleTypes, line, charPosition, endPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,9 @@
|
|||||||
package de.dhbw.model;
|
package de.dhbw.model;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class LSPMethod extends LSPVariable {
|
public class LSPMethod extends LSPVariable {
|
||||||
public LSPMethod(String name, ArrayList<Type> type, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
public LSPMethod(String name, ArrayList<Type> type, int line, int charPosition, int endPosition) {
|
||||||
super(name, type, line, charPosition, endPosition, originalTphName);
|
super(name, type, line, charPosition, endPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,10 @@
|
|||||||
package de.dhbw.model;
|
package de.dhbw.model;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class LSPParameter extends LSPVariable {
|
public class LSPParameter extends LSPMethod {
|
||||||
|
|
||||||
public LSPParameter(String name, ArrayList<Type> type, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
public LSPParameter(String name, ArrayList<Type> type, int line, int charPosition, int endPosition) {
|
||||||
super(name, type, line, charPosition, endPosition, originalTphName);
|
super(name, type, line, charPosition, endPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,33 +1,20 @@
|
|||||||
package de.dhbw.model;
|
package de.dhbw.model;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class LSPVariable {
|
public class LSPVariable { String name;
|
||||||
String name;
|
|
||||||
ArrayList<Type> possibleTypes;
|
ArrayList<Type> possibleTypes;
|
||||||
int line;
|
int line;
|
||||||
int charPosition;
|
int charPosition;
|
||||||
int endPosition;
|
int endPosition;
|
||||||
boolean needsInference;
|
boolean needsInference;
|
||||||
RefTypeOrTPHOrWildcardOrGeneric originalTphName;
|
|
||||||
|
|
||||||
public LSPVariable(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition, RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
public LSPVariable(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.possibleTypes = possibleTypes;
|
this.possibleTypes = possibleTypes;
|
||||||
this.line = line;
|
this.line = line;
|
||||||
this.charPosition = charPosition;
|
this.charPosition = charPosition;
|
||||||
this.endPosition = endPosition;
|
this.endPosition = endPosition;
|
||||||
this.originalTphName = originalTphName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getOriginalTphName() {
|
|
||||||
return originalTphName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOriginalTphName(RefTypeOrTPHOrWildcardOrGeneric originalTphName) {
|
|
||||||
this.originalTphName = originalTphName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndPosition() {
|
public int getEndPosition() {
|
||||||
|
@@ -1,25 +0,0 @@
|
|||||||
package de.dhbw.model;
|
|
||||||
|
|
||||||
public class LineCharPosition {
|
|
||||||
public final int line;
|
|
||||||
public final int charPosition;
|
|
||||||
|
|
||||||
public LineCharPosition(int line, int charPosition) {
|
|
||||||
this.line = line;
|
|
||||||
this.charPosition = charPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof LineCharPosition)) return false;
|
|
||||||
LineCharPosition that = (LineCharPosition) o;
|
|
||||||
return line == that.line && charPosition == that.charPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Line " + line + ", Char " + charPosition;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,93 +0,0 @@
|
|||||||
package de.dhbw.model;
|
|
||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class PlaceholderPoint {
|
|
||||||
public Token point;
|
|
||||||
private String insertString;
|
|
||||||
private int extraOffset = 0;
|
|
||||||
private PlaceholderType kind;
|
|
||||||
|
|
||||||
public PlaceholderPoint(Token point, String toInsert, PlaceholderType kind){
|
|
||||||
this.point = point;
|
|
||||||
this.kind = kind;
|
|
||||||
this.insertString = (toInsert.endsWith(" ")) ? toInsert : toInsert + " " ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGenericClassInsertPoint() {
|
|
||||||
return kind == PlaceholderType.GENERIC_CLASS_INSERT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String insert(String intoSource, List<PlaceholderPoint> additionalOffset){
|
|
||||||
return new StringBuilder(intoSource).insert(point.getStartIndex()+extraOffset, insertString).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInsertString() {
|
|
||||||
return insertString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addExtraOffset(int toAdd) {
|
|
||||||
this.extraOffset += toAdd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPositionInCode() {
|
|
||||||
return point.getStartIndex() + extraOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* PL 2018-06-19
|
|
||||||
* Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind
|
|
||||||
* eingefuegt damit man TypeReplaceMarker vergleichen kann
|
|
||||||
* @see java.lang.Object#equals(java.lang.Object)
|
|
||||||
*/
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
return this == obj;
|
|
||||||
/*
|
|
||||||
if(!(obj instanceof TypeInsertPoint)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return
|
|
||||||
((TypeInsertPoint)obj).getPositionInCode() == this.getPositionInCode() &&
|
|
||||||
((TypeInsertPoint)obj).insertString.equals(this.insertString);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return getPositionInCode() * 11 * insertString.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<PlaceholderPoint> getAdditionalPoints() {
|
|
||||||
return this.getAdditionalPoints();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return point.getLine() + ":" + point.getCharPositionInLine() + ":" + insertString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class TypeInsertPointPositionComparator implements Comparator<PlaceholderPoint> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(PlaceholderPoint o1, PlaceholderPoint o2) {
|
|
||||||
if (o1.point == null && o2.point == null) {
|
|
||||||
return 0;
|
|
||||||
} else if (o2.point == null) {
|
|
||||||
return 1;
|
|
||||||
} else if (o1.point == null) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (o1.getPositionInCode() > o2.getPositionInCode()) {
|
|
||||||
return 1;
|
|
||||||
} else if (o1.getPositionInCode() < o2.getPositionInCode()) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,7 +0,0 @@
|
|||||||
package de.dhbw.model;
|
|
||||||
|
|
||||||
public enum PlaceholderType {
|
|
||||||
NORMAL_INSERT,
|
|
||||||
GENERIC_CLASS_INSERT,
|
|
||||||
GENERERIC_METHOD_INSERT
|
|
||||||
}
|
|
@@ -1,68 +0,0 @@
|
|||||||
package de.dhbw.model;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class PlaceholderVariable {
|
|
||||||
/**
|
|
||||||
* point wird hauptsächlich zur Anzeige einer Annotation im Eclipse-plugin benutzt.
|
|
||||||
*/
|
|
||||||
public final PlaceholderPoint point;
|
|
||||||
Set<PlaceholderPoint> inserts;
|
|
||||||
ResultPair<?, ?> resultPair;
|
|
||||||
|
|
||||||
public PlaceholderVariable(PlaceholderPoint point, Set<PlaceholderPoint> additionalPoints, ResultPair<?, ?> resultPair) {
|
|
||||||
this.point = point;
|
|
||||||
inserts = additionalPoints;
|
|
||||||
this.resultPair = resultPair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String insert(String intoSource) {
|
|
||||||
List<PlaceholderPoint> offsets = new ArrayList<>();
|
|
||||||
String ret = intoSource;
|
|
||||||
|
|
||||||
List<PlaceholderPoint> insertsSorted = new ArrayList<>();
|
|
||||||
insertsSorted.add(point);
|
|
||||||
insertsSorted.addAll(inserts);
|
|
||||||
Collections.sort(insertsSorted, new PlaceholderPoint.TypeInsertPointPositionComparator().reversed());
|
|
||||||
|
|
||||||
for (PlaceholderPoint insertPoint : insertsSorted) {
|
|
||||||
ret = insertPoint.insert(ret, new ArrayList<>());
|
|
||||||
offsets.add(insertPoint);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInsertString() {
|
|
||||||
return point.getInsertString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResultPair<?, ?> getResultPair() {
|
|
||||||
return this.resultPair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (!(obj instanceof PlaceholderVariable)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return ((PlaceholderVariable) obj).point.equals(this.point);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<PlaceholderPoint> getAdditionalPoints() {
|
|
||||||
PlaceholderPoint.TypeInsertPointPositionComparator comparator = new PlaceholderPoint.TypeInsertPointPositionComparator();
|
|
||||||
TreeSet<PlaceholderPoint> result = new TreeSet<>(comparator.reversed());
|
|
||||||
result.addAll(inserts);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<PlaceholderPoint> getAdditionalPointsUnsorted() {
|
|
||||||
return inserts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return point.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -24,15 +24,4 @@ public class Type {
|
|||||||
public boolean isGeneric() {
|
public boolean isGeneric() {
|
||||||
return generic;
|
return generic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
return type.equals(obj.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,155 +0,0 @@
|
|||||||
package de.dhbw.service;
|
|
||||||
|
|
||||||
import de.dhbw.helper.CodeSnippetOptions;
|
|
||||||
import de.dhbw.helper.TextHelper;
|
|
||||||
import de.dhbw.helper.TypeResolver;
|
|
||||||
import de.dhbw.model.LSPVariable;
|
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
|
||||||
import org.eclipse.lsp4j.Diagnostic;
|
|
||||||
import org.eclipse.lsp4j.InlayHint;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CacheService {
|
|
||||||
private HashMap<String, List<InlayHint>> globalInlayHintMap = new HashMap<>();
|
|
||||||
private HashMap<String, String> lastSavedFiles = new HashMap<>();
|
|
||||||
private Boolean currentlyCalculating = false;
|
|
||||||
private HashMap<String, List<Diagnostic>> globalDiagnosticsMap = new HashMap<>();
|
|
||||||
private HashMap<String, String> textDocuments = new HashMap<>();
|
|
||||||
private CodeSnippetOptions codeSnippetOptions = new CodeSnippetOptions();
|
|
||||||
private TextHelper textHelper = new TextHelper();
|
|
||||||
private Boolean dontShowHints = false;
|
|
||||||
private TypeResolver typeResolver = new TypeResolver();
|
|
||||||
private Path fileRoot = null;
|
|
||||||
private Boolean singleFileOpened = false;
|
|
||||||
private List<LSPVariable> variables = new ArrayList<>();
|
|
||||||
private List<TypeInsert> typeInserts;
|
|
||||||
|
|
||||||
public List<TypeInsert> getTypeInserts() {
|
|
||||||
return typeInserts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeInserts(List<TypeInsert> typeInserts) {
|
|
||||||
this.typeInserts = typeInserts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset(){
|
|
||||||
globalInlayHintMap = new HashMap<>();
|
|
||||||
lastSavedFiles = new HashMap<>();
|
|
||||||
currentlyCalculating = false;
|
|
||||||
globalDiagnosticsMap = new HashMap<>();
|
|
||||||
textDocuments = new HashMap<>();
|
|
||||||
codeSnippetOptions = new CodeSnippetOptions();
|
|
||||||
textHelper = new TextHelper();
|
|
||||||
dontShowHints = false;
|
|
||||||
typeResolver = new TypeResolver();
|
|
||||||
fileRoot = null;
|
|
||||||
singleFileOpened = false;
|
|
||||||
typeInserts = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void updateGlobalMaps(List<Diagnostic> diagnostics, List<InlayHint> typeHint, String uri) {
|
|
||||||
globalDiagnosticsMap.put(uri, diagnostics);
|
|
||||||
globalInlayHintMap.put(uri, typeHint);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getCurrentlyCalculating() {
|
|
||||||
return currentlyCalculating;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getDontShowHints() {
|
|
||||||
return dontShowHints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getSingleFileOpened() {
|
|
||||||
return singleFileOpened;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, String> getLastSavedFiles() {
|
|
||||||
return lastSavedFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastSavedFiles(HashMap<String, String> lastSavedFiles) {
|
|
||||||
this.lastSavedFiles = lastSavedFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CodeSnippetOptions getCodeSnippetOptions() {
|
|
||||||
return codeSnippetOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, List<Diagnostic>> getGlobalDiagnosticsMap() {
|
|
||||||
return globalDiagnosticsMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, List<InlayHint>> getGlobalInlayHintMap() {
|
|
||||||
return globalInlayHintMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, String> getTextDocuments() {
|
|
||||||
return textDocuments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<LSPVariable> getVariables() {
|
|
||||||
return variables;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Path getFileRoot() {
|
|
||||||
return fileRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextHelper getTextHelper() {
|
|
||||||
return textHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypeResolver getTypeResolver() {
|
|
||||||
return typeResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCodeSnippetOptions(CodeSnippetOptions codeSnippetOptions) {
|
|
||||||
this.codeSnippetOptions = codeSnippetOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCurrentlyCalculating(Boolean currentlyCalculating) {
|
|
||||||
this.currentlyCalculating = currentlyCalculating;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDontShowHints(Boolean dontShowHints) {
|
|
||||||
this.dontShowHints = dontShowHints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFileRoot(Path fileRoot) {
|
|
||||||
this.fileRoot = fileRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGlobalDiagnosticsMap(HashMap<String, List<Diagnostic>> globalDiagnosticsMap) {
|
|
||||||
this.globalDiagnosticsMap = globalDiagnosticsMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGlobalInlayHintMap(HashMap<String, List<InlayHint>> globalInlayHintMap) {
|
|
||||||
this.globalInlayHintMap = globalInlayHintMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSingleFileOpened(Boolean singleFileOpened) {
|
|
||||||
this.singleFileOpened = singleFileOpened;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTextDocuments(HashMap<String, String> textDocuments) {
|
|
||||||
this.textDocuments = textDocuments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTextHelper(TextHelper textHelper) {
|
|
||||||
this.textHelper = textHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypeResolver(TypeResolver typeResolver) {
|
|
||||||
this.typeResolver = typeResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVariables(List<LSPVariable> variables) {
|
|
||||||
this.variables = variables;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
package de.dhbw.service;
|
|
||||||
|
|
||||||
import org.eclipse.lsp4j.*;
|
|
||||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
|
||||||
import org.eclipse.lsp4j.services.LanguageClient;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ClientService {
|
|
||||||
|
|
||||||
private LanguageClient client;
|
|
||||||
|
|
||||||
public ClientService(LanguageClient client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void publishDiagnostics(String uri, List<Diagnostic> diagnostics){
|
|
||||||
PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(uri, diagnostics);
|
|
||||||
client.publishDiagnostics(diagnosticsParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendClientLog(MessageType type, String message){
|
|
||||||
client.logMessage(new MessageParams(type, message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendClientLog(String message){
|
|
||||||
client.logMessage(new MessageParams(MessageType.Info, message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showMessage(MessageType type, String message) {
|
|
||||||
client.showMessage(new MessageParams(type, message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showMessage(String message) {
|
|
||||||
client.showMessage(new MessageParams(MessageType.Info, message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClient(LanguageClient client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateClient(LanguageClient client) {
|
|
||||||
client.refreshInlayHints();
|
|
||||||
client.refreshDiagnostics();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateClient() {
|
|
||||||
client.refreshInlayHints();
|
|
||||||
client.refreshDiagnostics();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LanguageClient getClient() {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startLoading(String taskName, String title, LanguageClient client) {
|
|
||||||
Either<String, Integer> token = Either.forLeft(taskName);
|
|
||||||
client.createProgress(new WorkDoneProgressCreateParams(token));
|
|
||||||
|
|
||||||
WorkDoneProgressBegin begin = new WorkDoneProgressBegin();
|
|
||||||
begin.setTitle(title);
|
|
||||||
begin.setCancellable(false);
|
|
||||||
begin.setPercentage(0);
|
|
||||||
|
|
||||||
ProgressParams beginParams = new ProgressParams(token, Either.forLeft(begin));
|
|
||||||
client.notifyProgress(beginParams);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopLoading(String taskName, String title, LanguageClient client) {
|
|
||||||
Either<String, Integer> token = Either.forLeft(taskName);
|
|
||||||
WorkDoneProgressEnd end = new WorkDoneProgressEnd();
|
|
||||||
end.setMessage(title);
|
|
||||||
|
|
||||||
ProgressParams endParams = new ProgressParams(token, Either.forLeft(end));
|
|
||||||
client.notifyProgress(endParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,31 +0,0 @@
|
|||||||
package de.dhbw.service;
|
|
||||||
|
|
||||||
import org.apache.log4j.LogManager;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.eclipse.lsp4j.MessageType;
|
|
||||||
|
|
||||||
public class LogService {
|
|
||||||
|
|
||||||
private final Logger logger = LogManager.getLogger(LogService.class);
|
|
||||||
private final ClientService clientService;
|
|
||||||
|
|
||||||
public LogService(ClientService clientService) {
|
|
||||||
this.clientService = clientService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void log(String message, MessageType type) {
|
|
||||||
clientService.sendClientLog(type, message);
|
|
||||||
switch (type) {
|
|
||||||
case Error -> logger.error(message);
|
|
||||||
case Warning -> logger.warn(message);
|
|
||||||
case Info -> logger.info(message);
|
|
||||||
default -> logger.debug(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void log(String message) {
|
|
||||||
clientService.sendClientLog(MessageType.Info, message);
|
|
||||||
logger.info(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
package de.dhbw.service;
|
|
||||||
|
|
||||||
import de.dhbw.helper.ConversionHelper;
|
|
||||||
import de.dhbwstuttgart.languageServerInterface.ParserInterface;
|
|
||||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
|
||||||
import org.eclipse.lsp4j.Diagnostic;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ParserService {
|
|
||||||
|
|
||||||
private final ConversionHelper conversionHelper;
|
|
||||||
private final ClientService clientService;
|
|
||||||
|
|
||||||
|
|
||||||
public ParserService(ConversionHelper conversionHelper, ClientService clientService, CacheService cacheService) {
|
|
||||||
this.conversionHelper = conversionHelper;
|
|
||||||
this.clientService = clientService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ParserError> getParserErrors(String input){
|
|
||||||
ParserInterface parserInterface = new ParserInterface();
|
|
||||||
return parserInterface.getParseErrors(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkParser(String input, String uri) {
|
|
||||||
List<Diagnostic> diagnosticsList = conversionHelper.parseErrorToDiagnostic(getParserErrors(input));
|
|
||||||
clientService.publishDiagnostics(uri, diagnosticsList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Diagnostic> getDiagnosticsOfErrors(String input, String uri) {
|
|
||||||
return conversionHelper.parseErrorToDiagnostic(getParserErrors(input));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,121 +0,0 @@
|
|||||||
package de.dhbw.service;
|
|
||||||
|
|
||||||
import de.dhbw.model.DocumentChanges;
|
|
||||||
import de.dhbw.model.LineCharPosition;
|
|
||||||
import org.eclipse.lsp4j.Range;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class TextDocumentService {
|
|
||||||
|
|
||||||
private final HashMap<String, String> files = new HashMap<>();
|
|
||||||
|
|
||||||
public TextDocumentService(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset(){
|
|
||||||
files.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getFileOfUri(String uri) {
|
|
||||||
return files.get(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveFileWithUri(String uri, String input) {
|
|
||||||
files.put(uri, input);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DocumentChanges calculateDifference(String currentText, String newText){
|
|
||||||
ArrayList<String> currentTextLines = new ArrayList<>(Arrays.stream(currentText.split("\n")).toList());
|
|
||||||
ArrayList<String> newTextLines = new ArrayList<>(Arrays.stream(newText.split("\n")).toList());
|
|
||||||
HashMap<LineCharPosition, String> preciseChanges = new HashMap<>();
|
|
||||||
ArrayList<Integer> offsetPerLine = new ArrayList<>();
|
|
||||||
HashMap<Integer, List<String>> textChanges = new HashMap<>();
|
|
||||||
int index = 0;
|
|
||||||
for (String newTextLine : newTextLines) {
|
|
||||||
if (!(currentTextLines.size() > index)) {
|
|
||||||
offsetPerLine.add(0);
|
|
||||||
} else {
|
|
||||||
Map<LineCharPosition, String> lineDiffs = differenceLinePos(currentTextLines.get(index), newTextLine, index);
|
|
||||||
preciseChanges.putAll(lineDiffs);
|
|
||||||
textChanges.put(index, difference(currentTextLines.get(index), newTextLine).stream().map(el -> el.replaceAll(" ", "")).toList());
|
|
||||||
offsetPerLine.add(newTextLine.length() - currentTextLines.get(index).length());
|
|
||||||
}
|
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DocumentChanges(preciseChanges, offsetPerLine, textChanges);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<LineCharPosition, String> differenceLinePos(String first, String second, int line) {
|
|
||||||
Map<LineCharPosition, String> result = new HashMap<>();
|
|
||||||
|
|
||||||
int i = 0, j = 0;
|
|
||||||
int startDiff = -1;
|
|
||||||
|
|
||||||
while (j < second.length()) {
|
|
||||||
if (i < first.length() && first.charAt(i) == second.charAt(j)) {
|
|
||||||
if (startDiff != -1) {
|
|
||||||
String diff = second.substring(startDiff, j);
|
|
||||||
result.put(new LineCharPosition(line, startDiff), diff);
|
|
||||||
startDiff = -1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
} else {
|
|
||||||
if (startDiff == -1) {
|
|
||||||
startDiff = j;
|
|
||||||
}
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startDiff != -1) {
|
|
||||||
String diff = second.substring(startDiff);
|
|
||||||
result.put(new LineCharPosition(line, startDiff), diff);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> difference(String first, String second) {
|
|
||||||
ArrayList<String> result = new ArrayList<>();
|
|
||||||
|
|
||||||
int i = 0, j = 0;
|
|
||||||
int startDiff = -1;
|
|
||||||
|
|
||||||
while (j < second.length()) {
|
|
||||||
if (i < first.length() && first.charAt(i) == second.charAt(j)) {
|
|
||||||
if (startDiff != -1) {
|
|
||||||
result.add(second.substring(startDiff, j));
|
|
||||||
startDiff = -1;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
} else {
|
|
||||||
if (startDiff == -1) {
|
|
||||||
startDiff = j;
|
|
||||||
}
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startDiff != -1) {
|
|
||||||
result.add(second.substring(startDiff));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean rangesOverlap(Range range1, Range range2) {
|
|
||||||
int start1 = range1.getStart().getLine() * 1000 + range1.getStart().getCharacter();
|
|
||||||
int end1 = range1.getEnd().getLine() * 1000 + range1.getEnd().getCharacter();
|
|
||||||
int start2 = range2.getStart().getLine() * 1000 + range2.getStart().getCharacter();
|
|
||||||
int end2 = range2.getEnd().getLine() * 1000 + range2.getEnd().getCharacter();
|
|
||||||
|
|
||||||
return start1 <= end2 && start2 <= end1;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
import de.dhbw.helper.CodeSnippetOptions;
|
import de.dhbw.helper.CodeSnippetOptions;
|
||||||
|
import de.dhbw.model.SnippetWithName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
@@ -6,12 +6,25 @@ import org.junit.Assert;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class CompilerInterfaceTest {
|
public class CompilerInterfaceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAbstractSyntaxAsString() throws IOException, ClassNotFoundException, URISyntaxException {
|
public void testAbstractSyntaxAsString() throws IOException, ClassNotFoundException {
|
||||||
|
// LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||||
|
// var res = languageServer.getResultSetAndAbstractSyntax("import java.lang.Integer;\n import java.lang.String;\n" +
|
||||||
|
// "public class test{\n" +
|
||||||
|
// "public main(test){" +
|
||||||
|
// "if(0>1){" +
|
||||||
|
// "return \"w\";" +
|
||||||
|
// "}" +
|
||||||
|
// "Integer i = 0;" +
|
||||||
|
// "return i;" +
|
||||||
|
// "}" +
|
||||||
|
// "}", "TEST");
|
||||||
|
//
|
||||||
|
// System.out.println("TEST OUTPUT:");
|
||||||
//
|
//
|
||||||
// ArrayList<String> allTypes = new ArrayList<>();
|
// ArrayList<String> allTypes = new ArrayList<>();
|
||||||
//
|
//
|
||||||
@@ -27,16 +40,18 @@ public class CompilerInterfaceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstraintTypes() throws IOException, ClassNotFoundException, URISyntaxException {
|
public void testConstraintTypes() throws IOException, ClassNotFoundException {
|
||||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
// LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||||
TypeResolver typeResolver = new TypeResolver();
|
// TypeResolver typeResolver = new TypeResolver();
|
||||||
|
//
|
||||||
|
//
|
||||||
var res = languageServer.getResultSetAndAbstractSyntax("/home/ruben/Documents/JavaTXLanguageServer/test/test.jav");
|
// var res = typeResolver.infereInput("import java.lang.Integer; public class test{\n" +
|
||||||
|
// " \n" +
|
||||||
var res2 = languageServer.getResultSetAndAbstractSyntax("/home/ruben/Documents/JavaTXLanguageServer/test/test.jav");
|
// " public main(testa){\n" +
|
||||||
|
// " return testa;\n" +
|
||||||
System.out.println("");
|
// " }\n" +
|
||||||
|
// "}");
|
||||||
|
// res.forEach(el -> el.getPossibleTypes().forEach(el2 -> System.out.println(el2.getType() + " " + (el2.isGeneric() ? "GENERIC" : "NO GENERIC"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
import de.dhbw.JavaTXTextDocumentService;
|
||||||
|
import de.dhbw.helper.CodeSnippetOptions;
|
||||||
|
import org.eclipse.lsp4j.DidSaveTextDocumentParams;
|
||||||
|
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -7,7 +11,6 @@ public class JavaTXLanguageDocumentServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void testWordExtraction() {
|
public void testWordExtraction() {
|
||||||
// JavaTXTextDocumentService service = new JavaTXTextDocumentService();
|
JavaTXTextDocumentService service = new JavaTXTextDocumentService();
|
||||||
// service.didSave(new DidSaveTextDocumentParams(new TextDocumentIdentifier("file:///c%3A/Users/ruben/Neuer%20Ordner%20%282%29/LSP-Vortrag/images/test.jav")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +0,0 @@
|
|||||||
public class t{
|
|
||||||
public test(){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user