org.eclipse.emf.ecore.EValidator Java Examples

The following examples show how to use org.eclipse.emf.ecore.EValidator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompositeEValidator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: ExtensibleValidator.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: ExtensibleValidator.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example #4
Source File: AbstractCompositeValidatorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example #5
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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();
}
 
Example #6
Source File: ValidatorTester.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: GlobalRegistries.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: ProfilerAbstractBuilderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #9
Source File: ProfilerAbstractBuilderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #10
Source File: ProfilerAbstractBuilderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #11
Source File: ValidatorTester.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #12
Source File: GlobalRegistries.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #13
Source File: IssuesProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #14
Source File: InjectorProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example #15
Source File: CompositeValidatorWithEObjectValidatorTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
@Test public void testContentsSize() {
	EValidator validator = registry.getEValidator(pack);
	assertNotNull(validator);
	assertTrue(validator instanceof CompositeEValidator);
	CompositeEValidator composite = (CompositeEValidator) validator;
	Collection<EValidatorEqualitySupport> contents = composite.getContents();
	assertEquals(3, contents.size());
}
 
Example #16
Source File: ExtensibleValidator.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example #17
Source File: CommonPackageImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public static CommonPackage init ()
{
    final CommonPackage result = initGen ();

    EValidator.Registry.INSTANCE.put ( result, new ExtensibleValidationDescriptor () );

    return result;
}
 
Example #18
Source File: CheckExtensionGenerator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Catalog validates.
 *
 * @param catalog
 *          the catalog
 * @return true, if successful
 */
private boolean catalogValidates(final CheckCatalog catalog) {
  EValidator.Registry eValidatorRegistry = EValidator.Registry.INSTANCE;
  EValidator eValidator = eValidatorRegistry.getEValidator(catalog.eClass().getEPackage());
  BasicDiagnostic diag = new BasicDiagnostic();
  eValidator.validate(catalog, diag, Maps.newHashMap());
  Iterable<Diagnostic> children = diag.getChildren();
  Iterable<Diagnostic> errors = Iterables.filter(children, new Predicate<Diagnostic>() {
    @Override
    public boolean apply(final Diagnostic input) {
      return input.getSeverity() == Diagnostic.ERROR;
    }
  });
  return Iterables.isEmpty(errors);
}
 
Example #19
Source File: AnnotationIssueProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #20
Source File: GlobalRegistries.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example #21
Source File: MigrationPackageImpl.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 MigrationPackage#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 MigrationPackage init() {
	if (isInited) {
		return (MigrationPackage) EPackage.Registry.INSTANCE.getEPackage(MigrationPackage.eNS_URI);
	}

	// Obtain or create and register package
	final MigrationPackageImpl theMigrationPackage = (MigrationPackageImpl) (EPackage.Registry.INSTANCE
		.get(eNS_URI) instanceof MigrationPackageImpl ? EPackage.Registry.INSTANCE
		.get(eNS_URI) : new MigrationPackageImpl());

	isInited = true;

	// Initialize simple dependencies
	EcorePackage.eINSTANCE.eClass();

	// Create package meta-data objects
	theMigrationPackage.createPackageContents();

	// Initialize created meta-data
	theMigrationPackage.initializePackageContents();

	// Register package validator
	EValidator.Registry.INSTANCE.put
		(theMigrationPackage,
			new EValidator.Descriptor() {
				@Override
				public EValidator getEValidator() {
					return MigrationValidator.INSTANCE;
				}
			});

	// Mark meta-data to indicate it can't be changed
	theMigrationPackage.freeze();

	// Update the registry and return the package
	EPackage.Registry.INSTANCE.put(MigrationPackage.eNS_URI, theMigrationPackage);
	return theMigrationPackage;
}
 
Example #22
Source File: GlobalRegistries.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example #23
Source File: SemverResourceValidator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** 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);
	}
}
 
Example #24
Source File: GlobalRegistries.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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();
}
 
Example #25
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example #26
Source File: EValidatorRegistrar.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example #27
Source File: CompositeEValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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);
	}
}
 
Example #28
Source File: ResourceValidatorImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @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);
	}
}
 
Example #29
Source File: N4JSStandaloneRegistrationHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** 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);
}
 
Example #30
Source File: GlobalRegistries.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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();
}