X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2FresourceFiles%2FResourceFileGenerator.java;fp=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2FresourceFiles%2FResourceFileGenerator.java;h=00271eb2beec06e0923dad7123cfb9f52e5569c1;hp=428dcfcba287f9e9f7e8cd685ba44cd3a64940cd;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFileGenerator.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFileGenerator.java index 428dcfcba..00271eb2b 100644 --- a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFileGenerator.java +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/ResourceFileGenerator.java @@ -1,134 +1,134 @@ -package org.simantics.graph.compiler.internal.resourceFiles; - -import gnu.trove.set.hash.THashSet; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.simantics.databoard.Bindings; -import org.simantics.databoard.adapter.AdaptException; -import org.simantics.databoard.binding.mutable.Variant; -import org.simantics.graph.IResourceFile; -import org.simantics.graph.query.Path; -import org.simantics.graph.query.PathChild; -import org.simantics.graph.query.Paths; -import org.simantics.graph.store.GraphStore; - -public class ResourceFileGenerator { - public static Collection generate(Paths paths, GraphStore store) { - int HasResourceClass = store.identities.pathToId(paths.HasResourceClass); - if(HasResourceClass < 0) - return Collections.emptyList(); - - Collection result = new ArrayList(); - - int resourceCount = store.identities.getResourceCount(); - for(int ontology=0;ontology0) { - packageName = fullClassName.substring(0, p); - className = fullClassName.substring(p+1); - } - else { - packageName = ""; - className = fullClassName; - } - - List resources = new ArrayList(); - findResources(store, - store.identities.pathToId(paths.Deprecated), - store.identities.idToPath(ontology), - ontology, - resources - ); - - ResourceFile file = new ResourceFile(packageName, className, resources); - file.sort(); - return file; - } - - private static void findResources(GraphStore store, - int deprecatedId, - Path root, - int parent, - List resources) { - for(int child : store.identities.getChildren(parent)) { - ResourceRef ref = createResource(root, store.identities.idToPath(child)); - if(!store.statements.getObjects(child, deprecatedId).isEmpty()) - ref.deprecated = true; - resources.add(ref); - findResources(store, deprecatedId, root, child, resources); - } - } - - static THashSet KEYWORDS = new THashSet(); - - static { - for(String s : new String[] { - "abstract", "continue", "for", "new", "switch", - "assert", "default", "goto", "package", "synchronized", - "boolean", "do", "if", "private", "this", - "break", "double", "implements", "protected", "throw", - "byte", "else", "import", "public", "throws", - "case", "enum", "instanceof", "return", "transient", - "catch", "extends", "int", "short", "try", - "char", "final", "interface", "static", "void", - "class", "finally", "long", "strictfp", "volatile", - "const", "float", "native", "super", "while", - "true", "false", "null" - }) - KEYWORDS.add(s); - } - - private static ResourceRef createResource(Path root, Path path) { - StringBuilder b = new StringBuilder(); - javaName(b, root, path); - String javaName = b.toString(); - if(KEYWORDS.contains(javaName)) - javaName = javaName + "_"; - else if(!Character.isJavaIdentifierStart(javaName.charAt(0))) - javaName = "_" + javaName; - return new ResourceRef(javaName, path.toString()); - } - - private static void javaName(StringBuilder b, Path root, Path path) { - if(!root.equals(path)) { - PathChild pc = (PathChild)path; - javaName(b, root, pc.parent); - if(b.length() > 0) - b.append('_'); - for(int i=0;i generate(Paths paths, GraphStore store) { + int HasResourceClass = store.identities.pathToId(paths.HasResourceClass); + if(HasResourceClass < 0) + return Collections.emptyList(); + + Collection result = new ArrayList(); + + int resourceCount = store.identities.getResourceCount(); + for(int ontology=0;ontology0) { + packageName = fullClassName.substring(0, p); + className = fullClassName.substring(p+1); + } + else { + packageName = ""; + className = fullClassName; + } + + List resources = new ArrayList(); + findResources(store, + store.identities.pathToId(paths.Deprecated), + store.identities.idToPath(ontology), + ontology, + resources + ); + + ResourceFile file = new ResourceFile(packageName, className, resources); + file.sort(); + return file; + } + + private static void findResources(GraphStore store, + int deprecatedId, + Path root, + int parent, + List resources) { + for(int child : store.identities.getChildren(parent)) { + ResourceRef ref = createResource(root, store.identities.idToPath(child)); + if(!store.statements.getObjects(child, deprecatedId).isEmpty()) + ref.deprecated = true; + resources.add(ref); + findResources(store, deprecatedId, root, child, resources); + } + } + + static THashSet KEYWORDS = new THashSet(); + + static { + for(String s : new String[] { + "abstract", "continue", "for", "new", "switch", + "assert", "default", "goto", "package", "synchronized", + "boolean", "do", "if", "private", "this", + "break", "double", "implements", "protected", "throw", + "byte", "else", "import", "public", "throws", + "case", "enum", "instanceof", "return", "transient", + "catch", "extends", "int", "short", "try", + "char", "final", "interface", "static", "void", + "class", "finally", "long", "strictfp", "volatile", + "const", "float", "native", "super", "while", + "true", "false", "null" + }) + KEYWORDS.add(s); + } + + private static ResourceRef createResource(Path root, Path path) { + StringBuilder b = new StringBuilder(); + javaName(b, root, path); + String javaName = b.toString(); + if(KEYWORDS.contains(javaName)) + javaName = javaName + "_"; + else if(!Character.isJavaIdentifierStart(javaName.charAt(0))) + javaName = "_" + javaName; + return new ResourceRef(javaName, path.toString()); + } + + private static void javaName(StringBuilder b, Path root, Path path) { + if(!root.equals(path)) { + PathChild pc = (PathChild)path; + javaName(b, root, pc.parent); + if(b.length() > 0) + b.append('_'); + for(int i=0;i