Commit 5fe034e7 authored by Dominique Marcadet's avatar Dominique Marcadet

improve types and values verification

parent 6fcbda81
...@@ -27,8 +27,10 @@ import org.eclipse.emf.common.util.DiagnosticChain; ...@@ -27,8 +27,10 @@ import org.eclipse.emf.common.util.DiagnosticChain;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.Enumeration; import fr.centralesupelec.edf.riseclipse.iec61850.nsd.Enumeration;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.AbstractDataAttribute; import fr.centralesupelec.edf.riseclipse.iec61850.scl.AbstractDataAttribute;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DAI;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.EnumType; import fr.centralesupelec.edf.riseclipse.iec61850.scl.EnumType;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.EnumVal; import fr.centralesupelec.edf.riseclipse.iec61850.scl.EnumVal;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.UnNaming;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.Val; import fr.centralesupelec.edf.riseclipse.iec61850.scl.Val;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.RiseClipseValidatorSCL; import fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.RiseClipseValidatorSCL;
import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole; import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole;
...@@ -69,7 +71,7 @@ public class EnumerationValidator extends TypeValidator { ...@@ -69,7 +71,7 @@ public class EnumerationValidator extends TypeValidator {
Diagnostic.WARNING, Diagnostic.WARNING,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0, 0,
"[NSD validation] validator for inherited enumeration " + inheritedFromName + " not found", "[NSD validation] validator for inherited enumeration \"" + inheritedFromName + "\" not found",
new Object[] { ada } )); new Object[] { ada } ));
// Avoid checking again // Avoid checking again
inheritedFromName = null; inheritedFromName = null;
...@@ -82,7 +84,7 @@ public class EnumerationValidator extends TypeValidator { ...@@ -82,7 +84,7 @@ public class EnumerationValidator extends TypeValidator {
Diagnostic.ERROR, Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0, 0,
"[NSD validation] bType of DA/BDA " + ada.getName() + " line = " + ada.getLineNumber() + ") is not Enum", "[NSD validation] bType of DA/BDA \"" + ada.getName() + "\" (line = " + ada.getLineNumber() + ") is not Enum",
new Object[] { ada } )); new Object[] { ada } ));
res = false; res = false;
} }
...@@ -91,7 +93,7 @@ public class EnumerationValidator extends TypeValidator { ...@@ -91,7 +93,7 @@ public class EnumerationValidator extends TypeValidator {
Diagnostic.ERROR, Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0, 0,
"[NSD validation] type of DA/BDA " + ada.getName() + " line = " + ada.getLineNumber() + ") is not " + getName(), "[NSD validation] type of DA/BDA \"" + ada.getName() + "\" (line = " + ada.getLineNumber() + ") is not " + getName(),
new Object[] { ada } )); new Object[] { ada } ));
res = false; res = false;
} }
...@@ -103,23 +105,32 @@ public class EnumerationValidator extends TypeValidator { ...@@ -103,23 +105,32 @@ public class EnumerationValidator extends TypeValidator {
res = validateEnumType( ada.getRefersToEnumType(), diagnostics ) && res; res = validateEnumType( ada.getRefersToEnumType(), diagnostics ) && res;
} }
for( DAI dai : ada.getReferredByDAI() ) {
// name is OK because it has been used to create link DAI -> DA
for( Val val : dai.getVal() ) {
res = validateValue( dai, val.getValue(), diagnostics ) && res;
}
}
return res; return res;
} }
protected boolean validateValue( AbstractDataAttribute ada, String value, DiagnosticChain diagnostics ) { protected boolean validateValue( UnNaming daOrDai, String value, DiagnosticChain diagnostics ) {
boolean res = true; boolean res = true;
if( ! literals.containsKey( value )) { if( ! literals.containsKey( value )) {
if( inheritedFrom != null ) { if( inheritedFrom != null ) {
res = inheritedFrom.validateValue( ada, value, diagnostics ) && res; res = inheritedFrom.validateValue( daOrDai, value, diagnostics ) && res;
} }
else { else {
String name = "";
if( daOrDai instanceof AbstractDataAttribute ) name = (( AbstractDataAttribute ) daOrDai ).getName();
if( daOrDai instanceof DAI ) name = (( DAI ) daOrDai ).getName();
diagnostics.add( new BasicDiagnostic( diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR, Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0, 0,
"[NSD validation] value of DA/BDA " + ada.getName() + " line = " + ada.getLineNumber() + ") is not valid", "[NSD validation] value \"" + value + "\" of DA/BDA \"" + name + "\" (line = " + daOrDai.getLineNumber() + ") is not valid for enumeration \"" + this.name + "\"",
new Object[] { ada } )); new Object[] { daOrDai } ));
res = false; res = false;
} }
} }
...@@ -146,7 +157,7 @@ public class EnumerationValidator extends TypeValidator { ...@@ -146,7 +157,7 @@ public class EnumerationValidator extends TypeValidator {
Diagnostic.ERROR, Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0, 0,
"[NSD validation] EnumVal " + enumVal.getValue() + " in EnumType (id = " + enumType.getId() "[NSD validation] EnumVal \"" + enumVal.getValue() + "\" in EnumType (id = " + enumType.getId()
+ ") at line " + enumVal.getLineNumber() + " is unknown", + ") at line " + enumVal.getLineNumber() + " is unknown",
new Object[] { enumVal } )); new Object[] { enumVal } ));
res = false; res = false;
...@@ -160,7 +171,7 @@ public class EnumerationValidator extends TypeValidator { ...@@ -160,7 +171,7 @@ public class EnumerationValidator extends TypeValidator {
Diagnostic.ERROR, Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0, 0,
"[NSD validation] EnumVal " + enumVal.getValue() + " in EnumType (id = " + enumType.getId() "[NSD validation] EnumVal \"" + enumVal.getValue() + "\" in EnumType (id = " + enumType.getId()
+ ") at line " + enumVal.getLineNumber() + " has incorrect ord (" + enumVal.getOrd() + ") at line " + enumVal.getLineNumber() + " has incorrect ord (" + enumVal.getOrd()
+ " instead of " + literals.get( enumVal.getValue() ) + ")", + " instead of " + literals.get( enumVal.getValue() ) + ")",
new Object[] { enumVal } )); new Object[] { enumVal } ));
...@@ -172,7 +183,7 @@ public class EnumerationValidator extends TypeValidator { ...@@ -172,7 +183,7 @@ public class EnumerationValidator extends TypeValidator {
Diagnostic.ERROR, Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0, 0,
"[NSD validation] EnumVal " + enumVal.getValue() + " in EnumType (id = " + enumType.getId() "[NSD validation] EnumVal \"" + enumVal.getValue() + "\" in EnumType (id = " + enumType.getId()
+ ") at line " + enumVal.getLineNumber() + " is not an integer", + ") at line " + enumVal.getLineNumber() + " is not an integer",
new Object[] { enumVal } )); new Object[] { enumVal } ));
res = false; res = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment