From: Hannu Niemistö Date: Fri, 12 May 2017 18:47:27 +0000 (+0300) Subject: Merge "(refs #7214) Treat $ exactly like function application" X-Git-Tag: v1.29.0~55 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=7a7f73011a6364cbb80ce4ef04424472d345a65a;hp=63f6a68f31de96e8e8f31cd99b79c365029aa557 Merge "(refs #7214) Treat $ exactly like function application" --- diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java index 1262f3909..a0d4f9da5 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/NamespaceMigrationStep.java @@ -11,8 +11,6 @@ *******************************************************************************/ package org.simantics.db.layer0.migration; -import gnu.trove.set.hash.TIntHashSet; - import java.util.ArrayList; import org.eclipse.core.runtime.IProgressMonitor; @@ -29,12 +27,19 @@ import org.simantics.graph.refactoring.GraphRefactoringException; import org.simantics.graph.refactoring.GraphRefactoringUtils; import org.simantics.graph.refactoring.MappingSpecification; import org.simantics.graph.refactoring.MappingSpecification.MappingRule; +import org.simantics.graph.representation.Identity; +import org.simantics.graph.representation.Internal; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.graph.store.IdentityStore; import org.simantics.layer0.Layer0; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import gnu.trove.set.hash.TIntHashSet; public class NamespaceMigrationStep implements MigrationStep { - + private static final Logger LOGGER = LoggerFactory.getLogger(NamespaceMigrationStep.class); + final ArrayList rules; public NamespaceMigrationStep(ReadGraph graph, Resource step) throws DatabaseException { @@ -50,7 +55,7 @@ public class NamespaceMigrationStep implements MigrationStep { if(fromURI != null && toURI != null) rules.add(new MappingRule(fromURI, toURI)); else - System.err.println("Namespace migration uri formation error: base " + base + " from " + from + " to " + to); + LOGGER.error("Namespace migration uri formation error: base " + base + " from " + from + " to " + to); } } } @@ -63,9 +68,13 @@ public class NamespaceMigrationStep implements MigrationStep { try { MappingSpecification mappingSpec = new MappingSpecification(rules); boolean fixed = GraphRefactoringUtils.fixIncorrectRoot(tg.identities); - System.err.println("fixed=" + fixed); + LOGGER.info("fixed=" + fixed); IdentityStore idStore = TransferableGraphConversion.extractIdentities(tg); - idStore.printChildMap(); + // Mark internal identities new + for(Identity id : tg.identities) + if(id.definition instanceof Internal) + idStore.markNew(id.resource); +// idStore.printChildMap(); // System.err.println("ids: " + idStore); // System.err.println("rc: " + tg.resourceCount); // System.err.println("idStore: " + idStore.toArray().length); @@ -79,7 +88,7 @@ public class NamespaceMigrationStep implements MigrationStep { if(fixed) GraphRefactoringUtils.unfixIncorrectRoot(tg.identities); - System.err.println("rc2: " + tg.resourceCount); + LOGGER.info("rc2: " + tg.resourceCount); // System.err.println("idStore2: " + idStore.toArray().length); } catch (GraphRefactoringException e) { diff --git a/bundles/org.simantics.graph.db/META-INF/MANIFEST.MF b/bundles/org.simantics.graph.db/META-INF/MANIFEST.MF index f21b3e776..165a104ed 100644 --- a/bundles/org.simantics.graph.db/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.graph.db/META-INF/MANIFEST.MF @@ -9,6 +9,5 @@ Require-Bundle: org.simantics.graph;bundle-version="1.0.0";visibility:=reexport, gnu.trove3;bundle-version="3.0.3", org.simantics.layer0;bundle-version="1.0.0", org.slf4j.api;bundle-version="1.7.2" -Export-Package: org.simantics.graph.db, - org.simantics.graph.db.old +Export-Package: org.simantics.graph.db Bundle-Vendor: VTT Technical Research Centre of Finland diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldMissingDependencyException.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldMissingDependencyException.java deleted file mode 100644 index 7ca83f318..000000000 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldMissingDependencyException.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.simantics.graph.db.old; - -import java.util.Set; - -import org.simantics.db.exception.DatabaseException; - -public class OldMissingDependencyException extends DatabaseException { - - private static final long serialVersionUID = -1579450497603555931L; - - private final OldTransferableGraphImportProcess1 process; - - public OldMissingDependencyException(OldTransferableGraphImportProcess1 process) { - super(createMessage(process)); - this.process = process; - } - - private static String createMessage(OldTransferableGraphImportProcess1 process) { - StringBuilder b = new StringBuilder(); - b.append("The following references were not found:\r\n"); - for(String missing : process.missingExternals) { - b.append(" -" + missing + "\r\n"); - } - return b.toString(); - } - - public Set getMissingURIs() { - return process.missingExternals; - } - -} diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphImportProcess1.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphImportProcess1.java deleted file mode 100644 index 6a69e8d92..000000000 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphImportProcess1.java +++ /dev/null @@ -1,479 +0,0 @@ -package org.simantics.graph.db.old; - -import java.io.DataOutput; -import java.io.DataOutputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.simantics.databoard.Bindings; -import org.simantics.databoard.adapter.AdaptException; -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.VirtualGraph; -import org.simantics.db.WriteOnlyGraph; -import org.simantics.db.common.WriteBindings; -import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; -import org.simantics.db.common.uri.UnescapedChildMapOfResource; -import org.simantics.db.common.utils.Logger; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.ResourceNotFoundException; -import org.simantics.db.service.ClusterBuilder; -import org.simantics.db.service.ClusterBuilder.ResourceHandle; -import org.simantics.db.service.SerialisationSupport; -import org.simantics.db.service.TransferableGraphSupport; -import org.simantics.graph.db.CoreInitialization; -import org.simantics.graph.db.IImportAdvisor; -import org.simantics.graph.representation.Extensions; -import org.simantics.graph.representation.External; -import org.simantics.graph.representation.Identity; -import org.simantics.graph.representation.IdentityDefinition; -import org.simantics.graph.representation.Internal; -import org.simantics.graph.representation.Optional; -import org.simantics.graph.representation.Root; -import org.simantics.graph.representation.TransferableGraphUtils; -import org.simantics.graph.representation.old.OldTransferableGraph1; -import org.simantics.graph.representation.old.OldValue1; - -public class OldTransferableGraphImportProcess1 { - - public static String LOG_FILE = "transferableGraphs.log"; - final static private boolean LOG = false; - - static DataOutput log; - - static { - - if (LOG) { - try { - FileOutputStream stream = new FileOutputStream(LOG_FILE); - log = new DataOutputStream(stream); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - - } - - private static void log(String line) { - if (LOG) { - try { - log.writeUTF(line + "\n"); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - OldTransferableGraph1 tg; - IImportAdvisor advisor; - - Resource[] resources; - ResourceHandle[] handles; - - Set missingExternals = new HashSet(); - - // Builtins - Resource RootLibrary; - Resource String; - Resource Library; - - Resource InstanceOf; - Resource ConsistsOf; - Resource PartOf; - Resource HasName; - Resource NameOf; - - public OldTransferableGraphImportProcess1(OldTransferableGraph1 tg, IImportAdvisor advisor) { - this.tg = tg; - this.advisor = advisor; - /*System.out.println("Transferable graph identities:"); - for(Identity id : tg.identities) { - if(id.definition instanceof Internal) { - Internal def = (Internal)id.definition; - System.out.println(" internal " + def.name); - } - else if(id.definition instanceof External) { - External def = (External)id.definition; - System.out.println(" external " + def.name); - } - }*/ - } - - public void findBuiltins(WriteOnlyGraph g) throws DatabaseException { - RootLibrary = g.getBuiltin("http:/"); - String = g.getBuiltin(CoreInitialization.LAYER0 + "String"); - Library = g.getBuiltin(CoreInitialization.LAYER0 + "Library"); - InstanceOf = g.getBuiltin(CoreInitialization.LAYER0 + "InstanceOf"); - ConsistsOf = g.getBuiltin(CoreInitialization.LAYER0 + "ConsistsOf"); - PartOf = g.getBuiltin(CoreInitialization.LAYER0 + "PartOf"); - HasName = g.getBuiltin(CoreInitialization.LAYER0 + "HasName"); - NameOf = g.getBuiltin(CoreInitialization.LAYER0 + "NameOf"); - } - - public void findBuiltins(ReadGraph g) throws DatabaseException { - RootLibrary = g.getBuiltin("http:/"); - String = g.getBuiltin(CoreInitialization.LAYER0 + "String"); - Library = g.getBuiltin(CoreInitialization.LAYER0 + "Library"); - InstanceOf = g.getBuiltin(CoreInitialization.LAYER0 + "InstanceOf"); - ConsistsOf = g.getBuiltin(CoreInitialization.LAYER0 + "ConsistsOf"); - PartOf = g.getBuiltin(CoreInitialization.LAYER0 + "PartOf"); - HasName = g.getBuiltin(CoreInitialization.LAYER0 + "HasName"); - NameOf = g.getBuiltin(CoreInitialization.LAYER0 + "NameOf"); - } - - /* Preparation that is used when the core is empty. - */ - void initialPrepare(WriteOnlyGraph graph) throws DatabaseException { - findBuiltins(graph); - - resources = new Resource[tg.resourceCount]; - - int Root = -1; - int SimanticsDomain = -1; - int Layer0 = -1; - - for(Identity identity : tg.identities) { - if(identity.definition instanceof Internal) { - Internal def = (Internal)identity.definition; - Resource res = null; - if(def.parent == Layer0) { - try { - res = graph.getBuiltin(CoreInitialization.LAYER0 + def.name); - } catch(ResourceNotFoundException e) { - } - } - else if(def.parent == SimanticsDomain) { - if(def.name.equals("Layer0-1.1")) - Layer0 = identity.resource; - } - else if(def.parent == Root) { - if(def.name.equals("www.simantics.org")) - SimanticsDomain = identity.resource; - } - - if(res == null) - res = createChild(graph, resources[def.parent], def.name); - else - createChild(graph, res, resources[def.parent], def.name); - resources[identity.resource] = res; - } - else if(identity.definition instanceof Root) { - Root = identity.resource; - resources[identity.resource] = RootLibrary; - } - } - } - - void addMissing(String external) { - Set removals = new HashSet(); - for(String ext : missingExternals) if(ext.startsWith(external)) return; - for(String ext : missingExternals) if(external.startsWith(ext)) removals.add(ext); - missingExternals.removeAll(removals); - missingExternals.add(external); - } - - void prepare(ReadGraph graph) throws DatabaseException { - findBuiltins(graph); - - Resource[] resources = new Resource[tg.resourceCount]; - - for(Identity identity : tg.identities) { - IdentityDefinition definition = identity.definition; - if(definition instanceof External) { - External def = (External)definition; - if(def.parent == -1) { - resources[identity.resource] = RootLibrary; - } else { - if("@inverse".equals(def.name)) { - Resource parent = resources[def.parent]; - Resource child = graph.getInverse(parent); - resources[identity.resource] = child; - } else { - Resource parent = resources[def.parent]; - // TODO: escape should be removed when names become well-behaving - if(parent != null) { - Resource child = graph - .syncRequest(new UnescapedChildMapOfResource(parent), - new TransientCacheAsyncListener>()) - .get(def.name); - if(child == null) { - addMissing(graph.getURI(parent) + "/" + def.name); - } - resources[identity.resource] = child; - } else { - addMissing(TransferableGraphUtils.getURI(tg.resourceCount, tg.identities, def.parent) + "/" + def.name); - } - } - } - } - else if(definition instanceof Internal) { - // Do not do anything for now - } - else if(definition instanceof Root) { - Root root = (Root)definition; - if(root.name.equals("")) - resources[identity.resource] = RootLibrary; - else - advisor.analyzeRoot(graph, root); - } - else if(definition instanceof Optional) { - External def = (External)definition; - Resource parent = resources[def.parent]; - if(parent != null) - resources[identity.resource] = - graph.syncRequest(new UnescapedChildMapOfResource(parent)).get(def.name); - } - } - - this.resources = resources; - - if(!missingExternals.isEmpty()) throw new OldMissingDependencyException(this); - - } - - Resource createChild(WriteOnlyGraph graph, Resource parent, String name) throws DatabaseException { - Resource child = graph.newResource(); - graph.claim(parent, ConsistsOf, PartOf, child); - Resource nameResource = graph.newResource(); - graph.claim(nameResource, InstanceOf, null, String); - graph.claimValue(nameResource, name, WriteBindings.STRING); - graph.claim(child, HasName, NameOf, nameResource); - return child; - } - - void createChild(WriteOnlyGraph graph, Resource child, Resource parent, String name) throws DatabaseException { - graph.claim(parent, ConsistsOf, PartOf, child); - Resource nameResource = graph.newResource(); - graph.claim(nameResource, InstanceOf, null, String); - graph.claimValue(nameResource, name, WriteBindings.STRING); - graph.claim(child, HasName, NameOf, nameResource); - } - - int[] getClustering() { - Variant v = tg.extensions.get(Extensions.CLUSTERING); - if(v == null) return null; - try { - return (int[])v.getValue(Bindings.INT_ARRAY); - } catch (AdaptException e) { - Logger.defaultLogError(e); - return null; - } - } - - void write(WriteOnlyGraph graph) throws DatabaseException { - - Resource[] resources = this.resources; - - this.handles = new ResourceHandle[resources.length]; - - ResourceHandle[] handles = this.handles; - - int[] clustering = getClustering(); - - // Internal identities - for(Identity identity : tg.identities) { - IdentityDefinition definition = identity.definition; - if(resources[identity.resource] != null) - continue; - if(definition instanceof External) { - // Already done everything - } - else if(definition instanceof Internal) { - Internal def = (Internal)definition; - resources[identity.resource] = - createChild(graph, resources[def.parent], def.name); - } - else if(definition instanceof Root) { - Root root = (Root)definition; - resources[identity.resource] = advisor.createRoot(graph, root); - } - else if(definition instanceof Optional) { - Optional def = (Optional)definition; - Resource child = createChild(graph, resources[def.parent], def.name); - graph.claim(child, InstanceOf, null, Library); // ??? - resources[identity.resource] = child; - } - } - - ClusterBuilder builder = graph.getService(ClusterBuilder.class); - SerialisationSupport ss = graph.getService(SerialisationSupport.class); - - if(clustering != null) { - - int i = 0; - for(int c : clustering) { - builder.newCluster(); - for(int r=0;r= 0) { - - if(resources[obj] == null) { - ResourceHandle inverse = handles[inv]; - object.addStatement(graph, inverse, subject); - } else { - graph.claim( - handles[obj].resource(ss), - handles[inv].resource(ss), - null, handles[sub].resource(ss)); - } - - } - - if(LOG) { - log("[STATEMENT] " + resources[statements[i]].getResourceId() + ", " + resources[statements[i+1]].getResourceId() + ", " + resources[statements[i+3]].getResourceId()); - } - - } - - // Write values - TransferableGraphSupport tgSupport = - graph.getService(TransferableGraphSupport.class); - VirtualGraph vg = graph.getProvider(); - for(OldValue1 value : tg.values) { - int file = value.resource & 0x80000000; - int resource = value.resource & 0x7FFFFFFF; - if (file != 0) { - graph.claimValue(handles[resource].resource(ss), value.value, Bindings.BYTE_ARRAY); - } else { - if(resource < internals) { - handles[resource].addValue(graph, value.value); - } else { - tgSupport.setValue(graph, handles[resource].resource(ss), vg, value.value); - } - //tgSupport.setValue(resources[resource], vg, value.value); - } - } - } - - void write2(WriteOnlyGraph graph) throws DatabaseException { - Resource[] resources = this.resources; - - // Internal identities - for(Identity identity : tg.identities) { - IdentityDefinition definition = identity.definition; - if(resources[identity.resource] != null) - continue; - if(definition instanceof External) { - // Already done everything - } - else if(definition instanceof Internal) { - Internal def = (Internal)definition; - resources[identity.resource] = - createChild(graph, resources[def.parent], def.name); - } - else if(definition instanceof Root) { - Root root = (Root)definition; - resources[identity.resource] = advisor.createRoot(graph, root); - } - else if(definition instanceof Optional) { - Optional def = (Optional)definition; - Resource child = createChild(graph, resources[def.parent], def.name); - graph.claim(child, InstanceOf, null, Library); // ??? - resources[identity.resource] = child; - } - } - - // Create blank resources - for(int i=0;i callback) throws DatabaseException, TransferableGraphException { - final OldTransferableGraphImportProcess1 process = new OldTransferableGraphImportProcess1(tg, - advisor == null ? new ImportAdvisor() : advisor); - session.syncRequest(new ReadRequest() { - @Override - public void run(ReadGraph graph) throws DatabaseException { - process.prepare(graph); - } - }); - session.syncRequest(new WriteOnlyRequest() { - @Override - public void perform(WriteOnlyGraph graph) throws DatabaseException { - process.write(graph); - if(callback != null) - callback.apply(graph, process); - } - }); - } - - public static void importGraph1(WriteGraph graph, final OldTransferableGraph1 tg, IImportAdvisor advisor) throws DatabaseException { - final OldTransferableGraphImportProcess1 process = new OldTransferableGraphImportProcess1(tg, - advisor == null ? new ImportAdvisor() : advisor); - process.prepare(graph); - process.write2(graph); - - } - -} diff --git a/bundles/org.simantics.graph/META-INF/MANIFEST.MF b/bundles/org.simantics.graph/META-INF/MANIFEST.MF index 5f4404acc..6ae6e86fe 100644 --- a/bundles/org.simantics.graph/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.graph/META-INF/MANIFEST.MF @@ -12,9 +12,9 @@ Export-Package: org.simantics.graph, org.simantics.graph.query, org.simantics.graph.refactoring, org.simantics.graph.representation, - org.simantics.graph.representation.old, org.simantics.graph.store, org.simantics.graph.tests.conversion, org.simantics.graph.utils Bundle-ClassPath: . Bundle-Vendor: VTT Technical Research Centre of Finland +Import-Package: org.slf4j diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/query/TransferableGraphConversion.java b/bundles/org.simantics.graph/src/org/simantics/graph/query/TransferableGraphConversion.java index 850c47d85..9c96f834d 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/query/TransferableGraphConversion.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/query/TransferableGraphConversion.java @@ -15,7 +15,6 @@ import org.simantics.graph.representation.Optional; import org.simantics.graph.representation.Root; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.graph.representation.Value; -import org.simantics.graph.representation.old.OldTransferableGraph1; import org.simantics.graph.store.GraphStore; import org.simantics.graph.store.IStore; import org.simantics.graph.store.IdentityStore; @@ -44,10 +43,6 @@ public class TransferableGraphConversion { return extractIdentities(tg.resourceCount, tg.identities); } - public static IdentityStore extractIdentities(OldTransferableGraph1 tg) { - return extractIdentities(tg.resourceCount, tg.identities); - } - private static IdentityStore extractIdentities(int resourceCount, Identity[] ids) { IdentityStore identities = new IdentityStore(); identities.setResourceCount(resourceCount); diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java index 9882048b7..9f8eca398 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/GraphRefactoringUtils.java @@ -1,6 +1,5 @@ package org.simantics.graph.refactoring; -import java.util.ArrayList; import java.util.Arrays; import org.simantics.databoard.util.URIStringUtils; @@ -11,23 +10,19 @@ import org.simantics.graph.query.UriUtils; import org.simantics.graph.refactoring.MappingSpecification.MappingRule; import org.simantics.graph.representation.External; import org.simantics.graph.representation.Identity; -import org.simantics.graph.representation.IdentityDefinition; import org.simantics.graph.representation.Internal; -import org.simantics.graph.representation.Optional; import org.simantics.graph.representation.Root; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.graph.representation.TransferableGraphUtils; -import org.simantics.graph.representation.old.OldTransferableGraph1; -import org.simantics.graph.representation.old.OldValue1; import org.simantics.graph.store.GraphStore; import org.simantics.graph.store.IdentityStore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import gnu.trove.list.array.TIntArrayList; -import gnu.trove.map.hash.TIntIntHashMap; import gnu.trove.set.hash.TIntHashSet; public class GraphRefactoringUtils { - + private static final Logger LOGGER = LoggerFactory.getLogger(GraphRefactoringUtils.class); /** * Moves an external resource. Returns true if did something. * @param parentsAffected @@ -48,7 +43,7 @@ public class GraphRefactoringUtils { // Find parent id int toParentId = ids.createPathToId(to.parent); if(ids.hasChild(toParentId, to.name)) { - System.err.println("refactor statements from " + from + " to " + to); + LOGGER.info("refactor statements from " + from + " to " + to); //throw new GraphRefactoringException("External reference to " + to + " already exists."); int toId = ids.pathToId(to); int[] statements = tg.statements; @@ -68,7 +63,7 @@ public class GraphRefactoringUtils { if(!(rule.to instanceof PathChild)) throw new GraphRefactoringException("Invalid target URI " + rule.to); if(!moveExternal(tg, ids, rule.from, (PathChild)rule.to, parentsAffected)) - System.err.println("Didn't find " + rule.from); + LOGGER.warn("Didn't find " + rule.from); } } @@ -159,69 +154,4 @@ public class GraphRefactoringUtils { } } - public static void compactify(OldTransferableGraph1 tg, - TIntHashSet removed) { - // Filter removed set - for(Identity id : tg.identities) { - IdentityDefinition def = id.definition; - if(def instanceof Root) - removed.remove(id.resource); - else if(def instanceof External) - removed.remove(((External)def).parent); - else if(def instanceof Internal) - removed.remove(((Internal)def).parent); - else if(def instanceof Optional) - removed.remove(((Optional)def).parent); - } - for(int r : tg.statements) - removed.remove(r); - for(OldValue1 value : tg.values) - removed.remove(value.resource); - - // Compactify - if(!removed.isEmpty()) { - // create map - int resourceCount = tg.resourceCount; - int[] map = new int[resourceCount]; - for(int i=0;i newIdentities = new ArrayList(tg.identities.length); - for(Identity id : tg.identities) { - if(removed.contains(id.resource)) - continue; - else - newIdentities.add(id); - id.resource = map[id.resource]; - IdentityDefinition def = id.definition; - if(def instanceof External) { - External d = (External)def; - d.parent = map[d.parent]; - } - else if(def instanceof Internal) { - External d = (External)def; - d.parent = map[d.parent]; - } - else if(def instanceof Optional) { - External d = (External)def; - d.parent = map[d.parent]; - } - } - tg.identities = newIdentities.toArray(new Identity[newIdentities.size()]); - int[] statements = tg.statements; - for(int i=0;i= 0) - statements[i] = map[r]; - } - for(OldValue1 value : tg.values) - value.resource = map[value.resource]; - tg.resourceCount = resourceCount; - } - } - } diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/PrintReferencesTool.java b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/PrintReferencesTool.java deleted file mode 100644 index d98069227..000000000 --- a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/PrintReferencesTool.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.simantics.graph.refactoring; - -import gnu.trove.map.hash.THashMap; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; - -import org.simantics.databoard.Files; -import org.simantics.graph.query.TransferableGraphConversion; -import org.simantics.graph.representation.old.OldTransferableGraph1; -import org.simantics.graph.store.IdentityStore; -import org.simantics.graph.store.IdentityStore.ConsistsOf; - -public class PrintReferencesTool { - - public static void main(String[] args) throws Exception { - print(new File(args[0])); - } - - public static void print(File input) throws IOException { - OldTransferableGraph1 tg = (OldTransferableGraph1) - Files.readFile(input, OldTransferableGraph1.BINDING); - GraphRefactoringUtils.fixIncorrectRoot(tg.identities); - IdentityStore idStore = TransferableGraphConversion.extractIdentities(tg); - printExternals(idStore, idStore.getRoot(""), 0); - } - - private static void printExternals(IdentityStore idStore, int cur, int indentation) { - THashMap map = idStore.getChildMap(cur); - if(map == null) - return; - ArrayList names = new ArrayList(map.keySet()); - Collections.sort(names); - for(String name : names) { - ConsistsOf co = map.get(name); - if(!idStore.isNewResource(co.child)) { - for(int i=0;i rules = new ArrayList(); - while(true) { - String line = reader.readLine(); - if(line == null) - break; - line = line.trim(); - if(line.isEmpty()) - continue; - String[] parts = line.trim().split(" "); - if(parts.length != 2) - throw new IOException("Invalid mapping spec format. Every non-empty line should contain two URIs."); - - Path from = UriUtils.uriToPath(parts[0]); - Path to = UriUtils.uriToPath(parts[1]); - - rules.add(new MappingRule(from, to)); - } - reader.close(); - - return new MappingSpecification(rules); - } - -} diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/old/OldTransferableGraph1.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/old/OldTransferableGraph1.java deleted file mode 100644 index b68bea31e..000000000 --- a/bundles/org.simantics.graph/src/org/simantics/graph/representation/old/OldTransferableGraph1.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.graph.representation.old; - -import java.util.TreeMap; - -import org.simantics.databoard.Bindings; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.databoard.serialization.Serializer; -import org.simantics.graph.representation.External; -import org.simantics.graph.representation.Identity; -import org.simantics.graph.representation.Internal; -import org.simantics.graph.representation.Root; -import org.simantics.graph.tests.conversion.TransferableGraph0; - - -/** - * Transferable graph datatype. - * See specification. - * @author Hannu Niemist� - * - * @deprecated superceded by {@link TransferableGraph0} - */ -@Deprecated -public class OldTransferableGraph1 { - public static Binding BINDING = Bindings.getBindingUnchecked(OldTransferableGraph1.class); - public static Serializer SERIALIZER = Bindings.getSerializerUnchecked(BINDING); - - public int resourceCount; - public Identity[] identities; - public int[] statements; - public OldValue1[] values; - public TreeMap extensions; - - public OldTransferableGraph1() {} - - public OldTransferableGraph1(int resourceCount, Identity[] identities, - int[] statements, OldValue1[] values) { - this(resourceCount, identities, statements, values, - new TreeMap()); - } - - public OldTransferableGraph1(int resourceCount, Identity[] identities, - int[] statements, OldValue1[] values, TreeMap extensions) { - this.resourceCount = resourceCount; - this.identities = identities; - this.statements = statements; - this.values = values; - this.extensions = extensions; - } - - public void print() { - System.out.println("Identities"); - for(Identity id : identities) { - System.out.print(" " + id.resource + " = "); - if(id.definition instanceof Root) { - Root def = (Root)id.definition; - System.out.println("ROOT(" + def.name + ")"); - } - else if(id.definition instanceof External) { - External def = (External)id.definition; - System.out.println("EXTERNAL(" + def.parent + ", " + def.name + ")"); - } - else if(id.definition instanceof Internal) { - Internal def = (Internal)id.definition; - System.out.println("INTERNAL(" + def.parent + ", " + def.name + ")"); - } - } - System.out.println("Statements:"); - for(int i=0;i inputFiles = new ArrayList(); - List outputFiles = new ArrayList(); - String ext = ".aprosSymbol"; - File outDir = new File(dir,"out"); - if (!outDir.exists()) - outDir.mkdir(); - for (File f: allFiles) { - if (!f.isFile()) - continue; - if (!f.getName().endsWith(ext)) - continue; - inputFiles.add(f); - String outputName = f.getName(); - outputFiles.add(new File(outDir,outputName)); - } - - File mappingSpec = new File(dir, "mappingSpec.txt"); - for (int i = 0; i < inputFiles.size() ; i++) { - - File input = inputFiles.get(i); - File output = outputFiles.get(i); - - System.out.println(input + " -> " + output); - - RefactoringTool.refactor(mappingSpec, input, output); - } - } - -} diff --git a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/mappingSpec.txt b/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/mappingSpec.txt deleted file mode 100644 index d85d332c2..000000000 --- a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/mappingSpec.txt +++ /dev/null @@ -1,6 +0,0 @@ -http://www.apros.fi/AprosStatic-6.0 http://www.apros.fi/Combustion/Configuration-6.0 -http://www.apros.fi/AprosDiagram-6.0/Terminals http://www.apros.fi/Apros-6.1/Terminals -http://www.apros.fi/AprosDiagram-6.0/Relations http://www.apros.fi/Combustion/Diagram-6.0/Relations -http://www.apros.fi/AprosDiagram-6.0/Symbols http://www.apros.fi/Combustion/Diagram-6.0/Symbols -http://www.apros.fi/AprosDiagram-6.0/AnalogSignalOutputRelation http://www.apros.fi/Combustion/Diagram-6.0/AnalogSignalOutputRelation -http://www.apros.fi/AprosDiagram-6.0/BinarySignalOutputRelation http://www.apros.fi/Combustion/Diagram-6.0/BinarySignalOutputRelation \ No newline at end of file diff --git a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/xor5.aprosSymbol b/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/xor5.aprosSymbol deleted file mode 100644 index d005eb22c..000000000 Binary files a/bundles/org.simantics.graph/tests/org/simantics/graph/tests/refactoring/xor5.aprosSymbol and /dev/null differ diff --git a/bundles/org.simantics.modeling/scl/Simantics/Misc.scl b/bundles/org.simantics.modeling/scl/Simantics/Misc.scl index e3c797715..c00c564e8 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/Misc.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/Misc.scl @@ -140,7 +140,7 @@ loop4 testScan testList found = do importJava "java.lang.System" where @JavaName "getProperty" - getSystemProperty :: String -> String + getSystemProperty :: String -> Maybe String importJava "org.simantics.modeling.LifeCycleContext" where data LifeCycleContext diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java index c75f7a941..09f7694dd 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphModuleSourceRepository.java @@ -71,7 +71,7 @@ public enum GraphModuleSourceRepository implements ModuleSourceRepository { } @Override public void removeListener(UpdateListener listener) { - listener = null; + this.listener = null; } @Override public boolean isDisposed() { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/TestScriptExecutor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/TestScriptExecutor.java index ab39d538a..4afeef91c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/TestScriptExecutor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/TestScriptExecutor.java @@ -12,11 +12,17 @@ public class TestScriptExecutor { private final CommandSession session; private final BufferedReader reader; private final SCLReportingHandler handler; + private boolean ignorePrints; public TestScriptExecutor(CommandSession session, BufferedReader reader, SCLReportingHandler handler) { + this(session, reader, handler, false); + } + + public TestScriptExecutor(CommandSession session, BufferedReader reader, SCLReportingHandler handler, boolean ignorePrints) { this.session = session; this.reader = reader; this.handler = handler == null ? SCLReportingHandler.DEFAULT : handler; + this.ignorePrints = ignorePrints; } public void execute() throws IOException { @@ -67,7 +73,8 @@ public class TestScriptExecutor { @Override public void print(String text) { handler.print(text); - actualResponse.append(text).append('\n'); + if (!ignorePrints) + actualResponse.append(text).append('\n'); } @Override diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java index fa5059626..45596c570 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java @@ -2,6 +2,7 @@ package org.simantics.scl.compiler.elaboration.java; import org.cojen.classfile.TypeDesc; import org.osgi.service.component.annotations.Component; +import org.simantics.scl.compiler.commands.CommandSession; import org.simantics.scl.compiler.common.names.Name; import org.simantics.scl.compiler.constants.JavaMethod; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; @@ -48,8 +49,13 @@ public class LoggingModule extends ConcreteModule { @Override public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) { ConcreteModule module = context.getCompilationContext().module; + String identifier; + if (module != null) + identifier = module.getName().replaceAll("/", "."); + else + identifier = CommandSession.class.getName(); apply.set(new ELiteral(javaMethod), new Expression[] { - new EExternalConstant(LoggerFactory.getLogger(module.getName().replaceAll("/", ".")), Logger), + new EExternalConstant(LoggerFactory.getLogger(identifier), Logger), apply.parameters[0] }); return apply; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Switch.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Switch.java index 27f853e02..386199d83 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Switch.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Switch.java @@ -1,6 +1,7 @@ package org.simantics.scl.compiler.internal.codegen.ssa.exits; import java.util.ArrayList; +import java.util.Arrays; import org.objectweb.asm.Label; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; @@ -26,6 +27,8 @@ import org.simantics.scl.compiler.types.TVar; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; +import gnu.trove.map.hash.TIntObjectHashMap; + public class Switch extends SSAExit implements ValRefBinder { ValRef scrutinee; @@ -60,14 +63,19 @@ public class Switch extends SSAExit implements ValRefBinder { int defaultId; for(defaultId=0;defaultId labelMap = new TIntObjectHashMap