]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Fix endless loop in type inference for over-applied functions"
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 13 Jun 2019 11:37:04 +0000 (11:37 +0000)
committerGerrit Code Review <gerrit2@simantics>
Thu, 13 Jun 2019 11:37:04 +0000 (11:37 +0000)
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/EdgeRequest.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/OpenDiagramFromConfigurationAdapter.java
bundles/org.simantics.modeling/src/org/simantics/modeling/services/ComponentNamingUtil.java

index b2951cb27e3c122322aeca97aabe124cac8b9702..5a37257e2531c051c39de0bea04af271e1adccce 100644 (file)
@@ -2296,67 +2296,16 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
        @Override
        final public void forEachPredicate(final ReadGraphImpl impl, final Resource subject, final AsyncMultiProcedure<Resource> procedure) {
 
-               throw new UnsupportedOperationException();
+        try {
 
-//             assert(subject != null);
-//             assert(procedure != null);
-//
-//             final ListenerBase listener = getListenerBase(procedure);
-//
-//             IntProcedure ip = new IntProcedure() {
-//
-//                     AtomicBoolean first = new AtomicBoolean(true);
-//
-//                     @Override
-//                     public void execute(ReadGraphImpl graph, int i) {
-//                             try {
-//                                     if(first.get()) {
-//                                             procedure.execute(graph, querySupport.getResource(i));
-//                                     } else {
-//                                             procedure.execute(impl.newRestart(graph), querySupport.getResource(i));
-//                                     }
-//                             } catch (Throwable t2) {
-//                                     Logger.defaultLogError(t2);
-//                             }
-//                     }
-//
-//                     @Override
-//                     public void finished(ReadGraphImpl graph) {
-//                             try {
-//                                     if(first.compareAndSet(true, false)) {
-//                                             procedure.finished(graph);
-////                                           impl.state.barrier.dec(this);
-//                                     } else {
-//                                             procedure.finished(impl.newRestart(graph));
-//                                     }
-//
-//                             } catch (Throwable t2) {
-//                                     Logger.defaultLogError(t2);
-//                             }
-//                     }
-//
-//                     @Override
-//                     public void exception(ReadGraphImpl graph, Throwable t) {
-//                             try {
-//                                     if(first.compareAndSet(true, false)) {
-//                                             procedure.exception(graph, t);
-//                                     } else {
-//                                             procedure.exception(impl.newRestart(graph), t);
-//                                     }
-//                             } catch (Throwable t2) {
-//                                     Logger.defaultLogError(t2);
-//                             }
-//                     }
-//
-//             };
-//
-//             int sId = querySupport.getId(subject);
-//
-//             try {
-//                     QueryCache.runnerPredicates(impl, sId, impl.parent, listener, ip);
-//             } catch (DatabaseException e) {
-//                     Logger.defaultLogError(e);
-//             }
+               for(Resource predicate : getPredicates(impl, subject))
+                   procedure.execute(impl, predicate);
+
+               procedure.finished(impl);
+
+           } catch (Throwable e) {
+               procedure.exception(impl, e);
+           }
 
        }
 
index 651228ce1d7756f10516430c6bbc8c71d355cece..826827f768c3cf4a4b06578c72fe2537d9f6c23b 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.db.common.procedure.adapter.ListenerSupport;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
 import org.simantics.db.procedure.AsyncProcedure;
 import org.simantics.diagram.content.EdgeResource;
+import org.simantics.diagram.internal.DebugPolicy;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.diagram.synchronization.ErrorHandler;
 import org.simantics.g2d.canvas.ICanvasContext;
@@ -30,16 +31,19 @@ import org.simantics.g2d.element.impl.Element;
  */
 public class EdgeRequest extends BaseRequest2<EdgeResource, IElement> {
 
+    final GraphToDiagramSynchronizer synchronizer;
     final ErrorHandler errorHandler;
     final ListenerSupport listenerSupport;
     final IDiagram diagram;
     final ConnectionSegmentAdapter adapter;
 
-    public EdgeRequest(ICanvasContext canvas, ErrorHandler errorHandler, ListenerSupport listenerSupport, IDiagram diagram, ConnectionSegmentAdapter adapter, EdgeResource resource) {
+    public EdgeRequest(GraphToDiagramSynchronizer synchronizer, ICanvasContext canvas, ErrorHandler errorHandler, ListenerSupport listenerSupport, IDiagram diagram, ConnectionSegmentAdapter adapter, EdgeResource resource) {
         super(canvas, resource);
 
         assert(adapter != null);
+        assert(synchronizer != null);
 
+        this.synchronizer = synchronizer;
         this.errorHandler = errorHandler;
         this.listenerSupport = listenerSupport;
         this.diagram = diagram;
@@ -96,6 +100,13 @@ public class EdgeRequest extends BaseRequest2<EdgeResource, IElement> {
 
                                     @Override
                                     public void execute(AsyncReadGraph graph, IElement element) {
+                                        
+                                        if (DebugPolicy.DEBUG_EDGE_LOAD)
+                                            System.out.println("    SPAWNED EDGE SEGMENT: " + element + " " + data);
+
+                                        // Register this for updates to work correctly
+                                        synchronizer.mapElementIfNew(data, element);
+                                        
 //                                        task.finish();
                                         // Tell the procedure to use this element
                                         procedure.execute(graph, element);
index aa35c63342c28e8d952a7989f2cc5edd26f83f21..03cedfcb39a66cae558ccd27f0431bffa3dadadf 100644 (file)
@@ -616,6 +616,17 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID
      */
     ConcurrentMap<Object, ConnectionEntityImpl> dataConnection = new ConcurrentHashMap<Object, ConnectionEntityImpl>();
 
+
+    void mapElementIfNew(final Object data, final IElement element) {
+        IElement mapped = getMappedElement(data);
+        if(mapped == null) {
+            mapElement(data, element);
+            currentUpdater.addedElements.add(element);
+            currentUpdater.addedElementMap.put(data, element);
+        }
+    }
+
+    
     /**
      * @param data
      * @param element
@@ -1744,9 +1755,15 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID
                                             @Override
                                             public void execute(Resource connectionType) {
                                                 synchronized (GraphToDiagramUpdater.this) {
+                                                    IElement mapped = getMappedElement(element);
+                                                    assert(mapped != null);
+                                                    
+                                                    if (DebugPolicy.DEBUG_CONNECTION_LISTENER)
+                                                        System.out.println("CONNECTION ENTITY CREATED " + e + " " + element);
+
                                                     //System.out.println("new connection entity " + e);
-                                                    ConnectionEntityImpl entity = new ConnectionEntityImpl(element, connectionType, e);
-                                                    e.setHint(ElementHints.KEY_CONNECTION_ENTITY, entity);
+                                                    ConnectionEntityImpl entity = new ConnectionEntityImpl(element, connectionType, mapped);
+                                                    mapped.setHint(ElementHints.KEY_CONNECTION_ENTITY, entity);
                                                     addedConnectionEntities.put(element, entity);
                                                 }
                                             }
@@ -2223,13 +2240,13 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID
                                     }
                                 });
 
-                            graph.syncRequest(new EdgeRequest(canvas, errorHandler, canvasListenerSupport, diagram, adapter, seg), new AsyncProcedure<IElement>() {
+                            graph.syncRequest(new EdgeRequest(GraphToDiagramSynchronizer.this, canvas, errorHandler, canvasListenerSupport, diagram, adapter, seg), new AsyncProcedure<IElement>() {
                                 @Override
                                 public void execute(AsyncReadGraph graph, IElement e) {
                                     if (DebugPolicy.DEBUG_EDGE_LOAD)
-                                        System.out.println("ADDED EDGE LOADED: " + e);
+                                        System.out.println("ADDED EDGE LOADED: " + e + " " + seg);
+
                                     if (e != null) {
-                                        mapElement(seg, e);
                                         synchronized (GraphToDiagramUpdater.this) {
                                             addedConnectionSegments.add(e);
                                             addedElementMap.put(seg, e);
@@ -2428,8 +2445,6 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID
                     @Override
                     public void execute(IElement loaded) {
                         // Invoked when the element has been loaded.
-                        if (DebugPolicy.DEBUG_EDGE_LISTENER)
-                            System.out.println("EDGE LoadListener for " + loaded);
 
                         if (loaded == null) {
                             disposeListener();
@@ -2437,6 +2452,10 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID
                         }
 
                         Object data = loaded.getHint(ElementHints.KEY_OBJECT);
+
+                        if (DebugPolicy.DEBUG_EDGE_LISTENER)
+                            System.out.println("EDGE LoadListener for " + loaded + " " + data);
+
                         if (addedElementMap.containsKey(data)) {
                             // This element was just loaded, in
                             // which case its hints need to
index 8c052561e2340ed051d5989836742d0684083e0f..0ca3b1b04406861467b845013717710ff5c45788 100644 (file)
@@ -13,6 +13,8 @@ package org.simantics.modeling.ui.diagramEditor;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.eclipse.ui.PlatformUI;
 import org.simantics.Simantics;
@@ -103,16 +105,21 @@ public class OpenDiagramFromConfigurationAdapter extends AbstractResourceEditorA
         Resource diagram = ComponentUtils.getPossibleCompositeDiagram(graph, r);
         if(diagram != null) return diagram;
         
-        if(selectedObjects.size() == 1) {
-               Object o = selectedObjects.iterator().next();
-               if(o instanceof Resource) {
-                       Resource res = (Resource)o;
-                       if(graph.isInstanceOf(res, DIA.Element)) {
-                               return graph.getPossibleObject(res, L0.PartOf);
-                       }
-               }
+        // TODO: what if the selected objects are from different diagrams?
+        if (selectedObjects.size() > 0) {
+            Set<Resource> diagrams = new HashSet<>();
+            for (Object o : selectedObjects) {
+                if (o instanceof Resource) {
+                    Resource res = (Resource)o;
+                    if (graph.isInstanceOf(res, DIA.Element)) {
+                        diagrams.add(graph.getPossibleObject(res, L0.PartOf));
+                    }
+                }
+            }
+            if (diagrams.size() == 1) {
+                return diagrams.iterator().next();
+            }
         }
-        
         return null;
 
     }
index fc629bdb0cc99bcdb71cf17ebb03c1d568f47375..1ac81874e12bd33fcbcc45f417c2a355fc1ad25d 100644 (file)
@@ -22,6 +22,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.primitiverequest.PossibleRelatedValueImplied2;
 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
 import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.common.utils.Versions;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.layer0.Layer0;
 import org.simantics.operation.Layer0X;
@@ -189,11 +190,13 @@ public final class ComponentNamingUtil {
         if (containerGeneratedNamePrefix != null)
             proposition.append(containerGeneratedNamePrefix);
         String componentPrefix = graph.getPossibleRelatedValue(componentType, L0X.HasGeneratedNamePrefix, Bindings.STRING);
-        if (componentPrefix == null) {
+        if (componentPrefix == null || "".equals(componentPrefix)) {
             Layer0 L0 = Layer0.getInstance(graph);
-            componentPrefix = graph.getPossibleRelatedValue(componentType, L0.HasName);
-            if (componentPrefix == null)
+            String name = graph.getPossibleRelatedValue(componentType, L0.HasName);
+            if (name == null)
                 componentPrefix = "Entity";
+            else
+                componentPrefix = Versions.getBaseName(name);
         }
         proposition.append(componentPrefix);
         return proposition.toString();