From: lempinen Date: Wed, 30 Nov 2011 08:10:14 +0000 (+0000) Subject: Changed NoSuchVariableIssue back to StandardIssue X-Git-Tag: simantics-1.6~91 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=89948490b3d47f03c3317029c09364adc9339b96;p=simantics%2Fsysdyn.git Changed NoSuchVariableIssue back to StandardIssue git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@23370 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java index 8c17feb9..e02e5055 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/DependencyFunction.java @@ -13,10 +13,10 @@ package org.simantics.sysdyn.ui.validation; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.Set; -import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.utils.ListUtils; @@ -77,6 +77,7 @@ public class DependencyFunction { ArrayList result = new ArrayList(); + StandardIssue noSuchVariableIssue = null; // Check that all references have corresponding arrows if(references != null && dependencies != null) { for(String reference : references) { @@ -85,7 +86,10 @@ public class DependencyFunction { if((variable = ValidationUtils.reach(graph, component, reference)) != null) { result.add(new StandardIssue(sr.Validations_MissingLinkIssue, component, variable)); } else { - result.add(new NoSuchVariableIssue(sr.Validations_NoSuchVariableIssue, reference, component)); + if(noSuchVariableIssue == null) { + noSuchVariableIssue = new StandardIssue(sr.Validations_NoSuchVariableIssue, component); + result.add(noSuchVariableIssue); + } } } } @@ -129,7 +133,7 @@ public class DependencyFunction { } return result; } - + /** * Unused dependency description * @@ -155,7 +159,9 @@ public class DependencyFunction { } /** - * No such variable description + * No such variable description. Finds all variables that the component refers to and adds + * their names to the issue description. + * * @param graph ReadGraph * @param converter * @param issue Issue @@ -164,9 +170,52 @@ public class DependencyFunction { */ @SCLValue(type = "ReadGraph -> Resource -> Variable -> String") public static String noSuchVariableIssueDescription(ReadGraph graph, Resource converter, Variable issue) throws DatabaseException { - SysdynResource sr = SysdynResource.getInstance(graph); + IssueResource ISSUE = IssueResource.getInstance(graph); Resource issueResource = issue.getRepresents(graph); - String variable = graph.getPossibleRelatedValue(issueResource, sr.Validations_NoSuchVariableIssue_variableName, Bindings.STRING); - return "Refers to variable " + variable + " that does not exist"; + Resource list = graph.getSingleObject(issueResource, ISSUE.DependencyIssueSource2_Issue_HasContexts); + List contexts = ListUtils.toList(graph, list); + Resource component = contexts.get(0); + + // Find all variables that are linked to component with arrows + Set dependencies = ValidationUtils.getDependencies(graph, component); + Set references = null; + + // Find all references in equations of component + try { + references = ValidationUtils.getReferences(graph, component); + } catch (SyntaxErrorException e) { + } catch (UnsupportedCharactersException e) { + } catch (UndefinedExpressionException e) { + } + + + ArrayList result = new ArrayList(); + // Loop all references + if(references != null && dependencies != null) { + for(String reference : references) { + // If dependencies does not contain reference and the reference is not reachable from component, add the name + if(!dependencies.contains(reference) && + ValidationUtils.reach(graph, component, reference) == null) { + result.add(reference); + } + } + } + if(result.size() == 0) { + return "Missing link"; + } else if(result.size() == 1) { + return "Refers to unexisting variable " + result.get(0); + } else { + StringBuilder sb = new StringBuilder(); + sb.append("Refers to unexisting variables "); + Iterator iterator = result.iterator(); + String reference; + while(iterator.hasNext()) { + reference = iterator.next(); + sb.append(reference); + if(iterator.hasNext()) + sb.append(", "); + } + return sb.toString(); + } } } 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 index 8368e095..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/NoSuchVariableIssue.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 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.sysdyn.ui.validation; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Calendar; -import java.util.UUID; - -import org.simantics.databoard.Bindings; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.ListUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.issues.common.StandardIssue; -import org.simantics.issues.ontology.IssueResource; -import org.simantics.layer0.Layer0; -import org.simantics.sysdyn.SysdynResource; - -/** - * Issue class for NoSuchVariableIssues. Extended from StandardIssue to allow - * a string parameter containing the name of the variable in an equation that - * does not correspond to any existing and reachable variable. - * - * @author Teemu Lempinen - * - */ -public class NoSuchVariableIssue extends StandardIssue { - - public String missingVariable; - - public NoSuchVariableIssue(Resource type, String missingVariable, Resource ... contexts) { - super(type, contexts); - this.missingVariable = missingVariable; - } - - /** - * Same as in StandardIssue. Added Validations_NoSuchVariableIssue_variableName. - */ - @Override - public void write(WriteGraph graph, Resource model, Resource source) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - IssueResource IR = IssueResource.getInstance(graph); - Resource issue = graph.newResource(); - graph.claim(issue, L0.InstanceOf, null, type); - graph.claimLiteral(issue, L0.HasName, UUID.randomUUID().toString(), Bindings.STRING); - graph.claim(issue, IR.DependencyIssueSource2_Issue_HasContexts, ListUtils.create(graph, L0.List, contexts)); - DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); - String created = format.format(Calendar.getInstance().getTime()); - graph.claimLiteral(issue, IR.HasCreationTime, created, Bindings.STRING); - graph.claim(source, IR.Manages, issue); - graph.claim(model, L0.ConsistsOf, issue); - - // Modification to standard issue: - graph.claimLiteral(issue, SysdynResource.getInstance(graph).Validations_NoSuchVariableIssue_variableName, this.missingVariable, Bindings.STRING); - } - - @Override - public String toString() { - return Arrays.toString(contexts) + " + missing: " + missingVariable; - } - -}