Skip to content

SymTypeExpression and wrappers return a supplier in case the symbol c… - #372

Draft
SE-FDr wants to merge 23 commits into
MontiCore:devfrom
Chrisslue:add-supplier
Draft

SE-FDr wants to merge 23 commits into
MontiCore:devfrom
Chrisslue:add-supplier

Conversation

@SE-FDr

@SE-FDr SE-FDr commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

…an not be resolved immediatly

ASTCDAttribute attribute = ast;
String templateName = "methods.Set";
if (getDecorationHelper().isSupplier(ast.getMCType())) {
// expose the unwrapped type (Supplier<X> -> X) in the setter parameter; the Supplier stays hidden

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may need another method:
one that allows one to set a supplier (for Lazy creation in, e.g., SymbolAdapters).

};


public static boolean shouldBeSupplied(String t) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldBeSupplied -> shouldHaveSupplier/shouldBeAccessedViaSupplier/etc.

import java.util.Arrays;


public class AccessAsSupplierTyps {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class AccessAsSupplierTyps {
public class AccessAsSupplierTypes {

import java.util.Arrays;


public class AccessAsSupplierTyps {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs documentation on what this class is for


public class AccessAsSupplierTyps {

public static final String SUPPLIER_TYPE = "java.util.function.Supplier";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be public?

return;
}

String defaultValue;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the defaultValue is what comes after the =.
This is more like the defaultInitialization or simmilar?

return ((ASTMCGenericType) type).getMCTypeArgumentList().get(0);
}

public ASTMCTypeArgument getReferenceTypeFromSupply(ASTMCType type) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public ASTMCTypeArgument getReferenceTypeFromSupply(ASTMCType type) {
public ASTMCTypeArgument getReferenceTypeOfSupplier(ASTMCType type) {

?

return ((ASTMCGenericType) type).getMCTypeArgumentList().get(0);
}

public ASTMCType createSupplierTypeOf(ASTMCType inner) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this fit more in the MCTypeFacade?

@@ -21,11 +21,11 @@ public void setFunctionList(List<FunctionSymbol> methodList){
}

public List<SymTypeExpression> getSuperClassesOnly(){
return superTypes;
return superTypes.get();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer something like getSuperTypesList()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do both methods return the same? Is this correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... yes, kind-of.
It is questionable design wise,
but the idea is that we cannot distinguish between them for TypeSymbols,
so we simply return them all.

}

public List<SymTypeExpression> getInterfaceList(){
return superTypes;
return superTypes.get();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here as well

public static <T, R> Supplier<R> map(Supplier<T> source, Function<? super T, ? extends R> mapper) {
return new ClearingMemorizer<>(() -> {
T value = source.get();
return value == null ? null : mapper.apply(value);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can the mapper not accept null?

* Evaluates the wrapped supplier at most once and caches the result. Afterwards the
* supplier is released (and with it everything it captured, e.g. the JSON it deserializes from).
*/
public class ClearingMemorizer<T> implements Supplier<T> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it called Clearing? that is an internal detail.

/**
* Wraps the type of every attribute that {@link #shouldHaveSupplier} selects into the internal supplier type.
*/
public void wrapSuppliers(Collection<ASTCDAttribute> attributes) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapSuppliers does not say anything about storing the values

* so the internal wrapper never leaks into the public API.
*/
public ASTMCType toPublicSupplierType(ASTMCType type) {
return createStdSupplierTypeOf(unwrapSupplier(type));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me wonder if the setup is too complex.
I am not sure.

…on because we have multiple return types)

made ClearingMemorizer.map more general
}


public static TypeSymbol resolveTypeSymbolOrLogError(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be part of its public api, it has nothing to do with the Factory directly

@@ -21,11 +21,11 @@ public void setFunctionList(List<FunctionSymbol> methodList){
}

public List<SymTypeExpression> getSuperClassesOnly(){
return superTypes;
return superTypes.get();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... yes, kind-of.
It is questionable design wise,
but the idea is that we cannot distinguish between them for TypeSymbols,
so we simply return them all.

This branch has not been deployed

No deployments
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.

2 participants