Skip to content

Commit 3ca0594

Browse files
committed
Small changes
- Update example - Rename EntityAccessorInstrumentationPlugin to ClassAccessorInstrumentationPlugin since it isn't intended just for entity classes. Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
1 parent b969d59 commit 3ca0594

File tree

8 files changed

+46
-18
lines changed

8 files changed

+46
-18
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<packaging>maven-plugin</packaging>
77

88
<!-- Changing this version requires to change AutoClassAccessorsMojo#AUTO_CLASS_ACCESSORS_VERSION -->
9-
<version>1.0.2</version>
9+
<version>1.0.3</version>
1010

1111
<name>auto-class-accessors-maven-plugin</name>
1212
<description>

sample/pom.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.github.manoelcampos</groupId>
66
<artifactId>automatic-class-accessors-sample</artifactId>
7-
<version>1.0.0</version>
7+
8+
<!-- The project version defines the version of the auto-class-accessors-maven-plugin to be used -->
9+
<version>1.0.3</version>
810

911
<properties>
1012
<maven.compiler.release>21</maven.compiler.release>
@@ -25,7 +27,7 @@
2527
<plugin>
2628
<groupId>io.github.manoelcampos</groupId>
2729
<artifactId>auto-class-accessors-maven-plugin</artifactId>
28-
<version>1.0.2</version>
30+
<version>${project.version}</version>
2931
<executions><execution><goals><goal>apply</goal></goals></execution></executions>
3032
</plugin>
3133
</plugins>
Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
package io.github.manoelcampos.accessors.sample;
22

3+
import java.util.function.Supplier;
4+
35
public class Main {
6+
private static long lastId = 1;
7+
48
public static void main(final String[] args) {
5-
final var product = new Product();
6-
product.id = 1L;
7-
product.available = true;
8-
product.name = " TV ";
9-
product.model = "xy123";
9+
final var product1 = new Product();
10+
product1.id = 1L;
11+
product1.available = true;
12+
product1.name = " TV ";
13+
product1.model = "xy123";
14+
15+
System.out.printf("Product id: %d name: %s model: %s available: %s%n%n", product1.id, product1.name, product1.model, product1.available);
16+
17+
18+
final var product2 = newProduct(() -> {
19+
final var p = new Product();
20+
p.name = "Smartphone ";
21+
p.brand = "new";
22+
p.model = "pro-x";
23+
return p;
24+
});
25+
26+
System.out.println(product2);
27+
}
1028

11-
System.out.printf("Product id: %d name: %s model: %s available: %s%n", product.id, product.name, product.model, product.available);
29+
/**
30+
* Crates a new {@link Product} instance using the given supplier and assignes an auto-increment ID.
31+
* @param supplier the {@link Supplier} to get a new Product.
32+
* @return the new Product instance with an assigned ID.
33+
*/
34+
private static Product newProduct(Supplier<Product> supplier) {
35+
final var product = supplier.get();
36+
product.id = ++lastId;
37+
return product;
1238
}
1339
}

src/main/java/io/github/manoelcampos/accessors/AutoClassAccessorsMojo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class AutoClassAccessorsMojo extends AbstractMojo {
2424
/**
2525
* A reference to the current version of the Auto Class Accessors Maven Plugin,
26-
* to get the {@link EntityAccessorInstrumentationPlugin class that implements a Byte Buddy Plugin}.
26+
* to get the {@link ClassAccessorInstrumentationPlugin class that implements a Byte Buddy Plugin}.
2727
* Such a class is the one that actually applies the byte code transformation,
2828
* replacing accesses to public instance fields by getter/setter calls.
2929
*
@@ -38,7 +38,7 @@ public class AutoClassAccessorsMojo extends AbstractMojo {
3838
*/
3939
final MavenDependency accessorsPlugin = new MavenDependency(
4040
"io.github.manoelcampos", "auto-class-accessors-maven-plugin",
41-
"1.0.2"
41+
"1.0.3"
4242
);
4343

4444
private final MavenDependency byteBuddyPlugin = new MavenDependency("net.bytebuddy", "byte-buddy-maven-plugin", "1.17.2");
@@ -82,7 +82,7 @@ private void runByteBuddyPlugin(final String goal) throws MojoExecutionException
8282
element("groupId", accessorsPlugin.groupId()),
8383
element("artifactId", accessorsPlugin.artifactId()),
8484
element("version", accessorsPlugin.version()),
85-
element("plugin", EntityAccessorInstrumentationPlugin.class.getName())
85+
element("plugin", ClassAccessorInstrumentationPlugin.class.getName())
8686
)
8787
)
8888
),

src/main/java/io/github/manoelcampos/accessors/EntityAccessorInstrumentationPlugin.java renamed to src/main/java/io/github/manoelcampos/accessors/ClassAccessorInstrumentationPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* This plugin defines how the transformation will be done, indicating when and how byte code will be changed.
1818
* @author Manoel Campos
1919
*/
20-
public class EntityAccessorInstrumentationPlugin implements Plugin {
20+
public class ClassAccessorInstrumentationPlugin implements Plugin {
2121
@Override
2222
public DynamicType.Builder<?> apply(
2323
final DynamicType.Builder<?> builder,
@@ -60,7 +60,7 @@ private static AsmVisitorWrapper.ForDeclaredMethods newFieldWriteVisitor(final T
6060
/**
6161
* {@inheritDoc}
6262
* Indicates that only classes (where a field access was intercepted) will be transformed by this plugin.
63-
* This no, interfaces and records are not transformed since there is no need for them.
63+
* This way, interfaces and records are not transformed since there is no need for them.
6464
* @param typeDefinition {@inheritDoc}
6565
* @return {@inheritDoc}
6666
*/

src/main/java/io/github/manoelcampos/accessors/GetterMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Aa {@link ElementMatcher} to check if a method is the getter for a given field.
1111
* @author Manoel Campos
12-
* @see EntityAccessorInstrumentationPlugin
12+
* @see ClassAccessorInstrumentationPlugin
1313
*/
1414
class GetterMatcher extends AbstractAccessorMatcher {
1515
/**

src/main/java/io/github/manoelcampos/accessors/InstanceFieldMatcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* It's used to intercept reads and writes to such fields in order to replace them by the respective accessor method calls.
1515
*
1616
* @author Manoel Campos
17-
* @see EntityAccessorInstrumentationPlugin
17+
* @see ClassAccessorInstrumentationPlugin
1818
*/
1919
class InstanceFieldMatcher extends ElementMatcher.Junction.AbstractBase<FieldDescription> {
2020
/**
@@ -32,7 +32,7 @@ enum AccessorLookup {
3232
private FieldDescription fieldDescription;
3333

3434
/**
35-
* The type being transformed
35+
* The type being transformed, which is the one that declares the field being matched.
3636
*/
3737
private final TypeDescription typeDescription;
3838

src/main/java/io/github/manoelcampos/accessors/SetterMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Aa {@link ElementMatcher} to check if a method is the setter for a given field.
1111
* @author Manoel Campos
12-
* @see EntityAccessorInstrumentationPlugin
12+
* @see ClassAccessorInstrumentationPlugin
1313
*/
1414
class SetterMatcher extends AbstractAccessorMatcher {
1515
/**

0 commit comments

Comments
 (0)