Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice')
-rw-r--r--plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/Config.xtext408
-rw-r--r--plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigRuntimeModule.java108
-rw-r--r--plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigStandaloneSetup.java48
-rw-r--r--plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/formatting/ConfigFormatter.java148
-rw-r--r--plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/generator/ConfigGenerator.xtend30
-rw-r--r--plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/scoping/ConfigScopeProvider.java286
-rw-r--r--plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/validation/ConfigJavaValidator.java986
7 files changed, 1007 insertions, 1007 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 dbe2a9e34..9ebaaa6c9 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
@@ -1,204 +1,204 @@
-/*******************************************************************************
- * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
- * 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:
- * Juergen Haug and Thomas Schuetz (initial contribution)
- *
- *******************************************************************************/
-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
-
-ConfigModel:
- imports+=Import*
- configElements+=ConfigElement*;
-
-ConfigElement:
- 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:
- * duplicates config, attributes
- */
-ActorClassConfig:
- 'ActorClassConfig' actor=[room::ActorClass|FQN] '{'
- (attributes+=AttrClassConfig)*
- '}';
-
- /*
- * Validation:
- * duplicates config, attributes
- * valid instance reference
- * Proposal:
- * attributes
- */
-ActorInstanceConfig:
- 'ActorInstanceConfig' root=[room::SubSystemClass|FQN] '/' path=RefPath '{'
- (
- (attributes+=AttrInstanceConfig)* &
- (ports+=PortInstanceConfig)*
- )
- '}';
-
-ProtocolClassConfig:
- 'ProtocolClassConfig' protocol=[room::ProtocolClass|FQN] '{'
- (
- ('regular' regular=PortClassConfig)? &
- ('conjugate' conjugated=PortClassConfig)?
- )
- '}';
-
-PortClassConfig:
- {PortClassConfig} 'Port' '{'
- (attributes+=AttrClassConfig)*
- '}';
-
-PortInstanceConfig:
- 'InterfaceItem' item=[room::InterfaceItem|ID] '{'
- (attributes+=AttrInstanceConfig)*
- '}';
-
- /*
- * Validation:
- * correct value type
- * Proposal:
- * correct Literal
- */
-AttrConfig:
- AttrClassConfig | AttrInstanceConfig;
-
- /*
- * Validation:
- * correct min, max type + available
- * min <= value <= max
- * if !value -> min <= attribute.defaultValue <= max
- * character length
- *
- */
-AttrClassConfig:
- 'Attr' attribute=[room::Attribute] ('=' value=LiteralArray)? ('{'
- (
- ('min' '=' min=NumberLiteral)?
- ('max' '=' max=NumberLiteral)?
- (attributes+=AttrClassConfig)*
- )
- '}')?;
-
-AttrInstanceConfig:
- 'Attr' attribute=[room::Attribute] ('=' value=LiteralArray)? ('{'
- (
- (dynConfig?='dynamic configuration' (readOnly?='read' | 'write'))?
- (attributes+=AttrInstanceConfig*)
- )
- '}')?;
-
- /*
- * Proposal:
- * for ActorInstanceConfig
- */
-RefPath:
- refs+=ID ('/' refs+=ID)*;
-
- // -------------------- from org.eclipse.etrice.core.Room.xtext ---------------
-Import:
- 'import' (importedNamespace=ImportedFQN 'from' | 'model') importURI=STRING;
-
-ImportedFQN:
- FQN ('.*')?;
-
-FQN:
- ID ('.' ID)*;
-
- // -----------------------------------------------------------------------------
-
-//enum Unit:
-// N|
-// W|
-// S = 's'|
-// KG = 'kg'|
-// M = 'm'|
-// C|
-// NM|
-// RPM|
-// V|
-// A|
-// HZ = 'Hz'|
-// KW
-//;
-
-// LiteralArray = BooleanLiteral+|NumberLiteral+
-// LiteralArray = StringLiteral
-LiteralArray:
- literals+=Literal (',' literals+=Literal)*;
-
- // Value Types for Attributes
-Literal:
- BooleanLiteral |
- NumberLiteral |
- StringLiteral;
-
-BooleanLiteral:
- {BooleanLiteral} ('false' | isTrue?='true');
-
-NumberLiteral:
- IntLiteral | RealLiteral;
-
-RealLiteral:
- {RealLiteral} value=Real;
-
-IntLiteral:
- {IntLiteral} value=Integer;
-
-StringLiteral:
- {StringLiteral} value=STRING;
-
-Integer returns ecore::ELong:
- SignedInteger | Hexadecimal;
-
-SignedInteger hidden():
- ('+' | '-')? INT;
-
-Hexadecimal hidden():
- HEX;
-
-Real returns ecore::EDouble:
- Decimal | DotDecimal | DecimalDot | DecimalExp;
-
-Decimal hidden():
- ('+' | '-')? INT '.' INT;
-
-DotDecimal hidden():
- ('+' | '-')? '.' INT;
-
-DecimalDot hidden():
- ('+' | '-')? INT '.';
-
-DecimalExp hidden():
- ('+' | '-')? INT '.' INT EXP;
-
-terminal EXP:
- ('e'|'E') ('+' | '-')? ('0'..'9')+;
-
-terminal HEX:
- ('0x' | '0X') ('0'..'9' | 'a'..'f' | 'A'..'F')+;
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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:
+ * Juergen Haug and Thomas Schuetz (initial contribution)
+ *
+ *******************************************************************************/
+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
+
+ConfigModel:
+ imports+=Import*
+ configElements+=ConfigElement*;
+
+ConfigElement:
+ 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:
+ * duplicates config, attributes
+ */
+ActorClassConfig:
+ 'ActorClassConfig' actor=[room::ActorClass|FQN] '{'
+ (attributes+=AttrClassConfig)*
+ '}';
+
+ /*
+ * Validation:
+ * duplicates config, attributes
+ * valid instance reference
+ * Proposal:
+ * attributes
+ */
+ActorInstanceConfig:
+ 'ActorInstanceConfig' root=[room::SubSystemClass|FQN] '/' path=RefPath '{'
+ (
+ (attributes+=AttrInstanceConfig)* &
+ (ports+=PortInstanceConfig)*
+ )
+ '}';
+
+ProtocolClassConfig:
+ 'ProtocolClassConfig' protocol=[room::ProtocolClass|FQN] '{'
+ (
+ ('regular' regular=PortClassConfig)? &
+ ('conjugate' conjugated=PortClassConfig)?
+ )
+ '}';
+
+PortClassConfig:
+ {PortClassConfig} 'Port' '{'
+ (attributes+=AttrClassConfig)*
+ '}';
+
+PortInstanceConfig:
+ 'InterfaceItem' item=[room::InterfaceItem|ID] '{'
+ (attributes+=AttrInstanceConfig)*
+ '}';
+
+ /*
+ * Validation:
+ * correct value type
+ * Proposal:
+ * correct Literal
+ */
+AttrConfig:
+ AttrClassConfig | AttrInstanceConfig;
+
+ /*
+ * Validation:
+ * correct min, max type + available
+ * min <= value <= max
+ * if !value -> min <= attribute.defaultValue <= max
+ * character length
+ *
+ */
+AttrClassConfig:
+ 'Attr' attribute=[room::Attribute] ('=' value=LiteralArray)? ('{'
+ (
+ ('min' '=' min=NumberLiteral)?
+ ('max' '=' max=NumberLiteral)?
+ (attributes+=AttrClassConfig)*
+ )
+ '}')?;
+
+AttrInstanceConfig:
+ 'Attr' attribute=[room::Attribute] ('=' value=LiteralArray)? ('{'
+ (
+ (dynConfig?='dynamic configuration' (readOnly?='read' | 'write'))?
+ (attributes+=AttrInstanceConfig*)
+ )
+ '}')?;
+
+ /*
+ * Proposal:
+ * for ActorInstanceConfig
+ */
+RefPath:
+ refs+=ID ('/' refs+=ID)*;
+
+ // -------------------- from org.eclipse.etrice.core.Room.xtext ---------------
+Import:
+ 'import' (importedNamespace=ImportedFQN 'from' | 'model') importURI=STRING;
+
+ImportedFQN:
+ FQN ('.*')?;
+
+FQN:
+ ID ('.' ID)*;
+
+ // -----------------------------------------------------------------------------
+
+//enum Unit:
+// N|
+// W|
+// S = 's'|
+// KG = 'kg'|
+// M = 'm'|
+// C|
+// NM|
+// RPM|
+// V|
+// A|
+// HZ = 'Hz'|
+// KW
+//;
+
+// LiteralArray = BooleanLiteral+|NumberLiteral+
+// LiteralArray = StringLiteral
+LiteralArray:
+ literals+=Literal (',' literals+=Literal)*;
+
+ // Value Types for Attributes
+Literal:
+ BooleanLiteral |
+ NumberLiteral |
+ StringLiteral;
+
+BooleanLiteral:
+ {BooleanLiteral} ('false' | isTrue?='true');
+
+NumberLiteral:
+ IntLiteral | RealLiteral;
+
+RealLiteral:
+ {RealLiteral} value=Real;
+
+IntLiteral:
+ {IntLiteral} value=Integer;
+
+StringLiteral:
+ {StringLiteral} value=STRING;
+
+Integer returns ecore::ELong:
+ SignedInteger | Hexadecimal;
+
+SignedInteger hidden():
+ ('+' | '-')? INT;
+
+Hexadecimal hidden():
+ HEX;
+
+Real returns ecore::EDouble:
+ Decimal | DotDecimal | DecimalDot | DecimalExp;
+
+Decimal hidden():
+ ('+' | '-')? INT '.' INT;
+
+DotDecimal hidden():
+ ('+' | '-')? '.' INT;
+
+DecimalDot hidden():
+ ('+' | '-')? INT '.';
+
+DecimalExp hidden():
+ ('+' | '-')? 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/ConfigRuntimeModule.java b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigRuntimeModule.java
index 831ce5ece..2882444e4 100644
--- a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigRuntimeModule.java
+++ b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigRuntimeModule.java
@@ -1,54 +1,54 @@
-/*******************************************************************************
- * Copyright (c) 2012 Juergen Haug
- * 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:
- * Juergen Haug
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.core;
-
-import org.eclipse.etrice.core.converter.ConfigValueConverterService;
-import org.eclipse.etrice.core.scoping.PlatformRelativeUriResolver;
-import org.eclipse.xtext.conversion.IValueConverterService;
-import org.eclipse.xtext.scoping.impl.ImportUriResolver;
-
-import com.google.inject.Binder;
-
-/**
- * Use this class to register components to be used at runtime / without the
- * Equinox extension registry.
- */
-public class ConfigRuntimeModule extends
- org.eclipse.etrice.core.AbstractConfigRuntimeModule {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.etrice.core.AbstractRoomRuntimeModule#
- * configureIScopeProviderDelegate(com.google.inject.Binder)
- */
- @Override
- public void configureIScopeProviderDelegate(Binder binder) {
- binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class)
- .annotatedWith(
- com.google.inject.name.Names
- .named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
- .to(org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.class);
- }
-
- // HOWTO: use URI imports - need special URI resolver
- public Class<? extends ImportUriResolver> bindImportUriResolver() {
- return PlatformRelativeUriResolver.class;
- }
-
- @Override
- public Class<? extends IValueConverterService> bindIValueConverterService() {
- return ConfigValueConverterService.class;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Juergen Haug
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core;
+
+import org.eclipse.etrice.core.converter.ConfigValueConverterService;
+import org.eclipse.etrice.core.scoping.PlatformRelativeUriResolver;
+import org.eclipse.xtext.conversion.IValueConverterService;
+import org.eclipse.xtext.scoping.impl.ImportUriResolver;
+
+import com.google.inject.Binder;
+
+/**
+ * Use this class to register components to be used at runtime / without the
+ * Equinox extension registry.
+ */
+public class ConfigRuntimeModule extends
+ org.eclipse.etrice.core.AbstractConfigRuntimeModule {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.etrice.core.AbstractRoomRuntimeModule#
+ * configureIScopeProviderDelegate(com.google.inject.Binder)
+ */
+ @Override
+ public void configureIScopeProviderDelegate(Binder binder) {
+ binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class)
+ .annotatedWith(
+ com.google.inject.name.Names
+ .named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
+ .to(org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.class);
+ }
+
+ // HOWTO: use URI imports - need special URI resolver
+ public Class<? extends ImportUriResolver> bindImportUriResolver() {
+ return PlatformRelativeUriResolver.class;
+ }
+
+ @Override
+ public Class<? extends IValueConverterService> bindIValueConverterService() {
+ return ConfigValueConverterService.class;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigStandaloneSetup.java b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigStandaloneSetup.java
index a7912b044..b602020e2 100644
--- a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigStandaloneSetup.java
+++ b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/ConfigStandaloneSetup.java
@@ -1,24 +1,24 @@
-/*******************************************************************************
- * Copyright (c) 2012 Juergen Haug
- * 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:
- * Juergen Haug
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.core;
-
-/**
- * Initialization support for running Xtext languages without equinox extension
- * registry
- */
-public class ConfigStandaloneSetup extends ConfigStandaloneSetupGenerated {
-
- public static void doSetup() {
- new ConfigStandaloneSetup().createInjectorAndDoEMFRegistration();
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Juergen Haug
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core;
+
+/**
+ * Initialization support for running Xtext languages without equinox extension
+ * registry
+ */
+public class ConfigStandaloneSetup extends ConfigStandaloneSetupGenerated {
+
+ public static void doSetup() {
+ new ConfigStandaloneSetup().createInjectorAndDoEMFRegistration();
+ }
+}
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 a5be3a1a8..03d31e61f 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
@@ -1,74 +1,74 @@
-/*******************************************************************************
- * Copyright (c) 2012 Juergen Haug
- * 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:
- * Juergen Haug
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.core.formatting;
-
-import org.eclipse.etrice.core.services.ConfigGrammarAccess;
-import org.eclipse.xtext.Keyword;
-import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter;
-import org.eclipse.xtext.formatting.impl.FormattingConfig;
-import org.eclipse.xtext.util.Pair;
-
-/**
- * This class contains custom formatting description.
- *
- * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#formatting
- * on how and when to use it
- *
- * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
- */
-public class ConfigFormatter extends AbstractDeclarativeFormatter {
-
- @Override
- protected void configureFormatting(FormattingConfig c) {
- ConfigGrammarAccess f = (ConfigGrammarAccess) getGrammarAccess();
-
- // general
-
- c.setAutoLinewrap(120);
- c.setLinewrap(1).before(f.getSL_COMMENTRule());
- c.setLinewrap(2).before(f.getML_COMMENTRule());
-
- for (Pair<Keyword, Keyword> pair : f.findKeywordPairs("{", "}")) {
- c.setLinewrap().after(pair.getFirst());
- c.setIndentationIncrement().after(pair.getFirst());
- c.setLinewrap().before(pair.getSecond());
- c.setIndentationDecrement().before(pair.getSecond());
- c.setSpace(" ").between(pair.getFirst(), pair.getSecond());
- }
-
- for (Keyword k: f.findKeywords("(", "|", ".", "*")) {
- c.setNoSpace().around(k);
- }
-
- for (Keyword k: f.findKeywords("<", "~")) {
- c.setNoSpace().after(k);
- }
- for (Keyword k: f.findKeywords(")", ">", ",", ":")) {
- c.setNoSpace().before(k);
- }
-
- for (Keyword k: f.findKeywords("regular","conjugate")) {
- c.setLinewrap().before(k);
- }
-
- c.setLinewrap(1).after(f.getImportRule());
-
- c.setLinewrap(2).around(f.getActorClassConfigRule());
- c.setLinewrap(2).around(f.getProtocolClassConfigRule());
- c.setLinewrap(2).around(f.getActorInstanceConfigRule());
-
- c.setLinewrap(1).around(f.getAttrClassConfigRule());
- c.setLinewrap(1).around(f.getAttrInstanceConfigRule());
- c.setLinewrap(1).around(f.getPortInstanceConfigRule());
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Juergen Haug
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.formatting;
+
+import org.eclipse.etrice.core.services.ConfigGrammarAccess;
+import org.eclipse.xtext.Keyword;
+import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter;
+import org.eclipse.xtext.formatting.impl.FormattingConfig;
+import org.eclipse.xtext.util.Pair;
+
+/**
+ * This class contains custom formatting description.
+ *
+ * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#formatting
+ * on how and when to use it
+ *
+ * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
+ */
+public class ConfigFormatter extends AbstractDeclarativeFormatter {
+
+ @Override
+ protected void configureFormatting(FormattingConfig c) {
+ ConfigGrammarAccess f = (ConfigGrammarAccess) getGrammarAccess();
+
+ // general
+
+ c.setAutoLinewrap(120);
+ c.setLinewrap(1).before(f.getSL_COMMENTRule());
+ c.setLinewrap(2).before(f.getML_COMMENTRule());
+
+ for (Pair<Keyword, Keyword> pair : f.findKeywordPairs("{", "}")) {
+ c.setLinewrap().after(pair.getFirst());
+ c.setIndentationIncrement().after(pair.getFirst());
+ c.setLinewrap().before(pair.getSecond());
+ c.setIndentationDecrement().before(pair.getSecond());
+ c.setSpace(" ").between(pair.getFirst(), pair.getSecond());
+ }
+
+ for (Keyword k: f.findKeywords("(", "|", ".", "*")) {
+ c.setNoSpace().around(k);
+ }
+
+ for (Keyword k: f.findKeywords("<", "~")) {
+ c.setNoSpace().after(k);
+ }
+ for (Keyword k: f.findKeywords(")", ">", ",", ":")) {
+ c.setNoSpace().before(k);
+ }
+
+ for (Keyword k: f.findKeywords("regular","conjugate")) {
+ c.setLinewrap().before(k);
+ }
+
+ c.setLinewrap(1).after(f.getImportRule());
+
+ c.setLinewrap(2).around(f.getActorClassConfigRule());
+ c.setLinewrap(2).around(f.getProtocolClassConfigRule());
+ c.setLinewrap(2).around(f.getActorInstanceConfigRule());
+
+ c.setLinewrap(1).around(f.getAttrClassConfigRule());
+ c.setLinewrap(1).around(f.getAttrInstanceConfigRule());
+ c.setLinewrap(1).around(f.getPortInstanceConfigRule());
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/generator/ConfigGenerator.xtend b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/generator/ConfigGenerator.xtend
index db116bd88..78f006b63 100644
--- a/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/generator/ConfigGenerator.xtend
+++ b/plugins/org.eclipse.etrice.core.config/src/org/eclipse/etrice/core/generator/ConfigGenerator.xtend
@@ -1,15 +1,15 @@
-/*
- * generated by Xtext
- */
-package org.eclipse.etrice.core.generator
-
-import org.eclipse.emf.ecore.resource.Resource
-import org.eclipse.xtext.generator.IGenerator
-import org.eclipse.xtext.generator.IFileSystemAccess
-
-class ConfigGenerator implements IGenerator {
-
- override void doGenerate(Resource resource, IFileSystemAccess fsa) {
- //TODO implement me
- }
-}
+/*
+ * generated by Xtext
+ */
+package org.eclipse.etrice.core.generator
+
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.xtext.generator.IGenerator
+import org.eclipse.xtext.generator.IFileSystemAccess
+
+class ConfigGenerator implements IGenerator {
+
+ override void doGenerate(Resource resource, IFileSystemAccess fsa) {
+ //TODO implement me
+ }
+}
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 32eba06c4..c241dfadd 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
@@ -1,143 +1,143 @@
-/*******************************************************************************
- * Copyright (c) 2012 Juergen Haug
- * 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:
- * Juergen Haug
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.core.scoping;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.etrice.core.config.ActorClassConfig;
-import org.eclipse.etrice.core.config.ActorInstanceConfig;
-import org.eclipse.etrice.core.config.AttrConfig;
-import org.eclipse.etrice.core.config.PortClassConfig;
-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.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;
-import org.eclipse.etrice.core.room.util.RoomHelpers;
-import org.eclipse.xtext.resource.EObjectDescription;
-import org.eclipse.xtext.resource.IEObjectDescription;
-import org.eclipse.xtext.scoping.IScope;
-import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
-import org.eclipse.xtext.scoping.impl.SimpleScope;
-
-/**
- * This class contains custom scoping description.
- *
- * @see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping on
- * how and when to use it
- *
- */
-public class ConfigScopeProvider extends AbstractDeclarativeScopeProvider {
-
- public IScope scope_PortInstanceConfig_item(PortInstanceConfig ctx,
- EReference ref) {
- final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>();
-
- ActorInstanceConfig actorConfig = (ActorInstanceConfig) ctx
- .eContainer();
- SubSystemClass subsystem = actorConfig.getRoot();
- if (subsystem != null) {
- ActorClass ac = ConfigUtil
- .resolve(subsystem, actorConfig.getPath());
- for (InterfaceItem item : ConfigUtil.getConfigurableInterfaceItems(
- ac, true))
- scopes.add(EObjectDescription.create(item.getName(), item));
- }
-
- return new SimpleScope(IScope.NULLSCOPE, scopes);
- }
-
- public IScope scope_AttrConfig_attribute(AttrConfig ctx, EReference ref) {
- final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>();
-
- 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);
- else if (ctx.eContainer() instanceof PortClassConfig)
- collectAttributes((PortClassConfig) ctx.eContainer(), scopes);
- else if (ctx.eContainer() instanceof PortInstanceConfig)
- collectAttributes((PortInstanceConfig) ctx.eContainer(), scopes);
- 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();
- if (actor != null) {
- for (Attribute att : RoomHelpers.getAllAttributes(actor)) {
- scopes.add(EObjectDescription.create(att.getName(), att));
- }
- }
- }
-
- private void collectAttributes(ActorInstanceConfig config,
- List<IEObjectDescription> scopes) {
- SubSystemClass subsystem = config.getRoot();
- if (subsystem != null) {
- ActorClass actor = ConfigUtil.resolve(subsystem, config.getPath());
- for (Attribute att : RoomHelpers.getAllAttributes(actor)) {
- scopes.add(EObjectDescription.create(att.getName(), att));
- }
- }
- }
-
- private void collectAttributes(PortClassConfig config,
- List<IEObjectDescription> scopes) {
- ProtocolClassConfig protocolConfig = (ProtocolClassConfig) config
- .eContainer();
- PortClass portClass = null;
- if (protocolConfig.getRegular() == config)
- portClass = protocolConfig.getProtocol().getRegular();
- else
- portClass = protocolConfig.getProtocol().getConjugate();
-
- if (portClass != null)
- for (Attribute att : portClass.getAttributes())
- scopes.add(EObjectDescription.create(att.getName(), att));
- }
-
- private void collectAttributes(PortInstanceConfig config,
- List<IEObjectDescription> scopes) {
- PortClass portClass = ConfigUtil.getPortClass(config);
- if (portClass != null)
- for (Attribute att : portClass.getAttributes())
- scopes.add(EObjectDescription.create(att.getName(), att));
- }
-}
-
-/*
- * IScope scope_<RefDeclaringEClass>_<Reference>( <ContextType> ctx, EReference
- * ref)
- *
- * IScope scope_<TypeToReturn>(<ContextType> ctx, EReference ref)
- */
+/*******************************************************************************
+ * Copyright (c) 2012 Juergen Haug
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.scoping;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.etrice.core.config.ActorClassConfig;
+import org.eclipse.etrice.core.config.ActorInstanceConfig;
+import org.eclipse.etrice.core.config.AttrConfig;
+import org.eclipse.etrice.core.config.PortClassConfig;
+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.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;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.xtext.resource.EObjectDescription;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.scoping.IScope;
+import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
+import org.eclipse.xtext.scoping.impl.SimpleScope;
+
+/**
+ * This class contains custom scoping description.
+ *
+ * @see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping on
+ * how and when to use it
+ *
+ */
+public class ConfigScopeProvider extends AbstractDeclarativeScopeProvider {
+
+ public IScope scope_PortInstanceConfig_item(PortInstanceConfig ctx,
+ EReference ref) {
+ final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>();
+
+ ActorInstanceConfig actorConfig = (ActorInstanceConfig) ctx
+ .eContainer();
+ SubSystemClass subsystem = actorConfig.getRoot();
+ if (subsystem != null) {
+ ActorClass ac = ConfigUtil
+ .resolve(subsystem, actorConfig.getPath());
+ for (InterfaceItem item : ConfigUtil.getConfigurableInterfaceItems(
+ ac, true))
+ scopes.add(EObjectDescription.create(item.getName(), item));
+ }
+
+ return new SimpleScope(IScope.NULLSCOPE, scopes);
+ }
+
+ public IScope scope_AttrConfig_attribute(AttrConfig ctx, EReference ref) {
+ final List<IEObjectDescription> scopes = new ArrayList<IEObjectDescription>();
+
+ 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);
+ else if (ctx.eContainer() instanceof PortClassConfig)
+ collectAttributes((PortClassConfig) ctx.eContainer(), scopes);
+ else if (ctx.eContainer() instanceof PortInstanceConfig)
+ collectAttributes((PortInstanceConfig) ctx.eContainer(), scopes);
+ 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();
+ if (actor != null) {
+ for (Attribute att : RoomHelpers.getAllAttributes(actor)) {
+ scopes.add(EObjectDescription.create(att.getName(), att));
+ }
+ }
+ }
+
+ private void collectAttributes(ActorInstanceConfig config,
+ List<IEObjectDescription> scopes) {
+ SubSystemClass subsystem = config.getRoot();
+ if (subsystem != null) {
+ ActorClass actor = ConfigUtil.resolve(subsystem, config.getPath());
+ for (Attribute att : RoomHelpers.getAllAttributes(actor)) {
+ scopes.add(EObjectDescription.create(att.getName(), att));
+ }
+ }
+ }
+
+ private void collectAttributes(PortClassConfig config,
+ List<IEObjectDescription> scopes) {
+ ProtocolClassConfig protocolConfig = (ProtocolClassConfig) config
+ .eContainer();
+ PortClass portClass = null;
+ if (protocolConfig.getRegular() == config)
+ portClass = protocolConfig.getProtocol().getRegular();
+ else
+ portClass = protocolConfig.getProtocol().getConjugate();
+
+ if (portClass != null)
+ for (Attribute att : portClass.getAttributes())
+ scopes.add(EObjectDescription.create(att.getName(), att));
+ }
+
+ private void collectAttributes(PortInstanceConfig config,
+ List<IEObjectDescription> scopes) {
+ PortClass portClass = ConfigUtil.getPortClass(config);
+ if (portClass != null)
+ for (Attribute att : portClass.getAttributes())
+ scopes.add(EObjectDescription.create(att.getName(), att));
+ }
+}
+
+/*
+ * IScope scope_<RefDeclaringEClass>_<Reference>( <ContextType> ctx, EReference
+ * ref)
+ *
+ * IScope scope_<TypeToReturn>(<ContextType> ctx, EReference ref)
+ */
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 50b3ba135..981b84728 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
@@ -1,493 +1,493 @@
-/*******************************************************************************
- * Copyright (c) 2012 Juergen Haug
- * 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:
- * Juergen Haug
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.core.validation;
-
-import java.util.HashSet;
-import java.util.List;
-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;
-import org.eclipse.etrice.core.config.AttrConfig;
-import org.eclipse.etrice.core.config.AttrInstanceConfig;
-import org.eclipse.etrice.core.config.BooleanLiteral;
-import org.eclipse.etrice.core.config.ConfigModel;
-import org.eclipse.etrice.core.config.ConfigPackage;
-import org.eclipse.etrice.core.config.IntLiteral;
-import org.eclipse.etrice.core.config.Literal;
-import org.eclipse.etrice.core.config.NumberLiteral;
-import org.eclipse.etrice.core.config.PortClassConfig;
-import org.eclipse.etrice.core.config.PortInstanceConfig;
-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
- Set<ActorClass> actorClasses = new HashSet<ActorClass>();
- for (ActorClassConfig classConfig : model.getActorClassConfigs()) {
- if (actorClasses.contains(classConfig.getActor()))
- error("duplicate class config", model,
- ConfigPackage.Literals.CONFIG_MODEL__CONFIG_ELEMENTS,
- model.getConfigElements().indexOf(classConfig));
- else
- actorClasses.add(classConfig.getActor());
- }
- // duplicate actor instance config check
- Set<String> actorRefs = new HashSet<String>();
- for (ActorInstanceConfig instanceConfig : model
- .getActorInstanceConfigs()) {
- String ref = instanceConfig.getRoot().getName()
- + refPathToString(instanceConfig.getPath());
- if (actorRefs.contains(ref))
- error("duplicate actor instance config", model,
- ConfigPackage.Literals.CONFIG_MODEL__CONFIG_ELEMENTS,
- model.getConfigElements().indexOf(instanceConfig));
- else
- actorRefs.add(ref);
- }
- // duplicate protocol class config check
- Set<ProtocolClass> protocolClasses = new HashSet<ProtocolClass>();
- for (ProtocolClassConfig protocolConfig : model
- .getProtocolClassConfigs()) {
- if (protocolClasses.contains(protocolConfig.getProtocol()))
- error("duplicate protocol class config", model,
- ConfigPackage.Literals.CONFIG_MODEL__CONFIG_ELEMENTS,
- model.getConfigElements().indexOf(protocolConfig));
- else
- protocolClasses.add(protocolConfig.getProtocol());
- }
- }
-
- @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);
-
- }
-
- @Check
- public void checkActorInstanceConfig(ActorInstanceConfig config) {
- ActorContainerClass root = config.getRoot();
- if (root != null && !root.eIsProxy()) {
- RefPath path = config.getPath();
- if (path != null) {
- String invalidSegment = ConfigUtil.checkPath(root, path);
- if (invalidSegment != null)
- error("no match for segment '" + invalidSegment + "'",
- 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
- Set<InterfaceItem> items = new HashSet<InterfaceItem>();
- for (PortInstanceConfig portConfig : config.getPorts()) {
- InterfaceItem item = portConfig.getItem();
- if (items.contains(item))
- error("duplicate port instance config",
- ConfigPackage.Literals.ACTOR_INSTANCE_CONFIG__PORTS,
- config.getPorts().indexOf(portConfig));
- else
- items.add(item);
- }
-
- checkDuplicateAttributes(config.getAttributes(),
- ConfigPackage.Literals.ACTOR_INSTANCE_CONFIG__ATTRIBUTES);
- }
-
- @Check
- public void checkPortClassConfig(PortClassConfig config) {
- checkDuplicateAttributes(config.getAttributes(),
- ConfigPackage.Literals.PORT_CLASS_CONFIG__ATTRIBUTES);
- }
-
- @Check
- public void checkPortInstanceConfig(PortInstanceConfig config) {
- checkDuplicateAttributes(config.getAttributes(),
- ConfigPackage.Literals.PORT_INSTANCE_CONFIG__ATTRIBUTES);
- }
-
- private void checkDuplicateAttributes(
- List<? extends AttrConfig> attrConfigs, EReference ref) {
- Set<Attribute> attributes = new HashSet<Attribute>();
- for (AttrConfig config : attrConfigs) {
- if (attributes.contains(config.getAttribute()))
- error("duplicate attribute entry", ref,
- attrConfigs.indexOf(config));
- else
- attributes.add(config.getAttribute());
- }
- }
-
- @Check
- public void checkAttrConfig(AttrConfig config) {
- Attribute a = config.getAttribute();
- if (a == null)
- return;
-
- 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);
- }
- }
-
- @Check
- public void checkAttrClassConfig(AttrClassConfig config) {
- Attribute attr = config.getAttribute();
- if (attr == null)
- return;
-
- DataType type = attr.getRefType().getType();
- if (type instanceof PrimitiveType) {
- PrimitiveType primitive = (PrimitiveType) type;
-
- checkAttrConfigMin(primitive, config);
- checkAttrConfigMax(primitive, config);
- }
- }
-
- @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);
-
- }
- }
-
- }
-
- private void checkAttrConfigValue(PrimitiveType primitive, AttrConfig config) {
- if (config.getValue() == null)
- return;
-
- List<Literal> values = config.getValue().getLiterals();
- EReference valueRef = ConfigPackage.eINSTANCE.getAttrConfig_Value();
- EReference arrayRef = ConfigPackage.eINSTANCE
- .getLiteralArray_Literals();
- LiteralType type = primitive.getType();
- Attribute attribute = config.getAttribute();
- int attrMult = (attribute.getSize() > 0) ? attribute.getSize() : 1;
- 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) {
- case BOOL:
- if (!(value instanceof BooleanLiteral))
- error("must be boolean value", valueRef);
- break;
- case REAL:
- if (!(value instanceof NumberLiteral))
- error("must be an integer or real value", valueRef);
- break;
- case INT:
- if (!(value instanceof IntLiteral))
- error("must be an integer", valueRef);
- break;
- case CHAR:
- if (!(value instanceof StringLiteral))
- error("must be a string", valueRef);
- else {
- if (values.size() > 1)
- error("multiplicity must be one", valueRef);
- StringLiteral strValue = (StringLiteral) value;
- if (attribute.getSize() > 0
- && attrMult < strValue.getValue().length())
- error("too many characters - maximal length is "
- + attrMult, valueRef);
- }
- break;
- }
- }
-
- // numeric check
- if ((type == LiteralType.INT || type == LiteralType.REAL)) {
- ActorClassConfig classConfig = null;
- if (config.eContainer() instanceof ActorInstanceConfig) {
- ActorInstanceConfig actorConfig = (ActorInstanceConfig) config
- .eContainer();
- ActorContainerClass actorClass = ConfigUtil.resolve(
- actorConfig.getRoot(), actorConfig.getPath());
- // find ActorClassConfig
- ConfigModel model = getConfigModel(actorConfig);
- for (ActorClassConfig cf : model.getActorClassConfigs()) {
- if (cf.getActor().equals(actorClass)) {
- classConfig = cf;
- break;
- }
- }
- } else if (config.eContainer() instanceof ActorClassConfig)
- classConfig = (ActorClassConfig) config.eContainer();
-
- AttrClassConfig attrClassConfig = null;
- if (classConfig != null) {
- for (AttrClassConfig acf : classConfig.getAttributes())
- if (config.getAttribute().equals(acf.getAttribute())) {
- attrClassConfig = acf;
- break;
- }
- }
-
- if (attrClassConfig != null) {
- NumberLiteral min = attrClassConfig.getMin();
- NumberLiteral max = attrClassConfig.getMax();
- for (Literal value : values) {
- if (!(value instanceof NumberLiteral))
- continue;
-
- 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));
- }
- }
- }
- }
- }
- }
-
- private void checkAttrConfigMin(PrimitiveType primitive,
- AttrClassConfig config) {
- NumberLiteral min = config.getMin();
- if (min == null)
- return;
-
- EReference minRef = ConfigPackage.eINSTANCE.getAttrClassConfig_Min();
- LiteralType type = primitive.getType();
-
- 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
- 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);
- }
-
- }
- }
-
- }
-
- private void checkAttrConfigMax(PrimitiveType primitive,
- AttrClassConfig config) {
- NumberLiteral max = config.getMax();
- if (max == null)
- return;
-
- EReference maxRef = ConfigPackage.eINSTANCE.getAttrClassConfig_Max();
- LiteralType type = primitive.getType();
-
- 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
- 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);
- }
-
- }
- }
- }
-
- private ConfigModel getConfigModel(EObject object) {
- EObject root = object;
- while (root.eContainer() != null)
- root = root.eContainer();
-
- return (ConfigModel) root;
- }
-
- private String refPathToString(RefPath path) {
- String str = "";
- for (String s : path.getRefs())
- str += "/" + s;
-
- return str;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Juergen Haug
+ * 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:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.validation;
+
+import java.util.HashSet;
+import java.util.List;
+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;
+import org.eclipse.etrice.core.config.AttrConfig;
+import org.eclipse.etrice.core.config.AttrInstanceConfig;
+import org.eclipse.etrice.core.config.BooleanLiteral;
+import org.eclipse.etrice.core.config.ConfigModel;
+import org.eclipse.etrice.core.config.ConfigPackage;
+import org.eclipse.etrice.core.config.IntLiteral;
+import org.eclipse.etrice.core.config.Literal;
+import org.eclipse.etrice.core.config.NumberLiteral;
+import org.eclipse.etrice.core.config.PortClassConfig;
+import org.eclipse.etrice.core.config.PortInstanceConfig;
+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
+ Set<ActorClass> actorClasses = new HashSet<ActorClass>();
+ for (ActorClassConfig classConfig : model.getActorClassConfigs()) {
+ if (actorClasses.contains(classConfig.getActor()))
+ error("duplicate class config", model,
+ ConfigPackage.Literals.CONFIG_MODEL__CONFIG_ELEMENTS,
+ model.getConfigElements().indexOf(classConfig));
+ else
+ actorClasses.add(classConfig.getActor());
+ }
+ // duplicate actor instance config check
+ Set<String> actorRefs = new HashSet<String>();
+ for (ActorInstanceConfig instanceConfig : model
+ .getActorInstanceConfigs()) {
+ String ref = instanceConfig.getRoot().getName()
+ + refPathToString(instanceConfig.getPath());
+ if (actorRefs.contains(ref))
+ error("duplicate actor instance config", model,
+ ConfigPackage.Literals.CONFIG_MODEL__CONFIG_ELEMENTS,
+ model.getConfigElements().indexOf(instanceConfig));
+ else
+ actorRefs.add(ref);
+ }
+ // duplicate protocol class config check
+ Set<ProtocolClass> protocolClasses = new HashSet<ProtocolClass>();
+ for (ProtocolClassConfig protocolConfig : model
+ .getProtocolClassConfigs()) {
+ if (protocolClasses.contains(protocolConfig.getProtocol()))
+ error("duplicate protocol class config", model,
+ ConfigPackage.Literals.CONFIG_MODEL__CONFIG_ELEMENTS,
+ model.getConfigElements().indexOf(protocolConfig));
+ else
+ protocolClasses.add(protocolConfig.getProtocol());
+ }
+ }
+
+ @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);
+
+ }
+
+ @Check
+ public void checkActorInstanceConfig(ActorInstanceConfig config) {
+ ActorContainerClass root = config.getRoot();
+ if (root != null && !root.eIsProxy()) {
+ RefPath path = config.getPath();
+ if (path != null) {
+ String invalidSegment = ConfigUtil.checkPath(root, path);
+ if (invalidSegment != null)
+ error("no match for segment '" + invalidSegment + "'",
+ 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
+ Set<InterfaceItem> items = new HashSet<InterfaceItem>();
+ for (PortInstanceConfig portConfig : config.getPorts()) {
+ InterfaceItem item = portConfig.getItem();
+ if (items.contains(item))
+ error("duplicate port instance config",
+ ConfigPackage.Literals.ACTOR_INSTANCE_CONFIG__PORTS,
+ config.getPorts().indexOf(portConfig));
+ else
+ items.add(item);
+ }
+
+ checkDuplicateAttributes(config.getAttributes(),
+ ConfigPackage.Literals.ACTOR_INSTANCE_CONFIG__ATTRIBUTES);
+ }
+
+ @Check
+ public void checkPortClassConfig(PortClassConfig config) {
+ checkDuplicateAttributes(config.getAttributes(),
+ ConfigPackage.Literals.PORT_CLASS_CONFIG__ATTRIBUTES);
+ }
+
+ @Check
+ public void checkPortInstanceConfig(PortInstanceConfig config) {
+ checkDuplicateAttributes(config.getAttributes(),
+ ConfigPackage.Literals.PORT_INSTANCE_CONFIG__ATTRIBUTES);
+ }
+
+ private void checkDuplicateAttributes(
+ List<? extends AttrConfig> attrConfigs, EReference ref) {
+ Set<Attribute> attributes = new HashSet<Attribute>();
+ for (AttrConfig config : attrConfigs) {
+ if (attributes.contains(config.getAttribute()))
+ error("duplicate attribute entry", ref,
+ attrConfigs.indexOf(config));
+ else
+ attributes.add(config.getAttribute());
+ }
+ }
+
+ @Check
+ public void checkAttrConfig(AttrConfig config) {
+ Attribute a = config.getAttribute();
+ if (a == null)
+ return;
+
+ 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);
+ }
+ }
+
+ @Check
+ public void checkAttrClassConfig(AttrClassConfig config) {
+ Attribute attr = config.getAttribute();
+ if (attr == null)
+ return;
+
+ DataType type = attr.getRefType().getType();
+ if (type instanceof PrimitiveType) {
+ PrimitiveType primitive = (PrimitiveType) type;
+
+ checkAttrConfigMin(primitive, config);
+ checkAttrConfigMax(primitive, config);
+ }
+ }
+
+ @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);
+
+ }
+ }
+
+ }
+
+ private void checkAttrConfigValue(PrimitiveType primitive, AttrConfig config) {
+ if (config.getValue() == null)
+ return;
+
+ List<Literal> values = config.getValue().getLiterals();
+ EReference valueRef = ConfigPackage.eINSTANCE.getAttrConfig_Value();
+ EReference arrayRef = ConfigPackage.eINSTANCE
+ .getLiteralArray_Literals();
+ LiteralType type = primitive.getType();
+ Attribute attribute = config.getAttribute();
+ int attrMult = (attribute.getSize() > 0) ? attribute.getSize() : 1;
+ 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) {
+ case BOOL:
+ if (!(value instanceof BooleanLiteral))
+ error("must be boolean value", valueRef);
+ break;
+ case REAL:
+ if (!(value instanceof NumberLiteral))
+ error("must be an integer or real value", valueRef);
+ break;
+ case INT:
+ if (!(value instanceof IntLiteral))
+ error("must be an integer", valueRef);
+ break;
+ case CHAR:
+ if (!(value instanceof StringLiteral))
+ error("must be a string", valueRef);
+ else {
+ if (values.size() > 1)
+ error("multiplicity must be one", valueRef);
+ StringLiteral strValue = (StringLiteral) value;
+ if (attribute.getSize() > 0
+ && attrMult < strValue.getValue().length())
+ error("too many characters - maximal length is "
+ + attrMult, valueRef);
+ }
+ break;
+ }
+ }
+
+ // numeric check
+ if ((type == LiteralType.INT || type == LiteralType.REAL)) {
+ ActorClassConfig classConfig = null;
+ if (config.eContainer() instanceof ActorInstanceConfig) {
+ ActorInstanceConfig actorConfig = (ActorInstanceConfig) config
+ .eContainer();
+ ActorContainerClass actorClass = ConfigUtil.resolve(
+ actorConfig.getRoot(), actorConfig.getPath());
+ // find ActorClassConfig
+ ConfigModel model = getConfigModel(actorConfig);
+ for (ActorClassConfig cf : model.getActorClassConfigs()) {
+ if (cf.getActor().equals(actorClass)) {
+ classConfig = cf;
+ break;
+ }
+ }
+ } else if (config.eContainer() instanceof ActorClassConfig)
+ classConfig = (ActorClassConfig) config.eContainer();
+
+ AttrClassConfig attrClassConfig = null;
+ if (classConfig != null) {
+ for (AttrClassConfig acf : classConfig.getAttributes())
+ if (config.getAttribute().equals(acf.getAttribute())) {
+ attrClassConfig = acf;
+ break;
+ }
+ }
+
+ if (attrClassConfig != null) {
+ NumberLiteral min = attrClassConfig.getMin();
+ NumberLiteral max = attrClassConfig.getMax();
+ for (Literal value : values) {
+ if (!(value instanceof NumberLiteral))
+ continue;
+
+ 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));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void checkAttrConfigMin(PrimitiveType primitive,
+ AttrClassConfig config) {
+ NumberLiteral min = config.getMin();
+ if (min == null)
+ return;
+
+ EReference minRef = ConfigPackage.eINSTANCE.getAttrClassConfig_Min();
+ LiteralType type = primitive.getType();
+
+ 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
+ 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);
+ }
+
+ }
+ }
+
+ }
+
+ private void checkAttrConfigMax(PrimitiveType primitive,
+ AttrClassConfig config) {
+ NumberLiteral max = config.getMax();
+ if (max == null)
+ return;
+
+ EReference maxRef = ConfigPackage.eINSTANCE.getAttrClassConfig_Max();
+ LiteralType type = primitive.getType();
+
+ 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
+ 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);
+ }
+
+ }
+ }
+ }
+
+ private ConfigModel getConfigModel(EObject object) {
+ EObject root = object;
+ while (root.eContainer() != null)
+ root = root.eContainer();
+
+ return (ConfigModel) root;
+ }
+
+ private String refPathToString(RefPath path) {
+ String str = "";
+ for (String s : path.getRefs())
+ str += "/" + s;
+
+ return str;
+ }
+}

Back to the top