diff --git a/kscr-intellij/.gitignore b/kscr-intellij/.gitignore deleted file mode 100644 index e63bc20..0000000 --- a/kscr-intellij/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/.gradle/ -/.idea/ -/build/ -/src/main/java/org/comroid/kscr/intellij/antlr_generated/ diff --git a/kscr-intellij/build.gradle.kts b/kscr-intellij/build.gradle.kts deleted file mode 100644 index 2eba194..0000000 --- a/kscr-intellij/build.gradle.kts +++ /dev/null @@ -1,37 +0,0 @@ -plugins { - id("org.jetbrains.intellij") version "1.3.0" - id("antlr") // TODO: Use the plugin to build the parser automatically - requires splitting parser and lexer - java -} - -group = "org.comroid.kscr" -version = "0.0.1" - -repositories { - mavenCentral() -} - -dependencies { - implementation("org.antlr:antlr4-runtime:4.9.3") - implementation("org.antlr:antlr4-intellij-adaptor:0.1") - //implementation("org.antlr:antlr4-master:4.9.3") - - testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") -} - -// See https://github.com/JetBrains/gradle-intellij-plugin/ -intellij { - version.set("2021.3") - plugins.add("com.intellij.java") - plugins.add("yaml") -} -tasks { - patchPluginXml { - changeNotes.set(""" - First version. """.trimIndent()) - } -} -tasks.getByName("test") { - useJUnitPlatform() -} \ No newline at end of file diff --git a/kscr-intellij/gradle/wrapper/gradle-wrapper.jar b/kscr-intellij/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 7454180..0000000 Binary files a/kscr-intellij/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/kscr-intellij/gradle/wrapper/gradle-wrapper.properties b/kscr-intellij/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 69a9715..0000000 --- a/kscr-intellij/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/kscr-intellij/gradlew b/kscr-intellij/gradlew deleted file mode 100644 index 744e882..0000000 --- a/kscr-intellij/gradlew +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or 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 UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$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 "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# 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" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/kscr-intellij/gradlew.bat b/kscr-intellij/gradlew.bat deleted file mode 100644 index 107acd3..0000000 --- a/kscr-intellij/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@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 diff --git a/kscr-intellij/settings.gradle.kts b/kscr-intellij/settings.gradle.kts deleted file mode 100644 index 1c542d3..0000000 --- a/kscr-intellij/settings.gradle.kts +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = "KScrIntellijPlugin" \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrBinaryFileType.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrBinaryFileType.java deleted file mode 100644 index 8c81044..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrBinaryFileType.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.comroid.kscr.intellij; - -import com.intellij.openapi.fileTypes.LanguageFileType; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; - -public class KScrBinaryFileType extends LanguageFileType implements KScrFileType { - - public static final KScrBinaryFileType FILE_TYPE = new KScrBinaryFileType(); - - protected KScrBinaryFileType(){ - super(KScrLanguage.LANGUAGE); - } - - public @NonNls @NotNull String getName(){ - return "KScr File"; - } - - public @NotNull String getDescription(){ - return "KScr file"; - } - - public @NotNull String getDefaultExtension(){ - return "kscr"; - } - - public @Nullable Icon getIcon(){ - return KScrIcons.SINGLE; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrFileType.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrFileType.java deleted file mode 100644 index 31a38d5..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrFileType.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.comroid.kscr.intellij; - -import com.intellij.openapi.fileTypes.FileType; - -public interface KScrFileType extends FileType { -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrIcons.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrIcons.java deleted file mode 100644 index fd542ce..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrIcons.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.comroid.kscr.intellij; - -import com.intellij.openapi.util.IconLoader; - -import javax.swing.*; - -public class KScrIcons{ - - // TODO: get a proper icon/branding - - public static final Icon SINGLE = IconLoader.getIcon("pluginIcon.svg", KScrIcons.class); - public static final Icon KScr_ICON = SINGLE; -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrLanguage.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrLanguage.java deleted file mode 100644 index e1cab7f..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrLanguage.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij; - -import com.intellij.lang.Language; - -public class KScrLanguage extends Language{ - - public static final KScrLanguage LANGUAGE = new KScrLanguage(); - - protected KScrLanguage(){ - super("KScr"); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrSourceFileType.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrSourceFileType.java deleted file mode 100644 index 3c8a3c2..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrSourceFileType.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.comroid.kscr.intellij; - -import com.intellij.openapi.fileTypes.LanguageFileType; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; - -public class KScrSourceFileType extends LanguageFileType implements KScrFileType { - - public static final KScrSourceFileType FILE_TYPE = new KScrSourceFileType(); - - protected KScrSourceFileType(){ - super(KScrLanguage.LANGUAGE); - } - - public @NonNls @NotNull String getName(){ - return "KScr File"; - } - - public @NotNull String getDescription(){ - return "KScr file"; - } - - public @NotNull String getDefaultExtension(){ - return "kscr"; - } - - public @Nullable Icon getIcon(){ - return KScrIcons.SINGLE; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrTemplates.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrTemplates.java deleted file mode 100644 index 0be69b8..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/KScrTemplates.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.comroid.kscr.intellij; - -import com.intellij.ide.fileTemplates.DefaultCreateFromTemplateHandler; -import com.intellij.ide.fileTemplates.FileTemplate; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiElement; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; - -public class KScrTemplates extends DefaultCreateFromTemplateHandler{ - - @Override - public boolean handlesTemplate(@NotNull FileTemplate template){ - return template.isTemplateOfType(KScrSourceFileType.FILE_TYPE); - } - - public @NotNull PsiElement createFromTemplate(@NotNull Project project, @NotNull PsiDirectory directory, String fileName, @NotNull FileTemplate template, @NotNull String templateText, @NotNull Map props) throws IncorrectOperationException{ - fileName += ".kscr"; - return super.createFromTemplate(project, directory, fileName, template, templateText, props); - } - - public boolean canCreate(PsiDirectory @NotNull [] dirs){ - // don't show internal templates in the right click menu outside the KScr Class menu - return false; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/actions/CreateKScrClassAction.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/actions/CreateKScrClassAction.java deleted file mode 100644 index e1ea938..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/actions/CreateKScrClassAction.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.comroid.kscr.intellij.actions; - -import com.intellij.ide.actions.CreateFileFromTemplateDialog; -import com.intellij.ide.actions.CreateTemplateInPackageAction; -import com.intellij.ide.fileTemplates.FileTemplate; -import com.intellij.ide.fileTemplates.FileTemplateManager; -import com.intellij.ide.fileTemplates.FileTemplateUtil; -import com.intellij.java.JavaBundle; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.NlsContexts; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.*; -import com.intellij.ui.LayeredIcon; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.PlatformIcons; -import org.comroid.kscr.intellij.KScrIcons; -import org.comroid.kscr.intellij.psi.KScrFile; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; - -import java.util.Properties; - -public class CreateKScrClassAction extends CreateTemplateInPackageAction { - - protected CreateKScrClassAction(){ - super("", "Create new KScr class", new LayeredIcon(PlatformIcons.CLASS_ICON, KScrIcons.KScr_ICON), JavaModuleSourceRootTypes.SOURCES); - } - - protected @Nullable PsiElement getNavigationElement(@NotNull KScrType createdElement){ - return createdElement; - } - - protected @Nullable KScrType doCreate(PsiDirectory dir, String className, String templateName) throws IncorrectOperationException{ - Project project = dir.getProject(); - FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate(templateName); - - Properties defaultProperties = FileTemplateManager.getInstance(project).getDefaultProperties(); - Properties properties = new Properties(defaultProperties); - properties.setProperty(FileTemplate.ATTRIBUTE_NAME, className); - /*for(Map.Entry entry : additionalProperties.entrySet()) - properties.setProperty(entry.getKey(), entry.getValue());*/ - - String fileName = className + ".kScr"; - - PsiElement element; - try{ - element = FileTemplateUtil.createFromTemplate(template, fileName, properties, dir); - }catch(Exception e){ - throw new IncorrectOperationException(e); - } - KScrFile file = (KScrFile)element.getContainingFile(); - return file.getTypeDef().orElseThrow(IncorrectOperationException::new); - } - - protected boolean checkPackageExists(PsiDirectory directory){ - PsiPackage pkg = JavaDirectoryService.getInstance().getPackage(directory); - if(pkg == null) - return false; - - String name = pkg.getQualifiedName(); - return StringUtil.isEmpty(name) || PsiNameHelper.getInstance(directory.getProject()).isQualifiedName(name); - } - - protected void buildDialog(@NotNull Project project, @NotNull PsiDirectory directory, CreateFileFromTemplateDialog.@NotNull Builder builder){ - builder - .setTitle("New KScr Class") - .addKind("Class", PlatformIcons.CLASS_ICON, "KScr Class") - .addKind("Interface", PlatformIcons.INTERFACE_ICON, "KScr Interface") - .addKind("Record", PlatformIcons.RECORD_ICON, "KScr Record") - .addKind("Enum", PlatformIcons.ENUM_ICON, "KScr Enum") - .addKind("Annotation", PlatformIcons.ANNOTATION_TYPE_ICON, "KScr Annotation"); - } - - @SuppressWarnings("UnstableApiUsage") - protected @NlsContexts.Command String getActionName(PsiDirectory directory, @NonNls @NotNull String newName, @NonNls String templateName){ - PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(directory); - return JavaBundle.message("progress.creating.class", StringUtil.getQualifiedName(psiPackage == null ? "" : psiPackage.getQualifiedName(), newName)); - } - - public boolean startInWriteAction(){ - return false; - } - - protected String removeExtension(String templateName, String className){ - return StringUtil.trimEnd(className, ".kscr"); - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/compiler/KScrCompileTask.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/compiler/KScrCompileTask.java deleted file mode 100644 index 7271505..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/compiler/KScrCompileTask.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.comroid.kscr.intellij.compiler; - -import com.intellij.openapi.compiler.CompileContext; -import com.intellij.openapi.compiler.CompileTask; - -public class KScrCompileTask implements CompileTask { - @Override - public boolean execute(CompileContext context) { - return false;//Todo - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/completion/KScrKeywordContributor.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/completion/KScrKeywordContributor.java deleted file mode 100644 index 7616bd8..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/completion/KScrKeywordContributor.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.comroid.kscr.intellij.completion; - -import com.intellij.codeInsight.completion.CompletionContributor; -import com.intellij.codeInsight.completion.CompletionType; -import com.intellij.patterns.PlatformPatterns; - -public class KScrKeywordContributor extends CompletionContributor { - public KScrKeywordContributor() { - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/facet/KScrFrameworkSupport.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/facet/KScrFrameworkSupport.java deleted file mode 100644 index b2539c7..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/facet/KScrFrameworkSupport.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.comroid.kscr.intellij.facet; - -import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable; -import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel; -import com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider; -import com.intellij.openapi.module.ModuleType; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -public class KScrFrameworkSupport extends FrameworkSupportProvider { - protected KScrFrameworkSupport() { - super("kscr-framework", "KScr Framework Support"); - } - - @Override - public @NotNull FrameworkSupportConfigurable createConfigurable(@NotNull FrameworkSupportModel model) { - return null;//Todo - } - - @Override - public boolean isEnabledForModuleType(@NotNull ModuleType moduleType) { - return false; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/InvalidSupertypeInspection.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/InvalidSupertypeInspection.java deleted file mode 100644 index 53a8159..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/InvalidSupertypeInspection.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.comroid.kscr.intellij.inspections; - -import com.intellij.codeInspection.InspectionManager; -import com.intellij.codeInspection.LocalQuickFix; -import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.codeInspection.ProblemHighlightType; -import com.intellij.lang.jvm.JvmClassKind; -import com.intellij.lang.jvm.JvmModifier; -import com.intellij.lang.jvm.types.JvmReferenceType; -import org.comroid.kscr.intellij.inspections.fixes.ChangeSupertypeKindFix; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.types.KScrKind; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; - -public class InvalidSupertypeInspection extends KScrInspection{ - - public ProblemDescriptor @NotNull [] checkTypeDef(@NotNull KScrType type, @NotNull InspectionManager manager, boolean isOnTheFly){ - var problems = new ArrayList(); - var extendsElems = PsiUtils - .childOfType(type, KScrExtendsClause.class) - .map(x -> PsiUtils.childrenOfType(x, KScrTypeRef.class)) - .orElse(List.of()); - for(KScrTypeRef elem : extendsElems){ - if(elem.getTextLength() == 0) - continue; - var extType = elem.asType(); - if(extType != null) - if(!(extType instanceof JvmReferenceType)) - problems.add(manager.createProblemDescriptor(elem, "Expecting a class, not primitive or array", isOnTheFly, new LocalQuickFix[0], ProblemHighlightType.GENERIC_ERROR)); - else{ - var extClass = elem.asClass(); - // TODO: check @AnnotationCanImplement - if(type.kind() == KScrKind.INTERFACE && !(extClass.getClassKind() == JvmClassKind.INTERFACE || extClass.getClassKind() == JvmClassKind.ANNOTATION)) - problems.add(manager.createProblemDescriptor(elem, "Expected an interface, not a class", isOnTheFly, new LocalQuickFix[0], ProblemHighlightType.GENERIC_ERROR)); - else if(type.kind() != KScrKind.INTERFACE && (extClass.getClassKind() == JvmClassKind.INTERFACE || extClass.getClassKind() == JvmClassKind.ANNOTATION)) - problems.add(manager.createProblemDescriptor(elem, "Expected a class, not an interface", isOnTheFly, new LocalQuickFix[]{ new ChangeSupertypeKindFix(elem, false) }, ProblemHighlightType.GENERIC_ERROR)); - // TODO: check sealed types - if(extClass.hasModifier(JvmModifier.FINAL)) - problems.add(manager.createProblemDescriptor(elem, "Cannot extend final type", isOnTheFly, new LocalQuickFix[0], ProblemHighlightType.GENERIC_ERROR)); - } - } - var implementsElems = PsiUtils - .childOfType(type, KScrImplementsClause.class) - .map(x -> PsiUtils.childrenOfType(x, KScrTypeRef.class)) - .orElse(List.of()); - for(KScrTypeRef elem : implementsElems){ - var extType = elem.asType(); - if(elem.getTextLength() == 0) - continue; - if(extType != null) - if(!(extType instanceof JvmReferenceType)) - problems.add(manager.createProblemDescriptor(elem, "Expecting a class, not primitive or array", isOnTheFly, new LocalQuickFix[0], ProblemHighlightType.GENERIC_ERROR)); - else{ - var implClass = elem.asClass(); - if(type.kind() == KScrKind.INTERFACE) - problems.add(manager.createProblemDescriptor(elem, "Interfaces cannot implement types", isOnTheFly, new LocalQuickFix[0], ProblemHighlightType.GENERIC_ERROR)); - else if(implClass.getClassKind() != JvmClassKind.INTERFACE) - problems.add(manager.createProblemDescriptor(elem, "Expected an interface", isOnTheFly, new LocalQuickFix[]{ new ChangeSupertypeKindFix(elem, true) }, ProblemHighlightType.GENERIC_ERROR)); - if(implClass.hasModifier(JvmModifier.FINAL)) // is this even valid Java or KScr? I guess sealed interfaces are basically this... - problems.add(manager.createProblemDescriptor(elem, "Cannot implement final type", isOnTheFly, new LocalQuickFix[0], ProblemHighlightType.GENERIC_ERROR)); - } - } - return problems.toArray(ProblemDescriptor[]::new); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/InvalidTypeRefInspection.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/InvalidTypeRefInspection.java deleted file mode 100644 index ac31cba..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/InvalidTypeRefInspection.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.comroid.kscr.intellij.inspections; - -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.ProblemsHolder; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiElementVisitor; -import org.comroid.kscr.intellij.psi.utils.KScrTypeReference; -import org.jetbrains.annotations.NotNull; - -public class InvalidTypeRefInspection extends LocalInspectionTool{ - - public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly){ - return new PsiElementVisitor(){ - public void visitElement(@NotNull PsiElement element){ - super.visitElement(element); - var ref = element.getReference(); - if(ref instanceof KScrTypeReference) - if(ref.resolve() == null){ - var text = element.getText(); - if(text.length() > 0 && !(text.equals("boolean") || text.equals("byte") || text.equals("short") || text.equals("char") - || text.equals("int") || text.equals("long") || text.equals("float") || text.equals("double"))) - holder.registerProblem(ref); - } - } - }; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/KScrInspection.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/KScrInspection.java deleted file mode 100644 index 499406a..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/KScrInspection.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.comroid.kscr.intellij.inspections; - -import com.intellij.codeInspection.InspectionManager; -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.psi.PsiFile; -import org.comroid.kscr.intellij.psi.KScrFile; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; - -public abstract class KScrInspection extends LocalInspectionTool{ - - public ProblemDescriptor @NotNull [] checkTypeDef(@NotNull KScrType type, @NotNull InspectionManager manager, boolean isOnTheFly){ - return new ProblemDescriptor[0]; - } - - public ProblemDescriptor @NotNull [] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly){ - List problems = new ArrayList<>(); - if(file instanceof KScrFile){ - KScrFile kScrFile = (KScrFile)file; - problems.addAll(List.of(kScrFile.getTypeDef().map(l -> checkTypeDef(l, manager, isOnTheFly)).orElse(new ProblemDescriptor[0]))); - } - return problems.toArray(ProblemDescriptor[]::new); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/ThisInStaticMethodInspection.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/ThisInStaticMethodInspection.java deleted file mode 100644 index 41f4c15..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/ThisInStaticMethodInspection.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.comroid.kscr.intellij.inspections; - -import com.intellij.codeInspection.LocalInspectionTool; -import com.intellij.codeInspection.ProblemHighlightType; -import com.intellij.codeInspection.ProblemsHolder; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.util.PsiTreeUtil; -import org.comroid.kscr.intellij.psi.expressions.KScrThisExpr; -import org.jetbrains.annotations.NotNull; - -public class ThisInStaticMethodInspection extends LocalInspectionTool{ - - public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly){ - return new PsiElementVisitor(){ - public void visitElement(@NotNull PsiElement element){ - super.visitElement(element); - if(element instanceof KScrThisExpr){ - var container = PsiTreeUtil.getParentOfType(element, KScrMethod.class); - if(container != null && container.isStatic() && element.getText().equals("this")) - holder.registerProblem(element, "'this' can only be used in non-static contexts", ProblemHighlightType.ERROR); - } - } - }; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/WrongFileNameForTypeNameInspection.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/WrongFileNameForTypeNameInspection.java deleted file mode 100644 index 292713f..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/WrongFileNameForTypeNameInspection.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.comroid.kscr.intellij.inspections; - -import com.intellij.codeHighlighting.HighlightDisplayLevel; -import com.intellij.codeInspection.InspectionManager; -import com.intellij.codeInspection.LocalQuickFix; -import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.codeInspection.ProblemHighlightType; -import org.comroid.kscr.intellij.inspections.fixes.RenameFileToTypeFix; -import org.comroid.kscr.intellij.inspections.fixes.RenameTypeToFileFix; -import org.jetbrains.annotations.NotNull; - -public class WrongFileNameForTypeNameInspection extends KScrInspection{ - - public ProblemDescriptor @NotNull [] checkTypeDef(@NotNull KScrType type, @NotNull InspectionManager manager, boolean isOnTheFly){ - String typeName = type.getName(); - if(type.isTopLevelType() && type.getNameIdentifier() != null) - if(type.getNameIdentifier().getTextLength() > 0){ - if(!typeName.equals(type.getContainingFile().getName())) - return new ProblemDescriptor[]{manager.createProblemDescriptor(type.getNameIdentifier(), "KScr type '" + typeName + "' should be declared in file '" + typeName + ".kScr'", new LocalQuickFix[]{new RenameFileToTypeFix(type, typeName), new RenameTypeToFileFix(type, type.getContainingFile().getName())}, ProblemHighlightType.ERROR, isOnTheFly, false)}; - }else return new ProblemDescriptor[]{manager.createProblemDescriptor(type, "KScr type must have name '" + type.getContainingFile().getName() + "'", new LocalQuickFix[]{}, ProblemHighlightType.GENERIC_ERROR, isOnTheFly, false)}; - return super.checkTypeDef(type, manager, isOnTheFly); - } - - public boolean isEnabledByDefault(){ - return true; - } - - @NotNull - public HighlightDisplayLevel getDefaultLevel() { - return HighlightDisplayLevel.ERROR; - } - - @NotNull - public String getShortName(){ - return "WrongFileNameForTypeName"; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/AddImportFix.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/AddImportFix.java deleted file mode 100644 index 8b2b2e2..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/AddImportFix.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.comroid.kscr.intellij.inspections.fixes; - -import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement; -import com.intellij.codeInspection.util.IntentionFamilyName; -import com.intellij.codeInspection.util.IntentionName; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import org.comroid.kscr.intellij.psi.KScrFile; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class AddImportFix extends LocalQuickFixAndIntentionActionOnPsiElement{ - - private final String fqName; - - public AddImportFix(String name, PsiElement on){ - super(on); - fqName = name; - } - - public @IntentionName @NotNull String getText(){ - return "Add import for '" + fqName + "'"; - } - - public @IntentionFamilyName @NotNull String getFamilyName(){ - return "Add missing import"; - } - - public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement){ - addImport(file, fqName); - } - - public static void addImport(@NotNull PsiFile file, String fqName){ - if(file instanceof KScrFile){ - KScrFile kScrFile = (KScrFile)file; - kScrFile.wrapper().flatMap(w -> PsiUtils.childOfType(w, KScrImportList.class)).ifPresent(list -> { - list.add(PsiUtils.createWhitespace(list, "\n")); - list.add(PsiUtils.createImportFromText(list, "import " + fqName + ";")); - }); - } - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/ChangeSupertypeKindFix.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/ChangeSupertypeKindFix.java deleted file mode 100644 index b375c53..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/ChangeSupertypeKindFix.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.comroid.kscr.intellij.inspections.fixes; - -import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement; -import com.intellij.codeInspection.util.IntentionFamilyName; -import com.intellij.codeInspection.util.IntentionName; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiWhiteSpace; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static org.comroid.kscr.intellij.psi.utils.PsiUtils.*; - -public class ChangeSupertypeKindFix extends LocalQuickFixAndIntentionActionOnPsiElement{ - - private final boolean toExtends; - - public ChangeSupertypeKindFix(@Nullable PsiElement element, boolean toExtends){ - super(element); - this.toExtends = toExtends; - } - - public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement){ - PsiElement from = startElement.getParent(); - String type = startElement.getText(); - var targetOpt = toExtends ? - childOfType(from.getParent(), KScrExtendsClause.class) : - childOfType(from.getParent(), KScrImplementsClause.class); - String newClause = targetOpt.map(x -> x.getText() + ", ").orElse(toExtends ? "extends " : "implements ") + type; - var newElem = toExtends ? - createExtendsClauseFromText(from.getParent(), newClause) : - createImplementsClauseFromText(from.getParent(), newClause); - - if(targetOpt.isPresent()) - targetOpt.get().replace(newElem); - else{ - if(toExtends){ - from.getParent().addBefore(newElem, from); from.addAfter(createWhitespace(newElem, " "), null); - }else{ - from.getParent().addAfter(newElem, from); from.addBefore(createWhitespace(newElem, " "), null); - } - } - - var others = childrenOfType(from, KScrTypeRef.class); - if(others.size() == 1) - from.delete(); - else{ - // clean up commas - // if we're first, remove first comma, else remove previous one - if(startElement == others.get(0)){ - while(startElement.getNextSibling() != null && (startElement.getNextSibling() instanceof PsiWhiteSpace || startElement.getNextSibling().getText().equals(","))) - startElement.getNextSibling().delete(); - }else{ - while(startElement.getPrevSibling() != null && (startElement.getPrevSibling() instanceof PsiWhiteSpace || startElement.getPrevSibling().getText().equals(","))) - startElement.getPrevSibling().delete(); - } - startElement.delete(); - } - } - - public @IntentionName @NotNull String getText(){ - return "Change to '" + (toExtends ? "extends" : "implements") + "'"; - } - - public @IntentionFamilyName @NotNull String getFamilyName(){ - return "Swap 'extends' and 'implements'"; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/RenameFileToTypeFix.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/RenameFileToTypeFix.java deleted file mode 100644 index b028488..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/RenameFileToTypeFix.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.comroid.kscr.intellij.inspections.fixes; - -import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement; -import com.intellij.codeInspection.util.IntentionFamilyName; -import com.intellij.codeInspection.util.IntentionName; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class RenameFileToTypeFix extends LocalQuickFixAndIntentionActionOnPsiElement{ - - private final String newName; - - public RenameFileToTypeFix(@Nullable PsiElement element, String newName){ - super(element); - this.newName = newName; - } - - public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement){ - if(startElement instanceof KScrType) - file.setName(newName + ".kScr"); - } - - public @IntentionName @NotNull String getText(){ - return "Rename file to '" + newName + ".kScr'"; - } - - public @IntentionFamilyName @NotNull String getFamilyName(){ - return "Rename file to match type"; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/RenameTypeToFileFix.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/RenameTypeToFileFix.java deleted file mode 100644 index f0a94b9..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/inspections/fixes/RenameTypeToFileFix.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.comroid.kscr.intellij.inspections.fixes; - -import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement; -import com.intellij.codeInspection.util.IntentionFamilyName; -import com.intellij.codeInspection.util.IntentionName; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class RenameTypeToFileFix extends LocalQuickFixAndIntentionActionOnPsiElement{ - - private final String newName; - - public RenameTypeToFileFix(@Nullable PsiElement element, String newName){ - super(element); - this.newName = newName; - } - - public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement){ - if(startElement instanceof KScrType) - ((KScrType)startElement).setName(newName); - } - - public @IntentionName @NotNull String getText(){ - return "Rename type to '" + newName + "'"; - } - - public @IntentionFamilyName @NotNull String getFamilyName(){ - return "Rename type to match file"; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/KScrParserDefinition.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/KScrParserDefinition.java deleted file mode 100644 index e956576..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/KScrParserDefinition.java +++ /dev/null @@ -1,175 +0,0 @@ -package org.comroid.kscr.intellij.parser; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.ParserDefinition; -import com.intellij.lang.PsiParser; -import com.intellij.lexer.Lexer; -import com.intellij.openapi.project.Project; -import com.intellij.psi.FileViewProvider; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.tree.IFileElementType; -import com.intellij.psi.tree.IStubFileElementType; -import com.intellij.psi.tree.TokenSet; -import org.comroid.kscr.intellij.KScrLanguage; -import org.comroid.kscr.intellij.antlr_generated.KScrLexer; -import org.comroid.kscr.intellij.antlr_generated.KScrParser; -import org.comroid.kscr.intellij.psi.Tokens; -import org.comroid.kscr.intellij.psi.ast.statements.*; -import org.comroid.kscr.intellij.psi.ast.common.*; -import org.comroid.kscr.intellij.psi.ast.types.*; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -public class KScrParserDefinition implements ParserDefinition { - public static final IStubFileElementType FILE = - new IStubFileElementType<>("cyclic.FILE", KScrLanguage.LANGUAGE){ - public @NonNls @NotNull String getExternalId(){ - return "cyclic.FILE"; - } - }; - - @Override - public @NotNull Lexer createLexer(Project project) { - return new LexerAdapter(new KScrLexer(null)); - } - - @Override - public @NotNull PsiParser createParser(Project project) { - return new ParserAdapter(); - } - - @Override - public @NotNull IFileElementType getFileNodeType() { - return FILE; - } - - @Override - public @NotNull TokenSet getCommentTokens() { - return Tokens.COMMENTS; - } - - @Override - public @NotNull TokenSet getWhitespaceTokens() { - return Tokens.WHITESPACES; - } - - @Override - public @NotNull TokenSet getStringLiteralElements() { - return Tokens.STRING_LITERALS; - } - - @Override - public @NotNull PsiElement createElement(ASTNode node) { - // TODO: replace with switch (by rule index) - var type = node.getElementType(); - if(type == Tokens.getRuleFor(KScrParser.RULE_file)) - return new KScrFileWrapper(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_classDecl)) - return new KScrType(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_id)) - return new KScrId(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_idPart)) - return new KScrIdPart(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_packageDecl)) - return new KScrPackageStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_importDecl)) - return new KScrImportStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_imports)) - return new KScrImportList(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_annotation)) - return new KScrAnnotation(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_rawType)) - return new KScrRawTypeRef(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_type)) - return new KScrTypeRef(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_typeOrInferred)) - return new KScrTypeRefOrInferred(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_member)) - return new KScrMemberWrapper(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_modifiers)) - return new KScrModifierList(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_modifier)) - return new KScrModifier(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_function)) - return new KScrMethod(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_constructor)) - return new KScrConstructor(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_statement)) - return new KScrStatementWrapper(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_value)) - return createExpr(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_call)) - return new KScrCall(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_initialisation)) - return new KScrInitialisation(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_varAssignment)) - return new KScrVariableAssignment(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_objectExtends)) - return new KScrExtendsClause(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_objectImplements)) - return new KScrImplementsClause(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_objectPermits)) - return new KScrPermitsClause(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_block)) - return new KScrBlock(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_varDecl)) - return new KScrVariableDef(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_parameter)) - return new KScrParameter(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_recordComponents)) - return new KScrRecordComponents(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_arguments)) - return new KScrArgumentsList(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_parameters)) - return new KScrParametersList(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_binaryop)) - return new KScrBinaryOp(node); - - if(type == Tokens.getRuleFor(KScrParser.RULE_assertStatement)) - return new KScrAssertStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_ctorCall)) - return new KScrConstructorCallStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_doWhileStatement)) - return new KScrDoWhileStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_foreachStatement)) - return new KScrForeachStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_forStatement)) - return new KScrForStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_ifStatement)) - return new KScrIfStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_elseStatement)) - return new KScrElseClause(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_returnStatement)) - return new KScrReturnStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_switchStatement)) - return new KScrSwitchStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_throwStatement)) - return new KScrThrowStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_mutation)) - return new KScrVarAssignStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_varIncrement)) - return new KScrVarIncrementStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_whileStatement)) - return new KScrWhileStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_yieldStatement)) - return new KScrYieldStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_tryStatement)) - return new KScrTryCatchStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_catchBlock)) - return new KScrCatchBlock(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_finallyBlock)) - return new KScrFinallyBlock(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_breakStatement)) - return new KScrBreakStatement(node); - if(type == Tokens.getRuleFor(KScrParser.RULE_continueStatement)) - return new KScrContinueStatement(node); - - return new KScrAstElement(node); - } - - @Override - public @NotNull PsiFile createFile(@NotNull FileViewProvider viewProvider) { - return null; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/KScrSyntaxHighlighter.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/KScrSyntaxHighlighter.java deleted file mode 100644 index 5ba0923..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/KScrSyntaxHighlighter.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.comroid.kscr.intellij.parser; - -import com.intellij.lexer.Lexer; -import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; -import com.intellij.openapi.editor.colors.TextAttributesKey; -import com.intellij.openapi.fileTypes.SyntaxHighlighter; -import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.tree.IElementType; -import org.comroid.kscr.intellij.antlr_generated.KScrLangLexer; -import org.comroid.kscr.intellij.psi.Tokens; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrSyntaxHighlighter extends SyntaxHighlighterFactory implements SyntaxHighlighter { - - public static final TextAttributesKey ID = TextAttributesKey.createTextAttributesKey("KScr-ID", DefaultLanguageHighlighterColors.IDENTIFIER); - public static final TextAttributesKey KEYWORD = TextAttributesKey.createTextAttributesKey("KScr-Keyword", DefaultLanguageHighlighterColors.KEYWORD); - public static final TextAttributesKey NUMLIT = TextAttributesKey.createTextAttributesKey("KScr-Number-Literal", DefaultLanguageHighlighterColors.NUMBER); - public static final TextAttributesKey STRLIT = TextAttributesKey.createTextAttributesKey("KScr-String-Literal", DefaultLanguageHighlighterColors.STRING); - public static final TextAttributesKey SYMBOLS = TextAttributesKey.createTextAttributesKey("KScr-Symbols", DefaultLanguageHighlighterColors.SEMICOLON); - public static final TextAttributesKey DOTCOMMA = TextAttributesKey.createTextAttributesKey("KScr-Dot-Comma", DefaultLanguageHighlighterColors.DOT); - public static final TextAttributesKey OPERATORS = TextAttributesKey.createTextAttributesKey("KScr-Operators", DefaultLanguageHighlighterColors.OPERATION_SIGN); - public static final TextAttributesKey COMMENT = TextAttributesKey.createTextAttributesKey("KScr-Comment", DefaultLanguageHighlighterColors.LINE_COMMENT); - - @NotNull - @Override public Lexer getHighlightingLexer(){ - KScrLangLexer lexer = new KScrLangLexer(null); - return new LexerAdapter(lexer); - } - - public TextAttributesKey @NotNull [] getTokenHighlights(IElementType element){ - if(Tokens.IDENTIFIERS.contains(element)) - return array(ID); - else if(Tokens.KEYWORDS.contains(element)) - return array(KEYWORD); - else if(Tokens.getFor(KScrLangLexer.STRLIT) == element) - return array(STRLIT); - else if(Tokens.LITERALS.contains(element)) - return array(NUMLIT); // Add boolean literal formatting - else if(Tokens.PUNCTUATION.contains(element)) - return array(DOTCOMMA); - else if(Tokens.SYMBOLS.contains(element)) - return array(SYMBOLS); - else if(Tokens.OPERATORS.contains(element)) - return array(OPERATORS); - else if(Tokens.COMMENTS.contains(element)) - return array(COMMENT); - - return new TextAttributesKey[0]; - } - - public @NotNull com.intellij.openapi.fileTypes.SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile){ - return new KScrSyntaxHighlighter(); - } - - public TextAttributesKey[] array(TextAttributesKey key){ - return new TextAttributesKey[]{key}; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/LexerAdapter.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/LexerAdapter.java deleted file mode 100644 index 9fbc9be..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/LexerAdapter.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.comroid.kscr.intellij.parser; - -import com.intellij.lang.Language; -import com.intellij.lexer.Lexer; -import com.intellij.lexer.LexerPosition; -import com.intellij.psi.tree.IElementType; -import org.antlr.intellij.adaptor.lexer.ANTLRLexerAdaptor; -import org.comroid.kscr.intellij.KScrLanguage; -import org.comroid.kscr.intellij.antlr_generated.KScrLexer; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class LexerAdapter extends ANTLRLexerAdaptor { - /** - * Constructs a new instance of {@link ANTLRLexerAdaptor} with - * the specified {@link Language} and underlying ANTLR {@link - * Lexer}. - * - * @param lexer The underlying ANTLR lexer. - */ - public LexerAdapter(org.antlr.v4.runtime.Lexer lexer) { - super(KScrLanguage.LANGUAGE, lexer); - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/ParserAdapter.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/ParserAdapter.java deleted file mode 100644 index 71d24e5..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/parser/ParserAdapter.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.comroid.kscr.intellij.parser; - -import com.intellij.lang.Language; -import com.intellij.lang.PsiParser; -import com.intellij.psi.tree.IElementType; -import org.antlr.intellij.adaptor.parser.ANTLRParserAdaptor; -import org.antlr.v4.runtime.Parser; -import org.antlr.v4.runtime.tree.ParseTree; -import org.comroid.kscr.intellij.KScrLanguage; -import org.comroid.kscr.intellij.antlr_generated.KScrParser; - -public class ParserAdapter extends ANTLRParserAdaptor { - /** - * Create a jetbrains adaptor for an ANTLR parser object. When - * the IDE requests a {@link #parse(IElementType, PsiBuilder)}, - * the token stream will be set on the parser. - * - * @param parser - */ - public ParserAdapter() { - super(KScrLanguage.LANGUAGE, new KScrParser(null)); - } - - @Override - protected ParseTree parse(Parser parser, IElementType root) { - return null; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrAstElement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrAstElement.java deleted file mode 100644 index 9e3809e..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrAstElement.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.comroid.kscr.intellij.psi; - -import com.intellij.extapi.psi.ASTWrapperPsiElement; -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import com.intellij.psi.ResolveState; -import com.intellij.psi.scope.PsiScopeProcessor; -import org.comroid.kscr.intellij.antlr_generated.KScrParser; -import org.antlr.intellij.adaptor.lexer.RuleIElementType; -import org.antlr.intellij.adaptor.psi.Trees; -import org.comroid.kscr.intellij.psi.KScrElement; -import org.jetbrains.annotations.NotNull; - -public class KScrAstElement extends ASTWrapperPsiElement implements KScrElement { - - public KScrAstElement(@NotNull ASTNode node){ - super(node); - } - - public PsiElement @NotNull [] getChildren(){ - // include leaves - return Trees.getChildren(this); - } - - public String toString(){ - if(getClass() != KScrAstElement.class) - return getClass().getSimpleName(); - boolean isRule = getNode().getElementType() instanceof RuleIElementType; - if(isRule && KScrParser.ruleNames.length < ((RuleIElementType)getNode().getElementType()).getRuleIndex()) - return getClass().getSimpleName() + "(" + KScrParser.ruleNames[((RuleIElementType)getNode().getElementType()).getRuleIndex()] + ")"; - return getClass().getSimpleName(); - } - - public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place){ - boolean cont = true; - for(PsiElement child : getChildren()) - if(cont && lastParent != child) - cont = processor.execute(child, state); - return cont; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrElement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrElement.java deleted file mode 100644 index ad73947..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrElement.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.comroid.kscr.intellij.psi; - -import com.intellij.psi.PsiElement; - -import java.util.Optional; - -public interface KScrElement extends PsiElement{ - - default Optional getContainer(){ - var file = getContainingFile(); - if(file instanceof KScrFile) - return ((KScrFile)file).wrapper(); - return Optional.empty(); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrFile.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrFile.java deleted file mode 100644 index 8821173..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrFile.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.comroid.kscr.intellij.psi; - -import com.intellij.extapi.psi.PsiFileBase; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.psi.FileViewProvider; -import org.comroid.kscr.intellij.KScrFileType; -import org.comroid.kscr.intellij.KScrLanguage; -import org.comroid.kscr.intellij.KScrSourceFileType; -import org.comroid.kscr.intellij.psi.ast.KScrImportStatement; -import org.comroid.kscr.intellij.psi.ast.KScrPackageStatement; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -public class KScrFile extends PsiFileBase{ - - public KScrFile(@NotNull FileViewProvider viewProvider){ - super(viewProvider, KScrLanguage.LANGUAGE); - } - - public @NotNull FileType getFileType(){ - return KScrSourceFileType.FILE_TYPE; - } - - public Optional wrapper(){ - return PsiUtils.childOfType(this, KScrFileWrapper.class); - } - - public Optional getPackage(){ - return wrapper().flatMap(KScrFileWrapper::getPackage); - } - - public String getPackageName(){ - return getPackage().map(KScrPackageStatement::getPackageName).orElse(""); - } - - public List getImports(){ - return wrapper().map(KScrFileWrapper::getImports).orElse(new ArrayList<>(0)); - } - - public Optional getTypeDef(){ - return wrapper().flatMap(KScrFileWrapper::getTypeDef); - } - - public @NotNull String getFileName(){ - return getViewProvider().getVirtualFile().getName(); - } - - public @NotNull String getName(){ - var o = super.getName(); - if(getTypeDef().isPresent()) - return o.substring(0, o.length() - ".KScr".length()); - return o; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrFileWrapper.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrFileWrapper.java deleted file mode 100644 index da7737d..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrFileWrapper.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.comroid.kscr.intellij.psi; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.util.PsiTreeUtil; -import org.comroid.kscr.intellij.psi.ast.KScrImportStatement; -import org.comroid.kscr.intellij.psi.ast.KScrPackageStatement; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -public class KScrFileWrapper extends KScrElement { - - public KScrFileWrapper(@NotNull ASTNode node){ - super(node); - } - - public Optional getPackage(){ - return PsiUtils.childOfType(this, KScrPackageStatement.class); - } - - public List getImports(){ - return new ArrayList<>(PsiTreeUtil.findChildrenOfType(this, KScrImportStatement.class)); - } - - public Optional getTypeDef(){ - return PsiUtils.childOfType(this, KScrType.class); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrStubElement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrStubElement.java deleted file mode 100644 index 8d6c4eb..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/KScrStubElement.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.comroid.kscr.intellij.psi; - -import com.intellij.extapi.psi.StubBasedPsiElementBase; -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import com.intellij.psi.StubBasedPsiElement; -import com.intellij.psi.stubs.IStubElementType; -import com.intellij.psi.stubs.StubElement; -import org.jetbrains.annotations.NotNull; - -public class KScrStubElement> - extends StubBasedPsiElementBase - implements KScrElement, StubBasedPsiElement{ - - private PsiElement navigationElement = null; - - public KScrStubElement(@NotNull Stub stub, @NotNull IStubElementType nodeType){ - super(stub, nodeType); - } - - public KScrStubElement(@NotNull ASTNode node){ - super(node); - } - - public KScrStubElement setNavigationElement(PsiElement navigationElement){ - this.navigationElement = navigationElement; - return this; - } - - public PsiElement getNavigationElement(){ - return navigationElement != null ? navigationElement : this; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/Tokens.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/Tokens.java deleted file mode 100644 index 5676856..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/Tokens.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.comroid.kscr.intellij.psi; - -import com.intellij.psi.TokenType; -import com.intellij.psi.tree.IElementType; -import com.intellij.psi.tree.TokenSet; -import org.antlr.intellij.adaptor.lexer.PSIElementTypeFactory; -import org.antlr.intellij.adaptor.lexer.RuleIElementType; -import org.antlr.intellij.adaptor.lexer.TokenIElementType; -import org.comroid.kscr.intellij.KScrLanguage; -import org.comroid.kscr.intellij.antlr_generated.KScrLangLexer; -import org.comroid.kscr.intellij.antlr_generated.KScrLangParser; -import org.jetbrains.annotations.Contract; - -import static org.antlr.intellij.adaptor.lexer.PSIElementTypeFactory.createTokenSet; - -import java.util.List; - -public class Tokens { - public static IElementType BAD_TOKEN_TYPE = TokenType.BAD_CHARACTER; - - public static final List TOKEN_ELEMENT_TYPES = PSIElementTypeFactory.getTokenIElementTypes(KScrLanguage.LANGUAGE); - public static final List RULE_ELEMENT_TYPES = PSIElementTypeFactory.getRuleIElementTypes(KScrLanguage.LANGUAGE); - - public static final TokenSet KEYWORDS = createTokenSet( - KScrLanguage.LANGUAGE, - - KScrLangLexer.BOOL, - KScrLangLexer.BYTE, - KScrLangLexer.SHORT, - KScrLangLexer.CHAR, - KScrLangLexer.INT, - KScrLangLexer.LONG, - KScrLangLexer.FLOAT, - KScrLangLexer.DOUBLE, - KScrLangLexer.VOID, - - KScrLangLexer.VAR, - - KScrLangLexer.PRIVATE, - KScrLangLexer.PROTECTED, - KScrLangLexer.PUBLIC, - - KScrLangLexer.FINAL, - KScrLangLexer.STATIC, - KScrLangLexer.ABSTRACT, - KScrLangLexer.SYNCHRONISED, - KScrLangLexer.NATIVE, - - KScrLangLexer.CLASS, - KScrLangLexer.INTERFACE, - KScrLangLexer.ENUM, - KScrLangLexer.AT, - KScrLangLexer.RECORD, - KScrLangLexer.SINGLE, - - KScrLangLexer.IMPORT, - KScrLangLexer.PACKAGE, - KScrLangLexer.EXTENDS, - KScrLangLexer.IMPLEMENTS, - KScrLangLexer.PERMITS, - - KScrLangLexer.RETURN, - KScrLangLexer.THROW, - KScrLangLexer.NEW, - KScrLangLexer.ASSERT, - - KScrLangLexer.THIS, - - KScrLangLexer.SWITCH, - KScrLangLexer.DEFAULT, - KScrLangLexer.CASE, - KScrLangLexer.WHILE, - KScrLangLexer.DO, - KScrLangLexer.IF, - KScrLangLexer.FOR, - KScrLangLexer.ELSE, - - KScrLangLexer.NULL, - KScrLangLexer.TRUE, - KScrLangLexer.FALSE - ); - - public static final TokenSet OPERATORS = createTokenSet( - KScrLanguage.LANGUAGE, - - KScrLangLexer.EQUAL, - KScrLangLexer.INEQUAL, - KScrLangLexer.GREATEREQ, - KScrLangLexer.LESSEREQ, - KScrLangLexer.GREATER, - KScrLangLexer.LESSER, - - KScrLangLexer.AND, - KScrLangLexer.OR, - KScrLangLexer.BITAND, - KScrLangLexer.BITOR, - - KScrLangLexer.UP, - - KScrLangLexer.PLUSPLUS, - KScrLangLexer.MINUSMINUS, - - KScrLangLexer.STAR, - KScrLangLexer.SLASH, - KScrLangLexer.PLUS, - KScrLangLexer.MINUS, - KScrLangLexer.PERCENT - ); - - // used for syntax highlighting - public static final TokenSet LITERALS = createTokenSet( - KScrLanguage.LANGUAGE, - - KScrLangLexer.NUMLIT, - KScrLangLexer.BOOLLIT, - KScrLangLexer.STRLIT, - KScrLangLexer.RANGELIT - ); - - public static final TokenSet SYMBOLS = createTokenSet( - KScrLanguage.LANGUAGE, - - KScrLangLexer.QUOTE, - KScrLangLexer.SEMICOLON, - - KScrLangLexer.RDASHARROW, - KScrLangLexer.LDASHARROW, - KScrLangLexer.DEQARROW, - KScrLangLexer.REQARROW - ); - - public static final TokenSet PUNCTUATION = createTokenSet( - KScrLanguage.LANGUAGE, - - KScrLangLexer.DOT, - KScrLangLexer.COMMA, - KScrLangLexer.COLON, - KScrLangLexer.ASSIGN, - - KScrLangLexer.EXCLAMATION, - KScrLangLexer.QUESTION - ); - - public static final TokenSet WHITESPACES = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.WS); - public static final TokenSet COMMENTS = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.SING_COMMENT); - public static final TokenSet STRING_LITERALS = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.STRLIT); - public static final TokenSet IDENTIFIERS = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.ID); - - // single-element sets - public static final TokenSet RULE_IMPORT = TokenSet.create(getRuleFor(KScrLangParser.RULE_importDecl)); - public static final TokenSet RULE_BIN_OP = TokenSet.create(getRuleFor(KScrLangParser.RULE_binaryop)); - public static final TokenSet RULE_CALL = TokenSet.create(getRuleFor(KScrLangParser.RULE_call)); - public static final TokenSet RULE_ID_PART = TokenSet.create(getRuleFor(KScrLangParser.RULE_idPart)); - public static final TokenSet RULE_INITIALISATION = TokenSet.create(getRuleFor(KScrLangParser.RULE_initialisation)); - public static final TokenSet RULE_CAST = TokenSet.create(getRuleFor(KScrLangParser.RULE_cast)); - public static final TokenSet RULE_NEW_ARRAY = TokenSet.create(getRuleFor(KScrLangParser.RULE_newArray)); - public static final TokenSet RULE_NEW_LIST_ARRAY = TokenSet.create(getRuleFor(KScrLangParser.RULE_newListedArray)); - - public static final TokenSet TOK_ASSIGN = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.ASSIGN); - public static final TokenSet TOK_INSTANCEOF = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.INSTANCEOF); - public static final TokenSet TOK_THIS = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.THIS); - public static final TokenSet TOK_STRING = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.STRLIT); - - public static final TokenSet TOK_CLASS = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.CLASS); - public static final TokenSet TOK_INTERFACE = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.INTERFACE); - public static final TokenSet TOK_ANNOTATION = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.ANNOTATION); - public static final TokenSet TOK_AT = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.AT); - public static final TokenSet TOK_ENUM = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.ENUM); - public static final TokenSet TOK_RECORD = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.RECORD); - public static final TokenSet TOK_SINGLE = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.SINGLE); - - public static final TokenSet TOK_NULL = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.NULL); - public static final TokenSet TOK_NUMLIT = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.NUMLIT); - public static final TokenSet TOK_RANGELIT = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.RANGELIT); - public static final TokenSet TOK_BOOLLIT = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.BOOLLIT); - - public static final TokenSet PARENTHESIS = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.LPAREN, KScrLangLexer.RPAREN); - public static final TokenSet SQ_BRACES = createTokenSet(KScrLanguage.LANGUAGE, KScrLangLexer.LSQUAR, KScrLangLexer.RSQUAR); - public static final TokenSet PRE_POST_OPS = TokenSet.create( - getRuleFor(KScrLangParser.RULE_prefixop), getRuleFor(KScrLangParser.RULE_postfixop)); - - // used for literal expression checking - public static final TokenSet SEM_LITERALS = createTokenSet(KScrLanguage.LANGUAGE, - KScrLangLexer.NULL, - KScrLangLexer.NUMLIT, - KScrLangLexer.RANGELIT, - KScrLangLexer.BOOLLIT - ); - - @Contract(pure = true) public static IElementType getFor(int type){ - return TOKEN_ELEMENT_TYPES.get(type); - } - - @Contract(pure = true) public static IElementType getRuleFor(int type){ - return RULE_ELEMENT_TYPES.get(type); - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrAnnotation.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrAnnotation.java deleted file mode 100644 index fae0592..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrAnnotation.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiReference; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.KScrIdHolder; -import org.comroid.kscr.intellij.psi.utils.KScrTypeReference; -import org.jetbrains.annotations.NotNull; - -public class KScrAnnotation extends KScrAstElement implements KScrIdHolder{ - - public KScrAnnotation(@NotNull ASTNode node){ - super(node); - } - - public PsiReference getReference(){ - return getIdElement().map(id -> new KScrTypeReference(id, this)).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrArgumentsList.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrArgumentsList.java deleted file mode 100644 index 3690c99..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrArgumentsList.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrArgumentsList extends KScrAstElement{ - - public KScrArgumentsList(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrBinaryOp.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrBinaryOp.java deleted file mode 100644 index 1015f20..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrBinaryOp.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrBinaryOp extends KScrAstElement{ - - public KScrBinaryOp(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrConstructor.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrConstructor.java deleted file mode 100644 index 918835e..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrConstructor.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmMethod; -import com.intellij.psi.util.PsiTreeUtil; -import org.comroid.kscr.intellij.psi.KScrCodeHolder; -import org.comroid.kscr.intellij.psi.KScrDefinitionAstElement; -import org.comroid.kscr.intellij.psi.KScrModifiersHolder; -import org.comroid.kscr.intellij.psi.ast.common.KScrParameter; -import org.comroid.kscr.intellij.psi.ast.statements.KScrStatement; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.types.JvmKScrlicConstructor; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Optional; - -// TODO: stubs -public class KScrConstructor extends KScrDefinitionAstElement implements KScrModifiersHolder, KScrCodeHolder{ - - public KScrConstructor(@NotNull ASTNode node){ - super(node); - } - - public List parameters(){ - var paramList = PsiUtils.childOfType(this, KScrParametersList.class); - return paramList.map(list -> PsiUtils.childrenOfType(list, KScrParameter.class)).orElseGet(List::of); - } - - public Optional body(){ - // last child is either a block or (-> +) statement - var last = getLastChild(); - if(last instanceof KScrStatement) - return Optional.of((KScrStatement)last); - return Optional.empty(); - } - - public JvmMethod toJvm(){ - return JvmKScrlicConstructor.of(this); - } - - public KScrType containingType(){ - return PsiTreeUtil.getParentOfType(this, KScrType.class); - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrFileWrapper.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrFileWrapper.java deleted file mode 100644 index 25124ce..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrFileWrapper.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.util.PsiTreeUtil; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -public class KScrFileWrapper extends KScrAstElement { - - public KScrFileWrapper(@NotNull ASTNode node){ - super(node); - } - - public Optional getPackage(){ - return PsiUtils.childOfType(this, KScrPackageStatement.class); - } - - public List getImports(){ - return new ArrayList<>(PsiTreeUtil.findChildrenOfType(this, KScrImportStatement.class)); - } - - public Optional getTypeDef(){ - return PsiUtils.childOfType(this, KScrType.class); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrId.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrId.java deleted file mode 100644 index 08f670c..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrId.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrId extends KScrAstElement{ - - public KScrId(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrIdPart.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrIdPart.java deleted file mode 100644 index 9642f1e..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrIdPart.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrIdPart extends KScrAstElement{ - - public KScrIdPart(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrImportList.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrImportList.java deleted file mode 100644 index 8c01a87..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrImportList.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrImportList extends KScrAstElement{ - - public KScrImportList(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrImportStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrImportStatement.java deleted file mode 100644 index b43a62c..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrImportStatement.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.psi.PsiReference; -import org.comroid.kscr.intellij.antlr_generated.KScrlicLangParser; -import org.comroid.kscr.intellij.psi.*; -import org.comroid.kscr.intellij.psi.utils.KScrTypeReference; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; - -public class KScrImportStatement extends KScrAstElement implements KScrIdHolder{ - - public KScrImportStatement(@NotNull ASTNode node){ - super(node); - } - - public boolean isStatic(){ - return !PsiUtils.matchingChildren(this, k -> k.getNode().getElementType() == Tokens.getFor(KScrlicLangParser.STATIC)).isEmpty(); - } - - public boolean isWildcard(){ - return !PsiUtils.matchingChildren(this, k -> k.getNode().getElementType() == Tokens.getFor(KScrlicLangParser.STAR)).isEmpty(); - } - - public String getImportName(){ - return getIdElement().map(KScrId::getText).orElse(""); - } - - public PsiReference getReference(){ - if(isWildcard()) - return null; - return getIdElement().map(id -> new KScrTypeReference(id, this)).orElse(null); - } - - public boolean importsType(JvmClass cpc){ - return importsType(cpc.getQualifiedName()); - } - - public boolean importsType(String fqTypeName){ - if(isStatic()) - return false; - return importsType(getImportName() + (isWildcard() ? ".*" : ""), fqTypeName); - } - - public static boolean importsType(String importName, String fqTypeName){ - if(importName.endsWith(".*")){ - String baseName = importName.substring(0, importName.length() - 1); - return fqTypeName.startsWith(baseName) && !fqTypeName.substring(baseName.length()).contains("."); - } - return fqTypeName.equals(importName); - } - - @Nullable - public static KScrImportStatement followToImport(JvmClass type, Collection list){ - if(type == null) - return null; - for(KScrImportStatement statement : list) - if(statement.importsType(type)) - return statement; - return null; - } - - public static boolean isQualificationRedundant(KScrClassReference reference, Collection list){ - return reference.isQualified() && followToImport(reference.resolveClass(), list) != null; - } - - // TODO: consider conflicting short names - public static boolean isQualificationRedundant(KScrClassReference reference){ - KScrFile file = reference.containingKScrlicFile(); - if(file == null) // so there's no imports - return false; - return isQualificationRedundant(reference, file.getImports()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrMethod.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrMethod.java deleted file mode 100644 index a1ba823..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrMethod.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.icons.AllIcons; -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmMethod; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiPrimitiveType; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.SearchScope; -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.antlr_generated.KScrlicLangLexer; -import org.comroid.kscr.intellij.psi.KScrCodeHolder; -import org.comroid.kscr.intellij.psi.KScrDefinitionStubElement; -import org.comroid.kscr.intellij.psi.Tokens; -import org.comroid.kscr.intellij.psi.ast.common.KScrBlock; -import org.comroid.kscr.intellij.psi.ast.common.KScrParameter; -import org.comroid.kscr.intellij.psi.ast.statements.KScrStatement; -import org.comroid.kscr.intellij.psi.ast.statements.KScrStatementWrapper; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.stubs.StubKScrMethod; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.comroid.kscr.intellij.psi.types.KScrKind; -import org.comroid.kscr.intellij.psi.types.JvmKScrlicClass; -import org.comroid.kscr.intellij.psi.types.JvmKScrlicMethod; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -public class KScrMethod extends KScrDefinitionStubElement implements KScrCodeHolder{ - - public KScrMethod(@NotNull ASTNode node){ - super(node); - } - - public KScrMethod(@NotNull StubKScrMethod method){ - super(method, StubTypes.KSCR_METHOD); - } - - public String fullyQualifiedName(){ - return containingType().fullyQualifiedName() + "::" + getName(); - } - - public KScrType containingType(){ - return getStubOrPsiParentOfType(KScrType.class); - } - - public Optional modifiers(){ - var stub = getStub(); - if(stub != null) - return Optional.ofNullable(stub.modifiers()).map(StubElement::getPsi); - return PsiUtils.childOfType(this, KScrModifierList.class); - } - - public boolean isStatic(){ - return modifiers().map(x -> x.hasModifier("static")).orElse(false); - } - - public Optional returns(){ - var stub = getStub(); - if(stub != null){ - var type = PsiUtils.createTypeReferenceFromText(this, stub.returnTypeText()); - return Optional.of((KScrTypeRef)type); - } - return PsiUtils.childOfType(this, KScrTypeRef.class); - } - - public List parameters(){ - var stub = getStub(); - if(stub != null){ - var params = stub.parameters(); - return params.stream().map(StubElement::getPsi).collect(Collectors.toList()); - } - var paramList = PsiUtils.childOfType(this, KScrParametersList.class); - return paramList.map(list -> PsiUtils.childrenOfType(list, KScrParameter.class)).orElseGet(List::of); - } - - public @Nullable JvmType returnType(){ - return returns().map(KScrTypeRef::asType).orElse(PsiPrimitiveType.NULL); - } - - public boolean overrides(JvmMethod other){ - return JvmClassUtils.overrides(JvmKScrlicMethod.of(this), other, getProject()); - } - - public @Nullable JvmMethod overriddenMethod(){ - return JvmClassUtils.findMethodInHierarchy(JvmKScrlicClass.of(containingType()), this::overrides, true); - } - - public boolean hasSemicolon(){ - var stub = getStub(); - if(stub != null) - return stub.hasSemicolon(); - - var node = getNode().getLastChildNode().getFirstChildNode(); - return node != null && node.getElementType() == Tokens.getFor(KScrlicLangLexer.SEMICOLON); - } - - public String getName(){ - var stub = getStub(); - if(stub != null) - return stub.name(); - - return super.getName(); - } - - public boolean hasModifier(String modifier){ - if(modifier.equals("abstract") && containingType().kind() == KScrKind.INTERFACE) - if(hasSemicolon()) // note that a semicolon does not mean abstract in classes - return true; - return KScrCodeHolder.super.hasModifier(modifier); - } - - public @Nullable Icon getIcon(int flags){ - // TODO: consider finality - return hasModifier("abstract") ? AllIcons.Nodes.AbstractMethod : AllIcons.Nodes.Method; - } - - public Optional body(){ - var body = getLastChild(); - if(body != null){ - if(body.getChildren().length > 1){ - // must be an arrow function - return PsiUtils.childOfType(body, KScrStatementWrapper.class) - .flatMap(KScrStatementWrapper::inner); - }else - return PsiUtils.childOfType(body, KScrBlock.class).map(KScrStatement.class::cast); - } - return Optional.empty(); - } - - public JvmMethod toJvm(){ - return JvmKScrlicMethod.of(this); - } - - public @NotNull SearchScope getUseScope(){ - if(hasModifier("private")) - return new LocalSearchScope(getContainingFile()); - return super.getUseScope(); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrModifier.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrModifier.java deleted file mode 100644 index 59f868e..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrModifier.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrModifier extends KScrAstElement{ - - public KScrModifier(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrModifierList.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrModifierList.java deleted file mode 100644 index 82e500a..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrModifierList.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import org.comroid.kscr.intellij.psi.KScrStubElement; -import org.comroid.kscr.intellij.psi.stubs.StubKScrModifierList; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.stream.Collectors; - -public class KScrModifierList extends KScrStubElement{ - - public KScrModifierList(@NotNull ASTNode node){ - super(node); - } - - public KScrModifierList(@NotNull StubKScrModifierList list){ - super(list, StubTypes.KSCR_MODIFIER_LIST); - } - - public boolean hasModifier(String modifier){ - if(getStub() != null) - return getStub().modifiers().contains(modifier); - - return PsiUtils.streamChildrenOfType(this, KScrModifier.class).anyMatch(x -> x.textMatches(modifier)); - } - - public List getModifiers(){ - if(getStub() != null) - return getStub().modifiers(); - - return PsiUtils.streamChildrenOfType(this, KScrModifier.class).map(PsiElement::getText).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrPackageStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrPackageStatement.java deleted file mode 100644 index 4ce7b01..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrPackageStatement.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrPackageStatement extends KScrAstElement{ - - public KScrPackageStatement(@NotNull ASTNode node){ - super(node); - } - - @Nullable - public String getPackageName(){ - return getId().map(PsiElement::getText).orElse(null); - } - - public @NotNull Optional getId(){ - return PsiUtils.childOfType(this, KScrId.class); - } - - // TODO: resolve against packages -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrParametersList.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrParametersList.java deleted file mode 100644 index c8a3bfe..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrParametersList.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.stubs.EmptyStub; -import org.comroid.kscr.intellij.psi.KScrStubElement; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.NotNull; - -public class KScrParametersList extends KScrStubElement>{ - - public KScrParametersList(@NotNull ASTNode node){ - super(node); - } - - public KScrParametersList(@NotNull EmptyStub stub){ - super(stub, StubTypes.KSCR_PARAMETERS_LIST); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrRawTypeRef.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrRawTypeRef.java deleted file mode 100644 index a3d81e4..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrRawTypeRef.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiReference; -import com.intellij.psi.PsiType; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.KScrIdHolder; -import org.comroid.kscr.intellij.psi.types.ClassTypeImpl; -import org.comroid.kscr.intellij.psi.utils.KScrTypeReference; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrRawTypeRef extends KScrAstElement implements KScrIdHolder{ - - public KScrRawTypeRef(@NotNull ASTNode node){ - super(node); - } - - public PsiReference getReference(){ - return getIdElement().map(id -> new KScrTypeReference(id, this)).orElse(null); - } - - @Nullable - public JvmType type(){ - switch(getText()){ - case "boolean": - return PsiType.BOOLEAN; - case "byte": - return PsiType.BYTE; - case "short": - return PsiType.SHORT; - case "char": - return PsiType.CHAR; - case "int": - return PsiType.INT; - case "long": - return PsiType.LONG; - case "float": - return PsiType.FLOAT; - case "double": - return PsiType.DOUBLE; - case "void": - return PsiType.VOID; - } - var ref = getReference(); - if(ref instanceof KScrTypeReference) - return ClassTypeImpl.of(((KScrTypeReference)ref).resolveClass()); - return null; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrTypeRef.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrTypeRef.java deleted file mode 100644 index 9c960ec..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrTypeRef.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.Tokens; -import org.comroid.kscr.intellij.psi.types.ArrayTypeImpl; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrTypeRef extends KScrAstElement{ - - public KScrTypeRef(@NotNull ASTNode node){ - super(node); - } - - @Nullable - public JvmType asType(){ - if(getNode().findChildByType(Tokens.SQ_BRACES) != null) - return PsiUtils.childOfType(this, KScrTypeRef.class) - .map(KScrTypeRef::asType) - .map(ArrayTypeImpl::of) - .orElse(null); - return PsiUtils.childOfType(this, KScrRawTypeRef.class) - .map(KScrRawTypeRef::type).orElse(null); - } - - @Nullable - public JvmClass asClass(){ - return JvmClassUtils.asClass(asType()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrTypeRefOrInferred.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrTypeRefOrInferred.java deleted file mode 100644 index d6dc184..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrTypeRefOrInferred.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class KScrTypeRefOrInferred extends KScrAstElement{ - - public KScrTypeRefOrInferred(@NotNull ASTNode node){ - super(node); - } - - public Optional ref(){ - return PsiUtils.childOfType(this, KScrTypeRef.class); - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrVariableAssignment.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrVariableAssignment.java deleted file mode 100644 index c6c4211..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/KScrVariableAssignment.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrVariableAssignment extends KScrAstElement{ - - public KScrVariableAssignment(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrBlock.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrBlock.java deleted file mode 100644 index e4be868..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrBlock.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.common; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.KScrVarScope; -import org.comroid.kscr.intellij.psi.KScrVariable; -import org.comroid.kscr.intellij.psi.ast.statements.KScrStatement; -import org.comroid.kscr.intellij.psi.ast.statements.KScrStatementWrapper; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class KScrBlock extends KScrAstElement implements KScrVarScope, KScrStatement{ - - public KScrBlock(@NotNull ASTNode node){ - super(node); - } - - public List available(){ - // all wrapped KScrVariableDefs - // plus our super-scope's variable - var defined = PsiUtils.wrappedChildrenOfType(this, KScrVariable.class); - var available = new ArrayList<>(defined); - KScrVarScope.scopeOf(this).ifPresent(scope -> available.addAll(scope.available())); - return available; - } - - public Stream streamBody(){ - return PsiUtils.streamChildrenOfType(this, KScrStatementWrapper.class) - .flatMap(x -> Stream.ofNullable(x.inner().orElse(null))); - } - - public List getBody(){ - return streamBody().collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrCall.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrCall.java deleted file mode 100644 index a4f6efc..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrCall.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.common; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.lang.jvm.JvmMethod; -import com.intellij.lang.jvm.JvmModifier; -import com.intellij.lang.jvm.JvmParameter; -import com.intellij.lang.jvm.types.JvmArrayType; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.openapi.util.NlsSafe; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.IncorrectOperationException; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.KScrIdPart; -import org.comroid.kscr.intellij.psi.ast.KScrMethod; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrExpression; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrIdExpr; -import org.comroid.kscr.intellij.psi.ast.statements.KScrStatement; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.utils.MethodUtils; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; -import java.util.stream.Collectors; - -public class KScrCall extends KScrAstElement implements PsiReference, KScrStatement{ - - public KScrCall(@NotNull ASTNode node){ - super(node); - } - - // FIXME: update to match compiler logic - - @Nullable - public JvmMethod resolveMethod(){ - class Target{ - final JvmMethod ref; - final int reach; - - Target(JvmMethod ref, int reach){ - this.ref = ref; - this.reach = reach; - } - } - // we don't necessarily have all arguments as children: - // our receiver is one level up - // pass expressions can be any number of levels up, so long as there's only passes or parenthesis - // TODO: super calls, constructors - KScrExpression on = getOn(); - List args = MethodUtils.getRealArgs(this); - String name = getCanonicalText(); - - List targets = new ArrayList<>(); - List candidates; - if(on != null){ - // TODO: consider types in brackets? - boolean isStatic = on instanceof KScrIdExpr && ((KScrIdExpr)on).resolveTarget() instanceof JvmClass; - candidates = JvmClassUtils.findAllMethodsInHierarchy(JvmClassUtils.asClass(on.type()), - m -> m.hasModifier(JvmModifier.STATIC) == isStatic, - false); - }else - candidates = getStandaloneCandidates(this); - - candidates: - for(JvmMethod x : candidates){ - // TODO: visibility - if(x.getName().equals(name)){ - List parameters = Arrays.stream(x.getParameters()).map(JvmParameter::getType).collect(Collectors.toList()); - int reach; - varargs: - if(x.isVarArgs()){ - if(args.size() < parameters.size() - 1) - break varargs; - reach = 2; - for(int i = 0; i < args.size(); i++){ - KScrExpression arg = args.get(i); - JvmType checking; - if(i + 1 < parameters.size()) - checking = parameters.get(i); - else{ - checking = parameters.get(parameters.size() - 1); - if(checking instanceof JvmArrayType){ - JvmArrayType arr = (JvmArrayType)checking; - checking = arr.getComponentType(); - }else - break varargs; // invalid varargs method - } - if(arg.isAssignableTo(checking)) - continue; - if(arg.isConvertibleTo(checking)){ - reach = 3; - continue; - } - break varargs; - } - targets.add(new Target(x, reach)); - } - if(x.getParameters().length != args.size()) - continue; - reach = 0; - for(int i = 0; i < parameters.size(); i++){ - JvmType pTarget = parameters.get(i); - // erase generics - // I'd put a to-do for generics, but this'll be rewritten anyways - pTarget = JvmClassUtils.eraseGenerics(pTarget, getProject()); - KScrExpression arg = args.get(i); - if(arg.type() != null && arg.isAssignableTo(pTarget)) - continue; - if(arg.isConvertibleTo(pTarget)){ - reach = 1; - continue; - } - continue candidates; - } - targets.add(new Target(x, reach)); - } - } - return targets - .stream() - .min(Comparator.comparingInt(x -> x.reach)) - .map(x -> x.ref) - .orElse(null); - } - - @NotNull - public static List getStandaloneCandidates(PsiElement at){ - List candidates; - var inMethod = PsiTreeUtil.getParentOfType(at, KScrMethod.class); - var inType = PsiTreeUtil.getParentOfType(at, KScrType.class); - if(inType != null) - candidates = (inMethod != null && inMethod.isStatic()) - ? inType.declaredMethods().stream().filter(x -> x.hasModifier(JvmModifier.STATIC)).collect(Collectors.toList()) - : new ArrayList<>(inType.declaredMethods()); - else - candidates = Collections.emptyList(); - return candidates; - } - - @Nullable - public KScrExpression getOn(){ - return PsiUtils.childOfType(getParent(), KScrExpression.class).orElse(null); - } - - public PsiReference getReference(){ - return getMethodName() != null ? this : null; - } - - public PsiElement getMethodName(){ - return PsiUtils.childOfType(this, KScrIdPart.class).orElse(null); - } - - public @NotNull PsiElement getElement(){ - return this; - } - - public @NotNull TextRange getRangeInElement(){ - return getMethodName().getTextRangeInParent(); - } - - public @Nullable PsiElement resolve(){ - var method = resolveMethod(); - PsiElement source = method != null ? method.getSourceElement() : null; - return source != null ? source.getNavigationElement() : null; - } - - public @NotNull @NlsSafe String getCanonicalText(){ - return getMethodName().getText(); - } - - public PsiElement handleElementRename(@NotNull String newElementName) throws IncorrectOperationException{ - getMethodName().replace(PsiUtils.createIdPartFromText(this, newElementName)); - return this; - } - - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException{ - if(element instanceof PsiNamedElement) - getMethodName().replace(PsiUtils.createIdPartFromText(this, ((PsiNamedElement)element).getName())); - else - throw new IncorrectOperationException("Can't bind a method call to something that has no name!"); - return this; - } - - public boolean isReferenceTo(@NotNull PsiElement element){ - return element == resolve(); - } - - public boolean isSoft(){ - return false; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrInitialisation.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrInitialisation.java deleted file mode 100644 index 3e8eae6..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrInitialisation.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.common; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.statements.KScrStatement; -import org.jetbrains.annotations.NotNull; - -public class KScrInitialisation extends KScrAstElement implements KScrStatement{ - - public KScrInitialisation(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrParameter.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrParameter.java deleted file mode 100644 index dadd302..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrParameter.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.common; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiType; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.SearchScope; -import com.intellij.util.PlatformIcons; -import org.comroid.kscr.intellij.antlr_generated.KScrlicLangLexer; -import org.comroid.kscr.intellij.psi.KScrDefinitionStubElement; -import org.comroid.kscr.intellij.psi.KScrVariable; -import org.comroid.kscr.intellij.psi.Tokens; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRef; -import org.comroid.kscr.intellij.psi.ast.types.KScrRecordComponents; -import org.comroid.kscr.intellij.psi.stubs.StubKScrParameter; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.comroid.kscr.intellij.psi.types.ArrayTypeImpl; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.Optional; - -public class KScrParameter extends KScrDefinitionStubElement implements KScrVariable{ - - public KScrParameter(@NotNull ASTNode node){ - super(node); - } - - public KScrParameter(@NotNull StubKScrParameter parameter){ - super(parameter, StubTypes.KSCR_PARAMETER); - } - - public String varName(){ - return getName(); - } - - public String getName(){ - var stub = getStub(); - if(stub != null) - return stub.name(); - return super.getName(); - } - - public JvmType varType(){ - var type = getTypeName() - .map(KScrTypeRef::asType) - .orElse(PsiType.NULL); - return isVarargs() ? ArrayTypeImpl.of(type) : type; - } - - public boolean hasModifier(String modifier){ - var stub = getStub(); - if(stub != null) - return stub.hasModifier(modifier); - - if(modifier.equals("final")) - return getNode().findChildByType(Tokens.getFor(KScrlicLangLexer.FINAL)) != null; - if(modifier.equals("private")) - return getParent() instanceof KScrRecordComponents; - return false; - } - - @NotNull - public Optional getTypeName(){ - var stub = getStub(); - if(stub != null){ - var type = PsiUtils.createTypeReferenceFromText(this, stub.typeText()); - return Optional.of((KScrTypeRef)type); - } - - return PsiUtils.childOfType(this, KScrTypeRef.class); - } - - public boolean isMethodParameter(){ - var stub = getStub(); - if(stub != null) - return !stub.isRecordComponent(); - - return !(getParent() instanceof KScrRecordComponents); - } - - public @NotNull SearchScope getUseScope(){ - return isMethodParameter() ? new LocalSearchScope(getContainingFile()) : super.getUseScope(); - } - - public @Nullable Icon getIcon(int flags){ - if(isMethodParameter()) - return PlatformIcons.PARAMETER_ICON; - else - return PlatformIcons.FIELD_ICON; - } - - public boolean isVarargs(){ - var stub = getStub(); - if(stub != null) - return stub.isVarargs(); - - return getNode().findChildByType(Tokens.getFor(KScrlicLangLexer.ELIPSES)) != null; - } - - public boolean isLocal(){ - return isMethodParameter(); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrVariableDef.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrVariableDef.java deleted file mode 100644 index e071f46..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/KScrVariableDef.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.common; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiPrimitiveType; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.SearchScope; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.PlatformIcons; -import org.comroid.kscr.intellij.psi.KScrDefinitionStubElement; -import org.comroid.kscr.intellij.psi.KScrModifiersHolder; -import org.comroid.kscr.intellij.psi.KScrVariable; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRef; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRefOrInferred; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrExpression; -import org.comroid.kscr.intellij.psi.ast.statements.KScrStatement; -import org.comroid.kscr.intellij.psi.ast.statements.KScrStatementWrapper; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.stubs.StubKScrField; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.comroid.kscr.intellij.psi.types.ClassTypeImpl; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.Optional; - -public class KScrVariableDef extends KScrDefinitionStubElement - implements KScrVariable, KScrModifiersHolder, KScrStatement{ - - public KScrVariableDef(@NotNull ASTNode node){ - super(node); - } - - public KScrVariableDef(@NotNull StubKScrField field){ - super(field, StubTypes.KSCR_FIELD); - } - - public String varName(){ - return getName(); - } - - public JvmType varType(){ - var stub = getStub(); - if(stub != null){ - // val is allowed here for enum fields only - String text = stub.typeText(); - KScrType container = stub.getParentStubOfType(KScrType.class); - if(text.equals("val") && container != null) - return ClassTypeImpl.of(container); - var type = PsiUtils.createTypeReferenceFromText(this, text); - return Optional.of((KScrTypeRef)type) - .map(KScrTypeRef::asType) - .orElse(PsiPrimitiveType.NULL); - } - - return PsiUtils.childOfType(this, KScrTypeRefOrInferred.class) - .flatMap(KScrTypeRefOrInferred::ref) - .map(KScrTypeRef::asType) - // for var/val - .orElseGet(() -> { - if(!isLocal()){ - if(PsiUtils.childOfType(this, KScrTypeRefOrInferred.class).map(PsiElement::getText).orElse("").equals("val")) - return ClassTypeImpl.of(PsiTreeUtil.getParentOfType(this, KScrType.class)); - return PsiPrimitiveType.NULL; - } - return PsiUtils.childOfType(this, KScrExpression.class) - .map(KScrExpression::type) - .orElse(PsiPrimitiveType.NULL); - }); - } - - public boolean hasModifier(String modifier){ - if(modifier.equals("final") || modifier.equals("static") || modifier.equals("public")){ - var stub = getStub(); // only fields have stubs - if(stub != null){ - if(stub.typeText().equals("val")) - return true; - }else{ - var type = PsiUtils.childOfType(this, KScrTypeRefOrInferred.class); - if(!isLocal() && type.isPresent() && type.get().getText().equals("val")) - return true; - } - } - return KScrModifiersHolder.super.hasModifier(modifier); - } - - public boolean isLocal(){ - if(getStub() != null) - return false; - return PsiTreeUtil.getParentOfType(this, KScrStatementWrapper.class) != null; - } - - public Optional initializer(){ - if(getStub() != null) - return Optional.empty(); - return PsiUtils.childOfType(this, KScrExpression.class); - } - - public boolean hasInferredType(){ - if(getStub() != null) - return false; - return PsiUtils.childOfType(this, KScrTypeRef.class) - .map(x -> x.getText().equals("var") || x.getText().equals("val")) - .orElse(false); - } - - public @NotNull SearchScope getUseScope(){ - return (isLocal() || hasModifier("private")) ? new LocalSearchScope(getContainingFile()) : super.getUseScope(); - } - - public @Nullable Icon getIcon(int flags){ - if(isLocal()) - return PlatformIcons.VARIABLE_ICON; - else - return PlatformIcons.FIELD_ICON; - } - - public String getName(){ - var stub = getStub(); - if(stub != null) - return stub.name(); - return super.getName(); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/package-info.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/package-info.java deleted file mode 100644 index eee90e8..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/common/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * For Psi elements that play multiple roles, e.g. - *

- KScrCall can be a statement or an expression. - *

- KScrParameter can be a method parameter or record component. - */ -package org.comroid.kscr.intellij.psi.ast.common; \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrAffixOpExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrAffixOpExpr.java deleted file mode 100644 index a673db3..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrAffixOpExpr.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrAffixOpExpr extends KScrExpression{ - - public KScrAffixOpExpr(@NotNull ASTNode node){ - super(node); - } - - public String operation(){ - if(isPostfix()) - return getLastChild().getText(); - else - return getFirstChild().getText(); - } - - public boolean isPostfix(){ - return getFirstChild() instanceof KScrExpression; - } - - public Optional expression(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } - - public @Nullable JvmType type(){ - return expression().map(KScrExpression::type).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrArrayIndexExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrArrayIndexExpr.java deleted file mode 100644 index 1c6fe53..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrArrayIndexExpr.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmArrayType; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrArrayIndexExpr extends KScrExpression{ - - public KScrArrayIndexExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional arrayExpr(){ - return PsiUtils.childOfType(this, KScrExpression.class, 0); - } - - public Optional indexExpr(){ - return PsiUtils.childOfType(this, KScrExpression.class, 1); - } - - public @Nullable JvmType type(){ - return arrayExpr() - .map(KScrExpression::type) - .map(x -> x instanceof JvmArrayType ? x : null) - .map(x-> ((JvmArrayType)x).getComponentType()) - .orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrAssignExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrAssignExpr.java deleted file mode 100644 index f7feeff..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrAssignExpr.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrAssignExpr extends KScrExpression{ - - public KScrAssignExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional expression(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } - - public @Nullable JvmType type(){ - return expression().map(KScrExpression::type).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrBinaryExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrBinaryExpr.java deleted file mode 100644 index db246e5..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrBinaryExpr.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.lang.jvm.types.JvmReferenceType; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiPrimitiveType; -import org.comroid.kscr.intellij.psi.ast.KScrBinaryOp; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Objects; -import java.util.Optional; - -import static org.comroid.kscr.intellij.psi.utils.JvmClassUtils.typeByName; - -public class KScrBinaryExpr extends KScrExpression{ - - public KScrBinaryExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional op(){ - return PsiUtils.childOfType(this, KScrBinaryOp.class); - } - - public String symbol(){ - return op().map(PsiElement::getText).orElse(""); - } - - public Optional left(){ - return PsiUtils.childOfType(this, KScrExpression.class, 0); - } - - public Optional right(){ - return PsiUtils.childOfType(this, KScrExpression.class, 1); - } - - public @Nullable JvmType type(){ - switch(symbol()){ - case "": - return null; - case "+": - // consider string addition - var lType = left().map(KScrExpression::type).orElse(null); - if(lType instanceof JvmReferenceType){ - var resolve = ((JvmReferenceType)lType).resolve(); - if(resolve instanceof JvmClass && Objects.equals(((JvmClass)resolve).getQualifiedName(), "java.lang.String")) - return typeByName("java.lang.String", getProject()); - } - var rType = right().map(KScrExpression::type).orElse(null); - if(rType instanceof JvmReferenceType){ - var resolve = ((JvmReferenceType)rType).resolve(); - if(resolve instanceof JvmClass && Objects.equals(((JvmClass)resolve).getQualifiedName(), "java.lang.String")) - return typeByName("java.lang.String", getProject()); - } - // otherwise fall-through - case "-": - case "*": - case "/": - case "%": - case "&": - case "|": - case "^": - case "<<": - case ">>": - case "<<<": - case ">>>": - return JvmClassUtils.highest( - left().map(KScrExpression::type).orElse(null), - right().map(KScrExpression::type).orElse(null)); - case "&&": - case "||": - case "==": - case "!=": - case ">=": - case "<=": - case ">": - case "<": - return PsiPrimitiveType.BOOLEAN; - case "|>": - return right().map(KScrExpression::type).orElse(null); - } - return null; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrCallExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrCallExpr.java deleted file mode 100644 index a3d2111..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrCallExpr.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmMethod; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.antlr_generated.KScrlicLangParser; -import org.comroid.kscr.intellij.psi.Tokens; -import org.comroid.kscr.intellij.psi.ast.common.KScrCall; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrCallExpr extends KScrExpression{ - - public KScrCallExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional call(){ - return PsiUtils.childOfType(this, KScrCall.class); - } - - public Optional on(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } - - public boolean isSuperCall(){ - return !PsiUtils.matchingChildren(this, k -> k.getNode().getElementType() == Tokens.getFor(KScrlicLangParser.SUPER)).isEmpty(); - } - - public @Nullable JvmType type(){ - return call().map(KScrCall::resolveMethod).map(JvmMethod::getReturnType).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrCastExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrCastExpr.java deleted file mode 100644 index 0d7d19a..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrCastExpr.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRef; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrCastExpr extends KScrExpression{ - - public KScrCastExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional castingTo(){ - return PsiUtils.childOfType(this, KScrElement.class).flatMap(x -> PsiUtils.childOfType(x, KScrTypeRef.class)); - } - - public @Nullable JvmType type(){ - return castingTo().map(KScrTypeRef::asType).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrClassLiteralExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrClassLiteralExpr.java deleted file mode 100644 index afad312..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrClassLiteralExpr.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiReference; -import org.comroid.kscr.intellij.psi.KScrIdHolder; -import org.comroid.kscr.intellij.psi.utils.KScrTypeReference; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static org.comroid.kscr.intellij.psi.utils.JvmClassUtils.typeByName; - -public class KScrClassLiteralExpr extends KScrExpression implements KScrIdHolder{ - - public KScrClassLiteralExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - return typeByName("java.lang.Class", getProject()); - } - - public PsiReference getReference(){ - return getIdElement().map(id -> new KScrTypeReference(id, this)).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrExpression.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrExpression.java deleted file mode 100644 index 13c9712..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrExpression.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiPrimitiveType; -import com.intellij.psi.impl.source.tree.CompositeElement; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; - -public class KScrExpression extends KScrAstElement{ - - public KScrExpression(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - return PsiPrimitiveType.NULL; - } - - public boolean isAssignableTo(JvmType type){ - return JvmClassUtils.isAssignableTo(type(), type); - } - - public boolean isConvertibleTo(JvmType type){ - return JvmClassUtils.isConvertibleTo(type(), type); - } - - - - private static final Field COMPOSITE_ELEMENT_WRAPPER; - - static{ - try{ - COMPOSITE_ELEMENT_WRAPPER = CompositeElement.class.getDeclaredField("myWrapper"); - }catch(NoSuchFieldException e){ - throw new RuntimeException(e); - } - } - - public void subtreeChanged(){ - super.subtreeChanged(); - // TODO: - // Since all expressions share an element type (PSI type is based on sub-trees), the PSI type doesn't get invalidated properly. - // The proper fix would be to preserve ANTLR tag information and give each tagged alternative its own element type. - // setPsi actually checks for a null value, so we set it by reflection - try{ - COMPOSITE_ELEMENT_WRAPPER.setAccessible(true); - COMPOSITE_ELEMENT_WRAPPER.set(getNode(), null); - COMPOSITE_ELEMENT_WRAPPER.setAccessible(false); - }catch(IllegalAccessException e){ - throw new RuntimeException(e); - } - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrIdExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrIdExpr.java deleted file mode 100644 index 0c3e927..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrIdExpr.java +++ /dev/null @@ -1,232 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.lang.jvm.JvmField; -import com.intellij.lang.jvm.types.JvmReferenceType; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.NlsSafe; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.*; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.IncorrectOperationException; -import org.comroid.kscr.intellij.antlr_generated.KScrlicLangLexer; -import org.comroid.kscr.intellij.psi.*; -import org.comroid.kscr.intellij.psi.ast.KScrIdPart; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.types.ClassTypeImpl; -import org.comroid.kscr.intellij.psi.types.JvmKScrlicField; -import org.comroid.kscr.intellij.psi.utils.ProjectTypeFinder; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; - -@SuppressWarnings("UnstableApiUsage") -public class KScrIdExpr extends KScrExpression implements PsiReference, KScrClassReference{ - - public KScrIdExpr(@NotNull ASTNode node){ - super(node); - } - - /* - Can resolve to: - - a local variable (int x = 0; int y = x;) - - a type (KScrExpression) - - a field (KScrExpression.COMPOSITE_ELEMENT_WRAPPER) - - a package (org.comroid.kscr.intellij.psi.elements.KScrExpression) - */ - - public String id(){ - return PsiUtils.childOfType(this, KScrIdPart.class).map(PsiElement::getText).orElse(""); - } - - @Nullable - public KScrExpression on(){ - return PsiUtils.childOfType(this, KScrExpression.class).orElse(null); - } - - @Nullable - public PsiElement dot(){ - return Arrays.stream(getChildren()) - .filter(x -> x.getNode().getElementType() == Tokens.getFor(KScrlicLangLexer.DOT)) - .findFirst() - .orElse(null); - } - - // [JvmClass | PsiPackage | KScrVariable | JvmField | String | null] - public Object resolveTarget(){ - var on = on(); - String id = id(); - if(on == null){ - var scope = KScrVarScope.scopeOf(this); - if(scope.isPresent()){ - var available = scope.get().available(); - var byName = available.stream().filter(x -> x.varName().equals(id)).findFirst(); - if(byName.isPresent()) - return byName.get(); - } - KScrType inside = PsiTreeUtil.getParentOfType(this, KScrType.class); - var inMethod = PsiTreeUtil.getParentOfType(this, KScrCodeHolder.class); - if(inside != null){ - var field = inside.fields().stream() - .filter(x -> x.varName().equals(id)) - .filter(x -> inMethod == null || !inMethod.isStatic() || x.hasModifier("static")) - .findFirst() - .orElse(null); - if(field != null) - return field; - } - return resolveById(id, getContainingFile(), getProject()); - }else{ - Object ret = null; - if(on instanceof KScrIdExpr){ - var res = ((KScrIdExpr)on).resolveTarget(); - if(res == null) - return null; - String narrowId = id; - if(res instanceof String) - narrowId = res + "." + narrowId; - if(res instanceof PsiPackage) - narrowId = ((PsiPackage)res).getQualifiedName() + "." + narrowId; - ret = resolveById(narrowId, getContainingFile(), getProject()); - } - JvmType type = on.type(); - if(!(type instanceof JvmReferenceType)) - return ret; - var res = ((JvmReferenceType)type).resolve(); - if(!(res instanceof JvmClass)) - return ret; - return Arrays.stream(((JvmClass)res).getFields()) - .filter(x -> x.getName().equals(id)) - .findFirst() - .map(Object.class::cast) - .orElse(ret); - } - } - - @NotNull - private static Object resolveById(String id, PsiFile file, Project project){ - if(file instanceof KScrFile){ - var type = ProjectTypeFinder.firstType(project, ProjectTypeFinder.getCandidates((KScrFile)file, id)); - if(type != null) - return type; - } - var psiPackage = JavaPsiFacade.getInstance(project).findPackage(id); - if(psiPackage != null) - return psiPackage; - return id; - } - - public @Nullable JvmType type(){ - var res = resolveTarget(); - if(res instanceof JvmClass) - return ClassTypeImpl.of((JvmClass)res); - if(res instanceof KScrVariable) - return ((KScrVariable)res).varType(); - if(res instanceof JvmField) - return ((JvmField)res).getType(); - return null; - } - - public PsiReference getReference(){ - return this; - } - - public @NotNull PsiElement getElement(){ - return this; - } - - public @NotNull TextRange getRangeInElement(){ - return PsiUtils.childOfType(this, KScrIdPart.class).map(PsiElement::getTextRangeInParent).orElse(getTextRangeInParent()); - } - - public @Nullable PsiElement resolve(){ - var res = resolveTarget(); - if(res instanceof JvmClass) - return ((JvmClass)res).getSourceElement(); - if(res instanceof PsiElement) - return (PsiElement)res; - if(res instanceof JvmKScrlicField) - return ((JvmKScrlicField)res).getSourceElement(); - return null; - } - - public @NotNull @NlsSafe String getCanonicalText(){ - var res = resolveTarget(); - if(res instanceof JvmClass){ - var qName = ((JvmClass)res).getQualifiedName(); - return qName != null ? qName : ""; - } - if(res instanceof PsiPackage) - return ((PsiPackage)res).getQualifiedName(); - if(res instanceof KScrVariable) - return ((KScrVariable)res).varName(); - return ""; - } - - public PsiElement handleElementRename(@NotNull String name) throws IncorrectOperationException{ - PsiUtils.childOfType(this, KScrIdPart.class).ifPresent(id -> id.replace(PsiUtils.createIdPartFromText(this, name))); - return this; - } - - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException{ - if(element instanceof PsiNamedElement){ - PsiUtils.childOfType(this, KScrIdPart.class).ifPresent(id -> id.replace(PsiUtils.createIdPartFromText(this, ((PsiNamedElement)element).getName()))); - return this; - } - throw new IncorrectOperationException("Can't bind an ID expression to something that has no name!"); - } - - public boolean isReferenceTo(@NotNull PsiElement element){ - var res = resolveTarget(); - if(res instanceof JvmClass) - return ((JvmClass)res).getSourceElement() == element; - if(res instanceof PsiElement) - return res == element; - if(res instanceof JvmField) - return ((JvmField)res).getSourceElement() == element; - return false; - } - - public boolean isSoft(){ - return false; - } - - public @Nullable JvmClass resolveClass(){ - var ref = resolveTarget(); - if(ref instanceof JvmClass) - return (JvmClass)ref; - return null; - } - - public boolean isQualified(){ - return on() != null; - } - - public @Nullable KScrFile containingKScrlicFile(){ - var file = getContainingFile(); - return file instanceof KScrFile ? (KScrFile)file : null; - } - - public void shortenReference(){ - var on = on(); - if(on != null) - on.delete(); - var dot = dot(); - if(dot != null) - dot.delete(); - } - - public @Nullable TextRange getQualifierRange(){ - var on = on(); - if(on == null) - return null; - var dot = dot(); - if(dot == null) - return on.getTextRangeInParent(); - return on.getTextRangeInParent().union(dot.getTextRangeInParent()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrInitialisationExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrInitialisationExpr.java deleted file mode 100644 index d024723..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrInitialisationExpr.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRef; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrInitialisationExpr extends KScrExpression{ - - public KScrInitialisationExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional initialising(){ - return PsiUtils.childOfType(this, KScrElement.class).flatMap(x -> PsiUtils.childOfType(x, KScrTypeRef.class)); - } - - public @Nullable JvmType type(){ - return initialising().map(KScrTypeRef::asType).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrInstanceOfExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrInstanceOfExpr.java deleted file mode 100644 index 7c9c86c..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrInstanceOfExpr.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrInstanceOfExpr extends KScrExpression{ - - public KScrInstanceOfExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - return PsiType.BOOLEAN; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrLiteralExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrLiteralExpr.java deleted file mode 100644 index 5f34917..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrLiteralExpr.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiType; -import org.comroid.kscr.intellij.psi.Tokens; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrLiteralExpr extends KScrExpression{ - - public KScrLiteralExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - if(getNode().findChildByType(Tokens.TOK_NULL) != null) - return PsiType.NULL; - if(getNode().findChildByType(Tokens.TOK_BOOLLIT) != null) - return PsiType.BOOLEAN; - // TODO: implicit conversions - if(getNode().findChildByType(Tokens.TOK_INTLIT) != null) - return PsiType.INT; - if(getNode().findChildByType(Tokens.TOK_DECLIT) != null) - return PsiType.DOUBLE; - return null; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrNewArrayExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrNewArrayExpr.java deleted file mode 100644 index 064c5b0..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrNewArrayExpr.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRef; -import org.comroid.kscr.intellij.psi.types.ArrayTypeImpl; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrNewArrayExpr extends KScrExpression{ - - public KScrNewArrayExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional elementType(){ - return PsiUtils.childOfType(this, KScrElement.class).flatMap(x -> PsiUtils.childOfType(x, KScrTypeRef.class)); - } - - public @Nullable JvmType type(){ - return elementType().map(KScrTypeRef::asType).map(ArrayTypeImpl::of).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrNewListArrayExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrNewListArrayExpr.java deleted file mode 100644 index 1727b48..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrNewListArrayExpr.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRef; -import org.comroid.kscr.intellij.psi.types.ArrayTypeImpl; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrNewListArrayExpr extends KScrExpression{ - - public KScrNewListArrayExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional elementType(){ - return PsiUtils.childOfType(this, KScrElement.class).flatMap(x -> PsiUtils.childOfType(x, KScrTypeRef.class)); - } - - public @Nullable JvmType type(){ - return elementType().map(KScrTypeRef::asType).map(ArrayTypeImpl::of).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrParenthesisedExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrParenthesisedExpr.java deleted file mode 100644 index b9ba3dd..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrParenthesisedExpr.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrParenthesisedExpr extends KScrExpression{ - - public KScrParenthesisedExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - var parenthesised = PsiUtils.childOfType(this, KScrExpression.class); - return parenthesised.map(KScrExpression::type).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrStringLiteralExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrStringLiteralExpr.java deleted file mode 100644 index 100afdb..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrStringLiteralExpr.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static org.comroid.kscr.intellij.psi.utils.JvmClassUtils.typeByName; - -public class KScrStringLiteralExpr extends KScrExpression{ - - public KScrStringLiteralExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - return typeByName("java.lang.String", getProject()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrThisExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrThisExpr.java deleted file mode 100644 index 0279626..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/expressions/KScrThisExpr.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.util.PsiTreeUtil; -import org.comroid.kscr.intellij.psi.KScrCodeHolder; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrThisExpr extends KScrExpression{ - - public KScrThisExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - var method = PsiTreeUtil.getParentOfType(this, KScrCodeHolder.class); - if(method == null || method.isStatic()) - return null; - return JvmClassUtils.asType(method.containingType()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrAssertStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrAssertStatement.java deleted file mode 100644 index 96647fe..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrAssertStatement.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrExpression; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class KScrAssertStatement extends KScrAstElement implements KScrStatement{ - - public KScrAssertStatement(@NotNull ASTNode node){ - super(node); - } - - public Optional condition(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrBreakStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrBreakStatement.java deleted file mode 100644 index 5331799..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrBreakStatement.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrBreakStatement extends KScrAstElement implements KScrStatement{ - - public KScrBreakStatement(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrCatchBlock.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrCatchBlock.java deleted file mode 100644 index 8b40802..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrCatchBlock.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiType; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.SearchScope; -import com.intellij.util.PlatformIcons; -import org.comroid.kscr.intellij.psi.KScrDefinitionAstElement; -import org.comroid.kscr.intellij.psi.KScrVarScope; -import org.comroid.kscr.intellij.psi.KScrVariable; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRef; -import org.comroid.kscr.intellij.psi.ast.common.KScrBlock; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -// Introduces the catch variable into scope -// Not picked up by KScrBlock - not a KScrStatement, part of KScrTryCatchStatement -public class KScrCatchBlock extends KScrDefinitionAstElement implements KScrVariable, KScrVarScope{ - - public KScrCatchBlock(@NotNull ASTNode node){ - super(node); - } - - public Optional body(){ - return PsiUtils.childOfType(this, KScrBlock.class).map(x -> x); - } - - public String varName(){ - return getName(); - } - - public JvmType varType(){ - return PsiUtils.childOfType(this, KScrTypeRef.class) - .map(KScrTypeRef::asType) - .orElse(PsiType.NULL); - } - - public boolean hasModifier(String modifier){ - return false; - } - - public boolean isLocal(){ - return true; - } - - public List available(){ - List superScope = new ArrayList<>(KScrVarScope.scopeOf(this).map(KScrVarScope::available).orElse(List.of())); - superScope.add(this); - return superScope; - } - - public @Nullable Icon getIcon(int flags){ - return PlatformIcons.VARIABLE_ICON; - } - - public @NotNull SearchScope getUseScope(){ - return new LocalSearchScope(getContainingFile()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrConstructorCallStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrConstructorCallStatement.java deleted file mode 100644 index d03f699..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrConstructorCallStatement.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrConstructorCallStatement extends KScrAstElement implements KScrStatement{ - - public KScrConstructorCallStatement(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrContinueStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrContinueStatement.java deleted file mode 100644 index 8ff1b8e..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrContinueStatement.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrContinueStatement extends KScrAstElement implements KScrStatement{ - - public KScrContinueStatement(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrDoWhileStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrDoWhileStatement.java deleted file mode 100644 index 443cd2b..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrDoWhileStatement.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrExpression; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class KScrDoWhileStatement extends KScrAstElement implements KScrStatement{ - - public KScrDoWhileStatement(@NotNull ASTNode node){ - super(node); - } - - public Optional body(){ - return PsiUtils.childOfType(this, KScrStatement.class); - } - - public Optional condition(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrElseClause.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrElseClause.java deleted file mode 100644 index 248fa2d..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrElseClause.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -// not a KScrStatement, part of KScrIfStatement -public class KScrElseClause extends KScrAstElement{ - - public KScrElseClause(@NotNull ASTNode node){ - super(node); - } - - public Optional body(){ - return PsiUtils.childOfType(this, KScrStatementWrapper.class) - .flatMap(KScrStatementWrapper::inner); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrFinallyBlock.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrFinallyBlock.java deleted file mode 100644 index 4f79f34..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrFinallyBlock.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.common.KScrBlock; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -// not a KScrStatement, part of KScrTryCatchStatement -public class KScrFinallyBlock extends KScrAstElement{ - - public KScrFinallyBlock(@NotNull ASTNode node){ - super(node); - } - - public Optional body(){ - return PsiUtils.childOfType(this, KScrBlock.class).map(x -> x); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrForStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrForStatement.java deleted file mode 100644 index ed61581..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrForStatement.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.KScrVarScope; -import org.comroid.kscr.intellij.psi.KScrVariable; -import org.comroid.kscr.intellij.psi.ast.common.KScrVariableDef; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrExpression; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -public class KScrForStatement extends KScrAstElement implements KScrStatement, KScrVarScope{ - - public KScrForStatement(@NotNull ASTNode node){ - super(node); - } - - public Optional start(){ - return PsiUtils.childOfType(this, KScrStatementWrapper.class, 0); - } - - public Optional condition(){ - return PsiUtils.childOfType(this, KScrExpression.class, 0); - } - - public Optional updater(){ - return PsiUtils.childOfType(this, KScrStatementWrapper.class, 1); - } - - public Optional body(){ - return PsiUtils.childOfType(this, KScrStatementWrapper.class, 2); - } - - public List available(){ - List superScope = new ArrayList<>(KScrVarScope.scopeOf(this).map(KScrVarScope::available).orElse(List.of())); - // add the index variable (or whatever) - start().flatMap(KScrStatementWrapper::inner).ifPresent(s -> { - if(s instanceof KScrVariableDef) - superScope.add((KScrVariable)s); - }); - return superScope; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrForeachStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrForeachStatement.java deleted file mode 100644 index 2ec523c..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrForeachStatement.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.lang.jvm.JvmClassKind; -import com.intellij.lang.jvm.types.JvmArrayType; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.search.LocalSearchScope; -import com.intellij.psi.search.SearchScope; -import com.intellij.util.PlatformIcons; -import org.comroid.kscr.intellij.antlr_generated.KScrlicLangLexer; -import org.comroid.kscr.intellij.psi.KScrDefinitionAstElement; -import org.comroid.kscr.intellij.psi.KScrVariable; -import org.comroid.kscr.intellij.psi.Tokens; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRef; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRefOrInferred; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrExpression; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrIdExpr; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.Optional; - -import static org.comroid.kscr.intellij.psi.utils.JvmClassUtils.typeByName; - -// Introduces the for-each variable into scope -// Picked up by KScrBlock -public class KScrForeachStatement extends KScrDefinitionAstElement implements KScrVariable, KScrStatement{ - - public KScrForeachStatement(@NotNull ASTNode node){ - super(node); - } - - public String varName(){ - return getName(); - } - - public JvmType varType(){ - // TODO: once the compiler supports Iterables that aren't Objects, update to match - return PsiUtils.childOfType(this, KScrTypeRefOrInferred.class) - .flatMap(KScrTypeRefOrInferred::ref) - .map(KScrTypeRef::asType) - // for var/val - .orElseGet(() -> { - Optional expression = PsiUtils.childOfType(this, KScrExpression.class); - if(expression.isPresent()){ - KScrExpression expr = expression.get(); - if(expr instanceof KScrIdExpr){ - var target = ((KScrIdExpr)expr).resolveTarget(); - if(target instanceof JvmClass && ((JvmClass)target).getClassKind() == JvmClassKind.ENUM) - return expr.type(); - } - var baseType = expr.type(); - if(baseType instanceof JvmArrayType) - return ((JvmArrayType)baseType).getComponentType(); - } - return typeByName("java.lang.Object", getProject()); - }); - } - - public boolean hasModifier(String modifier){ - if(!modifier.equals("final")) - return false; - return getNode().findChildByType(Tokens.getFor(KScrlicLangLexer.FINAL)) != null; - } - - public boolean isLocal(){ - return true; - } - - public @NotNull SearchScope getUseScope(){ - return new LocalSearchScope(getContainingFile()); - } - - public Optional iterator(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } - - public Optional body(){ - return PsiUtils.childOfType(this, KScrStatement.class); - } - - public @Nullable Icon getIcon(int flags){ - return PlatformIcons.VARIABLE_ICON; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrIfStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrIfStatement.java deleted file mode 100644 index 802234e..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrIfStatement.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class KScrIfStatement extends KScrAstElement implements KScrStatement{ - - public KScrIfStatement(@NotNull ASTNode node){ - super(node); - } - - public Optional body(){ - return PsiUtils.childOfType(this, KScrStatementWrapper.class) - .flatMap(KScrStatementWrapper::inner); - } - - public Optional elseClause(){ - return PsiUtils.childOfType(this, KScrElseClause.class); - } - - public Optional elseBody(){ - return elseClause().flatMap(KScrElseClause::body); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrReturnStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrReturnStatement.java deleted file mode 100644 index f62c3f9..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrReturnStatement.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrExpression; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrReturnStatement extends KScrAstElement implements KScrStatement{ - - public KScrReturnStatement(@NotNull ASTNode node){ - super(node); - } - - public Optional returns(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } - - @Nullable("Null means no expression") - public JvmType returnType(){ - return returns().map(KScrExpression::type).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrStatement.java deleted file mode 100644 index 0b56a56..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrStatement.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.psi.PsiElement; - -public interface KScrStatement extends PsiElement{ - - -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrStatementWrapper.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrStatementWrapper.java deleted file mode 100644 index e453584..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrStatementWrapper.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class KScrStatementWrapper extends KScrAstElement{ - - public KScrStatementWrapper(@NotNull ASTNode node){ - super(node); - } - - public Optional inner(){ - return PsiUtils.childOfType(this, KScrStatement.class); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrSwitchStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrSwitchStatement.java deleted file mode 100644 index 1cd6686..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrSwitchStatement.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrSwitchStatement extends KScrAstElement implements KScrStatement{ - - public KScrSwitchStatement(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrThrowStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrThrowStatement.java deleted file mode 100644 index 1a1b150..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrThrowStatement.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrExpression; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class KScrThrowStatement extends KScrAstElement implements KScrStatement{ - - public KScrThrowStatement(@NotNull ASTNode node){ - super(node); - } - - public Optional returns(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrTryCatchStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrTryCatchStatement.java deleted file mode 100644 index 75d6918..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrTryCatchStatement.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.common.KScrBlock; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class KScrTryCatchStatement extends KScrAstElement implements KScrStatement{ - - public KScrTryCatchStatement(@NotNull ASTNode node){ - super(node); - } - - public Optional body(){ - return PsiUtils.childOfType(this, KScrBlock.class).map(x -> x); // lol - } - - public Stream streamCatchBlocks(){ - return PsiUtils.streamChildrenOfType(this, KScrCatchBlock.class); - } - - public List getCatchBlocks(){ - return PsiUtils.childrenOfType(this, KScrCatchBlock.class); - } - - public Stream streamCatchBodies(){ - return streamCatchBlocks() - .map(KScrCatchBlock::body) - .flatMap(x -> Stream.ofNullable(x.orElse(null))); - } - - public List getCatchBodies(){ - return streamCatchBodies().collect(Collectors.toList()); - } - - public Optional finallyBlock(){ - return PsiUtils.childOfType(this, KScrFinallyBlock.class); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrVarAssignStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrVarAssignStatement.java deleted file mode 100644 index 53143a0..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrVarAssignStatement.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrVarAssignStatement extends KScrAstElement implements KScrStatement{ - - public KScrVarAssignStatement(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrVarIncrementStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrVarIncrementStatement.java deleted file mode 100644 index 162c3c1..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrVarIncrementStatement.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.jetbrains.annotations.NotNull; - -public class KScrVarIncrementStatement extends KScrAstElement implements KScrStatement{ - - public KScrVarIncrementStatement(@NotNull ASTNode node){ - super(node); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrWhileStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrWhileStatement.java deleted file mode 100644 index b35ed77..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrWhileStatement.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrExpression; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class KScrWhileStatement extends KScrAstElement implements KScrStatement{ - - public KScrWhileStatement(@NotNull ASTNode node){ - super(node); - } - - public Optional condition(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } - - public Optional body(){ - return PsiUtils.childOfType(this, KScrStatement.class); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrYieldStatement.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrYieldStatement.java deleted file mode 100644 index 73f163a..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/statements/KScrYieldStatement.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.statements; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrAstElement; -import org.comroid.kscr.intellij.psi.ast.expressions.KScrExpression; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class KScrYieldStatement extends KScrAstElement implements KScrStatement{ - - public KScrYieldStatement(@NotNull ASTNode node){ - super(node); - } - - public Optional yields(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrClassList.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrClassList.java deleted file mode 100644 index c00447d..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrClassList.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.types; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.psi.PsiElement; -import com.intellij.psi.stubs.IStubElementType; -import org.comroid.kscr.intellij.psi.KScrStubElement; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRef; -import org.comroid.kscr.intellij.psi.stubs.StubKScrClassList; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -public abstract class KScrClassList> extends KScrStubElement>{ - - public KScrClassList(@NotNull ASTNode node){ - super(node); - } - - public KScrClassList(@NotNull StubKScrClassList list, @NotNull IStubElementType nodeType){ - super(list, nodeType); - } - - @NotNull - public List elements(){ - return PsiUtils - .streamChildrenOfType(this, KScrTypeRef.class) - .map(KScrTypeRef::asClass) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - } - - @NotNull - public List elementNames(){ - var stub = getStub(); - if(stub != null) - return stub.elementFqNames(); - - return PsiUtils - .streamChildrenOfType(this, KScrTypeRef.class) - .map(PsiElement::getText) - .collect(Collectors.toList()); - } - - @NotNull - public Optional first(){ - return PsiUtils - .streamChildrenOfType(this, KScrTypeRef.class) - .map(KScrTypeRef::asClass) - .filter(Objects::nonNull) - .findFirst(); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrExtendsClause.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrExtendsClause.java deleted file mode 100644 index db2a8de..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrExtendsClause.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.types; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.stubs.StubKScrClassList; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.NotNull; - -public class KScrExtendsClause extends KScrClassList{ - - public KScrExtendsClause(@NotNull ASTNode node){ - super(node); - } - - public KScrExtendsClause(@NotNull StubKScrClassList list){ - super(list, StubTypes.KSCR_EXTENDS_LIST); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrImplementsClause.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrImplementsClause.java deleted file mode 100644 index 4a543f1..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrImplementsClause.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.types; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.stubs.StubKScrClassList; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.NotNull; - -public class KScrImplementsClause extends KScrClassList{ - - public KScrImplementsClause(@NotNull ASTNode node){ - super(node); - } - - public KScrImplementsClause(@NotNull StubKScrClassList list){ - super(list, StubTypes.KSCR_IMPLEMENTS_LIST); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrMemberWrapper.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrMemberWrapper.java deleted file mode 100644 index f8b70e0..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrMemberWrapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.types; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrStubElement; -import org.comroid.kscr.intellij.psi.stubs.StubKScrMemberWrapper; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.NotNull; - -public class KScrMemberWrapper extends KScrStubElement{ - - public KScrMemberWrapper(@NotNull ASTNode node){ - super(node); - } - - public KScrMemberWrapper(@NotNull StubKScrMemberWrapper stub){ - super(stub, StubTypes.KSCR_MEMBER); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrPermitsClause.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrPermitsClause.java deleted file mode 100644 index 791ac10..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrPermitsClause.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.types; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.stubs.StubKScrClassList; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.NotNull; - -public class KScrPermitsClause extends KScrClassList{ - - public KScrPermitsClause(@NotNull ASTNode node){ - super(node); - } - - public KScrPermitsClause(@NotNull StubKScrClassList list){ - super(list, StubTypes.KSCR_PERMITS_LIST); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrRecordComponents.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrRecordComponents.java deleted file mode 100644 index 65a8bcb..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrRecordComponents.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.types; - -import com.intellij.lang.ASTNode; -import org.comroid.kscr.intellij.psi.KScrStubElement; -import org.comroid.kscr.intellij.psi.ast.common.KScrParameter; -import org.comroid.kscr.intellij.psi.stubs.StubKScrRecordComponents; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class KScrRecordComponents extends KScrStubElement{ - - public KScrRecordComponents(@NotNull ASTNode node){ - super(node); - } - - public KScrRecordComponents(@NotNull StubKScrRecordComponents components){ - super(components, StubTypes.KSCR_RECORD_COMPONENTS); - } - - public List components(){ - return PsiUtils.childrenOfType(this, KScrParameter.class); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrType.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrType.java deleted file mode 100644 index 8df7653..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/ast/types/KScrType.java +++ /dev/null @@ -1,235 +0,0 @@ -package org.comroid.kscr.intellij.psi.ast.types; - -import com.intellij.icons.AllIcons; -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.lang.jvm.JvmMethod; -import com.intellij.openapi.project.DumbService; -import com.intellij.psi.CommonClassNames; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.impl.source.tree.SharedImplUtil; -import com.intellij.psi.stubs.IStubElementType; -import com.intellij.psi.stubs.StubElement; -import com.intellij.ui.LayeredIcon; -import com.intellij.util.IncorrectOperationException; -import com.intellij.util.PlatformIcons; -import com.intellij.util.ui.EDT; -import org.comroid.kscr.intellij.KScrlicIcons; -import org.comroid.kscr.intellij.antlr_generated.KScrlicLangParser; -import org.comroid.kscr.intellij.asJava.AsPsiUtil; -import org.comroid.kscr.intellij.psi.*; -import org.comroid.kscr.intellij.psi.ast.KScrFileWrapper; -import org.comroid.kscr.intellij.psi.ast.KScrMethod; -import org.comroid.kscr.intellij.psi.ast.KScrPackageStatement; -import org.comroid.kscr.intellij.psi.ast.common.KScrParameter; -import org.comroid.kscr.intellij.psi.ast.common.KScrVariableDef; -import org.comroid.kscr.intellij.psi.stubs.*; -import org.comroid.kscr.intellij.psi.types.KScrKind; -import org.comroid.kscr.intellij.psi.types.JvmKScrlicClass; -import org.comroid.kscr.intellij.psi.types.JvmKScrlicMethod; -import org.comroid.kscr.intellij.psi.utils.KScrModifiersHolder; -import org.comroid.kscr.intellij.psi.utils.ProjectTypeFinder; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class KScrType extends KScrDefinitionStubElement implements KScrModifiersHolder { - - public KScrType(@NotNull ASTNode node){ - super(node); - } - - public KScrType(@NotNull StubKScrType stub){ - super(stub, StubTypes.KSCR_TYPE); - } - - public boolean isTopLevelType(){ - return getParent() instanceof KScrFileWrapper; - } - - public String getPackageName(){ - if(getContainingFile() instanceof KScrFile){ - KScrFile file = (KScrFile)getContainingFile(); - return file.getPackage().map(KScrPackageStatement::getPackageName).orElse(""); - } - return ""; - } - - public @NotNull String fullyQualifiedName(){ - var stub = getStub(); - if(stub != null) - return stub.fullyQualifiedName(); - - // avoids PsiInvalidElementAccessException by skipping the stub-based implementation that doesn't work here anyways - PsiFile file = SharedImplUtil.getContainingFile(getNode()); - if(file instanceof KScrFile) - return ((KScrFile)file).getPackage().map(k -> k.getPackageName() + ".").orElse("") + super.fullyQualifiedName(); - return super.fullyQualifiedName(); - } - - public @NotNull KScrKind kind(){ - var stub = getStub(); - if(stub != null) - return stub.kind(); - - var objType = getNode().findChildByType(Tokens.getRuleFor(KScrlicLangParser.RULE_objectType)); - if(objType != null){ - if(objType.findChildByType(Tokens.TOK_CLASS) != null) - return KScrKind.CLASS; - if(objType.findChildByType(Tokens.TOK_INTERFACE) != null) - return KScrKind.INTERFACE; - if(objType.findChildByType(Tokens.TOK_ANNOTATION) != null || objType.findChildByType(Tokens.TOK_AT) != null) - return KScrKind.ANNOTATION; - if(objType.findChildByType(Tokens.TOK_ENUM) != null) - return KScrKind.ENUM; - if(objType.findChildByType(Tokens.TOK_RECORD) != null) - return KScrKind.RECORD; - if(objType.findChildByType(Tokens.TOK_SINGLE) != null) - return KScrKind.SINGLE; - } - return KScrKind.CLASS; - } - - public boolean isFinal(){ - return hasModifier("final"); - } - - @SuppressWarnings("unchecked") - public @NotNull List declaredMethods(){ - var stub = getStub(); - if(stub != null){ - ArrayList methods = stub.getChildrenStubs().stream() - .filter(StubKScrMemberWrapper.class::isInstance) - .flatMap(x -> (Stream>)x.getChildrenStubs().stream()) - .filter(StubKScrMethod.class::isInstance) - .map(StubKScrMethod.class::cast) - .map(StubElement::getPsi) - .map(JvmKScrlicMethod::of) - .collect(Collectors.toCollection(ArrayList::new)); - var recComponents = stub.findChildStubByType(StubTypes.KSCR_RECORD_COMPONENTS); - if(recComponents != null){ - var comps = recComponents.components(); - for(StubKScrParameter comp : comps) - if(methods.stream().noneMatch(m -> m.getParameters().length == 0 && Objects.equals(m.getName(), comp.name()))) - methods.add(AsPsiUtil.recordAccessorMethod(comp.getPsi())); - } - return methods; - } - - List methods - = PsiUtils.wrappedChildrenOfType(this, KScrMethod.class).stream().map(JvmKScrlicMethod::of).collect(Collectors.toList()); - List components = PsiUtils.childOfType(this, KScrRecordComponents.class) - .map(KScrRecordComponents::components) - .orElse(List.of()); - for(KScrParameter comp : components) - if(methods.stream().noneMatch(m -> m.getParameters().length == 0 && Objects.equals(m.getName(), comp.varName()))) - methods.add(AsPsiUtil.recordAccessorMethod(comp)); - return methods; - } - - public @NotNull List fields(){ - List defs = new ArrayList<>(PsiUtils.wrappedChildrenOfType(this, KScrVariableDef.class)); - PsiUtils.childOfType(this, KScrRecordComponents.class).ifPresent(rc -> defs.addAll(rc.components())); - return defs; - } - - public PsiElement setName(@NotNull String name) throws IncorrectOperationException{ - // also change the file name if top level - if(isTopLevelType()) - getContainingFile().setName(name + ".kscr"); - return super.setName(name); - } - - public List getMembers(){ - return PsiUtils.childrenOfType(this, KScrMemberWrapper.class); - } - - public @NotNull String name(){ - return getName(); - } - - public @Nullable Icon getIcon(int flags){ - var result = KScrlicIcons.KScr_FILE; - var objType = getNode().findChildByType(Tokens.getRuleFor(KScrlicLangParser.RULE_objectType)); - if(objType != null){ - if(objType.findChildByType(Tokens.TOK_CLASS) != null) - result = PlatformIcons.CLASS_ICON; - else if(objType.findChildByType(Tokens.TOK_INTERFACE) != null) - result = PlatformIcons.INTERFACE_ICON; - else if(objType.findChildByType(Tokens.TOK_ANNOTATION) != null || objType.findChildByType(Tokens.TOK_AT) != null) - result = PlatformIcons.ANNOTATION_TYPE_ICON; - else if(objType.findChildByType(Tokens.TOK_ENUM) != null) - result = PlatformIcons.ENUM_ICON; - else if(objType.findChildByType(Tokens.TOK_RECORD) != null) - result = PlatformIcons.RECORD_ICON; - else if(objType.findChildByType(Tokens.TOK_SINGLE) != null) - result = AllIcons.Nodes.Static; - } - if(!DumbService.isDumb(getProject()) - && !EDT.isCurrentThreadEdt() // TODO: can this can be refactored to not require slow operations? - && JvmClassUtils.hasMainMethod(JvmKScrlicClass.of(this))) - result = new LayeredIcon(result, AllIcons.Nodes.RunnableMark); - return new LayeredIcon(result, KScrlicIcons.KScr_DECORATION); - } - - @Nullable - public JvmClass getSuperType(){ - if(kind() == KScrKind.INTERFACE) - return null; - if(kind() == KScrKind.RECORD) - return JvmClassUtils.classByName(CommonClassNames.JAVA_LANG_RECORD, getProject()); - if(kind() == KScrKind.ENUM) - return JvmClassUtils.classByName(CommonClassNames.JAVA_LANG_ENUM, getProject()); - - var object = JvmClassUtils.classByName(CommonClassNames.JAVA_LANG_OBJECT, getProject()); - - var stub = getStub(); - if(stub != null){ - var extList = stub.extendsList(); - if(extList != null){ - var names = extList.elementFqNames(); - if(names.size() > 0) - return ProjectTypeFinder.getByName(getProject(), names.get(0), this); - else - return object; - } - } - - var exts = PsiUtils.childOfType(this, KScrExtendsClause.class); - return exts.flatMap(KScrClassList::first).orElse(object); - } - - @NotNull - public List getInterfaces(){ - var stub = getStub(); - if(stub != null){ - var cl = (kind() == KScrKind.INTERFACE) ? stub.extendsList() : stub.implementsList(); - if(cl != null){ - var names = cl.elementFqNames(); - return names.stream() - .map(x -> ProjectTypeFinder.getByName(getProject(), x, this)) - .collect(Collectors.toList()); - } - } - - Optional> list; - if(kind() == KScrKind.INTERFACE) - list = PsiUtils.childOfType(this, KScrExtendsClause.class); - else - list = PsiUtils.childOfType(this, KScrImplementsClause.class); - return list.map(KScrClassList::elements).orElse(List.of()); - } - - public IStubElementType getElementType(){ - return StubTypes.KSCR_TYPE; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrAffixOpExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrAffixOpExpr.java deleted file mode 100644 index a05882c..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrAffixOpExpr.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrAffixOpExpr extends KScrExpression{ - - public KScrAffixOpExpr(@NotNull ASTNode node){ - super(node); - } - - public String operation(){ - if(isPostfix()) - return getLastChild().getText(); - else - return getFirstChild().getText(); - } - - public boolean isPostfix(){ - return getFirstChild() instanceof KScrExpression; - } - - public Optional expression(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } - - public @Nullable JvmType type(){ - return expression().map(KScrExpression::type).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrArrayIndexExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrArrayIndexExpr.java deleted file mode 100644 index eaea960..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrArrayIndexExpr.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmArrayType; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrArrayIndexExpr extends KScrExpression{ - - public KScrArrayIndexExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional arrayExpr(){ - return PsiUtils.childOfType(this, KScrExpression.class, 0); - } - - public Optional indexExpr(){ - return PsiUtils.childOfType(this, KScrExpression.class, 1); - } - - public @Nullable JvmType type(){ - return arrayExpr() - .map(KScrExpression::type) - .map(x -> x instanceof JvmArrayType ? x : null) - .map(x-> ((JvmArrayType)x).getComponentType()) - .orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrAssignExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrAssignExpr.java deleted file mode 100644 index 37b7d21..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrAssignExpr.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrAssignExpr extends KScrExpression{ - - public KScrAssignExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional expression(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } - - public @Nullable JvmType type(){ - return expression().map(KScrExpression::type).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrBinaryExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrBinaryExpr.java deleted file mode 100644 index 9bc11db..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrBinaryExpr.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.util.Optional; - -public class KScrBinaryExpr extends KScrExpression{ - - public KScrBinaryExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional op(){ - return PsiUtils.childOfType(this, KScrBinaryOp.class); - } - - public String symbol(){ - return op().map(PsiElement::getText).orElse(""); - } - - public Optional left(){ - return PsiUtils.childOfType(this, KScrExpression.class, 0); - } - - public Optional right(){ - return PsiUtils.childOfType(this, KScrExpression.class, 1); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrCallExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrCallExpr.java deleted file mode 100644 index 146867d..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrCallExpr.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmMethod; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.antlr_generated.KScrLangParser; -import org.comroid.kscr.intellij.psi.Tokens; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrCallExpr extends KScrExpression{ - - public KScrCallExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional call(){ - return PsiUtils.childOfType(this, KScrCall.class); - } - - public Optional on(){ - return PsiUtils.childOfType(this, KScrExpression.class); - } - - public boolean isSuperCall(){ - return !PsiUtils.matchingChildren(this, k -> k.getNode().getElementType() == Tokens.getFor(KScrLangParser.SUPER)).isEmpty(); - } - - public @Nullable JvmType type(){ - return call().map(KScrCall::resolveMethod).map(JvmMethod::getReturnType).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrCastExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrCastExpr.java deleted file mode 100644 index 9a85476..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrCastExpr.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrCastExpr extends KScrExpression{ - - public KScrCastExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional castingTo(){ - return PsiUtils.childOfType(this, KScrElement.class).flatMap(x -> PsiUtils.childOfType(x, KScrTypeRef.class)); - } - - public @Nullable JvmType type(){ - return castingTo().map(KScrTypeRef::asType).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrClassLiteralExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrClassLiteralExpr.java deleted file mode 100644 index a432b7b..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrClassLiteralExpr.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiReference; -import org.comroid.kscr.intellij.psi.utils.KScrIdHolder; -import org.comroid.kscr.intellij.psi.utils.KScrTypeReference; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static org.comroid.kscr.intellij.psi.utils.JvmClassUtils.getByName; - -public class KScrClassLiteralExpr extends KScrExpression implements KScrIdHolder{ - - public KScrClassLiteralExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - return getByName("java.lang.Class", getProject()); - } - - public PsiReference getReference(){ - return getIdElement().map(id -> new KScrTypeReference(id, this)).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrIdExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrIdExpr.java deleted file mode 100644 index 684aef1..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrIdExpr.java +++ /dev/null @@ -1,178 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.lang.jvm.JvmField; -import com.intellij.lang.jvm.types.JvmReferenceType; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.NlsSafe; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.*; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.IncorrectOperationException; -import org.comroid.kscr.intellij.psi.KScrFile; -import org.comroid.kscr.intellij.psi.types.ClassTypeImpl; -import org.comroid.kscr.intellij.psi.utils.*; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; - -@SuppressWarnings("UnstableApiUsage") -public class KScrIdExpr extends KScrExpression implements PsiReference{ - - public KScrIdExpr(@NotNull ASTNode node){ - super(node); - } - - /* - Can resolve to: - - a local variable (int x = 0; int y = x;) - - a type (KScrExpression) - - a field (KScrExpression.COMPOSITE_ELEMENT_WRAPPER) - - a package (KScr.intellij.psi.KScrExpression) - */ - - public String id(){ - return PsiUtils.childOfType(this, KScrIdPart.class).map(PsiElement::getText).orElse(""); - } - - @Nullable - public KScrExpression on(){ - return PsiUtils.childOfType(this, KScrExpression.class).orElse(null); - } - - // [JvmClass | PsiPackage | KScrVariable | JvmField | String | null] - public Object resolveTarget(){ - var on = on(); - String id = id(); - if(on == null){ - var scope = KScrVarScope.scopeOf(this); - if(scope.isPresent()){ - var available = scope.get().available(); - var byName = available.stream().filter(x -> x.varName().equals(id)).findFirst(); - if(byName.isPresent()) - return byName.get(); - } - KScrType inside = PsiTreeUtil.getParentOfType(this, KScrType.class); - if(inside != null){ - var field = inside.fields().stream() - .filter(x -> x.varName().equals(id)) - .findFirst() - .orElse(null); - if(field != null) - return field; - } - return resolveById(id, getContainingFile(), getProject()); - }else{ - Object ret = null; - if(on instanceof KScrIdExpr){ - var res = ((KScrIdExpr)on).resolveTarget(); - if(res == null) - return null; - String narrowId = id; - if(res instanceof String) - narrowId = res + "." + narrowId; - if(res instanceof PsiPackage) - narrowId = ((PsiPackage)res).getQualifiedName() + "." + narrowId; - ret = resolveById(narrowId, getContainingFile(), getProject()); - } - JvmType type = on.type(); - if(!(type instanceof JvmReferenceType)) - return ret; - var res = ((JvmReferenceType)type).resolve(); - if(!(res instanceof JvmClass)) - return ret; - return Arrays.stream(((JvmClass)res).getFields()) - .filter(x -> x.getName().equals(id)) - .findFirst() - .map(Object.class::cast) - .orElse(ret); - } - } - - @NotNull - private static Object resolveById(String id, PsiFile file, Project project){ - if(file instanceof KScrFile){ - var type = ProjectTypeFinder.firstType(project, KScrTypeReference.getCandidates((KScrFile)file, id)); - if(type != null) - return type; - } - var psiPackage = JavaPsiFacade.getInstance(project).findPackage(id); - if(psiPackage != null) - return psiPackage; - return id; - } - - public @Nullable JvmType type(){ - var res = resolveTarget(); - if(res instanceof JvmClass) - return ClassTypeImpl.of((JvmClass)res); - if(res instanceof KScrVariable) - return ((KScrVariable)res).varType(); - if(res instanceof JvmField) - return ((JvmField)res).getType(); - return null; - } - - public PsiReference getReference(){ - return this; - } - - public @NotNull PsiElement getElement(){ - return this; - } - - public @NotNull TextRange getRangeInElement(){ - return PsiUtils.childOfType(this, KScrIdPart.class).map(PsiElement::getTextRangeInParent).orElse(getTextRangeInParent()); - } - - public @Nullable PsiElement resolve(){ - var res = resolveTarget(); - if(res instanceof JvmClass) - return ((JvmClass)res).getSourceElement(); - if(res instanceof PsiElement) - return (PsiElement)res; - return null; - } - - public @NotNull @NlsSafe String getCanonicalText(){ - var res = resolveTarget(); - if(res instanceof JvmClass){ - var qName = ((JvmClass)res).getQualifiedName(); - return qName != null ? qName : ""; - } - if(res instanceof PsiPackage) - return ((PsiPackage)res).getQualifiedName(); - if(res instanceof KScrVariable) - return ((KScrVariable)res).varName(); - return ""; - } - - public PsiElement handleElementRename(@NotNull String name) throws IncorrectOperationException{ - PsiUtils.childOfType(this, KScrIdPart.class).ifPresent(id -> id.replace(PsiUtils.createIdFromText(this, name))); - return this; - } - - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException{ - if(element instanceof PsiNamedElement){ - PsiUtils.childOfType(this, KScrIdPart.class).ifPresent(id -> id.replace(PsiUtils.createIdFromText(this, ((PsiNamedElement)element).getName()))); - return this; - } - throw new IncorrectOperationException("Can't bind an ID expression to something that has no name!"); - } - - public boolean isReferenceTo(@NotNull PsiElement element){ - var res = resolveTarget(); - if(res instanceof JvmClass) - return ((JvmClass)res).getSourceElement() == element; - if(res instanceof PsiElement) - return res == element; - return false; - } - - public boolean isSoft(){ - return false; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrInitialisationExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrInitialisationExpr.java deleted file mode 100644 index aae3abe..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrInitialisationExpr.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrInitialisationExpr extends KScrExpression{ - - public KScrInitialisationExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional initialising(){ - return PsiUtils.childOfType(this, KScrElement.class).flatMap(x -> PsiUtils.childOfType(x, KScrTypeRef.class)); - } - - public @Nullable JvmType type(){ - return initialising().map(KScrTypeRef::asType).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrInstanceOfExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrInstanceOfExpr.java deleted file mode 100644 index ba501f2..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrInstanceOfExpr.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrInstanceOfExpr extends KScrExpression{ - - public KScrInstanceOfExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - return PsiType.BOOLEAN; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrLiteralExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrLiteralExpr.java deleted file mode 100644 index da7acec..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrLiteralExpr.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiType; -import org.comroid.kscr.intellij.psi.Tokens; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrLiteralExpr extends KScrExpression{ - - public KScrLiteralExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - if(getNode().findChildByType(Tokens.TOK_NULL) != null) - return PsiType.NULL; - if(getNode().findChildByType(Tokens.TOK_BOOLLIT) != null) - return PsiType.BOOLEAN; - // TODO: implicit conversions - if(getNode().findChildByType(Tokens.TOK_NUMLIT) != null) - return PsiType.INT; - if(getNode().findChildByType(Tokens.TOK_RANGELIT) != null) - return PsiType.DOUBLE; - return null; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrNewArrayExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrNewArrayExpr.java deleted file mode 100644 index d4fa107..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrNewArrayExpr.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.types.ArrayTypeImpl; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrNewArrayExpr extends KScrExpression{ - - public KScrNewArrayExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional elementType(){ - return PsiUtils.childOfType(this, KScrElement.class).flatMap(x -> PsiUtils.childOfType(x, KScrTypeRef.class)); - } - - public @Nullable JvmType type(){ - return elementType().map(KScrTypeRef::asType).map(ArrayTypeImpl::of).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrNewListArrayExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrNewListArrayExpr.java deleted file mode 100644 index 728d714..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrNewListArrayExpr.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.types.ArrayTypeImpl; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -public class KScrNewListArrayExpr extends KScrExpression{ - - public KScrNewListArrayExpr(@NotNull ASTNode node){ - super(node); - } - - public Optional elementType(){ - return PsiUtils.childOfType(this, KScrElement.class).flatMap(x -> PsiUtils.childOfType(x, KScrTypeRef.class)); - } - - public @Nullable JvmType type(){ - return elementType().map(KScrTypeRef::asType).map(ArrayTypeImpl::of).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrParenthesisedExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrParenthesisedExpr.java deleted file mode 100644 index 3d5a308..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrParenthesisedExpr.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrParenthesisedExpr extends KScrExpression{ - - public KScrParenthesisedExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - var parenthesised = PsiUtils.childOfType(this, KScrExpression.class); - return parenthesised.map(KScrExpression::type).orElse(null); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrStringLiteralExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrStringLiteralExpr.java deleted file mode 100644 index 03a7736..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrStringLiteralExpr.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static org.comroid.kscr.intellij.psi.utils.JvmClassUtils.getByName; - -public class KScrStringLiteralExpr extends KScrExpression{ - - public KScrStringLiteralExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - return getByName("java.lang.String", getProject()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrThisExpr.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrThisExpr.java deleted file mode 100644 index 9fe4bd1..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/expressions/KScrThisExpr.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.comroid.kscr.intellij.psi.expressions; - -import com.intellij.lang.ASTNode; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.util.PsiTreeUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class KScrThisExpr extends KScrExpression{ - - public KScrThisExpr(@NotNull ASTNode node){ - super(node); - } - - public @Nullable JvmType type(){ - var method = PsiTreeUtil.getParentOfType(this, KScrMethod.class); - if(method == null || method.isStatic()) - return null; - return JvmClassUtils.asType(method.containingType()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/KScrFileStub.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/KScrFileStub.java deleted file mode 100644 index 0f611c9..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/KScrFileStub.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import com.intellij.psi.stubs.PsiFileStubImpl; -import com.intellij.psi.tree.IStubFileElementType; -import org.comroid.kscr.intellij.parser.KScrParserDefinition; -import org.comroid.kscr.intellij.psi.KScrFile; -import org.jetbrains.annotations.NotNull; - -public class KScrFileStub extends PsiFileStubImpl{ - - public KScrFileStub(KScrFile file){ - super(file); - } - - public @NotNull IStubFileElementType getType(){ - return KScrParserDefinition.FILE; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubAsKScrVariable.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubAsKScrVariable.java deleted file mode 100644 index 14c38de..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubAsKScrVariable.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.KScrVariable; -import org.jetbrains.annotations.NotNull; - -public interface StubAsKScrVariable extends StubElement{ - - @NotNull - String varName(); - - @NotNull - String varTypeText(); - - boolean hasModifier(String modifier); -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrClassList.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrClassList.java deleted file mode 100644 index 3565a14..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrClassList.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.types.KScrClassList; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public interface StubKScrClassList> extends StubElement { - @NotNull - List elementFqNames(); -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrField.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrField.java deleted file mode 100644 index 1643a84..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrField.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import org.comroid.kscr.intellij.psi.ast.common.KScrVariableDef; -import org.jetbrains.annotations.NotNull; - -public interface StubKScrField extends StubWithKScrModifiers, StubAsKScrVariable{ - - @NotNull - String name(); - - @NotNull - String typeText(); - - @NotNull - default String varName(){ - return name(); - } - - @NotNull - default String varTypeText(){ - return typeText(); - } - - default boolean hasModifier(String modifier){ - var modList = modifiers(); - return modList != null && modList.modifiers().contains(modifier); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrMemberWrapper.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrMemberWrapper.java deleted file mode 100644 index d79804b..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrMemberWrapper.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.types.KScrMemberWrapper; - -public interface StubKScrMemberWrapper extends StubElement{ - - // hold position in stub tree -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrMethod.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrMethod.java deleted file mode 100644 index f25d6fc..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrMethod.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import com.intellij.psi.stubs.EmptyStub; -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.KScrMethod; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public interface StubKScrMethod extends StubWithKScrModifiers{ - - @NotNull - String name(); - - @NotNull - default List parameters(){ - return getChildrenStubs().stream() - .filter(EmptyStub.class::isInstance) - .flatMap(x -> (Stream>)x.getChildrenStubs().stream()) - .filter(StubKScrParameter.class::isInstance) - .map(StubKScrParameter.class::cast) - .collect(Collectors.toList()); - } - - @NotNull - String returnTypeText(); - - boolean hasSemicolon(); -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrModifierList.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrModifierList.java deleted file mode 100644 index fc96d2d..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrModifierList.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.KScrModifierList; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public interface StubKScrModifierList extends StubElement{ - - @NotNull - List modifiers(); -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrParameter.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrParameter.java deleted file mode 100644 index 9a26f74..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrParameter.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import org.comroid.kscr.intellij.psi.ast.common.KScrParameter; -import org.jetbrains.annotations.NotNull; - -public interface StubKScrParameter extends StubAsKScrVariable{ - - @NotNull - String name(); - - @NotNull - String typeText(); - - boolean isVarargs(); - - @NotNull - default String varName(){ - return name(); - } - - @NotNull - default String varTypeText(){ - return typeText(); - } - - default boolean hasModifier(String modifier){ - if(!(modifier.equals("private") || modifier.equals("final"))) - return false; - // method parameter finality is not externally visible - return isRecordComponent(); - } - - default boolean isRecordComponent(){ - return getParentStub() instanceof StubKScrRecordComponents; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrRecordComponents.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrRecordComponents.java deleted file mode 100644 index 780665c..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrRecordComponents.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.types.KScrRecordComponents; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.stream.Collectors; - -public interface StubKScrRecordComponents extends StubElement{ - - @NotNull - default List components(){ - return getChildrenStubs().stream() - .filter(StubKScrParameter.class::isInstance) - .map(StubKScrParameter.class::cast) - .collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrType.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrType.java deleted file mode 100644 index d22f042..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubKScrType.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.types.KScrExtendsClause; -import org.comroid.kscr.intellij.psi.ast.types.KScrImplementsClause; -import org.comroid.kscr.intellij.psi.ast.types.KScrPermitsClause; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.types.KScrKind; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface StubKScrType extends StubElement { - - @NotNull - String fullyQualifiedName(); - - @NotNull - String shortName(); - - @NotNull - KScrKind kind(); - - @Nullable - default StubKScrClassList extendsList(){ - return findChildStubByType(StubTypes.KScr_EXTENDS_LIST); - } - - @Nullable - default StubKScrClassList implementsList(){ - return findChildStubByType(StubTypes.KScr_IMPLEMENTS_LIST); - } - - @Nullable - default StubKScrClassList permitsList(){ - return findChildStubByType(StubTypes.KScr_PERMITS_LIST); - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubTypes.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubTypes.java deleted file mode 100644 index 695f53c..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubTypes.java +++ /dev/null @@ -1,341 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import com.intellij.psi.stubs.*; -import org.comroid.kscr.intellij.KScrLanguage; -import org.comroid.kscr.intellij.antlr_generated.KScrLangParser; -import org.comroid.kscr.intellij.psi.Tokens; -import org.comroid.kscr.intellij.psi.ast.KScrMethod; -import org.comroid.kscr.intellij.psi.ast.KScrModifierList; -import org.comroid.kscr.intellij.psi.ast.KScrParametersList; -import org.comroid.kscr.intellij.psi.ast.KScrTypeRef; -import org.comroid.kscr.intellij.psi.ast.common.KScrParameter; -import org.comroid.kscr.intellij.psi.ast.common.KScrVariableDef; -import org.comroid.kscr.intellij.psi.ast.types.*; -import org.comroid.kscr.intellij.psi.indexes.StubIndexes; -import org.comroid.kscr.intellij.psi.stubs.impl.*; -import org.comroid.kscr.intellij.psi.types.KScrKind; -import org.comroid.kscr.intellij.psi.utils.PsiUtils; -import org.jetbrains.annotations.NotNull; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; - -public interface StubTypes{ - - IStubElementType KScr_TYPE = new KScrTypeStubElementType(); - IStubElementType KScr_MEMBER = new KScrMemberStubElementType(); - IStubElementType KScr_RECORD_COMPONENTS = new KScrRecordComponentsStubElementType(); - IStubElementType KScr_PARAMETER = new KScrParameterStubElementType(); - IStubElementType KScr_MODIFIER_LIST = new KScrModifierListStubElementType(); - IStubElementType KScr_METHOD = new KScrMethodStubElementType(); - IStubElementType KScr_FIELD = new KScrFieldStubElementType(); - - IStubElementType, KScrExtendsClause> KScr_EXTENDS_LIST - = new KScrClassListStubElementType<>("KScr_EXTENDS_LIST", KScrExtendsClause::new); - IStubElementType, KScrImplementsClause> KScr_IMPLEMENTS_LIST - = new KScrClassListStubElementType<>("KScr_IMPLEMENTS_LIST", KScrImplementsClause::new); - IStubElementType, KScrPermitsClause> KScr_PERMITS_LIST - = new KScrClassListStubElementType<>("KScr_PERMITS_LIST", KScrPermitsClause::new); - - IStubElementType, KScrParametersList> KScr_PARAMETERS_LIST - = new EmptyStubElementType<>("KScr_PARAMETERS_LIST", KScrLanguage.LANGUAGE){ - @SuppressWarnings("unchecked") - public KScrParametersList createPsi(@NotNull EmptyStub stub){ - return new KScrParametersList((EmptyStub)stub); - } - public @NotNull String getExternalId(){ - return "kScr." + this; - } - }; - - class KScrTypeStubElementType extends IStubElementType{ - - public KScrTypeStubElementType(){ - super("KScr_TYPE", KScrLanguage.LANGUAGE); - } - - public KScrType createPsi(@NotNull StubKScrType stub){ - return new KScrType(stub); - } - - public @NotNull StubKScrType createStub(@NotNull KScrType psi, StubElement parent){ - var stub = psi.getStub(); - return stub != null ? stub : new StubImplKScrType(parent, psi); - } - - public @NotNull String getExternalId(){ - return "kScr." + this; - } - - public void serialize(@NotNull StubKScrType stub, @NotNull StubOutputStream stream) throws IOException{ - stream.writeName(stub.shortName()); - stream.writeName(stub.fullyQualifiedName()); - stream.writeVarInt(stub.kind().ordinal()); - } - - public @NotNull StubKScrType deserialize(@NotNull StubInputStream stream, StubElement parent) throws IOException{ - return new StubImplKScrType(parent, - stream.readNameString(), - stream.readNameString(), - KScrKind.values()[stream.readVarInt()]); - } - - public void indexStub(@NotNull StubKScrType stub, @NotNull IndexSink sink){ - sink.occurrence(StubIndexes.TYPES_BY_FQ_NAME, stub.fullyQualifiedName()); - sink.occurrence(StubIndexes.TYPES_BY_SHORT_NAME, stub.shortName()); - } - } - - class KScrClassListStubElementType> extends IStubElementType, CL>{ - - private final Function, CL> builder; - - public KScrClassListStubElementType(String name, Function, CL> builder){ - super(name, KScrLanguage.LANGUAGE); - this.builder = builder; - } - - public CL createPsi(@NotNull StubKScrClassList stub){ - return builder.apply(stub); - } - - public @NotNull StubKScrClassList createStub(@NotNull CL psi, StubElement parent){ - var stub = psi.getStub(); - return stub != null ? stub : new StubImplKScrClassList<>(parent, this, psi.elementNames()); - } - - public @NotNull String getExternalId(){ - return "kScr." + this; - } - - public void serialize(@NotNull StubKScrClassList stub, @NotNull StubOutputStream stream) throws IOException{ - var names = stub.elementFqNames(); - stream.writeVarInt(names.size()); - for(String name : names) - stream.writeName(name); - } - - public @NotNull StubKScrClassList deserialize(@NotNull StubInputStream stream, StubElement parent) throws IOException{ - int size = stream.readVarInt(); - var list = new ArrayList(size); - for(int i = 0; i < size; i++) - list.add(stream.readNameString()); - return new StubImplKScrClassList<>(parent, this, list); - } - - @SuppressWarnings("EqualsBetweenInconvertibleTypes") - public void indexStub(@NotNull StubKScrClassList stub, @NotNull IndexSink sink){ - if(this.equals(KScr_EXTENDS_LIST) || this.equals(KScr_IMPLEMENTS_LIST)) - for(String name : stub.elementFqNames()) - sink.occurrence(StubIndexes.INHERITANCE_LISTS, name); - } - } - - class KScrMemberStubElementType extends IStubElementType{ - - public KScrMemberStubElementType(){ - super("KScr_MEMBER", KScrLanguage.LANGUAGE); - } - - public KScrMemberWrapper createPsi(@NotNull StubKScrMemberWrapper stub){ - return new KScrMemberWrapper(stub); - } - - public @NotNull StubKScrMemberWrapper createStub(@NotNull KScrMemberWrapper psi, StubElement parent){ - return new StubImplKScrMemberWrapper(parent); - } - - public @NotNull String getExternalId(){ - return "kScr." + this; - } - - public void serialize(@NotNull StubKScrMemberWrapper stub, @NotNull StubOutputStream dataStream){} - - public @NotNull StubKScrMemberWrapper deserialize(@NotNull StubInputStream dataStream, StubElement parent){ - return new StubImplKScrMemberWrapper(parent); - } - - public void indexStub(@NotNull StubKScrMemberWrapper stub, @NotNull IndexSink sink){} - } - - class KScrRecordComponentsStubElementType extends IStubElementType{ - - public KScrRecordComponentsStubElementType(){ - super("KScr_RECORD_COMPONENTS", KScrLanguage.LANGUAGE); - } - - public KScrRecordComponents createPsi(@NotNull StubKScrRecordComponents stub){ - return new KScrRecordComponents(stub); - } - - public @NotNull StubKScrRecordComponents createStub(@NotNull KScrRecordComponents psi, StubElement parent){ - return new StubImplKScrRecordComponents(parent); - } - - public @NotNull String getExternalId(){ - return "kScr." + this; - } - - public void serialize(@NotNull StubKScrRecordComponents stub, @NotNull StubOutputStream stream){} - - public @NotNull StubKScrRecordComponents deserialize(@NotNull StubInputStream stream, StubElement parentStub){ - return new StubImplKScrRecordComponents(parentStub); - } - - public void indexStub(@NotNull StubKScrRecordComponents stub, @NotNull IndexSink sink){} - } - - class KScrParameterStubElementType extends IStubElementType{ - - public KScrParameterStubElementType(){ - super("KScr_PARAMETER", KScrLanguage.LANGUAGE); - } - - public KScrParameter createPsi(@NotNull StubKScrParameter stub){ - return new KScrParameter(stub); - } - - public @NotNull StubKScrParameter createStub(@NotNull KScrParameter psi, StubElement parent){ - String name = psi.varName(), type = psi.getTypeName().map(PsiElement::getText).orElse(""); - boolean varargs = psi.isVarargs(); - return new StubImplKScrParameter(parent, name, type, varargs); - } - - public @NotNull String getExternalId(){ - return "kScr." + this; - } - - public void serialize(@NotNull StubKScrParameter stub, @NotNull StubOutputStream stream) throws IOException{ - stream.writeName(stub.name()); - stream.writeName(stub.typeText()); - stream.writeBoolean(stub.isVarargs()); - } - - public @NotNull StubKScrParameter deserialize(@NotNull StubInputStream stream, StubElement parent) throws IOException{ - var name = stream.readNameString(); - var type = stream.readNameString(); - return new StubImplKScrParameter(parent, name != null ? name : "", type != null ? type : "", stream.readBoolean()); - } - - public void indexStub(@NotNull StubKScrParameter stub, @NotNull IndexSink sink){ - if(stub.isRecordComponent()) - sink.occurrence(StubIndexes.FIELDS, stub.name()); - } - } - - class KScrModifierListStubElementType extends IStubElementType{ - - public KScrModifierListStubElementType(){ - super("KScr_MODIFIER_LIST", KScrLanguage.LANGUAGE); - } - - public KScrModifierList createPsi(@NotNull StubKScrModifierList stub){ - return new KScrModifierList(stub); - } - - public @NotNull StubKScrModifierList createStub(@NotNull KScrModifierList psi, StubElement parent){ - return new StubImplKScrModifierList(parent, Collections.unmodifiableList(psi.getModifiers())); - } - - public @NotNull String getExternalId(){ - return "kScr." + this; - } - - public void serialize(@NotNull StubKScrModifierList stub, @NotNull StubOutputStream stream) throws IOException{ - var list = stub.modifiers(); - stream.writeVarInt(list.size()); - for(String mod : list) - stream.writeName(mod); - } - - public @NotNull StubKScrModifierList deserialize(@NotNull StubInputStream stream, StubElement parent) throws IOException{ - int amount = stream.readVarInt(); - List modifiers = new ArrayList<>(amount); - for(int i = 0; i < amount; i++) - modifiers.add(stream.readNameString()); - return new StubImplKScrModifierList(parent, modifiers); - } - - public void indexStub(@NotNull StubKScrModifierList stub, @NotNull IndexSink sink){} - } - - class KScrMethodStubElementType extends IStubElementType{ - - public KScrMethodStubElementType(){ - super("KScr_METHOD", KScrLanguage.LANGUAGE); - } - - public KScrMethod createPsi(@NotNull StubKScrMethod stub){ - return new KScrMethod(stub); - } - - public @NotNull StubKScrMethod createStub(@NotNull KScrMethod psi, StubElement parent){ - return new StubImplKScrMethod(parent, psi.getName(), psi.returns().map(PsiElement::getText).orElse(""), psi.hasSemicolon()); - } - - public @NotNull String getExternalId(){ - return "kScr." + this; - } - - public void serialize(@NotNull StubKScrMethod stub, @NotNull StubOutputStream stream) throws IOException{ - stream.writeName(stub.name()); - stream.writeName(stub.returnTypeText()); - stream.writeBoolean(stub.hasSemicolon()); - } - - public @NotNull StubKScrMethod deserialize(@NotNull StubInputStream stream, StubElement parent) throws IOException{ - return new StubImplKScrMethod(parent, stream.readNameString(), stream.readNameString(), stream.readBoolean()); - } - - public void indexStub(@NotNull StubKScrMethod stub, @NotNull IndexSink sink){ - sink.occurrence(StubIndexes.METHODS, stub.name()); - } - } - - class KScrFieldStubElementType extends IStubElementType{ - - public KScrFieldStubElementType(){ - super("KScr_FIELD", KScrLanguage.LANGUAGE); - } - - public KScrVariableDef createPsi(@NotNull StubKScrField stub){ - return new KScrVariableDef(stub); - } - - public @NotNull StubKScrField createStub(@NotNull KScrVariableDef psi, StubElement parent){ - return new StubImplKScrField( - parent, - psi.varName(), - PsiUtils.childOfType(psi, KScrTypeRef.class).map(PsiElement::getText).orElse("")); - } - - public @NotNull String getExternalId(){ - return "kScr." + this; - } - - public void serialize(@NotNull StubKScrField stub, @NotNull StubOutputStream stream) throws IOException{ - stream.writeName(stub.name()); - stream.writeName(stub.typeText()); - } - - public @NotNull StubKScrField deserialize(@NotNull StubInputStream stream, StubElement parent) throws IOException{ - var name = stream.readNameString(); - var type = stream.readNameString(); - return new StubImplKScrField(parent, name != null ? name : "", type != null ? type : ""); - } - - public void indexStub(@NotNull StubKScrField stub, @NotNull IndexSink sink){ - sink.occurrence(StubIndexes.FIELDS, stub.name()); - } - - public boolean shouldCreateStub(ASTNode node){ - // only fields, not locals - return node.getTreeParent().getElementType() == Tokens.getRuleFor(KScrLangParser.RULE_member); - } - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubWithKScrModifiers.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubWithKScrModifiers.java deleted file mode 100644 index 992858b..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/StubWithKScrModifiers.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.stubs.StubElement; -import org.jetbrains.annotations.Nullable; - -public interface StubWithKScrModifiers extends StubElement{ - - @Nullable - default StubKScrModifierList modifiers(){ - return findChildStubByType(StubTypes.KScr_MODIFIER_LIST); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrClassList.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrClassList.java deleted file mode 100644 index 1a9be8b..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrClassList.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs.impl; - -import com.intellij.psi.stubs.IStubElementType; -import com.intellij.psi.stubs.StubBase; -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.types.KScrClassList; -import org.comroid.kscr.intellij.psi.stubs.StubKScrClassList; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class StubImplKScrClassList> extends StubBase implements StubKScrClassList{ - - @NotNull - private final List elementFqNames; - - public StubImplKScrClassList(@Nullable StubElement parent, IStubElementType elementType, @NotNull List fqNames){ - super(parent, elementType); - elementFqNames = fqNames; - } - - public @NotNull List elementFqNames(){ - return elementFqNames; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrField.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrField.java deleted file mode 100644 index 2b08d86..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrField.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs.impl; - -import com.intellij.psi.stubs.StubBase; -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.common.KScrVariableDef; -import org.comroid.kscr.intellij.psi.stubs.StubKScrField; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class StubImplKScrField extends StubBase implements StubKScrField{ - - @NotNull - private final String name, typeText; - - public StubImplKScrField(@Nullable StubElement parent, @NotNull String name, @NotNull String typeText){ - super(parent, StubTypes.KScr_FIELD); - this.name = name; - this.typeText = typeText; - } - - public @NotNull String name(){ - return name; - } - - public @NotNull String typeText(){ - return typeText; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrMemberWrapper.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrMemberWrapper.java deleted file mode 100644 index 383cf18..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrMemberWrapper.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs.impl; - -import com.intellij.psi.stubs.StubBase; -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.types.KScrMemberWrapper; -import org.comroid.kscr.intellij.psi.stubs.StubKScrMemberWrapper; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.Nullable; - -public class StubImplKScrMemberWrapper extends StubBase implements StubKScrMemberWrapper{ - - public StubImplKScrMemberWrapper(@Nullable StubElement parent){ - super(parent, StubTypes.KScr_MEMBER); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrMethod.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrMethod.java deleted file mode 100644 index 6a299dc..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrMethod.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs.impl; - -import com.intellij.psi.stubs.StubBase; -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.KScrMethod; -import org.comroid.kscr.intellij.psi.stubs.StubKScrMethod; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class StubImplKScrMethod extends StubBase implements StubKScrMethod{ - - @NotNull - private final String name, returnType; - private final boolean hasSemicolon; - - public StubImplKScrMethod(@Nullable StubElement parent, String name, String returnType, boolean semicolon){ - super(parent, StubTypes.KScr_METHOD); - this.name = name; - this.returnType = returnType; - hasSemicolon = semicolon; - } - - public @NotNull String name(){ - return name; - } - - public @NotNull String returnTypeText(){ - return returnType; - } - - public boolean hasSemicolon(){ - return hasSemicolon; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrModifierList.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrModifierList.java deleted file mode 100644 index 330c3b4..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrModifierList.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs.impl; - -import com.intellij.psi.stubs.StubBase; -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.KScrModifierList; -import org.comroid.kscr.intellij.psi.stubs.StubKScrModifierList; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -public class StubImplKScrModifierList extends StubBase implements StubKScrModifierList{ - - @NotNull - private final List modifiers; - - public StubImplKScrModifierList(@Nullable StubElement parent, @NotNull List modifiers){ - super(parent, StubTypes.KScr_MODIFIER_LIST); - this.modifiers = modifiers; - } - - public @NotNull List modifiers(){ - return modifiers; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrParameter.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrParameter.java deleted file mode 100644 index 0fbead1..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrParameter.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs.impl; - -import com.intellij.psi.stubs.StubBase; -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.common.KScrParameter; -import org.comroid.kscr.intellij.psi.stubs.StubKScrParameter; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class StubImplKScrParameter extends StubBase implements StubKScrParameter{ - - @NotNull - private final String name, typeText; - private final boolean varargs; - - public StubImplKScrParameter(@Nullable StubElement parent, - @NotNull String name, - @NotNull String typeText, - boolean varargs){ - super(parent, StubTypes.KScr_PARAMETER); - this.name = name; - this.typeText = typeText; - this.varargs = varargs; - } - - @NotNull - public String name(){ - return name; - } - - public @NotNull String typeText(){ - return typeText; - } - - public boolean isVarargs(){ - return varargs; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrRecordComponents.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrRecordComponents.java deleted file mode 100644 index bb6a729..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrRecordComponents.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs.impl; - -import com.intellij.psi.stubs.StubBase; -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.types.KScrRecordComponents; -import org.comroid.kscr.intellij.psi.stubs.StubKScrRecordComponents; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.jetbrains.annotations.Nullable; - -public class StubImplKScrRecordComponents extends StubBase implements StubKScrRecordComponents{ - - public StubImplKScrRecordComponents(@Nullable StubElement parent){ - super(parent, StubTypes.KScr_RECORD_COMPONENTS); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrType.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrType.java deleted file mode 100644 index 5cd6e27..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/stubs/impl/StubImplKScrType.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.comroid.kscr.intellij.psi.stubs.impl; - -import com.intellij.psi.stubs.StubBase; -import com.intellij.psi.stubs.StubElement; -import org.comroid.kscr.intellij.psi.ast.types.KScrType; -import org.comroid.kscr.intellij.psi.stubs.StubKScrType; -import org.comroid.kscr.intellij.psi.stubs.StubTypes; -import org.comroid.kscr.intellij.psi.types.KScrKind; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class StubImplKScrType extends StubBase implements StubKScrType{ - - @NotNull - private final String fqName; - @NotNull - private final String shortName; - @NotNull - private final KScrKind kind; - - public StubImplKScrType(@Nullable StubElement parent, KScrType type){ - this(parent, type.getName(), type.getName(), type.kind()); - } - - public StubImplKScrType(@Nullable StubElement parent, String shortName, String fqName, KScrKind kind){ - super(parent, StubTypes.KScr_TYPE); - this.shortName = shortName; - this.fqName = fqName; - this.kind = kind; - } - - @NotNull - public String fullyQualifiedName(){ - return fqName; - } - - @NotNull - public String shortName(){ - return shortName; - } - - @NotNull - public KScrKind kind(){ - return kind; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/ArrayTypeImpl.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/ArrayTypeImpl.java deleted file mode 100644 index 78b317f..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/ArrayTypeImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.comroid.kscr.intellij.psi.types; - -import com.intellij.lang.jvm.JvmAnnotation; -import com.intellij.lang.jvm.types.JvmArrayType; -import com.intellij.lang.jvm.types.JvmType; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; -import java.util.WeakHashMap; - -public class ArrayTypeImpl implements JvmArrayType{ - - private static final Map CACHE = new WeakHashMap<>(); - - private final JvmType component; - - private ArrayTypeImpl(JvmType component){ - this.component = component; - } - - public static ArrayTypeImpl of(JvmType type){ - if(type == null) - return null; - return CACHE.computeIfAbsent(type, ArrayTypeImpl::new); - } - - public @NotNull JvmType getComponentType(){ - return component; - } - - public JvmAnnotation @NotNull [] getAnnotations(){ - return new JvmAnnotation[0]; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/ClassTypeImpl.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/ClassTypeImpl.java deleted file mode 100644 index c499e51..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/ClassTypeImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.comroid.kscr.intellij.psi.types; - -import com.intellij.lang.jvm.JvmAnnotation; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.lang.jvm.JvmTypeDeclaration; -import com.intellij.lang.jvm.JvmTypeParameter; -import com.intellij.lang.jvm.types.JvmReferenceType; -import com.intellij.lang.jvm.types.JvmSubstitutor; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.lang.jvm.types.JvmTypeResolveResult; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; - -public class ClassTypeImpl implements JvmReferenceType{ - - private static final Map CACHE = new WeakHashMap<>(); - - private final JvmClass underlying; - - private ClassTypeImpl(JvmClass underlying){ - this.underlying = underlying; - } - - @Nullable - public static ClassTypeImpl of(JvmClass jClass){ - if(jClass == null) - return null; - return CACHE.computeIfAbsent(jClass, ClassTypeImpl::new); - } - - public @NotNull String getName(){ - var name = underlying.getName(); - return name != null ? name : ""; - } - - public @Nullable JvmTypeResolveResult resolveType(){ - return new JvmTypeResolveResult(){ - public @NotNull JvmTypeDeclaration getDeclaration(){ - return underlying; - } - - public @NotNull JvmSubstitutor getSubstitutor(){ - return new JvmSubstitutor(){ - public @NotNull Collection getTypeParameters(){ - return List.of(); - } - - public @Nullable JvmType substitute(@NotNull JvmTypeParameter typeParameter){ - return null; - } - }; - } - }; - } - - public @NotNull Iterable typeArguments(){ - return List.of(); - } - - public JvmAnnotation @NotNull [] getAnnotations(){ - return new JvmAnnotation[0]; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrClass.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrClass.java deleted file mode 100644 index 8fa5ba9..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrClass.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.comroid.kscr.intellij.psi.types; - -import com.intellij.lang.jvm.*; -import com.intellij.lang.jvm.types.JvmReferenceType; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Locale; -import java.util.Map; -import java.util.WeakHashMap; - -@SuppressWarnings("UnstableApiUsage") -public class JvmKScrClass implements JvmClass{ - - private static final Map CACHE = new WeakHashMap<>(); - - private final KScrType underlying; - - private JvmKScrClass(KScrType underlying){ - this.underlying = underlying; - } - - public static JvmKScrClass of(KScrType type){ - if(type == null) - return null; - return CACHE.computeIfAbsent(type, JvmKScrClass::new); - } - - public @Nullable JvmClass getContainingClass(){ - return null; - } - - public @Nullable @NonNls String getName(){ - return underlying.getName(); - } - - public @Nullable @NonNls String getQualifiedName(){ - return underlying.fullyQualifiedName(); - } - - public @NotNull JvmClassKind getClassKind(){ - return underlying.kind().toJvmKind(); - } - - public @Nullable JvmReferenceType getSuperClassType(){ - return ClassTypeImpl.of(underlying.getSuperType()); - } - - public JvmReferenceType @NotNull [] getInterfaceTypes(){ - return underlying.getInterfaces().stream().map(ClassTypeImpl::of).toArray(JvmReferenceType[]::new); - } - - public JvmMethod @NotNull [] getMethods(){ - return underlying.methods().stream().map(JvmKScrMethod::of).toArray(JvmMethod[]::new); - } - - public JvmField @NotNull [] getFields(){ - return underlying.fields().stream().map(JvmKScrField::of).toArray(JvmField[]::new); - } - - public JvmClass @NotNull [] getInnerClasses(){ - return new JvmClass[0]; - } - - public JvmTypeParameter @NotNull [] getTypeParameters(){ - return new JvmTypeParameter[0]; - } - - public boolean hasModifier(@NotNull JvmModifier modifier){ - if(modifier == JvmModifier.PACKAGE_LOCAL) - return !(underlying.hasModifier("public") || underlying.hasModifier("protected") || underlying.hasModifier("private")); - return underlying.hasModifier(modifier.name().toLowerCase(Locale.ROOT)); - } - - public JvmAnnotation @NotNull [] getAnnotations(){ - return new JvmAnnotation[0]; - } - - public @Nullable PsiElement getSourceElement(){ - return underlying; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrField.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrField.java deleted file mode 100644 index 2afb3fc..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrField.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.comroid.kscr.intellij.psi.types; - -import com.intellij.lang.jvm.JvmAnnotation; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.lang.jvm.JvmField; -import com.intellij.lang.jvm.JvmModifier; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiElement; -import org.comroid.kscr.intellij.psi.utils.KScrVariable; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; -import java.util.WeakHashMap; - -@SuppressWarnings("UnstableApiUsage") -public class JvmKScrField implements JvmField{ - - private static final Map CACHE = new WeakHashMap<>(); - - private final KScrVariable underlying; - - private JvmKScrField(KScrVariable underlying){ - this.underlying = underlying; - } - - public static JvmKScrField of(KScrVariable var){ - if(var == null) - return null; - return CACHE.computeIfAbsent(var, JvmKScrField::new); - } - - public @Nullable JvmClass getContainingClass(){ - return null; - } - - public @NotNull String getName(){ - return underlying.varName(); - } - - public @NotNull JvmType getType(){ - return underlying.varType(); - } - - public boolean hasModifier(@NotNull JvmModifier modifier){ - return false; - } - - public JvmAnnotation @NotNull [] getAnnotations(){ - return new JvmAnnotation[0]; - } - - public @Nullable PsiElement getSourceElement(){ - return underlying.declaration(); - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrMethod.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrMethod.java deleted file mode 100644 index e235cad..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrMethod.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.comroid.kscr.intellij.psi.types; - -import com.intellij.lang.jvm.*; -import com.intellij.lang.jvm.types.JvmReferenceType; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Locale; -import java.util.Map; -import java.util.WeakHashMap; - -@SuppressWarnings("UnstableApiUsage") -public class JvmKScrMethod implements JvmMethod{ - - private static final Map CACHE = new WeakHashMap<>(); - - private final KScrMethod underlying; - - private JvmKScrMethod(KScrMethod underlying){ - this.underlying = underlying; - } - - public static JvmKScrMethod of(KScrMethod method){ - if(method == null) - return null; - return CACHE.computeIfAbsent(method, JvmKScrMethod::new); - } - - public boolean isConstructor(){ - return false; - } - - public @Nullable JvmClass getContainingClass(){ - return JvmKScrClass.of(underlying.containingType()); - } - - public @NotNull String getName(){ - return underlying.getName(); - } - - public @Nullable JvmType getReturnType(){ - return underlying.returnType(); - } - - public JvmParameter @NotNull [] getParameters(){ - return underlying.parameters().stream().map(JvmKScrParameter::of).toArray(JvmKScrParameter[]::new); - } - - public boolean isVarArgs(){ - return false; - } - - public JvmReferenceType @NotNull [] getThrowsTypes(){ - return new JvmReferenceType[0]; - } - - public JvmTypeParameter @NotNull [] getTypeParameters(){ - return new JvmTypeParameter[0]; - } - - public boolean hasModifier(@NotNull JvmModifier modifier){ - if(modifier == JvmModifier.PACKAGE_LOCAL) - return !(underlying.hasModifier("public") || underlying.hasModifier("protected") || underlying.hasModifier("private")); - return underlying.hasModifier(modifier.name().toLowerCase(Locale.ROOT)); - } - - public JvmAnnotation @NotNull [] getAnnotations(){ - return new JvmAnnotation[0]; - } - - public @Nullable PsiElement getSourceElement(){ - return underlying; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrParameter.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrParameter.java deleted file mode 100644 index 2fc27f9..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/JvmKScrParameter.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.comroid.kscr.intellij.psi.types; - -import com.intellij.lang.jvm.JvmAnnotation; -import com.intellij.lang.jvm.JvmModifier; -import com.intellij.lang.jvm.JvmParameter; -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; -import java.util.WeakHashMap; - -public class JvmKScrParameter implements JvmParameter{ - - private static final Map CACHE = new WeakHashMap<>(); - - private final KScrParameter underlying; - - private JvmKScrParameter(KScrParameter underlying){ - this.underlying = underlying; - } - - public static JvmKScrParameter of(KScrParameter type){ - if(type == null) - return null; - return CACHE.computeIfAbsent(type, JvmKScrParameter::new); - } - - - public @NotNull JvmType getType(){ - return underlying.varType(); - } - - public boolean hasModifier(@NotNull JvmModifier modifier){ - // TODO: final parameters - return false; - } - - public JvmAnnotation @NotNull [] getAnnotations(){ - return new JvmAnnotation[0]; - } - - public @NonNls @Nullable String getName(){ - return underlying.getName(); - } - - public @Nullable PsiElement getSourceElement(){ - return underlying; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/KScrKind.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/KScrKind.java deleted file mode 100644 index 7868d88..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/types/KScrKind.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.comroid.kscr.intellij.psi.types; - -import com.intellij.lang.jvm.JvmClassKind; - -public enum KScrKind{ - CLASS, INTERFACE, ENUM, RECORD, ANNOTATION, SINGLE, CONSTRUCTED; - - @SuppressWarnings("UnstableApiUsage") - public JvmClassKind toJvmKind(){ - switch(this){ - default: - case CLASS: - return JvmClassKind.CLASS; - case INTERFACE: - return JvmClassKind.INTERFACE; - case ENUM: - return JvmClassKind.ENUM; - case ANNOTATION: - return JvmClassKind.ANNOTATION; - } - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrIdHolder.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrIdHolder.java deleted file mode 100644 index 3c27284..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrIdHolder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.comroid.kscr.intellij.psi.utils; - -import com.intellij.extapi.psi.ASTDelegatePsiElement; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -/** - * Contains common logic for finding and changing the name of elements that have an immediate KScrId child. - */ -public interface KScrIdHolder extends PsiElement{ - - default Optional getIdElement(){ - return PsiUtils.childOfType(this, KScrId.class); - } - - @Nullable - default String getId(){ - return getIdElement().map(ASTDelegatePsiElement::getText).orElse(null); - } - - default String getId(String orElse){ - return getIdElement().map(ASTDelegatePsiElement::getText).orElse(orElse); - } - - default void setName(String name){ - getIdElement().ifPresent(id -> id.replace(PsiUtils.createIdFromText(this, name))); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrModifiersHolder.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrModifiersHolder.java deleted file mode 100644 index f78b6a5..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrModifiersHolder.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.comroid.kscr.intellij.psi.utils; - -import com.intellij.psi.PsiElement; - -import java.util.Optional; - -public interface KScrModifiersHolder extends PsiElement{ - - default Optional getModifiersElement(){ - return PsiUtils.childOfType(this, KScrModifierList.class); - } - - default boolean hasModifier(String modifier){ - return getModifiersElement().map(k -> k.hasModifier(modifier)).orElse(false); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrTypeReference.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrTypeReference.java deleted file mode 100644 index 92e25b2..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrTypeReference.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.comroid.kscr.intellij.psi.utils; - -import com.intellij.codeInsight.lookup.LookupElementBuilder; -import com.intellij.codeInspection.LocalQuickFix; -import com.intellij.codeInspection.LocalQuickFixProvider; -import com.intellij.lang.jvm.JvmClass; -import com.intellij.lang.jvm.JvmClassKind; -import com.intellij.lang.jvm.JvmModifier; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.PsiReference; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.search.PsiShortNamesCache; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.ui.JBColor; -import com.intellij.util.IncorrectOperationException; -import org.comroid.kscr.intellij.inspections.fixes.AddImportFix; -import org.comroid.kscr.intellij.psi.*; -import org.comroid.kscr.intellij.psi.types.KScrKind; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -public class KScrTypeReference implements PsiReference, LocalQuickFixProvider{ - - KScrId id; - KScrIdHolder from; - - public KScrTypeReference(KScrId id, KScrIdHolder from){ - this.id = id; - this.from = from; - } - - public @NotNull PsiElement getElement(){ - return from; - } - - public @NotNull TextRange getRangeInElement(){ - return id.getTextRangeInParent(); - } - - public @Nullable JvmClass resolveClass(){ - if(id == null) - return null; - var p = id.getProject(); - // possible names come from imports - var file = from.getContainingFile(); - if(file instanceof KScrFile) - return ProjectTypeFinder.firstType(p, getCandidates((KScrFile)file, id.getText())); - return ProjectTypeFinder.findByName(p, id.getText()).orElse(null); - } - - @NotNull - public static List getCandidates(KScrFile file, String id){ - Optional pkg = file.getPackage().map(KScrPackageStatement::getPackageName); - List candidates = file.getImports().stream() - .filter(x -> !x.isStatic()) - .map(x -> x.isWildcard() ? (x.getImportName() + "." + id) : (x.getImportName().endsWith(id) ? x.getImportName() : null)) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - candidates.add(0, id); - // TODO: all implicit imports - candidates.add(1, "java.lang." + id); - pkg.ifPresent(s -> candidates.add(2, s + "." + id)); - return candidates; - } - - public @Nullable PsiElement resolve(){ - var cClass = resolveClass(); - return cClass != null ? cClass.getSourceElement() : null; - } - - public @NotNull String getCanonicalText(){ - var cClass = resolveClass(); - return cClass != null ? cClass.getQualifiedName() : id.getText(); - } - - public PsiElement handleElementRename(@NotNull String name) throws IncorrectOperationException{ - from.setName(name); - return from; - } - - public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException{ - if(element instanceof KScrType){ - from.setName(((KScrType)element).fullyQualifiedName()); - return from; - } - throw new IncorrectOperationException("Can't bind a KScrBaseTypeRef to an element that is not a KScrTypeDef"); - } - - public boolean isReferenceTo(@NotNull PsiElement element){ - if(element instanceof KScrType) - return matchesType((KScrType)element); - return resolve() == element; - } - - public boolean isSoft(){ - return false; - } - - public boolean matchesType(KScrType typeDef){ - String ourId = id.getText(); - if(ourId == null || ourId.isBlank()) - return false; - if(from.getContainingFile() instanceof KScrFile){ - KScrFile file = (KScrFile)from.getContainingFile(); - Optional pkg = file.getPackage().map(KScrPackageStatement::getPackageName); - if(!pkg.map(String::isBlank).orElse(true) && typeDef.getPackageName().isBlank()){ - // we're not in the default package -> we can't reference it - return false; - } - String fqName = typeDef.fullyQualifiedName(); - // check if - // its FQ-name == our text (plus package name) - if(fqName.equals(ourId) || (pkg.isPresent() && (pkg.get() + "." + ourId).equals(fqName))) - return true; - // it's FQ-name == some import that ends in our text, - // it's FQ-name == a wildcard import + our text - // TODO: static imports for inner types - // TODO: also consider target's visibility - for(KScrImportStatement i : file.getImports()) - if(!i.isStatic()){ - String name = i.getImportName(); - if(i.isWildcard() && fqName.equals(name + "." + ourId)) - return true; - else if(name.endsWith(ourId) && fqName.equals(name)) - return true; - } - return false; - }else - return typeDef.fullyQualifiedName().equals(ourId); - } - - public LocalQuickFix @Nullable [] getQuickFixes(){ - // we resolve to nothing, see if there exists a type with the right short name - var shortName = id.getText(); - if(shortName.contains(".")) - return new LocalQuickFix[0]; - - var project = id.getProject(); - List candidates = ProjectTypeFinder.findAll(project, x -> x.getName().equals(shortName)); - candidates.addAll(Arrays.asList(PsiShortNamesCache.getInstance(project).getClassesByName(shortName, GlobalSearchScope.everythingScope(project)))); - - return candidates.stream() - .map(x -> new AddImportFix(x.getQualifiedName(), id)) - .toArray(LocalQuickFix[]::new); - } - - public Object @NotNull [] getVariants(){ - Predicate isWrongClause = (aClass) -> { - KScrType in; - if(PsiTreeUtil.getParentOfType(id, KScrImplementsClause.class) != null) - if(aClass.getClassKind() != JvmClassKind.INTERFACE) - return true; - if(PsiTreeUtil.getParentOfType(id, KScrExtendsClause.class) != null && (in = PsiTreeUtil.getParentOfType(id, KScrType.class)) != null) - return aClass.hasModifier(JvmModifier.FINAL) - || (in.kind() != KScrKind.INTERFACE && aClass.getClassKind() == JvmClassKind.INTERFACE) - || (in.kind() == KScrKind.INTERFACE && aClass.getClassKind() != JvmClassKind.INTERFACE) - || aClass.getClassKind() == JvmClassKind.ANNOTATION; - return false; - }; - - return fillCompletion(id, isWrongClause); - } - - public static Object @NotNull [] fillCompletion(KScrElement at, Predicate isWrongClause){ - List list = new ArrayList<>(); - for(JvmClass aClass : ProjectTypeFinder.allVisibleAt(at.getProject(), at)){ - boolean wrongClause = isWrongClause.test(aClass); - PsiElement decl = aClass.getSourceElement(); - if(decl != null){ - var fqName = aClass.getQualifiedName(); - LookupElementBuilder builder = LookupElementBuilder - .createWithIcon((PsiNamedElement)decl) - .withTailText(" " + JvmClassUtils.getPackageName(aClass)) - .withPsiElement(aClass.getSourceElement()) - .withInsertHandler((ctx, elem) -> { - if(ctx.getFile() instanceof KScrFile){ - KScrFile cFile = (KScrFile)ctx.getFile(); - if(cFile.getImports().stream().noneMatch(imp -> imp.importsType(aClass)) - && !KScrImportStatement.importsType("java.lang.*", fqName) - && !KScrImportStatement.importsType(cFile.getPackageName() + ".*", fqName)) - AddImportFix.addImport(cFile, fqName); - } - }); - if(wrongClause) - builder = builder.withItemTextForeground(JBColor.RED); - list.add(builder); - } - } - return list.toArray(); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrVarScope.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrVarScope.java deleted file mode 100644 index c5fb544..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrVarScope.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.comroid.kscr.intellij.psi.utils; - -import com.intellij.psi.PsiElement; -import com.intellij.psi.util.PsiTreeUtil; - -import java.util.List; -import java.util.Optional; - -public interface KScrVarScope extends PsiElement{ - - List available(); - - static Optional scopeOf(PsiElement e){ - return Optional.ofNullable(PsiTreeUtil.getParentOfType(e, KScrVarScope.class)); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrVariable.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrVariable.java deleted file mode 100644 index 92f1ad5..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/KScrVariable.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.comroid.kscr.intellij.psi.utils; - -import com.intellij.lang.jvm.types.JvmType; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.Nullable; - -public interface KScrVariable{ - - String varName(); - - JvmType varType(); - - boolean hasModifier(String modifier); - - @Nullable - default PsiElement declaration(){ - if(this instanceof PsiElement) - return (PsiElement)this; - return null; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/MethodUtils.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/MethodUtils.java deleted file mode 100644 index 54c226f..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/MethodUtils.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.comroid.kscr.intellij.psi.utils; - -import com.intellij.psi.PsiElement; -import org.comroid.kscr.intellij.psi.*; -import org.comroid.kscr.intellij.psi.expressions.KScrBinaryExpr; -import org.comroid.kscr.intellij.psi.expressions.KScrParenthesisedExpr; - -import java.util.ArrayList; -import java.util.List; - -public class MethodUtils{ - - public static List getRealArgs(KScrCall call){ - var declaredArgs = PsiUtils.childOfType(call, KScrArgumentsList.class) - .map(x -> PsiUtils.childrenOfType(x, KScrExpression.class)) - .orElse(List.of()); - if(call.getParent() instanceof KScrStatement) - return declaredArgs; - - var args = new ArrayList<>(declaredArgs); - PsiElement current = call.getParent(); - while(current instanceof KScrExpression){ - current = current.getParent(); - if(!(current instanceof KScrParenthesisedExpr || current instanceof KScrBinaryExpr)) - break; - if(current instanceof KScrBinaryExpr){ - var bin = (KScrBinaryExpr)current; - var symbol = bin.symbol(); - if(!symbol.equals("|>")) - break; - bin.left().ifPresent(x -> args.add(0, x)); - } - } - return args; - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/ProjectTypeFinder.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/ProjectTypeFinder.java deleted file mode 100644 index baf1dd4..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/ProjectTypeFinder.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.comroid.kscr.intellij.psi.utils; - -import com.intellij.lang.jvm.JvmClass; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.JavaPsiFacade; -import com.intellij.psi.PsiManager; -import com.intellij.psi.search.GlobalSearchScope; -import org.comroid.kscr.intellij.KScrFileType; -import org.comroid.kscr.intellij.KScrSourceFileType; -import org.comroid.kscr.intellij.psi.*; -import org.comroid.kscr.intellij.psi.types.JvmKScrClass; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Predicate; - -public class ProjectTypeFinder{ - - @Nullable - public static JvmClass firstType(Project p, List candidates){ - for(String candidate : candidates){ - var type = ProjectTypeFinder.findByName(p, candidate); - if(type.isPresent()) - return type.get(); - } - return null; - } - - public static List allVisibleAt(Project in, KScrElement at){ - // TODO: check visibility modifiers - var types = findAll(in, x -> true); - addTypesFromPackage(in, types, "java.lang"); - for(KScrImportStatement imp : at.getContainer().map(KScrFileWrapper::getImports).orElse(Collections.emptyList())){ - if(imp.isWildcard()) - addTypesFromPackage(in, types, imp.getImportName()); - else if(!imp.isWildcard()){ - var t = JavaPsiFacade.getInstance(in).findClass(imp.getImportName(), GlobalSearchScope.allScope(in)); - if(t != null) - types.add(t); - } - } - return types; - } - - private static void addTypesFromPackage(Project in, List types, String pkg){ - var aPackage = JavaPsiFacade.getInstance(in).findPackage(pkg); - if(aPackage != null) - types.addAll(Arrays.asList(aPackage.getClasses())); - } - - public static Optional findByName(Project in, String qualifiedName){ - // first check types in project - // can appear in any file due to inner types - return find(in, y -> y.fullyQualifiedName().equals(qualifiedName), null) - .or(() -> Optional.ofNullable(JavaPsiFacade.getInstance(in).findClass(qualifiedName, GlobalSearchScope.allScope(in)))); - } - - /** - * Checks every KScr type in a project and returns the first type found that matches the criteria, or an empty - * Optional if none exist. - * - * @param in - * The project to search in. - * @param checker - * The criteria to search against. - * @return The first type found that matches the criteria. - */ - public static Optional find(@NotNull Project in, @NotNull Predicate checker, @Nullable Predicate directCheck){ - AtomicReference> ret = new AtomicReference<>(Optional.empty()); - ProjectRootManager.getInstance(in).getFileIndex().iterateContent(vf -> { - if(directCheck != null && !directCheck.test(vf)) - return true; - if(!vf.isDirectory() && Objects.equals(vf.getExtension(), "KScr") && vf.getFileType() == KScrSourceFileType.FILE_TYPE){ - KScrFile file = (KScrFile)PsiManager.getInstance(in).findFile(vf); - if(file != null){ - var type = file.getTypeDef(); - if(type.isPresent()){ - var checked = checkTypeAndMembers(type.get(), checker); - if(checked.isPresent()){ - ret.set(checked); - return false; - } - } - } - } - return true; - }); - return ret.get(); - } - - public static List findAll(@NotNull Project in, @NotNull Predicate checker){ - List ret = new ArrayList<>(); - ProjectRootManager.getInstance(in).getFileIndex().iterateContent(vf -> { - if(!vf.isDirectory() && Objects.equals(vf.getExtension(), "KScr") && vf.getFileType() == KScrSourceFileType.FILE_TYPE){ - KScrFile file = (KScrFile)PsiManager.getInstance(in).findFile(vf); - if(file != null){ - var type = file.getTypeDef(); - if(type.isPresent()){ - var checked = checkTypeAndMembers(type.get(), checker); - if(checked.isPresent()){ - ret.add(checked.get()); - return true; // don't stop - } - } - } - } - return true; - }); - return ret; - } - - public static Optional checkTypeAndMembers(@NotNull KScrType type, @NotNull Predicate checker){ - if(checker.test(type)) - return Optional.of(JvmKScrClass.of(type)); - for(KScrMember member : type.getMembers()){ - Optional def = PsiUtils.childOfType(member, KScrType.class); - if(def.isPresent()){ - var r = checkTypeAndMembers(def.get(), checker); - if(r.isPresent()) - return r; - } - } - return Optional.empty(); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/PsiUtils.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/PsiUtils.java deleted file mode 100644 index ccb2c9a..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/psi/utils/PsiUtils.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.comroid.kscr.intellij.psi.utils; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFileFactory; -import com.intellij.psi.impl.PsiFileFactoryImpl; -import com.intellij.psi.tree.IElementType; -import org.comroid.kscr.intellij.KScrLanguage; -import org.comroid.kscr.intellij.antlr_generated.KScrLexer; -import org.comroid.kscr.intellij.antlr_generated.KScrParser; -import org.comroid.kscr.intellij.psi.Tokens; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class PsiUtils{ - - @NotNull - private static PsiElement createFromText(Project project, PsiElement context, String text, IElementType type){ - PsiFileFactoryImpl factory = (PsiFileFactoryImpl)PsiFileFactory.getInstance(project); - var ret = factory.createElementFromText(text, KScrLanguage.LANGUAGE, type, context); - assert ret != null; - return ret; - } - - @NotNull - public static PsiElement createFromText(@NotNull PsiElement context, String text, IElementType elementType){ - return createFromText(context.getProject(), context, text, elementType).getFirstChild(); - } - - // the ID token is understood in ParserAdaptor to mean a full ID - @NotNull - public static PsiElement createIdFromText(@NotNull PsiElement context, String text){ - return createFromText(context, text, Tokens.getFor(KScrLexer.ID)); - } - - @NotNull - public static PsiElement createIdPartFromText(@NotNull PsiElement context, String text){ - return createIdFromText(context, text).getFirstChild(); - } - - @NotNull - public static PsiElement createExpressionFromText(@NotNull PsiElement context, String text){ - return createFromText(context, text, Tokens.getRuleFor(KScrParser.RULE_expr)); - } - - @NotNull - public static PsiElement createImportFromText(@NotNull PsiElement context, String text){ - return createFromText(context, text, Tokens.getRuleFor(KScrParser.RULE_importDecl)); - } - - @NotNull - public static PsiElement createExtendsClauseFromText(@NotNull PsiElement context, String text){ - return createFromText(context, text, Tokens.getRuleFor(KScrParser.RULE_objectExtends)); - } - - @NotNull - public static PsiElement createImplementsClauseFromText(@NotNull PsiElement context, String text){ - return createFromText(context, text, Tokens.getRuleFor(KScrParser.RULE_objectImplements)); - } - - @NotNull - public static PsiElement createTypeReferenceFromText(@NotNull PsiElement context, String text){ - return createFromText(context, text, Tokens.getRuleFor(KScrParser.RULE_type)); - } - - @NotNull - public static PsiElement createWhitespace(@NotNull PsiElement context, String text){ - assert text.isBlank(); - return createFromText(context, text, Tokens.getFor(KScrLexer.ID)); - } - - @NotNull - public static List childrenOfType(@NotNull PsiElement parent, Class filter){ - return streamChildrenOfType(parent, filter) - .collect(Collectors.toList()); - } - - @NotNull - public static Stream streamChildrenOfType(@NotNull PsiElement parent, Class filter){ - return Arrays.stream(parent.getChildren()) - .filter(filter::isInstance) - .map(z -> (X)z); - } - - @NotNull - public static List wrappedChildrenOfType(@NotNull PsiElement parent, Class filter){ - return streamWrappedChildrenOfType(parent, filter) - .collect(Collectors.toList()); - } - - @NotNull - public static Stream streamWrappedChildrenOfType(@NotNull PsiElement parent, Class filter){ - return Arrays.stream(parent.getChildren()) - .map(PsiElement::getFirstChild) - .filter(filter::isInstance) - .map(z -> (X)z); - } - - @NotNull - public static List matchingChildren(@NotNull PsiElement parent, Predicate filter){ - return Arrays.stream(parent.getChildren()) - .filter(filter) - .collect(Collectors.toList()); - } - - @NotNull - public static Optional childOfType(@NotNull PsiElement parent, Class filter){ - return streamChildrenOfType(parent, filter).findFirst(); - } - - @NotNull - public static Optional childOfType(@NotNull PsiElement parent, Class filter, int index){ - var c = childrenOfType(parent, filter); - if(c.size() > index) - return Optional.of(c.get(index)); - else - return Optional.empty(); - } - - @NotNull - public static Optional wrappedChildOfType(@NotNull PsiElement parent, Class filter){ - return streamWrappedChildrenOfType(parent, filter).findFirst(); - } - - @NotNull - public static Optional wrappedChildOfType(@NotNull PsiElement parent, Class filter, int index){ - var c = wrappedChildrenOfType(parent, filter); - if(c.size() > index) - return Optional.of(c.get(index)); - else - return Optional.empty(); - } -} \ No newline at end of file diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/KScrSdkType.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/KScrSdkType.java deleted file mode 100644 index 585225c..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/KScrSdkType.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.comroid.kscr.intellij.sdk; - -import com.intellij.openapi.projectRoots.*; -import org.jdom.Element; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.util.Arrays; - -public class KScrSdkType extends SdkType { - public static final KScrSdkType INSTANCE = new KScrSdkType(); - - public KScrSdkType() { - super("KScrSDK"); - } - - @Override - public @Nullable String suggestHomePath() { - return File.separator + "dev" + File.separator + "sdk" + File.separator + "kscr"; - } - - @Override - public boolean isValidSdkHome(@NotNull String path) { - File f = new File(path); - File[] array = f.listFiles(); - if (array == null) - return false; - return f.exists() && Arrays.stream(array).anyMatch(x -> x.getName().equals("kscr.exe")); - } - - @Override - public @NotNull String suggestSdkName(@Nullable String currentSdkName, @NotNull String sdkHome) { - return currentSdkName == null ? getName() : currentSdkName; - } - - @Override - public @NotNull @Nls(capitalization = Nls.Capitalization.Title) String getPresentableName() { - return getName(); - } - - @Override - public @Nullable AdditionalDataConfigurable createAdditionalDataConfigurable(@NotNull SdkModel sdkModel, @NotNull SdkModificator sdkModificator) { - return null; - } - - @Override - public void saveAdditionalData(@NotNull SdkAdditionalData additionalData, @NotNull Element additional) { - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/config/KScrLanguageConfiguration.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/config/KScrLanguageConfiguration.java deleted file mode 100644 index 22bb2c7..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/config/KScrLanguageConfiguration.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.comroid.kscr.intellij.sdk.config; - -import com.intellij.openapi.options.Configurable; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.util.NlsContexts; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; - -public class KScrLanguageConfiguration implements Configurable { - @Override - public @NlsContexts.ConfigurableName String getDisplayName() { - return "KScr"; - } - - @Override - public @Nullable JComponent createComponent() { - return null; - } - - @Override - public boolean isModified() { - return false; - } - - @Override - public void apply() throws ConfigurationException { - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/KScrModuleBuilder.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/KScrModuleBuilder.java deleted file mode 100644 index be7bf8b..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/KScrModuleBuilder.java +++ /dev/null @@ -1,170 +0,0 @@ -package org.comroid.kscr.intellij.sdk.module; - -import com.intellij.ide.NewProjectWizardLegacy; -import com.intellij.ide.util.projectWizard.*; -import com.intellij.openapi.module.ModifiableModuleModel; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleType; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.projectRoots.SdkTypeId; -import com.intellij.openapi.roots.*; -import com.intellij.openapi.roots.libraries.Library; -import com.intellij.openapi.roots.libraries.LibraryTable; -import com.intellij.openapi.roots.ui.configuration.ModulesProvider; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import org.comroid.kscr.intellij.sdk.KScrSdkType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class KScrModuleBuilder extends ModuleBuilder implements SourcePathsBuilder, ModuleBuilderListener { - private final KScrModuleType moduleType; - // Pair - private List> srcPaths; - // Pair - private List> libraries; - - @Override - public List> getSourcePaths() throws ConfigurationException { - if (srcPaths == null){ - final List> paths = new ArrayList<>(); - final String path = getContentEntryPath() + File.separator + "src" + File.separator + "main"; - new File(path).mkdirs(); - paths.add(Pair.create(path, "")); - return paths; - } - return srcPaths; - } - - @Override - public void setSourcePaths(List> sourcePaths) { - srcPaths = sourcePaths == null ? null : new ArrayList<>(sourcePaths); - } - - @Override - public void addSourcePath(Pair sourcePathInfo) { - if (srcPaths == null) - srcPaths = new ArrayList<>(); - srcPaths.add(sourcePathInfo); - } - - @Override - public boolean isAvailable() { - return NewProjectWizardLegacy.isAvailable(); - } - - @Override - public boolean isSuitableSdkType(SdkTypeId sdkType) { - return sdkType instanceof KScrSdkType; - } - - public KScrModuleBuilder(KScrModuleType moduleType) { - this.moduleType = moduleType; - } - - @Override - public ModuleType getModuleType() { - return moduleType; - } - - @Override - public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, @NotNull ModulesProvider modulesProvider) { - - } - - @Override - public void setupRootModel(@NotNull ModifiableRootModel rootModel) throws ConfigurationException { - final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class); - compilerModuleExtension.setExcludeOutput(true); - if (myJdk != null){ - rootModel.setSdk(myJdk); - } else { - rootModel.inheritSdk(); - } - - ContentEntry contentEntry = doAddContentEntry(rootModel); - if (contentEntry != null) { - final List> sourcePaths = getSourcePaths(); - - if (sourcePaths != null) { - for (final Pair sourcePath : sourcePaths) { - String first = sourcePath.first; - new File(first).mkdirs(); - final VirtualFile sourceRoot = LocalFileSystem.getInstance() - .refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first)); - if (sourceRoot != null) { - contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second); - } - } - } - } - - if (myCompilerOutputPath != null) { - // should set only absolute paths - String canonicalPath; - try { - canonicalPath = FileUtil.resolveShortWindowsName(myCompilerOutputPath); - } - catch (IOException e) { - canonicalPath = myCompilerOutputPath; - } - compilerModuleExtension - .setCompilerOutputPath(VfsUtilCore.pathToUrl(canonicalPath)); - } - else { - compilerModuleExtension.inheritCompilerOutputPath(true); - } - - LibraryTable libraryTable = rootModel.getModuleLibraryTable(); - for (Pair libInfo : myModuleLibraries) { - final String moduleLibraryPath = libInfo.first; - final String sourceLibraryPath = libInfo.second; - Library library = libraryTable.createLibrary(); - Library.ModifiableModel modifiableModel = library.getModifiableModel(); - modifiableModel.addRoot(getUrlByPath(moduleLibraryPath), OrderRootType.CLASSES); - if (sourceLibraryPath != null) { - modifiableModel.addRoot(getUrlByPath(sourceLibraryPath), OrderRootType.SOURCES); - } - modifiableModel.commit(); - } - } - - @Nullable - @Override - public List commit(@NotNull Project project, ModifiableModuleModel model, ModulesProvider modulesProvider) { - LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(ProjectManager.getInstance().getDefaultProject()); - Boolean aDefault = extension.getDefault(); - LOG.debug("commit: aDefault=" + aDefault); - LanguageLevelProjectExtension instance = LanguageLevelProjectExtension.getInstance(project); - if (aDefault != null && !aDefault) { - instance.setLanguageLevel(extension.getLanguageLevel()); - } - else { - //setup language level according to jdk, then setup default flag - Sdk sdk = ProjectRootManager.getInstance(project).getProjectSdk(); - LOG.debug("commit: projectSdk=" + sdk); - if (sdk != null) { - JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk); - LOG.debug("commit: sdk.version=" + version); - if (version != null) { - instance.setLanguageLevel(version.getMaxLanguageLevel()); - instance.setDefault(true); - } - } - } - return super.commit(project, model, modulesProvider); - } - - @Override - public void moduleCreated(@NotNull Module module) { - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/KScrModuleType.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/KScrModuleType.java deleted file mode 100644 index 64f8c2d..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/KScrModuleType.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.comroid.kscr.intellij.sdk.module; - -import com.intellij.openapi.module.ModuleType; -import com.intellij.util.PlatformIcons; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; - -public class KScrModuleType extends ModuleType { - public static final KScrModuleType INSTANCE = new KScrModuleType(); - - protected KScrModuleType() { - super("KScrModule"); - } - - @NotNull - @Override - public KScrModuleBuilder createModuleBuilder() { - return new KScrModuleBuilder(this); - } - - @Override - public @NotNull @Nls(capitalization = Nls.Capitalization.Title) String getName() { - return "KScr Project"; - } - - @Override - public @NotNull @Nls(capitalization = Nls.Capitalization.Sentence) String getDescription() { - return "KScr source project; class library or application"; - } - - @Override - public @NotNull Icon getNodeIcon(boolean isOpened) { - return isOpened ? PlatformIcons.LIBRARY_ICON : PlatformIcons.FOLDER_ICON; - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/wizard/KScrWizardStep.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/wizard/KScrWizardStep.java deleted file mode 100644 index b28ec7e..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/wizard/KScrWizardStep.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.comroid.kscr.intellij.sdk.module.wizard; - -import com.intellij.ide.util.projectWizard.ModuleWizardStep; -import com.intellij.ui.wizard.WizardStep; - -import javax.swing.*; - -public class KScrWizardStep extends ModuleWizardStep { - @Override - public JComponent getComponent() { - return null; - } - - @Override - public void updateDataModel() { - - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/wizard/panel/KScrInstallSdkComboBox.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/wizard/panel/KScrInstallSdkComboBox.java deleted file mode 100644 index 5618516..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/wizard/panel/KScrInstallSdkComboBox.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.comroid.kscr.intellij.sdk.module.wizard.panel; - -public class KScrInstallSdkComboBox { -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/wizard/panel/KScrInstallSdkPanel.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/wizard/panel/KScrInstallSdkPanel.java deleted file mode 100644 index 98d0c59..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/sdk/module/wizard/panel/KScrInstallSdkPanel.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.comroid.kscr.intellij.sdk.module.wizard.panel; - -import com.google.gson.JsonElement; -import com.intellij.ide.util.PropertiesComponent; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.application.AccessToken; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.fileChooser.FileChooser; -import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.fileChooser.FileChooserFactory; -import com.intellij.openapi.fileChooser.PathChooserDialog; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.vfs.VfsUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.ui.components.ActionLink; -import com.intellij.util.download.DownloadableFileDescription; -import com.intellij.util.download.DownloadableFileService; -import com.intellij.util.download.FileDownloader; -import com.intellij.util.io.HttpRequests; -import com.intellij.util.io.ZipUtil; -import org.comroid.kscr.intellij.util.RequestUtil; - -import javax.swing.*; -import java.awt.*; -import java.io.FilenameFilter; -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; -import java.util.stream.StreamSupport; - -public class KScrInstallSdkPanel extends JPanel { - public static final String LAST_USED_KSCR_HOME = "LAST_USED_KSCR_HOME"; - private ActionLink myDownloadLink; - private JPanel myRoot; - private KScrInstallSdkComboBox mySdkComboBox; - - public KScrInstallSdkPanel() { - super(new BorderLayout()); - add(myRoot, BorderLayout.CENTER); - } - - private void createUIComponents() { - myDownloadLink = new ActionLink("Download and Install KScr SDK", event -> { - FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false); - PathChooserDialog pathChooser = FileChooserFactory.getInstance() - .createPathChooser(descriptor, null, KScrInstallSdkPanel.this); - pathChooser.choose(VfsUtil.getUserHomeDir(), new FileChooser.FileChooserConsumer() { - @Override - public void cancelled() { - } - - @Override - public void consume(List virtualFiles) { - if (virtualFiles.size() == 1) { - VirtualFile dir = virtualFiles.get(0); - String dirName = dir.getName(); - try { - if (!dirName.toLowerCase().contains("smalltalk") && !dirName.toLowerCase().contains("redline")) { - try { - dir = dir.createChildDirectory(this, "RedlineSmalltalk"); - } catch (IOException e) {// - } - } - var url = StreamSupport.stream(HttpRequests.request("https://api.github.com/repos/comroid-git/KScr/releases") - .accept("application/json") - .connect(RequestUtil::parseJson).getAsJsonArray() - .get(0).getAsJsonObject() - .get("assets").getAsJsonArray() - .spliterator(), false) - .map(JsonElement::getAsJsonObject) - .filter(asset -> asset.get("name").getAsString().endsWith(".zip")) - .findFirst() - .map(asset -> asset.get("browser_download_url").getAsString()) - .orElseThrow(() -> new RuntimeException("Could not find latest KScr release")); - var split = url.lastIndexOf('/'); - String urlDir = url.substring(0, split); - String urlFile = url.substring(split + 1); - var fileService = DownloadableFileService.getInstance(); - var fileDescription = fileService.createFileDescription(urlDir, urlFile); - var downloader = fileService.createDownloader(List.of(fileDescription), "KScr Distribution"); - var files = downloader.download(Path.of(System.getProperty("java.io.tmpdir"), "kscr-dist/").toFile()); - if (files.size() == 1) { - ZipUtil.extract(files.get(0).first.toPath(), dir.toNioPath(), (parent, file) -> true); - PropertiesComponent.getInstance().setValue(LAST_USED_KSCR_HOME, dir.getPath()); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - }}); - }); - } - - public String getSdkName() { - final Sdk selectedSdk = mySdkComboBox.getSelectedSdk(); - return selectedSdk == null ? null : selectedSdk.getName(); - } - - public Sdk getSdk() { - return mySdkComboBox.getSelectedSdk(); - } - - public void setSdk(Sdk sdk) { - mySdkComboBox.getComboBox().setSelectedItem(sdk); - } -} diff --git a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/util/RequestUtil.java b/kscr-intellij/src/main/java/org/comroid/kscr/intellij/util/RequestUtil.java deleted file mode 100644 index 4fa6817..0000000 --- a/kscr-intellij/src/main/java/org/comroid/kscr/intellij/util/RequestUtil.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.comroid.kscr.intellij.util; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.intellij.util.io.HttpRequests; - -import java.io.IOException; - -public final class RequestUtil { - public static JsonElement parseJson(HttpRequests.Request request) throws IOException { - String data = request.readString(); - return new Gson().toJsonTree(data); - } -} diff --git a/kscr-intellij/src/main/resources/META-INF/plugin.xml b/kscr-intellij/src/main/resources/META-INF/plugin.xml deleted file mode 100644 index 33ef20c..0000000 --- a/kscr-intellij/src/main/resources/META-INF/plugin.xml +++ /dev/null @@ -1,138 +0,0 @@ - - org.comroid.KScrIntelliJPlugin - KScr Language - comroid - - - - com.intellij.modules.platform - com.intellij.modules.lang - com.intellij.java - - org.jetbrains.plugins.yaml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/kscr-intellij/src/main/resources/fileTemplates/KScr Annotation.kscr.ft b/kscr-intellij/src/main/resources/fileTemplates/KScr Annotation.kscr.ft deleted file mode 100644 index 3b17dd0..0000000 --- a/kscr-intellij/src/main/resources/fileTemplates/KScr Annotation.kscr.ft +++ /dev/null @@ -1,5 +0,0 @@ -package ${PACKAGE_NAME}; - -public annotation ${NAME} { - -} \ No newline at end of file diff --git a/kscr-intellij/src/main/resources/fileTemplates/KScr Class.kscr.ft b/kscr-intellij/src/main/resources/fileTemplates/KScr Class.kscr.ft deleted file mode 100644 index cd2a7d7..0000000 --- a/kscr-intellij/src/main/resources/fileTemplates/KScr Class.kscr.ft +++ /dev/null @@ -1,5 +0,0 @@ -package ${PACKAGE_NAME}; - -public class ${NAME} { - -} \ No newline at end of file diff --git a/kscr-intellij/src/main/resources/fileTemplates/KScr Enum.kscr.ft b/kscr-intellij/src/main/resources/fileTemplates/KScr Enum.kscr.ft deleted file mode 100644 index 3d814f8..0000000 --- a/kscr-intellij/src/main/resources/fileTemplates/KScr Enum.kscr.ft +++ /dev/null @@ -1,5 +0,0 @@ -package ${PACKAGE_NAME}; - -public enum ${NAME} { - -} \ No newline at end of file diff --git a/kscr-intellij/src/main/resources/fileTemplates/KScr Interface.kscr.ft b/kscr-intellij/src/main/resources/fileTemplates/KScr Interface.kscr.ft deleted file mode 100644 index 2cd74d8..0000000 --- a/kscr-intellij/src/main/resources/fileTemplates/KScr Interface.kscr.ft +++ /dev/null @@ -1,5 +0,0 @@ -package ${PACKAGE_NAME}; - -public interface ${NAME} { - -} \ No newline at end of file diff --git a/kscr-intellij/src/main/resources/inspectionDescriptions/InvalidTypeName.html b/kscr-intellij/src/main/resources/inspectionDescriptions/InvalidTypeName.html deleted file mode 100644 index 045fdac..0000000 --- a/kscr-intellij/src/main/resources/inspectionDescriptions/InvalidTypeName.html +++ /dev/null @@ -1,8 +0,0 @@ - - -Reports unresolved type references, such as an occurrence of the expression `X.class` without the type `X` being visible or imported. - - - - - \ No newline at end of file diff --git a/kscr-intellij/src/main/resources/inspectionDescriptions/WrongFileNameForTypeName.html b/kscr-intellij/src/main/resources/inspectionDescriptions/WrongFileNameForTypeName.html deleted file mode 100644 index 40ad42b..0000000 --- a/kscr-intellij/src/main/resources/inspectionDescriptions/WrongFileNameForTypeName.html +++ /dev/null @@ -1,8 +0,0 @@ - - -Reports classes that have a different names to their enclosing file, such as class T; in a file named B.cyc. - - - - - \ No newline at end of file diff --git a/kscr-intellij/src/main/resources/pluginIcon.svg b/kscr-intellij/src/main/resources/pluginIcon.svg deleted file mode 100644 index 31c66f8..0000000 --- a/kscr-intellij/src/main/resources/pluginIcon.svg +++ /dev/null @@ -1,32 +0,0 @@ - - - - - kscr - - diff --git a/kscr-lang-server/CompletionHandler.cs b/kscr-lang-server/CompletionHandler.cs new file mode 100644 index 0000000..8bac2fc --- /dev/null +++ b/kscr-lang-server/CompletionHandler.cs @@ -0,0 +1,141 @@ +using Antlr4.Runtime; +using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Document; +using OmniSharp.Extensions.LanguageServer.Protocol.Server; + +namespace KScr.LangServer; + +public class CompletionHandler : ICompletionHandler +{ + + private const string PackageReferenceElement = "PackageReference"; + private const string IncludeAttribute = "Include"; + private const string VersionAttribute = "Version"; + + private readonly ILanguageServer _router; + private readonly BufferManager _bufferManager; + private readonly NuGetAutoCompleteService _nuGetService; + + private readonly DocumentSelector _documentSelector = new DocumentSelector( + new DocumentFilter() + { + Pattern = "**/*.csproj" + } + ); + + private CompletionCapability _capability; + + public CompletionHandler(ILanguageServer router, BufferManager bufferManager, NuGetAutoCompleteService nuGetService) + { + _router = router; + _bufferManager = bufferManager; + _nuGetService = nuGetService; + } + + public CompletionRegistrationOptions GetRegistrationOptions() + { + return new CompletionRegistrationOptions + { + DocumentSelector = _documentSelector, + ResolveProvider = false + }; + } + + public async Task Handle(CompletionParams request, CancellationToken cancellationToken) + { + var documentPath = request.TextDocument.Uri.ToString(); + var buffer = _bufferManager.GetBuffer(documentPath); + + if (buffer == null) + { + return new CompletionList(); + } + + var syntaxTree = Parser.Parse(buffer); + + var position = GetPosition(buffer.GetText(0, buffer.Length), + (int)request.Position.Line, + (int)request.Position.Character); + + var node = syntaxTree.FindNode(position); + + var attribute = node.AncestorNodes().OfType().FirstOrDefault(); + if (attribute != null && node.ParentElement.Name.Equals(PackageReferenceElement)) + { + if (attribute.Name.Equals(IncludeAttribute)) + { + var completions = await _nuGetService.GetPackages(attribute.Value); + + var diff = position - attribute.ValueNode.Start; + + return new CompletionList(completions.Select(x => new CompletionItem + { + Label = x, + Kind = CompletionItemKind.Reference, + TextEdit = new TextEdit + { + NewText = x, + Range = new Range( + new Position + { + Line = request.Position.Line, + Character = request.Position.Character - diff + 1 + }, new Position + { + Line = request.Position.Line, + Character = request.Position.Character - diff + attribute.ValueNode.Width - 1 + }) + } + }), isIncomplete: completions.Count > 1); + } + else if (attribute.Name.Equals(VersionAttribute)) + { + var includeNode = node.ParentElement.Attributes.FirstOrDefault(x => x.Name.Equals(IncludeAttribute)); + + if (includeNode != null && !string.IsNullOrEmpty(includeNode.Value)) + { + var versions = await _nuGetService.GetPackageVersions(includeNode.Value, attribute.Value); + + var diff = position - attribute.ValueNode.Start; + + return new CompletionList(versions.Select(x => new CompletionItem + { + Label = x, + Kind = CompletionItemKind.Reference, + TextEdit = new TextEdit + { + NewText = x, + Range = new Range( + new Position + { + Line = request.Position.Line, + Character = request.Position.Character - diff + 1 + }, new Position + { + Line = request.Position.Line, + Character = request.Position.Character - diff + attribute.ValueNode.Width - 1 + }) + } + })); + } + } + } + + return new CompletionList(); + } + + private static int GetPosition(string buffer, int line, int col) + { + var position = 0; + for (var i = 0; i < line; i++) + { + position = buffer.IndexOf('\n', position) + 1; + } + return position + col; + } + + public void SetCapability(CompletionCapability capability) + { + _capability = capability; + } +} \ No newline at end of file diff --git a/kscr-lang-server/DidChangeWatchedFilesHandler.cs b/kscr-lang-server/DidChangeWatchedFilesHandler.cs new file mode 100644 index 0000000..ce8683a --- /dev/null +++ b/kscr-lang-server/DidChangeWatchedFilesHandler.cs @@ -0,0 +1,15 @@ +using MediatR; +using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; +using OmniSharp.Extensions.LanguageServer.Protocol.Workspace; + +namespace KScr.LangServer; + +internal class DidChangeWatchedFilesHandler : IDidChangeWatchedFilesHandler +{ + public DidChangeWatchedFilesRegistrationOptions GetRegistrationOptions() => new DidChangeWatchedFilesRegistrationOptions(); + + public Task Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken) => Unit.Task; + + public DidChangeWatchedFilesRegistrationOptions GetRegistrationOptions(DidChangeWatchedFilesCapability capability, ClientCapabilities clientCapabilities) => new DidChangeWatchedFilesRegistrationOptions(); +} \ No newline at end of file diff --git a/kscr-lang-server/FoldingRangeHandler.cs b/kscr-lang-server/FoldingRangeHandler.cs new file mode 100644 index 0000000..2489c00 --- /dev/null +++ b/kscr-lang-server/FoldingRangeHandler.cs @@ -0,0 +1,33 @@ +using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Document; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; + +namespace KScr.LangServer; + +internal class FoldingRangeHandler : IFoldingRangeHandler +{ + public FoldingRangeRegistrationOptions GetRegistrationOptions() => + new FoldingRangeRegistrationOptions { + DocumentSelector = DocumentSelector.ForLanguage("csharp") + }; + + public Task?> Handle( + FoldingRangeRequestParam request, + CancellationToken cancellationToken + ) => + Task.FromResult?>( + new Container( + new FoldingRange { + StartLine = 10, + EndLine = 20, + Kind = FoldingRangeKind.Region, + EndCharacter = 0, + StartCharacter = 0 + } + ) + ); + + public FoldingRangeRegistrationOptions GetRegistrationOptions(FoldingRangeCapability capability, ClientCapabilities clientCapabilities) => new FoldingRangeRegistrationOptions { + DocumentSelector = DocumentSelector.ForLanguage("csharp") + }; +} \ No newline at end of file diff --git a/kscr-lang-server/KScrFileSyncHandler.cs b/kscr-lang-server/KScrFileSyncHandler.cs new file mode 100644 index 0000000..3db81b4 --- /dev/null +++ b/kscr-lang-server/KScrFileSyncHandler.cs @@ -0,0 +1,81 @@ +using System.Collections.Concurrent; +using MediatR; +using OmniSharp.Extensions.LanguageServer.Protocol; +using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Document; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; +using OmniSharp.Extensions.LanguageServer.Protocol.Server; +using OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Window; + +namespace KScr.LangServer; + +public class KScrFileSyncHandler : ITextDocumentSyncHandler +{ + private readonly ILanguageServer _router; + private readonly BufferManager _bufferManager; + + private readonly DocumentSelector _documentSelector = new DocumentSelector( + new DocumentFilter() + { + Pattern = "**/*.csproj" + } + ); + + private SynchronizationCapability _capability; + + public KScrFileSyncHandler(ILanguageServer router, BufferManager bufferManager) + { + _router = router; + _bufferManager = bufferManager; + } + + public TextDocumentSyncKind Change { get; } = TextDocumentSyncKind.Full; + + public TextDocumentChangeRegistrationOptions GetRegistrationOptions() + { + return new TextDocumentChangeRegistrationOptions() + { + DocumentSelector = _documentSelector, + SyncKind = Change + }; + } + + public TextDocumentAttributes GetTextDocumentAttributes(Uri uri) + { + return new TextDocumentAttributes(uri, "xml"); + } + + public Task Handle(DidChangeTextDocumentParams request, CancellationToken cancellationToken) + { + var documentPath = request.TextDocument.Uri.ToString(); + var text = request.ContentChanges.FirstOrDefault()?.Text; + + _bufferManager.UpdateBuffer(documentPath, text); + + _router.Window.LogInfo($"Updated buffer for document: {documentPath}\n{text}"); + + return Unit.Task; + } + + public Task Handle(DidOpenTextDocumentParams request, CancellationToken cancellationToken) + { + _bufferManager.UpdateBuffer(request.TextDocument.Uri.ToString(), request.TextDocument.Text); + return Unit.Task; + } +} + +public class BufferManager +{ + private ConcurrentDictionary _buffers = new(); + + public void UpdateBuffer(string documentPath, string buffer) + { + _buffers.AddOrUpdate(documentPath, buffer, (k, v) => buffer); + } + + public string? GetBuffer(string documentPath) + { + return _buffers.TryGetValue(documentPath, out var buffer) ? buffer : null; + } +} \ No newline at end of file diff --git a/kscr-lang-server/KScrLangServer.cs b/kscr-lang-server/KScrLangServer.cs index 8326501..d5bba64 100644 --- a/kscr-lang-server/KScrLangServer.cs +++ b/kscr-lang-server/KScrLangServer.cs @@ -1,9 +1,30 @@ -namespace KScr.LangServer; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using OmniSharp.Extensions.LanguageServer.Server; + +namespace KScr.LangServer; public static class KScrLangServer { - public static void Main(string[] args) + public static async Task Main(string[] args) + { + var server = await LanguageServer.From(options => + options + .WithInput(Console.OpenStandardInput()) + .WithOutput(Console.OpenStandardOutput()) + .WithLoggerFactory(new LoggerFactory()) + .AddDefaultLoggingProvider() + //.WithMinimumLogLevel(LogLevel.Trace) + .WithServices(ConfigureServices) + .WithHandler() + .WithHandler() + ); + + await server.WaitForExit; + } + + static void ConfigureServices(IServiceCollection services) { - throw new NotImplementedException("Language Server is not implemented"); + services.AddSingleton(); } } \ No newline at end of file diff --git a/kscr-lang-server/Program.cs b/kscr-lang-server/Program.cs new file mode 100644 index 0000000..bbdc5df --- /dev/null +++ b/kscr-lang-server/Program.cs @@ -0,0 +1,179 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Linq; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; +using OmniSharp.Extensions.LanguageServer.Server; + +// ReSharper disable UnusedParameter.Local + +namespace KScr.LangServer; + +internal class Program +{ + private static void Main(string[] args) + { + MainAsync(args).Wait(); + } + + private static async Task MainAsync(string[] args) + { + // Debugger.Launch(); + // while (!Debugger.IsAttached) + // { + // await Task.Delay(100); + // } + + IObserver workDone = null!; + + var server = await LanguageServer.From( + options => + options + .WithInput(Console.OpenStandardInput()) + .WithOutput(Console.OpenStandardOutput()) + .ConfigureLogging( + x => x + .AddLanguageProtocolLogging() + .SetMinimumLevel(LogLevel.Debug) + ) + .WithHandler() + .WithHandler() + .WithHandler() + .WithHandler() + .WithHandler() + .WithHandler() + .WithServices(x => x.AddLogging(b => b.SetMinimumLevel(LogLevel.Trace))) + .WithServices( + services => + { + services.AddSingleton( + provider => + { + var loggerFactory = provider.GetService(); + var logger = loggerFactory.CreateLogger(); + + logger.LogInformation("Configuring"); + + return new Foo(logger); + } + ); + services.AddSingleton( + new ConfigurationItem + { + Section = "typescript", + } + ).AddSingleton( + new ConfigurationItem + { + Section = "terminal", + } + ); + } + ) + .OnInitialize( + async (server, request, token) => + { + var manager = server.WorkDoneManager.For( + request, new WorkDoneProgressBegin + { + Title = "Server is starting...", + Percentage = 10, + } + ); + workDone = manager; + + await Task.Delay(2000).ConfigureAwait(false); + + manager.OnNext( + new WorkDoneProgressReport + { + Percentage = 20, + Message = "loading in progress" + } + ); + } + ) + .OnInitialized( + async (server, request, response, token) => + { + workDone.OnNext( + new WorkDoneProgressReport + { + Percentage = 40, + Message = "loading almost done", + } + ); + + await Task.Delay(2000).ConfigureAwait(false); + + workDone.OnNext( + new WorkDoneProgressReport + { + Message = "loading done", + Percentage = 100, + } + ); + workDone.OnCompleted(); + } + ) + .OnStarted( + async (languageServer, token) => + { + using var manager = await languageServer.WorkDoneManager.Create(new WorkDoneProgressBegin { Title = "Doing some work..." }) + .ConfigureAwait(false); + + manager.OnNext(new WorkDoneProgressReport { Message = "doing things..." }); + await Task.Delay(10000).ConfigureAwait(false); + manager.OnNext(new WorkDoneProgressReport { Message = "doing things... 1234" }); + await Task.Delay(10000).ConfigureAwait(false); + manager.OnNext(new WorkDoneProgressReport { Message = "doing things... 56789" }); + + var logger = languageServer.Services.GetService>(); + var configuration = await languageServer.Configuration.GetConfiguration( + new ConfigurationItem + { + Section = "typescript", + }, new ConfigurationItem + { + Section = "terminal", + } + ).ConfigureAwait(false); + + var baseConfig = new JObject(); + foreach (var config in languageServer.Configuration.AsEnumerable()) + { + baseConfig.Add(config.Key, config.Value); + } + + logger.LogInformation("Base Config: {@Config}", baseConfig); + + var scopedConfig = new JObject(); + foreach (var config in configuration.AsEnumerable()) + { + scopedConfig.Add(config.Key, config.Value); + } + + logger.LogInformation("Scoped Config: {@Config}", scopedConfig); + } + ) + ).ConfigureAwait(false); + + await server.WaitForExit.ConfigureAwait(false); + } +} + +internal class Foo +{ + private readonly ILogger _logger; + + public Foo(ILogger logger) + { + logger.LogInformation("inside ctor"); + _logger = logger; + } + + public void SayFoo() + { + _logger.LogInformation("Fooooo!"); + } +} \ No newline at end of file diff --git a/kscr-lang-server/SemanticTokensHandler.cs b/kscr-lang-server/SemanticTokensHandler.cs new file mode 100644 index 0000000..5cc1578 --- /dev/null +++ b/kscr-lang-server/SemanticTokensHandler.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using OmniSharp.Extensions.LanguageServer.Protocol; +using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Document; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; + +namespace KScr.LangServer; + +#pragma warning disable 618 +public class SemanticTokensHandler : SemanticTokensHandlerBase +{ + private readonly ILogger _logger; + + public SemanticTokensHandler(ILogger logger) + { + _logger = logger; + } + + public override async Task Handle( + SemanticTokensParams request, CancellationToken cancellationToken + ) + { + var result = await base.Handle(request, cancellationToken).ConfigureAwait(false); + return result; + } + + public override async Task Handle( + SemanticTokensRangeParams request, CancellationToken cancellationToken + ) + { + var result = await base.Handle(request, cancellationToken).ConfigureAwait(false); + return result; + } + + public override async Task Handle( + SemanticTokensDeltaParams request, + CancellationToken cancellationToken + ) + { + var result = await base.Handle(request, cancellationToken).ConfigureAwait(false); + return result; + } + + protected override async Task Tokenize( + SemanticTokensBuilder builder, ITextDocumentIdentifierParams identifier, + CancellationToken cancellationToken + ) + { + using var typesEnumerator = RotateEnum(SemanticTokenType.Defaults).GetEnumerator(); + using var modifiersEnumerator = RotateEnum(SemanticTokenModifier.Defaults).GetEnumerator(); + // you would normally get this from a common source that is managed by current open editor, current active editor, etc. + var content = await File.ReadAllTextAsync(DocumentUri.GetFileSystemPath(identifier), cancellationToken).ConfigureAwait(false); + await Task.Yield(); + + foreach (var (line, text) in content.Split('\n').Select((text, line) => ( line, text ))) + { + var parts = text.TrimEnd().Split(';', ' ', '.', '"', '(', ')'); + var index = 0; + foreach (var part in parts) + { + typesEnumerator.MoveNext(); + modifiersEnumerator.MoveNext(); + if (string.IsNullOrWhiteSpace(part)) continue; + index = text.IndexOf(part, index, StringComparison.Ordinal); + builder.Push(line, index, part.Length, typesEnumerator.Current, modifiersEnumerator.Current); + } + } + } + + protected override Task + GetSemanticTokensDocument(ITextDocumentIdentifierParams @params, CancellationToken cancellationToken) + { + return Task.FromResult(new SemanticTokensDocument(RegistrationOptions.Legend)); + } + + + private IEnumerable RotateEnum(IEnumerable values) + { + while (true) + { + foreach (var item in values) + yield return item; + } + } + + protected override SemanticTokensRegistrationOptions CreateRegistrationOptions( + SemanticTokensCapability capability, ClientCapabilities clientCapabilities + ) + { + return new SemanticTokensRegistrationOptions + { + DocumentSelector = DocumentSelector.ForLanguage("csharp"), + Legend = new SemanticTokensLegend + { + TokenModifiers = capability.TokenModifiers, + TokenTypes = capability.TokenTypes + }, + Full = new SemanticTokensCapabilityRequestFull + { + Delta = true + }, + Range = true + }; + } +} +#pragma warning restore 618 \ No newline at end of file diff --git a/kscr-lang-server/TextDocumentHandler.cs b/kscr-lang-server/TextDocumentHandler.cs new file mode 100644 index 0000000..b16dcf1 --- /dev/null +++ b/kscr-lang-server/TextDocumentHandler.cs @@ -0,0 +1,252 @@ +using MediatR; +using Microsoft.Extensions.Logging; +using OmniSharp.Extensions.LanguageServer.Protocol; +using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Document; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; +using OmniSharp.Extensions.LanguageServer.Protocol.Progress; +using OmniSharp.Extensions.LanguageServer.Protocol.Server; +using OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Server.WorkDone; +using OmniSharp.Extensions.LanguageServer.Protocol.Workspace; +using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range; + + +#pragma warning disable CS0618 + +namespace KScr.LangServer; + +internal class TextDocumentHandler : TextDocumentSyncHandlerBase +{ + private readonly ILogger _logger; + private readonly ILanguageServerConfiguration _configuration; + + private readonly DocumentSelector _documentSelector = new DocumentSelector( + new DocumentFilter { + Pattern = "**/*.cs" + } + ); + + public TextDocumentHandler(ILogger logger, Foo foo, ILanguageServerConfiguration configuration) + { + _logger = logger; + _configuration = configuration; + foo.SayFoo(); + } + + public TextDocumentSyncKind Change { get; } = TextDocumentSyncKind.Full; + + public override Task Handle(DidChangeTextDocumentParams notification, CancellationToken token) + { + _logger.LogCritical("Critical"); + _logger.LogDebug("Debug"); + _logger.LogTrace("Trace"); + _logger.LogInformation("Hello world!"); + return Unit.Task; + } + + public override async Task Handle(DidOpenTextDocumentParams notification, CancellationToken token) + { + await Task.Yield(); + _logger.LogInformation("Hello world!"); + await _configuration.GetScopedConfiguration(notification.TextDocument.Uri, token).ConfigureAwait(false); + return Unit.Value; + } + + public override Task Handle(DidCloseTextDocumentParams notification, CancellationToken token) + { + if (_configuration.TryGetScopedConfiguration(notification.TextDocument.Uri, out var disposable)) + { + disposable.Dispose(); + } + + return Unit.Task; + } + + public override Task Handle(DidSaveTextDocumentParams notification, CancellationToken token) => Unit.Task; + + protected override TextDocumentSyncRegistrationOptions CreateRegistrationOptions(SynchronizationCapability capability, ClientCapabilities clientCapabilities) => new TextDocumentSyncRegistrationOptions() { + DocumentSelector = _documentSelector, + Change = Change, + Save = new SaveOptions() { IncludeText = true } + }; + + public override TextDocumentAttributes GetTextDocumentAttributes(DocumentUri uri) => new TextDocumentAttributes(uri, "csharp"); +} + +internal class MyDocumentSymbolHandler : IDocumentSymbolHandler +{ + public async Task Handle( + DocumentSymbolParams request, + CancellationToken cancellationToken + ) + { + // you would normally get this from a common source that is managed by current open editor, current active editor, etc. + var content = await File.ReadAllTextAsync(DocumentUri.GetFileSystemPath(request), cancellationToken).ConfigureAwait(false); + var lines = content.Split('\n'); + var symbols = new List(); + for (var lineIndex = 0; lineIndex < lines.Length; lineIndex++) + { + var line = lines[lineIndex]; + var parts = line.Split(' ', '.', '(', ')', '{', '}', '[', ']', ';'); + var currentCharacter = 0; + foreach (var part in parts) + { + if (string.IsNullOrWhiteSpace(part)) + { + currentCharacter += part.Length + 1; + continue; + } + + symbols.Add( + new DocumentSymbol { + Detail = part, + Deprecated = true, + Kind = SymbolKind.Field, + Tags = new[] { SymbolTag.Deprecated }, + Range = new Range( + new Position(lineIndex, currentCharacter), + new Position(lineIndex, currentCharacter + part.Length) + ), + SelectionRange = + new Range( + new Position(lineIndex, currentCharacter), + new Position(lineIndex, currentCharacter + part.Length) + ), + Name = part + } + ); + currentCharacter += part.Length + 1; + } + } + + // await Task.Delay(2000, cancellationToken); + return symbols; + } + + public DocumentSymbolRegistrationOptions GetRegistrationOptions(DocumentSymbolCapability capability, ClientCapabilities clientCapabilities) => new DocumentSymbolRegistrationOptions { + DocumentSelector = DocumentSelector.ForLanguage("csharp") + }; +} + +internal class MyWorkspaceSymbolsHandler : IWorkspaceSymbolsHandler +{ + private readonly IServerWorkDoneManager _serverWorkDoneManager; + private readonly IProgressManager _progressManager; + private readonly ILogger _logger; + + public MyWorkspaceSymbolsHandler(IServerWorkDoneManager serverWorkDoneManager, IProgressManager progressManager, ILogger logger) + { + _serverWorkDoneManager = serverWorkDoneManager; + _progressManager = progressManager; + _logger = logger; + } + + public async Task> Handle( + WorkspaceSymbolParams request, + CancellationToken cancellationToken + ) + { + using var reporter = _serverWorkDoneManager.For( + request, new WorkDoneProgressBegin { + Cancellable = true, + Message = "This might take a while...", + Title = "Some long task....", + Percentage = 0 + } + ); + using var partialResults = _progressManager.For(request, cancellationToken); + if (partialResults != null) + { + await Task.Delay(2000, cancellationToken).ConfigureAwait(false); + + reporter.OnNext( + new WorkDoneProgressReport { + Cancellable = true, + Percentage = 20 + } + ); + await Task.Delay(500, cancellationToken).ConfigureAwait(false); + + reporter.OnNext( + new WorkDoneProgressReport { + Cancellable = true, + Percentage = 40 + } + ); + await Task.Delay(500, cancellationToken).ConfigureAwait(false); + + reporter.OnNext( + new WorkDoneProgressReport { + Cancellable = true, + Percentage = 50 + } + ); + await Task.Delay(500, cancellationToken).ConfigureAwait(false); + + partialResults.OnNext( + new[] { + new SymbolInformation { + ContainerName = "Partial Container", + Deprecated = true, + Kind = SymbolKind.Constant, + Location = new Location { + Range = new Range( + new Position(2, 1), + new Position(2, 10) + ) + }, + Name = "Partial name" + } + } + ); + + reporter.OnNext( + new WorkDoneProgressReport { + Cancellable = true, + Percentage = 70 + } + ); + await Task.Delay(500, cancellationToken).ConfigureAwait(false); + + reporter.OnNext( + new WorkDoneProgressReport { + Cancellable = true, + Percentage = 90 + } + ); + + partialResults.OnCompleted(); + return new SymbolInformation[] { }; + } + + try + { + return new[] { + new SymbolInformation { + ContainerName = "Container", + Deprecated = true, + Kind = SymbolKind.Constant, + Location = new Location { + Range = new Range( + new Position(1, 1), + new Position(1, 10) + ) + }, + Name = "name" + } + }; + } + finally + { + reporter.OnNext( + new WorkDoneProgressReport { + Cancellable = true, + Percentage = 100 + } + ); + } + } + + public WorkspaceSymbolRegistrationOptions GetRegistrationOptions(WorkspaceSymbolCapability capability, ClientCapabilities clientCapabilities) => new WorkspaceSymbolRegistrationOptions(); +} \ No newline at end of file diff --git a/kscr-lang-server/kscr-lang-server.csproj b/kscr-lang-server/kscr-lang-server.csproj index 05b5a21..c8f33ac 100644 --- a/kscr-lang-server/kscr-lang-server.csproj +++ b/kscr-lang-server/kscr-lang-server.csproj @@ -14,11 +14,11 @@ - + - + diff --git a/kscr-vscode/language-configuration.json b/kscr-vscode/language-configuration.json deleted file mode 100644 index 4375673..0000000 --- a/kscr-vscode/language-configuration.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "comments": { - // symbol used for single line comment. Remove this entry if your language does not support line comments - "lineComment": "//", - // symbols used for start and end a block comment. Remove this entry if your language does not support block comments - //"blockComment": [ "/*", "*/" ] - }, - // symbols used as brackets - "brackets": [ - ["{", "}"], - ["[", "]"], - ["(", ")"], - ["<", ">"] - ], - // symbols that are auto closed when typing - "autoClosingPairs": [ - ["{", "}"], - ["[", "]"], - ["(", ")"], - ["<", ">"], - ["\"", "\""], - ["'", "'"] - ], - // symbols that can be used to surround a selection - "surroundingPairs": [ - ["{", "}"], - ["[", "]"], - ["(", ")"], - ["<", ">"], - ["\"", "\""], - ["'", "'"] - ], - "folding": { - "markers": { - "start": "//region", - "end": "//endregion" - } - } -} \ No newline at end of file