ca.ubc.cs.elide.nodes
Class NodeFactory

java.lang.Object
  |
  +--ca.ubc.cs.elide.nodes.NodeFactory

public class NodeFactory
extends java.lang.Object

Use NodeFactory to easily create instances of ClassNode, FieldNode, MethodNode, and TextNode.

For each of these classes, NodeFactory takes a string with source code describing the object, and returns the parsed representation. Often, it will be easiest to use ELIDE's extended %{}% string literal syntax with these methods.


Constructor Summary
NodeFactory()
           
 
Method Summary
static ClassNode createClass(java.lang.String text)
          Creates a ClassNode from a String of Java source code defining the class.
static FieldNode createField(java.lang.String text)
          Creates a FieldNode from a String of Java source code defining the field.
static MethodNode createMethod(java.lang.String text)
          Creates a MethodNode from a String of Java source code defining the class.
static TextNode createText(java.lang.String text)
          Creates a TextNode from a String of Java source code.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeFactory

public NodeFactory()
Method Detail

createClass

public static ClassNode createClass(java.lang.String text)
Creates a ClassNode from a String of Java source code defining the class.

For example:

 ClassNode newClass = NodeFactory.createClass(%{
 	public class Foo {
		...
	}
   }%);
 

createField

public static FieldNode createField(java.lang.String text)
Creates a FieldNode from a String of Java source code defining the field.

For example:

 FieldNode newField = NodeFactory.createField(%{ public int x = 3 }%);
 

In most cases, ClassNode.extend(java.lang.String) can be used instead.


createMethod

public static MethodNode createMethod(java.lang.String text)
Creates a MethodNode from a String of Java source code defining the class.

For example:

 MethodNode newMethod = NodeFactory.createMethod(%{
 	public void foo() {
		...
	}
   }%);
 
In most cases, ClassNode.extend(java.lang.String) can be used instead.

createText

public static TextNode createText(java.lang.String text)
Creates a TextNode from a String of Java source code.

For example:

 TextNode snippet = NodeFactory.createText(%{
 	if(x > 0) { doSomething(); }
   }%);