org.eclipse.xtext.diagnostics.IDiagnosticConsumer Java Examples

The following examples show how to use org.eclipse.xtext.diagnostics.IDiagnosticConsumer. 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: LazyLinker.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: XtextLinker.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #3
Source File: Xtext2EcoreTransformerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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;
}
 
Example #4
Source File: AbstractCleaningLinker.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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();
}
 
Example #5
Source File: XtextLinker.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void beforeModelLinked(EObject model, IDiagnosticConsumer diagnosticsConsumer) {
	discardGeneratedPackages(model);
	clearAllReferences(model);
	super.beforeModelLinked(model, diagnosticsConsumer);
	cache.getOrCreate(model.eResource()).ignoreNotifications();
}
 
Example #6
Source File: XtextLinker.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
protected Xtext2EcoreTransformer createTransformer(Grammar grammar, IDiagnosticConsumer consumer) {
	final Xtext2EcoreTransformer transformer = new Xtext2EcoreTransformer(grammar);
	transformer.setErrorAcceptor(new TransformationDiagnosticsProducer(consumer));
	transformer.setPostProcessor(postProcessor);
	return transformer;
}
 
Example #7
Source File: Xtext2EcoreTransformerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public XtextResource doGetResource(InputStream in, URI uri) throws Exception {
	XtextResourceSet rs = get(XtextResourceSet.class);
	Map<URI, URI> uriMap = rs.getURIConverter().getURIMap();
	uriMap.put(URI.createPlatformPluginURI("org.eclipse.xtext/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformPluginURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformPluginURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformPluginURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformResourceURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformResourceURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/"));
	uriMap.put(URI.createPlatformResourceURI("org.eclipse.xtext.common.types/", false),
			URI.createURI("classpath:/"));
	rs.setClasspathURIContext(getClass());
	XtextResource resource = ((XtextResource) getResourceFactory().createResource(uri));
	rs.getResources().add(resource);
	XtextLinker linker = new XtextLinker() {
		@Override
		protected Xtext2EcoreTransformer createTransformer(Grammar grammar, IDiagnosticConsumer consumer) {
			Xtext2EcoreTransformer result = super.createTransformer(grammar, consumer);
			result.setErrorAcceptor(new Xtext2EcoreTransformerTest.MyErrorAcceptor(result.getErrorAcceptor(),
					Xtext2EcoreTransformerTest.this.errorAcceptorMock));
			return result;
		}
	};
	linker.setScopeProvider(((XtextLinker) resource.getLinker()).getScopeProvider());
	linker.setLinkingService(((Linker) resource.getLinker()).getLinkingService());
	linker.setLinkingHelper(((Linker) resource.getLinker()).getLinkingHelper());
	linker.setPackageRemover(new XtextLinker.PackageRemover());
	linker.setDiagnosticMessageProvider(new LinkingDiagnosticMessageProvider());
	linker.setCache(new OnChangeEvictingCache());
	resource.setLinker(linker);
	resource.load(in, null);
	return resource;
}
 
Example #8
Source File: N4JSLinker.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #9
Source File: N4JSLinker.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
			}
		}
	});
}
 
Example #10
Source File: TransformationDiagnosticsProducer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TransformationDiagnosticsProducer(IDiagnosticConsumer consumer) {
	super(consumer);
}
 
Example #11
Source File: XtextLinker.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void afterModelLinked(EObject model, IDiagnosticConsumer diagnosticsConsumer) {
	super.afterModelLinked(model, diagnosticsConsumer);
	cache.getOrCreate(model.eResource()).listenToNotifications();
}
 
Example #12
Source File: AbstractCleaningLinker.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void afterModelLinked(EObject model, IDiagnosticConsumer diagnosticsConsumer) {
	// clients may override
}
 
Example #13
Source File: ASTStructureDiagnosticProducer.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
ASTStructureDiagnosticProducer(IDiagnosticConsumer consumer) {
	super(consumer);
}
 
Example #14
Source File: Linker.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected IDiagnosticProducer createDiagnosticProducer(IDiagnosticConsumer consumer) {
	return new LinkingDiagnosticProducer(consumer);
}
 
Example #15
Source File: Linker.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void doLinkModel(EObject model, IDiagnosticConsumer consumer) {
	final IDiagnosticProducer producer = createDiagnosticProducer(consumer);
	ensureModelLinked(model, producer);
}
 
Example #16
Source File: LinkingDiagnosticProducer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public LinkingDiagnosticProducer(IDiagnosticConsumer consumer) {
	super(consumer);
}
 
Example #17
Source File: N4JSInjectorProviderWithoutStructureValidation.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void validate(EObject model, IDiagnosticConsumer consumer) {
	// no-op
}
 
Example #18
Source File: ILinker.java    From xtext-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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);
 
Example #19
Source File: AbstractCleaningLinker.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
protected abstract void doLinkModel(EObject model, IDiagnosticConsumer diagnosticsConsumer);