-package org.simantics.graph.compiler.internal.values;\r
-\r
-import java.util.Collection;\r
-\r
-import org.antlr.runtime.tree.Tree;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.graph.compiler.internal.parsing.GraphParser;\r
-import org.simantics.graph.compiler.internal.store.IPreValue;\r
-import org.simantics.graph.compiler.internal.translation.DataValueTranslator;\r
-import org.simantics.graph.query.Path;\r
-import org.simantics.graph.query.Paths;\r
-import org.simantics.ltk.ISource;\r
-import org.simantics.ltk.Location;\r
-import org.simantics.ltk.Problem;\r
-import org.simantics.ltk.antlr.ANTLRUtils;\r
-\r
-public class TreeValue implements IPreValue {\r
-\r
- ISource source;\r
- Tree tree;\r
- \r
- public TreeValue(ISource source, Tree tree) {\r
- this.source = source;\r
- this.tree = tree;\r
- }\r
-\r
- @Override\r
- public Object toValue(Binding binding, Collection<Problem> problems) {\r
- return new DataValueTranslator(source, problems).translate(tree, binding);\r
- }\r
-\r
- public Tree getTree() {\r
- return tree;\r
- }\r
-\r
- @Override\r
- public Path getDefaultType(Paths paths) {\r
- Tree b = this.tree;\r
- while(b.getType() == GraphParser.TUPLE && b.getChildCount() == 1)\r
- b = b.getChild(0);\r
- \r
- switch(b.getType()) {\r
- case GraphParser.INT: return paths.Integer;\r
- case GraphParser.FLOAT: return paths.Double;\r
- case GraphParser.STRING: return paths.String;\r
- case GraphParser.TRUE:\r
- case GraphParser.FALSE: return paths.Boolean;\r
- case GraphParser.VARIANT: return paths.Variant;\r
- case GraphParser.ARRAY:\r
- if(b.getChildCount() > 0) {\r
- switch(b.getChild(0).getType()) {\r
- case GraphParser.INT:\r
- case GraphParser.FLOAT:\r
- for(int i=0;i<b.getChildCount();++i)\r
- if(b.getChild(i).getType() == GraphParser.FLOAT)\r
- return paths.DoubleArray;\r
- return paths.IntegerArray;\r
- case GraphParser.STRING:\r
- return paths.StringArray;\r
- case GraphParser.TRUE:\r
- case GraphParser.FALSE:\r
- return paths.BooleanArray;\r
- }\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- @Override\r
- public Location getLocation() {\r
- return ANTLRUtils.location(source, tree);\r
- }\r
- \r
- @Override\r
- public String toString() {\r
- return tree.getText();\r
- }\r
-}\r
+package org.simantics.graph.compiler.internal.values;
+
+import java.util.Collection;
+
+import org.antlr.runtime.tree.Tree;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.graph.compiler.internal.parsing.GraphParser;
+import org.simantics.graph.compiler.internal.store.IPreValue;
+import org.simantics.graph.compiler.internal.translation.DataValueTranslator;
+import org.simantics.graph.query.Path;
+import org.simantics.graph.query.Paths;
+import org.simantics.ltk.ISource;
+import org.simantics.ltk.Location;
+import org.simantics.ltk.Problem;
+import org.simantics.ltk.antlr.ANTLRUtils;
+
+public class TreeValue implements IPreValue {
+
+ ISource source;
+ Tree tree;
+
+ public TreeValue(ISource source, Tree tree) {
+ this.source = source;
+ this.tree = tree;
+ }
+
+ @Override
+ public Object toValue(Binding binding, Collection<Problem> problems) {
+ return new DataValueTranslator(source, problems).translate(tree, binding);
+ }
+
+ public Tree getTree() {
+ return tree;
+ }
+
+ @Override
+ public Path getDefaultType(Paths paths) {
+ Tree b = this.tree;
+ while(b.getType() == GraphParser.TUPLE && b.getChildCount() == 1)
+ b = b.getChild(0);
+
+ switch(b.getType()) {
+ case GraphParser.INT: return paths.Integer;
+ case GraphParser.FLOAT: return paths.Double;
+ case GraphParser.STRING: return paths.String;
+ case GraphParser.TRUE:
+ case GraphParser.FALSE: return paths.Boolean;
+ case GraphParser.VARIANT: return paths.Variant;
+ case GraphParser.ARRAY:
+ if(b.getChildCount() > 0) {
+ switch(b.getChild(0).getType()) {
+ case GraphParser.INT:
+ case GraphParser.FLOAT:
+ for(int i=0;i<b.getChildCount();++i)
+ if(b.getChild(i).getType() == GraphParser.FLOAT)
+ return paths.DoubleArray;
+ return paths.IntegerArray;
+ case GraphParser.STRING:
+ return paths.StringArray;
+ case GraphParser.TRUE:
+ case GraphParser.FALSE:
+ return paths.BooleanArray;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Location getLocation() {
+ return ANTLRUtils.location(source, tree);
+ }
+
+ @Override
+ public String toString() {
+ return tree.getText();
+ }
+}