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