diff options
Diffstat (limited to 'plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice')
7 files changed, 315 insertions, 128 deletions
diff --git a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/Config.xtext b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/Config.xtext index 7a1848321..dbe2a9e34 100644 --- a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/Config.xtext +++ b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/Config.xtext @@ -13,18 +13,29 @@ grammar org.eclipse.etrice.core.Config with org.eclipse.xtext.common.Terminals generate config "http://www.eclipse.org/etrice/core/Config" import "http://www.eclipse.org/emf/2002/Ecore" as ecore -import 'platform:/resource/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/Room.ecore' as room +import "platform:/resource/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/Room.ecore" as room -/* - * Postprocessor: - * getActor(Class|Instance)Config() - */ ConfigModel: imports+=Import* configElements+=ConfigElement*; ConfigElement: - ActorClassConfig | ActorInstanceConfig | ProtocolClassConfig; + SubSystemConfig | ActorClassConfig | ActorInstanceConfig | ProtocolClassConfig; + +SubSystemConfig: + 'SubSystemConfig' subSystem=[room::SubSystemClass] '{' + dynConfig=DynamicConfig + '}'; + +DynamicConfig: + 'dynamic configuration' '{' + ( + (('file path' filePath=STRING) | + (('user import' userCode1=STRING) + ('user constructor' userCode2=STRING))) & + ('polling timer [ms]' polling=INT)? + ) + '}'; /* * Validation: @@ -32,7 +43,7 @@ ConfigElement: */ ActorClassConfig: 'ActorClassConfig' actor=[room::ActorClass|FQN] '{' - attributes+=AttrClassConfig* + (attributes+=AttrClassConfig)* '}'; /* @@ -44,24 +55,28 @@ ActorClassConfig: */ ActorInstanceConfig: 'ActorInstanceConfig' root=[room::SubSystemClass|FQN] '/' path=RefPath '{' - attributes+=AttrInstanceConfig* - ports+=PortInstanceConfig* + ( + (attributes+=AttrInstanceConfig)* & + (ports+=PortInstanceConfig)* + ) '}'; ProtocolClassConfig: 'ProtocolClassConfig' protocol=[room::ProtocolClass|FQN] '{' - (('regular' regular=PortClassConfig)? & - ('conjugate' conjugated=PortClassConfig)?) + ( + ('regular' regular=PortClassConfig)? & + ('conjugate' conjugated=PortClassConfig)? + ) '}'; PortClassConfig: {PortClassConfig} 'Port' '{' - attributes+=AttrClassConfig* + (attributes+=AttrClassConfig)* '}'; PortInstanceConfig: 'InterfaceItem' item=[room::InterfaceItem|ID] '{' - attributes+=AttrInstanceConfig* + (attributes+=AttrInstanceConfig)* '}'; /* @@ -83,12 +98,20 @@ AttrConfig: */ AttrClassConfig: 'Attr' attribute=[room::Attribute] ('=' value=LiteralArray)? ('{' - (('min' '=' min=NumberLiteral)? & - ('max' '=' max=NumberLiteral)?) + ( + ('min' '=' min=NumberLiteral)? + ('max' '=' max=NumberLiteral)? + (attributes+=AttrClassConfig)* + ) '}')?; AttrInstanceConfig: - 'Attr' attribute=[room::Attribute] ('=' value=LiteralArray)?; + 'Attr' attribute=[room::Attribute] ('=' value=LiteralArray)? ('{' + ( + (dynConfig?='dynamic configuration' (readOnly?='read' | 'write'))? + (attributes+=AttrInstanceConfig*) + ) + '}')?; /* * Proposal: @@ -127,10 +150,9 @@ FQN: // LiteralArray = BooleanLiteral+|NumberLiteral+ // LiteralArray = StringLiteral LiteralArray: - literals+=Literal (',' literals+=Literal)* -; + literals+=Literal (',' literals+=Literal)*; -// Value Types for Attributes + // Value Types for Attributes Literal: BooleanLiteral | NumberLiteral | @@ -151,7 +173,7 @@ IntLiteral: StringLiteral: {StringLiteral} value=STRING; -Integer returns ecore::EInt: +Integer returns ecore::ELong: SignedInteger | Hexadecimal; SignedInteger hidden(): @@ -173,8 +195,10 @@ DecimalDot hidden(): ('+' | '-')? INT '.'; DecimalExp hidden(): - ('+' | '-')? INT '.' INT ID ('+' | '-')? INT; - //DecimalPosExp hidden(): -// ('+' | '-')? INT '.' INT ID; + ('+' | '-')? INT '.' INT EXP; + +terminal EXP: + ('e'|'E') ('+' | '-')? ('0'..'9')+; + terminal HEX: ('0x' | '0X') ('0'..'9' | 'a'..'f' | 'A'..'F')+; diff --git a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigPostprocessor.ext b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigPostprocessor.ext index 1cb017efa..d785f05db 100644 --- a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigPostprocessor.ext +++ b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigPostprocessor.ext @@ -52,6 +52,15 @@ process(EClass this) : if(element instanceof ProtocolClassConfig)
list.add((ProtocolClassConfig) element);
return list;'
+ )->addOperation(
+ "getSubSystemConfigs",
+ ePackage.getEClassifier("SubSystemConfig"),
+ -1,
+ 'EList<SubSystemConfig> list = new org.eclipse.emf.common.util.BasicEList<SubSystemConfig>();
+ for(ConfigElement element : this.getConfigElements())
+ if(element instanceof SubSystemConfig)
+ list.add((SubSystemConfig) element);
+ return list;'
))
default: null
}
diff --git a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/config/util/ConfigUtil.java b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/config/util/ConfigUtil.java index c2f2bc3a3..4eb476223 100644 --- a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/config/util/ConfigUtil.java +++ b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/config/util/ConfigUtil.java @@ -16,10 +16,7 @@ import java.util.ArrayList; import java.util.Iterator;
import java.util.List;
-import org.eclipse.etrice.core.config.IntLiteral;
-import org.eclipse.etrice.core.config.NumberLiteral;
import org.eclipse.etrice.core.config.PortInstanceConfig;
-import org.eclipse.etrice.core.config.RealLiteral;
import org.eclipse.etrice.core.config.RefPath;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.ActorContainerClass;
@@ -35,7 +32,6 @@ import org.eclipse.etrice.core.room.PortClass; import org.eclipse.etrice.core.room.PrimitiveType;
import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.SAPRef;
-import org.eclipse.etrice.core.room.SPPRef;
import org.eclipse.etrice.core.room.SubSystemClass;
import org.eclipse.etrice.core.room.util.RoomHelpers;
@@ -55,11 +51,35 @@ public class ConfigUtil { return null;
}
- public static ActorContainerClass resolve(ActorContainerClass root,
+ public static ActorClass resolve(ActorContainerClass root,
RefPath path) {
- if (path == null)
- return root;
+ if(path.getRefs().isEmpty())
+ return null;
+
+ ActorContainerClass result = root;
+ for (String ref : path.getRefs()) {
+ ActorRef match = null;
+ for (ActorContainerRef actor : RoomHelpers.getRefs(result, true)) {
+ if (actor instanceof ActorRef && actor.getName().equals(ref)) {
+ match = (ActorRef) actor;
+ break;
+ }
+ }
+ if (match == null)
+ return null;
+ result = match.getType();
+ }
+
+ return (ActorClass) result;
+ }
+
+ public static ActorRef getLastActorRef(ActorContainerClass root,
+ RefPath path) {
+ if(path.getRefs().isEmpty())
+ return null;
+
+ ActorRef lastMatch = null;
ActorContainerClass result = root;
for (String ref : path.getRefs()) {
ActorRef match = null;
@@ -73,9 +93,10 @@ public class ConfigUtil { if (match == null)
return null;
result = match.getType();
+ lastMatch = match;
}
- return result;
+ return lastMatch;
}
/**
@@ -125,18 +146,6 @@ public class ConfigUtil { return null;
}
- public static double literalToDouble(NumberLiteral number) {
- double dValue = 0;
- if (number instanceof IntLiteral)
- dValue = ((IntLiteral) number).getValue();
- else if (number instanceof RealLiteral)
- dValue = ((RealLiteral) number).getValue();
- else
- assert (false) : "unexpected type";
-
- return dValue;
- }
-
public static PortClass getPortClass(PortInstanceConfig config) {
InterfaceItem item = config.getItem();
PortClass portClass = null;
diff --git a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/converter/ConfigValueConverterService.java b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/converter/ConfigValueConverterService.java index 68634f13b..c88c8b7d0 100644 --- a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/converter/ConfigValueConverterService.java +++ b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/converter/ConfigValueConverterService.java @@ -16,14 +16,14 @@ import org.eclipse.xtext.conversion.IValueConverter; import org.eclipse.xtext.conversion.ValueConverter;
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
-import org.eclipse.xtext.conversion.impl.INTValueConverter;
import org.eclipse.xtext.nodemodel.INode;
+import org.eclipse.xtext.util.Strings;
public class ConfigValueConverterService extends DefaultTerminalConverters {
@ValueConverter(rule = "Integer")
- public IValueConverter<Integer> getIntegerConverter() {
- return new IntegerConverter();
+ public IValueConverter<Long> getLongConverter() {
+ return new LongConverter();
}
@ValueConverter(rule = "Real")
@@ -31,23 +31,31 @@ public class ConfigValueConverterService extends DefaultTerminalConverters { return new DoubleConverter();
}
- public class IntegerConverter extends INTValueConverter {
+ public class LongConverter extends AbstractLexerBasedConverter<Long> {
@Override
- public Integer toValue(String string, INode node)
+ public Long toValue(String string, INode node)
throws ValueConverterException {
+ if (Strings.isEmpty(string))
+ throw new ValueConverterException(
+ "Couldn't convert empty string to integer.", node, null);
if (string.startsWith("0x") || string.startsWith("0X")) {
try {
- int value = Integer.parseInt(string.substring(2), 16);
+ long value = Long.parseLong(string.substring(2), 16);
return value;
} catch (NumberFormatException e) {
throw new ValueConverterException("Couldn't convert '"
+ string + "' to hex.", node, e);
}
- } else if (string.startsWith("+"))
- return toValue(string.substring(1), node);
- else
- return super.toValue(string, node);
+ } else {
+ try {
+ long value = Long.parseLong(string);
+ return value;
+ } catch (NumberFormatException e) {
+ throw new ValueConverterException("Couldn't convert '"
+ + string + "' to integer.", node, e);
+ }
+ }
}
}
@@ -56,12 +64,15 @@ public class ConfigValueConverterService extends DefaultTerminalConverters { @Override
public Double toValue(String string, INode node)
throws ValueConverterException {
+ if (Strings.isEmpty(string))
+ throw new ValueConverterException(
+ "Couldn't convert empty string to double.", node, null);
try {
double value = Double.parseDouble(string);
return value;
} catch (NumberFormatException e) {
throw new ValueConverterException("Couldn't convert '" + string
- + "' to double.", node, null);
+ + "' to double.", node, e);
}
}
diff --git a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/formatting/ConfigFormatter.java b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/formatting/ConfigFormatter.java index 0502260cf..a45a48cac 100644 --- a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/formatting/ConfigFormatter.java +++ b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/formatting/ConfigFormatter.java @@ -26,7 +26,7 @@ public class ConfigFormatter extends AbstractDeclarativeFormatter { // general c.setAutoLinewrap(120); - c.setLinewrap(2).before(f.getSL_COMMENTRule()); + c.setLinewrap(1).before(f.getSL_COMMENTRule()); c.setLinewrap(2).before(f.getML_COMMENTRule()); for (Pair<Keyword, Keyword> pair : f.findKeywordPairs("{", "}")) { diff --git a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/scoping/ConfigScopeProvider.java b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/scoping/ConfigScopeProvider.java index 1d62c848f..b8fdae79b 100644 --- a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/scoping/ConfigScopeProvider.java +++ b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/scoping/ConfigScopeProvider.java @@ -23,8 +23,8 @@ import org.eclipse.etrice.core.config.PortInstanceConfig; import org.eclipse.etrice.core.config.ProtocolClassConfig; import org.eclipse.etrice.core.config.util.ConfigUtil; import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.core.room.ActorContainerClass; import org.eclipse.etrice.core.room.Attribute; +import org.eclipse.etrice.core.room.DataClass; import org.eclipse.etrice.core.room.InterfaceItem; import org.eclipse.etrice.core.room.PortClass; import org.eclipse.etrice.core.room.SubSystemClass; @@ -52,10 +52,10 @@ public class ConfigScopeProvider extends AbstractDeclarativeScopeProvider { .eContainer(); SubSystemClass subsystem = actorConfig.getRoot(); if (subsystem != null) { - ActorContainerClass acc = ConfigUtil.resolve(subsystem, - actorConfig.getPath()); + ActorClass ac = ConfigUtil + .resolve(subsystem, actorConfig.getPath()); for (InterfaceItem item : ConfigUtil.getConfigurableInterfaceItems( - acc, true)) + ac, true)) scopes.add(EObjectDescription.create(item.getName(), item)); } @@ -65,7 +65,9 @@ public class ConfigScopeProvider extends AbstractDeclarativeScopeProvider { public IScope scope_AttrConfig_attribute(AttrConfig ctx, EReference ref) { final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>(); - if (ctx.eContainer() instanceof ActorClassConfig) + if (ctx.eContainer() instanceof AttrConfig) + collectAttributes((AttrConfig) ctx.eContainer(), scopes); + else if (ctx.eContainer() instanceof ActorClassConfig) collectAttributes((ActorClassConfig) ctx.eContainer(), scopes); else if (ctx.eContainer() instanceof ActorInstanceConfig) collectAttributes((ActorInstanceConfig) ctx.eContainer(), scopes); @@ -76,6 +78,17 @@ public class ConfigScopeProvider extends AbstractDeclarativeScopeProvider { return new SimpleScope(IScope.NULLSCOPE, scopes); } + private void collectAttributes(AttrConfig config, + List<IEObjectDescription> scopes) { + if (config.getAttribute().getRefType().getType() instanceof DataClass) { + DataClass dc = (DataClass) config.getAttribute().getRefType() + .getType(); + for (Attribute att : RoomHelpers.getAllAttributes(dc)) { + scopes.add(EObjectDescription.create(att.getName(), att)); + } + } + } + private void collectAttributes(ActorClassConfig config, List<IEObjectDescription> scopes) { ActorClass actor = config.getActor(); @@ -90,13 +103,9 @@ public class ConfigScopeProvider extends AbstractDeclarativeScopeProvider { List<IEObjectDescription> scopes) { SubSystemClass subsystem = config.getRoot(); if (subsystem != null) { - ActorContainerClass actor = ConfigUtil.resolve(subsystem, - config.getPath()); - if (actor instanceof ActorClass) { - for (Attribute att : RoomHelpers - .getAllAttributes((ActorClass) actor)) { - scopes.add(EObjectDescription.create(att.getName(), att)); - } + ActorClass actor = ConfigUtil.resolve(subsystem, config.getPath()); + for (Attribute att : RoomHelpers.getAllAttributes(actor)) { + scopes.add(EObjectDescription.create(att.getName(), att)); } } } diff --git a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/validation/ConfigJavaValidator.java b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/validation/ConfigJavaValidator.java index 165a94271..87d9aa487 100644 --- a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/validation/ConfigJavaValidator.java +++ b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/validation/ConfigJavaValidator.java @@ -18,6 +18,7 @@ import java.util.Set; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.etrice.core.config.ActorClassConfig; import org.eclipse.etrice.core.config.ActorInstanceConfig; import org.eclipse.etrice.core.config.AttrClassConfig; @@ -35,19 +36,26 @@ import org.eclipse.etrice.core.config.ProtocolClassConfig; import org.eclipse.etrice.core.config.RealLiteral; import org.eclipse.etrice.core.config.RefPath; import org.eclipse.etrice.core.config.StringLiteral; +import org.eclipse.etrice.core.config.SubSystemConfig; import org.eclipse.etrice.core.config.util.ConfigUtil; +import org.eclipse.etrice.core.converter.ConfigValueConverterService; import org.eclipse.etrice.core.room.ActorClass; import org.eclipse.etrice.core.room.ActorContainerClass; +import org.eclipse.etrice.core.room.ActorRef; import org.eclipse.etrice.core.room.Attribute; import org.eclipse.etrice.core.room.DataType; import org.eclipse.etrice.core.room.InterfaceItem; import org.eclipse.etrice.core.room.LiteralType; import org.eclipse.etrice.core.room.PrimitiveType; import org.eclipse.etrice.core.room.ProtocolClass; +import org.eclipse.etrice.core.room.SubSystemClass; +import org.eclipse.xtext.conversion.ValueConverterException; import org.eclipse.xtext.validation.Check; public class ConfigJavaValidator extends AbstractConfigJavaValidator { + private ConfigValueConverterService converter = new ConfigValueConverterService(); + @Check public void checkConfigModel(ConfigModel model) { // duplicate actor class config check @@ -88,6 +96,9 @@ public class ConfigJavaValidator extends AbstractConfigJavaValidator { @Check public void checkActorClassConfig(ActorClassConfig config) { + if (config.getActor().isAbstract()) + error("abstract actor classes not supported", + ConfigPackage.Literals.ACTOR_CLASS_CONFIG__ACTOR); checkDuplicateAttributes(config.getAttributes(), ConfigPackage.Literals.ACTOR_CLASS_CONFIG__ATTRIBUTES); @@ -102,8 +113,17 @@ public class ConfigJavaValidator extends AbstractConfigJavaValidator { String invalidSegment = ConfigUtil.checkPath(root, path); if (invalidSegment != null) error("no match for segment '" + invalidSegment + "'", - ConfigPackage.eINSTANCE - .getActorInstanceConfig_Path()); + ConfigPackage.Literals.ACTOR_INSTANCE_CONFIG__PATH); + else { + ActorRef aRef = ConfigUtil.getLastActorRef(root, path); + if (aRef != null) { + if (aRef.getSize() > 1) + error("no arrays of actor references supported", + ConfigPackage.Literals.ACTOR_INSTANCE_CONFIG__PATH); + } else + error("invalid actor reference", + ConfigPackage.Literals.ACTOR_INSTANCE_CONFIG__PATH); + } } } // duplicate port instance config check @@ -148,15 +168,21 @@ public class ConfigJavaValidator extends AbstractConfigJavaValidator { @Check public void checkAttrConfig(AttrConfig config) { - Attribute attr = config.getAttribute(); - if (attr == null) + Attribute a = config.getAttribute(); + if (a == null) return; - DataType type = attr.getRefType().getType(); + DataType type = a.getRefType().getType(); if (type instanceof PrimitiveType) { PrimitiveType primitive = (PrimitiveType) type; - checkAttrConfigValue(primitive, config); + } else if (type instanceof DataType) { + if (config.getValue() != null) + error("not available", + ConfigPackage.Literals.ATTR_CONFIG__VALUE); + if (a.getSize() > 0) + error("DataClass arrays not supported", + ConfigPackage.Literals.ATTR_CLASS_CONFIG__ATTRIBUTES); } } @@ -177,6 +203,32 @@ public class ConfigJavaValidator extends AbstractConfigJavaValidator { @Check public void checkAttrInstanceConfig(AttrInstanceConfig config) { + Attribute attr = config.getAttribute(); + if (attr == null) + return; + + EStructuralFeature feature = ConfigPackage.eINSTANCE + .getAttrInstanceConfig_DynConfig(); + if (config.isDynConfig()) { + if (!(config.eContainer() instanceof ActorInstanceConfig)) + error("dynamic configuration only at root attributes", feature); + if (config.eContainer() instanceof ActorInstanceConfig) { + SubSystemClass ssc = ((ActorInstanceConfig) config.eContainer()) + .getRoot(); + ConfigModel model = getConfigModel(config); + boolean found = false; + for (SubSystemConfig c : model.getSubSystemConfigs()) + if (c.getSubSystem().equals(ssc)) { + if (c.getDynConfig() == null) + error("no source for dynamic config in SubSystemConfig", + feature); + found = true; + } + if (!found) + error("no SubSystemConfig found", feature); + + } + } } @@ -191,10 +243,13 @@ public class ConfigJavaValidator extends AbstractConfigJavaValidator { LiteralType type = primitive.getType(); Attribute attribute = config.getAttribute(); int attrMult = (attribute.getSize() > 0) ? attribute.getSize() : 1; - if (values.size() > attrMult) - error("too many values, multiplicity is " + attrMult, valueRef); - if (values.size() > 1 && values.size() < attrMult) - error("not enough values, multiplicity is " + attrMult, valueRef); + if (type != LiteralType.CHAR) { + if (values.size() > attrMult) + error("too many values, multiplicity is " + attrMult, valueRef); + if (values.size() > 1 && values.size() < attrMult) + error("not enough values, multiplicity is " + attrMult, + valueRef); + } // type check for (Literal value : values) { switch (type) { @@ -217,7 +272,8 @@ public class ConfigJavaValidator extends AbstractConfigJavaValidator { if (values.size() > 1) error("multiplicity must be one", valueRef); StringLiteral strValue = (StringLiteral) value; - if (attrMult < strValue.getValue().length()) + if (attribute.getSize() > 0 + && attrMult < strValue.getValue().length()) error("too many characters - maximal length is " + attrMult, valueRef); } @@ -260,19 +316,38 @@ public class ConfigJavaValidator extends AbstractConfigJavaValidator { if (!(value instanceof NumberLiteral)) continue; - double dValue = ConfigUtil - .literalToDouble((NumberLiteral) value); - if (min != null) { - double dMin = ConfigUtil.literalToDouble(min); - if (dMin > dValue) - error("value is less than minimum", arrayRef, - values.indexOf(value)); - } - if (max != null) { - double dMax = ConfigUtil.literalToDouble(max); - if (dMax < dValue) - error("value exceeds maximum", arrayRef, - values.indexOf(value)); + if (value instanceof RealLiteral) { + double dbValue = ((RealLiteral) value).getValue(); + if (min instanceof RealLiteral) { + double dbMin = ((RealLiteral) min).getValue(); + if (dbMin > dbValue) + error("value is less than minimum", + config.getValue(), arrayRef, + values.indexOf(value)); + } + if (max instanceof RealLiteral) { + double dbMax = ((RealLiteral) max).getValue(); + if (dbMax < dbValue) + error("value exceeds maximum", + config.getValue(), arrayRef, + values.indexOf(value)); + } + } else if (value instanceof IntLiteral) { + long lValue = ((IntLiteral) value).getValue(); + if (min instanceof IntLiteral) { + long lMin = ((IntLiteral) min).getValue(); + if (lMin > lValue) + error("value is less than minimum", + config.getValue(), arrayRef, + values.indexOf(value)); + } + if (max instanceof IntLiteral) { + long lMax = ((IntLiteral) max).getValue(); + if (lMax < lValue) + error("value exceeds maximum", + config.getValue(), arrayRef, + values.indexOf(value)); + } } } } @@ -287,29 +362,54 @@ public class ConfigJavaValidator extends AbstractConfigJavaValidator { EReference minRef = ConfigPackage.eINSTANCE.getAttrClassConfig_Min(); LiteralType type = primitive.getType(); - switch (type) { - case INT: - if (config instanceof RealLiteral) - error("must be an integer", minRef); - break; - default: - if (config != null) - error("no minimum allowed", minRef); - } if (type == LiteralType.INT || type == LiteralType.REAL) { + if (primitive.getType() == LiteralType.INT) { + if (!(min instanceof IntLiteral)) + error("incompatible datatype: maximum is not int", minRef); + } else if (primitive.getType() == LiteralType.REAL) { + if (!(min instanceof RealLiteral)) + error("incompatible datatype: maximum is not real", minRef); + } // check room default if config default is not set - if (config.getValue() == null) { - double dMin = ConfigUtil.literalToDouble(min); - String defaultValue = config.getAttribute() - .getDefaultValueLiteral(); - try { - double dDefaulValue = Double.parseDouble(defaultValue); - if (dMin > dDefaulValue) - error("default value in ROOM model is less than this minimun", + String defaultValue = config.getAttribute() + .getDefaultValueLiteral(); + if (config.getValue() == null && defaultValue != null) { + if (type == LiteralType.INT) { + if (min instanceof IntLiteral) { + try { + long lDefaultValue = converter.getLongConverter() + .toValue(defaultValue, null); + long lMax = ((IntLiteral) min).getValue(); + if (lMax < lDefaultValue) + error("default value in ROOM model is less than this maximum", + minRef); + } catch (ValueConverterException e) { + warning("could not compare with int value in ROOM model (parse error)", + minRef); + } + } else + warning("could not compare with int value in ROOM model (incompatible datatypes)", + minRef); + } else if (type == LiteralType.REAL) { + if (min instanceof RealLiteral) { + try { + double dbDefaultValue = converter + .getRealConverter().toValue(defaultValue, + null); + double dbMax = ((RealLiteral) min).getValue(); + if (dbMax < dbDefaultValue) + error("default value in ROOM model is less than this maximum", + minRef); + } catch (ValueConverterException e1) { + warning("could not compare with real value in ROOM model (parse error)", + minRef); + } + } else + warning("could not compare with real value in ROOM model (incompatible datatypes)", minRef); - } catch (NumberFormatException e) { } + } } @@ -317,35 +417,60 @@ public class ConfigJavaValidator extends AbstractConfigJavaValidator { private void checkAttrConfigMax(PrimitiveType primitive, AttrClassConfig config) { - NumberLiteral max = config.getMin(); + NumberLiteral max = config.getMax(); if (max == null) return; EReference maxRef = ConfigPackage.eINSTANCE.getAttrClassConfig_Max(); LiteralType type = primitive.getType(); - switch (type) { - case INT: - if (max instanceof RealLiteral) - error("must be an integer", maxRef); - break; - default: - if (max != null) - error("no maximum allowed", maxRef); - } if (type == LiteralType.INT || type == LiteralType.REAL) { + if (primitive.getType() == LiteralType.INT) { + if (!(max instanceof IntLiteral)) + error("incompatible datatype: maximum is not int", maxRef); + } else if (primitive.getType() == LiteralType.REAL) { + if (!(max instanceof RealLiteral)) + error("incompatible datatype: maximum is not real", maxRef); + } // check room default if config default is not set - if (config.getValue() == null) { - double dMax = ConfigUtil.literalToDouble(max); - String defaultValue = config.getAttribute() - .getDefaultValueLiteral(); - try { - double dDefaulValue = Double.parseDouble(defaultValue); - if (dMax < dDefaulValue) - error("default value in ROOM model exceeds this maximum", + String defaultValue = config.getAttribute() + .getDefaultValueLiteral(); + if (config.getValue() == null && defaultValue != null) { + if (type == LiteralType.INT) { + if (max instanceof IntLiteral) { + try { + long lDefaultValue = converter.getLongConverter() + .toValue(defaultValue, null); + long lMax = ((IntLiteral) max).getValue(); + if (lMax < lDefaultValue) + error("default value in ROOM model exceeds this maximum", + maxRef); + } catch (ValueConverterException e) { + warning("could not compare with int value in ROOM model (parse error)", + maxRef); + } + } else + warning("could not compare with int value in ROOM model (incompatible datatypes)", + maxRef); + } else if (type == LiteralType.REAL) { + if (max instanceof RealLiteral) { + try { + double dbDefaultValue = converter + .getRealConverter().toValue(defaultValue, + null); + double dbMax = ((RealLiteral) max).getValue(); + if (dbMax < dbDefaultValue) + error("default value in ROOM model exceeds this maximum", + maxRef); + } catch (ValueConverterException e1) { + warning("could not compare with real value in ROOM model (parse error)", + maxRef); + } + } else + warning("could not compare with real value in ROOM model (incompatible datatypes)", maxRef); - } catch (NumberFormatException e) { } + } } } |