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 3aa5358b authored by Dominique Marcadet's avatar Dominique Marcadet

use RiseClipse formatter

parent f83ba91a
......@@ -18,7 +18,6 @@
*/
package fr.centralesupelec.edf.riseclipse.iec61850.scl.validator;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
......@@ -42,25 +41,25 @@ import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole;
import fr.centralesupelec.edf.riseclipse.util.RiseClipseModelLoader;
import fr.centralesupelec.edf.riseclipse.util.TextRiseClipseConsole;
public class NsdModelLoader extends RiseClipseModelLoader {
public class NsdModelLoader extends RiseClipseModelLoader {
public NsdModelLoader( IRiseClipseConsole console ) {
super( console );
}
@Override
public void reset() {
super.reset(new NsdResourceSetImpl(true, console) );
super.reset( new NsdResourceSetImpl( true, console ) );
// Register the appropriate resource factory to handle all file
// extensions.
getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap()
.put( Resource.Factory.Registry.DEFAULT_EXTENSION, new NsdResourceFactoryImpl() );
.put( Resource.Factory.Registry.DEFAULT_EXTENSION, new NsdResourceFactoryImpl() );
// Register the package to ensure it is available during loading.
getResourceSet().getPackageRegistry().put( NsdPackage.eNS_URI, NsdPackage.eINSTANCE );
}
@Override
public NsdResourceSetImpl getResourceSet() {
return ( NsdResourceSetImpl ) super.getResourceSet();
......@@ -70,48 +69,49 @@ public class NsdModelLoader extends RiseClipseModelLoader {
Object eValidator = EValidator.Registry.INSTANCE.remove( NsdPackage.eINSTANCE );
Resource resource = load( name );
if( eValidator != null ) {
EValidator.Registry.INSTANCE.put( NsdPackage.eINSTANCE, eValidator );
}
return resource;
}
public static void main( String[] args ) {
IRiseClipseConsole console = new TextRiseClipseConsole();
//console.setLevel( IRiseClipseConsole.ERROR_LEVEL );
NsdModelLoader loader = new NsdModelLoader( console );
org.eclipse.ocl.xtext.oclinecore.OCLinEcoreStandaloneSetup.doSetup();
Map<Object, Object> context = new HashMap< Object, Object >();
Map< Object, Object > context = new HashMap< Object, Object >();
SubstitutionLabelProvider substitutionLabelProvider = new EValidator.SubstitutionLabelProvider() {
@Override
public String getValueLabel( EDataType eDataType, Object value ) {
return Diagnostician.INSTANCE.getValueLabel( eDataType, value );
}
@Override
public String getObjectLabel( EObject eObject ) {
NsdItemProviderAdapterFactory adapter = new NsdItemProviderAdapterFactory();
IItemLabelProvider labelProvider = ( IItemLabelProvider ) adapter .adapt( eObject, IItemLabelProvider.class );
IItemLabelProvider labelProvider = ( IItemLabelProvider ) adapter.adapt( eObject,
IItemLabelProvider.class );
return labelProvider.getText( eObject );
}
@Override
public String getFeatureLabel( EStructuralFeature eStructuralFeature ) {
return Diagnostician.INSTANCE.getFeatureLabel( eStructuralFeature );
}
};
context.put(EValidator.SubstitutionLabelProvider.class, substitutionLabelProvider );
context.put( EValidator.SubstitutionLabelProvider.class, substitutionLabelProvider );
for( int i = 0; i < args.length; ++i ) {
Resource resource = loader.load( args[i] );
if( resource == null ) continue;
if( resource.getContents().size() == 0 ) continue;
Diagnostic diagnostic = Diagnostician.INSTANCE.validate( resource.getContents().get( 0 ), context );
if( diagnostic.getSeverity() == Diagnostic.ERROR || diagnostic.getSeverity() == Diagnostic.WARNING ) {
for( Iterator< Diagnostic > d = diagnostic.getChildren().iterator(); d.hasNext(); ) {
Diagnostic childDiagnostic = d.next();
......
......@@ -45,9 +45,9 @@ public class NsdValidator {
public NsdValidator( @NonNull ComposedEValidator validator, IRiseClipseConsole console ) {
nsdLoader = new NsdModelLoader( console );
validator.addChild( new NsdEObjectValidator( nsdLoader.getResourceSet() ));
validator.addChild( new NsdEObjectValidator( nsdLoader.getResourceSet() ) );
}
public void addNsdDocument( String nsdFile, IRiseClipseConsole console ) {
console.info( "Loading nsd: " + nsdFile );
nsdLoader.load( nsdFile );
......@@ -55,31 +55,32 @@ public class NsdValidator {
public void validate( Resource resource, final AdapterFactory adapter, IRiseClipseConsole console ) {
nsdLoader.getResourceSet().finalizeLoad( console );
Map<Object, Object> context = new HashMap< Object, Object >();
Map< Object, Object > context = new HashMap< Object, Object >();
SubstitutionLabelProvider substitutionLabelProvider = new EValidator.SubstitutionLabelProvider() {
@Override
public String getValueLabel( EDataType eDataType, Object value ) {
return Diagnostician.INSTANCE.getValueLabel( eDataType, value );
}
@Override
public String getObjectLabel( EObject eObject ) {
IItemLabelProvider labelProvider = ( IItemLabelProvider ) adapter.adapt( eObject, IItemLabelProvider.class );
IItemLabelProvider labelProvider = ( IItemLabelProvider ) adapter.adapt( eObject,
IItemLabelProvider.class );
return labelProvider.getText( eObject );
}
@Override
public String getFeatureLabel( EStructuralFeature eStructuralFeature ) {
return Diagnostician.INSTANCE.getFeatureLabel( eStructuralFeature );
}
};
context.put(EValidator.SubstitutionLabelProvider.class, substitutionLabelProvider );
context.put( EValidator.SubstitutionLabelProvider.class, substitutionLabelProvider );
for( int n = 0; n < resource.getContents().size(); ++n ) {
Diagnostic diagnostic = Diagnostician.INSTANCE.validate( resource.getContents().get( n ), context );
if( diagnostic.getSeverity() == Diagnostic.ERROR || diagnostic.getSeverity() == Diagnostic.WARNING ) {
//EObject root = ( EObject ) diagnostic.getData().get( 0 );
//URI uri = root.eResource().getURI();
......@@ -97,7 +98,9 @@ public class NsdValidator {
else if( data.get( 1 ) instanceof EAttribute ) {
EAttribute attribute = ( EAttribute ) data.get( 1 );
if( attribute == null ) continue;
console.error( "\tAttribute " + attribute.getName() + " of " + substitutionLabelProvider.getObjectLabel( object ) + " : " + childDiagnostic.getChildren().get( 0 ).getMessage() );
console.error( "\tAttribute " + attribute.getName() + " of "
+ substitutionLabelProvider.getObjectLabel( object ) + " : "
+ childDiagnostic.getChildren().get( 0 ).getMessage() );
}
else {
console.error( "\t" + childDiagnostic.getMessage() );
......
......@@ -18,7 +18,6 @@
*/
package fr.centralesupelec.edf.riseclipse.iec61850.scl.validator;
import java.io.File;
import java.util.ArrayList;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.provider.NsdItemProviderAdapterFactory;
......@@ -26,10 +25,6 @@ import fr.centralesupelec.edf.riseclipse.iec61850.scl.SclPackage;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.provider.SclItemProviderAdapterFactory;
import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole;
import fr.centralesupelec.edf.riseclipse.util.TextRiseClipseConsole;
import fr.centralesupelec.edf.riseclipse.validation.ocl.OCLValidator;
import org.eclipse.emf.ecore.EValidator;
//import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.pivot.validation.ComposedEValidator;
......@@ -46,33 +41,34 @@ public class RiseClipseValidatorSCL {
public static void usage( IRiseClipseConsole console ) {
console.setLevel( IRiseClipseConsole.INFO_LEVEL );
console.info( "java -jar RiseClipseValidatorSCL.jar [--verbose] [--make-explicit-links] [<oclFile> | <nsdFile> | <sclFile>]*" );
console.info(
"java -jar RiseClipseValidatorSCL.jar [--verbose] [--make-explicit-links] [<oclFile> | <nsdFile> | <sclFile>]*" );
console.info( /*"Files ending with \".ocl\" are considered OCL files, "
+*/ "files ending with \\\".nsd\\\" are considered NSD files, "
+ "all others are considered SCL files" );
+*/ "files ending with \\\".nsd\\\" are considered NSD files, "
+ "all others are considered SCL files" );
System.exit( -1 );
}
public static void main( String[] args ) {
final IRiseClipseConsole console = new TextRiseClipseConsole();
console.setLevel( IRiseClipseConsole.INFO_LEVEL );
displayLegal( console );
console.setLevel( IRiseClipseConsole.WARNING_LEVEL );
if( args.length == 0 ) usage( console );
boolean make_explicit_links = false;
int posFiles = 0;
for( int i = 0; i < args.length; ++i ) {
if( args[i].startsWith( "--" )) {
if( args[i].startsWith( "--" ) ) {
posFiles = i + 1;
if( "--verbose".equals( args[i] )) {
if( "--verbose".equals( args[i] ) ) {
console.setLevel( IRiseClipseConsole.INFO_LEVEL );
}
else if( "--make-explicit-links".equals( args[i] )) {
else if( "--make-explicit-links".equals( args[i] ) ) {
make_explicit_links = true;
}
else {
......@@ -90,7 +86,7 @@ public class RiseClipseValidatorSCL {
oclFiles.add( args[i] );
oclValidation = true;
}
else*/ if( args[i].endsWith( ".nsd" )) {
else*/ if( args[i].endsWith( ".nsd" ) ) {
nsdFiles.add( args[i] );
nsdValidation = true;
}
......@@ -98,17 +94,19 @@ public class RiseClipseValidatorSCL {
sclFiles.add( args[i] );
}
}
prepare( console, /*oclFiles,*/ nsdFiles );
for( int i = 0; i < sclFiles.size(); ++i ) {
run( console, make_explicit_links, sclFiles.get( i ));
run( console, make_explicit_links, sclFiles.get( i ) );
}
}
public static void displayLegal( IRiseClipseConsole console ) {
console.info( "Copyright (c) 2019 CentraleSupélec & EDF." );
console.info( "All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0" );
console.info( "which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html" );
console.info(
"All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0" );
console.info(
"which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html" );
console.info( "" );
console.info( "This file is part of the RiseClipse tool." );
console.info( "Contributors:" );
......@@ -124,18 +122,19 @@ public class RiseClipseValidatorSCL {
console.info( "" );
}
public static void prepare( IRiseClipseConsole console, /*ArrayList< String > oclFiles,*/ ArrayList< String > nsdFiles ) {
public static void prepare( IRiseClipseConsole console,
/*ArrayList< String > oclFiles,*/ ArrayList< String > nsdFiles ) {
@NonNull
ComposedEValidator validator = ComposedEValidator.install( SclPackage.eINSTANCE );
/*if( oclValidation ) {
oclValidator = new OCLValidator( validator, true );
for( int i = 0; i < oclFiles.size(); ++i ) {
oclValidator.addOCLDocument( oclFiles.get( i ), console );
}
}*/
if( nsdValidation ) {
nsdValidator = new NsdValidator( validator, console );
for( int i = 0; i < nsdFiles.size(); ++i ) {
......@@ -146,13 +145,13 @@ public class RiseClipseValidatorSCL {
sclLoader = new SCLModelLoader( console );
sclAdapter = new SclItemProviderAdapterFactory();
/*for(EValidator v: validator.getChildren()) {
if(v.getClass() == NsdEObjectValidator.class) {
NsdEObjectValidator nsdValidator = (NsdEObjectValidator) v;
nsdValidator.initializeValidationData();
}
}*/
/*for(EValidator v: validator.getChildren()) {
if(v.getClass() == NsdEObjectValidator.class) {
NsdEObjectValidator nsdValidator = (NsdEObjectValidator) v;
nsdValidator.initializeValidationData();
}
}*/
}
public static void run( IRiseClipseConsole console, boolean make_explicit_links, String sclFile ) {
......@@ -171,8 +170,7 @@ public class RiseClipseValidatorSCL {
console.info( "Validating file: " + sclFile + " with NSD" );
nsdValidator.validate( resource, sclAdapter, console );
}
}
}
}
}
......@@ -27,9 +27,8 @@ import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole;
import fr.centralesupelec.edf.riseclipse.util.RiseClipseModelLoader;
import fr.centralesupelec.edf.riseclipse.util.TextRiseClipseConsole;
public class SCLModelLoader extends RiseClipseModelLoader {
public SCLModelLoader( IRiseClipseConsole console ) {
super( console );
}
......@@ -41,27 +40,27 @@ public class SCLModelLoader extends RiseClipseModelLoader {
// Register the appropriate resource factory to handle all file
// extensions.
getResourceSet().getResourceFactoryRegistry().getExtensionToFactoryMap()
.put( Resource.Factory.Registry.DEFAULT_EXTENSION, new SclResourceFactoryImpl() );
.put( Resource.Factory.Registry.DEFAULT_EXTENSION, new SclResourceFactoryImpl() );
// Register the package to ensure it is available during loading.
getResourceSet().getPackageRegistry().put( SclPackage.eNS_URI, SclPackage.eINSTANCE );
}
public Resource loadWithoutValidation( String name ) {
Object eValidator = EValidator.Registry.INSTANCE.remove( SclPackage.eINSTANCE );
Resource resource = load( name );
if( eValidator != null ) {
EValidator.Registry.INSTANCE.put( SclPackage.eINSTANCE, eValidator );
}
return resource;
}
public static void main( String[] args ) {
IRiseClipseConsole console = new TextRiseClipseConsole();
SCLModelLoader loader = new SCLModelLoader( console );
for( int i = 0; i < args.length; ++i ) {
@SuppressWarnings( "unused" )
Resource resource = loader.load( args[i] );
......
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