Compare commits
39 Commits
d470a93645
...
Release
Author | SHA1 | Date | |
---|---|---|---|
|
a63af12365 | ||
|
4971e0762c | ||
|
f072e26e1d | ||
|
1e3fa2d315 | ||
|
119ced125d | ||
|
306204d436 | ||
|
bdc0b8a2b6 | ||
|
ecd57ceec7 | ||
|
1803fec36a | ||
|
c3d2252476 | ||
|
1dfa30e05e | ||
|
b08c921933 | ||
|
252f64a2bb | ||
|
7143126741 | ||
|
de2595cf62 | ||
|
58a895b581 | ||
|
0740f95c26 | ||
|
b192e33615 | ||
|
4219678db6 | ||
|
12781de581 | ||
|
89af1759ff | ||
|
1e117600f9 | ||
|
6f457479aa | ||
|
3b0b97841e | ||
|
fbf8704af6 | ||
|
dc896a453d | ||
|
5d41a19705 | ||
|
ae2461b99d | ||
|
234e6eed1a | ||
|
9ea1bff5f4 | ||
|
a4060225e1 | ||
|
2a72aa3a57 | ||
|
cabb7258aa | ||
|
25a1876b8f | ||
|
d9177cbdf2 | ||
|
c0b7f55491 | ||
|
6d0f243c80 | ||
|
bc09039e73 | ||
|
6d6786d3b7 |
6
.idea/JavaTXLanguageServer.iml
generated
Normal file
6
.idea/JavaTXLanguageServer.iml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
</component>
|
||||
</module>
|
42
Clients/Intellij/.gitignore
vendored
Normal file
42
Clients/Intellij/.gitignore
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
3
Clients/Intellij/.idea/.gitignore
generated
vendored
Normal file
3
Clients/Intellij/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
17
Clients/Intellij/.idea/gradle.xml
generated
Normal file
17
Clients/Intellij/.idea/gradle.xml
generated
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
7
Clients/Intellij/.idea/misc.xml
generated
Normal file
7
Clients/Intellij/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<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" />
|
||||
</component>
|
||||
</project>
|
6
Clients/Intellij/.idea/vcs.xml
generated
Normal file
6
Clients/Intellij/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</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()
|
||||
}
|
BIN
Clients/Intellij/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
Clients/Intellij/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
Clients/Intellij/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
Clients/Intellij/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#Thu Feb 20 15:20:24 CET 2025
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
234
Clients/Intellij/gradlew
vendored
Executable file
234
Clients/Intellij/gradlew
vendored
Executable file
@@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
89
Clients/Intellij/gradlew.bat
vendored
Normal file
89
Clients/Intellij/gradlew.bat
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
2
Clients/Intellij/settings.gradle
Normal file
2
Clients/Intellij/settings.gradle
Normal file
@@ -0,0 +1,2 @@
|
||||
rootProject.name = 'Intellij'
|
||||
|
17
Clients/Intellij/src/main/java/org/example/Main.java
Normal file
17
Clients/Intellij/src/main/java/org/example/Main.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package org.example;
|
||||
|
||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
||||
// to see how IntelliJ IDEA suggests fixing it.
|
||||
System.out.printf("Hello and welcome!");
|
||||
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
||||
System.out.println("i = " + i);
|
||||
}
|
||||
}
|
||||
}
|
76
Clients/Intellij/src/resources/META-INF/plugin.xml
Normal file
76
Clients/Intellij/src/resources/META-INF/plugin.xml
Normal file
@@ -0,0 +1,76 @@
|
||||
<!--
|
||||
an example how you can configure an plugin xml with you plugin
|
||||
see also jetbrains documentation: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
|
||||
<idea-plugin>
|
||||
<id>your.plugin.namespace</id>
|
||||
<name>Your Plugin Name</name>
|
||||
<vendor>your company/org</vendor>
|
||||
<description>a description of your plugin</description>
|
||||
|
||||
<!-- Product and plugin compatibility requirements -->
|
||||
<!-- https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html -->
|
||||
<depends>com.intellij.modules.platform</depends>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<!-- register a preloading activity. You need to init IntellijLanguageClient with your config, see readme -->
|
||||
<preloadingActivity implementation="your.plugin.MyPreloadingActivity" id="your.plugin.MyPreloadingActivity"/>
|
||||
|
||||
<!-- register intellijLanguageClient as a Service OR as a plugin component (see readme)... -->
|
||||
<applicationService serviceImplementation="org.wso2.lsp4intellij.IntellijLanguageClient"/>
|
||||
|
||||
<!-- register a listener on editor events, required for lsp file sync -->
|
||||
<editorFactoryListener implementation="org.wso2.lsp4intellij.listeners.LSPEditorListener"/>
|
||||
<fileDocumentManagerListener implementation="org.wso2.lsp4intellij.listeners.LSPFileDocumentManagerListener"/>
|
||||
|
||||
<!-- for displaying notifications by lsp -->
|
||||
<notificationGroup id="lsp" displayType="STICKY_BALLOON"/>
|
||||
|
||||
<!-- for displaying progress notifications by lsp in the Event Log -->
|
||||
<notificationGroup id="LSPProgressNotification" displayType="NONE" />
|
||||
|
||||
<!-- for displaying the statusbar icon -->
|
||||
<statusBarWidgetFactory implementation="org.wso2.lsp4intellij.statusbar.LSPServerStatusWidgetFactory"
|
||||
id="org.wso2.lsp4intellij.statusbar.LSPServerStatusWidgetFactory"
|
||||
order="first" />
|
||||
|
||||
<!-- needed for completion -->
|
||||
<completion.contributor implementationClass="org.wso2.lsp4intellij.contributors.LSPCompletionContributor"
|
||||
id="org.wso2.lsp4intellij.contributors.LSPCompletionContributor" language="YOUR_LANGUAGE_ID"/>
|
||||
<!-- needed for completion as well as signature help -->
|
||||
<typedHandler implementation="org.wso2.lsp4intellij.listeners.LSPTypedHandler"
|
||||
id="LSPTypedHandler"/>
|
||||
|
||||
<!-- needed for code diagnostics -->
|
||||
<externalAnnotator id="LSPAnnotator" language="YOUR_LANGUAGE_ID"
|
||||
implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/>
|
||||
|
||||
<!-- needed for Workspace Symbols -->
|
||||
<gotoSymbolContributor implementation="org.wso2.lsp4intellij.contributors.symbol.LSPSymbolContributor"
|
||||
id="LSPSymbolContributor"/>
|
||||
|
||||
<!-- needed for renaming -->
|
||||
<renameHandler implementation="org.wso2.lsp4intellij.contributors.rename.LSPRenameHandler" id="LSPRenameHandler" order="first"/>
|
||||
<renamePsiElementProcessor implementation="org.wso2.lsp4intellij.contributors.rename.LSPRenameProcessor" id="LSPRenameProcessor" order="first"/>
|
||||
|
||||
<!-- needed for folding support -->
|
||||
<lang.foldingBuilder language="YOUR_LANGUAGE_ID" implementationClass="org.wso2.lsp4intellij.contributors.LSPFoldingRangeProvider" id="LSPFoldingRangeProvider" order="first" />
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
<!-- needed for hover -->
|
||||
<action id="org.intellij.sdk.action.QuickDocAction" class="org.wso2.lsp4intellij.actions.LSPQuickDocAction">
|
||||
</action>
|
||||
|
||||
<!-- needed for find references -->
|
||||
<action class="org.wso2.lsp4intellij.actions.LSPReferencesAction" id="LSPFindUsages">
|
||||
<keyboard-shortcut first-keystroke="shift alt F7" keymap="$default"/>
|
||||
</action>
|
||||
</actions>
|
||||
<applicationListeners>
|
||||
<!-- required for lsp file sync -->
|
||||
<listener class="org.wso2.lsp4intellij.listeners.VFSListener"
|
||||
topic="com.intellij.openapi.vfs.VirtualFileListener"/>
|
||||
<listener class="org.wso2.lsp4intellij.listeners.LSPProjectManagerListener"
|
||||
topic="com.intellij.openapi.project.ProjectManagerListener"/>
|
||||
</applicationListeners>
|
||||
</idea-plugin>
|
Binary file not shown.
@@ -22,7 +22,6 @@ public class JavaTXLanguageServer implements LanguageServer {
|
||||
public void connect(LanguageClient client) {
|
||||
this.client = client;
|
||||
textDocumentService.setClient(client);
|
||||
|
||||
}
|
||||
|
||||
private final JavaTXTextDocumentService textDocumentService = new JavaTXTextDocumentService();
|
||||
|
@@ -1,19 +1,14 @@
|
||||
package de.dhbw;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import de.dhbw.compiler.languageServerInterface.ParserInterface;
|
||||
import de.dhbw.compiler.languageServerInterface.model.ParserError;
|
||||
import de.dhbw.helper.CodeSnippetOptions;
|
||||
import de.dhbw.helper.TextHelper;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
import de.dhbw.model.LSPVariable;
|
||||
import de.dhbw.model.ParseError.DiagnoseErrorListener;
|
||||
import de.dhbw.model.SnippetWithName;
|
||||
import de.dhbw.parser.Java17Lexer;
|
||||
import de.dhbw.parser.Java17Parser;
|
||||
import de.dhbw.parser.Java17ParserBaseListener;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
import de.dhbw.model.Type;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.eclipse.lsp4j.*;
|
||||
@@ -33,7 +28,9 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(JavaTXTextDocumentService.class);
|
||||
LanguageClient client;
|
||||
HashMap<String, ArrayList<LSPVariable>> dataCache = new HashMap<>();
|
||||
HashMap<String, List<InlayHint>> globalInlayHintMap = new HashMap<>();
|
||||
Boolean calculate = false;
|
||||
HashMap<String, List<Diagnostic>> globalDiagnosticsMap = new HashMap<>();
|
||||
HashMap<String, String> textDocuments = new HashMap<>();
|
||||
CodeSnippetOptions codeSnippetOptions = new CodeSnippetOptions();
|
||||
TextHelper textHelper = new TextHelper();
|
||||
@@ -88,30 +85,36 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
*/
|
||||
@Override
|
||||
public void didChange(DidChangeTextDocumentParams params) {
|
||||
logger.debug("DIDCHANGE-EVENT");
|
||||
logger.info("DIDCHANGE-EVENT");
|
||||
|
||||
AtomicReference<String> summedUp = new AtomicReference<>("");
|
||||
params.getContentChanges().forEach(el -> summedUp.set(summedUp.get() + el.getText()));
|
||||
textDocuments.put(params.getTextDocument().getUri(), summedUp.get());
|
||||
DiagnoseErrorListener errorListener = new DiagnoseErrorListener();
|
||||
|
||||
String input = summedUp.get();
|
||||
CharStream charStream = CharStreams.fromString(input);
|
||||
|
||||
Java17Lexer lexer = new Java17Lexer(charStream);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
ParserInterface parserInterface = new ParserInterface();
|
||||
|
||||
Java17Parser parser = new Java17Parser(tokens);
|
||||
parser.removeErrorListeners();
|
||||
parser.addErrorListener(errorListener);
|
||||
List<ParserError> parserErrors = parserInterface.getParseErrors(input);
|
||||
|
||||
|
||||
ParseTree tree = parser.sourceFile();
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
Java17ParserBaseListener listener = new Java17ParserBaseListener();
|
||||
walker.walk(listener, tree);
|
||||
logger.info("Found " + parserErrors.size() + " Errors.");
|
||||
|
||||
PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(params.getTextDocument().getUri(), errorListener.getErrorMessages());
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -123,7 +126,7 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
*/
|
||||
@Override
|
||||
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
|
||||
logger.debug("FORMAT-EVENT");
|
||||
logger.info("FORMAT-EVENT");
|
||||
|
||||
List<TextEdit> edits = new ArrayList<>();
|
||||
|
||||
@@ -149,78 +152,84 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
|
||||
@Override
|
||||
public void didSave(DidSaveTextDocumentParams didSaveTextDocumentParams) {
|
||||
calculate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<InlayHint>> inlayHint(InlayHintParams params) {
|
||||
logger.info("The Client requested Inlay-Hints.");
|
||||
|
||||
logger.debug("INLAYHINT-EVENT");
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||
try {
|
||||
ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||
var sWatch = Stopwatch.createUnstarted();
|
||||
sWatch.start();
|
||||
try {
|
||||
|
||||
ArrayList<LSPVariable> typesOfMethodAndParameters;
|
||||
ArrayList<LSPVariable> typesOfMethodAndParameters = typeResolver.infereInput(textDocuments.get(params.getTextDocument().getUri()));
|
||||
List<InlayHint> typeHint = new ArrayList<>();
|
||||
|
||||
if(dataCache.containsKey(textDocuments.get(params.getTextDocument().getUri()))){
|
||||
logger.debug("Returning Cache instead of calculating types");
|
||||
typesOfMethodAndParameters = dataCache.get(textDocuments.get(params.getTextDocument().getUri()));
|
||||
}else{
|
||||
typesOfMethodAndParameters = typeResolver.infereMethodsWithParameters(textDocuments.get(params.getTextDocument().getUri()));
|
||||
dataCache.put(textDocuments.get(params.getTextDocument().getUri()), typesOfMethodAndParameters);
|
||||
}
|
||||
List<InlayHint> typeHint = new ArrayList<>();
|
||||
for (var variable : typesOfMethodAndParameters) {
|
||||
|
||||
for (var variable : typesOfMethodAndParameters) {
|
||||
InlayHint inlayHint = new InlayHint();
|
||||
|
||||
String typeDisplay = "";
|
||||
for(Type type : variable.getPossibleTypes()){
|
||||
typeDisplay += " | " + type.getType().replaceAll("GTV ", "");
|
||||
}
|
||||
|
||||
|
||||
InlayHint inlayHint = new InlayHint();
|
||||
|
||||
AtomicReference<String> typeDisplay = new AtomicReference<String>();
|
||||
variable.getPossibleTypes().forEach(el -> {
|
||||
typeDisplay.getAndSet("| " + el);
|
||||
});
|
||||
|
||||
inlayHint.setLabel(typeDisplay.get().substring(2));
|
||||
inlayHint.setPosition(new Position(variable.getLine() - 1, variable.getCharPosition()));
|
||||
inlayHint.setKind(InlayHintKind.Parameter);
|
||||
typeHint.add(inlayHint);
|
||||
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);
|
||||
typeHint.add(inlayHint);
|
||||
|
||||
|
||||
for (var typ : variable.getPossibleTypes()) {
|
||||
Range errorRange = new Range(
|
||||
new Position(variable.getLine() - 1, variable.getCharPosition()), // Startposition
|
||||
new Position(variable.getLine() - 1, textHelper.getEndingCharOfStartingChar(variable.getLine() - 1, variable.getCharPosition(), textDocuments.get(params.getTextDocument().getUri()))) // Endposition
|
||||
);
|
||||
Diagnostic diagnostic = new Diagnostic(
|
||||
errorRange,
|
||||
typ,
|
||||
DiagnosticSeverity.Hint,
|
||||
"JavaTX Language Server"
|
||||
);
|
||||
//Diagnostics of Types
|
||||
for (var typ : variable.getPossibleTypes()) {
|
||||
Range errorRange = new Range(
|
||||
new Position(variable.getLine() - 1, variable.getCharPosition()), // Startposition
|
||||
new Position(variable.getLine() - 1, textHelper.getEndingCharOfStartingChar(variable.getLine() - 1, variable.getCharPosition(), textDocuments.get(params.getTextDocument().getUri()))) // Endposition
|
||||
);
|
||||
Diagnostic diagnostic = new Diagnostic(
|
||||
errorRange,
|
||||
//TODO: REMOVE! Temporary Fix because GTV, like TPH can be thrown away in the TypeResolver
|
||||
typ.getType().replaceAll("GTV ", ""),
|
||||
DiagnosticSeverity.Hint,
|
||||
"JavaTX Language Server"
|
||||
);
|
||||
diagnostic.setCode(typ.isGeneric() ? "GENERIC" : "TYPE");
|
||||
|
||||
|
||||
diagnostics.add(diagnostic);
|
||||
diagnostics.add(diagnostic);
|
||||
}
|
||||
}
|
||||
logger.info("Returning [" + typeHint.size() + "] Inlay-Hints.");
|
||||
|
||||
|
||||
globalDiagnosticsMap.put(params.getTextDocument().getUri(), diagnostics);
|
||||
globalInlayHintMap.put(params.getTextDocument().getUri(), typeHint);
|
||||
|
||||
PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(params.getTextDocument().getUri(), diagnostics);
|
||||
client.publishDiagnostics(diagnosticsParams);
|
||||
sWatch.stop();
|
||||
logger.info("Finished Calculating in [" + sWatch.elapsed().toSeconds() + "s]");
|
||||
|
||||
return typeHint;
|
||||
|
||||
} catch (Exception e) {
|
||||
sWatch.stop();
|
||||
logger.info("Calculating returned an Error after [" + sWatch.elapsed().toSeconds() + "s]");
|
||||
String stacktrace = "";
|
||||
|
||||
for (var i : e.getStackTrace()) {
|
||||
stacktrace += i.toString() + "\n";
|
||||
}
|
||||
|
||||
logger.error("Error trying to get Inlay-Hints and Diagnostics for Client:\n" + e.getMessage() + "\n" + stacktrace);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
logger.debug("Returning " + typeHint.size() + " Typehints.");
|
||||
|
||||
|
||||
PublishDiagnosticsParams diagnosticsParams = new PublishDiagnosticsParams(params.getTextDocument().getUri(), diagnostics);
|
||||
client.publishDiagnostics(diagnosticsParams);
|
||||
|
||||
|
||||
return typeHint;
|
||||
|
||||
} catch (Exception e) {
|
||||
String stacktrace = "";
|
||||
|
||||
for(var i : e.getStackTrace()){
|
||||
stacktrace += i.toString() + "\n";
|
||||
}
|
||||
|
||||
logger.error("Fehler in der Anzeige der Typen: " + e.getMessage() + "\n" + stacktrace);
|
||||
return Collections.emptyList();
|
||||
}});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -353,37 +362,68 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
|
||||
logger.debug("INSERT-EVENT");
|
||||
List<Diagnostic> diagnostics = params.getContext().getDiagnostics();
|
||||
logger.info("Client requested Insert at Line [" + params.getRange().getStart().getLine() + "] and from Char [" + params.getRange().getStart().getCharacter() + "] to [" + params.getRange().getEnd().getCharacter() + "].");
|
||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
||||
|
||||
|
||||
List<Diagnostic> diagnosticInCurrentDocument = params.getContext().getDiagnostics();
|
||||
logger.info("Document has currently [" + diagnosticInCurrentDocument.size() + "] Diagnostics.");
|
||||
Range requestedRange = params.getRange();
|
||||
|
||||
List<Diagnostic> relevantDiagnostics = diagnostics.stream()
|
||||
//All Diagnostics that are in range of the hover -> All Diagnostics of the selected Variable and thus all Types of the Variable
|
||||
List<Diagnostic> diagnosticsOverlappingHover = diagnosticInCurrentDocument.stream()
|
||||
.filter(diagnostic -> rangesOverlap(diagnostic.getRange(), requestedRange)).toList();
|
||||
|
||||
Range range = params.getRange();
|
||||
Range rangeOfInsert = params.getRange();
|
||||
String documentUri = params.getTextDocument().getUri();
|
||||
|
||||
List<Either<Command, CodeAction>> actions = new ArrayList<>();
|
||||
for (Diagnostic typeDiagnostic : relevantDiagnostics) {
|
||||
|
||||
for (Diagnostic typeDiagnostic : diagnosticsOverlappingHover) {
|
||||
try {
|
||||
String replacementText = typeDiagnostic.getMessage() +
|
||||
String typeWithReplacedVariable = typeDiagnostic.getMessage() +
|
||||
" " +
|
||||
textHelper.getTextOfChars(
|
||||
textDocuments.get(params.getTextDocument().getUri()),
|
||||
range.getStart().getLine(),
|
||||
range.getStart().getCharacter(),
|
||||
range.getEnd().getCharacter()
|
||||
rangeOfInsert.getStart().getLine(),
|
||||
rangeOfInsert.getStart().getCharacter(),
|
||||
rangeOfInsert.getEnd().getCharacter()
|
||||
);
|
||||
|
||||
var listOfChanges = new ArrayList<>(List.of(new TextEdit(range, replacementText)));
|
||||
ArrayList<TextEdit> listOfChanges = new ArrayList<>();
|
||||
|
||||
var isTypeImported = typeResolver.isTypeImported(textDocuments.get(params.getTextDocument().getUri()), typeDiagnostic.getMessage());
|
||||
if (!isTypeImported) {
|
||||
Range importRange = new Range(new Position(0, 0), new Position(0, 0));
|
||||
listOfChanges.add(new TextEdit(importRange, "import " + typeDiagnostic.getMessage() + ";\n"));
|
||||
if (typeDiagnostic.getCode().getLeft().equals("GENERIC")) {
|
||||
for (var diagnostic : globalDiagnosticsMap.get(params.getTextDocument().getUri())) {
|
||||
|
||||
if (diagnostic.getMessage().contains(typeDiagnostic.getMessage()) || typeDiagnostic.getMessage().contains(diagnostic.getMessage())) {
|
||||
String genericType = diagnostic.getMessage() +
|
||||
" " +
|
||||
textHelper.getTextOfChars(
|
||||
textDocuments.get(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));
|
||||
}
|
||||
|
||||
logger.debug("Returning " + listOfChanges.size() + " Changes for the Document.");
|
||||
var isTypeImported = false;
|
||||
|
||||
if (!typeDiagnostic.getCode().getLeft().equalsIgnoreCase("generic")) {
|
||||
isTypeImported = typeResolver.isTypeImported(textDocuments.get(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"));
|
||||
}
|
||||
|
||||
logger.info("Returning [" + listOfChanges.size() + "] Changes for the Document.");
|
||||
|
||||
Map<String, List<TextEdit>> changes = new HashMap<>();
|
||||
changes.put(documentUri, listOfChanges);
|
||||
|
||||
@@ -394,8 +434,8 @@ public class JavaTXTextDocumentService implements org.eclipse.lsp4j.services.Tex
|
||||
action.setKind(CodeActionKind.QuickFix);
|
||||
action.setEdit(edit);
|
||||
actions.add(Either.forRight(action));
|
||||
} catch (Exception ignored) {
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error creating Actions, returning empty List. The Error was:\n" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,7 +5,7 @@ import de.dhbw.compiler.bytecode.Codegen;
|
||||
import de.dhbw.compiler.environment.CompilationEnvironment;
|
||||
import de.dhbw.compiler.environment.DirectoryClassLoader;
|
||||
import de.dhbw.compiler.exceptions.DebugException;
|
||||
import de.dhbw.compiler.languageServerInterface.LanguageServerTransferObject;
|
||||
import de.dhbw.compiler.languageServerInterface.model.LanguageServerTransferObject;
|
||||
import de.dhbw.compiler.parser.JavaTXParser;
|
||||
import de.dhbw.compiler.parser.NullToken;
|
||||
import de.dhbw.compiler.parser.scope.GenericsRegistry;
|
||||
@@ -57,7 +57,7 @@ import java.util.Map.Entry;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbw.parser.Java17Parser;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser;
|
||||
import org.apache.commons.io.output.NullOutputStream;
|
||||
|
||||
public class JavaTXCompiler {
|
||||
@@ -406,7 +406,8 @@ public class JavaTXCompiler {
|
||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
||||
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
||||
logFile.flush();
|
||||
return new LanguageServerTransferObject(li.getResults(), sf, ASTTypePrinter.print(sf));
|
||||
generateBytecode(sf, li.getResults());
|
||||
return new LanguageServerTransferObject(li.getResults(), sf, ASTTypePrinter.print(sf), generatedGenerics);
|
||||
}
|
||||
/* UnifyResultModel End */
|
||||
else {
|
||||
@@ -433,7 +434,8 @@ public class JavaTXCompiler {
|
||||
}
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
}
|
||||
return new LanguageServerTransferObject(results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()), sf, ASTTypePrinter.print(sf));
|
||||
generateBytecode(sf, results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()));
|
||||
return new LanguageServerTransferObject(results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()), sf, ASTTypePrinter.print(sf), generatedGenerics);
|
||||
}
|
||||
|
||||
public List<ResultSet> typeInference(File file) throws ClassNotFoundException, IOException {
|
||||
|
@@ -8,16 +8,13 @@ import java.util.*;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import de.dhbw.compiler.core.JavaTXCompiler;
|
||||
import de.dhbw.compiler.syntaxtree.ClassOrInterface;
|
||||
import de.dhbw.compiler.syntaxtree.factory.ASTFactory;
|
||||
|
||||
import de.dhbw.compiler.exceptions.DebugException;
|
||||
import de.dhbw.compiler.exceptions.NotImplementedException;
|
||||
import de.dhbw.compiler.parser.JavaTXParser;
|
||||
|
||||
import de.dhbw.compiler.parser.scope.GatherNames;
|
||||
import de.dhbw.compiler.parser.scope.JavaClassRegistry;
|
||||
import de.dhbw.parser.Java17Parser;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser;
|
||||
|
||||
/**
|
||||
* Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt Sie erstellt anhand dieser Informationen die JavaClassNameRegistry
|
||||
|
@@ -1,34 +1,44 @@
|
||||
package de.dhbw.compiler.languageServerInterface;
|
||||
|
||||
import de.dhbw.compiler.syntaxtree.SourceFile;
|
||||
import de.dhbw.compiler.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbw.compiler.typeinference.result.ResultSet;
|
||||
import de.dhbw.compiler.languageServerInterface.model.LanguageServerTransferObject;
|
||||
import de.dhbw.compiler.core.JavaTXCompiler;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of an Interface for the Language-Server to get the Resultset and abstract Syntax.
|
||||
* */
|
||||
*/
|
||||
public class LanguageServerInterface {
|
||||
|
||||
private static final Logger log = Logger.getLogger(LanguageServerInterface.class);
|
||||
|
||||
/**
|
||||
* get final Result Set
|
||||
* */
|
||||
*/
|
||||
public LanguageServerTransferObject getResultSetAndAbstractSyntax(String input) throws IOException, ClassNotFoundException {
|
||||
|
||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||
File tempSourcefile = File.createTempFile("temp", ".java");
|
||||
tempSourcefile.deleteOnExit();
|
||||
int RETRYCOUNT = 50;
|
||||
for (int i = 0; i < RETRYCOUNT; i++) {
|
||||
try {
|
||||
File tempSourcefile = File.createTempFile("temp", ".java");
|
||||
tempSourcefile.deleteOnExit();
|
||||
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(tempSourcefile));
|
||||
out.write(input);
|
||||
out.close();
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(tempSourcefile));
|
||||
out.write(input);
|
||||
out.close();
|
||||
|
||||
JavaTXCompiler tx = new JavaTXCompiler(tempSourcefile);
|
||||
var test = tx.getResultSetAndAbstractSyntax(tempSourcefile);
|
||||
System.setOut(System.out);
|
||||
return test;
|
||||
JavaTXCompiler tx = new JavaTXCompiler(tempSourcefile);
|
||||
var test = tx.getResultSetAndAbstractSyntax(tempSourcefile);
|
||||
log.debug("JAVA-TX LANGUAGE SERVER INTERFACE RESULTED IN THE FOLLOWING: \n" + test.getResultSets().toString());
|
||||
System.setOut(System.out);
|
||||
return test;
|
||||
} catch (Exception e) {
|
||||
log.error("ERROR FETCHING COMPILER RESULTS: \n" + e.getMessage());
|
||||
log.warn("NEW RETRY. RETRYCOUNT IS: " + i);
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("ERROR FETCHING COMPILER RESULTS");
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,38 @@
|
||||
package de.dhbw.compiler.languageServerInterface;
|
||||
|
||||
import de.dhbw.compiler.languageServerInterface.model.CustomParserErrorHandler;
|
||||
import de.dhbw.compiler.languageServerInterface.model.ParserError;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Lexer;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser;
|
||||
import de.dhbw.compiler.parser.antlr.Java17ParserBaseListener;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParserInterface {
|
||||
|
||||
public List<ParserError> getParseErrors(String input){
|
||||
|
||||
CustomParserErrorHandler errorListener = new CustomParserErrorHandler();
|
||||
CharStream charStream = CharStreams.fromString(input);
|
||||
|
||||
Java17Lexer lexer = new Java17Lexer(charStream);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
|
||||
Java17Parser parser = new Java17Parser(tokens);
|
||||
parser.removeErrorListeners();
|
||||
parser.addErrorListener(errorListener);
|
||||
|
||||
|
||||
ParseTree tree = parser.sourceFile();
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
Java17ParserBaseListener listener = new Java17ParserBaseListener();
|
||||
walker.walk(listener, tree);
|
||||
|
||||
return errorListener.getErrorMessages();
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
package de.dhbw.compiler.languageServerInterface.model;
|
||||
|
||||
import de.dhbw.compiler.languageServerInterface.model.ParserError;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.atn.ATNConfigSet;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.eclipse.lsp4j.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomParserErrorHandler implements ANTLRErrorListener {
|
||||
private final List<ParserError> errorMessages = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
|
||||
int endCharPosition = charPositionInLine;
|
||||
if (offendingSymbol instanceof Token) {
|
||||
Token offendingToken = (Token) offendingSymbol;
|
||||
endCharPosition = charPositionInLine + offendingToken.getText().length();
|
||||
}
|
||||
|
||||
ParserError parserError = new ParserError(line, charPositionInLine, endCharPosition, msg);
|
||||
errorMessages.add(parserError);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportAmbiguity(Parser parser, DFA dfa, int i, int i1, boolean b, BitSet bitSet, ATNConfigSet atnConfigSet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportAttemptingFullContext(Parser parser, DFA dfa, int i, int i1, BitSet bitSet, ATNConfigSet atnConfigSet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportContextSensitivity(Parser parser, DFA dfa, int i, int i1, int i2, ATNConfigSet atnConfigSet) {
|
||||
|
||||
}
|
||||
|
||||
public List<ParserError> getErrorMessages() {
|
||||
return errorMessages;
|
||||
}
|
||||
}
|
@@ -1,21 +1,29 @@
|
||||
package de.dhbw.compiler.languageServerInterface;
|
||||
package de.dhbw.compiler.languageServerInterface.model;
|
||||
|
||||
import de.dhbw.compiler.syntaxtree.SourceFile;
|
||||
import de.dhbw.compiler.target.generate.GenericsResult;
|
||||
import de.dhbw.compiler.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LanguageServerTransferObject {
|
||||
List<ResultSet> resultSets;
|
||||
SourceFile Ast;
|
||||
String printedAst;
|
||||
public LanguageServerTransferObject(List<ResultSet> resultSets, SourceFile Ast, String printedAst) {
|
||||
Map<SourceFile, List<GenericsResult>> generatedGenerics = new HashMap<>();
|
||||
|
||||
|
||||
public LanguageServerTransferObject(List<ResultSet> resultSets, SourceFile Ast, String printedAst, Map<SourceFile, List<GenericsResult>> generatedGenerics) {
|
||||
this.resultSets = resultSets;
|
||||
this.Ast = Ast;
|
||||
this.printedAst = printedAst;
|
||||
this.generatedGenerics = generatedGenerics;
|
||||
}
|
||||
|
||||
public List<ResultSet> getResultSets() {return resultSets;}
|
||||
public SourceFile getAst() {return Ast;}
|
||||
public String getPrintedAst() {return printedAst;}
|
||||
public Map<SourceFile, List<GenericsResult>> getGeneratedGenerics() {return generatedGenerics;}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package de.dhbw.compiler.languageServerInterface.model;
|
||||
|
||||
public class ParserError {
|
||||
|
||||
private int line;
|
||||
private int charPositionInLine;
|
||||
private int endCharPosition;
|
||||
String msg;
|
||||
|
||||
public ParserError(int line, int charPositionInLine, int endCharPosition, String msg) {
|
||||
this.line = line;
|
||||
this.charPositionInLine = charPositionInLine;
|
||||
this. endCharPosition = endCharPosition;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getEndCharPosition() {
|
||||
return endCharPosition;
|
||||
}
|
||||
|
||||
public void setEndCharPosition(int endCharPosition) {
|
||||
this.endCharPosition = endCharPosition;
|
||||
}
|
||||
|
||||
public void setCharPositionInLine(int charPositionInLine) {
|
||||
this.charPositionInLine = charPositionInLine;
|
||||
}
|
||||
|
||||
public void setLine(int line) {
|
||||
this.line = line;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCharPositionInLine() {
|
||||
return charPositionInLine;
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package de.dhbw.compiler.languageServerInterface.model;
|
||||
|
||||
import de.dhbw.compiler.typeinference.unify.UnifyResultEvent;
|
||||
import de.dhbw.compiler.typeinference.unify.UnifyResultListener;
|
||||
import de.dhbw.helper.TypeResolver;
|
||||
|
||||
public class ResultSetListener implements UnifyResultListener {
|
||||
|
||||
TypeResolver typeResolver;
|
||||
|
||||
public ResultSetListener(TypeResolver typeResolver){
|
||||
this.typeResolver = typeResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewTypeResultFound(UnifyResultEvent evt) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,21 +1,12 @@
|
||||
package de.dhbw.compiler.parser;
|
||||
|
||||
import de.dhbw.compiler.environment.CompilationEnvironment;
|
||||
import de.dhbw.compiler.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbw.compiler.parser.scope.JavaClassRegistry;
|
||||
import de.dhbw.compiler.syntaxtree.SourceFile;
|
||||
|
||||
import de.dhbw.parser.Java17Lexer;
|
||||
import de.dhbw.parser.Java17Parser;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Lexer;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JavaTXParser {
|
||||
public static Java17Parser.SourceFileContext parse(File source) throws IOException, ClassNotFoundException {
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package de.dhbw.compiler.parser.SyntaxTreeGenerator;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -14,11 +13,9 @@ import de.dhbw.compiler.core.JavaTXCompiler;
|
||||
import de.dhbw.compiler.syntaxtree.*;
|
||||
import de.dhbw.compiler.syntaxtree.statement.*;
|
||||
import de.dhbw.compiler.syntaxtree.type.Void;
|
||||
import de.dhbw.compiler.target.tree.expression.TargetUnaryOp;
|
||||
import de.dhbw.compiler.target.generate.StatementToTargetExpression;
|
||||
import de.dhbw.parser.Java17Parser;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import de.dhbw.parser.Java17Parser.*;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser.*;
|
||||
import de.dhbw.compiler.exceptions.NotImplementedException;
|
||||
import de.dhbw.compiler.parser.NullToken;
|
||||
|
||||
|
@@ -17,13 +17,11 @@ import de.dhbw.compiler.parser.NullToken;
|
||||
import de.dhbw.compiler.syntaxtree.*;
|
||||
import de.dhbw.compiler.syntaxtree.Record;
|
||||
import de.dhbw.compiler.syntaxtree.statement.*;
|
||||
import de.dhbw.parser.Java17Parser;
|
||||
import de.dhbw.parser.Java17Parser.*;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser.*;
|
||||
import org.antlr.v4.runtime.CommonToken;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import com.google.common.graph.ElementOrder.Type;
|
||||
|
||||
import de.dhbw.compiler.environment.PackageCrawler;
|
||||
import de.dhbw.compiler.exceptions.NotImplementedException;
|
||||
import de.dhbw.compiler.exceptions.TypeinferenceException;
|
||||
|
@@ -16,8 +16,8 @@ import de.dhbw.compiler.syntaxtree.type.RefType;
|
||||
import de.dhbw.compiler.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbw.compiler.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbw.compiler.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbw.parser.Java17Parser;
|
||||
import de.dhbw.parser.Java17Parser.*;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser.*;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@@ -1,12 +1,9 @@
|
||||
package de.dhbw.parser;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Lexer.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.compiler.parser.antlr;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Lexer.g4 by ANTLR 4.13.1
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.TokenStream;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.atn.*;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.misc.*;
|
||||
|
||||
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "this-escape"})
|
||||
public class Java17Lexer extends Lexer {
|
@@ -1,12 +1,12 @@
|
||||
package de.dhbw.parser;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.compiler.parser.antlr;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
|
||||
import org.antlr.v4.runtime.atn.*;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.misc.*;
|
||||
import org.antlr.v4.runtime.tree.*;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
|
||||
public class Java17Parser extends Parser {
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbw.parser;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.compiler.parser.antlr;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
import org.antlr.v4.runtime.tree.ErrorNode;
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbw.parser;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.compiler.parser.antlr;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
|
||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||
|
||||
/**
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbw.parser;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.compiler.parser.antlr;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
|
||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||
|
||||
/**
|
@@ -1,4 +1,4 @@
|
||||
package de.dhbw.parser;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.compiler.parser.antlr;// Generated from C:/Users/ruben/IdeaProjects/JavaCompilerCore/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 by ANTLR 4.13.1
|
||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||
|
||||
/**
|
@@ -5,11 +5,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import de.dhbw.compiler.core.JavaTXCompiler;
|
||||
import de.dhbw.compiler.environment.PackageCrawler;
|
||||
import de.dhbw.compiler.exceptions.NotImplementedException;
|
||||
import de.dhbw.parser.Java17Parser;
|
||||
import de.dhbw.compiler.parser.antlr.Java17Parser;
|
||||
|
||||
|
||||
public class GatherNames {
|
||||
|
@@ -13,7 +13,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TypeInsertPlacer extends AbstractASTWalker {
|
||||
public class TypeInsertPlacer extends AbstractASTWalker {
|
||||
Set<TypeInsert> inserts = new HashSet<>();
|
||||
private ResultSet withResults;
|
||||
String pkgName;
|
||||
|
@@ -1,32 +1,82 @@
|
||||
package de.dhbw.helper;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class TextHelper {
|
||||
|
||||
private static final Logger log = Logger.getLogger(TextHelper.class);
|
||||
|
||||
public Integer getEndingCharOfStartingChar(Integer line, Integer startChar, String input){
|
||||
|
||||
List<String> endingChars = List.of("(", ")", " ", "{", "}", ";", ",");
|
||||
public Integer getClassPositionForGeneric(Integer line, String input, Integer startChar){
|
||||
log.info("Calculating Position of Class-Generic Variable at Line [" + line + "] and Char [" + startChar + "].");
|
||||
|
||||
String[] lines = input.split("\n");
|
||||
|
||||
if(lines.length < line){
|
||||
log.warn("Returning hardcoded Value because the requested Line [" + line + "] does not exist in Text Document.");
|
||||
return startChar+3;
|
||||
}
|
||||
|
||||
String[] linesInChar = lines[line].split("");
|
||||
|
||||
|
||||
var index = startChar;
|
||||
var found = false;
|
||||
|
||||
|
||||
for (int i = startChar; i < linesInChar.length; i++) {
|
||||
|
||||
|
||||
if(linesInChar[i].contains("{")){
|
||||
index = i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found){
|
||||
index = linesInChar.length-1;
|
||||
}
|
||||
|
||||
|
||||
for(int j = index; j <= linesInChar.length; j--){
|
||||
if(!linesInChar[j].isEmpty() && !linesInChar[j].equals(" ")){
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
public Integer getEndingCharOfStartingChar(Integer line, Integer startChar, String input){
|
||||
log.info("Calculating ending-Position for Variable at Line [" + line + "] and Char [" + startChar + "].");
|
||||
List<String> endingChars = List.of("(", ")", " ", "{", "}", ";", ",");
|
||||
|
||||
String[] lines = input.split("\n");
|
||||
|
||||
if(lines.length < line){
|
||||
log.warn("Returning hardcoded Value because the requested Line [" + line + "] does not exist in Text Document.");
|
||||
return startChar+3;
|
||||
}
|
||||
|
||||
String[] linesInChar = lines[line].split("");
|
||||
|
||||
|
||||
|
||||
var index = startChar;
|
||||
for (int i = startChar; i < linesInChar.length; i++) {
|
||||
index++;
|
||||
|
||||
if(endingChars.contains(linesInChar[i])){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return startChar+3;
|
||||
return index-1;
|
||||
}
|
||||
|
||||
public String getTextOfChars(String textDocument, Integer line, Integer charStart, Integer charEnd){
|
||||
|
@@ -1,17 +1,21 @@
|
||||
package de.dhbw.helper;
|
||||
|
||||
import de.dhbw.JavaTXLanguageServer;
|
||||
import de.dhbw.compiler.languageServerInterface.LanguageServerInterface;
|
||||
import de.dhbw.compiler.languageServerInterface.LanguageServerTransferObject;
|
||||
import de.dhbw.compiler.languageServerInterface.model.LanguageServerTransferObject;
|
||||
import de.dhbw.compiler.syntaxtree.ClassOrInterface;
|
||||
import de.dhbw.compiler.syntaxtree.Method;
|
||||
import de.dhbw.model.LSPMethod;
|
||||
import de.dhbw.model.LSPVariable;
|
||||
import de.dhbw.model.LSPParameter;
|
||||
import de.dhbw.compiler.syntaxtree.SourceFile;
|
||||
import de.dhbw.compiler.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbw.compiler.target.generate.GenericsResult;
|
||||
import de.dhbw.compiler.typeinference.result.ResultSet;
|
||||
import de.dhbw.model.*;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
@@ -19,176 +23,218 @@ import java.util.*;
|
||||
*/
|
||||
public class TypeResolver {
|
||||
|
||||
HashMap<Integer, LanguageServerTransferObject> dataCache = new HashMap<>();
|
||||
LanguageServerInterface languageServer;
|
||||
private static final Logger logger = LogManager.getLogger(TypeResolver.class);
|
||||
|
||||
|
||||
private List<ResultSet> currentResults = new ArrayList<>();
|
||||
|
||||
public List<ResultSet> getCurrentResults() {
|
||||
return currentResults;
|
||||
}
|
||||
|
||||
public void setCurrentResults(List<ResultSet> currentResults) {
|
||||
this.currentResults = currentResults;
|
||||
}
|
||||
|
||||
public void addToCurrentResults(List<ResultSet> additionalResults) {
|
||||
this.currentResults.addAll(additionalResults);
|
||||
}
|
||||
|
||||
public TypeResolver() {
|
||||
languageServer = new LanguageServerInterface();
|
||||
}
|
||||
|
||||
/**
|
||||
* find the concrete Type of all TPHs and return the outcome as Hashmap.
|
||||
*/
|
||||
public HashMap<String, ArrayList<String>> findAvailableTypes(LanguageServerTransferObject resultSet) throws IOException, ClassNotFoundException {
|
||||
|
||||
HashMap<String, ArrayList<String>> typePlaceholderTypes = new HashMap<>();
|
||||
|
||||
resultSet.getResultSets().forEach(conSet -> {
|
||||
for (var constraint : conSet.results) {
|
||||
|
||||
var typeNameString = constraint.getLeft().toString();
|
||||
|
||||
ArrayList<String> finalTypes = new ArrayList<>();
|
||||
Queue<String> queue = new LinkedList<>();
|
||||
|
||||
if (typeNameString.contains("TPH ")) {
|
||||
queue.add(typeNameString);
|
||||
} else {
|
||||
finalTypes.add(typeNameString);
|
||||
}
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
var nextType = queue.remove();
|
||||
resultSet.getResultSets().forEach(el -> el.results.forEach(el2 -> {
|
||||
|
||||
if (el2.getLeft().toString().equals(nextType)) {
|
||||
if (el2.getRight().toString().toLowerCase().contains("TPH")) {
|
||||
queue.add(el2.getRight().toString());
|
||||
} else {
|
||||
if (!finalTypes.contains(el2.getRight().toString())) {
|
||||
finalTypes.add(el2.getRight().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
typePlaceholderTypes.put(typeNameString, finalTypes);
|
||||
}
|
||||
}
|
||||
);
|
||||
return typePlaceholderTypes;
|
||||
}
|
||||
|
||||
public ArrayList<String> findTypeOfMethod(LanguageServerTransferObject transferObj, Method method) throws IOException, ClassNotFoundException {
|
||||
|
||||
var typeHashMap = findAvailableTypes(transferObj);
|
||||
|
||||
if (method.getReturnType().toString().contains("TPH ")) {
|
||||
return typeHashMap.get(method.getReturnType().toString());
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean isTypeImported(String input, String type){
|
||||
try {
|
||||
private LanguageServerTransferObject getCacheOrCalculate(String input) throws IOException, ClassNotFoundException {
|
||||
logger.info("Trying to find cached Compiler-Answer for input with key [" + input.hashCode() + "].");
|
||||
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(input);
|
||||
dataCache.put(input.hashCode(), transferObject);
|
||||
return transferObject;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTypeImported(String input, String type) {
|
||||
try {
|
||||
var transferObject = getCacheOrCalculate(input);
|
||||
var abstractSyntax = transferObject.getAst();
|
||||
|
||||
var isAlreadyImported = false;
|
||||
for(var importStatement : abstractSyntax.getImports()){
|
||||
logger.debug(importStatement.toString() + "<>" + type);
|
||||
for (var importStatement : abstractSyntax.getImports()) {
|
||||
isAlreadyImported = !isAlreadyImported && importStatement.toString().equals(type);
|
||||
}
|
||||
|
||||
return isAlreadyImported;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error creating Transferobject: " + Arrays.toString(e.getStackTrace()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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<>();
|
||||
|
||||
public ArrayList<ArrayList<String>> findTypesOfAllParameters(LanguageServerTransferObject transferObj, Method method) throws IOException, ClassNotFoundException {
|
||||
|
||||
var typeHashMap = findAvailableTypes(transferObj);
|
||||
ArrayList<ArrayList<String>> paramTypes = new ArrayList<>();
|
||||
|
||||
for (var param : method.getParameterList()) {
|
||||
|
||||
if (param.getType().toString().contains("TPH ")) {
|
||||
try {
|
||||
paramTypes.add(typeHashMap.get(param.getType().toString()));
|
||||
|
||||
} catch (Exception e) {
|
||||
paramTypes.add(new ArrayList<>(List.of("java.lang.Object")));
|
||||
}
|
||||
} else {
|
||||
paramTypes.add(new ArrayList<>());
|
||||
resultSets.forEach(conSet -> {
|
||||
if (method.getReturnType().toString().toLowerCase().contains("tph ")) {
|
||||
normalType.add(conSet.resolveType(method.getReturnType()).resolvedType.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return paramTypes;
|
||||
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> infereMethodsWithParameters(String input) throws IOException, ClassNotFoundException {
|
||||
public ArrayList<LSPVariable> infereInput(String input) throws IOException, ClassNotFoundException {
|
||||
logger.info("Infering Types for Input.");
|
||||
|
||||
var transferObj = languageServer.getResultSetAndAbstractSyntax(input);
|
||||
ArrayList<LSPVariable> methodsWithParametersLSPVariableList = new ArrayList<>();
|
||||
|
||||
ArrayList<LSPVariable> methodLSPVariableList = new ArrayList<>();
|
||||
|
||||
//TODO: Hier noch irgendwie die Klasse rausfinden oder durchgehen.
|
||||
//GENERICS OF CLASS
|
||||
for (var method : transferObj.getAst().getAllMethods()) {
|
||||
|
||||
var type = findTypeOfMethod(transferObj, method);
|
||||
if (!type.isEmpty()) {
|
||||
methodLSPVariableList.add(new LSPMethod(method.name, type, method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
||||
|
||||
for (var clazz : transferObj.getAst().getClasses()) {
|
||||
ArrayList<Type> genericTypes = getClassGenerics(transferObj.getGeneratedGenerics(), method, clazz);
|
||||
TextHelper helper = new TextHelper();
|
||||
methodsWithParametersLSPVariableList.add(new LSPClass("test", genericTypes, clazz.getOffset().getLine(), helper.getClassPositionForGeneric(clazz.getOffset().getLine() - 1, input, clazz.getOffset().getStopIndex()), clazz.getOffset().getStopIndex()));
|
||||
}
|
||||
|
||||
var paramType = findTypesOfAllParameters(transferObj, method);
|
||||
}
|
||||
|
||||
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 (!types.isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(types), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
||||
}
|
||||
if (!generics.isEmpty()) {
|
||||
ArrayList<Type> typesThatAreGeneric = filterOutDuplicates(generics, types);
|
||||
typesThatAreGeneric.forEach(el -> el.setType("<" + el.getType() + "> " + el.getType()));
|
||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), method.getOffset().getCharPositionInLine(), method.getOffset().getStopIndex()));
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (var param : method.getParameterList()) {
|
||||
if (!paramType.get(index).isEmpty()) {
|
||||
methodLSPVariableList.add(new LSPParameter(method.name, paramType.get(index), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
||||
index++;
|
||||
ArrayList<Type> typeParam = getAvailableTypes(transferObj.getResultSets(), param.getType());
|
||||
ArrayList<Type> genericParam = getAvailableGenericTypes(transferObj.getGeneratedGenerics().values().stream().flatMap(List::stream).collect(Collectors.toList()), param.getType());
|
||||
|
||||
if (!typeParam.isEmpty()) {
|
||||
methodsWithParametersLSPVariableList.add(new LSPParameter(method.name, filterOutDuplicates(typeParam), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
||||
}
|
||||
|
||||
if (!genericParam.isEmpty()) {
|
||||
ArrayList<Type> typesThatAreGeneric = filterOutDuplicates(genericParam, typeParam);
|
||||
methodsWithParametersLSPVariableList.add(new LSPMethod(method.name, filterOutDuplicates(typesThatAreGeneric), method.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return methodLSPVariableList;
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public ArrayList<LSPMethod> infereMethodType(String input) throws IOException, ClassNotFoundException {
|
||||
var transferObj = languageServer.getResultSetAndAbstractSyntax(input);
|
||||
//Für RefTypes und so dann entsprechend InstanceOf durch den Syntaxbaum denke ich
|
||||
ArrayList<LSPMethod> methodNameWithTypeList = new ArrayList<>();
|
||||
|
||||
for (var method : transferObj.getAst().getAllMethods()) {
|
||||
|
||||
var type = findTypeOfMethod(transferObj, method);
|
||||
methodNameWithTypeList.add(new LSPMethod(method.name, type, method.getOffset().getLine(), method.getOffset().getStartIndex(), method.getOffset().getStopIndex()));
|
||||
}
|
||||
|
||||
return methodNameWithTypeList;
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public ArrayList<LSPParameter> infereParameterType(String input, String methodName) throws IOException, ClassNotFoundException {
|
||||
var transferObj = languageServer.getResultSetAndAbstractSyntax(input);
|
||||
System.out.println(transferObj.getResultSets().toString());
|
||||
System.out.println(transferObj.getPrintedAst());
|
||||
ArrayList<LSPParameter> LSPParameter = new ArrayList<>();
|
||||
|
||||
for (var method : transferObj.getAst().getAllMethods()) {
|
||||
if (method.name.equals(methodName)) {
|
||||
int index = 0;
|
||||
for (var param : method.getParameterList()) {
|
||||
|
||||
var type = findTypesOfAllParameters(transferObj, method);
|
||||
|
||||
LSPParameter.add(new LSPParameter(method.name, type.get(index), param.getOffset().getLine(), param.getOffset().getCharPositionInLine(), param.getOffset().getStopIndex()));
|
||||
index++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return LSPParameter;
|
||||
return methodsWithParametersLSPVariableList;
|
||||
}
|
||||
|
||||
|
||||
|
9
LanguageServer/src/main/java/de/dhbw/model/LSPClass.java
Normal file
9
LanguageServer/src/main/java/de/dhbw/model/LSPClass.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package de.dhbw.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LSPClass extends LSPVariable{
|
||||
public LSPClass(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition) {
|
||||
super(name, possibleTypes, line, charPosition, endPosition);
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@ package de.dhbw.model;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LSPMethod extends LSPVariable {
|
||||
public LSPMethod(String name, ArrayList<String> type, int line, int charPosition, int endPosition) {
|
||||
public LSPMethod(String name, ArrayList<Type> type, int line, int charPosition, int endPosition) {
|
||||
super(name, type, line, charPosition, endPosition);
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
|
||||
public class LSPParameter extends LSPMethod {
|
||||
|
||||
public LSPParameter(String name, ArrayList<String> type, int line, int charPosition, int endPosition) {
|
||||
public LSPParameter(String name, ArrayList<Type> type, int line, int charPosition, int endPosition) {
|
||||
super(name, type, line, charPosition, endPosition);
|
||||
}
|
||||
}
|
||||
|
@@ -3,13 +3,13 @@ package de.dhbw.model;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LSPVariable { String name;
|
||||
ArrayList<String> possibleTypes;
|
||||
ArrayList<Type> possibleTypes;
|
||||
int line;
|
||||
int charPosition;
|
||||
int endPosition;
|
||||
boolean needsInference;
|
||||
|
||||
public LSPVariable(String name, ArrayList<String> possibleTypes, int line, int charPosition, int endPosition) {
|
||||
public LSPVariable(String name, ArrayList<Type> possibleTypes, int line, int charPosition, int endPosition) {
|
||||
this.name = name;
|
||||
this.possibleTypes = possibleTypes;
|
||||
this.line = line;
|
||||
@@ -33,11 +33,11 @@ public class LSPVariable { String name;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ArrayList<String> getPossibleTypes() {
|
||||
public ArrayList<Type> getPossibleTypes() {
|
||||
return possibleTypes;
|
||||
}
|
||||
|
||||
public void setPossibleTypes(ArrayList<String> possibleTypes) {
|
||||
public void setPossibleTypes(ArrayList<Type> possibleTypes) {
|
||||
this.possibleTypes = possibleTypes;
|
||||
}
|
||||
|
||||
|
27
LanguageServer/src/main/java/de/dhbw/model/Type.java
Normal file
27
LanguageServer/src/main/java/de/dhbw/model/Type.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package de.dhbw.model;
|
||||
|
||||
public class Type {
|
||||
String type;
|
||||
boolean generic;
|
||||
|
||||
public Type(String type, boolean generic){
|
||||
this.type = type;
|
||||
this.generic = generic;
|
||||
}
|
||||
|
||||
public void setGeneric(boolean generic) {
|
||||
this.generic = generic;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean isGeneric() {
|
||||
return generic;
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@ log4j.rootLogger=DEBUG, FILE
|
||||
|
||||
# File Appender
|
||||
log4j.appender.FILE=org.apache.log4j.FileAppender
|
||||
log4j.appender.FILE.File=/home/ruben/logs/application.log
|
||||
log4j.appender.FILE.File=C:/Users/ruben/Desktop/log.txt
|
||||
log4j.appender.FILE.Append=true
|
||||
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c{1}] %m%n
|
||||
|
@@ -5,21 +5,32 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CompilerInterfaceTest {
|
||||
|
||||
@Test
|
||||
public void testAbstractSyntaxAsString() throws IOException, ClassNotFoundException {
|
||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
var res = languageServer.getResultSetAndAbstractSyntax("import java.lang.Integer; public class test{\n" +
|
||||
" \n" +
|
||||
" public main( test){\n" +
|
||||
" Integer i = test; " +
|
||||
" return i;\n" +
|
||||
" }\n" +
|
||||
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;" +
|
||||
"}" +
|
||||
"}");
|
||||
|
||||
System.out.println("TEST OUTPUT:");
|
||||
|
||||
ArrayList<String> allTypes = new ArrayList<>();
|
||||
|
||||
res.getResultSets().forEach(el -> allTypes.add(el.resolveType(res.getAst().getAllMethods().get(0).getReturnType()).resolvedType.toString()));
|
||||
var results = res.getGeneratedGenerics().entrySet().iterator().next();
|
||||
|
||||
|
||||
System.out.println(res.getResultSets().toString());
|
||||
|
||||
|
||||
@@ -27,10 +38,25 @@ public class CompilerInterfaceTest {
|
||||
System.out.println(res.getPrintedAst());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstraintTypes() throws IOException, ClassNotFoundException {
|
||||
LanguageServerInterface languageServer = new LanguageServerInterface();
|
||||
TypeResolver typeResolver = new TypeResolver();
|
||||
|
||||
|
||||
var res = typeResolver.infereInput("import java.lang.Integer; public class test{\n" +
|
||||
" \n" +
|
||||
" public main(testa){\n" +
|
||||
" return testa;\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
res.forEach(el -> el.getPossibleTypes().forEach(el2 -> System.out.println(el2.getType() + " " + (el2.isGeneric() ? "GENERIC" : "NO GENERIC"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeFinder() throws IOException, ClassNotFoundException {
|
||||
TypeResolver typeResolver = new TypeResolver();
|
||||
var inferedMethods = typeResolver.infereMethodsWithParameters("import java.lang.Integer;\n import java.lang.String;\n" +
|
||||
var inferedMethods = typeResolver.infereInput("import java.lang.Integer;\n import java.lang.String;\n" +
|
||||
"public class test{\n" +
|
||||
"public main(test){" +
|
||||
"if(0>1){" +
|
||||
@@ -46,10 +72,25 @@ public class CompilerInterfaceTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericTypes() throws IOException, ClassNotFoundException {
|
||||
TypeResolver typeResolver = new TypeResolver();
|
||||
var inferedMethods = typeResolver.infereInput("import java.lang.Integer; public class test{\n" +
|
||||
" \n" +
|
||||
" public main(testa){\n" +
|
||||
" return testa;\n" +
|
||||
" }\n" +
|
||||
"}"
|
||||
);
|
||||
|
||||
inferedMethods.forEach(el -> System.out.println(el.getName() + ": " + el.getPossibleTypes() + " | " + el.getLine() + " " + el.getCharPosition()));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeFinderParameter() throws IOException, ClassNotFoundException {
|
||||
TypeResolver typeResolver = new TypeResolver();
|
||||
var inferedMethods = typeResolver.infereMethodsWithParameters("import java.lang.Integer;\n" +
|
||||
var inferedMethods = typeResolver.infereInput("import java.lang.Integer;\n" +
|
||||
"import java.lang.String; \n" +
|
||||
"public class test{\n" +
|
||||
" public main(test, test2){\n" +
|
||||
|
14
README.md
14
README.md
@@ -8,8 +8,8 @@ Currently the Language Server has the following functionalities:
|
||||
- Autocomplete for ForLoops and Main Method.
|
||||
- Basic Autoformatting (removing every Space at the End of the Line)
|
||||
- Display Type of Methods and Parameters with TypeInference
|
||||
- Select Type of typinfered Type and replace it.
|
||||
- Give Hint of all possible Types to Select from
|
||||
- Select Type of typinfered Type and replace it (including Generics)
|
||||
- Give Hint of all possible Types to Select from (including Generics)
|
||||
|
||||
|
||||
## Project Structure
|
||||
@@ -17,7 +17,7 @@ Currently the Language Server has the following functionalities:
|
||||
.
|
||||
├── Client/
|
||||
│ ├── VisualStudioCode -> Containing the Client for VS Code. In this Case a Extension.
|
||||
│ ├── Eclipse
|
||||
│ ├── Emacs
|
||||
│ ├── Intellij
|
||||
│ └── ...
|
||||
└── LanguageServer/
|
||||
@@ -44,7 +44,13 @@ To use this Language Server you have to follow this steps:
|
||||
4. run ```npm run compile```
|
||||
5. Go to Debug and Run the Extension.
|
||||
6. Press F1 and execute the Hello World Command.
|
||||
7. You can create .java Files which will be analysed by the Language Server.
|
||||
7. You can create .jav Files which will be analysed by the Language Server.
|
||||
|
||||
## Known Problems and what to do
|
||||
|
||||
1. If the TypeInference does not display any Typehints or Typeselection, restart the IDE including the Extension thus deleting the Cache.
|
||||
2. Selecting a Generic will Result in a Class-Generic extending Object, wich is not legal in Java. Delete the extends Statement.
|
||||
3. Selecting a Generic after another Generic is selected results in illegal Syntax. Delete the newly greated Generic and add the Generic Name and if needet its extension into the other Declaration.
|
||||
|
||||
## Logic
|
||||
The Language Server in itself can be used for any Client. The Clients task is to start the Langauge Server and handle the Communication with it.
|
||||
|
Reference in New Issue
Block a user