X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Frefactoring%2FGraphRefactoringUtils.java;h=90b134e33762b5f991baa5288a2974906f2bad7b;hp=1b6251266aa832f69694ee38f0d8d60bd6b786b3;hb=1cc487c3f6cf4b46b1fdd727183a9483e3bc05bb;hpb=969bd23cab98a79ca9101af33334000879fb60c5 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 1b6251266..90b134e33 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,210 +1,173 @@ -package org.simantics.graph.refactoring; - -import java.util.ArrayList; - -import org.simantics.graph.query.Path; -import org.simantics.graph.query.PathChild; -import org.simantics.graph.query.TransferableGraphConversion; -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.IdentityStore; - -import gnu.trove.list.array.TIntArrayList; -import gnu.trove.set.hash.TIntHashSet; - -public class GraphRefactoringUtils { - - /** - * Moves an external resource. Returns true if did something. - * @param parentsAffected - */ - public static boolean moveExternal(TransferableGraph1 tg, IdentityStore ids, Path from, PathChild to, TIntHashSet parentsAffected) throws GraphRefactoringException { - // Find from id - int fromId = ids.pathToId(from); - if(fromId < 0) - return false; - if(ids.isNewResource(fromId)) - throw new GraphRefactoringException("Cannot move internal resource " + from + "."); - - // Remove old identity - int parentId = ids.removeIdentity(fromId); - if(parentId >= 0) - parentsAffected.add(parentId); - - // Find parent id - int toParentId = ids.createPathToId(to.parent); - if(ids.hasChild(toParentId, to.name)) { - System.err.println("refactor statements from " + from + " to " + to); - //throw new GraphRefactoringException("External reference to " + to + " already exists."); - int toId = ids.pathToId(to); - int[] statements = tg.statements; - 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; - } - } - -} +package org.simantics.graph.refactoring; + +import java.util.Arrays; + +import org.simantics.databoard.util.URIStringUtils; +import org.simantics.graph.query.Path; +import org.simantics.graph.query.PathChild; +import org.simantics.graph.query.TransferableGraphConversion; +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.Internal; +import org.simantics.graph.representation.Root; +import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.graph.representation.TransferableGraphUtils; +import org.simantics.graph.store.GraphStore; +import org.simantics.graph.store.IdentityStore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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 + */ + public static boolean moveExternal(TransferableGraph1 tg, IdentityStore ids, Path from, PathChild to, TIntHashSet parentsAffected) throws GraphRefactoringException { + // Find from id + int fromId = ids.pathToId(from); + if(fromId < 0) + return false; + if(ids.isNewResource(fromId)) + throw new GraphRefactoringException("Cannot move internal resource " + from + "."); + + // Remove old identity + int parentId = ids.removeIdentity(fromId); + if(parentId >= 0) + parentsAffected.add(parentId); + + // Find parent id + int toParentId = ids.createPathToId(to.parent); + if(ids.hasChild(toParentId, to.name)) { + 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; + for(int i=0;i