]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/util/IsReferableQuery.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / util / IsReferableQuery.java
index 6812a59a08dabac91e1c1b2b5b8911dcb1bf8b77..d757f507f4ef2063ea41f08458bdd0a8639e3633 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2010- Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- *    VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.databoard.binding.util;\r
-\r
-import java.util.IdentityHashMap;\r
-\r
-import org.simantics.databoard.type.ArrayType;\r
-import org.simantics.databoard.type.BooleanType;\r
-import org.simantics.databoard.type.ByteType;\r
-import org.simantics.databoard.type.Component;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.databoard.type.Datatype.Visitor;\r
-import org.simantics.databoard.type.DoubleType;\r
-import org.simantics.databoard.type.FloatType;\r
-import org.simantics.databoard.type.IntegerType;\r
-import org.simantics.databoard.type.LongType;\r
-import org.simantics.databoard.type.MapType;\r
-import org.simantics.databoard.type.OptionalType;\r
-import org.simantics.databoard.type.RecordType;\r
-import org.simantics.databoard.type.StringType;\r
-import org.simantics.databoard.type.UnionType;\r
-import org.simantics.databoard.type.VariantType;\r
-\r
-public class IsReferableQuery implements Visitor<Result> {\r
-       \r
-       public static Result isReferable(Datatype type) {\r
-               IsReferableQuery query = new IsReferableQuery();\r
-               Result result = type.accept(query);\r
-               return result;\r
-       }\r
-       \r
-       IdentityHashMap<Datatype, Result> visited = new IdentityHashMap<Datatype, Result>();    \r
-       \r
-       @Override\r
-       public Result visit(ArrayType b) {\r
-               visited.put(b, Result.No);\r
-               Datatype ct = b.componentType();\r
-               Result cr = visited.get(ct);\r
-               if (cr!=null) return cr;                \r
-               cr = ct.accept(this);\r
-               if (cr!=Result.No) visited.put(b, cr);          \r
-               return cr; \r
-       }\r
-\r
-       @Override\r
-       public Result visit(BooleanType b) {\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       public Result visit(DoubleType b) {\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       public Result visit(FloatType b) {\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       public Result visit(IntegerType b) {\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       public Result visit(ByteType b) {\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       public Result visit(LongType b) {\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       public Result visit(OptionalType b) {\r
-               visited.put(b, Result.No);\r
-               Datatype ct = b.getComponentType();\r
-               Result cr = visited.get(ct);\r
-               if (cr!=null) return cr;                \r
-               cr = ct.accept(this);\r
-               if (cr!=Result.No) visited.put(b, cr);          \r
-               return cr; \r
-       }\r
-\r
-       @Override\r
-       public Result visit(RecordType b) {             \r
-               if (b.isReferable()) {\r
-                       visited.put(b, Result.Yes);\r
-                       return Result.Yes;\r
-               }\r
-                               \r
-               Result result = Result.No;\r
-               visited.put(b, result);\r
-               \r
-               for (Component c : b.getComponents()) {\r
-                       Datatype ct = c.type;\r
-                       \r
-                       Result cr = visited.get(ct);\r
-                       if (cr==null) cr = ct.accept(this);\r
-                       if (cr!=null) {\r
-                               if (cr == Result.Yes) {\r
-                                       result = cr;\r
-                                       break;\r
-                               }\r
-                               if (cr == Result.Possible) {\r
-                                       result = cr;                                    \r
-                               }\r
-                       }                       \r
-               }\r
-               \r
-               if (result!=Result.No) visited.put(b, result);          \r
-               return result;\r
-       }\r
-\r
-       @Override\r
-       public Result visit(StringType b) {\r
-               return Result.No;\r
-       }\r
-\r
-       @Override\r
-       public Result visit(UnionType b) {\r
-               Result result = Result.No;\r
-               visited.put(b, result);\r
-               \r
-               for (Component c : b.getComponents()) {\r
-                       Datatype ct = c.type;\r
-                       \r
-                       Result cr = visited.get(ct);\r
-                       if (cr==null) cr = ct.accept(this);\r
-                       if (cr!=null) {\r
-                               if (cr == Result.Yes) {\r
-                                       result = cr;\r
-                                       break;\r
-                               }\r
-                               if (cr == Result.Possible) {\r
-                                       result = cr;                                    \r
-                               }\r
-                       }                       \r
-               }\r
-               \r
-               if (result!=Result.No) visited.put(b, result);          \r
-               return result;\r
-       }\r
-\r
-       @Override\r
-       public Result visit(VariantType b) {\r
-               return Result.Possible;\r
-       }\r
-\r
-       @Override\r
-       public Result visit(MapType b) {\r
-               visited.put(b, Result.No);\r
-               Datatype kt = b.keyType;\r
-               Result kr = visited.get(kt);\r
-               if (kr == null) kr = kt.accept(this);\r
-               \r
-               Datatype vt = b.valueType;\r
-               Result vr = visited.get(vt);\r
-               if (vr == null) vr = vt.accept(this);\r
-               \r
-               Result result = Result.No;\r
-               if (kr==Result.Yes || vr==Result.Yes) result = Result.Yes;\r
-               else if (kr==Result.Possible || vr==Result.Possible) result = Result.Possible;\r
-\r
-               if (result!=Result.No) \r
-                       visited.put(b, Result.No);\r
-               \r
-               return result; \r
-       }\r
-       \r
-}\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2010- Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *    VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.databoard.binding.util;
+
+import java.util.IdentityHashMap;
+
+import org.simantics.databoard.type.ArrayType;
+import org.simantics.databoard.type.BooleanType;
+import org.simantics.databoard.type.ByteType;
+import org.simantics.databoard.type.Component;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.databoard.type.Datatype.Visitor;
+import org.simantics.databoard.type.DoubleType;
+import org.simantics.databoard.type.FloatType;
+import org.simantics.databoard.type.IntegerType;
+import org.simantics.databoard.type.LongType;
+import org.simantics.databoard.type.MapType;
+import org.simantics.databoard.type.OptionalType;
+import org.simantics.databoard.type.RecordType;
+import org.simantics.databoard.type.StringType;
+import org.simantics.databoard.type.UnionType;
+import org.simantics.databoard.type.VariantType;
+
+public class IsReferableQuery implements Visitor<Result> {
+       
+       public static Result isReferable(Datatype type) {
+               IsReferableQuery query = new IsReferableQuery();
+               Result result = type.accept(query);
+               return result;
+       }
+       
+       IdentityHashMap<Datatype, Result> visited = new IdentityHashMap<Datatype, Result>();    
+       
+       @Override
+       public Result visit(ArrayType b) {
+               visited.put(b, Result.No);
+               Datatype ct = b.componentType();
+               Result cr = visited.get(ct);
+               if (cr!=null) return cr;                
+               cr = ct.accept(this);
+               if (cr!=Result.No) visited.put(b, cr);          
+               return cr; 
+       }
+
+       @Override
+       public Result visit(BooleanType b) {
+               return null;
+       }
+
+       @Override
+       public Result visit(DoubleType b) {
+               return null;
+       }
+
+       @Override
+       public Result visit(FloatType b) {
+               return null;
+       }
+
+       @Override
+       public Result visit(IntegerType b) {
+               return null;
+       }
+
+       @Override
+       public Result visit(ByteType b) {
+               return null;
+       }
+
+       @Override
+       public Result visit(LongType b) {
+               return null;
+       }
+
+       @Override
+       public Result visit(OptionalType b) {
+               visited.put(b, Result.No);
+               Datatype ct = b.getComponentType();
+               Result cr = visited.get(ct);
+               if (cr!=null) return cr;                
+               cr = ct.accept(this);
+               if (cr!=Result.No) visited.put(b, cr);          
+               return cr; 
+       }
+
+       @Override
+       public Result visit(RecordType b) {             
+               if (b.isReferable()) {
+                       visited.put(b, Result.Yes);
+                       return Result.Yes;
+               }
+                               
+               Result result = Result.No;
+               visited.put(b, result);
+               
+               for (Component c : b.getComponents()) {
+                       Datatype ct = c.type;
+                       
+                       Result cr = visited.get(ct);
+                       if (cr==null) cr = ct.accept(this);
+                       if (cr!=null) {
+                               if (cr == Result.Yes) {
+                                       result = cr;
+                                       break;
+                               }
+                               if (cr == Result.Possible) {
+                                       result = cr;                                    
+                               }
+                       }                       
+               }
+               
+               if (result!=Result.No) visited.put(b, result);          
+               return result;
+       }
+
+       @Override
+       public Result visit(StringType b) {
+               return Result.No;
+       }
+
+       @Override
+       public Result visit(UnionType b) {
+               Result result = Result.No;
+               visited.put(b, result);
+               
+               for (Component c : b.getComponents()) {
+                       Datatype ct = c.type;
+                       
+                       Result cr = visited.get(ct);
+                       if (cr==null) cr = ct.accept(this);
+                       if (cr!=null) {
+                               if (cr == Result.Yes) {
+                                       result = cr;
+                                       break;
+                               }
+                               if (cr == Result.Possible) {
+                                       result = cr;                                    
+                               }
+                       }                       
+               }
+               
+               if (result!=Result.No) visited.put(b, result);          
+               return result;
+       }
+
+       @Override
+       public Result visit(VariantType b) {
+               return Result.Possible;
+       }
+
+       @Override
+       public Result visit(MapType b) {
+               visited.put(b, Result.No);
+               Datatype kt = b.keyType;
+               Result kr = visited.get(kt);
+               if (kr == null) kr = kt.accept(this);
+               
+               Datatype vt = b.valueType;
+               Result vr = visited.get(vt);
+               if (vr == null) vr = vt.accept(this);
+               
+               Result result = Result.No;
+               if (kr==Result.Yes || vr==Result.Yes) result = Result.Yes;
+               else if (kr==Result.Possible || vr==Result.Possible) result = Result.Possible;
+
+               if (result!=Result.No) 
+                       visited.put(b, Result.No);
+               
+               return result; 
+       }
+       
+}
+