Skip to content
Snippets Groups Projects
Commit c06b09a0 authored by dgelessus's avatar dgelessus
Browse files

Improve a few minor things in Node and Token templates

parent 78de827b
No related branches found
No related tags found
No related merge requests found
...@@ -2,17 +2,19 @@ ...@@ -2,17 +2,19 @@
package org.sablecc.sablecc.node; package org.sablecc.sablecc.node;
import java.util.*; import java.util.LinkedList;
import java.util.List;
import de.hhu.stups.sablecc.patch.PositionedNode; import de.hhu.stups.sablecc.patch.PositionedNode;
public abstract class Node extends PositionedNode implements Switchable, Cloneable public abstract class Node extends PositionedNode implements Switchable, Cloneable
{ {
private Node parent; private Node parent;
public Node() protected Node()
{} {}
public Node(Node node) protected Node(Node node)
{ {
super(node); super(node);
// Copy constructor intentionally does not keep parent! // Copy constructor intentionally does not keep parent!
...@@ -41,7 +43,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab ...@@ -41,7 +43,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab
this.parent.replaceChild(this, node); this.parent.replaceChild(this, node);
} }
protected String toString(Node node) protected static String toString(Node node)
{ {
if(node != null) if(node != null)
{ {
...@@ -51,9 +53,9 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab ...@@ -51,9 +53,9 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab
return ""; return "";
} }
protected String toString(List<?> list) protected static String toString(List<?> list)
{ {
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
for(Object o : list) for(Object o : list)
{ {
...@@ -64,7 +66,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab ...@@ -64,7 +66,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <T extends Node> T cloneNode(T node) protected static <T extends Node> T cloneNode(T node)
{ {
if(node != null) if(node != null)
{ {
...@@ -75,7 +77,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab ...@@ -75,7 +77,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <T extends Node> List<T> cloneList(List<T> list) protected static <T extends Node> List<T> cloneList(List<T> list)
{ {
List<T> clone = new LinkedList<T>(); List<T> clone = new LinkedList<T>();
......
...@@ -12,24 +12,24 @@ public abstract class Token extends Node implements IToken ...@@ -12,24 +12,24 @@ public abstract class Token extends Node implements IToken
private int line; private int line;
private int pos; private int pos;
public Token(String text, int line, int pos) protected Token(String text, int line, int pos)
{ {
this.text = text; this.text = text;
this.line = line; this.line = line;
this.pos = pos; this.pos = pos;
} }
public Token(String text) protected Token(String text)
{ {
this(text, 0, 0); this(text, 0, 0);
} }
public Token() protected Token()
{ {
this((String)null); this((String)null);
} }
public Token(Token token) protected Token(Token token)
{ {
super(token); super(token);
this.text = token.text; this.text = token.text;
...@@ -37,6 +37,9 @@ public abstract class Token extends Node implements IToken ...@@ -37,6 +37,9 @@ public abstract class Token extends Node implements IToken
this.pos = token.pos; this.pos = token.pos;
} }
@Override
public abstract Token clone();
@Override @Override
public String getText() public String getText()
{ {
......
...@@ -201,24 +201,24 @@ public abstract class Token extends Node implements IToken ...@@ -201,24 +201,24 @@ public abstract class Token extends Node implements IToken
private int line; private int line;
private int pos; private int pos;
public Token(String text, int line, int pos) protected Token(String text, int line, int pos)
{ {
this.text = text; this.text = text;
this.line = line; this.line = line;
this.pos = pos; this.pos = pos;
} }
public Token(String text) protected Token(String text)
{ {
this(text, 0, 0); this(text, 0, 0);
} }
public Token() protected Token()
{ {
this((String)null); this((String)null);
} }
public Token(Token token) protected Token(Token token)
{ {
super(token); super(token);
this.text = token.text; this.text = token.text;
...@@ -226,6 +226,9 @@ public abstract class Token extends Node implements IToken ...@@ -226,6 +226,9 @@ public abstract class Token extends Node implements IToken
this.pos = token.pos; this.pos = token.pos;
} }
@Override
public abstract Token clone();
@Override @Override
public String getText() public String getText()
{ {
...@@ -323,17 +326,19 @@ Macro:Node ...@@ -323,17 +326,19 @@ Macro:Node
package $0$; package $0$;
import java.util.*; import java.util.LinkedList;
import java.util.List;
import de.hhu.stups.sablecc.patch.PositionedNode; import de.hhu.stups.sablecc.patch.PositionedNode;
public abstract class Node extends PositionedNode implements Switchable, Cloneable public abstract class Node extends PositionedNode implements Switchable, Cloneable
{ {
private Node parent; private Node parent;
public Node() protected Node()
{} {}
public Node(Node node) protected Node(Node node)
{ {
super(node); super(node);
// Copy constructor intentionally does not keep parent! // Copy constructor intentionally does not keep parent!
...@@ -362,7 +367,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab ...@@ -362,7 +367,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab
this.parent.replaceChild(this, node); this.parent.replaceChild(this, node);
} }
protected String toString(Node node) protected static String toString(Node node)
{ {
if(node != null) if(node != null)
{ {
...@@ -372,9 +377,9 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab ...@@ -372,9 +377,9 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab
return ""; return "";
} }
protected String toString(List<?> list) protected static String toString(List<?> list)
{ {
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
for(Object o : list) for(Object o : list)
{ {
...@@ -385,7 +390,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab ...@@ -385,7 +390,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <T extends Node> T cloneNode(T node) protected static <T extends Node> T cloneNode(T node)
{ {
if(node != null) if(node != null)
{ {
...@@ -396,7 +401,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab ...@@ -396,7 +401,7 @@ public abstract class Node extends PositionedNode implements Switchable, Cloneab
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <T extends Node> List<T> cloneList(List<T> list) protected static <T extends Node> List<T> cloneList(List<T> list)
{ {
List<T> clone = new LinkedList<T>(); List<T> clone = new LinkedList<T>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment