下面列出了怎么用org.eclipse.emf.ecore.EValidator的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public boolean validate ( final EObject eObject, final DiagnosticChain diagnostics, final Map<Object, Object> context )
{
boolean result = true;
for ( final EValidator v : this.otherValidators )
{
if ( !v.validate ( eObject, diagnostics, context ) )
{
result = false;
}
}
ValidationPlugin.runValidation ( eObject, diagnostics, context );
return result;
}
@Override
public boolean validate ( final EClass eClass, final EObject eObject, final DiagnosticChain diagnostics, final Map<Object, Object> context )
{
boolean result = true;
for ( final EValidator v : this.otherValidators )
{
if ( !v.validate ( eClass, eObject, diagnostics, context ) )
{
result = false;
}
}
ValidationPlugin.runValidation ( eObject, diagnostics, context );
return result;
}
@Test public void testFullBuildBigProjectWithRefeernceToJar() throws Exception {
IJavaProject project = workspace.createJavaProject("foo");
workspace.addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
IFolder folder = project.getProject().getFolder("src");
IFile jarFile = project.getProject().getFile("my.jar");
jarFile.create(jarInputStream(new TextFile("my/element"+F_EXT,"object ReferenceMe")), true, workspace.monitor());
workspace.addJarToClasspath(project, jarFile);
int NUM_FILES = 2000;
IFile[] files = new IFile[NUM_FILES];
StopWatch timer = new StopWatch();
for (int i = 0; i < NUM_FILES; i++) {
IFile file = folder.getFile("Test_" + i + "_" + F_EXT);
files[i] = file;
String contents = "object Foo" + i + " references ReferenceMe";
file.create(new StringInputStream(contents), true, workspace.monitor());
}
logAndReset("Creating files", timer);
workspace.build();
logAndReset("Auto build", timer);
IMarker[] iMarkers = folder.findMarkers(EValidator.MARKER, true, IResource.DEPTH_INFINITE);
for (IMarker iMarker : iMarkers) {
System.out.println(iMarker.getAttribute(IMarker.MESSAGE));
}
assertEquals(0,iMarkers.length);
}
@Test public void testFullBuildBigProjectWithLinkingErrors() throws Exception {
IJavaProject project = workspace.createJavaProject("foo");
workspace.addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
IFolder folder = project.getProject().getFolder("src");
int NUM_FILES = 200;
IFile[] files = new IFile[NUM_FILES];
StopWatch timer = new StopWatch();
for (int i = 0; i < NUM_FILES; i++) {
IFile file = folder.getFile("Test_" + i + "_" + F_EXT);
files[i] = file;
String contents = "object Foo" + i + " references Foo" + (i * 1000);
if (i == NUM_FILES)
contents = "object Foo" + i;
file.create(new StringInputStream(contents), true, workspace.monitor());
}
logAndReset("Creating files", timer);
workspace.build();
logAndReset("Auto build", timer);
IMarker[] iMarkers = folder.findMarkers(EValidator.MARKER, true, IResource.DEPTH_INFINITE);
assertEquals(NUM_FILES-1,iMarkers.length);
}
@Test public void testFullBuildBigProjectWithSyntaxErrors() throws Exception {
IJavaProject project = workspace.createJavaProject("foo");
workspace.addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
IFolder folder = project.getProject().getFolder("src");
int NUM_FILES = 500;
IFile[] files = new IFile[NUM_FILES];
StopWatch timer = new StopWatch();
for (int i = 0; i < NUM_FILES; i++) {
IFile file = folder.getFile("Test_" + i + "_" + F_EXT);
files[i] = file;
String contents = "object Foo" + i + " references Foo" + (i * 1000);
if (i == NUM_FILES)
contents = "object Foo" + i;
file.create(new StringInputStream(contents), true, workspace.monitor());
}
logAndReset("Creating files", timer);
workspace.build();
logAndReset("Auto build", timer);
IMarker[] iMarkers = folder.findMarkers(EValidator.MARKER, true, IResource.DEPTH_INFINITE);
assertEquals(NUM_FILES-1,iMarkers.length);
}
@Inject
public ValidatorTester(T validator, EValidatorRegistrar registrar, @Named(Constants.LANGUAGE_NAME) final String languageName) {
this.validator = validator;
EValidator.Registry originalRegistry = registrar.getRegistry();
EValidatorRegistryImpl newRegistry = new EValidatorRegistryImpl();
registrar.setRegistry(newRegistry);
this.validator.register(registrar);
diagnostician = new Diagnostician(newRegistry) {
@Override
public java.util.Map<Object,Object> createDefaultContext() {
java.util.Map<Object,Object> map = super.createDefaultContext();
map.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, languageName);
return map;
}
};
registrar.setRegistry(originalRegistry);
validatorCalled = false;
}
public static GlobalStateMemento makeCopyOfGlobalState() {
GlobalStateMemento memento = new GlobalStateMemento();
memento.validatorReg = new HashMap<EPackage, Object>(EValidator.Registry.INSTANCE);
for(Map.Entry<EPackage, Object> validatorEntry: memento.validatorReg.entrySet()) {
Object existingValue = validatorEntry.getValue();
if (existingValue instanceof CompositeEValidator) {
validatorEntry.setValue(((CompositeEValidator) existingValue).getCopyAndClearContents());
}
}
memento.epackageReg = new HashMap<String, Object>(EPackage.Registry.INSTANCE);
memento.protocolToFactoryMap = new HashMap<String, Object>(Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap());
memento.extensionToFactoryMap = new HashMap<String, Object>(Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap());
memento.contentTypeIdentifierToFactoryMap = new HashMap<String, Object>(Resource.Factory.Registry.INSTANCE.getContentTypeToFactoryMap());
memento.protocolToServiceProviderMap = new HashMap<String, Object>(IResourceServiceProvider.Registry.INSTANCE.getProtocolToFactoryMap());
memento.extensionToServiceProviderMap = new HashMap<String, Object>(IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap());
memento.contentTypeIdentifierToServiceProviderMap = new HashMap<String, Object>(IResourceServiceProvider.Registry.INSTANCE.getContentTypeToFactoryMap());
memento.annotationValidatorMap = new HashMap<>(getAnnotationValidatorMap());
return memento;
}
public List<Issue> getPersistedIssues(URI uri) {
List<Issue> result = Lists.newArrayList();
Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(uri);
for (Pair<IStorage, IProject> storageToProject : storages) {
IStorage iStorage = storageToProject.getFirst();
if (iStorage instanceof IFile) {
try {
IMarker[] markers;
markers = ((IFile) iStorage).findMarkers(EValidator.MARKER, true, 1);
for (IMarker iMarker : markers) {
Issue issue = issueUtil.createIssue(iMarker);
if(issue != null)
result.add(issue);
}
} catch (CoreException e) {
log.error(e.getMessage(), e);
}
}
}
return result;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof EValidatorEqualitySupport))
return false;
EValidator otherDelegate = ((EValidatorEqualitySupport) obj).getDelegate();
if (otherDelegate.getClass().equals(getDelegate().getClass())) {
if (delegate instanceof AbstractInjectableValidator) {
AbstractInjectableValidator casted = (AbstractInjectableValidator) getDelegate();
AbstractInjectableValidator otherCasted = (AbstractInjectableValidator) otherDelegate;
if (casted.isLanguageSpecific() == otherCasted.isLanguageSpecific()) {
if (casted.isLanguageSpecific()) {
return Objects.equal(casted.getLanguageName(), otherCasted.getLanguageName());
}
return true;
}
return false;
}
return true;
}
return false;
}
public static GlobalStateMemento makeCopyOfGlobalState() {
GlobalStateMemento memento = new GlobalStateMemento();
memento.validatorReg = new HashMap<EPackage, Object>(EValidator.Registry.INSTANCE);
for(Map.Entry<EPackage, Object> validatorEntry: memento.validatorReg.entrySet()) {
Object existingValue = validatorEntry.getValue();
if (existingValue instanceof CompositeEValidator) {
validatorEntry.setValue(((CompositeEValidator) existingValue).getCopyAndClearContents());
}
}
memento.epackageReg = new HashMap<String, Object>(EPackage.Registry.INSTANCE);
memento.protocolToFactoryMap = new HashMap<String, Object>(Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap());
memento.extensionToFactoryMap = new HashMap<String, Object>(Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap());
memento.contentTypeIdentifierToFactoryMap = new HashMap<String, Object>(Resource.Factory.Registry.INSTANCE.getContentTypeToFactoryMap());
memento.protocolToServiceProviderMap = new HashMap<String, Object>(IResourceServiceProvider.Registry.INSTANCE.getProtocolToFactoryMap());
memento.extensionToServiceProviderMap = new HashMap<String, Object>(IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap());
memento.contentTypeIdentifierToServiceProviderMap = new HashMap<String, Object>(IResourceServiceProvider.Registry.INSTANCE.getContentTypeToFactoryMap());
memento.annotationValidatorMap = new HashMap<>(getAnnotationValidatorMap());
return memento;
}
@Inject
public ValidatorTester(T validator, EValidatorRegistrar registrar, @Named(Constants.LANGUAGE_NAME) final String languageName) {
this.validator = validator;
EValidator.Registry originalRegistry = registrar.getRegistry();
EValidatorRegistryImpl newRegistry = new EValidatorRegistryImpl();
registrar.setRegistry(newRegistry);
this.validator.register(registrar);
diagnostician = new Diagnostician(newRegistry) {
@Override
public java.util.Map<Object,Object> createDefaultContext() {
java.util.Map<Object,Object> map = super.createDefaultContext();
map.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, languageName);
return map;
}
};
registrar.setRegistry(originalRegistry);
validatorCalled = false;
}
@Test public void testBug_279962() {
EValidator validator = registry.getEValidator(pack);
assertTrue(validator instanceof CompositeEValidator);
CompositeEValidator composite = (CompositeEValidator) validator;
int prevSize = composite.getContents().size();
get(Val_279962_01.class);
get(Val_279962_04.class);
assertEquals(prevSize + 2, composite.getContents().size());
assertNotNull(validator);
Resource resource = get(XtextResource.class);
Model model = EnumRulesTestLanguageFactory.eINSTANCE.createModel();
resource.getContents().add(model);
// do not expect an exception
validator.validate(model, new BasicDiagnostic(), null);
assertEquals(prevSize + 4, composite.getContents().size());
}
@Override
public void setUp() throws Exception {
super.setUp();
with(XtextStandaloneSetup.class);
EValidator.Registry.INSTANCE.put(EcorePackage.eINSTANCE, EcoreValidator.INSTANCE);
File tempFile = File.createTempFile("XtextValidationTest", ".ecore");
tempFile.deleteOnExit();
Files.asCharSink(tempFile, StandardCharsets.UTF_8).write("<?xml version='1.0' encoding='UTF-8'?>" +
"<ecore:EPackage xmi:version='2.0' xmlns:xmi='http://www.omg.org/XMI'"+
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
" xmlns:ecore='http://www.eclipse.org/emf/2002/Ecore'"+
" name='XtextValidationBugs'"+
" nsURI='http://XtextValidationBugs'"+
" nsPrefix='XtextValidationBugs'>"+
" <eClassifiers xsi:type='ecore:EClass' name='Bug322875'>"+
" <eStructuralFeatures xsi:type='ecore:EReference' name='referencesETypeFromClasspathPackage' eType='ecore:EClass classpath:/org/eclipse/xtext/Xtext.ecore#//Grammar'/>"+
" </eClassifiers>"+
"</ecore:EPackage>");
xtextValidationTest_ecore = tempFile.toURI().toURL();
}
/** Registration method that is executed on injector instantiation. */
@Inject
public void registerServiceProvider(Injector injector) {
// register N4JS resource service providers
new N4JSStandaloneSetup().register(injector);
final N4JSValidator validator = injector.getInstance(N4JSValidator.class);
final EValidatorRegistrar registrar = injector.getInstance(EValidatorRegistrar.class);
// clear list of existing N4JS-package validators (removes obsolete validators originating from other injectors)
EValidator.Registry.INSTANCE.remove(N4JSPackage.eINSTANCE);
// re-register N4JSValidator
validator.register(registrar);
}
/** Copied from parent class to change language to {@code SemverGlobals.LANGUAGE_NAME} */
@Override
protected void validate(Resource resource, EObject eObject, CheckMode mode, CancelIndicator monitor,
IAcceptor<Issue> acceptor) {
try {
Map<Object, Object> options = Maps.newHashMap();
options.put(CheckMode.KEY, mode);
options.put(CancelableDiagnostician.CANCEL_INDICATOR, monitor);
// disable concrete syntax validation, since a semantic model that has been parsed
// from the concrete syntax always complies with it - otherwise there are parse errors.
options.put(ConcreteSyntaxEValidator.DISABLE_CONCRETE_SYNTAX_EVALIDATOR, Boolean.TRUE);
// see EObjectValidator.getRootEValidator(Map<Object, Object>)
options.put(EValidator.class, diagnostician);
options.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, SemverGlobals.LANGUAGE_NAME);
Diagnostic diagnostic = diagnostician.validate(eObject, options);
if (!diagnostic.getChildren().isEmpty()) {
for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
issueFromEValidatorDiagnostic(childDiagnostic, acceptor);
}
} else {
issueFromEValidatorDiagnostic(diagnostic, acceptor);
}
} catch (RuntimeException e) {
operationCanceledManager.propagateAsErrorIfCancelException(e);
}
}
@Override
public boolean validate ( final EDataType eDataType, final Object value, final DiagnosticChain diagnostics, final Map<Object, Object> context )
{
boolean result = true;
for ( final EValidator v : this.otherValidators )
{
if ( !v.validate ( eDataType, value, diagnostics, context ) )
{
result = false;
}
}
return result;
}
public static CommonPackage init ()
{
final CommonPackage result = initGen ();
EValidator.Registry.INSTANCE.put ( result, new ExtensibleValidationDescriptor () );
return result;
}
/**
* Creates, registers, and initializes the <b>Package</b> for this model, and for any others upon which it depends.
*
* <p>This method is used to initialize {@link ExecComponentsPackage#eINSTANCE} when that field is accessed.
* Clients should not invoke it directly. Instead, they should simply access that field to obtain the package.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #eNS_URI
* @see #createPackageContents()
* @see #initializePackageContents()
* @generated
*/
public static ExecComponentsPackage init ()
{
if ( isInited )
return (ExecComponentsPackage)EPackage.Registry.INSTANCE.getEPackage ( ExecComponentsPackage.eNS_URI );
// Obtain or create and register package
ExecComponentsPackageImpl theExecComponentsPackage = (ExecComponentsPackageImpl) ( EPackage.Registry.INSTANCE.get ( eNS_URI ) instanceof ExecComponentsPackageImpl ? EPackage.Registry.INSTANCE.get ( eNS_URI ) : new ExecComponentsPackageImpl () );
isInited = true;
// Initialize simple dependencies
ComponentPackage.eINSTANCE.eClass ();
// Create package meta-data objects
theExecComponentsPackage.createPackageContents ();
// Initialize created meta-data
theExecComponentsPackage.initializePackageContents ();
// Register package validator
EValidator.Registry.INSTANCE.put
( theExecComponentsPackage,
new EValidator.Descriptor ()
{
public EValidator getEValidator ()
{
return ExecComponentsValidator.INSTANCE;
}
} );
// Mark meta-data to indicate it can't be changed
theExecComponentsPackage.freeze ();
// Update the registry and return the package
EPackage.Registry.INSTANCE.put ( ExecComponentsPackage.eNS_URI, theExecComponentsPackage );
return theExecComponentsPackage;
}
/**
* Creates, registers, and initializes the <b>Package</b> for this model, and for any others upon which it depends.
*
* <p>This method is used to initialize {@link ConfigurationPackage#eINSTANCE} when that field is accessed.
* Clients should not invoke it directly. Instead, they should simply access that field to obtain the package.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #eNS_URI
* @see #createPackageContents()
* @see #initializePackageContents()
* @generated
*/
public static ConfigurationPackage init ()
{
if ( isInited )
return (ConfigurationPackage)EPackage.Registry.INSTANCE.getEPackage ( ConfigurationPackage.eNS_URI );
// Obtain or create and register package
ConfigurationPackageImpl theConfigurationPackage = (ConfigurationPackageImpl) ( EPackage.Registry.INSTANCE.get ( eNS_URI ) instanceof ConfigurationPackageImpl ? EPackage.Registry.INSTANCE.get ( eNS_URI ) : new ConfigurationPackageImpl () );
isInited = true;
// Initialize simple dependencies
XMLTypePackage.eINSTANCE.eClass ();
// Create package meta-data objects
theConfigurationPackage.createPackageContents ();
// Initialize created meta-data
theConfigurationPackage.initializePackageContents ();
// Register package validator
EValidator.Registry.INSTANCE.put
( theConfigurationPackage,
new EValidator.Descriptor ()
{
public EValidator getEValidator ()
{
return ConfigurationValidator.INSTANCE;
}
} );
// Mark meta-data to indicate it can't be changed
theConfigurationPackage.freeze ();
// Update the registry and return the package
EPackage.Registry.INSTANCE.put ( ConfigurationPackage.eNS_URI, theConfigurationPackage );
return theConfigurationPackage;
}
/**
* Creates, registers, and initializes the <b>Package</b> for this model,
* and for any others upon which it depends.
* <p>
* This method is used to initialize {@link ConfigurationPackage#eINSTANCE}
* when that field is accessed. Clients should not invoke it directly.
* Instead, they should simply access that field to obtain the package. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #eNS_URI
* @see #createPackageContents()
* @see #initializePackageContents()
* @generated
*/
public static ConfigurationPackage init ()
{
if ( isInited )
return (ConfigurationPackage)EPackage.Registry.INSTANCE.getEPackage ( ConfigurationPackage.eNS_URI );
// Obtain or create and register package
ConfigurationPackageImpl theConfigurationPackage = (ConfigurationPackageImpl) ( EPackage.Registry.INSTANCE.get ( eNS_URI ) instanceof ConfigurationPackageImpl ? EPackage.Registry.INSTANCE.get ( eNS_URI ) : new ConfigurationPackageImpl () );
isInited = true;
// Initialize simple dependencies
XMLTypePackage.eINSTANCE.eClass ();
// Create package meta-data objects
theConfigurationPackage.createPackageContents ();
// Initialize created meta-data
theConfigurationPackage.initializePackageContents ();
// Register package validator
EValidator.Registry.INSTANCE.put
( theConfigurationPackage,
new EValidator.Descriptor ()
{
public EValidator getEValidator ()
{
return ConfigurationValidator.INSTANCE;
}
} );
// Mark meta-data to indicate it can't be changed
theConfigurationPackage.freeze ();
// Update the registry and return the package
EPackage.Registry.INSTANCE.put ( ConfigurationPackage.eNS_URI, theConfigurationPackage );
return theConfigurationPackage;
}
@Test
public void testUiTestBetweenTwoRuntimeTests() {
URI workWithMe = URI.createURI("dummy:/sample." + EXTENSION);
Assert.assertEquals(EXTENSION, workWithMe.fileExtension());
// the first test is a runtime test
FoldingTestLanguageInjectorProvider runtime = new FoldingTestLanguageInjectorProvider();
runtime.setupRegistry();
Injector runtimeInjector = runtime.getInjector();
EValidator.Registry runtimeRegistry = runtimeInjector.getInstance(EValidator.Registry.class);
EValidator validator = runtimeRegistry.getEValidator(FoldingPackage.eINSTANCE);
runtime.restoreRegistry();
// trigger ui injector initialization from second test case
FoldingTestLanguageUiInjectorProvider ui = new FoldingTestLanguageUiInjectorProvider();
Injector uiInjector = ui.getInjector();
EValidator.Registry uiValidatorRegistry = uiInjector.getInstance(EValidator.Registry.class);
Assert.assertSame(runtimeRegistry, uiValidatorRegistry);
CompositeEValidator uiValidator = (CompositeEValidator) uiValidatorRegistry.getEValidator(FoldingPackage.eINSTANCE);
List<EValidatorEqualitySupport> validators = new ArrayList<>(uiValidator.getContents());
Assert.assertNotNull(validator);
// run next runtime test
runtime.setupRegistry();
runtime.restoreRegistry();
// run next ui test and check that we see the correct validator configuration
CompositeEValidator newValidator = (CompositeEValidator) uiValidatorRegistry.getEValidator(FoldingPackage.eINSTANCE);
Assert.assertEquals(validators, newValidator.getContents());
}
public static MockMarker newFastErrorMarker(IResource resource, EObject context, Integer code) {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
if (context != null)
attributes.put(EValidator.URI_ATTRIBUTE, EcoreUtil.getURI(context).toString());
attributes.put(Issue.CODE_KEY, code);
return new MockMarker(EValidator.MARKER, resource, context, attributes);
}
protected Map<Annotation, Position> getAnnotationsToAdd(Multimap<Position, Annotation> positionToAnnotations,
List<Issue> issues, IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return HashBiMap.create();
}
Map<Annotation, Position> annotationToPosition = Maps.newHashMapWithExpectedSize(issues.size());
for (Issue issue : issues) {
if (monitor.isCanceled()) {
return annotationToPosition;
}
if (isSet(issue.getOffset()) && isSet(issue.getLength()) && issue.getMessage() != null) {
String type = lookup.getAnnotationType(EValidator.MARKER, getMarkerSeverity(issue.getSeverity()));
boolean isQuickfixable = false;
if (issueResolutionProvider instanceof IssueResolutionProviderExtension) {
isQuickfixable = ((IssueResolutionProviderExtension)issueResolutionProvider).hasResolutionFor(issue);
} else {
isQuickfixable = issueResolutionProvider.hasResolutionFor(issue.getCode());
}
Annotation annotation = new XtextAnnotation(type, false, xtextDocument, issue, isQuickfixable);
if (issue.getOffset() < 0 || issue.getLength() < 0) {
LOG.error("Invalid annotation position offset=" + issue.getOffset() + " length = "
+ issue.getLength());
}
Position position = new Position(Math.max(0, issue.getOffset()), Math.max(0, issue.getLength()));
annotationToPosition.put(annotation, position);
positionToAnnotations.put(position, annotation);
}
}
return annotationToPosition;
}
public void restoreGlobalState() {
clearGlobalRegistries();
EValidator.Registry.INSTANCE.putAll(validatorReg);
EPackage.Registry.INSTANCE.putAll(epackageReg);
Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap().putAll(protocolToFactoryMap);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().putAll(extensionToFactoryMap);
Resource.Factory.Registry.INSTANCE.getContentTypeToFactoryMap().putAll(contentTypeIdentifierToFactoryMap);
IResourceServiceProvider.Registry.INSTANCE.getProtocolToFactoryMap().putAll(protocolToServiceProviderMap);
IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().putAll(extensionToServiceProviderMap);
IResourceServiceProvider.Registry.INSTANCE.getContentTypeToFactoryMap().putAll(contentTypeIdentifierToServiceProviderMap);
getAnnotationValidatorMap().putAll(annotationValidatorMap);
}
public static void clearGlobalRegistries() {
EValidator.Registry.INSTANCE.clear();
EPackage.Registry.INSTANCE.clear();
Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap().clear();
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().clear();
Resource.Factory.Registry.INSTANCE.getContentTypeToFactoryMap().clear();
IResourceServiceProvider.Registry.INSTANCE.getProtocolToFactoryMap().clear();
IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().clear();
IResourceServiceProvider.Registry.INSTANCE.getContentTypeToFactoryMap().clear();
getAnnotationValidatorMap().clear();
initializeDefaults();
}
public void register(EPackage ePackage, EValidator registerMe) {
EValidator validator = getRegistry().getEValidator(ePackage);
if (validator == null) {
validator = compositeProvider.get();
}
else if (!(validator instanceof CompositeEValidator)) {
CompositeEValidator newValidator = compositeProvider.get();
newValidator.addValidator(validator);
validator = newValidator;
}
((CompositeEValidator) validator).addValidator(registerMe);
getRegistry().put(ePackage, validator);
}
/**
* @since 2.4
*/
protected void validate(Resource resource, EObject element, final CheckMode mode, final CancelIndicator monitor,
IAcceptor<Issue> acceptor) {
try {
Map<Object, Object> options = Maps.newHashMap();
options.put(CheckMode.KEY, mode);
options.put(CancelableDiagnostician.CANCEL_INDICATOR, monitor);
// disable concrete syntax validation, since a semantic model that has been parsed
// from the concrete syntax always complies with it - otherwise there are parse errors.
options.put(ConcreteSyntaxEValidator.DISABLE_CONCRETE_SYNTAX_EVALIDATOR, Boolean.TRUE);
// see EObjectValidator.getRootEValidator(Map<Object, Object>)
options.put(EValidator.class, diagnostician);
if (resource instanceof XtextResource) {
options.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME,
((XtextResource) resource).getLanguageName());
}
Diagnostic diagnostic = diagnostician.validate(element, options);
if (!diagnostic.getChildren().isEmpty()) {
for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
issueFromEValidatorDiagnostic(childDiagnostic, acceptor);
}
} else {
issueFromEValidatorDiagnostic(diagnostic, acceptor);
}
} catch (RuntimeException e) {
operationCanceledManager.propagateAsErrorIfCancelException(e);
log.error(e.getMessage(), e);
}
}
public void addValidator(EValidator validator) {
if (this == validator)
return;
if (validator instanceof CompositeEValidator) {
CompositeEValidator other = (CompositeEValidator) validator;
for(int i = 0; i < other.getContents().size(); i++)
addValidator(other.getContents().get(i).delegate);
} else {
EValidatorEqualitySupport equalitySupport = equalitySupportProvider.get();
equalitySupport.setDelegate(validator);
if (!getContents().contains(equalitySupport))
this.getContents().add(equalitySupport);
}
}
@Check
public void checkGeneratedPackage(GeneratedMetamodel metamodel) {
Map<Object, Object> context = getContext();
if (context != null) {
Diagnostician diagnostician = (Diagnostician) context.get(EValidator.class);
if (diagnostician != null)
checkGeneratedPackage(metamodel, diagnostician, context);
}
}
public void restoreGlobalState() {
clearGlobalRegistries();
EValidator.Registry.INSTANCE.putAll(validatorReg);
EPackage.Registry.INSTANCE.putAll(epackageReg);
Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap().putAll(protocolToFactoryMap);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().putAll(extensionToFactoryMap);
Resource.Factory.Registry.INSTANCE.getContentTypeToFactoryMap().putAll(contentTypeIdentifierToFactoryMap);
IResourceServiceProvider.Registry.INSTANCE.getProtocolToFactoryMap().putAll(protocolToServiceProviderMap);
IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().putAll(extensionToServiceProviderMap);
IResourceServiceProvider.Registry.INSTANCE.getContentTypeToFactoryMap().putAll(contentTypeIdentifierToServiceProviderMap);
getAnnotationValidatorMap().putAll(annotationValidatorMap);
}