]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/expression/node/Node.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.spreadsheet.common / src / org / simantics / spreadsheet / common / expression / node / Node.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 /* This file was generated by SableCC (http://www.sablecc.org/). */\r
13 \r
14 package org.simantics.spreadsheet.common.expression.node;\r
15 \r
16 import java.util.*;\r
17 \r
18 @SuppressWarnings("nls")\r
19 public abstract class Node implements Switchable, Cloneable\r
20 {\r
21     private Node parent;\r
22 \r
23     @Override\r
24     public abstract Object clone();\r
25 \r
26     public Node parent()\r
27     {\r
28         return this.parent;\r
29     }\r
30 \r
31     void parent(@SuppressWarnings("hiding") Node parent)\r
32     {\r
33         this.parent = parent;\r
34     }\r
35 \r
36     abstract void removeChild(Node child);\r
37     abstract void replaceChild(Node oldChild, Node newChild);\r
38 \r
39     public void replaceBy(Node node)\r
40     {\r
41         this.parent.replaceChild(this, node);\r
42     }\r
43 \r
44     protected String toString(Node node)\r
45     {\r
46         if(node != null)\r
47         {\r
48             return node.toString();\r
49         }\r
50 \r
51         return "";\r
52     }\r
53 \r
54     protected String toString(List list)\r
55     {\r
56         StringBuffer s = new StringBuffer();\r
57 \r
58         for(Iterator i = list.iterator(); i.hasNext();)\r
59         {\r
60             s.append(i.next());\r
61         }\r
62 \r
63         return s.toString();\r
64     }\r
65 \r
66     @SuppressWarnings("unchecked")\r
67     protected <T extends Node> T cloneNode(T node)\r
68     {\r
69         if(node != null)\r
70         {\r
71             return (T) node.clone();\r
72         }\r
73 \r
74         return null;\r
75     }\r
76 \r
77     protected <T> List<T> cloneList(List<T> list)\r
78     {\r
79         List<T> clone = new LinkedList<T>();\r
80 \r
81         for(T n : list)\r
82         {\r
83             clone.add(n);\r
84         }\r
85 \r
86         return clone;\r
87     }\r
88 }\r