]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Changed NoSuchVariableIssue back to StandardIssue
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 30 Nov 2011 08:10:14 +0000 (08:10 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 30 Nov 2011 08:10:14 +0000 (08:10 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23370 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableIssue.java [deleted file]

index 8c17feb9c3d83c9ca157a361e6e7d3ca4202d571..e02e505554396fc52bc58e2cb61ced3a4a124632 100644 (file)
@@ -13,10 +13,10 @@ package org.simantics.sysdyn.ui.validation;
 \r
 import java.util.ArrayList;\r
 import java.util.Collections;\r
+import java.util.Iterator;\r
 import java.util.List;\r
 import java.util.Set;\r
 \r
-import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.utils.ListUtils;\r
@@ -77,6 +77,7 @@ public class DependencyFunction {
         ArrayList<Issue> result = new ArrayList<Issue>();\r
 \r
 \r
+        StandardIssue noSuchVariableIssue = null;\r
         // Check that all references have corresponding arrows\r
         if(references != null && dependencies != null) {\r
             for(String reference : references) {\r
@@ -85,7 +86,10 @@ public class DependencyFunction {
                     if((variable = ValidationUtils.reach(graph, component, reference)) != null) {\r
                         result.add(new StandardIssue(sr.Validations_MissingLinkIssue, component, variable));\r
                     } else {\r
-                        result.add(new NoSuchVariableIssue(sr.Validations_NoSuchVariableIssue, reference, component));\r
+                        if(noSuchVariableIssue == null) {\r
+                            noSuchVariableIssue = new StandardIssue(sr.Validations_NoSuchVariableIssue, component);\r
+                            result.add(noSuchVariableIssue);\r
+                        }\r
                     }\r
                 } \r
             }\r
@@ -129,7 +133,7 @@ public class DependencyFunction {
         }\r
         return result;\r
     }\r
-    \r
+\r
     /**\r
      * Unused dependency description\r
      *  \r
@@ -155,7 +159,9 @@ public class DependencyFunction {
     }\r
 \r
     /**\r
-     * No such variable description\r
+     * No such variable description. Finds all variables that the component refers to and adds\r
+     * their names to the issue description.\r
+     * \r
      * @param graph ReadGraph\r
      * @param converter\r
      * @param issue Issue\r
@@ -164,9 +170,52 @@ public class DependencyFunction {
      */\r
     @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
     public static String noSuchVariableIssueDescription(ReadGraph graph, Resource converter, Variable issue) throws DatabaseException {\r
-        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        IssueResource ISSUE = IssueResource.getInstance(graph);\r
         Resource issueResource = issue.getRepresents(graph);\r
-        String variable = graph.getPossibleRelatedValue(issueResource, sr.Validations_NoSuchVariableIssue_variableName, Bindings.STRING);\r
-        return "Refers to variable " + variable + " that does not exist";\r
+        Resource list = graph.getSingleObject(issueResource, ISSUE.DependencyIssueSource2_Issue_HasContexts);\r
+        List<Resource> contexts = ListUtils.toList(graph, list);\r
+        Resource component = contexts.get(0);\r
+\r
+        // Find all variables that are linked to component with arrows\r
+        Set<String> dependencies = ValidationUtils.getDependencies(graph, component);\r
+        Set<String> references = null;\r
+\r
+        // Find all references in equations of component\r
+        try {\r
+            references = ValidationUtils.getReferences(graph, component);\r
+        } catch (SyntaxErrorException e) {\r
+        } catch (UnsupportedCharactersException e) {\r
+        } catch (UndefinedExpressionException e) {\r
+        }\r
+\r
+\r
+        ArrayList<String> result = new ArrayList<String>();\r
+        // Loop all references\r
+        if(references != null && dependencies != null) {\r
+            for(String reference : references) {\r
+                // If dependencies does not contain reference and the reference is not reachable from component, add the name\r
+                if(!dependencies.contains(reference) &&\r
+                        ValidationUtils.reach(graph, component, reference) == null) {\r
+                    result.add(reference);\r
+                } \r
+            }\r
+        }\r
+        if(result.size() == 0) {\r
+            return "Missing link";\r
+        } else if(result.size() == 1) {\r
+            return "Refers to unexisting variable " + result.get(0);\r
+        } else {\r
+            StringBuilder sb = new StringBuilder();\r
+            sb.append("Refers to unexisting variables ");\r
+            Iterator<String> iterator = result.iterator();\r
+            String reference;\r
+            while(iterator.hasNext()) {\r
+                reference = iterator.next();\r
+                sb.append(reference);\r
+                if(iterator.hasNext())\r
+                    sb.append(", ");\r
+            }\r
+            return sb.toString();\r
+        }\r
     }\r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableIssue.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableIssue.java
deleted file mode 100644 (file)
index 8368e09..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.ui.validation;\r
-\r
-import java.text.DateFormat;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Arrays;\r
-import java.util.Calendar;\r
-import java.util.UUID;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.ListUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.issues.common.StandardIssue;\r
-import org.simantics.issues.ontology.IssueResource;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.sysdyn.SysdynResource;\r
-\r
-/**\r
- * Issue class for NoSuchVariableIssues. Extended from StandardIssue to allow\r
- * a string parameter containing the name of the variable in an equation that\r
- * does not correspond to any existing and reachable variable.\r
- * \r
- * @author Teemu Lempinen\r
- *\r
- */\r
-public class NoSuchVariableIssue extends StandardIssue {\r
-\r
-    public String missingVariable;\r
-    \r
-    public NoSuchVariableIssue(Resource type, String missingVariable, Resource ... contexts) {\r
-        super(type, contexts);\r
-        this.missingVariable = missingVariable;\r
-    }\r
-    \r
-    /**\r
-     * Same as in StandardIssue. Added Validations_NoSuchVariableIssue_variableName.\r
-     */\r
-    @Override\r
-    public void write(WriteGraph graph, Resource model, Resource source) throws DatabaseException {\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
-        IssueResource IR = IssueResource.getInstance(graph);\r
-        Resource issue = graph.newResource();\r
-        graph.claim(issue, L0.InstanceOf, null, type);\r
-        graph.claimLiteral(issue, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING);\r
-        graph.claim(issue, IR.DependencyIssueSource2_Issue_HasContexts, ListUtils.create(graph, L0.List, contexts));\r
-        DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");\r
-        String created = format.format(Calendar.getInstance().getTime());\r
-        graph.claimLiteral(issue, IR.HasCreationTime, created, Bindings.STRING);\r
-        graph.claim(source, IR.Manages, issue);\r
-        graph.claim(model, L0.ConsistsOf, issue);\r
-        \r
-        // Modification to standard issue:\r
-        graph.claimLiteral(issue, SysdynResource.getInstance(graph).Validations_NoSuchVariableIssue_variableName, this.missingVariable, Bindings.STRING);\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return Arrays.toString(contexts) +  " + missing: " + missingVariable; \r
-    }\r
-\r
-}\r