Skip to content

Conversation

@glelouet
Copy link
Contributor

@glelouet glelouet commented Sep 18, 2025

Depends on #113 for the yaml tests

This feature allows to specify how fields are accessed (inside a container, "can"), with developer extension in mind

  • weak reference and no container(=default) options
  • developer extensions
  • javafx container in the external modules (binds to external libs)
  • WeakHashMap for caching, abstract FieldType createField(Object) for cache miss

User Usage

add the field option corresponding :

WeakRefTest:
  var:
     hash:
        class: string
        options:
           - weakref

Which generates:

public class WeakRefTest {
    private WeakReference<String> hash;

    /**
     * set the {@link #hash}
     */
    public void setHash(String hash) {
        this.hash = new WeakReference<String>(hash);
    }

    /**
     * @return the {@link #hash}
     */
    public String getHash() {
        return hash.get();
    }
}

Dev extension

Model :

The available canners are listed by the generator, the stream of which can be concatenated to override values

	Stream<Entry<String, Class<? extends FieldCanner>>> FlatStructureGenerator::streamCanners() {
		return Stream.of(
				new SimpleEntry<>("weakref", WeakReferenceCanner.class),
				new SimpleEntry<>("", NoCanner.class));
	}

If the option received by the FlatStructureGenerator is such an alias of canner, it is stored in the FieldOptions

	protected void FlatStructureGenerator::applyToFieldOptions(String optStr, FieldOptions options) {
       …
		if (cannersAliases().contains(optStr)) {
			options.setCanner(optStr);
			return;
		}

At the moment only the empty one (NoCanner) and the Weak Reference one (WeakReferenceCanner) are present.

Those canners can change the actual field type ( String -> WeakReference\<String> ) , the way it is get ( field -> field.get() ), set (field=param -> field= new WeakReference<String>(param)), and app specific property accessor.
Default "additional" method is scheduled to allow more complex code additions.

Extension :

If a developer wants to change (ad or replace), he can create his own class, and register them in his own Generator subclass. for example,

	Stream<Entry<String, Class<? extends FieldCanner>>> FlatStructureGenerator::streamCanners() {
		return Stream.concat(
				super.streamCanners(), 
				Stream.of(new SimpleEntry<>("", WeakReferenceCanner.class)));

would make the default accessor using weak references. Which would fail for primitive but hey ! he can.

glelouet and others added 15 commits September 6, 2025 22:09
"name" for shorter and easier to wollow ones.
redirected methods are now sorted by:
 1. method name
 2. number of arguments
 3. method signature (using Method::toString)

Canners now have a general call addAdditional which by default redirects
to specific getter/setter methods (empty), can prevent actual getter and
setter methods, and are called to create the actual field (default is
usual), which allows to assign it.
@glelouet
Copy link
Contributor Author

I think mutator would be a better name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant