From 931cbf415850766945c46a446a2ab19f00a35194 Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 22 Oct 2010 13:02:02 +0000 Subject: [PATCH] Syntax error messages for lookup tables, when the syntax is correct but dimensions are not. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18510 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../widgets/expressions/ExpressionField.java | 18 +++++++++++++----- .../widgets/expressions/ExpressionUtils.java | 2 +- .../expressions/WithLookupExpression.java | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java index 7eed11e4..aac8c3b9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java @@ -137,18 +137,26 @@ public class ExpressionField extends Composite { } } - public void setSyntaxError(Token token){ + public void setSyntaxError(Token token, String message){ + setSyntaxError(token.image, message, token.beginLine, token.beginColumn, token.endLine, token.endColumn); + } + + public void setSyntaxError(org.simantics.sysdyn.tableParser.Token token, String message){ + setSyntaxError(token.image, message, token.beginLine, token.beginColumn, token.endLine, token.endColumn); + } + + public void setSyntaxError(String image, String message, int beginLine, int beginColumn, int endLine, int endColumn) { int start = 0; int offset = this._document.getLength(); - if(token.image != null && this._document.getLength() > 0) { + if(image != null && this._document.getLength() > 0) { try { - start = this._document.getLineOffset(token.beginLine - 1) + token.beginColumn - 1; - offset = this._document.getLineOffset(token.endLine - 1) + token.endColumn - start; + start = this._document.getLineOffset(beginLine - 1) + beginColumn - 1; + offset = this._document.getLineOffset(endLine - 1) + endColumn - start; } catch (BadLocationException e) { e.printStackTrace(); } } - setSyntaxError(start, offset, "MissingLink", "Syntax error"); + setSyntaxError(start, offset, "MissingLink", message == null ? "Syntax Error" : message); } public void setSyntaxError(int start, int offset, String type, String text) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionUtils.java index 54aa4ae5..cbf98765 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionUtils.java @@ -72,7 +72,7 @@ public class ExpressionUtils { for(String t : cr.keySet()) variables.add(t); } catch (ParseException e1) { - ef.setSyntaxError(e1.currentToken); + ef.setSyntaxError(e1.currentToken, "Syntax Error"); } catch (TokenMgrError err) { ef.setSyntaxError(0, textString.length(), "MissingLink", "Expression contains unsupported characters"); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java index e7e4d2bd..96eecd76 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java @@ -372,7 +372,8 @@ public class WithLookupExpression implements IExpression { Double.parseDouble(yTokens.get(i).image))); } } catch (ParseException e1) { -// e1.printStackTrace(); + this.lookup.setSyntaxError(e1.currentToken, "Syntax Error"); + System.out.println("MESSAGE: " + e1.getMessage()); return; } -- 2.47.1