ASTCreator cannot handle lists of strings
peterwvj opened this issue · 2 comments
peterwvj commented
Given the tree specification below:
Packages
base demo.ast;
analysis demo.analysis;
Tokens
java_String = 'java:java.lang.String';
Abstract Syntax Tree
Top {-> package='demo.ast.nodes'}
= {test} [field]:java_String*
;
Aspect Declaration
The code produced by ASTCreator does not compile since there seems to be a problem with the way that the tool handles lists of strings. The compilation errors are:
[ERROR] /home/peter/dev/playground/string-bug/target/generated-sources/astCreator/demo/ast/nodes/ATestTop.java:[114,25] no suitable method found for cloneListExternal(java.util.List<capture#1 of ? extends java.lang.String>)
method demo.ast.Node.<T>cloneListExternal(java.util.List<T>,java.util.Map<demo.ast.INode,demo.ast.INode>) is not applicable
(cannot instantiate from arguments because actual and formal argument lists differ in length)
method demo.ast.Node.<T>cloneListExternal(java.util.List<T>) is not applicable
(inferred type does not conform to declared bound(s)
inferred: capture#1 of ? extends java.lang.String
bound(s): demo.ast.ExternalNode)
[ERROR] /home/peter/dev/playground/string-bug/target/generated-sources/astCreator/demo/ast/nodes/ATestTop.java:[146,25] no suitable method found for cloneListExternal(java.util.List<capture#2 of ? extends java.lang.String>,java.util.Map<demo.ast.INode,demo.ast.INode>)
method demo.ast.Node.<T>cloneListExternal(java.util.List<T>,java.util.Map<demo.ast.INode,demo.ast.INode>) is not applicable
(inferred type does not conform to declared bound(s)
inferred: capture#2 of ? extends java.lang.String
bound(s): demo.ast.ExternalNode)
method demo.ast.Node.<T>cloneListExternal(java.util.List<T>) is not applicable
(cannot instantiate from arguments because actual and formal argument lists differ in length)
peterwvj commented
One workaround for this is to use an externally defined class to wrap the strings. In Overture this is done using the org.overture.ast.node.ExternalNode.ClonableString
class.
lausdahl commented
This is actually by design. So what should we do:
- Add a check saying that only object extending
ExternalNode
and specified asjava_String = 'java:node:java.lang.String';
can be used for lists of any kind. - Add yet another type of list which can handle basic java types which do not need cloning since they are by value.