Skip to content

Commit

Permalink
CodeAction to generate missing property in Qute template
Browse files Browse the repository at this point in the history
Generates Java code for a property referenced in a Qute template that
doesn't exist yet.

It can generate:
  *  A new public field, or update the visibility of an existing field
  *  A new getter, properly returning the field bearing the
     corresponding name if it exists
  *  A new template extension in the detected template extensions class
  *  A new template extension in a newly generated template extensions
     class

Closes redhat-developer#536

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Jul 18, 2022
1 parent e12966c commit a7ec8ea
Show file tree
Hide file tree
Showing 57 changed files with 2,211 additions and 263 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Eclipse
#.project
#.classpath
.settings/
bin/

# IntelliJ
.idea
*.ipr
*.iml
*.iws

# NetBeans
nb-configuration.xml

# Visual Studio Code
.vscode

# OSX
.DS_Store

# Vim
*.swp
*.swo

# patch
*.orig
*.rej

# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
release.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>qute-quickstart-templateextensions</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>qute-quickstart-templateextensions</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.7.5.Final</quarkus.platform.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<compiler-plugin.version>3.8.0</compiler-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-qute</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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) {
hello.data("age", 12);
hello.data("height", 1.50, "weight", 50L);
return hello.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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.acme.qute;

import java.math.BigDecimal;

public class Item {

public final String name;

public final BigDecimal price;

private int identifier;

public Item(BigDecimal price, String name) {
this.price = price;
this.name = name;
}

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"));
}

}
Loading

0 comments on commit a7ec8ea

Please sign in to comment.