Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 02d9b600 authored by Dominique Marcadet's avatar Dominique Marcadet

display line numbers in messages

parent b5948ec8
......@@ -43,6 +43,7 @@ public class AnyLNValidator {
this.lnClass = lnClass.getName();
this.doMap = new HashMap<>(); // link between DOI (name) and its respective DataObject
this.cdcMap = new HashMap<>(); // link between CDC (name) and its respective DOIValidator
generateValidators( doMap, cdcMap, lnClass );
// LNClass hierarchy taken into account
......@@ -56,10 +57,10 @@ public class AnyLNValidator {
public void generateValidators( HashMap< String, DataObject > doMap, HashMap< String, DOIValidator > cdcMap, AnyLNClass lnClass ) {
for( DataObject dObj : lnClass.getDataObject() ) {
this.doMap.put( dObj.getName(), dObj );
doMap.put( dObj.getName(), dObj );
if( dObj.getRefersToCDC() != null ) {
if( ! cdcMap.containsKey( dObj.getRefersToCDC().getName() )) {
this.cdcMap.put( dObj.getRefersToCDC().getName(), new DOIValidator( dObj.getRefersToCDC() ));
cdcMap.put( dObj.getRefersToCDC().getName(), new DOIValidator( dObj.getRefersToCDC() ));
}
}
}
......@@ -74,19 +75,18 @@ public class AnyLNValidator {
AbstractRiseClipseConsole.getConsole().verbose( "validateDOI( " + doi.getName() + " )" );
// Test if DOI is a possible DOI in this LN
if( ! this.doMap.containsKey( doi.getName() ) ) {
if( ! doMap.containsKey( doi.getName() ) ) {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"DO " + doi.getName() + " not found in LNClass " + ln.getLnClass(),
"DO " + doi.getName() + " in LN at line " + ln.getLineNumber() + " not found in LNClass " + ln.getLnClass(),
new Object[] { ln } ));
continue;
}
// Control of DOI presence in LN
String presCond = this.doMap.get( doi.getName() ).getPresCond();
this.updateCompulsory( doi, presCond, checkedDO, diagnostics );
updateCompulsory( doi, checkedDO, diagnostics );
// Validation of DOI content
if( ! validateDOI( doi, diagnostics ) ) {
......@@ -96,29 +96,29 @@ public class AnyLNValidator {
}
// Verify all necessary DOI were present
if( ! this.doMap.entrySet().stream()
.map( x -> checkCompulsory( ln, x.getKey(), x.getValue().getPresCond(), checkedDO, diagnostics ))
if( ! doMap.values().stream()
.map( x -> checkCompulsory( ln, x, checkedDO, diagnostics ))
.reduce( ( a, b ) -> a && b ).get() ) {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"LN does not contain all mandatory DO from class " + ln.getLnClass(),
"LN at line " + ln.getLineNumber() + " does not contain all mandatory DO from class " + ln.getLnClass(),
new Object[] { ln } ));
res = false;
}
return res;
}
public boolean checkCompulsory( AnyLN ln, String name, String presCond, HashSet< String > checkedDO, DiagnosticChain diagnostics ) {
switch( presCond ) {
public boolean checkCompulsory( AnyLN ln, DataObject dataObject, HashSet< String > checkedDO, DiagnosticChain diagnostics ) {
switch( dataObject.getPresCond() ) {
case "M":
if( ! checkedDO.contains( name ) ) {
if( ! checkedDO.contains( dataObject.getName() ) ) {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"DO " + name + " is missing",
"DO " + dataObject.getName() + " is missing in LN at line " + ln.getLineNumber(),
new Object[] { ln } ));
return false;
}
......@@ -126,8 +126,8 @@ public class AnyLNValidator {
return true;
}
public boolean updateCompulsory( DOI doi, String presCond, HashSet< String > checkedDO, DiagnosticChain diagnostics ) {
switch( presCond ) {
public boolean updateCompulsory( DOI doi, HashSet< String > checkedDO, DiagnosticChain diagnostics ) {
switch( doMap.get( doi.getName() ).getPresCond() ) {
case "M":
case "O":
if( checkedDO.contains( doi.getName() )) {
......@@ -135,20 +135,18 @@ public class AnyLNValidator {
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"DO " + doi + " cannot appear more than once",
"DO " + doi + " cannot appear more than once in LN at line " + doi.getAnyLN().getLineNumber(),
new Object[] { doi } ));
return false;
}
else {
checkedDO.add( doi.getName() );
break;
}
checkedDO.add( doi.getName() );
break;
case "F":
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"DO " + doi + " is forbidden",
"DO " + doi + " is forbidden in LN at line " + doi.getAnyLN().getLineNumber(),
new Object[] { doi } ));
return false;
}
......@@ -157,10 +155,10 @@ public class AnyLNValidator {
public boolean validateDOI( DOI doi, DiagnosticChain diagnostics ) {
AbstractRiseClipseConsole.getConsole().verbose( "found DO " + doi.getName() + " in LNClass " + this.lnClass );
AbstractRiseClipseConsole.getConsole().verbose( "found DO " + doi.getName() + " in LNClass " + lnClass );
// DOIValidator validates DOI content
String cdc = this.doMap.get( doi.getName() ).getRefersToCDC().getName();
String cdc = doMap.get( doi.getName() ).getRefersToCDC().getName();
return cdcMap.get( cdc ).validateDOI( doi, diagnostics );
}
......
......@@ -40,6 +40,7 @@ public class DOIValidator {
public DOIValidator( CDC cdc ) {
this.cdc = cdc.getName();
this.daMap = new HashMap<>(); // link between DAI (name) and its respective DataAttribute
for( DataAttribute da : cdc.getDataAttribute() ) {
this.daMap.put( da.getName(), da );
}
......@@ -50,22 +51,22 @@ public class DOIValidator {
HashSet< String > checkedDA = new HashSet<>();
for( DAI dai : doi.getDAI() ) {
AbstractRiseClipseConsole.getConsole().verbose( "validateDAI( " + dai.getName() + " )" );
AbstractRiseClipseConsole.getConsole().verbose( "validateDAI( " + dai.getName() + " ) (line" + dai.getLineNumber() + ")" );
// Test if DAI is a possible DAI in this DOI
if( ! this.daMap.containsKey( dai.getName() ) ) {
if( ! daMap.containsKey( dai.getName() ) ) {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"DA " + dai.getName() + " not found in CDC",
"DAI " + dai.getName() + " (line" + dai.getLineNumber() + ") not found in CDC",
new Object[] { doi, cdc } ));
res = false;
continue;
}
// Control of DAI presence in DOI
this.updateCompulsory( dai, checkedDA, diagnostics );
updateCompulsory( dai, checkedDA, diagnostics );
// Validation of DAI content
if( ! validateDAI( dai, diagnostics ) ) {
......@@ -75,21 +76,21 @@ public class DOIValidator {
}
// Verify all necessary DAI were present
if( ! this.daMap.values().stream()
.map( x -> checkCompulsory( x, checkedDA, diagnostics ) )
if( ! daMap.values().stream()
.map( x -> checkCompulsory( doi, x, checkedDA, diagnostics ) )
.reduce( ( a, b ) -> a && b ).get() ) {
diagnostics.add( new BasicDiagnostic(
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"DO does not contain all mandatory DA from CDC ",
"DOI (line " + doi.getLineNumber() + ") does not contain all mandatory DA from CDC ",
new Object[] { doi, cdc } ));
res = false;
}
return res;
}
public boolean checkCompulsory( DataAttribute da, HashSet< String > checked, DiagnosticChain diagnostics ) {
public boolean checkCompulsory( DOI doi, DataAttribute da, HashSet< String > checked, DiagnosticChain diagnostics ) {
switch( da.getPresCond() ) {
case "M":
if( ! checked.contains( da.getName() )) {
......@@ -97,7 +98,7 @@ public class DOIValidator {
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"DA " + da.getName() + " not found in CDC",
"DA " + da.getName() + " not found in DOI (line " + doi.getLineNumber() + ")",
new Object[] { da } ));
return false;
}
......@@ -106,7 +107,7 @@ public class DOIValidator {
}
public boolean updateCompulsory( DAI dai, HashSet< String > checked, DiagnosticChain diagnostics ) {
switch( this.daMap.get( dai.getName() ).getPresCond() ) {
switch( daMap.get( dai.getName() ).getPresCond() ) {
case "M":
case "O":
if( checked.contains( dai.getName() ) ) {
......@@ -114,7 +115,7 @@ public class DOIValidator {
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"DA " + dai.getName() + " cannot appear more than once",
"DAI " + dai.getName() + " (line " + dai.getLineNumber() + ") cannot appear more than once",
new Object[] { dai } ));
return false;
}
......@@ -127,7 +128,7 @@ public class DOIValidator {
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"DA " + dai.getName() + " is forbidden",
"DAI " + dai.getName() + " (line " + dai.getLineNumber() + ") is forbidden",
new Object[] { dai } ));
return false;
}
......@@ -136,10 +137,10 @@ public class DOIValidator {
public boolean validateDAI( DAI dai, DiagnosticChain diagnostics ) {
AbstractRiseClipseConsole.getConsole().verbose( "found DA " + dai.getName() + " in CDC " + this.cdc );
AbstractRiseClipseConsole.getConsole().verbose( "found DA " + dai.getName() + " in CDC " + cdc );
// DataAttributes that are BASIC have a BasicType which describes allowed Val of DA
DataAttribute da = this.daMap.get( dai.getName() );
DataAttribute da = daMap.get( dai.getName() );
if( da.getTypeKind().getName().equals( "BASIC" ) ) {
for( Val val : dai.getVal() ) {
if( ! validateVal( val.getValue(), da.getType() )) {
......@@ -147,11 +148,11 @@ public class DOIValidator {
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"Val " + val.getValue() + " of DA " + dai.getName() + " is not of type " + da.getType(),
"Val " + val.getValue() + " (" + dai.getLineNumber() + ") of DA " + dai.getName() + " is not of type " + da.getType(),
new Object[] { dai, val } ));
return false;
}
AbstractRiseClipseConsole.getConsole().verbose( "Val " + val.getValue() + " of DA " + dai.getName() +
AbstractRiseClipseConsole.getConsole().verbose( "Val " + val.getValue() + " (" + dai.getLineNumber() + ") of DA " + dai.getName() +
" is of type " + da.getType() );
}
}
......
......@@ -75,14 +75,14 @@ public class NsdEObjectValidator implements EValidator {
AnyLN ln = ( AnyLN ) eObject;
return validateLN( ln, diagnostics );
default:
AbstractRiseClipseConsole.getConsole().info( "NOT IMPLEMENTED: NSDEObjectValidator.validate( " + eClass.getName() + " )" );
AbstractRiseClipseConsole.getConsole().info( "NOT IMPLEMENTED: NsdEObjectValidator.validate( " + eClass.getName() + " )" );
return false;
}
}
@Override
public boolean validate( EDataType eDataType, Object value, DiagnosticChain diagnostics, Map< Object, Object > context ) {
AbstractRiseClipseConsole.getConsole().info( "NOT IMPLEMENTED: NSDEObjectValidator.validate( " + eDataType.getName() +" )" );
AbstractRiseClipseConsole.getConsole().info( "NOT IMPLEMENTED: NsdEObjectValidator.validate( " + eDataType.getName() + " )" );
// TODO: use nsdResource to validate value
......@@ -91,7 +91,7 @@ public class NsdEObjectValidator implements EValidator {
public boolean validateLN( AnyLN ln, DiagnosticChain diagnostics ) {
AbstractRiseClipseConsole.getConsole().verbose( "" );
AbstractRiseClipseConsole.getConsole().verbose( "NSDEObjectValidator.validateLN( " + ln.getLnClass() + " )" );
AbstractRiseClipseConsole.getConsole().verbose( "NsdEObjectValidator.validateLN( " + ln.getLnClass() + " )" );
// Check that LN has valid LNClass
if( ! this.lnMap.containsKey( ln.getLnClass() )) {
......@@ -99,11 +99,11 @@ public class NsdEObjectValidator implements EValidator {
Diagnostic.ERROR,
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"LNClass " + ln.getLnClass() + " not found in NSD files",
"LNClass " + ln.getLnClass() + " not found in NSD files for LN at line " + ln.getLineNumber(),
new Object[] { ln } ));
return false;
}
AbstractRiseClipseConsole.getConsole().verbose( "found LNClass " + ln.getLnClass() + " in NSD files" );
AbstractRiseClipseConsole.getConsole().verbose( "found LNClass " + ln.getLnClass() + " in NSD files for LN at line " + ln.getLineNumber() );
// AnyLNValidator validates LN content
return lnMap.get( ln.getLnClass() ).validateLN( ln, diagnostics );
......
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