| <?xml version="1.0" encoding="UTF-8"?> |
| <templates><template id="ASTAbstractRule.cu" name="ASTAbstractRule.cu" description="ASTAbstractRule CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaRuleCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName}; |
| |
| /** |
| * |
| * ${generatedBy} |
| */ |
| public abstract class ${typeName} ${extends} { |
| /** |
| * Construct a new ${typeName}. |
| */ |
| public ${typeName}() { |
| super(); |
| } |
| |
| ${ASTVisitorClass_acceptImpl} |
| |
| }</template><template id="ASTBaseClass.cu" name="ASTBaseClass.cu" description="ASTBaseClass CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName}; |
| |
| import org.eclipse.gymnast.runtime.core.ast.ASTNode; |
| import org.eclipse.gymnast.runtime.core.ast.ASTNodeImpl; |
| import org.eclipse.gymnast.runtime.core.ast.TokenInfo; |
| |
| /** |
| * The superclass of all ASTNodes for language ${astName}. |
| * |
| * ${generatedBy} |
| */ |
| public abstract class ${astBaseClassName} extends ${astBaseClassBaseName} { |
| |
| protected ${astBaseClassName} _parent; |
| |
| /** |
| * @return the parent of this ASTNode or null if this is the root node of a tree |
| */ |
| public ASTNode getParent() { |
| return _parent; |
| } |
| |
| /** |
| * Construct a new ${astBaseClassName}. |
| */ |
| public ${astBaseClassName}() { |
| super(); |
| } |
| |
| /** |
| * Construct a new ${astBaseClassName}. |
| * |
| * @param token a Token to initialize the offset and text for this node. |
| */ |
| public ${astBaseClassName}(TokenInfo tokenInfo) { |
| super(tokenInfo); |
| } |
| |
| /** |
| * The external entry point used to initiate the visitor on this node. |
| * |
| * @param visitor the Visitor to visit this node tree |
| */ |
| public final void accept(${astVisitorClassName} visitor) { |
| visitor.preVisit(this); |
| acceptImpl(visitor); |
| visitor.postVisit(this); |
| } |
| |
| /** |
| * This method can be overridden by subclasses which should provide exactly |
| * the same implementation. Here <code>this</code> refers to the generic node |
| * class, but in the subclass implementations <code>this</code> will refer to |
| * the specific subclass type. Thus the correct specific <code>beginVisit</code> |
| * and <code>endVisit</code> methods will be invoked for each subclass and the |
| * generic methods will be invoked for subclasses that don't need specific visitor |
| * behavior. |
| */ |
| public void acceptImpl(${astVisitorClassName} visitor) { |
| boolean visitChildren = visitor.beginVisit(this); |
| if (visitChildren) visitChildren(visitor); |
| visitor.endVisit(this); |
| } |
| |
| /** |
| * Iterate through the children of this node and accept the visitor on each. |
| */ |
| protected void visitChildren(${astVisitorClassName} visitor) { |
| for (int i = 0; i < getChildCount(); i++) { |
| ASTNode child = getChild(i); |
| if (child instanceof ${astBaseClassName}) { |
| ${astBaseClassName} c = (${astBaseClassName})child; |
| c.accept(visitor); |
| } |
| } |
| } |
| |
| } |
| </template><template id="ASTContainerRule.cu" name="ASTContainerRule.cu" description="ASTContainerRule CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaRuleCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName}; |
| |
| import org.eclipse.gymnast.runtime.core.ast.ASTNode; |
| |
| /** |
| * |
| * ${generatedBy} |
| */ |
| public ${typeKind} ${typeName} ${extends} ${implements} { |
| |
| ${^foreach_KeywordLiteral} public static final String KW_${literal_UC} = "${literal}"; |
| ${^END} |
| ${^foreach_ChildElement} private ${childType} _${childName}; |
| ${^END} |
| ${^foreach_ChildElement} public ${childType} getAs${childName_UC}() { |
| return _${childName}; |
| } |
| ${^END} |
| |
| ${^foreach_ChildElement} public boolean isChild${childName_UC}() { |
| return _${childName} != null; |
| } |
| ${^END} |
| |
| /** |
| * @return the number of children of this ASTNode |
| */ |
| public int getChildCount() { |
| int count = 0; |
| ${^foreach_ChildElement} if (_${childName} != null) count++; |
| ${^END} |
| return count; |
| } |
| |
| /** |
| * @param index the index of a child ASTNode to get |
| * @return the child ASTNode at the given index |
| * @throws IndexOutOfBoundsException when the index is out of bounds |
| */ |
| public ASTNode getChild(int index) { |
| if (index != 0) throw new IndexOutOfBoundsException(); |
| ${^foreach_ChildElement} if (_${childName} != null) return _${childName}; |
| ${^END} |
| throw new IndexOutOfBoundsException(); |
| } |
| |
| /** |
| * Construct a new ${typeName}. |
| */ |
| public ${typeName}() { |
| super(); |
| } |
| |
| ${^foreach_ChildElement} public void initAs${childName_UC}(${childTypeOrToken} ${childName}) { |
| if (_${childName}._parent != null) throw new RuntimeException(); |
| _${childName}._parent = this; |
| _${childName} = ${childName}; |
| } |
| ${^END} |
| |
| ${ASTVisitorClass_acceptImpl} |
| |
| } |
| </template><template id="ASTListRule.cu" name="ASTListRule.cu" description="ASTListRule CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaRuleCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName}; |
| |
| import java.util.ArrayList; |
| import org.eclipse.gymnast.runtime.core.ast.ASTNode; |
| import org.eclipse.gymnast.runtime.core.ast.TokenInfo; |
| |
| /** |
| * |
| * ${generatedBy} |
| */ |
| public ${typeKind} ${typeName} ${extends} { |
| |
| private ArrayList _children = new ArrayList(); |
| |
| /** |
| * @return the number of children of this ASTNode |
| */ |
| public int getChildCount() { |
| return _children.size(); |
| } |
| |
| /** |
| * @param index the index of a child ASTNode to get |
| * @return the child ASTNode at the given index |
| * @throws IndexOutOfBoundsException when the index is out of bounds |
| */ |
| public ASTNode getChild(int index) { |
| return (ASTNode)_children.get(index); |
| } |
| |
| /** |
| * Add a child to this list. |
| */ |
| public void addChild(${astBaseClassName} child) { |
| if (child == null) return; |
| if (child._parent != null) throw new RuntimeException(); |
| _children.add(child); |
| child._parent = this; |
| } |
| |
| /** |
| * Wrap the provided Token in a ${astTokenClassName} |
| * and add it as a child of this node. |
| * |
| * @param token the Token to be added as a child of this node |
| */ |
| public void addChild(TokenInfo tokenInfo) { |
| addChild(new ${astTokenClassName}(tokenInfo)); |
| } |
| |
| /** |
| * Construct a new ${typeName}. |
| */ |
| public ${typeName}() { |
| super(); |
| } |
| |
| ${ASTVisitorClass_acceptImpl} |
| |
| } |
| </template><template id="ASTSequenceRule.cu" name="ASTSequenceRule.cu" description="ASTSequenceRule CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaRuleCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName}; |
| |
| import org.eclipse.gymnast.runtime.core.ast.ASTNode; |
| import org.eclipse.gymnast.runtime.core.ast.TokenInfo; |
| |
| /** |
| * |
| * ${generatedBy} |
| */ |
| public ${typeKind} ${typeName} ${extends} ${implements} { |
| |
| ${^foreach_KeywordLiteral} public static final String KW_${literal_UC} = "${literal}"; |
| ${^END} |
| ${^foreach_ChildElement} private ${childType} _${childName}; |
| ${^END} |
| ${^foreach_ChildElement} public ${childType} get${childName_UC}() { |
| return _${childName}; |
| } |
| ${^END} |
| |
| /** |
| * @return the number of children of this ASTNode |
| */ |
| public int getChildCount() { |
| int count = 0; |
| ${^foreach_ChildElement} if (_${childName} != null) count++; |
| ${^END} |
| return count; |
| } |
| |
| /** |
| * @param index the index of a child ASTNode to get |
| * @return the child ASTNode at the given index |
| * @throws IndexOutOfBoundsException when the index is out of bounds |
| */ |
| public ASTNode getChild(int index) { |
| int count = -1; |
| ${^foreach_ChildElement} if ((_${childName} != null) && (++count == index)) return _${childName}; |
| ${^END} |
| throw new IndexOutOfBoundsException(); |
| } |
| |
| /** |
| * Construct a new ${typeName}. |
| */ |
| public ${typeName}( |
| ${^foreach_ChildElement} ${childTypeOrToken} ${childName}${comma} |
| ${^END} ) { |
| super(); |
| |
| ${^foreach_ChildElement} if (${childName} != null) { |
| _${childName} = ${initExpr}; |
| if (_${childName}._parent != null) throw new RuntimeException(); |
| _${childName}._parent = this; |
| } |
| ${^END} |
| } |
| |
| ${ASTVisitorClass_acceptImpl} |
| |
| } |
| </template><template id="ASTTokenClass.cu" name="ASTTokenClass.cu" description="ASTTokenClass CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName}; |
| |
| import org.eclipse.gymnast.runtime.core.ast.ASTNode; |
| import org.eclipse.gymnast.runtime.core.ast.TokenInfo; |
| |
| /** |
| * Represents a token in the language grammar. |
| * Can be subclassed to represent specific token subgroups. |
| * |
| * ${generatedBy} |
| */ |
| public class ${astTokenClassName} extends ${astBaseClassName} { |
| |
| /** |
| * @return the number of children of this ASTNode |
| */ |
| public final int getChildCount() { |
| // token rules cannot have children! |
| return 0; |
| } |
| |
| /** |
| * @param index the index of a child ASTNode to get |
| * @return the child ASTNode at the given index |
| * @throws IndexOutOfBoundsException when the index is out of bounds |
| */ |
| public final ASTNode getChild(int index) { |
| // token rules cannot have children! |
| throw new IndexOutOfBoundsException(); |
| } |
| |
| /** |
| * Construct a new ${astTokenClassName} |
| */ |
| public ${astTokenClassName}(TokenInfo tokenInfo) { |
| super(tokenInfo); |
| } |
| |
| ${ASTVisitorClass_acceptImpl} |
| |
| } |
| </template><template id="ASTTokenRule.cu" name="ASTTokenRule.cu" description="ASTTokenRule CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaRuleCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName}; |
| |
| import org.eclipse.gymnast.runtime.core.ast.TokenInfo; |
| |
| /** |
| * |
| * ${generatedBy} |
| */ |
| public class ${typeName} extends ${astTokenClassName} { |
| |
| ${^foreach_KeywordLiteral} public static final String KW_${literal_UC} = "${literal}"; |
| ${^END} |
| |
| /** |
| * Construct a new ${typeName}. |
| */ |
| public ${typeName}(TokenInfo tokenInfo) { |
| super(tokenInfo); |
| } |
| |
| ${ASTVisitorClass_acceptImpl} |
| |
| }</template><template id="ASTVisitorClass.cu" name="ASTVisitorClass.cu" description="ASTVisitorClass CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName}; |
| |
| /** |
| * A Visitor pattern stub implementation for language ${astName}. |
| * |
| * ${generatedBy} |
| */ |
| public class ${astVisitorClassName} { |
| |
| /** |
| * The external entry point used to perform a visit beginning at the given node. |
| * |
| * @param node the ${astBaseClassName} to visit |
| */ |
| public final void visit(${astBaseClassName} node) { |
| node.accept(this); |
| } |
| |
| /** |
| * Called just before <code>beginVisit</code> for each node being visited. |
| * This may be overridden to provide special behavior at that point in processing. |
| * |
| * @param node the ${astBaseClassName} currently being visited |
| */ |
| public void preVisit(${astBaseClassName} node) { |
| } |
| |
| /** |
| * Called just after <code>endVisit</code> for each node being visited. |
| * This may be overridden to provide special behavior at that point in processing. |
| * |
| * @param node the ${astBaseClassName} currently being visited |
| */ |
| public void postVisit(${astBaseClassName} node) { |
| } |
| |
| /** |
| * This is called, for each node being visited, just after <code>preVisit</code> and |
| * before (optionally) visiting the children of the node. |
| * This <code>beginVisit</code> method is the generic one called for node types that |
| * don't provide a specific overloaded form of <code>beginVisit</code>. |
| * This may be overridden to provide special behavior at that point in processing. |
| * |
| * @param node the ${astBaseClassName} currently being visited |
| * @return true to visit the children of the node, false to prevent visiting the children of the node |
| */ |
| public boolean beginVisit(${astBaseClassName} node) { |
| return true; |
| } |
| |
| /** |
| * This is called, for each node being visited, after <code>beginVisit</code> and |
| * (optionally) visiting the children of the node and before <code>postVisit</code>. |
| * This <code>endVisit</code> method is the generic one called for node types that |
| * don't provide a specific overloaded form of <code>endVisit</code>. |
| * This may be overridden to provide special behavior at that point in processing. |
| * |
| * @param node the ${astBaseClassName} currently being visited |
| */ |
| public void endVisit(${astBaseClassName} node) { |
| } |
| |
| /** |
| * This is called, for each node being visited, just after <code>preVisit</code> and |
| * before (optionally) visiting the children of the node. |
| * This <code>beginVisit</code> method is the specific one called for nodes |
| * of type <code>${astTokenClassName}</code> |
| * This may be overridden to provide special behavior at that point in processing. |
| * |
| * @param tokenNode the node currently being visited |
| * @return true to visit the children of the node, false to prevent visiting the children of the node |
| */ |
| public boolean beginVisit(${astTokenClassName} tokenNode) { |
| return beginVisit((${astBaseClassName})tokenNode); |
| } |
| |
| /** |
| * This is called, for each node being visited, after <code>beginVisit</code> and |
| * (optionally) visiting the children of the node and before <code>postVisit</code>. |
| * This <code>endVisit</code> method is the specific one called for nodes |
| * of type <code>${astTokenClassName}</code> |
| * This may be overridden to provide special behavior at that point in processing. |
| * |
| * @param tokenNode the node currently being visited |
| */ |
| public void endVisit(${astTokenClassName} tokenNode) { |
| endVisit((${astBaseClassName})tokenNode); |
| } |
| |
| ${^foreach_Rule} /** |
| * This is called, for each node being visited, just after <code>preVisit</code> and |
| * before (optionally) visiting the children of the node. |
| * This <code>beginVisit</code> method is the specific one called for nodes |
| * of type <code>${ruleName_UC}</code> |
| * This may be overridden to provide special behavior at that point in processing. |
| * |
| * @param ${ruleName_LC} the node currently being visited |
| * @return true to visit the children of the node, false to prevent visiting the children of the node |
| */ |
| public boolean beginVisit(${ruleName_UC} ${ruleName_LC}) { |
| return beginVisit((${ruleBaseClassName})${ruleName_LC}); |
| } |
| |
| /** |
| * This is called, for each node being visited, after <code>beginVisit</code> and |
| * (optionally) visiting the children of the node and before <code>postVisit</code>. |
| * This <code>endVisit</code> method is the specific one called for nodes |
| * of type <code>${ruleName_UC}</code> |
| * This may be overridden to provide special behavior at that point in processing. |
| * |
| * @param ${ruleName_LC} the node currently being visited |
| */ |
| public void endVisit(${ruleName_UC} ${ruleName_LC}) { |
| endVisit((${ruleBaseClassName})${ruleName_LC}); |
| } |
| ${^END} |
| |
| }</template><template id="ASTVisitorClass_acceptImpl" name="ASTVisitorClass_acceptImpl" description="acceptImpl method for the visitor framework" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaMethod" enabled="true" deleted="false" autoinsert="true"> /** |
| * This method overrides the superclass <code>acceptImpl</code> providing |
| * the same implementation. Here <code>this</code> refers to this specific node |
| * class, so the <code>beginVisit</code> and <code>endVisit</code> methods |
| * specific to this type in the visitor will be invoked. |
| */ |
| public void acceptImpl(${astVisitorClassName} visitor) { |
| boolean visitChildren = visitor.beginVisit(this); |
| if (visitChildren) visitChildren(visitor); |
| visitor.endVisit(this); |
| }</template></templates> |