diff --git a/org.lflang/src/org/lflang/AttributeUtils.java b/org.lflang/src/org/lflang/AttributeUtils.java index 8e52048fea..ee8cef1bbf 100644 --- a/org.lflang/src/org/lflang/AttributeUtils.java +++ b/org.lflang/src/org/lflang/AttributeUtils.java @@ -42,6 +42,7 @@ import org.lflang.lf.Reactor; import org.lflang.lf.StateVar; import org.lflang.lf.Timer; +import org.lflang.util.StringUtil; /** * A helper class for processing attributes in the AST. @@ -105,7 +106,7 @@ public static String getFirstArgumentValue(Attribute attr) { if (attr == null || attr.getAttrParms().isEmpty()) { return null; } - return attr.getAttrParms().get(0).getValue(); + return StringUtil.removeQuotes(attr.getAttrParms().get(0).getValue()); } /** diff --git a/org.lflang/src/org/lflang/util/StringUtil.java b/org.lflang/src/org/lflang/util/StringUtil.java index 3352796e12..9be21d46e8 100644 --- a/org.lflang/src/org/lflang/util/StringUtil.java +++ b/org.lflang/src/org/lflang/util/StringUtil.java @@ -73,13 +73,23 @@ public static String removeQuotes(String str) { if (str.length() < 2) { return str; } - if (str.startsWith("\"") && str.endsWith("\"") - || str.startsWith("'") && str.endsWith("'")) { + if (hasQuotes(str)) { return str.substring(1, str.length() - 1); } return str; } + /** + * Return true if the given string is surrounded by single or double + * quotes, + */ + public static boolean hasQuotes(String str) { + if (str == null) { + return false; + } + return str.startsWith("\"") && str.endsWith("\"") || str.startsWith("'") && str.endsWith("'"); + } + /** * Intelligently trim the white space in a code block. * diff --git a/org.lflang/src/org/lflang/validation/AttributeSpec.java b/org.lflang/src/org/lflang/validation/AttributeSpec.java index dcd141870b..766621e595 100644 --- a/org.lflang/src/org/lflang/validation/AttributeSpec.java +++ b/org.lflang/src/org/lflang/validation/AttributeSpec.java @@ -36,6 +36,7 @@ import org.lflang.lf.AttrParm; import org.lflang.lf.Attribute; import org.lflang.lf.LfPackage.Literals; +import org.lflang.util.StringUtil; /** * Specification of the structure of an attribute annotation. @@ -155,28 +156,35 @@ private boolean isOptional() { // Check if a parameter has the right type. // Currently only String, Int, Boolean, and Float are supported. public void check(LFValidator validator, AttrParm parm) { - switch(type) { - case STRING: - // nothing to check, all literals are reported as strings - break; - case INT: - if (!ASTUtils.isInteger(parm.getValue())) { - validator.error("Incorrect type: \"" + parm.getName() + "\"" + " should have type Int.", - Literals.ATTRIBUTE__ATTR_NAME); - } - break; - case BOOLEAN: - if (!ASTUtils.isBoolean(parm.getValue())) { - validator.error("Incorrect type: \"" + parm.getName() + "\"" + " should have type Boolean.", - Literals.ATTRIBUTE__ATTR_NAME); - } - break; - case FLOAT: - if (!ASTUtils.isFloat(parm.getValue())) { - validator.error("Incorrect type: \"" + parm.getName() + "\"" + " should have type Float.", - Literals.ATTRIBUTE__ATTR_NAME); - } - break; + switch (type) { + case STRING: + if (!StringUtil.hasQuotes(parm.getValue())) { + validator.error("Incorrect type: \"" + parm.getName() + "\"" + + " should have type String.", + Literals.ATTRIBUTE__ATTR_NAME); + } + break; + case INT: + if (!ASTUtils.isInteger(parm.getValue())) { + validator.error( + "Incorrect type: \"" + parm.getName() + "\"" + " should have type Int.", + Literals.ATTRIBUTE__ATTR_NAME); + } + break; + case BOOLEAN: + if (!ASTUtils.isBoolean(parm.getValue())) { + validator.error( + "Incorrect type: \"" + parm.getName() + "\"" + " should have type Boolean.", + Literals.ATTRIBUTE__ATTR_NAME); + } + break; + case FLOAT: + if (!ASTUtils.isFloat(parm.getValue())) { + validator.error( + "Incorrect type: \"" + parm.getName() + "\"" + " should have type Float.", + Literals.ATTRIBUTE__ATTR_NAME); + } + break; } } }