Skip to content

Commit 96e6a26

Browse files
Fix code formatting and extract base class for Java code generating Mojos
1 parent dba3f13 commit 96e6a26

File tree

7 files changed

+36
-29
lines changed

7 files changed

+36
-29
lines changed

core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/JavaCodeGenerationConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public enum SetterStyle {
8181
if ( namePostfix == null ) {
8282
namePostfix = "";
8383
}
84-
if (setterStyle == null ) {
84+
if ( setterStyle == null ) {
8585
setterStyle = SetterStyle.STANDARD;
8686
}
8787
}

core/esmf-aspect-model-java-generator/src/test/java/org/eclipse/esmf/aspectmodel/java/StaticClassGenerationResult.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ public void assertMethods( final String className, final Map<String, String> exp
148148

149149
/**
150150
* Allows the assertion of method bodies for static meta properties in a generated meta class.
151-
*
151+
* <p>
152152
* Method bodies are asserted in a relaxed way:
153153
* <ul>
154154
* <li>all whitespace is trimmed before comparing</li>
155155
* <li>the given method body may also be just a part of the full method body, i.e. the check is performed using .contains()</li>
156156
* </ul>
157-
*
157+
* </p>
158158
* @param className the name of the meta class
159159
* @param propertyName the name of the property (given in CONSTANT_CASE)
160160
* @param expectedMethodBodies the expected (partial) contents of the static meta property methods, where the key is the method name
@@ -174,10 +174,12 @@ public void assertStaticMetaPropertyMethods( final String className, final Strin
174174
.stream()
175175
.map( VariableDeclarator::getInitializer )
176176
.flatMap( Optional::stream )
177-
.filter( exp -> exp instanceof ObjectCreationExpr )
177+
.filter( ObjectCreationExpr.class::isInstance )
178178
.map( ObjectCreationExpr.class::cast )
179-
.flatMap(
180-
oc -> oc.getChildNodes().stream().filter( n -> n instanceof MethodDeclaration ).map( MethodDeclaration.class::cast ) )
179+
.flatMap( oc -> oc.getChildNodes()
180+
.stream()
181+
.filter( MethodDeclaration.class::isInstance )
182+
.map( MethodDeclaration.class::cast ) )
181183
.anyMatch( md -> md.getBody()
182184
.map( b -> b.getStatements().stream().anyMatch(
183185
s -> expectedMethodBodies.containsKey( md.getName().toString() ) && s.toString().trim()

core/esmf-aspect-model-java-generator/src/test/java/org/eclipse/esmf/aspectmodel/java/StaticMetaModelJavaGeneratorTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Optional;
2929
import java.util.Set;
3030
import java.util.regex.Pattern;
31+
3132
import javax.xml.datatype.DatatypeFactory;
3233
import javax.xml.datatype.XMLGregorianCalendar;
3334

@@ -463,7 +464,7 @@ void testCharacteristicInstantiationForEnums() throws IOException {
463464
final String expectedTestPropertyCharacteristicConstructorCall =
464465
"""
465466
new DefaultEnumeration(MetaModelBaseAttributes.builder().withUrn(AspectModelUrn.fromUrn(NAMESPACE + "TestEnumeration")).build(), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer"), new ArrayList<Value>() {
466-
467+
467468
{
468469
add(new DefaultScalarValue(MetaModelBaseAttributes.builder().build(), new BigInteger("1"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
469470
add(new DefaultScalarValue(MetaModelBaseAttributes.builder().build(), new BigInteger("2"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
@@ -680,7 +681,8 @@ void testStaticMetaModelWithSetters() throws IOException {
680681
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode().apply( getGenerators( aspect, true,
681682
JavaCodeGenerationConfig.SetterStyle.STANDARD ) );
682683

683-
result.assertStaticMetaPropertyMethods( "MetaAspectWithEntity", "TEST_PROPERTY", Map.of("setValue","object.setTestProperty(value)") );
684+
result.assertStaticMetaPropertyMethods( "MetaAspectWithEntity", "TEST_PROPERTY",
685+
Map.of( "setValue", "object.setTestProperty(value)" ) );
684686
}
685687

686688
@Test
@@ -689,6 +691,6 @@ void testStaticMetaModelWithFluentCompactSetters() throws IOException {
689691
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode().apply( getGenerators( aspect, true,
690692
JavaCodeGenerationConfig.SetterStyle.FLUENT_COMPACT ) );
691693

692-
result.assertStaticMetaPropertyMethods( "MetaAspectWithEntity", "TEST_PROPERTY", Map.of("setValue","object.testProperty(value)") );
694+
result.assertStaticMetaPropertyMethods( "MetaAspectWithEntity", "TEST_PROPERTY", Map.of( "setValue", "object.testProperty(value)" ) );
693695
}
694696
}

tools/esmf-aspect-model-maven-plugin/src/main/java/org/eclipse/esmf/aspectmodel/GenerateJavaClasses.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.slf4j.LoggerFactory;
3131

3232
@Mojo( name = GenerateJavaClasses.MAVEN_GOAL, defaultPhase = LifecyclePhase.GENERATE_SOURCES )
33-
public class GenerateJavaClasses extends CodeGenerationMojo {
33+
public class GenerateJavaClasses extends JavaCodeGenerationMojo {
3434
public static final String MAVEN_GOAL = "generateJavaClasses";
3535
private static final Logger LOG = LoggerFactory.getLogger( GenerateJavaClasses.class );
3636

@@ -43,12 +43,6 @@ public class GenerateJavaClasses extends CodeGenerationMojo {
4343
@Parameter( defaultValue = "deduction" )
4444
protected String jsonTypeInfo;
4545

46-
@Parameter( defaultValue = "false" )
47-
protected boolean enableSetters;
48-
49-
@Parameter( defaultValue = "standard" )
50-
protected String setterStyle;
51-
5246
/**
5347
* Default constructor used by Maven plugin instantiation
5448
*/

tools/esmf-aspect-model-maven-plugin/src/main/java/org/eclipse/esmf/aspectmodel/GenerateStaticJavaClasses.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,14 @@
2525
import org.apache.maven.plugin.MojoExecutionException;
2626
import org.apache.maven.plugins.annotations.LifecyclePhase;
2727
import org.apache.maven.plugins.annotations.Mojo;
28-
import org.apache.maven.plugins.annotations.Parameter;
2928
import org.slf4j.Logger;
3029
import org.slf4j.LoggerFactory;
3130

3231
@Mojo( name = GenerateStaticJavaClasses.MAVEN_GOAL, defaultPhase = LifecyclePhase.GENERATE_SOURCES )
33-
public class GenerateStaticJavaClasses extends CodeGenerationMojo {
32+
public class GenerateStaticJavaClasses extends JavaCodeGenerationMojo {
3433
public static final String MAVEN_GOAL = "generateStaticJavaClasses";
3534
private static final Logger LOG = LoggerFactory.getLogger( GenerateStaticJavaClasses.class );
3635

37-
@Parameter( defaultValue = "false" )
38-
protected boolean enableSetters;
39-
40-
@Parameter( defaultValue = "standard" )
41-
protected String setterStyle;
42-
4336
@Override
4437
public void executeGeneration() throws MojoExecutionException {
4538
final Set<Aspect> aspects = loadAspects();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.eclipse.esmf.aspectmodel;
2+
3+
import org.apache.maven.plugins.annotations.Parameter;
4+
5+
/**
6+
* Base class for all Mojos that generate Java code.
7+
*/
8+
public abstract class JavaCodeGenerationMojo extends CodeGenerationMojo {
9+
@Parameter( defaultValue = "false" )
10+
protected boolean enableSetters;
11+
12+
@Parameter( defaultValue = "standard" )
13+
protected String setterStyle;
14+
}

tools/samm-cli/src/test/java/org/eclipse/esmf/SammCliTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,8 @@ void testAspectToJavaWithSetters() {
704704
void testAspectToJavaWithFluentSetters() {
705705
final File outputDir = outputDirectory.toFile();
706706
final ExecutionResult result = sammCli.runAndExpectSuccess( "--disable-color", "aspect", defaultInputFile, "to", "java",
707-
"--output-directory", outputDir.getAbsolutePath(), "--custom-resolver", resolverCommand(), "--enable-setters", "--setter-style", "FLUENT" );
707+
"--output-directory", outputDir.getAbsolutePath(), "--custom-resolver", resolverCommand(), "--enable-setters", "--setter-style",
708+
"FLUENT" );
708709
assertThat( result.stdout() ).isEmpty();
709710
assertThat( result.stderr() ).isEmpty();
710711

@@ -721,7 +722,8 @@ void testAspectToJavaWithFluentSetters() {
721722
void testAspectToJavaWithFluentCompactSetters() {
722723
final File outputDir = outputDirectory.toFile();
723724
final ExecutionResult result = sammCli.runAndExpectSuccess( "--disable-color", "aspect", defaultInputFile, "to", "java",
724-
"--output-directory", outputDir.getAbsolutePath(), "--custom-resolver", resolverCommand(), "--enable-setters", "--setter-style", "FLUENT_COMPACT" );
725+
"--output-directory", outputDir.getAbsolutePath(), "--custom-resolver", resolverCommand(), "--enable-setters", "--setter-style",
726+
"FLUENT_COMPACT" );
725727
assertThat( result.stdout() ).isEmpty();
726728
assertThat( result.stderr() ).isEmpty();
727729

@@ -1642,7 +1644,7 @@ private File inputFile( final String filename ) {
16421644
* Returns the File object for a test model file
16431645
*/
16441646
private File inputFile( final TestModel testModel ) {
1645-
final boolean isValid = !( testModel instanceof InvalidTestAspect );
1647+
final boolean isValid = !(testModel instanceof InvalidTestAspect);
16461648
final String resourcePath = String.format(
16471649
"%s/../../core/esmf-test-aspect-models/src/main/resources/%s/org.eclipse.esmf.test/1.0.0/%s.ttl",
16481650
System.getProperty( "user.dir" ), isValid ? "valid" : "invalid", testModel.getName() );
@@ -1693,8 +1695,8 @@ private String resolverCommand() {
16931695
// are not resolved to the file system but to the jar)
16941696
try {
16951697
final String resolverScript = new File(
1696-
System.getProperty( "user.dir" ) + "/target/test-classes/model_resolver" + ( OS.WINDOWS.isCurrentOs()
1697-
? ".bat" : ".sh" ) ).getCanonicalPath();
1698+
System.getProperty( "user.dir" ) + "/target/test-classes/model_resolver" + (OS.WINDOWS.isCurrentOs()
1699+
? ".bat" : ".sh") ).getCanonicalPath();
16981700
final String modelsRoot = new File( System.getProperty( "user.dir" ) + "/target/classes/valid" ).getCanonicalPath();
16991701
final String metaModelVersion = KnownVersion.getLatest().toString().toLowerCase();
17001702
return resolverScript + " " + modelsRoot + " " + metaModelVersion;

0 commit comments

Comments
 (0)