]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/parser/ast/type/visitor/AstTypePrinter.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / parser / ast / type / visitor / AstTypePrinter.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  Industry THTH ry.
4  *  All rights reserved. This program and the accompanying materials
5  *  are made available under the terms of the Eclipse Public License v1.0
6  *  which accompanies this distribution, and is available at
7  *  http://www.eclipse.org/legal/epl-v10.html
8  *
9  *  Contributors:
10  *      VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.databoard.parser.ast.type.visitor;
13
14 import org.simantics.databoard.parser.ast.type.AstArrayType;
15 import org.simantics.databoard.parser.ast.type.AstComponent;
16 import org.simantics.databoard.parser.ast.type.AstRecordType;
17 import org.simantics.databoard.parser.ast.type.AstTupleType;
18 import org.simantics.databoard.parser.ast.type.AstType;
19 import org.simantics.databoard.parser.ast.type.AstTypeReference;
20 import org.simantics.databoard.parser.ast.type.AstUnionType;
21
22 public class AstTypePrinter implements AstTypeVisitorVoid {
23         StringBuilder b = new StringBuilder();  
24
25         @Override
26         public void visit(AstArrayType arrayType) {
27                 arrayType.componentType.accept(this);
28                 b.append("[]");
29         }
30
31         @Override
32         public void visit(AstRecordType recordType) {
33                 b.append("{");
34                 boolean first = true;
35                 for(AstComponent component : recordType.components) {
36                         if(first)
37                                 first = false;
38                         else
39                                 b.append(", ");
40                         b.append(component.name);
41                         b.append(" : ");
42                         component.type.accept(this);
43                 }
44                 b.append("}");          
45         }
46
47         @Override
48         public void visit(AstTupleType tupleType) {
49                 b.append("(");
50                 boolean first = true;
51                 for(AstType component : tupleType.components) {
52                         if(first)
53                                 first = false;
54                         else
55                                 b.append(", ");                 
56                         component.accept(this);
57                 }
58                 b.append(")");                  
59         }
60
61         @Override
62         public void visit(AstTypeReference typeReference) {
63                 b.append(typeReference.name);
64                 if(!typeReference.parameters.isEmpty()) {
65                         b.append("(");
66                         boolean first = true;
67                         for(AstType component : typeReference.parameters) {
68                                 if(first)
69                                         first = false;
70                                 else
71                                         b.append(", ");                 
72                                 component.accept(this);
73                         }
74                         b.append(")");  
75                 }
76         }
77
78         @Override
79         public void visit(AstUnionType unionType) {
80                 boolean first = true;
81                 for(AstComponent component : unionType.components) {
82                         if(first)
83                                 first = false;
84                         else
85                                 b.append(" | ");
86                         b.append(component.name);
87                         b.append(' ');
88                         component.type.accept(this);
89                 }
90         }
91         
92         @Override
93         public String toString() {
94                 return b.toString();
95         }
96 }