diff --git a/projects/qute/projects/gradle/qute-quickstart/README.md b/projects/qute/projects/gradle/qute-quickstart/README.md new file mode 100644 index 000000000..23c90ef06 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/README.md @@ -0,0 +1,59 @@ +# qute-quickstart + +This project uses Quarkus, the Supersonic Subatomic Java Framework. + +If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ . + +## Running the application in dev mode + +You can run your application in dev mode that enables live coding using: +```shell script +./gradlew quarkusDev +``` + +> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/. + +## Packaging and running the application + +The application can be packaged using: +```shell script +./gradlew build +``` +It produces the `quarkus-run.jar` file in the `build/quarkus-app/` directory. +Be aware that it’s not an _über-jar_ as the dependencies are copied into the `build/quarkus-app/lib/` directory. + +The application is now runnable using `java -jar build/quarkus-app/quarkus-run.jar`. + +If you want to build an _über-jar_, execute the following command: +```shell script +./gradlew build -Dquarkus.package.type=uber-jar +``` + +The application, packaged as an _über-jar_, is now runnable using `java -jar build/*-runner.jar`. + +## Creating a native executable + +You can create a native executable using: +```shell script +./gradlew build -Dquarkus.package.type=native +``` + +Or, if you don't have GraalVM installed, you can run the native executable build in a container using: +```shell script +./gradlew build -Dquarkus.package.type=native -Dquarkus.native.container-build=true +``` + +You can then execute your native executable with: `./build/qute-quickstart-1.0.0-SNAPSHOT-runner` + +If you want to learn more about building native executables, please consult https://quarkus.io/guides/gradle-tooling. + +## Related Guides + + +## Provided Code + +### RESTEasy Reactive Qute + +Create your web page using Quarkus RESTEasy Reactive & Qute + +[Related guide section...](https://quarkus.io/guides/qute#type-safe-templates) diff --git a/projects/qute/projects/gradle/qute-quickstart/build.gradle b/projects/qute/projects/gradle/qute-quickstart/build.gradle new file mode 100644 index 000000000..d97aee478 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/build.gradle @@ -0,0 +1,36 @@ +plugins { + id 'java' + id 'io.quarkus' +} + +repositories { + mavenCentral() + mavenLocal() +} + +dependencies { + implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") + implementation 'io.quarkus:quarkus-resteasy-reactive-qute' + implementation 'io.quarkus:quarkus-arc' + testImplementation 'io.quarkus:quarkus-junit5' +} + +group 'org.acme' +version '1.0.0-SNAPSHOT' + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +test { + systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager" +} +compileJava { + options.encoding = 'UTF-8' + options.compilerArgs << '-parameters' +} + +compileTestJava { + options.encoding = 'UTF-8' +} diff --git a/projects/qute/projects/gradle/qute-quickstart/gradle.properties b/projects/qute/projects/gradle/qute-quickstart/gradle.properties new file mode 100644 index 000000000..dc488d33e --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/gradle.properties @@ -0,0 +1,6 @@ +#Gradle properties +quarkusPluginId=io.quarkus +quarkusPluginVersion=3.4.3 +quarkusPlatformGroupId=io.quarkus.platform +quarkusPlatformArtifactId=quarkus-bom +quarkusPlatformVersion=3.4.3 \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/gradle/wrapper/gradle-wrapper.jar b/projects/qute/projects/gradle/qute-quickstart/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..62d4c0535 Binary files /dev/null and b/projects/qute/projects/gradle/qute-quickstart/gradle/wrapper/gradle-wrapper.jar differ diff --git a/projects/qute/projects/gradle/qute-quickstart/gradle/wrapper/gradle-wrapper.properties b/projects/qute/projects/gradle/qute-quickstart/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..fae08049a --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/projects/qute/projects/gradle/qute-quickstart/gradlew b/projects/qute/projects/gradle/qute-quickstart/gradlew new file mode 100644 index 000000000..fbd7c5158 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/gradlew @@ -0,0 +1,185 @@ +#!/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 + ;; + 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/projects/qute/projects/gradle/qute-quickstart/gradlew.bat b/projects/qute/projects/gradle/qute-quickstart/gradlew.bat new file mode 100644 index 000000000..a9f778a7a --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/gradlew.bat @@ -0,0 +1,104 @@ +@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 init + +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 init + +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 + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +: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 %CMD_LINE_ARGS% + +: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/projects/qute/projects/gradle/qute-quickstart/settings.gradle b/projects/qute/projects/gradle/qute-quickstart/settings.gradle new file mode 100644 index 000000000..6100bd5a8 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/settings.gradle @@ -0,0 +1,11 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + mavenLocal() + } + plugins { + id "${quarkusPluginId}" version "${quarkusPluginVersion}" + } +} +rootProject.name='qute-quickstart' diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/SomePage.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/SomePage.java new file mode 100644 index 000000000..a35714966 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/SomePage.java @@ -0,0 +1,29 @@ +package org.acme; + +import io.quarkus.qute.Template; +import io.quarkus.qute.TemplateInstance; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.MediaType; + +import static java.util.Objects.requireNonNull; + +@Path("/some-page") +public class SomePage { + + private final Template page; + + public SomePage(Template page) { + this.page = requireNonNull(page, "page is required"); + } + + @GET + @Produces(MediaType.TEXT_HTML) + public TemplateInstance get(@QueryParam("name") String name) { + return page.data("name", name); + } + +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/A.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/A.java new file mode 100644 index 000000000..f05ae35ab --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/A.java @@ -0,0 +1,6 @@ +package org.acme.qute; + +public class A +{ + +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Globals.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Globals.java new file mode 100644 index 000000000..801800bb5 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Globals.java @@ -0,0 +1,22 @@ +package org.acme.qute; + +import io.quarkus.qute.TemplateGlobal; + +enum Color { RED, GREEN, BLUE } + +@TemplateGlobal +public class Globals { + + static int age = 40; + + static String name; + + static Color[] myColors() { + return new Color[] { Color.RED, Color.BLUE }; + } + + @TemplateGlobal(name = "currentUser") + static String user() { + return "Mia"; + } +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/HelloResource.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/HelloResource.java new file mode 100644 index 000000000..9dc85e3a5 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/HelloResource.java @@ -0,0 +1,63 @@ +package org.acme.qute; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import io.quarkus.qute.Location; +import io.quarkus.qute.Template; +import io.quarkus.qute.TemplateInstance; + +@Path("/hello") +public class HelloResource { + + @Inject + Template hello; + + @Inject + Template goodbye; + + @Location("detail/items2_v1.html") + @Inject + Template hallo; + + @Inject + Template bonjour; + + @Inject + Template aurevoir; + + public HelloResource(@Location("detail/page1.html") Template page1, @Location("detail/page2.html") Template page2) { + this.bonjour = page1; + this.aurevoir = requireNonNull(page2, "page is required"); + } + + private Template requireNonNull(Template page2, String string) { + return null; + } + + @GET + @Produces(MediaType.TEXT_HTML) + public TemplateInstance get(@QueryParam("name") String name) { + return hello.data("height", 1.50, "weight", 50L) + .data("age", 12) + .data("name", name); + } + + @GET + @Produces(MediaType.TEXT_HTML) + public TemplateInstance get2(@QueryParam("name") String name) { + goodbye.data("age2", 12); + return goodbye.data("name2", name); + } + + @GET + @Produces(MediaType.TEXT_HTML) + public TemplateInstance get3(@QueryParam("name") String name) { + hallo.data("age3", 12); + return hallo.data("name3", name); + } +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/IgnoreInjectAnnotation.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/IgnoreInjectAnnotation.java new file mode 100644 index 000000000..2e7e849db --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/IgnoreInjectAnnotation.java @@ -0,0 +1,9 @@ +package org.acme.qute; + +import javax.inject.Named; +import javax.enterprise.inject.Stereotype; + +@Named +public @interface IgnoreInjectAnnotation { + +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/InjectedData.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/InjectedData.java new file mode 100644 index 000000000..fc88cadd9 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/InjectedData.java @@ -0,0 +1,23 @@ +package org.acme.qute; + +import javax.inject.Named; + +@Named +public class InjectedData { + + @Named + private String foo; + + @Named("bar") + private String aBar; + + @Named("user") + public String getUser() { + return null; + } + + @Named + public String getSystemUser() { + return null; + } +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Item.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Item.java new file mode 100644 index 000000000..d98dfb042 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Item.java @@ -0,0 +1,40 @@ +package org.acme.qute; + +import java.math.BigDecimal; + +public class Item { + + /** + * The name of the item + */ + public final String name; + + public final BigDecimal price; + + private final int identifier = 0, version = 1; + + private double volume; + + public Item(BigDecimal price, String name) { + this.price = price; + this.name = name; + } + + /** + * Returns the derived items. + * + * @return the derived items + */ + public Item[] getDerivedItems() { + return null; + } + + public String varArgsMethod(int index, String... elements) { + return null; + } + + public static BigDecimal staticMethod(Item item) { + return item.price.multiply(new BigDecimal("0.9")); + } + +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemResource.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemResource.java new file mode 100644 index 000000000..e52a83310 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemResource.java @@ -0,0 +1,51 @@ +package org.acme.qute; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import io.quarkus.qute.CheckedTemplate; +import io.quarkus.qute.TemplateExtension; +import io.quarkus.qute.TemplateInstance; + +@Path("items") +public class ItemResource { + + @CheckedTemplate + static class Templates { + static native TemplateInstance items(List items); + + static native TemplateInstance map(Map> items, Map.Entry entry); + } + + @CheckedTemplate(requireTypeSafeExpressions = true) + static class Templates2 { + static native TemplateInstance items2(List items); + } + + @GET + @Produces(MediaType.TEXT_HTML) + public TemplateInstance get() { + List items = new ArrayList<>(); + items.add(new Item(new BigDecimal(10), "Apple")); + items.add(new Item(new BigDecimal(16), "Pear")); + items.add(new Item(new BigDecimal(30), "Orange")); + return Templates.items(items); + } + + /** + * This template extension method implements the "discountedPrice" computed + * property. + */ + @TemplateExtension + static BigDecimal discountedPrice(Item item) { + return item.price.multiply(new BigDecimal("0.9")); + } + +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemResourceWithCustomBasePath.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemResourceWithCustomBasePath.java new file mode 100644 index 000000000..d2fc3836c --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemResourceWithCustomBasePath.java @@ -0,0 +1,39 @@ +package org.acme.qute; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import io.quarkus.qute.CheckedTemplate; +import io.quarkus.qute.TemplateExtension; +import io.quarkus.qute.TemplateInstance; + +@Path("items3") +public class ItemResourceWithCustomBasePath { + + @CheckedTemplate(basePath="ItemResourceWithFragment") + static class Templates { + static native TemplateInstance items(List items); + static native TemplateInstance items$id1(List items); + static native TemplateInstance items3$id2(List items); + static native TemplateInstance items3$(List items); + } + + @GET + @Produces(MediaType.TEXT_HTML) + public TemplateInstance get() { + List items = new ArrayList<>(); + items.add(new Item(new BigDecimal(10), "Apple")); + items.add(new Item(new BigDecimal(16), "Pear")); + items.add(new Item(new BigDecimal(30), "Orange")); + return Templates.items(items); + } + + +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemResourceWithFragment.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemResourceWithFragment.java new file mode 100644 index 000000000..921879153 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemResourceWithFragment.java @@ -0,0 +1,46 @@ +package org.acme.qute; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import io.quarkus.qute.CheckedTemplate; +import io.quarkus.qute.TemplateExtension; +import io.quarkus.qute.TemplateInstance; + +@Path("items2") +public class ItemResourceWithFragment { + + @CheckedTemplate + static class Templates { + static native TemplateInstance items(List items); + static native TemplateInstance items$id1(List items); + static native TemplateInstance items3$id2(List items); + static native TemplateInstance items3$(List items); + } + + @CheckedTemplate(ignoreFragments = true) + static class Templates2 { + static native TemplateInstance items2(List items); + static native TemplateInstance items2$id1(List items); + static native TemplateInstance items2$id2(List items); + } + + @GET + @Produces(MediaType.TEXT_HTML) + public TemplateInstance get() { + List items = new ArrayList<>(); + items.add(new Item(new BigDecimal(10), "Apple")); + items.add(new Item(new BigDecimal(16), "Pear")); + items.add(new Item(new BigDecimal(30), "Orange")); + return Templates.items(items); + } + + +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemTemplates.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemTemplates.java new file mode 100644 index 000000000..824acae9d --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemTemplates.java @@ -0,0 +1,15 @@ +package org.acme.qute; + +import io.quarkus.qute.CheckedTemplate; +import io.quarkus.qute.TemplateInstance; + +import java.util.List; + +@CheckedTemplate +public class ItemTemplates { + + static native TemplateInstance items(List items); + static native TemplateInstance items$id1(List items); + static native TemplateInstance items3$id2(List items); + static native TemplateInstance items3$(List items); +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemTemplatesCustomBasePath.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemTemplatesCustomBasePath.java new file mode 100644 index 000000000..0090c253b --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemTemplatesCustomBasePath.java @@ -0,0 +1,15 @@ +package org.acme.qute; + +import java.util.List; +import io.quarkus.qute.CheckedTemplate; +import io.quarkus.qute.TemplateInstance; + +@CheckedTemplate(basePath="ItemResourceWithFragment") +public class ItemTemplatesCustomBasePath { + + static native TemplateInstance items(List items); + static native TemplateInstance items$id1(List items); + static native TemplateInstance items3$id2(List items); + static native TemplateInstance items3$(List items); + +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemTemplatesIgnoreFragments.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemTemplatesIgnoreFragments.java new file mode 100644 index 000000000..0d4acfd16 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemTemplatesIgnoreFragments.java @@ -0,0 +1,14 @@ +package org.acme.qute; + +import io.quarkus.qute.CheckedTemplate; +import io.quarkus.qute.TemplateInstance; + +import java.util.List; + +@CheckedTemplate(ignoreFragments = true) +public class ItemTemplatesIgnoreFragments { + + static native TemplateInstance items2(List items); + static native TemplateInstance items2$id1(List items); + static native TemplateInstance items2$id2(List items); +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemWithAnnotationInParams.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemWithAnnotationInParams.java new file mode 100644 index 000000000..d9068cb16 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemWithAnnotationInParams.java @@ -0,0 +1,11 @@ +package org.acme.qute; + +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; + +public class ItemWithAnnotationInParams { + + public Item getItemByIndex(@NotNull Item item, @NotNull int index) { + return null; + } +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemWithRegisterForReflection.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemWithRegisterForReflection.java new file mode 100644 index 000000000..a0168ce37 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemWithRegisterForReflection.java @@ -0,0 +1,26 @@ +package org.acme.qute; + +import java.math.BigDecimal; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection(fields = false) +public class ItemWithRegisterForReflection { + + public final String name; + + public final BigDecimal price; + + public ItemWithRegisterForReflection(BigDecimal price, String name) { + this.price = price; + this.name = name; + } + + public Item[] getDerivedItems() { + return null; + } + + public static BigDecimal staticMethod(Item item) { + return item.price.multiply(new BigDecimal("0.9")); + } +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemWithTemplateData.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemWithTemplateData.java new file mode 100644 index 000000000..843de08e2 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/ItemWithTemplateData.java @@ -0,0 +1,29 @@ +package org.acme.qute; + +import java.math.BigDecimal; + +import io.quarkus.qute.TemplateData; + +@TemplateData(target = BigDecimal.class) +@TemplateData(ignoreSuperclasses = true) +public class ItemWithTemplateData { + + public final String name; + + public final BigDecimal price; + + public static String count; + + public ItemWithTemplateData(BigDecimal price, String name) { + this.price = price; + this.name = name; + } + + public Item[] getDerivedItems() { + return null; + } + + public static BigDecimal staticMethod(Item item) { + return item.price.multiply(new BigDecimal("0.9")); + } +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/MyTemplateExtensions.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/MyTemplateExtensions.java new file mode 100644 index 000000000..1ded69808 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/MyTemplateExtensions.java @@ -0,0 +1,8 @@ +package org.acme.qute; + +import io.quarkus.qute.TemplateExtension; + +@TemplateExtension +public class MyTemplateExtensions { + +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/NestedClass.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/NestedClass.java new file mode 100644 index 000000000..aefb2c8aa --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/NestedClass.java @@ -0,0 +1,12 @@ +package org.acme.qute; + +public class NestedClass { + + public class Foo { + + } + + public class Bar { + + } +} \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/SomeInterface.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/SomeInterface.java new file mode 100644 index 000000000..2ad881521 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/SomeInterface.java @@ -0,0 +1,7 @@ +package org.acme.qute; + +public interface SomeInterface { + + String getName(); + +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Statuses.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Statuses.java new file mode 100644 index 000000000..454404978 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Statuses.java @@ -0,0 +1,15 @@ +package org.acme.qute; + +import io.quarkus.qute.TemplateData; + +@TemplateData +@TemplateData(namespace = "FOO") +@TemplateData(namespace = "BAR") +public class Statuses { + public static final String ON = "on"; + public static final String OFF = "off"; + + public static String staticMethod(String state) { + return state == "on" ? Statuses.ON : Statuses.OFF; + } +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/StatusesEnum.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/StatusesEnum.java new file mode 100644 index 000000000..e82ee04e6 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/StatusesEnum.java @@ -0,0 +1,9 @@ +package org.acme.qute; + +import io.quarkus.qute.TemplateEnum; + +@TemplateEnum +public enum StatusesEnum { + ON, + OFF +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Templates.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Templates.java new file mode 100644 index 000000000..695e7d784 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/Templates.java @@ -0,0 +1,11 @@ +package org.acme.qute; + +import io.quarkus.qute.CheckedTemplate; +import io.quarkus.qute.TemplateInstance; + +@CheckedTemplate +public class Templates { + + public static native TemplateInstance hello2(String name); + public static native TemplateInstance hello3(String name); +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/cyclic/ClassA.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/cyclic/ClassA.java new file mode 100644 index 000000000..de72ca78e --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/cyclic/ClassA.java @@ -0,0 +1,14 @@ +package org.acme.qute.cyclic; + +public class ClassA extends ClassC { + + public String name; + + /** + * cyclic documentation + */ + public String convert() { + return "hello"; + } + +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/cyclic/ClassB.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/cyclic/ClassB.java new file mode 100644 index 000000000..166a72841 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/cyclic/ClassB.java @@ -0,0 +1,5 @@ +package org.acme.qute.cyclic; + +public class ClassB extends ClassA { + +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/cyclic/ClassC.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/cyclic/ClassC.java new file mode 100644 index 000000000..412297139 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/cyclic/ClassC.java @@ -0,0 +1,5 @@ +package org.acme.qute.cyclic; + +public class ClassC extends ClassB { + +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/generic/A.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/generic/A.java new file mode 100644 index 000000000..2c5be496f --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/generic/A.java @@ -0,0 +1,12 @@ +package org.acme.qute.generic; + +import java.util.Iterator; + +public class A extends B implements Iterable { + + @Override + public Iterator iterator() { + return null; + } + +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/generic/AImpl.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/generic/AImpl.java new file mode 100644 index 000000000..b3d331caf --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/generic/AImpl.java @@ -0,0 +1,5 @@ +package org.acme.qute.generic; + +public class AImpl extends A { + +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/generic/B.java b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/generic/B.java new file mode 100644 index 000000000..cd1714193 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/java/org/acme/qute/generic/B.java @@ -0,0 +1,16 @@ +package org.acme.qute.generic; + +public class B { + + /** + * some docs + */ + public B1 field; + + /** + * some docs + */ + public B1 get(B2 param) { + return null; + } +} diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/META-INF/resources/index.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/META-INF/resources/index.html new file mode 100644 index 000000000..fdb50cc4c --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/META-INF/resources/index.html @@ -0,0 +1,284 @@ + + + + + qute-quickstart - 1.0.0-SNAPSHOT + + + +
+
+
+ + + + + quarkus_logo_horizontal_rgb_1280px_reverse + + + + + + + + + + + + + + + + + + +
+
+
+ +
+
+
+

You just made a Quarkus application.

+

This page is served by Quarkus.

+ Visit the Dev UI +

This page: src/main/resources/META-INF/resources/index.html

+

App configuration: src/main/resources/application.properties

+

Static assets: src/main/resources/META-INF/resources/

+

Code: src/main/java

+

Dev UI V1: /q/dev-v1

+

Generated starter code:

+
    +
  • + RESTEasy Reactive Qute Create your web page using Quarkus RESTEasy Reactive & Qute +
    @Path: /some-page +
    Related guide +
  • + +
+
+
+

Selected extensions

+
    +
  • RESTEasy Reactive Qute
  • +
+
Documentation
+

Practical step-by-step guides to help you achieve a specific goal. Use them to help get your work + done.

+
Set up your IDE
+

Everyone has a favorite IDE they like to use to code. Learn how to configure yours to maximize your + Quarkus productivity.

+
+
+
+ + diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/application.properties b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/application.properties new file mode 100644 index 000000000..e69de29bb diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/ItemResource/items.qute.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/ItemResource/items.qute.html new file mode 100644 index 000000000..9e8922efa --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/ItemResource/items.qute.html @@ -0,0 +1,24 @@ +{! This parameter declarations makes it possible to validate expressions in the template !} +{@java.util.List items} + + + + +Qute - Items + + +

List of Items

+
    + {#for item in items} +
  • + {item.name}: + {#if item.price < 15} + {item.price} + {#else} + {item.price} {item.discountedPrice} + {/if} +
  • + {/for} +
+ + \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/ItemResourceWithFragment/items.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/ItemResourceWithFragment/items.html new file mode 100644 index 000000000..e69de29bb diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/ItemResourceWithFragment/items2$id1.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/ItemResourceWithFragment/items2$id1.html new file mode 100644 index 000000000..e69de29bb diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/ItemResourceWithFragment/items2.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/ItemResourceWithFragment/items2.html new file mode 100644 index 000000000..e69de29bb diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/detail/page1.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/detail/page1.html new file mode 100644 index 000000000..e69de29bb diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/globals.qute.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/globals.qute.html new file mode 100644 index 000000000..331ca7c39 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/globals.qute.html @@ -0,0 +1,8 @@ + + +

+ User: {currentUser} + Age: {age} + Colors: {#each myColors}{it}{#if it_hasNext}, {/if}{/each} +

+ \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/hello.qute.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/hello.qute.html new file mode 100644 index 000000000..2d0071f05 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/hello.qute.html @@ -0,0 +1,10 @@ + + + + +Qute Hello World + + +

Hello {name ?: "world"}!

+ + \ No newline at end of file diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/hello2.qute.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/hello2.qute.html new file mode 100644 index 000000000..e69de29bb diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/items.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/items.html new file mode 100644 index 000000000..e69de29bb diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/items2$id1.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/items2$id1.html new file mode 100644 index 000000000..e69de29bb diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/items2.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/items2.html new file mode 100644 index 000000000..e69de29bb diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/page.qute.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/page.qute.html new file mode 100644 index 000000000..203bd4b37 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/page.qute.html @@ -0,0 +1,30 @@ + + + + + Hello {name ?: "Qute"} + + + +

Hello {name ?: "Qute"}

+ +

Create your web page using Quarkus RESTEasy & Qute

+ + diff --git a/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/status.qute.html b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/status.qute.html new file mode 100644 index 000000000..b7bf5c697 --- /dev/null +++ b/projects/qute/projects/gradle/qute-quickstart/src/main/resources/templates/status.qute.html @@ -0,0 +1,2 @@ +{FOO:ON} +{StatusesEnum:ON} \ No newline at end of file diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/java/AbstractQuteTemplateLinkCollector.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/java/AbstractQuteTemplateLinkCollector.java index 6cad3ba03..b90b0cb62 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/java/AbstractQuteTemplateLinkCollector.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/java/AbstractQuteTemplateLinkCollector.java @@ -1,14 +1,14 @@ /******************************************************************************* -* Copyright (c) 2021 Red Hat Inc. and others. -* All rights reserved. This program and the accompanying materials -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v20.html -* -* SPDX-License-Identifier: EPL-2.0 -* -* Contributors: -* Red Hat Inc. - initial API and implementation -*******************************************************************************/ + * Copyright (c) 2021 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial API and implementation + *******************************************************************************/ package com.redhat.devtools.intellij.qute.psi.internal.java; import com.intellij.openapi.module.Module; @@ -21,14 +21,15 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; -import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; +import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; import com.redhat.devtools.intellij.qute.psi.internal.AnnotationLocationSupport; import com.redhat.devtools.intellij.qute.psi.utils.AnnotationUtils; import com.redhat.devtools.intellij.qute.psi.utils.PsiQuteProjectUtils; import com.redhat.devtools.intellij.qute.psi.utils.PsiTypeUtils; import com.redhat.devtools.intellij.qute.psi.utils.TemplatePathInfo; import org.eclipse.lsp4j.Range; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.net.MalformedURLException; @@ -37,228 +38,258 @@ import java.util.logging.Level; import java.util.logging.Logger; -import static com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants.CHECKED_TEMPLATE_ANNOTATION; -import static com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants.OLD_CHECKED_TEMPLATE_ANNOTATION; -import static com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants.CHECKED_TEMPLATE_ANNOTATION_IGNORE_FRAGMENTS; -import static com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants.TEMPLATE_CLASS; +import static com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants.*; import static com.redhat.devtools.intellij.qute.psi.internal.template.datamodel.CheckedTemplateSupport.getBasePath; import static com.redhat.devtools.intellij.qute.psi.internal.template.datamodel.CheckedTemplateSupport.isIgnoreFragments; +import static com.redhat.devtools.intellij.qute.psi.utils.PsiQuteProjectUtils.*; /** * Abstract class which collects {@link PsiMethod} or * {@link com.intellij.psi.PsiField} which defines a Qute template link: - * + * *
    *
  • declared methods which have class annotated with @CheckedTemplate.
  • *
  • declared field which have Template as type.
  • *
- * - * @author Angelo ZERR * + * @author Angelo ZERR */ public abstract class AbstractQuteTemplateLinkCollector extends JavaRecursiveElementVisitor { - private static final Logger LOGGER = Logger.getLogger(AbstractQuteTemplateLinkCollector.class.getName()); + private static final Logger LOGGER = Logger.getLogger(AbstractQuteTemplateLinkCollector.class.getName()); + + private static String[] suffixes = {".qute.html", ".qute.json", ".qute.txt", ".qute.yaml", ".html", ".json", + ".txt", ".yaml"}; - private static String[] suffixes = { ".qute.html", ".qute.json", ".qute.txt", ".qute.yaml", ".html", ".json", - ".txt", ".yaml" }; + protected static final String PREFERRED_SUFFIX = ".html"; // TODO make it configurable - protected static final String PREFERRED_SUFFIX = ".html"; // TODO make it configurable + private static final String TEMPLATE_TYPE = "Template"; - private static final String TEMPLATE_TYPE = "Template"; + protected final PsiFile typeRoot; + protected final IPsiUtils utils; + protected final ProgressIndicator monitor; + private final @Nullable VirtualFile resourcesDir; - protected final PsiFile typeRoot; - protected final IPsiUtils utils; - protected final ProgressIndicator monitor; + private int levelTypeDecl; - private int levelTypeDecl; + private AnnotationLocationSupport annotationLocationSupport; - private AnnotationLocationSupport annotationLocationSupport; + private PsiFile compilationUnit; - private PsiFile compilationUnit; + public AbstractQuteTemplateLinkCollector(PsiFile typeRoot, IPsiUtils utils, ProgressIndicator monitor) { + this.typeRoot = typeRoot; + this.compilationUnit = typeRoot; + this.utils = utils; + this.monitor = monitor; + this.levelTypeDecl = 0; + this.resourcesDir = findBestResourcesDir(utils.getModule()); + } - public AbstractQuteTemplateLinkCollector(PsiFile typeRoot, IPsiUtils utils, ProgressIndicator monitor) { - this.typeRoot = typeRoot; - this.compilationUnit = typeRoot; - this.utils = utils; - this.monitor = monitor; - this.levelTypeDecl = 0; - } + @Override + public void visitField(PsiField node) { + PsiType type = node.getType(); + if (isTemplateType(type)) { + // The field type is the Qute template + // private Template items; - @Override - public void visitField(PsiField node) { - PsiType type = node.getType(); - if (isTemplateType(type)) { - // The field type is the Qute template - // private Template items; + // Try to get the @Location annotation + // @Location("detail/items2_v1.html") + // Template items2; + PsiLiteralValue locationExpression = AnnotationLocationSupport.getLocationExpression(node, node.getModifierList()); - // Try to get the @Location annotation - // @Location("detail/items2_v1.html") - // Template items2; - PsiLiteralValue locationExpression = AnnotationLocationSupport.getLocationExpression(node, node.getModifierList()); + if (locationExpression == null) { + // The field doesn't declare @Location, + // try to find the @Location declared in the constructor parameter which + // initializes the field - if (locationExpression == null) { - // The field doesn't declare @Location, - // try to find the @Location declared in the constructor parameter which - // initializes the field + // private final Template page; + // public SomePage(@Location("foo/bar/page.qute.html") Template page) { + // this.page = requireNonNull(page, "page is required"); + // } + locationExpression = getAnnotationLocationSupport() + .getLocationExpressionFromConstructorParameter(node.getName()); + } + String fieldName = node.getName(); + collectTemplateLink(null, node, locationExpression, getTypeDeclaration(node), null, fieldName, false); + } + super.visitField(node); + } - // private final Template page; - // public SomePage(@Location("foo/bar/page.qute.html") Template page) { - // this.page = requireNonNull(page, "page is required"); - // } - locationExpression = getAnnotationLocationSupport() - .getLocationExpressionFromConstructorParameter(node.getName()); - } - String fieldName = node.getName(); - collectTemplateLink(null, node, locationExpression, getTypeDeclaration(node), null, fieldName, false); - } - super.visitField(node); - } + /** + * Returns the @Location support. + * + * @return the @Location support. + */ + private AnnotationLocationSupport getAnnotationLocationSupport() { + if (annotationLocationSupport == null) { + // Initialize the @Location support to try to find an @Location in the + // constructor which initializes some fields + annotationLocationSupport = new AnnotationLocationSupport(compilationUnit); + } + return annotationLocationSupport; + } - /** - * Returns the @Location support. - * - * @return the @Location support. - */ - private AnnotationLocationSupport getAnnotationLocationSupport() { - if (annotationLocationSupport == null) { - // Initialize the @Location support to try to find an @Location in the - // constructor which initializes some fields - annotationLocationSupport = new AnnotationLocationSupport(compilationUnit); - } - return annotationLocationSupport; - } + @Override + public void visitClass(PsiClass node) { + levelTypeDecl++; + for (PsiAnnotation annotation : node.getAnnotations()) { + if (AnnotationUtils.isMatchAnnotation(annotation, CHECKED_TEMPLATE_ANNOTATION) + || AnnotationUtils.isMatchAnnotation(annotation, OLD_CHECKED_TEMPLATE_ANNOTATION)) { + // @CheckedTemplate + // public static class Templates { + // public static native TemplateInstance book(Book book); + boolean ignoreFragments = isIgnoreFragments(annotation); + String basePath = getBasePath(annotation); + for (PsiMethod method : node.getMethods()) { + collectTemplateLink(basePath, method, node, ignoreFragments); + } + } + } + super.visitClass(node); + levelTypeDecl--; + } - @Override - public void visitClass(PsiClass node) { - levelTypeDecl++; - for(PsiAnnotation annotation : node.getAnnotations()) { - if (AnnotationUtils.isMatchAnnotation(annotation, CHECKED_TEMPLATE_ANNOTATION) - || AnnotationUtils.isMatchAnnotation(annotation, OLD_CHECKED_TEMPLATE_ANNOTATION)) { - // @CheckedTemplate - // public static class Templates { - // public static native TemplateInstance book(Book book); - boolean ignoreFragments = isIgnoreFragments(annotation); - String basePath = getBasePath(annotation); - for(PsiMethod method : node.getMethods()) { - collectTemplateLink(basePath, method, node, ignoreFragments ); - } - } - } - super.visitClass(node); - levelTypeDecl--; - } + private static PsiClass getTypeDeclaration(PsiElement node) { + return PsiTreeUtil.getParentOfType(node, PsiClass.class); + } - private static PsiClass getTypeDeclaration(PsiElement node) { - return PsiTreeUtil.getParentOfType(node, PsiClass.class); - } + private void collectTemplateLink(String basePath, PsiMethod methodDeclaration, PsiClass type, boolean ignoreFragments) { + String className = null; + boolean innerClass = levelTypeDecl > 1; + if (innerClass) { + className = PsiTypeUtils.getSimpleClassName(typeRoot.getName()); + } + String methodName = methodDeclaration.getName(); + collectTemplateLink(basePath, methodDeclaration, null, type, className, methodName, ignoreFragments); + } - private void collectTemplateLink(String basePath, PsiMethod methodDeclaration, PsiClass type, boolean ignoreFragments) { - String className = null; - boolean innerClass = levelTypeDecl > 1; - if (innerClass) { - className = PsiTypeUtils.getSimpleClassName(typeRoot.getName()); - } - String methodName = methodDeclaration.getName(); - collectTemplateLink(basePath, methodDeclaration, null, type, className, methodName, ignoreFragments ); - } + private void collectTemplateLink(String basePath, PsiElement fieldOrMethod, PsiLiteralValue locationAnnotation, PsiClass type, String className, + String fieldOrMethodName, boolean ignoreFragment) { + try { + String location = locationAnnotation != null && locationAnnotation.getValue() instanceof String ? (String) locationAnnotation.getValue() : null; + Module project = utils.getModule(); + TemplatePathInfo templatePathInfo = location != null + ? PsiQuteProjectUtils.getTemplatePath(basePath, null, location, ignoreFragment) + : PsiQuteProjectUtils.getTemplatePath(basePath, className, fieldOrMethodName, ignoreFragment); - private void collectTemplateLink(String basePath, PsiElement fieldOrMethod, PsiLiteralValue locationAnnotation, PsiClass type, String className, - String fieldOrMethodName, boolean ignoreFragment ) { - try { - String location = locationAnnotation != null && locationAnnotation.getValue() instanceof String ? (String) locationAnnotation.getValue() : null; - Module project = utils.getModule(); - TemplatePathInfo templatePathInfo = location != null - ? PsiQuteProjectUtils.getTemplatePath(basePath, null, location, ignoreFragment) - : PsiQuteProjectUtils.getTemplatePath(basePath, className, fieldOrMethodName, ignoreFragment); + VirtualFile templateFile; + if (location == null) { + templateFile = getTemplateFile(project, templatePathInfo.getTemplateUri()); + templatePathInfo = new TemplatePathInfo( + getRelativePath(templatePathInfo.getTemplateUri(), templateFile, project), + templatePathInfo.getFragmentId()); + } else { + templateFile = getVirtualFile(resourcesDir, templatePathInfo.getTemplateUri(), ""); + } + collectTemplateLink(basePath, fieldOrMethod, locationAnnotation, type, className, fieldOrMethodName, location, + templateFile, templatePathInfo); + } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + throw e; + } catch (RuntimeException e) { + LOGGER.log(Level.WARNING, "Error while creating Qute CodeLens for Java file.", e); + } + } - VirtualFile templateFile = null; - if (location == null) { - templateFile = getTemplateFile(project, templatePathInfo.getTemplateUri()); - templatePathInfo = new TemplatePathInfo( - getRelativePath(templatePathInfo.getTemplateUri(), templateFile, project), - templatePathInfo.getFragmentId()); - } else { - templateFile = getVirtualFile(project, templatePathInfo.getTemplateUri(), ""); - } - collectTemplateLink(basePath, fieldOrMethod, locationAnnotation, type, className, fieldOrMethodName, location, - templateFile, templatePathInfo); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { - throw e; - } catch (RuntimeException e) { - LOGGER.log(Level.WARNING, "Error while creating Qute CodeLens for Java file.", e); - } - } + private VirtualFile getTemplateFile(Module project, String templateFilePathWithoutExtension) { + for (String suffix : suffixes) { + VirtualFile templateFile = getVirtualFile(resourcesDir, templateFilePathWithoutExtension, suffix); + if (templateFile != null) { + return templateFile; + } + } + return getVirtualFile(resourcesDir, templateFilePathWithoutExtension, PREFERRED_SUFFIX); + } - private VirtualFile getTemplateFile(Module project, String templateFilePathWithoutExtension) { - for (String suffix : suffixes) { - VirtualFile templateFile = getVirtualFile(project, templateFilePathWithoutExtension, suffix); - if (templateFile != null) { - return templateFile; - } - } - return getVirtualFile(project, templateFilePathWithoutExtension, PREFERRED_SUFFIX); - } + @Nullable + private VirtualFile getVirtualFile(VirtualFile resourcesDir, String templateFilePathWithoutExtension, String suffix) { + if (resourcesDir != null) { + VirtualFile templatesDir = resourcesDir.findFileByRelativePath(TEMPLATES_FOLDER_NAME); + if (templatesDir != null && templatesDir.exists()) { + VirtualFile templateFile = templatesDir.findFileByRelativePath(templateFilePathWithoutExtension + suffix); + if (templateFile != null && templateFile.exists()) { + return templateFile; + } + } + } + return null; + } - @Nullable - private VirtualFile getVirtualFile(Module project, String templateFilePathWithoutExtension, String suffix) { - for(VirtualFile root : ModuleRootManager.getInstance(project).getContentRoots()) { - VirtualFile templateFile = root.findFileByRelativePath(templateFilePathWithoutExtension + suffix); - if (templateFile != null && templateFile.exists()) { - return templateFile; - } - } - return null; - } + protected String getVirtualFileUrl(Module project, String templateFilePathWithoutExtension, String suffix) { + try { + for (VirtualFile root : ModuleRootManager.getInstance(project).getContentRoots()) { + return new URL(LSPIJUtils.toUri(root).toURL(), templateFilePathWithoutExtension + suffix).toString(); + } + } catch (MalformedURLException e) { + } + return null; + } - protected String getVirtualFileUrl(Module project, String templateFilePathWithoutExtension, String suffix) { - try { - for(VirtualFile root : ModuleRootManager.getInstance(project).getContentRoots()) { - return new URL(LSPIJUtils.toUri(root).toURL(), templateFilePathWithoutExtension + suffix).toString(); - } - } catch (MalformedURLException e) {} - return null; - } + /** + * Returns the relative template file path from the module. + * + * @param templateFilePath the template file path (without file extension). + * @param templateFile the template file and null otherwise. + * @param module the module. + * @return the relative template file path from the module. + */ + private @NotNull String getRelativePath(@NotNull String templateFilePath, @Nullable VirtualFile templateFile, @NotNull Module module) { + if (templateFile != null) { + // The template file exists + // Compute the relative path from the module root path: + // - src/main/resources/templates/page.html for Maven project + // - resources/templates/page.html for Gradle project + for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { + String path = VfsUtilCore.getRelativePath(templateFile, root); + if (path != null) { + return path; + } + } + // Corner usecase, returns the full template file path. + return templateFile.getPath(); + } + // The template file doesn't exist + // Compute the relative path from the module root path: + // - src/main/resources/templates/page.html for Maven project + // - resources/templates/page.html for Gradle project + String relativeResourcesPath = RESOURCES_BASE_DIR; + if (resourcesDir != null) { + for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { + String path = VfsUtilCore.getRelativePath(resourcesDir, root); + if (path != null) { + relativeResourcesPath = path; + break; + } + } + } + return relativeResourcesPath + "/" + TEMPLATES_FOLDER_NAME + templateFilePath + PREFERRED_SUFFIX; + } - protected String getRelativePath(String templateFilePath, VirtualFile templateFile, Module module) { - if (templateFile != null) { - for(VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { - String path = VfsUtilCore.getRelativePath(templateFile, root); - if (path != null) { - return path; - } - } - return templateFile.getPath(); - } else { - return templateFilePath + PREFERRED_SUFFIX; - } - } - protected Range createRange(PsiElement fieldOrMethod) { - if (fieldOrMethod instanceof PsiField) { - TextRange tr = ((PsiField) fieldOrMethod).getNameIdentifier().getTextRange(); - return utils.toRange(typeRoot, tr.getStartOffset(), tr.getLength()); - } - if (fieldOrMethod instanceof PsiLiteralValue) { - TextRange tr = ((PsiLiteralValue) fieldOrMethod).getTextRange(); - return utils.toRange(typeRoot, tr.getStartOffset(), tr.getLength()); - } - PsiMethod method = (PsiMethod) fieldOrMethod; - PsiIdentifier methodName = method.getNameIdentifier(); - TextRange tr = methodName.getTextRange(); - return utils.toRange(typeRoot, tr.getStartOffset(), tr.getLength()); - } + protected Range createRange(PsiElement fieldOrMethod) { + if (fieldOrMethod instanceof PsiField) { + TextRange tr = ((PsiField) fieldOrMethod).getNameIdentifier().getTextRange(); + return utils.toRange(typeRoot, tr.getStartOffset(), tr.getLength()); + } + if (fieldOrMethod instanceof PsiLiteralValue) { + TextRange tr = fieldOrMethod.getTextRange(); + return utils.toRange(typeRoot, tr.getStartOffset(), tr.getLength()); + } + PsiMethod method = (PsiMethod) fieldOrMethod; + PsiIdentifier methodName = method.getNameIdentifier(); + TextRange tr = methodName.getTextRange(); + return utils.toRange(typeRoot, tr.getStartOffset(), tr.getLength()); + } - protected abstract void collectTemplateLink(String basePath, PsiElement node, PsiLiteralValue locationAnnotation, PsiClass type, - String className, String fieldOrMethodName, String location, VirtualFile templateFile, TemplatePathInfo templatePathInfo); + protected abstract void collectTemplateLink(String basePath, PsiElement node, PsiLiteralValue locationAnnotation, PsiClass type, + String className, String fieldOrMethodName, String location, VirtualFile templateFile, TemplatePathInfo templatePathInfo); - private static boolean isTemplateType(PsiType type) { - if (type instanceof PsiClassType) { - PsiClass clazz = ((PsiClassType) type).resolve(); - if (clazz != null) { - return TEMPLATE_CLASS.equals(clazz.getQualifiedName()); - } - } - return false; - } + private static boolean isTemplateType(PsiType type) { + if (type instanceof PsiClassType) { + PsiClass clazz = ((PsiClassType) type).resolve(); + if (clazz != null) { + return TEMPLATE_CLASS.equals(clazz.getQualifiedName()); + } + } + return false; + } } diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/PsiQuteProjectUtils.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/PsiQuteProjectUtils.java index abca3ba00..d44feec4f 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/PsiQuteProjectUtils.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/PsiQuteProjectUtils.java @@ -1,14 +1,14 @@ /******************************************************************************* -* Copyright (c) 2021 Red Hat Inc. and others. -* All rights reserved. This program and the accompanying materials -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v20.html -* -* SPDX-License-Identifier: EPL-2.0 -* -* Contributors: -* Red Hat Inc. - initial API and implementation -*******************************************************************************/ + * Copyright (c) 2021 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial API and implementation + *******************************************************************************/ package com.redhat.devtools.intellij.qute.psi.utils; import com.intellij.openapi.module.Module; @@ -16,13 +16,13 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.vfs.VirtualFile; -import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil; import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; import com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants; import com.redhat.qute.commons.ProjectInfo; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.model.java.JavaResourceRootType; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -32,104 +32,146 @@ * JDT Qute utilities. * * @author Angelo ZERR - * */ public class PsiQuteProjectUtils { - private static final String TEMPLATES_BASE_DIR = "src/main/resources/templates/"; - - /** - * Value for Qute annotations indicating behaviour should be using the default - */ - private static final String DEFAULTED = "<>"; - - private PsiQuteProjectUtils() { - } - - public static ProjectInfo getProjectInfo(Module javaProject) { - String projectUri = getProjectURI(javaProject); - String templateBaseDir = getTemplateBaseDir(javaProject); - // Project dependencies - Set projectDependencies = new HashSet<>(); - ModuleUtilCore.getDependencies(javaProject, projectDependencies); - return new ProjectInfo(projectUri, projectDependencies - .stream() - .filter(projectDependency -> !javaProject.equals(projectDependency)) - .map(projectDependency -> LSPIJUtils.getProjectUri(projectDependency)) - .collect(Collectors.toList()), templateBaseDir); - } - - private static String getTemplateBaseDir(Module javaProject) { - return LSPIJUtils.toUri(javaProject).resolve(TEMPLATES_BASE_DIR).toASCIIString(); - } - - /** - * Returns the project URI of the given project. - * - * @param project the project - * @return the project URI of the given project. - */ - public static String getProjectURI(Module project) { - return LSPIJUtils.getProjectUri(project); - } - - /** - * Returns the project URI of the given project. - * - * @param project the project - * @return the project URI of the given project. - */ - public static String getProjectURI(Project project) { - return LSPIJUtils.getProjectUri(project); - } - - public static boolean hasQuteSupport(Module javaProject) { - return PsiTypeUtils.findType(javaProject, QuteJavaConstants.ENGINE_BUILDER_CLASS) != null; - } - - public static String getTemplatePath(String basePath, String className, String methodOrFieldName) { - StringBuilder path = new StringBuilder(TEMPLATES_BASE_DIR); - if (basePath != null && !DEFAULTED.equals(basePath)) { - appendAndSlash(path, basePath); - } else if (className != null) { - appendAndSlash(path, className); - } - return path.append(methodOrFieldName).toString(); - } - - public static TemplatePathInfo getTemplatePath(String basePath, String className, String methodOrFieldName, boolean ignoreFragments) { - String fragmentId = null; - StringBuilder templateUri = new StringBuilder(TEMPLATES_BASE_DIR); - if (basePath != null && !DEFAULTED.equals(basePath)) { - appendAndSlash(templateUri, basePath); - } else if (className != null) { - appendAndSlash(templateUri, className); - } - if (!ignoreFragments) { - int fragmentIndex = methodOrFieldName != null ? methodOrFieldName.lastIndexOf('$') : -1; - if (fragmentIndex != -1) { - fragmentId = methodOrFieldName.substring(fragmentIndex + 1, methodOrFieldName.length()); - methodOrFieldName = methodOrFieldName.substring(0, fragmentIndex); - } - } - templateUri.append(methodOrFieldName); - return new TemplatePathInfo(templateUri.toString(), fragmentId); - } - - /** - * Appends a segment to a path, add trailing "/" if necessary - * @param path the path to append to - * @param segment the segment to append to the path - */ - public static void appendAndSlash(@NotNull StringBuilder path, @NotNull String segment) { - path.append(segment); - if (!segment.endsWith("/")) { - path.append('/'); - } - } - - public static boolean isQuteTemplate(VirtualFile file, Module module) { - return file.getPath().contains("templates") && - ModuleRootManager.getInstance(module).getFileIndex().isInSourceContent(file); - } + public static final String RESOURCES_BASE_DIR = "src/main/resources"; + + public static final String TEMPLATES_FOLDER_NAME = "templates/"; + + /** + * Value for Qute annotations indicating behaviour should be using the default + */ + private static final String DEFAULTED = "<>"; + + private PsiQuteProjectUtils() { + } + + public static ProjectInfo getProjectInfo(Module javaProject) { + String projectUri = getProjectURI(javaProject); + String templateBaseDir = getTemplateBaseDir(javaProject); + // Project dependencies + Set projectDependencies = new HashSet<>(); + ModuleUtilCore.getDependencies(javaProject, projectDependencies); + return new ProjectInfo(projectUri, projectDependencies + .stream() + .filter(projectDependency -> !javaProject.equals(projectDependency)) + .map(LSPIJUtils::getProjectUri) + .collect(Collectors.toList()), templateBaseDir); + } + + /** + * Returns the full path of the Qute templates base dir '$base-dir-of-module/src/main/resources/templates' for the given module. + * + * @param javaProject the Java module project. + * + * @return the full path of the Qute templates base dir '$base-dir-of-module/src/main/resources/templates' for the given module. + */ + private static String getTemplateBaseDir(Module javaProject) { + VirtualFile resourcesDir = findBestResourcesDir(javaProject); + if (resourcesDir != null) { + return LSPIJUtils.toUri(resourcesDir).resolve(TEMPLATES_FOLDER_NAME).toASCIIString(); + } + return LSPIJUtils.toUri(javaProject).resolve(RESOURCES_BASE_DIR).resolve(TEMPLATES_FOLDER_NAME).toASCIIString(); + } + + /** + * Returns the best resources dir for the given Java module project. + * + * @param javaProject the Java module project. + * + * @return the best resources dir for the given Java module project. + */ + public static @Nullable VirtualFile findBestResourcesDir(@NotNull Module javaProject) { + List resourcesDirs = ModuleRootManager.getInstance(javaProject).getSourceRoots(JavaResourceRootType.RESOURCE); + if (!resourcesDirs.isEmpty()) { + // The module configure 'Resources folder' + // 1) loop for each configured resources dir and returns the first which contains 'templates' folder. + for (var dir : resourcesDirs) { + var templatesDir = dir.findChild(TEMPLATES_FOLDER_NAME); + if (templatesDir != null && templatesDir.exists()) { + return dir; + } + } + // 2) no resources directories contains the 'templates' folder,returns the first. + return resourcesDirs.get(0); + } + // Corner usecase, the module doesn't configure 'Resources folder', use the first content roots + VirtualFile[] roots = ModuleRootManager.getInstance(javaProject).getContentRoots(); + if (roots.length > 0) { + return roots[0]; + } + return javaProject.getModuleFile(); + } + + /** + * Returns the project URI of the given project. + * + * @param project the project + * @return the project URI of the given project. + */ + public static String getProjectURI(Module project) { + return LSPIJUtils.getProjectUri(project); + } + + /** + * Returns the project URI of the given project. + * + * @param project the project + * @return the project URI of the given project. + */ + public static String getProjectURI(Project project) { + return LSPIJUtils.getProjectUri(project); + } + + public static boolean hasQuteSupport(Module javaProject) { + return PsiTypeUtils.findType(javaProject, QuteJavaConstants.ENGINE_BUILDER_CLASS) != null; + } + + public static String getTemplatePath(String basePath, String className, String methodOrFieldName) { + StringBuilder path = new StringBuilder(); + if (basePath != null && !DEFAULTED.equals(basePath)) { + appendAndSlash(path, basePath); + } else if (className != null) { + appendAndSlash(path, className); + } + return path.append(methodOrFieldName).toString(); + } + + public static TemplatePathInfo getTemplatePath(String basePath, String className, String methodOrFieldName, boolean ignoreFragments) { + String fragmentId = null; + StringBuilder templateUri = new StringBuilder(); + if (basePath != null && !DEFAULTED.equals(basePath)) { + appendAndSlash(templateUri, basePath); + } else if (className != null) { + appendAndSlash(templateUri, className); + } + if (!ignoreFragments) { + int fragmentIndex = methodOrFieldName != null ? methodOrFieldName.lastIndexOf('$') : -1; + if (fragmentIndex != -1) { + fragmentId = methodOrFieldName.substring(fragmentIndex + 1); + methodOrFieldName = methodOrFieldName.substring(0, fragmentIndex); + } + } + templateUri.append(methodOrFieldName); + return new TemplatePathInfo(templateUri.toString(), fragmentId); + } + + /** + * Appends a segment to a path, add trailing "/" if necessary + * + * @param path the path to append to + * @param segment the segment to append to the path + */ + public static void appendAndSlash(@NotNull StringBuilder path, @NotNull String segment) { + path.append(segment); + if (!segment.endsWith("/")) { + path.append('/'); + } + } + + public static boolean isQuteTemplate(VirtualFile file, Module module) { + return file.getPath().contains("templates") && + ModuleRootManager.getInstance(module).getFileIndex().isInSourceContent(file); + } } diff --git a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/GradleJavaCodeLensTest.java b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/GradleJavaCodeLensTest.java new file mode 100644 index 000000000..7807a12c6 --- /dev/null +++ b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/GradleJavaCodeLensTest.java @@ -0,0 +1,381 @@ +/******************************************************************************* + * Copyright (c) 2021 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial API and implementation + *******************************************************************************/ +package com.redhat.devtools.intellij.qute.psi.java; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.progress.EmptyProgressIndicator; +import com.redhat.devtools.intellij.GradleTestCase; +import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; +import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; +import com.redhat.devtools.intellij.qute.psi.QuteMavenModuleImportingTestCase; +import com.redhat.devtools.intellij.qute.psi.QuteMavenProjectName; +import com.redhat.devtools.intellij.qute.psi.QuteSupportForJava; +import com.redhat.qute.commons.QuteJavaCodeLensParams; +import org.apache.commons.io.FileUtils; +import org.eclipse.lsp4j.CodeLens; +import org.eclipse.lsp4j.Command; +import org.eclipse.lsp4j.Position; +import org.eclipse.lsp4j.Range; +import org.junit.Test; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Tests for Qute @CheckedTemplate support code lens inside Java files. + * + * @author Angelo ZERR + */ +public class GradleJavaCodeLensTest extends GradleTestCase { + + private static final Logger LOGGER = Logger.getLogger(GradleJavaCodeLensTest.class.getSimpleName()); + private static Level oldLevel; + + @Override + public void setUp() throws Exception { + super.setUp(); + FileUtils.copyDirectory(new File("projects/qute/projects/gradle/qute-quickstart"), new File(getProjectPath())); + importProject(); + } + + @Test + public void testTemplateField() throws Exception { + // public class HelloResource { + + // [Open `resources/templates/hello.qute.html`] + // Template hello; + + // [Create `resources/templates/goodbye.qute.html`] + // Template goodbye; + + // [Create `resources/templates/detail/items2_v1.html`] + // @Location("detail/items2_v1.html") + // Template hallo; + // + // [Open `resources/templates/detail/page1.html`] + // Template bonjour; + // + // [Create `resources/templates/detail/page2.html`] + // Template aurevoir; + // + // public HelloResource(@Location("detail/page1.html") Template page1, + // @Location("detail/page2.html") Template page2) { + // this.bonjour = page1; + // this.aurevoir = requireNonNull(page2, "page is required"); + // } + + Module module = getModule("qute-quickstart"); + QuteJavaCodeLensParams params = new QuteJavaCodeLensParams(); + String javaFileUri = LSPIJUtils.toUri(module).resolve("src/main/java/org/acme/qute/HelloResource.java").toASCIIString(); + params.setUri(javaFileUri); + + List lenses = QuteSupportForJava.getInstance().codeLens(params, PsiUtilsLSImpl.getInstance(myProject), + new EmptyProgressIndicator()); + assertEquals(5, lenses.size()); + + String helloTemplateFileUri = LSPIJUtils.toUri(module).resolve("resources/templates/hello.qute.html").toASCIIString(); + String goodbyeTemplateFileUri = LSPIJUtils.toUri(module).resolve("resources/templates/goodbye.qute.html").toASCIIString(); + String halloTemplateFileUri = LSPIJUtils.toUri(module).resolve("resources/templates/detail/items2_v1.html").toASCIIString(); + String bonjourTemplateFileUri = LSPIJUtils.toUri(module).resolve("resources/templates/detail/page1.html").toASCIIString(); + String aurevoirTemplateFileUri = LSPIJUtils.toUri(module).resolve("resources/templates/detail/page2.html").toASCIIString(); + + assertCodeLens(lenses, // + cl(r(16, 1, 17, 16), // + "Open `resources/templates/hello.qute.html`", // + "qute.command.open.uri", Arrays.asList(helloTemplateFileUri)), // + cl(r(19, 1, 20, 18), // + "Create `resources/templates/goodbye.html`", // + "qute.command.generate.template.file", Arrays.asList(goodbyeTemplateFileUri)), // + cl(r(22, 1, 24, 16), // + "Create `resources/templates/detail/items2_v1.html`", // + "qute.command.generate.template.file", Arrays.asList(halloTemplateFileUri)), // + cl(r(26, 1, 27, 18), // + "Open `resources/templates/detail/page1.html`", // + "qute.command.open.uri", Arrays.asList(bonjourTemplateFileUri)), // + cl(r(29, 1, 30, 19), // + "Create `resources/templates/detail/page2.html`", // + "qute.command.generate.template.file", Arrays.asList(aurevoirTemplateFileUri))); + } + + @Test + public void testCheckedTemplate() throws Exception { + // @CheckedTemplate + // public class Templates { + // [Open `resources/templates/hello2.qute.html`] + // public static native TemplateInstance hello2(String name); + // [Open `resources/templates/hello3.qute.html`] + // public static native TemplateInstance hello3(String name); + Module module = getModule("qute-quickstart"); + QuteJavaCodeLensParams params = new QuteJavaCodeLensParams(); + String javaFileUri = LSPIJUtils.toUri(module).resolve("src/main/java/org/acme/qute/Templates.java").toASCIIString(); + params.setUri(javaFileUri); + + List lenses = QuteSupportForJava.getInstance().codeLens(params, PsiUtilsLSImpl.getInstance(myProject), + new EmptyProgressIndicator()); + assertEquals(2, lenses.size()); + + String goodbyeFileUri = LSPIJUtils.toUri(module).resolve("resources/templates/hello2.qute.html").toASCIIString(); + String hello3FileUri1 = LSPIJUtils.toUri(module).resolve("resources/templates/hello3.qute.html").toASCIIString(); + + assertCodeLens(lenses, // + cl(r(8, 1, 8, 59), // + "Open `resources/templates/hello2.qute.html`", // + "qute.command.open.uri", Arrays.asList(goodbyeFileUri)), // + cl(r(9, 4, 9, 62), // + "Create `resources/templates/hello3.html`", // + "qute.command.generate.template.file", Arrays.asList(hello3FileUri1))); + } + + @Test + public void testCheckedTemplateInInnerClass() throws Exception { + // public class ItemResource { + // @CheckedTemplate + // static class Templates { + // [Open `resources/templates/ItemResource/items.qute.html`] + // static native TemplateInstance items(List items); + + // static class Templates2 { + // [Create `resources/templates/ItemResource/items2.qute.html`] + // static native TemplateInstance items2(List items); + + Module module = getModule("qute-quickstart"); + QuteJavaCodeLensParams params = new QuteJavaCodeLensParams(); + String javaFileUri = LSPIJUtils.toUri(module).resolve("src/main/java/org/acme/qute/ItemResource.java").toASCIIString(); + params.setUri(javaFileUri); + + List lenses = QuteSupportForJava.getInstance().codeLens(params, PsiUtilsLSImpl.getInstance(myProject), + new EmptyProgressIndicator()); + assertEquals(3, lenses.size()); + + String itemsUri = LSPIJUtils.toUri(module).resolve("/resources/templates/ItemResource/items.qute.html").toASCIIString(); + String mapUri = LSPIJUtils.toUri(module).resolve("/resources/templates/ItemResource/map.html").toASCIIString(); + String items2Uri = LSPIJUtils.toUri(module).resolve("/resources/templates/ItemResource/items2.html").toASCIIString(); + + assertCodeLens(lenses, // + cl(r(21, 2, 21, 57), // + "Open `resources/templates/ItemResource/items.qute.html`", // + "qute.command.open.uri", Arrays.asList(itemsUri)), // + cl(r(23, 2, 23, 102), // + "Create `resources/templates/ItemResource/map.html`", // + "qute.command.generate.template.file", Arrays.asList(mapUri)), // + cl(r(28, 2, 28, 58), // + "Create `resources/templates/ItemResource/items2.html`", // + "qute.command.generate.template.file", Arrays.asList(items2Uri))); + } + + @Test + public void testCheckedTemplateWithFragment() throws Exception { + + // @CheckedTemplate + //public class ItemTemplates { + // + // static native TemplateInstance items(List items); + // static native TemplateInstance items$id1(List items); + // static native TemplateInstance items3$id2(List items); + // static native TemplateInstance items3$(List items); + //} + Module module = getModule("qute-quickstart"); + QuteJavaCodeLensParams params = new QuteJavaCodeLensParams(); + String javaFileUri = LSPIJUtils.toUri(module).resolve("src/main/java/org/acme/qute/ItemTemplates.java").toASCIIString(); + params.setUri(javaFileUri); + + List lenses = QuteSupportForJava.getInstance().codeLens(params, PsiUtilsLSImpl.getInstance(myProject), + new EmptyProgressIndicator()); + assertEquals(3, lenses.size()); + + String itemsUri = LSPIJUtils.toUri(module).resolve("/resources/templates/items.html").toASCIIString(); + String items3Uri = LSPIJUtils.toUri(module).resolve("resources/templates/items3.html").toASCIIString(); + + assertCodeLens(lenses, // + cl(r(10, 4, 10, 59), // + "Open `resources/templates/items.html`", // + "qute.command.open.uri", Arrays.asList(itemsUri)), // + cl(r(11, 4, 11, 63), // + "Open `id1` fragment of `resources/templates/items.html`", // + "qute.command.open.uri", Arrays.asList(itemsUri, "id1")), // + cl(r(12, 4, 12, 64), // + "Create `resources/templates/items3.html`", // + "qute.command.generate.template.file", Arrays.asList(items3Uri))); + + // @CheckedTemplate(ignoreFragments = true) + // public class ItemTemplatesIgnoreFragments { + // + // static native TemplateInstance items2(List items); + // static native TemplateInstance items2$id1(List items); + // static native TemplateInstance items2$id2(List items); + //} + params = new QuteJavaCodeLensParams(); + javaFileUri = LSPIJUtils.toUri(module).resolve("src/main/java/org/acme/qute/ItemTemplatesIgnoreFragments.java").toASCIIString(); + params.setUri(javaFileUri); + + lenses = QuteSupportForJava.getInstance().codeLens(params, PsiUtilsLSImpl.getInstance(myProject), + new EmptyProgressIndicator()); + assertEquals(3, lenses.size()); + + String items2Uri = LSPIJUtils.toUri(module).resolve("/resources/templates/items2.html").toASCIIString(); + String items2Uri_id1 = LSPIJUtils.toUri(module).resolve("/resources/templates/items2$id1.html").toASCIIString(); + String items2Uri_id2 = LSPIJUtils.toUri(module).resolve("/resources/templates/items2$id2.html").toASCIIString(); + + assertCodeLens(lenses, // + cl(r(10, 4, 10, 60), // + "Open `resources/templates/items2.html`", // + "qute.command.open.uri", Arrays.asList(items2Uri)), // + cl(r(11, 4, 11, 64), // + "Open `resources/templates/items2$id1.html`", // + "qute.command.open.uri", Arrays.asList(items2Uri_id1)), // + cl(r(12, 4, 12, 64), // + "Create `resources/templates/items2$id2.html`", // + "qute.command.generate.template.file", Arrays.asList(items2Uri_id2))); + } + + public void testCheckedTemplateWithCustomBasePath() throws Exception { + + // @CheckedTemplate(basePath="ItemResourceWithFragment") + //public class ItemTemplatesCustomBasePath { + // + // static native TemplateInstance items(List items); + // static native TemplateInstance items$id1(List items); + // static native TemplateInstance items3$id2(List items); + // static native TemplateInstance items3$(List items); + //} + + Module module = getModule("qute-quickstart"); + QuteJavaCodeLensParams params = new QuteJavaCodeLensParams(); + String javaFileUri = LSPIJUtils.toUri(module).resolve("src/main/java/org/acme/qute/ItemTemplatesCustomBasePath.java").toASCIIString(); + params.setUri(javaFileUri); + + List lenses = QuteSupportForJava.getInstance().codeLens(params, PsiUtilsLSImpl.getInstance(myProject), + new EmptyProgressIndicator()); + assertEquals(3, lenses.size()); + + String itemsUri = LSPIJUtils.toUri(module).resolve("/resources/templates/ItemResourceWithFragment/items.html").toASCIIString(); + String items3Uri = LSPIJUtils.toUri(module).resolve("resources/templates/ItemResourceWithFragment/items3.html").toASCIIString(); + + assertCodeLens(lenses, // + cl(r(9, 1, 9, 56), // + "Open `resources/templates/ItemResourceWithFragment/items.html`", // + "qute.command.open.uri", Arrays.asList(itemsUri)), // + cl(r(10, 1, 10, 60), // + "Open `id1` fragment of `resources/templates/ItemResourceWithFragment/items.html`", // + "qute.command.open.uri", Arrays.asList(itemsUri, "id1")), // + cl(r(11, 1, 11, 61), // + "Create `resources/templates/ItemResourceWithFragment/items3.html`", // + "qute.command.generate.template.file", Arrays.asList(items3Uri))); + + } + + public void testCheckedTemplateInInnerClassWithCustomBasePath() throws Exception { + + // @CheckedTemplate(basePath="ItemResourceWithFragment") + //public class ItemTemplatesCustomBasePath { + // + // static native TemplateInstance items(List items); + // static native TemplateInstance items$id1(List items); + // static native TemplateInstance items3$id2(List items); + // static native TemplateInstance items3$(List items); + //} + + Module module = getModule("qute-quickstart"); + QuteJavaCodeLensParams params = new QuteJavaCodeLensParams(); + String javaFileUri = LSPIJUtils.toUri(module).resolve("src/main/java/org/acme/qute/ItemTemplatesCustomBasePath.java").toASCIIString(); + params.setUri(javaFileUri); + + List lenses = QuteSupportForJava.getInstance().codeLens(params, PsiUtilsLSImpl.getInstance(myProject), + new EmptyProgressIndicator()); + assertEquals(3, lenses.size()); + + String itemsUri = LSPIJUtils.toUri(module).resolve("/resources/templates/ItemResourceWithFragment/items.html").toASCIIString(); + String items3Uri = LSPIJUtils.toUri(module).resolve("resources/templates/ItemResourceWithFragment/items3.html").toASCIIString(); + + assertCodeLens(lenses, // + cl(r(9, 1, 9, 56), // + "Open `resources/templates/ItemResourceWithFragment/items.html`", // + "qute.command.open.uri", Arrays.asList(itemsUri)), // + cl(r(10, 1, 10, 60), // + "Open `id1` fragment of `resources/templates/ItemResourceWithFragment/items.html`", // + "qute.command.open.uri", Arrays.asList(itemsUri, "id1")), // + cl(r(11, 1, 11, 61), // + "Create `resources/templates/ItemResourceWithFragment/items3.html`", // + "qute.command.generate.template.file", Arrays.asList(items3Uri))); + + } + @Test + public void testCheckedTemplateInInnerClassWithFragment() throws Exception { + Module module = getModule("qute-quickstart"); + QuteJavaCodeLensParams params = new QuteJavaCodeLensParams(); + String javaFileUri = LSPIJUtils.toUri(module).resolve("src/main/java/org/acme/qute/ItemResourceWithFragment.java").toASCIIString(); + params.setUri(javaFileUri); + + List lenses = QuteSupportForJava.getInstance().codeLens(params, PsiUtilsLSImpl.getInstance(myProject), + new EmptyProgressIndicator()); + assertEquals(6, lenses.size()); + + String itemsUri = LSPIJUtils.toUri(module).resolve("/resources/templates/ItemResourceWithFragment/items.html").toASCIIString(); + String items3Uri = LSPIJUtils.toUri(module).resolve("resources/templates/ItemResourceWithFragment/items3.html").toASCIIString(); + String items2Uri = LSPIJUtils.toUri(module).resolve("/resources/templates/ItemResourceWithFragment/items2.html").toASCIIString(); + String items2Uri_id1 = LSPIJUtils.toUri(module).resolve("/resources/templates/ItemResourceWithFragment/items2$id1.html").toASCIIString(); + String items2Uri_id2 = LSPIJUtils.toUri(module).resolve("/resources/templates/ItemResourceWithFragment/items2$id2.html").toASCIIString(); + + assertCodeLens(lenses, // + cl(r(21, 2, 21, 57), // + "Open `resources/templates/ItemResourceWithFragment/items.html`", // + "qute.command.open.uri", Arrays.asList(itemsUri)), // + cl(r(22, 2, 22, 61), // + "Open `id1` fragment of `resources/templates/ItemResourceWithFragment/items.html`", // + "qute.command.open.uri", Arrays.asList(itemsUri, "id1")), // + cl(r(23, 2, 23, 62), // + "Create `resources/templates/ItemResourceWithFragment/items3.html`", // + "qute.command.generate.template.file", Arrays.asList(items3Uri)), // + + cl(r(29, 2, 29, 58), // + "Open `resources/templates/ItemResourceWithFragment/items2.html`", // + "qute.command.open.uri", Arrays.asList(items2Uri)), // + cl(r(30, 2, 30, 62), // + "Open `resources/templates/ItemResourceWithFragment/items2$id1.html`", // + "qute.command.open.uri", Arrays.asList(items2Uri_id1)), // + cl(r(31, 2, 31, 62), // + "Create `resources/templates/ItemResourceWithFragment/items2$id2.html`", // + "qute.command.generate.template.file", Arrays.asList(items2Uri_id2))); + } + + public static Range r(int line, int startChar, int endChar) { + return r(line, startChar, line, endChar); + } + + public static Range r(int startLine, int startChar, int endLine, int endChar) { + Position start = new Position(startLine, startChar); + Position end = new Position(endLine, endChar); + return new Range(start, end); + } + + public static CodeLens cl(Range range, String title, String command, List arguments) { + return new CodeLens(range, new Command(title, command, arguments), null); + } + + public static void assertCodeLens(List actual, CodeLens... expected) { + assertEquals(expected.length, actual.size()); + for (int i = 0; i < expected.length; i++) { + assertEquals(expected[i].getRange(), actual.get(i).getRange()); + Command expectedCommand = expected[i].getCommand(); + Command actualCommand = actual.get(i).getCommand(); + if (expectedCommand != null && actualCommand != null) { + assertEquals(expectedCommand.getTitle(), actualCommand.getTitle()); + assertEquals(expectedCommand.getCommand(), actualCommand.getCommand()); + } + assertEquals(expected[i].getData(), actual.get(i).getData()); + } + } + +} diff --git a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/JavaCodeLensTest.java b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaCodeLensTest.java similarity index 98% rename from src/test/java/com/redhat/devtools/intellij/qute/psi/java/JavaCodeLensTest.java rename to src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaCodeLensTest.java index 6865f842f..81fb658cc 100644 --- a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/JavaCodeLensTest.java +++ b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaCodeLensTest.java @@ -13,9 +13,9 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.EmptyProgressIndicator; -import com.redhat.devtools.intellij.MavenModuleImportingTestCase; import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; +import com.redhat.devtools.intellij.qute.psi.QuteMavenModuleImportingTestCase; import com.redhat.devtools.intellij.qute.psi.QuteMavenProjectName; import com.redhat.devtools.intellij.qute.psi.QuteSupportForJava; import com.redhat.qute.commons.QuteJavaCodeLensParams; @@ -25,7 +25,6 @@ import org.eclipse.lsp4j.Range; import org.junit.Test; -import java.io.File; import java.util.Arrays; import java.util.List; import java.util.logging.Level; @@ -36,9 +35,9 @@ * * @author Angelo ZERR */ -public class JavaCodeLensTest extends MavenModuleImportingTestCase { +public class MavenJavaCodeLensTest extends QuteMavenModuleImportingTestCase { - private static final Logger LOGGER = Logger.getLogger(JavaCodeLensTest.class.getSimpleName()); + private static final Logger LOGGER = Logger.getLogger(MavenJavaCodeLensTest.class.getSimpleName()); private static Level oldLevel; private Module module; @@ -46,7 +45,7 @@ public class JavaCodeLensTest extends MavenModuleImportingTestCase { @Override protected void setUp() throws Exception { super.setUp(); - module = createMavenModule(new File("projects/qute/projects/maven/" + QuteMavenProjectName.qute_quickstart)); + module = loadMavenProject(QuteMavenProjectName.qute_quickstart); } @Test diff --git a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/JavaDiagnosticsTest.java b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDiagnosticsTest.java similarity index 97% rename from src/test/java/com/redhat/devtools/intellij/qute/psi/java/JavaDiagnosticsTest.java rename to src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDiagnosticsTest.java index 195e304e3..e54be88cf 100644 --- a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/JavaDiagnosticsTest.java +++ b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDiagnosticsTest.java @@ -13,9 +13,9 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.EmptyProgressIndicator; -import com.redhat.devtools.intellij.MavenModuleImportingTestCase; import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; +import com.redhat.devtools.intellij.qute.psi.QuteMavenModuleImportingTestCase; import com.redhat.devtools.intellij.qute.psi.QuteMavenProjectName; import com.redhat.devtools.intellij.qute.psi.QuteSupportForJava; import com.redhat.devtools.intellij.qute.psi.internal.java.QuteErrorCode; @@ -23,7 +23,6 @@ import org.eclipse.lsp4j.*; import org.junit.Test; -import java.io.File; import java.util.Arrays; import java.util.List; import java.util.logging.Level; @@ -34,9 +33,9 @@ * * @author Angelo ZERR */ -public class JavaDiagnosticsTest extends MavenModuleImportingTestCase { +public class MavenJavaDiagnosticsTest extends QuteMavenModuleImportingTestCase { - private static final Logger LOGGER = Logger.getLogger(JavaDiagnosticsTest.class.getSimpleName()); + private static final Logger LOGGER = Logger.getLogger(MavenJavaDiagnosticsTest.class.getSimpleName()); private static Level oldLevel; private Module module; @@ -44,7 +43,7 @@ public class JavaDiagnosticsTest extends MavenModuleImportingTestCase { @Override protected void setUp() throws Exception { super.setUp(); - module = createMavenModule(new File("projects/qute/projects/maven/" + QuteMavenProjectName.qute_quickstart)); + module = loadMavenProject(QuteMavenProjectName.qute_quickstart); } @Test diff --git a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/JavaDocumentLinkTest.java b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDocumentLinkTest.java similarity index 97% rename from src/test/java/com/redhat/devtools/intellij/qute/psi/java/JavaDocumentLinkTest.java rename to src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDocumentLinkTest.java index 395ebc4d4..864937fcd 100644 --- a/src/test/java/com/redhat/devtools/intellij/qute/psi/java/JavaDocumentLinkTest.java +++ b/src/test/java/com/redhat/devtools/intellij/qute/psi/java/MavenJavaDocumentLinkTest.java @@ -14,9 +14,9 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.EmptyProgressIndicator; -import com.redhat.devtools.intellij.MavenModuleImportingTestCase; import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; import com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.ls.PsiUtilsLSImpl; +import com.redhat.devtools.intellij.qute.psi.QuteMavenModuleImportingTestCase; import com.redhat.devtools.intellij.qute.psi.QuteMavenProjectName; import com.redhat.devtools.intellij.qute.psi.QuteSupportForJava; import com.redhat.qute.commons.QuteJavaDocumentLinkParams; @@ -25,7 +25,6 @@ import org.eclipse.lsp4j.Range; import org.junit.Test; -import java.io.File; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -35,9 +34,9 @@ * * @author Angelo ZERR */ -public class JavaDocumentLinkTest extends MavenModuleImportingTestCase { +public class MavenJavaDocumentLinkTest extends QuteMavenModuleImportingTestCase { - private static final Logger LOGGER = Logger.getLogger(JavaDocumentLinkTest.class.getSimpleName()); + private static final Logger LOGGER = Logger.getLogger(MavenJavaDocumentLinkTest.class.getSimpleName()); private static Level oldLevel; private Module module; @@ -45,7 +44,7 @@ public class JavaDocumentLinkTest extends MavenModuleImportingTestCase { @Override protected void setUp() throws Exception { super.setUp(); - module = createMavenModule(new File("projects/qute/projects/maven/" + QuteMavenProjectName.qute_quickstart)); + module = loadMavenProject(QuteMavenProjectName.qute_quickstart); } @Test