Search in sources :

Example 1 with TreeIterator

use of org.eclipse.emf.common.util.TreeIterator in project n4js by eclipse.

the class N4JSLinker method doLinkModel.

/**
 * 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
            String resourceName = resource.getURI().toString();
            try (ClosableMeasurement mes = dcPreProcess.getClosableMeasurement(resourceName)) {
                preProcessor.process(resource.getScript(), resource);
            }
            // AST structure validation
            if (!resource.isValidationDisabled()) {
                try (ClosableMeasurement m1 = dcValidations.getClosableMeasurement(resourceName);
                    ClosableMeasurement m2 = dcStructureValidations.getClosableMeasurement(resourceName)) {
                    getStructureValidator().validate(model, consumer);
                }
            }
        }
    });
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) ClosableMeasurement(org.eclipse.n4js.smith.ClosableMeasurement) LinkingDiagnosticProducer(org.eclipse.xtext.linking.impl.LinkingDiagnosticProducer) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) TreeIterator(org.eclipse.emf.common.util.TreeIterator) N4JSValueConverterWithValueException(org.eclipse.n4js.conversion.N4JSValueConverterWithValueException) N4JSValueConverterException(org.eclipse.n4js.conversion.N4JSValueConverterException) BadEscapementException(org.eclipse.n4js.conversion.AbstractN4JSStringValueConverter.BadEscapementException)

Example 2 with TreeIterator

use of org.eclipse.emf.common.util.TreeIterator in project xtext-xtend by eclipse.

the class XtendCompiler method needSyntheticSelfVariable.

@Override
protected boolean needSyntheticSelfVariable(XClosure closure, LightweightTypeReference typeRef) {
    JvmType jvmType = typeRef.getType();
    TreeIterator<EObject> closureIterator = closure.eAllContents();
    while (closureIterator.hasNext()) {
        EObject obj1 = closureIterator.next();
        if (obj1 instanceof XClosure) {
            closureIterator.prune();
        } else if (obj1 instanceof XtendTypeDeclaration) {
            TreeIterator<EObject> typeIterator = obj1.eAllContents();
            while (typeIterator.hasNext()) {
                EObject obj2 = typeIterator.next();
                if (obj2 instanceof XClosure) {
                    typeIterator.prune();
                } else if (obj2 instanceof XFeatureCall && isReferenceToSelf((XFeatureCall) obj2, jvmType)) {
                    return true;
                }
            }
            closureIterator.prune();
        }
    }
    return false;
}
Also used : XClosure(org.eclipse.xtext.xbase.XClosure) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmType(org.eclipse.xtext.common.types.JvmType) TreeIterator(org.eclipse.emf.common.util.TreeIterator)

Example 3 with TreeIterator

use of org.eclipse.emf.common.util.TreeIterator in project xtext-core by eclipse.

the class EMFGeneratorFragment2 method getReferencedEPackages.

protected Set<EPackage> getReferencedEPackages(final List<EPackage> packs) {
    final HashSet<EPackage> result = CollectionLiterals.<EPackage>newHashSet();
    for (final EPackage pkg : packs) {
        {
            final TreeIterator<EObject> iterator = pkg.eAllContents();
            while (iterator.hasNext()) {
                {
                    final EObject obj = iterator.next();
                    EList<EObject> _eCrossReferences = obj.eCrossReferences();
                    for (final EObject crossRef : _eCrossReferences) {
                        boolean _eIsProxy = crossRef.eIsProxy();
                        if (_eIsProxy) {
                            URI _eProxyURI = ((InternalEObject) crossRef).eProxyURI();
                            String _plus = ("Proxy \'" + _eProxyURI);
                            String _plus_1 = (_plus + "\' could not be resolved");
                            EMFGeneratorFragment2.LOG.error(_plus_1);
                        } else {
                            final EPackage p = EcoreUtil2.<EPackage>getContainerOfType(crossRef, EPackage.class);
                            if ((p != null)) {
                                result.add(p);
                            }
                        }
                    }
                }
            }
        }
    }
    result.removeAll(packs);
    result.remove(EcorePackage.eINSTANCE);
    result.remove(XMLTypePackage.eINSTANCE);
    result.remove(XMLNamespacePackage.eINSTANCE);
    return result;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) TreeIterator(org.eclipse.emf.common.util.TreeIterator) URI(org.eclipse.emf.common.util.URI) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EPackage(org.eclipse.emf.ecore.EPackage)

Example 4 with TreeIterator

use of org.eclipse.emf.common.util.TreeIterator in project xtext-core by eclipse.

the class LazyLinker method doLinkModel.

@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);
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) INode(org.eclipse.xtext.nodemodel.INode) LinkingDiagnosticProducer(org.eclipse.xtext.linking.impl.LinkingDiagnosticProducer) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) Resource(org.eclipse.emf.ecore.resource.Resource) TreeIterator(org.eclipse.emf.common.util.TreeIterator) WrappedException(org.eclipse.emf.common.util.WrappedException)

Aggregations

TreeIterator (org.eclipse.emf.common.util.TreeIterator)4 EObject (org.eclipse.emf.ecore.EObject)4 InternalEObject (org.eclipse.emf.ecore.InternalEObject)3 LinkingDiagnosticProducer (org.eclipse.xtext.linking.impl.LinkingDiagnosticProducer)2 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)2 URI (org.eclipse.emf.common.util.URI)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 BadEscapementException (org.eclipse.n4js.conversion.AbstractN4JSStringValueConverter.BadEscapementException)1 N4JSValueConverterException (org.eclipse.n4js.conversion.N4JSValueConverterException)1 N4JSValueConverterWithValueException (org.eclipse.n4js.conversion.N4JSValueConverterWithValueException)1 ClosableMeasurement (org.eclipse.n4js.smith.ClosableMeasurement)1 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)1 JvmType (org.eclipse.xtext.common.types.JvmType)1 INode (org.eclipse.xtext.nodemodel.INode)1 XClosure (org.eclipse.xtext.xbase.XClosure)1 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)1