Skip to content
Snippets Groups Projects
Commit fe27ca8c authored by Jay Billings's avatar Jay Billings
Browse files

ICE now generates auto-registering factories for DataElements.


Also fixed some typos and version numbers.

Signed-off-by: default avatarJay Jay Billings <jayjaybillings@gmail.com>
parent 8aba8c0a
No related branches found
No related tags found
No related merge requests found
Pipeline #73973 failed
Showing
with 287 additions and 27 deletions
......@@ -33,27 +33,23 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
......@@ -31,7 +31,7 @@
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0-rc6</version>
<version>1.1.1</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
......@@ -155,7 +155,7 @@
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0-rc6</version>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<!-- Lombok -->
......
......@@ -24,7 +24,7 @@ import java.lang.annotation.Target;
* the new application.
*
* Unlike other ICE annotations, CommandLineApp will only produce an
* implementation, not and interface and an implementation. An interface is
* implementation, not an interface and an implementation. An interface is
* not needed since main() is implemented as a function in its own class.
*
* @author Jay Jay Billings
......
/*******************************************************************************
* Copyright (c) 2025- The Band Gap Corporation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Jay Jay Billings - Initial implementation
*******************************************************************************/
package org.eclipse.ice.dev.annotations.processors;
import java.io.IOException;
import java.io.Writer;
import javax.annotation.processing.Filer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This writer is used for created Data Element Factories from the Velocity
* template.
* @author Jay Jay Billings
*/
public class DataElementFactoryWriter extends VelocitySourceWriter implements GeneratedFileWriter {
/**
* Context key for package.
*/
private static final String PACKAGE = "package";
/**
* Context key for interface.
*/
private static final String INTERFACE = "interface";
/**
* Logging tool
*/
private static final Logger logger = LoggerFactory.getLogger(CommandLineAppWriter.class);
/**
* Fully qualified name of generated interface;
*/
private String fullyQualifiedName;
/**
* Location of CommandLineApp template for use with Velocity.
*/
private static final String IMPL_TEMPLATE = "templates/DataElementFactory.vm";
/**
* Constructor
*
* @param data the metadata for the data element currently being processed
*/
public DataElementFactoryWriter(DataElementMetadata data) {
super(IMPL_TEMPLATE);
this.fullyQualifiedName = data.getFullyQualifiedName() + "Factory";
context.put(PACKAGE, data.getPackageName());
context.put(INTERFACE, data.getName());
}
@Override
public Writer openWriter(Filer filer) throws IOException {
logger.debug("Apache velocity context for @DataElement factory: " + context);
return filer.createSourceFile(fullyQualifiedName).openWriter();
}
}
......@@ -46,6 +46,7 @@ import com.google.auto.service.AutoService;
*
* @author Daniel Bluhm
* @author Michael Walsh
* @author Jay Jay Billings
*
*/
@SupportedAnnotationTypes({
......
......@@ -44,6 +44,7 @@ public class DataElementWriterGenerator implements WriterGenerator {
List<GeneratedFileWriter> writers = new ArrayList<>();
writers.add(new InterfaceWriter(data));
writers.add(new ImplementationWriter(data));
writers.add(new DataElementFactoryWriter(data));
try {
writers.add(new TypeScriptWriter(data));
} catch (UnsupportedOperationException e) {
......
......@@ -35,6 +35,9 @@ import org.slf4j.LoggerFactory;
* instance that happened to come first in the pool to be ignored when building
* objects.
*
* 20250513 - It strikes me that this is a bullshit class and should be deleted
* at the earliest possible opportunity. ~JJB
*
* @author Daniel Bluhm
*/
public class FromDataBuilder<T> {
......
......@@ -62,14 +62,10 @@ public class ImplementationWriter
*/
private String fullyQualifiedName;
/**
/**
* Constructor
*
* @param packageName
* @param interfaceName
* @param className
* @param fields
* @param generatedFile
* @param data the metadata for the data element currently being processed
*/
public ImplementationWriter(DataElementMetadata data) {
super(IMPL_TEMPLATE);
......
......@@ -58,22 +58,19 @@ public class InterfaceWriter
/**
* Fully qualified name of generated interface;
*/
private String fqn;
private String fullyQualifiedName;
/**
* Constructor
*
* @param packageName
* @param interfaceName
* @param fields
* @param generatedFile
* @param data the metadata for the data element currently being processed
*/
public InterfaceWriter(
DataElementMetadata data
) {
super(TEMPLATE);
this.fqn = data.getFullyQualifiedName();
this.fullyQualifiedName = data.getFullyQualifiedName();
Fields fields = data.getFields().getNonDefaultFields();
context.put(PACKAGE, data.getPackageName());
context.put(INTERFACE, data.getName());
......@@ -83,6 +80,6 @@ public class InterfaceWriter
@Override
public Writer openWriter(Filer filer) throws IOException {
return filer.createSourceFile(fqn).openWriter();
return filer.createSourceFile(fullyQualifiedName).openWriter();
}
}
#if($package)
package $package;
#end
import org.eclipse.ice.data.IDataElement;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
#imports
/**
* This is a factory for creating ${interface} instances.
*/
@ApplicationScoped
public class ${interface}Factory {
/**
* This function produces a default (i.e., nullary-constructed) instance
* of ${interface}.
*/
@Produces public ${interface} build() throws Exception {
return ${interface}Implementation.builder().build();
}
/**
* This function returns the configurable builder that can be used to
* create customized instances of ${interface}.
*/
@Produces public ${interface}Implementation.${interface}ImplementationBuilder builder() {
return ${interface}Implementation.builder();
}
}
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2020- UT-Battelle, LLC.
* Copyright (c) 2020- UT-Battelle, LLC., 2025- The Band Gap Corporation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
......@@ -7,6 +7,7 @@
*
* Contributors:
* Daniel Bluhm - Initial implementation
* Jay Jay Billings - Enhancements
*******************************************************************************/
package org.eclipse.ice.tests.dev.annotations.processors;
......@@ -41,7 +42,7 @@ import lombok.AllArgsConstructor;
* }
* </pre>
* @author Daniel Bluhm
*
* @author Jay Jay Billings
*/
class DataElementProcessorTest {
......@@ -61,6 +62,11 @@ class DataElementProcessorTest {
*/
private static final String IMPLEMENTATION = "TestImplementation";
/**
* Fully qualified name of the generated implementation.
*/
private static final String FACTORY = "TestFactory";
/**
* Logger.
*/
......@@ -116,14 +122,19 @@ class DataElementProcessorTest {
private static enum Patterns implements JavaFileObjectResource {
DEFAULTS_INT("Defaults.java"),
DEFAULTS_IMPL("DefaultsImplementation.java"),
DEFAULTS_FACTORY("DefaultsFactory.java"),
SINGLE_INT("Single.java"),
SINGLE_IMPL("SingleImplementation.java"),
SINGLE_FACTORY("SingleFactory.java"),
MANY_INT("Many.java"),
MANY_IMPL("ManyImplementation.java"),
MANY_FACTORY("ManyFactory.java"),
SINGLE_NON_PRIMITIVE_INT("SingleNonPrimitive.java"),
SINGLE_NON_PRIMITIVE_IMPL("SingleNonPrimitiveImplementation.java"),
SINGLE_NON_PRIMITIVE_FACTORY("SingleNonPrimitiveFactory.java"),
MANY_NON_PRIMITIVE_INT("ManyNonPrimitive.java"),
MANY_NON_PRIMITIVE_IMPL("ManyNonPrimitiveImplementation.java"),
MANY_NON_PRIMITIVE_FACTORY("ManyNonPrimitiveFactory.java"),
ACCESSIBILITY_PRESERVED("AccessibilityPreserved.java"),
DATAFIELD_GETTER_INT("Getter.java"),
DATAFIELD_SETTER_INT("Setter.java"),
......@@ -160,7 +171,6 @@ class DataElementProcessorTest {
}
/**
* Assert that the interface generated in this compilation matches the given
* pattern.
* @param compilation about which the assertion is made
......@@ -187,6 +197,19 @@ class DataElementProcessorTest {
.containsElementsIn(impl);
}
/**
* Assert that the factory generated in this compilation matches the given
* pattern.
* @param compilation about which the assertion is made
* @param factory factory pattern
*/
private static void assertFactoryMatches(Compilation compilation, JavaFileObject factory) {
assertThat(compilation)
.generatedSourceFile(FACTORY)
.containsElementsIn(factory);
}
/**
* Assert that the default fields were generated.
* @param compilation about which the assertion is made
......@@ -194,6 +217,7 @@ class DataElementProcessorTest {
private static void assertDefaultsPresent(Compilation compilation) {
assertInterfaceMatches(compilation, Patterns.DEFAULTS_INT.get());
assertImplementationMatches(compilation, Patterns.DEFAULTS_IMPL.get());
assertFactoryMatches(compilation, Patterns.DEFAULTS_FACTORY.get());
}
/**
......@@ -260,6 +284,7 @@ class DataElementProcessorTest {
assertSucceededAndLogWarnings(compilation);
assertInterfaceMatches(compilation, Patterns.SINGLE_INT.get());
assertImplementationMatches(compilation, Patterns.SINGLE_IMPL.get());
assertFactoryMatches(compilation, Patterns.SINGLE_FACTORY.get());
}
/**
......@@ -271,6 +296,7 @@ class DataElementProcessorTest {
assertSucceededAndLogWarnings(compilation);
assertInterfaceMatches(compilation, Patterns.MANY_INT.get());
assertImplementationMatches(compilation, Patterns.MANY_IMPL.get());
assertFactoryMatches(compilation, Patterns.MANY_FACTORY.get());
}
/**
......@@ -282,6 +308,7 @@ class DataElementProcessorTest {
assertSucceededAndLogWarnings(compilation);
assertInterfaceMatches(compilation, Patterns.SINGLE_NON_PRIMITIVE_INT.get());
assertImplementationMatches(compilation, Patterns.SINGLE_NON_PRIMITIVE_IMPL.get());
assertFactoryMatches(compilation, Patterns.SINGLE_NON_PRIMITIVE_FACTORY.get());
}
/**
......@@ -293,6 +320,7 @@ class DataElementProcessorTest {
assertSucceededAndLogWarnings(compilation);
assertInterfaceMatches(compilation, Patterns.MANY_NON_PRIMITIVE_INT.get());
assertImplementationMatches(compilation, Patterns.MANY_NON_PRIMITIVE_IMPL.get());
assertFactoryMatches(compilation, Patterns.MANY_NON_PRIMITIVE_FACTORY.get());
}
/**
......
import org.eclipse.ice.data.IDataElement;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
/**
* This is a factory for creating Test instances.
*/
@ApplicationScoped
public class TestFactory {
/**
* This function produces a default (i.e., nullary-constructed) instance
* of Test.
*/
@Produces public Test build() throws Exception {
return TestImplementation.builder().build();
}
/**
* This function returns the configurable builder that can be used to
* create customized instances of Test.
*/
@Produces public TestImplementation.TestImplementationBuilder builder() {
return TestImplementation.builder();
}
}
\ No newline at end of file
import org.eclipse.ice.data.IDataElement;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
/**
* This is a factory for creating Test instances.
*/
@ApplicationScoped
public class TestFactory {
/**
* This function produces a default (i.e., nullary-constructed) instance
* of Test.
*/
@Produces public Test build() throws Exception {
return TestImplementation.builder().build();
}
/**
* This function returns the configurable builder that can be used to
* create customized instances of Test.
*/
@Produces public TestImplementation.TestImplementationBuilder builder() {
return TestImplementation.builder();
}
}
\ No newline at end of file
import org.eclipse.ice.data.IDataElement;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
/**
* This is a factory for creating Test instances.
*/
@ApplicationScoped
public class TestFactory {
/**
* This function produces a default (i.e., nullary-constructed) instance
* of Test.
*/
@Produces public Test build() throws Exception {
return TestImplementation.builder().build();
}
/**
* This function returns the configurable builder that can be used to
* create customized instances of Test.
*/
@Produces public TestImplementation.TestImplementationBuilder builder() {
return TestImplementation.builder();
}
}
\ No newline at end of file
import org.eclipse.ice.data.IDataElement;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
/**
* This is a factory for creating Test instances.
*/
@ApplicationScoped
public class TestFactory {
/**
* This function produces a default (i.e., nullary-constructed) instance
* of Test.
*/
@Produces public Test build() throws Exception {
return TestImplementation.builder().build();
}
/**
* This function returns the configurable builder that can be used to
* create customized instances of Test.
*/
@Produces public TestImplementation.TestImplementationBuilder builder() {
return TestImplementation.builder();
}
}
\ No newline at end of file
import org.eclipse.ice.data.IDataElement;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
/**
* This is a factory for creating Test instances.
*/
@ApplicationScoped
public class TestFactory {
/**
* This function produces a default (i.e., nullary-constructed) instance
* of Test.
*/
@Produces public Test build() throws Exception {
return TestImplementation.builder().build();
}
/**
* This function returns the configurable builder that can be used to
* create customized instances of Test.
*/
@Produces public TestImplementation.TestImplementationBuilder builder() {
return TestImplementation.builder();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment