/** * Sets attributes for the given {@link IMarker}. * * @param marker * the {@link IMarker} * @param resource * the {@link IFile} containing the mode * @param instruction * the {@link EObject} representing the instruction * @param persistent * should be persisted * @throws CoreException * if attributes can't be set */ protected void setMarkerAttibutes(final IMarker marker, IFile resource, EObject instruction, boolean persistent) throws CoreException { final IItemLabelProvider provider = (IItemLabelProvider)ADAPTER_FACTORY.adapt(instruction, IItemLabelProvider.class); marker.setAttribute(IBreakpoint.ENABLED, true); marker.setAttribute(IBreakpoint.PERSISTED, persistent); marker.setAttribute(IBreakpoint.ID, getModelIdentifier()); marker.setAttribute(EValidator.URI_ATTRIBUTE, EcoreUtil.getURI(instruction).toString()); final String instructionText = provider.getText(instruction); marker.setAttribute(IMarker.MESSAGE, "DSL Breakpoint: " + resource.getFullPath() + " [" + instructionText + "]"); try { marker.setAttribute(IMAGE_ATTRIBUTE, toAttribute(provider.getImage(instruction))); } catch (IOException e) { Activator.getDefault().error(e); } marker.setAttribute(TEXT_ATTRIBUTE, instructionText); }
/** * Show the given {@link EObject instruction}. * * @param editorPart * the opened {@link DialectEditor} * @param instruction * the {@link EObject instruction} to show */ public static void showInstruction(DialectEditor editorPart, EObject instruction) { final URI resourceURI = instruction.eResource().getURI(); if (resourceURI.isPlatformResource()) { final String resourcePath = resourceURI.toPlatformString(true); final IResource resource = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path( resourcePath)); try { final IMarker marker = resource.createMarker(EValidator.MARKER); marker.setAttribute(EValidator.URI_ATTRIBUTE, EcoreUtil.getURI(instruction).toString()); final TraceabilityMarkerNavigationProvider navigationProvider = new TraceabilityMarkerNavigationProvider( (DialectEditor)editorPart); navigationProvider.gotoMarker(marker); marker.delete(); } catch (CoreException e) { DebugSiriusIdeUiPlugin.INSTANCE.log(e); } } }
@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; }
/** * Registers validators. */ static void setup() { final EValidator.Registry registry = EValidator.Registry.INSTANCE; registry.put(TypesPackage.eINSTANCE, new TypesValidator()); registry.put(ModulesPackage.eINSTANCE, new ModulesValidator()); registry.put(ResourcesPackage.eINSTANCE, new ResourcesValidator()); registry.put(ResponsesPackage.eINSTANCE, new ResponsesValidator()); final RamlObjectValidator ramlObjectValidator = new RamlObjectValidator(); for (final EPackage ePackage : PACKAGES) { final CompositeValidator compositeValidator = new CompositeValidator(); compositeValidator.add(ramlObjectValidator); final EValidator validator = registry.getEValidator(ePackage); if (validator != null) { compositeValidator.add(validator); } registry.put(ePackage, compositeValidator); } }
@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()); 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.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>" , tempFile, StandardCharsets.UTF_8); xtextValidationTest_ecore = tempFile.toURI().toURL(); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void gotoMarker(IMarker marker) { try { if (marker.getType().equals(EValidator.MARKER)) { String uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null); if (uriAttribute != null) { URI uri = URI.createURI(uriAttribute); EObject eObject = editingDomain.getResourceSet().getEObject(uri, true); if (eObject != null) { setSelectionToViewer(Collections.singleton(editingDomain.getWrapper(eObject))); } } } } catch (CoreException exception) { ModelEditorPlugin.INSTANCE.log(exception); } }
/** * {@inheritDoc} * * @see org.eclipse.mylyn.docs.intent.mapping.ide.adapter.IMarkerToLocationDescriptor#getAdapter(org.eclipse.core.resources.IMarker) */ public ILocationDescriptor getAdapter(IMarker marker) { ILocationDescriptor res = null; try { if (marker.isSubtypeOf(EValidator.MARKER)) { final String uri = (String)marker.getAttribute(IEObjectLocationMaker.URI_ATTRIBUTE); // TODO we should change this to use a global ResourceSet... final ResourceSet rs = new ResourceSetImpl(); final EObject eObject = rs.getEObject(URI.createURI(uri), true); res = IdeMappingUtils.adapt(eObject, ILocationDescriptor.class); } } catch (CoreException e) { Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); } return res; }
public static List<Diagnostic> execute(Model model){ OCLstdlibStandaloneSetup.doSetup(); EssentialOCLStandaloneSetup.doSetup(); CompleteOCLStandaloneSetup.doSetup(); OCLstdlib.install(); OCL ocl = OCL.newInstance(); List<String> oclFilePaths = new ArrayList<String>(); oclFilePaths.add("model/ontouml.ocl"); if(checkTypes) oclFilePaths.add("model/types.ocl"); if(checkRelationships) oclFilePaths.add("model/relationships.ocl"); if(checkMetaAttributes) oclFilePaths.add("model/metaattributes.ocl"); if(checkBinaryProperties) oclFilePaths.add("model/binproperties.ocl"); if(checkDependencies) oclFilePaths.add("model/dependency.ocl"); if(checkCardinalities) oclFilePaths.add("model/cardinalities.ocl"); ComposedEValidator composed = ComposedEValidator.install(OntoumlPackage.eINSTANCE); for(String oclPath: oclFilePaths){ File file = new File(oclPath); URI oclURI = URI.createFileURI(file.getAbsolutePath()); CompleteOCLEObjectValidator myValidator = new CompleteOCLEObjectValidator(OntoumlPackage.eINSTANCE, oclURI, ocl.getEnvironmentFactory()); EValidator.Registry.INSTANCE.put(OntoumlPackage.eINSTANCE, myValidator); composed.addChild(myValidator); } Diagnostic diagnostics = Diagnostician.INSTANCE.validate(model); return diagnostics.getChildren(); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void gotoMarker(IMarker marker) { try { if (marker.getType().equals(EValidator.MARKER)) { String uriAttribute = marker.getAttribute( EValidator.URI_ATTRIBUTE, null); if (uriAttribute != null) { URI uri = URI.createURI(uriAttribute); EObject eObject = editingDomain.getResourceSet() .getEObject(uri, true); if (eObject != null) { setSelectionToViewer(Collections .singleton(editingDomain.getWrapper(eObject))); } } } } catch (CoreException exception) { bpmn2EditorPlugin.INSTANCE.log(exception); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void gotoMarker(IMarker marker) { try { if (marker.getType().equals(EValidator.MARKER)) { String uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null); if (uriAttribute != null) { URI uri = URI.createURI(uriAttribute); EObject eObject = editingDomain.getResourceSet().getEObject(uri, true); if (eObject != null) { setSelectionToViewer(Collections.singleton(editingDomain.getWrapper(eObject))); } } } } catch (CoreException exception) { NotationEditorPlugin.INSTANCE.log(exception); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void gotoMarker(IMarker marker) { try { if (marker.getType().equals(EValidator.MARKER)) { String uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null); if (uriAttribute != null) { URI uri = URI.createURI(uriAttribute); EObject eObject = editingDomain.getResourceSet().getEObject(uri, true); if (eObject != null) { setSelectionToViewer(Collections.singleton(editingDomain.getWrapper(eObject))); } } } } catch (CoreException exception) { HistoryEditorPlugin.INSTANCE.log(exception); } }
/** * <!-- begin-user-doc --> <!-- end-user-doc --> * * @generated */ public void gotoMarker(IMarker marker) { try { if (marker.getType().equals(EValidator.MARKER)) { String uriAttribute = marker.getAttribute( EValidator.URI_ATTRIBUTE, null); if (uriAttribute != null) { URI uri = URI.createURI(uriAttribute); EObject eObject = editingDomain.getResourceSet() .getEObject(uri, true); if (eObject != null) { setSelectionToViewer(Collections .singleton(editingDomain.getWrapper(eObject))); } } } } catch (CoreException exception) { ConfigEditorPlugin.INSTANCE.log(exception); } }
public void validate(View model) { // initialize OCL org.eclipse.ocl.examples.pivot.OCL.initialize(null); String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI_PIVOT; EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI, new OCLInvocationDelegateFactory.Global()); EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI, new OCLSettingDelegateFactory.Global()); EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI, new OCLValidationDelegateFactory.Global()); OCLinEcoreStandaloneSetup.doSetup(); // install the OCL standard library OCLstdlib.install(); // do diagnostic diag = Diagnostician.INSTANCE.validate(model); modelname = model.getID(); }
public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) { Object eValidator; EClass eType = eClass; while ((eValidator = eValidatorRegistry.get(eType.eContainer())) == null) { List<EClass> eSuperTypes = eType.getESuperTypes(); if (eSuperTypes.isEmpty()) { eValidator = eValidatorRegistry.get(null); break; } else { eType = eSuperTypes.get(0); } } boolean circular = context.get(EObjectValidator.ROOT_OBJECT) == eObject; boolean result = doValidate((EValidator)eValidator, eClass, eObject, diagnostics, context); if ((result || diagnostics != null) && !circular) { result &= doValidateContents(eObject, diagnostics, context); } return result; }
@Override public Object get(Object key) { Object validationDelegate = super.get(key); if (validationDelegate instanceof EValidator.ValidationDelegate.Descriptor) { EValidator.ValidationDelegate.Descriptor validationDelegateDescriptor = (EValidator.ValidationDelegate.Descriptor)validationDelegate; validationDelegate = validationDelegateDescriptor.getValidationDelegate(); put((String)key, validationDelegate); return validationDelegate; } else if (validationDelegate != null) { return validationDelegate; } else { return delegatedGet(key); } }
@Override public Object get(Object key) { Object eValidator = super.get(key); if (eValidator instanceof EValidator.Descriptor) { EValidator.Descriptor eValidatorDescriptor = (EValidator.Descriptor)eValidator; eValidator = eValidatorDescriptor.getEValidator(); put((EPackage)key, eValidator); return eValidator; } else if (eValidator != null) { return eValidator; } else { return delegatedGet(key); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void gotoMarker(IMarker marker) { try { if (marker.getType().equals(EValidator.MARKER)) { String uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null); if (uriAttribute != null) { URI uri = URI.createURI(uriAttribute); EObject eObject = editingDomain.getResourceSet().getEObject(uri, true); if (eObject != null) { setSelectionToViewer(Collections.singleton(editingDomain.getWrapper(eObject))); } } } } catch (CoreException exception) { CityGMLEditorPlugin.INSTANCE.log(exception); } }