-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gytis Trikleris
committed
Mar 15, 2021
1 parent
203bfca
commit 665dd43
Showing
35 changed files
with
1,256 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2496,4 +2496,4 @@ | |
</profile> | ||
</profiles> | ||
|
||
</project> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
extensions/resteasy-reactive/quarkus-resteasy-reactive-links/deployment/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-resteasy-reactive-links-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-resteasy-reactive-links-deployment</artifactId> | ||
<name>Quarkus - RESTEasy Reactive - Links - Deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-links</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-internal</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${project.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
<parameters>true</parameters> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
29 changes: 29 additions & 0 deletions
29
...rc/main/java/io/quarkus/resteasy/reactive/links/deployment/GetterAccessorImplementor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkus.resteasy.reactive.links.deployment; | ||
|
||
import static io.quarkus.gizmo.MethodDescriptor.ofMethod; | ||
|
||
import io.quarkus.gizmo.ClassCreator; | ||
import io.quarkus.gizmo.ClassOutput; | ||
import io.quarkus.gizmo.MethodCreator; | ||
import io.quarkus.gizmo.ResultHandle; | ||
import io.quarkus.resteasy.reactive.links.runtime.GetterAccessor; | ||
|
||
class GetterAccessorImplementor { | ||
|
||
/** | ||
* Implements a {@link GetterAccessor} that knows how to access a specific getter method of a specific type. | ||
*/ | ||
void implement(ClassOutput classOutput, GetterMetadata getterMetadata) { | ||
ClassCreator classCreator = ClassCreator.builder() | ||
.classOutput(classOutput).className(getterMetadata.getGetterAccessorName()) | ||
.interfaces(GetterAccessor.class) | ||
.build(); | ||
MethodCreator methodCreator = classCreator.getMethodCreator("get", Object.class, Object.class); | ||
ResultHandle value = methodCreator.invokeVirtualMethod( | ||
ofMethod(getterMetadata.getEntityType(), getterMetadata.getGetterName(), getterMetadata.getFieldType()), | ||
methodCreator.getMethodParam(0)); | ||
methodCreator.returnValue(value); | ||
methodCreator.close(); | ||
classCreator.close(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...oyment/src/main/java/io/quarkus/resteasy/reactive/links/deployment/GetterImplementor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.quarkus.resteasy.reactive.links.deployment; | ||
|
||
import static io.quarkus.gizmo.DescriptorUtils.objectToDescriptor; | ||
import static org.objectweb.asm.Opcodes.ACC_PUBLIC; | ||
import static org.objectweb.asm.Opcodes.ALOAD; | ||
import static org.objectweb.asm.Opcodes.GETFIELD; | ||
import static org.objectweb.asm.Opcodes.IRETURN; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.MethodVisitor; | ||
import org.objectweb.asm.Type; | ||
|
||
import io.quarkus.gizmo.Gizmo; | ||
|
||
class GetterImplementor extends ClassVisitor { | ||
|
||
private final GetterMetadata getterMetadata; | ||
|
||
static BiFunction<String, ClassVisitor, ClassVisitor> getVisitorFunction(GetterMetadata getterMetadata) { | ||
return (className, classVisitor) -> new GetterImplementor(classVisitor, getterMetadata); | ||
} | ||
|
||
GetterImplementor(ClassVisitor outputClassVisitor, GetterMetadata getterMetadata) { | ||
super(Gizmo.ASM_API_VERSION, outputClassVisitor); | ||
this.getterMetadata = getterMetadata; | ||
} | ||
|
||
@Override | ||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, | ||
String[] exceptions) { | ||
return super.visitMethod(access, name, descriptor, signature, exceptions); | ||
} | ||
|
||
@Override | ||
public void visitEnd() { | ||
generateGetter(); | ||
super.visitEnd(); | ||
} | ||
|
||
private void generateGetter() { | ||
String owner = Type.getType(objectToDescriptor(getterMetadata.getEntityType())).getInternalName(); | ||
String fieldDescriptor = objectToDescriptor(getterMetadata.getFieldType()); | ||
String getterDescriptor = "()" + fieldDescriptor; | ||
|
||
MethodVisitor mv = super.visitMethod(ACC_PUBLIC, getterMetadata.getGetterName(), getterDescriptor, null, null); | ||
mv.visitVarInsn(ALOAD, 0); | ||
mv.visitFieldInsn(GETFIELD, owner, getterMetadata.getFieldName(), fieldDescriptor); | ||
mv.visitInsn(Type.getType(fieldDescriptor).getOpcode(IRETURN)); | ||
mv.visitMaxs(0, 0); | ||
mv.visitEnd(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...eployment/src/main/java/io/quarkus/resteasy/reactive/links/deployment/GetterMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.quarkus.resteasy.reactive.links.deployment; | ||
|
||
import java.util.Objects; | ||
|
||
import org.jboss.jandex.FieldInfo; | ||
|
||
class GetterMetadata { | ||
|
||
private static final String GETTER_PREFIX = "resteasy_links_get_"; | ||
|
||
private static final String ACCESSOR_SUFFIX = "$_resteasy_links"; | ||
|
||
private final String entityType; | ||
|
||
private final String fieldType; | ||
|
||
private final String fieldName; | ||
|
||
GetterMetadata(FieldInfo fieldInfo) { | ||
this.entityType = fieldInfo.declaringClass().toString(); | ||
this.fieldType = fieldInfo.type().name().toString(); | ||
this.fieldName = fieldInfo.name(); | ||
} | ||
|
||
public String getEntityType() { | ||
return entityType; | ||
} | ||
|
||
public String getFieldType() { | ||
return fieldType; | ||
} | ||
|
||
public String getFieldName() { | ||
return fieldName; | ||
} | ||
|
||
public String getGetterName() { | ||
return GETTER_PREFIX + fieldName; | ||
} | ||
|
||
public String getGetterAccessorName() { | ||
return entityType + ACCESSOR_SUFFIX + getGetterName(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
GetterMetadata that = (GetterMetadata) o; | ||
return entityType.equals(that.entityType) | ||
&& fieldType.equals(that.fieldType) | ||
&& fieldName.equals(that.fieldName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(entityType, fieldType, fieldName); | ||
} | ||
} |
Oops, something went wrong.