]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Sync git svn branch with SVN repository r33303.
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 4 Oct 2016 20:07:47 +0000 (23:07 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 4 Oct 2016 20:07:47 +0000 (23:07 +0300)
refs #6740
refs #6726
refs #6739
refs #6735
refs #6731
refs #6730
refs #6729
refs #6728
refs #6724
refs #6701
refs #6669

19 files changed:
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/EntityInstances.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/OntologiesFromLibrary.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/Configuration.java
bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/Content.java [new file with mode: 0644]
bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/IAbstractRequestInterface.java
bundles/org.simantics.document.ui/src/org/simantics/document/ui/actions/NewDocumentFolder.java [new file with mode: 0644]
bundles/org.simantics.fileimport/src/org/simantics/fileimport/SimanticsResourceFileImport.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DiagramViewerSelectionProvider.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SingleElementNode.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintEnvironment.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSolver.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ReduceSerializable.java [new file with mode: 0644]
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/CellValueVisitor.java
bundles/org.simantics.tests.modelled.ontology/graph.tg
bundles/org.simantics.tests.modelled.ui.ontology/graph.tg
bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph
bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java
bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtil.java

index b0d71503b192f1e7249717c43791864afeb271f6..428b96a5db558a8faa9a28b29b867c60d84e93f2 100644 (file)
@@ -11,8 +11,6 @@
  *******************************************************************************/\r
 package org.simantics.db.layer0.adapter.impl;\r
 \r
-import gnu.trove.set.hash.THashSet;\r
-\r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
 import java.util.Collections;\r
@@ -30,11 +28,15 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.Instances;\r
 import org.simantics.db.layer0.genericrelation.IndexQueries;\r
 import org.simantics.db.layer0.util.Layer0Utils;\r
+import org.simantics.db.request.ReadExt;\r
+import org.simantics.db.request.RequestFlags;\r
 import org.simantics.db.service.CollectionSupport;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.operation.Layer0X;\r
 import org.simantics.scl.runtime.function.Function;\r
 \r
+import gnu.trove.set.hash.THashSet;\r
+\r
 /**\r
  * @author Antti Villberg\r
  * @author Tuukka Lehtonen\r
@@ -58,7 +60,7 @@ public class EntityInstances implements Instances {
      * A (cacheable) query to optimize single index queries for immutable\r
      * indexes such as ontologies.\r
      */\r
-    public static class QueryIndex extends TernaryRead<Resource, Resource, String, List<Resource>> {\r
+    public static class QueryIndex extends TernaryRead<Resource, Resource, String, List<Resource>> implements ReadExt {\r
 \r
         public QueryIndex(Resource index, Resource type, String filter) {\r
             super(index, type, filter);\r
@@ -125,6 +127,17 @@ public class EntityInstances implements Instances {
                return "QueryIndex " + parameter + " " + parameter2 + " " + parameter3;\r
         }\r
 \r
+               @Override\r
+               public boolean isImmutable(ReadGraph graph) throws DatabaseException {\r
+                       // TODO Auto-generated method stub\r
+                       return false;\r
+               }\r
+\r
+               @Override\r
+               public int getType() {\r
+                       return RequestFlags.IMMEDIATE_UPDATE;\r
+               }\r
+\r
     }\r
 \r
     private List<Resource> findRec(ReadGraph graph, Resource index, String filter, Set<Resource> visited) throws DatabaseException {\r
index a742b1e48639d4ad8b6cf90dfd3ac351b2e60fa8..1b88cbb656f09a48278fce200a30deed750ffd55 100644 (file)
@@ -17,23 +17,21 @@ import java.util.List;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.ResourceRead;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.request.Read;\r
 import org.simantics.layer0.Layer0;\r
 \r
-public class OntologiesFromLibrary implements Read<List<Resource>> {\r
-    \r
-    Resource library;\r
+public class OntologiesFromLibrary extends ResourceRead<List<Resource>> {\r
     \r
     public OntologiesFromLibrary(Resource library) {\r
-        this.library = library;\r
+       super(library);\r
     }\r
 \r
     @Override\r
     public List<Resource> perform(ReadGraph graph) throws DatabaseException {\r
         Layer0 L0 = Layer0.getInstance(graph);\r
         ArrayList<Resource> result = new ArrayList<Resource>();\r
-        for(Resource r : graph.syncRequest(new ObjectsWithType(library, L0.ConsistsOf, L0.Library))) {\r
+        for(Resource r : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, L0.Library))) {\r
             if(graph.isInstanceOf(r, L0.Ontology))\r
                 result.add(r);\r
             else\r
index 1ec3e51507788783ed94cdf524e2e24942886310..5849163661215fdf1df54944fba0d5297c4b8fb7 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.db.layer0.request;
 \r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.IndexRoot;\r
 import org.simantics.db.common.request.ResourceRead;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
@@ -26,7 +27,7 @@ public class Configuration extends ResourceRead<Resource> {
     @Override\r
     public Resource perform(ReadGraph graph) throws DatabaseException {\r
 \r
-       Resource model = graph.syncRequest(new Model(resource));\r
+       Resource model = graph.syncRequest(new IndexRoot(resource));\r
        return graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
 \r
     }\r
diff --git a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/Content.java b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/Content.java
new file mode 100644 (file)
index 0000000..ba933d7
--- /dev/null
@@ -0,0 +1,49 @@
+/*******************************************************************************\r
+ * Copyright (c) 2014, 2016 Association for Decentralized \r
+ * Information Management in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the THTH Simantics \r
+ * Division Member Component License which accompanies this \r
+ * distribution, and is available at\r
+ * http://www.simantics.org/legal/sdmcl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.document.server.io;\r
+\r
+public class Content {\r
+       private byte[] data;\r
+       private String mimeType;\r
+       private long lastModified;\r
+       \r
+       public Content(byte[] data, String mimeType, long lastModified) {\r
+               this.data = data;\r
+               this.mimeType = mimeType;\r
+               this.lastModified = lastModified;\r
+       }\r
+\r
+       public byte[] getData() {\r
+               return data;\r
+       }\r
+\r
+       public void setData(byte[] data) {\r
+               this.data = data;\r
+       }\r
+\r
+       public String getMimeType() {\r
+               return mimeType;\r
+       }\r
+\r
+       public void setMimeType(String mimeType) {\r
+               this.mimeType = mimeType;\r
+       }\r
+\r
+       public long getLastModified() {\r
+               return lastModified;\r
+       }\r
+\r
+       public void setLastModified(long lastModified) {\r
+               this.lastModified = lastModified;\r
+       }\r
+}\r
index c7bd2939271d5c48f6f69da87238e0120976bc9d..dce45ac05e2a7d081ff50ef01e04563e32d3a042 100644 (file)
@@ -12,6 +12,7 @@ public interface IAbstractRequestInterface {
        String requestCSS(String documentURI);\r
        int[] requestLoadingIndicatorDelay(String documentURI);\r
        Double requestPollingInterval(String documentURI);\r
+       Content requestContent(String resourceURI);\r
        public CommandResult execute(String id, CommandContext context);\r
        public void subscribeDocument(String document, String sessionGUID, IDocumentListener documentListener);\r
        public IJSONResult readChanges(String uri, String sessionGUID, int sequenceNumber);\r
diff --git a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/actions/NewDocumentFolder.java b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/actions/NewDocumentFolder.java
new file mode 100644 (file)
index 0000000..5a99604
--- /dev/null
@@ -0,0 +1,52 @@
+package org.simantics.document.ui.actions;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.ActionFactory;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class NewDocumentFolder implements ActionFactory {\r
+       Resource folderType;\r
+       Resource relation;\r
+       \r
+       public NewDocumentFolder(ReadGraph graph, String folderTypeUri, String relationUri) throws DatabaseException {\r
+               folderType = graph.getResource(folderTypeUri);\r
+               relation = graph.getResource(relationUri);\r
+       }\r
+       \r
+       @Override\r
+       public Runnable create(Object target) {\r
+\r
+               if(!(target instanceof Resource))\r
+                       return null;\r
+\r
+               final Resource resource = (Resource)target;\r
+\r
+               return new Runnable() {\r
+                       @Override\r
+                       public void run() {\r
+                               SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+                                       \r
+                                       @Override\r
+                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                           graph.markUndoPoint();\r
+                                           \r
+                                               Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+                           String name = NameUtils.findFreshName(graph, "Folder", resource, relation);\r
+                           Resource folder = graph.newResource();\r
+                           graph.claim(folder, l0.InstanceOf, folderType);\r
+                           graph.claimLiteral(folder, l0.HasName, name);\r
+                           graph.claim(resource, relation, folder);\r
+                                       }\r
+                                       \r
+                               });\r
+                       }\r
+               };\r
+       }\r
+}\r
index 70439ef1db950a3861a2c7452a26d42f936882b5..eea85d47d9f559e9306193b5bbdc328559ac99eb 100644 (file)
@@ -32,7 +32,14 @@ public abstract class SimanticsResourceFileImport implements IGenericFileImport
     final public Optional<String> perform(Path file) throws Exception {\r
         \r
         Path dropins = Activator.getDropinsFolder();\r
-        Path parts = dropins.relativize(file);\r
+        \r
+        Path parts;\r
+        if (file.toAbsolutePath().toString().startsWith(dropins.toAbsolutePath().toString())) {\r
+               parts = dropins.relativize(file);\r
+        } else {\r
+               parts = file.getFileName();\r
+        }\r
+        \r
         Resource parent = resolveParent(null, parts);\r
         if (parent == null)\r
             return Optional.empty();\r
index 4317f59799f9c8819bb1459fe76d3997ac56dc90..42c489e24d4b866d310507cf7d1d00d4cc1508cf 100644 (file)
@@ -18,6 +18,7 @@ import org.simantics.db.layer0.request.PossibleModel;
 import org.simantics.db.layer0.variable.Variable;\r
 import org.simantics.db.layer0.variable.Variables;\r
 import org.simantics.diagram.Logger;\r
+import org.simantics.diagram.flag.FlagUtil;\r
 import org.simantics.diagram.stubs.DiagramResource;\r
 import org.simantics.diagram.ui.DiagramModelHints;\r
 import org.simantics.diagram.ui.WorkbenchSelectionProvider;\r
@@ -25,6 +26,7 @@ import org.simantics.g2d.diagram.IDiagram;
 import org.simantics.g2d.element.ElementHints;\r
 import org.simantics.g2d.element.ElementUtils;\r
 import org.simantics.g2d.element.IElement;\r
+import org.simantics.layer0.Layer0;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.selection.AnyResource;\r
@@ -83,8 +85,16 @@ public class DiagramViewerSelectionProvider extends WorkbenchSelectionProvider {
                                     //return Variables.getPossibleVariable(graph, resource2);\r
                                     return var;\r
                                 }\r
+                                \r
+                                if(graph.isInstanceOf(resource2, DIA.Flag)) {\r
+                                       Layer0 L0 = Layer0.getInstance(graph);\r
+                                       Variable signal = FlagUtil.getPossibleFlagSignal(graph, var, resource2, L0.Entity);\r
+                                       if(signal != null)\r
+                                               return signal;\r
+                                }\r
 \r
                                 return null;\r
+                                \r
                             }\r
 \r
                             return var.browsePossible(graph, config);\r
index c6a8b950e0e8a6f22218bb70d0637fc2c45360cd..9220e18fd35a429f8e5d6bde95befc4c7d33da5a 100644 (file)
@@ -144,7 +144,7 @@ public class SingleElementNode extends TransformNode implements InitValueSupport
     }\r
 \r
     protected boolean hitTest(MouseEvent event) {\r
-        Rectangle2D bounds = super.getBoundsInLocal(false);\r
+        Rectangle2D bounds = super.getBoundsInLocal(true);\r
         if (bounds == null)\r
             return false;\r
         Point2D localPos = NodeUtil.worldToLocal(this, event.controlPosition, new Point2D.Double());\r
index 82df9000799336691ccd77ad4287c8384cc64959..ba982b1c6ab14c8fe886e318e471e42d4af54594 100644 (file)
@@ -1,11 +1,7 @@
 package org.simantics.scl.compiler.internal.elaboration.constraints;
 
-import org.cojen.classfile.TypeDesc;
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.constants.ClassConstant;
-import org.simantics.scl.compiler.constants.JavaConstructor;
-import org.simantics.scl.compiler.constants.JavaStaticField;
-import org.simantics.scl.compiler.constants.JavaStaticMethod;
 import org.simantics.scl.compiler.constants.StringConstant;
 import org.simantics.scl.compiler.elaboration.expressions.EApply;
 import org.simantics.scl.compiler.elaboration.expressions.EConstant;
@@ -49,35 +45,7 @@ public class ConstraintEnvironment {
         }
         return result;
     }
-    
-    private static final Type SERIALIZABLE_BOOLEAN = Types.pred(Types.SERIALIZABLE, Types.BOOLEAN);
-    private static final Type SERIALIZABLE_BYTE = Types.pred(Types.SERIALIZABLE, Types.BYTE);
-    private static final Type SERIALIZABLE_SHORT = Types.pred(Types.SERIALIZABLE, Types.SHORT);
-    private static final Type SERIALIZABLE_INTEGER = Types.pred(Types.SERIALIZABLE, Types.INTEGER);
-    private static final Type SERIALIZABLE_LONG = Types.pred(Types.SERIALIZABLE, Types.LONG);
-    private static final Type SERIALIZABLE_FLOAT = Types.pred(Types.SERIALIZABLE, Types.FLOAT);
-    private static final Type SERIALIZABLE_DOUBLE = Types.pred(Types.SERIALIZABLE, Types.DOUBLE);
-    private static final Type SERIALIZABLE_STRING = Types.pred(Types.SERIALIZABLE, Types.STRING);
-    
-    private static final Type SERIALIZABLE_BOOLEAN_ARRAY = Types.pred(Types.SERIALIZABLE, Types.BOOLEAN_ARRAY);
-    private static final Type SERIALIZABLE_BYTE_ARRAY = Types.pred(Types.SERIALIZABLE, Types.BYTE_ARRAY);
-    private static final Type SERIALIZABLE_SHORT_ARRAY = Types.pred(Types.SERIALIZABLE, Types.SHORT_ARRAY);
-    private static final Type SERIALIZABLE_INTEGER_ARRAY = Types.pred(Types.SERIALIZABLE, Types.INTEGER_ARRAY);
-    private static final Type SERIALIZABLE_LONG_ARRAY = Types.pred(Types.SERIALIZABLE, Types.LONG_ARRAY);
-    private static final Type SERIALIZABLE_FLOAT_ARRAY = Types.pred(Types.SERIALIZABLE, Types.FLOAT_ARRAY);
-    private static final Type SERIALIZABLE_DOUBLE_ARRAY = Types.pred(Types.SERIALIZABLE, Types.DOUBLE_ARRAY);
-    
-    private static final Type SERIALIZABLE_BOOLEAN_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.BOOLEAN));
-    private static final Type SERIALIZABLE_BYTE_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.BYTE));
-    private static final Type SERIALIZABLE_SHORT_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.SHORT));
-    private static final Type SERIALIZABLE_INTEGER_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.INTEGER));
-    private static final Type SERIALIZABLE_LONG_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.LONG));
-    private static final Type SERIALIZABLE_FLOAT_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.FLOAT));
-    private static final Type SERIALIZABLE_DOUBLE_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.DOUBLE));
-    
-    private static final Type SERIALIZABLE_TUPLE0 = Types.pred(Types.SERIALIZABLE, Types.tuple());
-       private static final Type SERIALIZABLE_VARIANT = Types.pred(Types.SERIALIZABLE, Types.VARIANT);
-    
+       
     public Reduction reduce(TPred constraint) {
         // VecComp
         if(constraint.typeClass == Types.VEC_COMP) {
@@ -87,145 +55,8 @@ public class ConstraintEnvironment {
                         Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
         }
         // Serializable
-        if(constraint.typeClass == Types.SERIALIZABLE) {
-            Type parameter = Types.canonical(constraint.parameters[0]);            
-            if(parameter instanceof TCon) {
-                TCon con = (TCon)parameter;
-                if(con == Types.DOUBLE)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/DoubleBinding"), SERIALIZABLE_DOUBLE, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.STRING)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "STRING", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/StringBinding"), SERIALIZABLE_STRING, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.INTEGER)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/IntegerBinding"), SERIALIZABLE_INTEGER, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.BOOLEAN)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/BooleanBinding"), SERIALIZABLE_BOOLEAN, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.BYTE)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BYTE", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ByteBinding"), SERIALIZABLE_BYTE, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.FLOAT)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/FloatBinding"), SERIALIZABLE_FLOAT, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.LONG)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "LONG", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/LongBinding"), SERIALIZABLE_LONG, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.tupleConstructor(0))
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "VOID", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/Binding"), SERIALIZABLE_TUPLE0, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.VARIANT)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "VARIANT", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/VariantBinding"), SERIALIZABLE_VARIANT, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.DOUBLE_ARRAY)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_DOUBLE_ARRAY, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.INTEGER_ARRAY)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_INTEGER_ARRAY, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.BOOLEAN_ARRAY)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BOOLEAN_ARRAY, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.BYTE_ARRAY)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BYTE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BYTE_ARRAY, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.FLOAT_ARRAY)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_FLOAT_ARRAY, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                else if(con == Types.LONG_ARRAY)
-                    return new Reduction(
-                            new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "LONG_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_LONG_ARRAY, -1)),
-                                    Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-            }
-            else if(parameter instanceof TApply) {
-                TApply apply1 = (TApply)parameter;
-                Type f1 = Types.canonical(apply1.function);
-                Type p1 = Types.canonical(apply1.parameter);
-                if(f1 instanceof TCon) {
-                    TCon con = (TCon)f1;
-                    if(con == Types.LIST)
-                        return new Reduction(
-                            new ELiteral(new JavaConstructor("org/simantics/databoard/binding/impl/ArrayListBinding", Types.NO_EFFECTS, 
-                                    Types.pred(Types.SERIALIZABLE, Types.list(p1)), Types.pred(Types.SERIALIZABLE, p1))),
-                            Type.EMPTY_ARRAY, new TPred[] { Types.pred(Types.SERIALIZABLE, p1) });
-                    else if(con == Types.MAYBE)
-                        return new Reduction(
-                            new ELiteral(new JavaConstructor("org/simantics/databoard/binding/impl/OptionalBindingDefault", Types.NO_EFFECTS, 
-                                    Types.pred(Types.SERIALIZABLE, Types.apply(Types.MAYBE, p1)), Types.pred(Types.SERIALIZABLE, p1))),
-                            Type.EMPTY_ARRAY, new TPred[] { Types.pred(Types.SERIALIZABLE, p1) });
-                    else if(con == Types.VECTOR) {
-                       if (p1 == Types.DOUBLE)
-                                   return new Reduction(
-                                           new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_DOUBLE_VECTOR, -1)),
-                                                   Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);                               
-                        else if(p1 == Types.INTEGER)
-                            return new Reduction(
-                                    new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_INTEGER_VECTOR, -1)),
-                                            Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                        else if(p1 == Types.BOOLEAN)
-                            return new Reduction(
-                                    new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BOOLEAN_VECTOR, -1)),
-                                            Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                        else if(p1 == Types.BYTE)
-                            return new Reduction(
-                                    new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "BYTE_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BYTE_VECTOR, -1)),
-                                            Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                        else if(p1 == Types.FLOAT)
-                            return new Reduction(
-                                    new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_FLOAT_VECTOR, -1)),
-                                            Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                        else if(p1 == Types.LONG)
-                            return new Reduction(
-                                    new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "LONG_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_LONG_VECTOR, -1)),
-                                            Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-                        else
-                               return new Reduction(
-                                               new ELiteral(new JavaStaticMethod("org/simantics/databoard/Bindings", "getArrayBinding", Types.NO_EFFECTS, 
-                                    Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, p1)), Types.pred(Types.SERIALIZABLE, p1))),
-                            Type.EMPTY_ARRAY, new TPred[] { Types.pred(Types.SERIALIZABLE, p1) });
-                    }
-                }
-                else if(f1 instanceof TApply) {
-                    TApply apply2 = (TApply)parameter;
-                    Type f2 = Types.canonical(apply2.function);
-                    Type p2 = Types.canonical(apply2.parameter);
-                    if(f2 instanceof TCon) {
-                        TCon con = (TCon)f2;
-                        /*if(con == Types.tupleConstructor(2)) {
-                            return new Reduction(
-                                    new EConstant(Builtins.TUPLE_CONSTRUCTORS[2]new JavaConstructor("org/simantics/databoard/binding/impl/ArrayListBinding", Types.NO_EFFECTS, 
-                                            Types.pred(Types.SERIALIZABLE, p1), Types.pred(Types.SERIALIZABLE, Types.list(p1)))),
-                                    Type.EMPTY_ARRAY, 
-                                    new TPred[] { Types.pred(Types.SERIALIZABLE, p2), Types.pred(Types.SERIALIZABLE, p1) });
-                        }*/
-                    }
-                }
-            }
-            
-               // Default to a binding as an ObjectVariantBinding
-            // This can be applied only if the type is ground type (i.e. does not contain type variables),
-            // because otherwise the Serializable instance could be provided as a parameter to the function
-            if(parameter.isGround())
-                return new Reduction(
-                        new ELiteral(new JavaStaticField("org/simantics/databoard/Bindings", "OBJECT", Types.NO_EFFECTS,
-                                TypeDesc.forClass("org/simantics/databoard/binding/VariantBinding"), Types.pred(Types.SERIALIZABLE, parameter), -1)),
-                                Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);
-        }
+        if(constraint.typeClass == Types.SERIALIZABLE)
+            return ReduceSerializable.reduceSerializable(constraint.parameters[0]);
         
         // Typeable
         else if(constraint.typeClass == Types.TYPEABLE) {
index dd91efb70feff2aba4eea80f9264f6a5365f2429..15ac6d664210a2b032c72011816d514678aab9d0 100644 (file)
@@ -155,7 +155,7 @@ public class ConstraintSolver {
                         }\r
                         for(Constraint constraint : group) {\r
                             Reduction reduction = environment.reduce(constraint.constraint);\r
-                            if(reduction.parameters.length > 0)\r
+                            if(reduction.demands.length > 0)\r
                                 throw new InternalCompilerError();\r
                             constraint.setGenerator(Constraint.STATE_HAS_INSTANCE,\r
                                     reduction.generator, reduction.parameters);\r
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ReduceSerializable.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ReduceSerializable.java
new file mode 100644 (file)
index 0000000..ea0276e
--- /dev/null
@@ -0,0 +1,147 @@
+package org.simantics.scl.compiler.internal.elaboration.constraints;\r
+\r
+import org.cojen.classfile.TypeDesc;\r
+import org.simantics.scl.compiler.constants.ClassConstant;\r
+import org.simantics.scl.compiler.constants.Constant;\r
+import org.simantics.scl.compiler.constants.JavaConstructor;\r
+import org.simantics.scl.compiler.constants.JavaStaticField;\r
+import org.simantics.scl.compiler.constants.JavaStaticMethod;\r
+import org.simantics.scl.compiler.elaboration.expressions.EApply;\r
+import org.simantics.scl.compiler.elaboration.expressions.EApplyType;\r
+import org.simantics.scl.compiler.elaboration.expressions.ELiteral;\r
+import org.simantics.scl.compiler.elaboration.expressions.Expression;\r
+import org.simantics.scl.compiler.elaboration.expressions.Expressions;\r
+import org.simantics.scl.compiler.types.TCon;\r
+import org.simantics.scl.compiler.types.TPred;\r
+import org.simantics.scl.compiler.types.TVar;\r
+import org.simantics.scl.compiler.types.Type;\r
+import org.simantics.scl.compiler.types.Types;\r
+import org.simantics.scl.compiler.types.kinds.Kinds;\r
+import org.simantics.scl.compiler.types.util.MultiApply;\r
+\r
+import gnu.trove.map.hash.THashMap;\r
+\r
+public class ReduceSerializable {\r
+    \r
+    private static final TVar A = Types.var(Kinds.STAR);\r
+    private static final TVar B = Types.var(Kinds.STAR);\r
+    \r
+    private static final Type SERIALIZABLE_BOOLEAN = Types.pred(Types.SERIALIZABLE, Types.BOOLEAN);\r
+    private static final Type SERIALIZABLE_BYTE = Types.pred(Types.SERIALIZABLE, Types.BYTE);\r
+    private static final Type SERIALIZABLE_INTEGER = Types.pred(Types.SERIALIZABLE, Types.INTEGER);\r
+    private static final Type SERIALIZABLE_LONG = Types.pred(Types.SERIALIZABLE, Types.LONG);\r
+    private static final Type SERIALIZABLE_FLOAT = Types.pred(Types.SERIALIZABLE, Types.FLOAT);\r
+    private static final Type SERIALIZABLE_DOUBLE = Types.pred(Types.SERIALIZABLE, Types.DOUBLE);\r
+    private static final Type SERIALIZABLE_STRING = Types.pred(Types.SERIALIZABLE, Types.STRING);\r
+    \r
+    private static final Type SERIALIZABLE_BOOLEAN_ARRAY = Types.pred(Types.SERIALIZABLE, Types.BOOLEAN_ARRAY);\r
+    private static final Type SERIALIZABLE_BYTE_ARRAY = Types.pred(Types.SERIALIZABLE, Types.BYTE_ARRAY);\r
+    private static final Type SERIALIZABLE_INTEGER_ARRAY = Types.pred(Types.SERIALIZABLE, Types.INTEGER_ARRAY);\r
+    private static final Type SERIALIZABLE_LONG_ARRAY = Types.pred(Types.SERIALIZABLE, Types.LONG_ARRAY);\r
+    private static final Type SERIALIZABLE_FLOAT_ARRAY = Types.pred(Types.SERIALIZABLE, Types.FLOAT_ARRAY);\r
+    private static final Type SERIALIZABLE_DOUBLE_ARRAY = Types.pred(Types.SERIALIZABLE, Types.DOUBLE_ARRAY);\r
+    \r
+    private static final Type SERIALIZABLE_BOOLEAN_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.BOOLEAN));\r
+    private static final Type SERIALIZABLE_BYTE_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.BYTE));\r
+    private static final Type SERIALIZABLE_INTEGER_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.INTEGER));\r
+    private static final Type SERIALIZABLE_LONG_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.LONG));\r
+    private static final Type SERIALIZABLE_FLOAT_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.FLOAT));\r
+    private static final Type SERIALIZABLE_DOUBLE_VECTOR = Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, Types.DOUBLE));\r
+    \r
+    private static final Type SERIALIZABLE_TUPLE0 = Types.pred(Types.SERIALIZABLE, Types.tuple());\r
+    private static final Type SERIALIZABLE_VARIANT = Types.pred(Types.SERIALIZABLE, Types.VARIANT);\r
+    \r
+    private static final TCon MLIST = Types.con("MList", "T");\r
+    private static final TCon MAP = Types.con("Map", "T");\r
+    private static final TCon MMAP = Types.con("MMap", "T");\r
+    \r
+    private static Constant GET_BINDING =\r
+            new JavaStaticMethod("org/simantics/databoard/Bindings", "getBinding", Types.NO_EFFECTS,\r
+                    Types.pred(Types.SERIALIZABLE, A), Types.pred(Types.VEC_COMP, A));\r
+\r
+    private static final THashMap<TCon,Constant> BINDING_CONSTANTS0 = new THashMap<TCon,Constant>();\r
+    static {\r
+        BINDING_CONSTANTS0.put(Types.DOUBLE,        new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE",        Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/DoubleBinding"),  SERIALIZABLE_DOUBLE, -1));\r
+        BINDING_CONSTANTS0.put(Types.STRING,        new JavaStaticField("org/simantics/databoard/Bindings", "STRING",        Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/StringBinding"),  SERIALIZABLE_STRING, -1));\r
+        BINDING_CONSTANTS0.put(Types.INTEGER,       new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER",       Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/IntegerBinding"), SERIALIZABLE_INTEGER, -1));\r
+        BINDING_CONSTANTS0.put(Types.BOOLEAN,       new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN",       Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/BooleanBinding"), SERIALIZABLE_BOOLEAN, -1));\r
+        BINDING_CONSTANTS0.put(Types.BYTE,          new JavaStaticField("org/simantics/databoard/Bindings", "BYTE",          Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ByteBinding"),    SERIALIZABLE_BYTE, -1));\r
+        BINDING_CONSTANTS0.put(Types.FLOAT,         new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT",         Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/FloatBinding"),   SERIALIZABLE_FLOAT, -1));\r
+        BINDING_CONSTANTS0.put(Types.LONG,          new JavaStaticField("org/simantics/databoard/Bindings", "LONG",          Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/LongBinding"),    SERIALIZABLE_LONG, -1));\r
+        BINDING_CONSTANTS0.put(Types.UNIT,          new JavaStaticField("org/simantics/databoard/Bindings", "VOID",          Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/Binding"),        SERIALIZABLE_TUPLE0, -1));\r
+        BINDING_CONSTANTS0.put(Types.VARIANT,       new JavaStaticField("org/simantics/databoard/Bindings", "VARIANT",       Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/VariantBinding"), SERIALIZABLE_VARIANT, -1));\r
+        BINDING_CONSTANTS0.put(Types.DOUBLE_ARRAY,  new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE_ARRAY",  Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_DOUBLE_ARRAY, -1));\r
+        BINDING_CONSTANTS0.put(Types.INTEGER_ARRAY, new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_INTEGER_ARRAY, -1));\r
+        BINDING_CONSTANTS0.put(Types.BOOLEAN_ARRAY, new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_BOOLEAN_ARRAY, -1));\r
+        BINDING_CONSTANTS0.put(Types.BYTE_ARRAY,    new JavaStaticField("org/simantics/databoard/Bindings", "BYTE_ARRAY",    Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_BYTE_ARRAY, -1));\r
+        BINDING_CONSTANTS0.put(Types.FLOAT_ARRAY,   new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT_ARRAY",   Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_FLOAT_ARRAY, -1));\r
+        BINDING_CONSTANTS0.put(Types.LONG_ARRAY,    new JavaStaticField("org/simantics/databoard/Bindings", "LONG_ARRAY",    Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_LONG_ARRAY, -1));\r
+    }\r
+    \r
+    private static final THashMap<TCon,Constant> BINDING_CONSTANTS1 = new THashMap<TCon,Constant>();\r
+    static {\r
+        BINDING_CONSTANTS1.put(Types.LIST,   new JavaConstructor("org/simantics/databoard/binding/impl/ArrayListBinding",       Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.list(A)),               Types.pred(Types.SERIALIZABLE, A)));\r
+        BINDING_CONSTANTS1.put(Types.MAYBE,  new JavaConstructor("org/simantics/databoard/binding/impl/OptionalBindingDefault", Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.apply(Types.MAYBE, A)), Types.pred(Types.SERIALIZABLE, A)));\r
+        BINDING_CONSTANTS1.put(Types.VECTOR, new JavaStaticMethod("org/simantics/databoard/Bindings", "getArrayBinding",        Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.pred(Types.VECTOR, A)), Types.pred(Types.SERIALIZABLE, A)));\r
+        BINDING_CONSTANTS1.put(MLIST,        new JavaConstructor("org/simantics/databoard/binding/impl/ArrayListBinding",       Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.apply(MLIST, A)),       Types.pred(Types.SERIALIZABLE, A)));\r
+    }\r
+    \r
+    private static final THashMap<TCon,Constant> VECTOR_BINDING_CONSTANTS = new THashMap<TCon,Constant>();\r
+    static {\r
+        VECTOR_BINDING_CONSTANTS.put(Types.DOUBLE,  new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE_ARRAY",  Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_DOUBLE_VECTOR, -1));\r
+        VECTOR_BINDING_CONSTANTS.put(Types.INTEGER, new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_INTEGER_VECTOR, -1));\r
+        VECTOR_BINDING_CONSTANTS.put(Types.BOOLEAN, new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BOOLEAN_VECTOR, -1));\r
+        VECTOR_BINDING_CONSTANTS.put(Types.BYTE,    new JavaStaticField("org/simantics/databoard/Bindings", "BYTE_ARRAY",    Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_BYTE_VECTOR, -1));\r
+        VECTOR_BINDING_CONSTANTS.put(Types.FLOAT,   new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT_ARRAY",   Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_FLOAT_VECTOR, -1));\r
+        VECTOR_BINDING_CONSTANTS.put(Types.LONG,    new JavaStaticField("org/simantics/databoard/Bindings", "LONG_ARRAY",    Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"), SERIALIZABLE_LONG_VECTOR, -1));\r
+    }\r
+    \r
+    private static final THashMap<TCon,Constant> BINDING_CONSTANTS2 = new THashMap<TCon,Constant>();\r
+    static {\r
+        BINDING_CONSTANTS2.put(MAP, new JavaConstructor("org/simantics/databoard/binding/impl/HashMapBinding", Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.apply(MAP, A, B)), Types.pred(Types.SERIALIZABLE, A), Types.pred(Types.SERIALIZABLE, B)));\r
+        BINDING_CONSTANTS2.put(MMAP, new JavaConstructor("org/simantics/databoard/binding/impl/HashMapBinding", Types.NO_EFFECTS, Types.pred(Types.SERIALIZABLE, Types.apply(MMAP, A, B)), Types.pred(Types.SERIALIZABLE, A), Types.pred(Types.SERIALIZABLE, B)));\r
+    }\r
+        \r
+    public static Reduction reduceSerializable(Type parameter) {\r
+        MultiApply apply = Types.matchApply(parameter);\r
+        if(!(apply.constructor instanceof TCon))\r
+            return null;\r
+        \r
+        switch(apply.parameters.length) {\r
+        case 0: {\r
+            Constant constant = BINDING_CONSTANTS0.get(apply.constructor);\r
+            if(constant != null)\r
+                return new Reduction(new ELiteral(constant), Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);\r
+        } break;\r
+        case 1: {\r
+            Type parameter0 = apply.parameters[0];\r
+            if(apply.constructor == Types.VECTOR) {\r
+                Constant vecConstant = VECTOR_BINDING_CONSTANTS.get(parameter0);\r
+                if(vecConstant != null)\r
+                    return new Reduction(new ELiteral(vecConstant), Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);\r
+            }\r
+            Constant constant = BINDING_CONSTANTS1.get(apply.constructor);\r
+            if(constant != null)\r
+                return new Reduction(new EApplyType(new ELiteral(constant), parameter0), Type.EMPTY_ARRAY, new TPred[] { Types.pred(Types.SERIALIZABLE, parameter0) });\r
+        } break;\r
+        case 2: {\r
+            Constant constant = BINDING_CONSTANTS2.get(apply.constructor);\r
+            if(constant != null)\r
+                return new Reduction(Expressions.applyTypes(new ELiteral(constant), apply.parameters),\r
+                        Type.EMPTY_ARRAY,\r
+                        new TPred[] { Types.pred(Types.SERIALIZABLE, apply.parameters[0]), Types.pred(Types.SERIALIZABLE, apply.parameters[1]) });\r
+        } break;\r
+        }\r
+      \r
+        // Default to a binding based on the class of the type.\r
+        // This can be applied only if the type is ground type (i.e. does not contain type variables),\r
+        // because otherwise the Serializable instance could be provided as a parameter to the function\r
+        if(parameter.isGround()) {\r
+            Expression bindingGenerator = new EApplyType(new ELiteral(GET_BINDING), parameter);\r
+            Expression bindingExpression = new EApply(bindingGenerator, new ELiteral(new ClassConstant(Types.pred(Types.VEC_COMP, parameter), parameter)));\r
+            return new Reduction(bindingExpression, Type.EMPTY_ARRAY, TPred.EMPTY_ARRAY);\r
+        }\r
+        \r
+        return null;\r
+    }\r
+}\r
index 5e8c548878e4b10e010cb6fc8f0f7cddc8da18ef..e6454fc0c22fcc6561fbe82cb6f96dc651b21b3c 100644 (file)
@@ -556,7 +556,15 @@ public class Types {
             parameters.add(Types.canonical(apply.parameter));
             type = canonical(apply.function);
         }
-        return new MultiApply(type, parameters.toArray(new Type[parameters.size()]));
+        Type[] parametersArray;
+        if(parameters.isEmpty())
+            parametersArray = Type.EMPTY_ARRAY;
+        else {
+            parametersArray = new Type[parameters.size()];
+            for(int i=0,j=parametersArray.length-1;i<parametersArray.length;++i,--j)
+                parametersArray[i] = parameters.get(j);
+        }
+        return new MultiApply(type, parametersArray);
     }
     
     public static Type unifyApply(TCon func, Type type) throws MatchException {
index 022326248c39bacdf395e484f06de8220410893a..0fa6ce0a599e65ec0132077c77d716502cd84c8a 100644 (file)
@@ -183,21 +183,20 @@ public class CellValueVisitor implements AstValueVisitor<Object> {
                        if(rightVal==null) rightResult = rightTemp.toString();\r
                        else rightResult = rightVal;\r
                }\r
-               \r
-               if ((leftResult instanceof String) || (rightResult instanceof String)) {\r
+               if ((leftResult instanceof String) && (rightResult instanceof String)) {\r
                        String leftString = (leftResult.toString()).toLowerCase();\r
                        String rightString = (rightResult.toString()).toLowerCase();\r
                        if("<".equals(astRelation.op.trim())) return leftString.compareTo(rightString) < 0;\r
                        else if(">".equals(astRelation.op.trim())) return leftString.compareTo(rightString) > 0;\r
-                       // empty string should equal zero (TODO: this is a hack, the proper fix should be somewhere earlier so other cases would work as well)\r
-                       else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0 || emptyAndZero(leftString, rightString) || emptyAndZero(rightString, leftString);\r
+                       else if("=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) == 0;\r
                        else if("<>".equals(astRelation.op.trim())) return leftString.compareTo(rightString) != 0 ;\r
                        else if("<=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) <= 0 ;\r
                        else if(">=".equals(astRelation.op.trim())) return leftString.compareTo(rightString) >= 0 ;\r
                        else throw new IllegalStateException();\r
                } else {\r
-                       Number leftNumber = SpreadsheetGraphUtils.asNumber(leftResult);\r
-                       Number rightNumber = SpreadsheetGraphUtils.asNumber(rightResult);\r
+                       Number leftNumber = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(leftResult);\r
+                       Number rightNumber = SpreadsheetGraphUtils.asDoubleWhereEmptyStringIsZero(rightResult);\r
+                       if(leftNumber==null || rightNumber==null) return false;\r
                        if("<".equals(astRelation.op.trim())) return leftNumber.doubleValue() < rightNumber.doubleValue();\r
                        else if(">".equals(astRelation.op.trim())) return leftNumber.doubleValue() > rightNumber.doubleValue();\r
                        else if("=".equals(astRelation.op.trim())) return leftNumber.doubleValue() == rightNumber.doubleValue();\r
@@ -208,15 +207,6 @@ public class CellValueVisitor implements AstValueVisitor<Object> {
                }\r
        }\r
        \r
-       private static boolean emptyAndZero(String a, String b) {\r
-           try {\r
-               return a.isEmpty() && (Double.parseDouble(b) == 0);\r
-           }\r
-           catch (NumberFormatException e) {\r
-               return false;\r
-           }\r
-       }\r
-       \r
        Object leftValueWithPrefix(Object result, AstValue value, String prefix, boolean forceNumber) {\r
                if(result == null) {\r
                        Object obj = value.accept(this);\r
index 6ffc03aa5ed5416b67d462932478e936909e6855..b80a9c8cd7c334963089f33bc98d0ef064fb23f4 100644 (file)
Binary files a/bundles/org.simantics.tests.modelled.ontology/graph.tg and b/bundles/org.simantics.tests.modelled.ontology/graph.tg differ
index c8b53e56cebb192783c1b3263d5f8bc995a22df5..862131139dfd500072221ac32ba7b194cd28064c 100644 (file)
Binary files a/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg and b/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg differ
index 6f7d89c2da75ab6836aa453eb1d3bdeeeda3e776..b51213dc8475a00c1eab2cc62bb09d9245948367 100644 (file)
@@ -29,9 +29,9 @@ MBC = TestsUI.BrowseContext : VP.BrowseContext
 
 MBC
     @VP.namedRelationChildRule           TestsUI.Contributions.STSSuites L0.Entity   L0.ConsistsOf TESTS.STSSuite
-    @VP.namedConstantImageRule           TestsUI.Contributions.ModuleImage           TESTS.STSSuite                         TestsUI.testSuiteImage
+    @VP.namedConstantImageRule           TestsUI.Contributions.SuiteImage           TESTS.STSSuite                         TestsUI.testSuiteImage
     @VP.namedRelationChildRule           TestsUI.Contributions.STSTests L0.Entity   L0.ConsistsOf TESTS.STSTest
-    @VP.namedConstantImageRule           TestsUI.Contributions.ModuleImage           TESTS.STSTest                         TestsUI.testImage
+    @VP.namedConstantImageRule           TestsUI.Contributions.TestImage           TESTS.STSTest                         TestsUI.testImage
 
 MAC = TestsUI.ModelingActionContext : VP.BrowseContext
     VP.BrowseContext.IsIncludedIn PROJECT.ProjectActionContext
index 4aa14a70a5bce5dfe949e64e9cad4cc8e2b4f524..897d42c9dbc9198c6f5de7299a195a058ba6494d 100644 (file)
@@ -12,11 +12,12 @@ public class TestsUIResource {
     \r
     public final Resource BrowseContext;\r
     public final Resource Contributions;\r
-    public final Resource Contributions_ModuleImage;\r
     public final Resource Contributions_NewSTSSuite;\r
     public final Resource Contributions_NewSTSTest;\r
     public final Resource Contributions_STSSuites;\r
     public final Resource Contributions_STSTests;\r
+    public final Resource Contributions_SuiteImage;\r
+    public final Resource Contributions_TestImage;\r
     public final Resource ModelingActionContext;\r
     public final Resource ModelingActionContext_Actions;\r
     public final Resource ModelingActionContext_Actions_NewSTSSuite;\r
@@ -29,11 +30,12 @@ public class TestsUIResource {
     public static class URIs {\r
         public static final String BrowseContext = "http://www.simantics.org/TestsUI-1.0/BrowseContext";\r
         public static final String Contributions = "http://www.simantics.org/TestsUI-1.0/Contributions";\r
-        public static final String Contributions_ModuleImage = "http://www.simantics.org/TestsUI-1.0/Contributions/ModuleImage";\r
         public static final String Contributions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSSuite";\r
         public static final String Contributions_NewSTSTest = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSTest";\r
         public static final String Contributions_STSSuites = "http://www.simantics.org/TestsUI-1.0/Contributions/STSSuites";\r
         public static final String Contributions_STSTests = "http://www.simantics.org/TestsUI-1.0/Contributions/STSTests";\r
+        public static final String Contributions_SuiteImage = "http://www.simantics.org/TestsUI-1.0/Contributions/SuiteImage";\r
+        public static final String Contributions_TestImage = "http://www.simantics.org/TestsUI-1.0/Contributions/TestImage";\r
         public static final String ModelingActionContext = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext";\r
         public static final String ModelingActionContext_Actions = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions";\r
         public static final String ModelingActionContext_Actions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/NewSTSSuite";\r
@@ -56,11 +58,12 @@ public class TestsUIResource {
     public TestsUIResource(ReadGraph graph) {\r
         BrowseContext = getResourceOrNull(graph, URIs.BrowseContext);\r
         Contributions = getResourceOrNull(graph, URIs.Contributions);\r
-        Contributions_ModuleImage = getResourceOrNull(graph, URIs.Contributions_ModuleImage);\r
         Contributions_NewSTSSuite = getResourceOrNull(graph, URIs.Contributions_NewSTSSuite);\r
         Contributions_NewSTSTest = getResourceOrNull(graph, URIs.Contributions_NewSTSTest);\r
         Contributions_STSSuites = getResourceOrNull(graph, URIs.Contributions_STSSuites);\r
         Contributions_STSTests = getResourceOrNull(graph, URIs.Contributions_STSTests);\r
+        Contributions_SuiteImage = getResourceOrNull(graph, URIs.Contributions_SuiteImage);\r
+        Contributions_TestImage = getResourceOrNull(graph, URIs.Contributions_TestImage);\r
         ModelingActionContext = getResourceOrNull(graph, URIs.ModelingActionContext);\r
         ModelingActionContext_Actions = getResourceOrNull(graph, URIs.ModelingActionContext_Actions);\r
         ModelingActionContext_Actions_NewSTSSuite = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_NewSTSSuite);\r
index ae17537f02f3a9fe2ecad21183bb948a1ecee5d1..a1a525d80f19ad735bf42c72698032a6d6159208 100644 (file)
@@ -25,6 +25,8 @@ public class FormattingUtil {
 \r
     private int floatDigits;\r
     private int doubleDigits;\r
+    private double lowLimit;\r
+    private double highLimit;\r
     private DecimalFormatSymbols decimalFormatSymbols;\r
 \r
     private DecimalFormat flow;\r
@@ -38,20 +40,28 @@ public class FormattingUtil {
     public FormattingUtil(int floatDigits, int doubleDigits) {\r
         this(floatDigits, doubleDigits, Locale.getDefault());\r
     }\r
-\r
+    \r
     public FormattingUtil(int floatDigits, int doubleDigits, Locale locale) {\r
-        this.floatDigits = floatDigits;\r
+        this(floatDigits, doubleDigits, 0.01, 1e6, locale);\r
+    }\r
+\r
+    public FormattingUtil(int floatDigits, int doubleDigits, double lowLimit, double highLimit, Locale locale) {\r
+       this.floatDigits = floatDigits;\r
         this.doubleDigits = doubleDigits;\r
-        this.decimalFormatSymbols = DecimalFormatSymbols.getInstance(locale);\r
+        this.lowLimit = lowLimit;\r
+        this.highLimit = highLimit;\r
+        this.decimalFormatSymbols = DecimalFormatSymbols.getInstance(locale != null ? locale : Locale.getDefault());\r
         initFormats();\r
     }\r
 \r
     private void initFormats() {\r
         this.flow = createLowFormat(floatDigits);\r
-        this.fmiddles = createMiddleFormats(6, floatDigits);\r
+        double exp = Math.log10(highLimit);\r
+        int formatCount = Math.max(1, (int) Math.ceil(exp));\r
+        this.fmiddles = createMiddleFormats(formatCount, floatDigits);\r
         this.fhigh = createHighFormat(floatDigits);\r
         this.dlow = createLowFormat(doubleDigits);\r
-        this.dmiddles = createMiddleFormats(6, doubleDigits);\r
+        this.dmiddles = createMiddleFormats(formatCount, doubleDigits);\r
         this.dhigh = createHighFormat(doubleDigits);\r
     }\r
 \r
@@ -66,7 +76,8 @@ public class FormattingUtil {
 \r
     private DecimalFormat createHighFormat(int digitCount) {\r
         StringBuilder fmt = new StringBuilder();\r
-        fmt.append("##0.");\r
+        fmt.append("##0");\r
+        if (digitCount > 3) fmt.append(".");\r
         for (int i = 3; i < digitCount; ++i)\r
             fmt.append('#');\r
         fmt.append("E0");\r
@@ -74,8 +85,8 @@ public class FormattingUtil {
         return new DecimalFormat(fmt.toString(), decimalFormatSymbols);\r
     }\r
 \r
-    private static DecimalFormat[] createMiddleFormats(int formatCount, int digitCount) {\r
-        DecimalFormat[] middles = new DecimalFormat[6];\r
+    private DecimalFormat[] createMiddleFormats(int formatCount, int digitCount) {\r
+        DecimalFormat[] middles = new DecimalFormat[formatCount];\r
         for (int exp10 = 0; exp10 < formatCount; ++exp10) {\r
             StringBuilder fmt = new StringBuilder();\r
             int digits = digitCount;\r
@@ -83,11 +94,11 @@ public class FormattingUtil {
                 fmt.append('#');\r
             fmt.append('0');\r
             --digits;\r
-            fmt.append('.');\r
+            if (digits > 0) fmt.append('.');\r
             for (; digits > 0; --digits)\r
                 fmt.append('#');\r
             //System.out.println(fmt.toString());\r
-            middles[exp10] = new DecimalFormat(fmt.toString(), DecimalFormatSymbols.getInstance(Locale.US));\r
+            middles[exp10] = new DecimalFormat(fmt.toString(), decimalFormatSymbols);\r
         }\r
         return middles;\r
     }\r
@@ -145,16 +156,16 @@ public class FormattingUtil {
         }\r
     }\r
 \r
-    private String formatNumber(float v) {\r
+    public String formatNumber(float v) {\r
         if (Float.isInfinite(v)) {\r
             return (v == Float.POSITIVE_INFINITY) ? "\u221E" : "-\u221E";\r
         } else if (Float.isNaN(v)) {\r
             return "NaN";\r
         } else {\r
             float abs = Math.abs(v);\r
-            if (abs < 1.0f && abs >= 0.01f) {\r
+            if (abs < 1.0f && abs >= (float)lowLimit) {\r
                 return flow.format(v);\r
-            } else if (abs >= 1.0f && abs < 1e6f) {\r
+            } else if (abs >= 1.0f && abs < (float)highLimit) {\r
                 double exp = Math.log10(abs);\r
                 int expi = (int) Math.floor(exp);\r
 //                System.out.println("format(" + v + ")");\r
@@ -168,16 +179,16 @@ public class FormattingUtil {
         }\r
     }\r
 \r
-    private String formatNumber(double v) {\r
+    public String formatNumber(double v) {\r
         if (Double.isInfinite(v)) {\r
             return (v == Double.POSITIVE_INFINITY) ? "\u221E" : "-\u221E";\r
         } else if (Double.isNaN(v)) {\r
             return "NaN";\r
         } else {\r
             double abs = Math.abs(v);\r
-            if (abs < 1.0 && abs >= 0.01) {\r
+            if (abs < 1.0 && abs >= lowLimit) {\r
                 return dlow.format(v);\r
-            } else if (abs >= 1.0 && abs < 1e6) {\r
+            } else if (abs >= 1.0 && abs < highLimit) {\r
                 double exp = Math.log10(abs);\r
                 int expi = (int) Math.floor(exp);\r
 //                System.out.println("format(" + v + ")");\r