/** * Clears the list of encoded URIs in {@link N4JSResource}, installs proxies for all cross references inside the * parsed model. If validation is enabled finally the {@link ASTStructureValidator} is triggered, that checks the * now linked AST structure. */ @Override protected void doLinkModel(final EObject model, final IDiagnosticConsumer consumer) { final LinkingDiagnosticProducer producer = new LinkingDiagnosticProducer(consumer); getCache().execWithoutCacheClear((N4JSResource) model.eResource(), new IUnitOfWork.Void<N4JSResource>() { @Override public void process(N4JSResource resource) throws Exception { // actual linking resource.clearLazyProxyInformation(); clearReferences(model); installProxies(resource, model, producer); TreeIterator<EObject> iterator = model.eAllContents(); while (iterator.hasNext()) { EObject eObject = iterator.next(); clearReferences(eObject); installProxies(resource, eObject, producer); } // pre-processing of AST preProcessor.process(resource.getScript(), resource); // AST structure validation if (!resource.isValidationDisabled()) getStructureValidator().validate(model, consumer); } }); }
@Override public void linkModel(EObject model, IDiagnosticConsumer consumer) { if (model instanceof Grammar) { final Xtext2EcoreTransformer transformer = createTransformer((Grammar) model, consumer); //TODO duplicate transformer.removeGeneratedPackages(); super.linkModel(model, consumer); updateOverriddenRules((Grammar) model); try { transformer.transform(); } catch (Exception e) { log.error(e.getMessage(), e); consumer.consume(new ExceptionDiagnostic(e), Severity.ERROR); } if (!model.eResource().eAdapters().contains(packageRemover)) model.eResource().eAdapters().add(packageRemover); } else { super.linkModel(model, consumer); } }
@Override protected void doLinkModel(final EObject model, IDiagnosticConsumer consumer) { final Multimap<EStructuralFeature.Setting, INode> settingsToLink = ArrayListMultimap.create(); final LinkingDiagnosticProducer producer = new LinkingDiagnosticProducer(consumer); cache.execWithoutCacheClear(model.eResource(), new IUnitOfWork.Void<Resource>() { @Override public void process(Resource state) throws Exception { TreeIterator<EObject> iterator = getAllLinkableContents(model); boolean clearAllReferencesRequired = isClearAllReferencesRequired(state); while (iterator.hasNext()) { EObject eObject = iterator.next(); if (clearAllReferencesRequired) { clearReferences(eObject); } installProxies(eObject, producer, settingsToLink); } } }); installQueuedLinks(settingsToLink); }
/** * Removes the imported names before linking and cleans other caches attached to the AST. */ @Override protected void beforeModelLinked(EObject model, IDiagnosticConsumer diagnosticsConsumer) { ImportedNamesAdapter adapter = ImportedNamesAdapter.find(model.eResource()); if (adapter != null) adapter.clear(); ComposedMemberScope.clearCachedComposedMembers(model); }
@Override public XtextResource doGetResource(final InputStream in, final URI uri) throws Exception { XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class); rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/")); rs.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/")); rs.setClasspathURIContext(this.getClass()); Resource _createResource = this.getResourceFactory().createResource(uri); final XtextResource resource = ((XtextResource) _createResource); rs.getResources().add(resource); XtextLinker linker = new XtextLinker() { @Override protected Xtext2EcoreTransformer createTransformer(final Grammar grammar, final IDiagnosticConsumer consumer) { Xtext2EcoreTransformer result = super.createTransformer(grammar, consumer); ErrorAcceptor _errorAcceptor = result.getErrorAcceptor(); Xtext2EcoreTransformerTest.MyErrorAcceptor _myErrorAcceptor = new Xtext2EcoreTransformerTest.MyErrorAcceptor(_errorAcceptor, Xtext2EcoreTransformerTest.this.errorAcceptorMock); result.setErrorAcceptor(_myErrorAcceptor); return result; } }; ILinker _linker = resource.getLinker(); linker.setScopeProvider(((XtextLinker) _linker).getScopeProvider()); ILinker _linker_1 = resource.getLinker(); linker.setLinkingService(((Linker) _linker_1).getLinkingService()); ILinker _linker_2 = resource.getLinker(); linker.setLinkingHelper(((Linker) _linker_2).getLinkingHelper()); XtextLinker.PackageRemover _packageRemover = new XtextLinker.PackageRemover(); linker.setPackageRemover(_packageRemover); LinkingDiagnosticMessageProvider _linkingDiagnosticMessageProvider = new LinkingDiagnosticMessageProvider(); linker.setDiagnosticMessageProvider(_linkingDiagnosticMessageProvider); OnChangeEvictingCache _onChangeEvictingCache = new OnChangeEvictingCache(); linker.setCache(_onChangeEvictingCache); resource.setLinker(linker); resource.load(in, null); return resource; }
@SuppressWarnings("deprecation") @Override protected void beforeModelLinked(EObject model, IDiagnosticConsumer diagnosticsConsumer) { discardGeneratedPackages(model); clearAllReferences(model); super.beforeModelLinked(model, diagnosticsConsumer); cache.getOrCreate(model.eResource()).ignoreNotifications(); }
protected void beforeModelLinked(EObject model, IDiagnosticConsumer diagnosticsConsumer) { Resource resource = model.eResource(); if (resource instanceof LazyLinkingResource) { ((LazyLinkingResource) resource).clearLazyProxyInformation(); } ImportedNamesAdapter adapter = ImportedNamesAdapter.find(resource); if (adapter!=null) adapter.clear(); }
@Override public XtextResource doGetResource(final InputStream in, final URI uri) throws Exception { XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class); rs.setClasspathURIContext(this.getClass()); Resource _createResource = this.getResourceFactory().createResource(uri); final XtextResource resource = ((XtextResource) _createResource); rs.getResources().add(resource); XtextLinker linker = new XtextLinker() { @Override protected Xtext2EcoreTransformer createTransformer(final Grammar grammar, final IDiagnosticConsumer consumer) { Xtext2EcoreTransformer result = super.createTransformer(grammar, consumer); ErrorAcceptor _errorAcceptor = result.getErrorAcceptor(); Xtext2EcoreTransformerTest.MyErrorAcceptor _myErrorAcceptor = new Xtext2EcoreTransformerTest.MyErrorAcceptor(_errorAcceptor, Xtext2EcoreTransformerTest.this.errorAcceptorMock); result.setErrorAcceptor(_myErrorAcceptor); return result; } }; ILinker _linker = resource.getLinker(); linker.setScopeProvider(((XtextLinker) _linker).getScopeProvider()); ILinker _linker_1 = resource.getLinker(); linker.setLinkingService(((Linker) _linker_1).getLinkingService()); ILinker _linker_2 = resource.getLinker(); linker.setLinkingHelper(((Linker) _linker_2).getLinkingHelper()); XtextLinker.PackageRemover _packageRemover = new XtextLinker.PackageRemover(); linker.setPackageRemover(_packageRemover); LinkingDiagnosticMessageProvider _linkingDiagnosticMessageProvider = new LinkingDiagnosticMessageProvider(); linker.setDiagnosticMessageProvider(_linkingDiagnosticMessageProvider); OnChangeEvictingCache _onChangeEvictingCache = new OnChangeEvictingCache(); linker.setCache(_onChangeEvictingCache); resource.setLinker(linker); resource.load(in, null); return resource; }
@Override public void validate(EObject model, IDiagnosticConsumer consumer) { // no-op }
ASTStructureDiagnosticProducer(IDiagnosticConsumer consumer) { super(consumer); }
public TransformationDiagnosticsProducer(IDiagnosticConsumer consumer) { super(consumer); }
protected Xtext2EcoreTransformer createTransformer(Grammar grammar, IDiagnosticConsumer consumer) { final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar); transformer.setErrorAcceptor(new TransformationDiagnosticsProducer(consumer)); transformer.setPostProcessor(postProcessor); return transformer; }
@Override protected void afterModelLinked(EObject model, IDiagnosticConsumer diagnosticsConsumer) { super.afterModelLinked(model, diagnosticsConsumer); cache.getOrCreate(model.eResource()).listenToNotifications(); }
protected void afterModelLinked(EObject model, IDiagnosticConsumer diagnosticsConsumer) { // clients may override }
protected IDiagnosticProducer createDiagnosticProducer(IDiagnosticConsumer consumer) { return new LinkingDiagnosticProducer(consumer); }
@Override protected void doLinkModel(EObject model, IDiagnosticConsumer consumer) { final IDiagnosticProducer producer = createDiagnosticProducer(consumer); ensureModelLinked(model, producer); }
public LinkingDiagnosticProducer(IDiagnosticConsumer consumer) { super(consumer); }
/** * Sets cross references in the passed {@link EObject} and its {@link EObject#eAllContents() contents}, * using the information available (usually using the {@link INode} model associated via {@link NodeModelUtils}) * * @param model the root model of a resource * @param diagnosticsConsumer the consumer of linking diagnostics */ void linkModel(EObject model, IDiagnosticConsumer diagnosticsConsumer);
protected abstract void doLinkModel(EObject model, IDiagnosticConsumer diagnosticsConsumer);