Java 类org.eclipse.emf.common.util.TreeIterator 实例源码

项目:xtext-core    文件:AbstractElementFinder.java   
@SuppressWarnings("unchecked")
protected <T> List<T> findByNestedRuleCall(Class<T> clazz, AbstractRule... rule) {
    Set<AbstractRule> rls = new HashSet<AbstractRule>(Arrays.asList(rule));
    ArrayList<T> r = new ArrayList<T>();
    for (AbstractRule ar : getRules()) {
        TreeIterator<EObject> i = ar.eAllContents();
        while (i.hasNext()) {
            EObject o = i.next();
            if (clazz.isInstance(o)) {
                TreeIterator<EObject> ct = o.eAllContents();
                while (ct.hasNext()) {
                    EObject cto = ct.next();
                    if (cto instanceof RuleCall && rls.contains(((RuleCall) cto).getRule())) {
                        r.add((T) o);
                        break;
                    }
                }
                i.prune();
            }
        }
    }
    return r;
}
项目:xtext-core    文件:AbstractElementFinder.java   
public List<RuleCall> findRuleCalls(AbstractRule... rules) {
    Set<AbstractRule> rls = new HashSet<AbstractRule>(Arrays.asList(rules));
    ArrayList<RuleCall> r = new ArrayList<RuleCall>();
    for (AbstractRule ar : getRules()) {
        TreeIterator<EObject> i = ar.eAllContents();
        while (i.hasNext()) {
            EObject o = i.next();
            if (o instanceof RuleCall) {
                RuleCall c = (RuleCall) o;
                if (rls.contains(c.getRule()))
                    r.add(c);
            }
        }
    }
    return r;
}
项目:ttc2017smartGrids    文件:GlueModelCreator.java   
public static void cosem(Resource cosemResource, Root root, Hashtable<String, MeterAsset> allMeterAssets) {
    HashSet<PhysicalDevice> devices = new HashSet<>();
    HashSet<MeterAssetPhysicalDevicePair> devicePairs = new HashSet<>();
    TreeIterator<EObject> cosemIterator = cosemResource.getAllContents();
    while (cosemIterator.hasNext()) {
        EObject eOb = cosemIterator.next();
        if (eOb instanceof PhysicalDevice) {
            PhysicalDevice device = (PhysicalDevice) eOb;
            devices.add(device);
            String idNs = device.getID();
            if (allMeterAssets.containsKey(idNs)) {
                MeterAssetPhysicalDevicePair pair = GluemodelFactory.eINSTANCE
                        .createMeterAssetPhysicalDevicePair();
                pair.setB(device);
                pair.setA(allMeterAssets.get(idNs));
                devicePairs.add(pair);
            }
        }
    }

    root.getMeterAssetToPhysicalDevice().addAll(devicePairs);
}
项目:n4js    文件:TranspilerUtils.java   
/**
 * Search entire containment tree below 'root' for objects of type 'cls'. If last argument is <code>false</code>,
 * then sub trees below a matching node won't be searched.
 */
public static final <T extends EObject> List<T> collectNodes(EObject root, Class<T> cls,
        boolean searchForNestedNodes) {
    final List<T> result = new ArrayList<>();
    final TreeIterator<EObject> iter = root.eAllContents();
    while (iter.hasNext()) {
        final EObject obj = iter.next();
        if (cls.isAssignableFrom(obj.getClass())) {
            @SuppressWarnings("unchecked")
            final T objCasted = (T) obj;
            result.add(objCasted);
            if (!searchForNestedNodes)
                iter.prune();
        }
    }
    return result;
}
项目:n4js    文件:TranspilerUtils.java   
/**
 * root usually a function or other ThisProviding environment.
 *
 * @param root
 *            function or method.
 * @param cls
 *            Type of element to report.
 * @return nodes of (sub-)type cls in the same this-environment
 */
public static final <T extends EObject> List<T> collectNodesWithinSameThisEnvironment(EObject root, Class<T> cls) {
    final List<T> result = new ArrayList<>();
    final TreeIterator<EObject> iter = root.eAllContents();
    while (iter.hasNext()) {
        final EObject obj = iter.next();
        if (cls.isAssignableFrom(obj.getClass())) {
            @SuppressWarnings("unchecked")
            final T objCasted = (T) obj;
            result.add(objCasted);
        }
        // check for same environment
        if (obj instanceof ThisArgProvider) {
            iter.prune();
        }
    }
    return result;
}
项目:n4js    文件:N4JSPostProcessor.java   
private static void exposeTypesReferencedBy(EObject root) {
    final TreeIterator<EObject> i = root.eAllContents();
    while (i.hasNext()) {
        final EObject object = i.next();
        for (EReference currRef : object.eClass().getEAllReferences()) {
            if (!currRef.isContainment() && !currRef.isContainer()) {
                final Object currTarget = object.eGet(currRef);
                if (currTarget instanceof Collection<?>) {
                    for (Object currObj : (Collection<?>) currTarget) {
                        exposeType(currObj);
                    }
                } else {
                    exposeType(currTarget);
                }
            }
        }
    }
}
项目:n4js    文件:N4JSLinker.java   
/**
 * 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);
        }
    });
}
项目:n4js    文件:GlobalObjectScope.java   
@Override
protected void buildMap(Resource resource, Map<QualifiedName, IEObjectDescription> elements) {
    IDefaultResourceDescriptionStrategy strategy = ((XtextResource) resource).getResourceServiceProvider()
            .get(IDefaultResourceDescriptionStrategy.class);
    TreeIterator<EObject> allProperContents = EcoreUtil.getAllProperContents(resource, false);
    IAcceptor<IEObjectDescription> acceptor = new IAcceptor<IEObjectDescription>() {
        @Override
        public void accept(IEObjectDescription description) {
            elements.put(description.getQualifiedName(), description);
        }
    };
    while (allProperContents.hasNext()) {
        EObject content = allProperContents.next();
        if (!strategy.createEObjectDescriptions(content, acceptor)) {
            allProperContents.prune();
        }
    }
}
项目:gemoc-studio-modeldebugging    文件:SelectAnyEObjectDialog.java   
public SelectAnyEObjectDialog(Shell parent, ResourceSet resourceSet, ILabelProvider renderer) {
    super(parent, renderer);
    _searchedResourceSet = resourceSet;
    ArrayList<EObject> all = new ArrayList<EObject>();
    EcoreUtil.resolveAll(resourceSet);
    for (Resource r : _searchedResourceSet.getResources())
    {
        for (TreeIterator<EObject> iterator = r.getAllContents(); iterator.hasNext();) {
            EObject o =  iterator.next();
            if(select(o)) all.add(o);
        }
    }

    Object[] elements = all.toArray();
    this.setElements(elements);
}
项目:neoscada    文件:ValidationRunner.java   
public boolean run ( final EObject element, final DiagnosticChain diagnostics, final Map<Object, Object> context )
{
    if ( element == null )
    {
        return true;
    }

    boolean result = runElement ( element, diagnostics, context );

    final TreeIterator<EObject> it = element.eAllContents ();
    while ( it.hasNext () )
    {
        if ( !runElement ( it.next (), diagnostics, context ) )
        {
            result = false;
        }
    }

    return result;
}
项目:rgse.ttc17.emoflon.tgg    文件:GlueModelCreator.java   
public static void cosem(Resource cosemResource, Root root, Hashtable<String, MeterAsset> allMeterAssets) {
    HashSet<PhysicalDevice> devices = new HashSet<>();
    HashSet<MeterAssetPhysicalDevicePair> devicePairs = new HashSet<>();
    TreeIterator<EObject> cosemIterator = cosemResource.getAllContents();
    while (cosemIterator.hasNext()) {
        EObject eOb = cosemIterator.next();
        if (eOb instanceof PhysicalDevice) {
            PhysicalDevice device = (PhysicalDevice) eOb;
            devices.add(device);
            String idNs = device.getID();
            if (allMeterAssets.containsKey(idNs)) {
                MeterAssetPhysicalDevicePair pair = GluemodelFactory.eINSTANCE
                        .createMeterAssetPhysicalDevicePair();
                pair.setB(device);
                pair.setA(allMeterAssets.get(idNs));
                devicePairs.add(pair);
            }
        }
    }

    root.getMeterAssetToPhysicalDevice().addAll(devicePairs);
}
项目:Saturn    文件:SaturnDocLoadSaveUtil.java   
private static void undoTextElementToTextNode(XMLResource saturnResourceImpl_, Map<Entry, Entry> textNodes_)
{
  DocumentRoot o = (DocumentRoot) saturnResourceImpl_.getContents().get(0);
  Saturn saturn = (Saturn) o.eContents().get(0);
  TreeIterator<EObject> ee = saturn.eAllContents();
  while (ee.hasNext())
  {
    EObject e = ee.next();
    if (e == null) continue;
    EClass ec = e.eClass();
    if (!ValuesPackage.eINSTANCE.getComplexValue().isSuperTypeOf(ec)) continue;

    ComplexValue cv = (ComplexValue) e;
    for (int i = 0; i < cv.getMixed().size(); i++)
    {
      FeatureMap.Entry entry = cv.getMixed().get(i);
      if (textNodes_.containsKey(entry))
      {
        Entry textComplexValueEntry = textNodes_.get(entry);
        cv.getMixed().set(i, textComplexValueEntry);
      }
    }
  }
}
项目:gemoc-studio    文件:FsmTraceConstructor.java   
private void addInitialState() {
    if (lastState == null) {
        // Creation of the initial state
        Set<Resource> allResources = getAllExecutedModelResources();
        lastState = fsmTrace.States.StatesFactory.eINSTANCE.createSpecificState();
        for (Resource r : allResources) {
            for (TreeIterator<EObject> i = r.getAllContents(); i.hasNext();) {
                EObject o = i.next();

                if (o instanceof org.eclipse.gemoc.sample.legacyfsm.xsfsm.xsfsm.fsm.NamedElement) {
                    org.eclipse.gemoc.sample.legacyfsm.xsfsm.xsfsm.fsm.NamedElement o_cast = (org.eclipse.gemoc.sample.legacyfsm.xsfsm.xsfsm.fsm.NamedElement) o;
                    addNewObjectToState(o_cast, lastState);
                }
            }
        }
        this.traceRoot.getStates().add(lastState);
    }
}
项目:time4sys    文件:ReferencingViewpointElementQuery.java   
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param object_p: The model element for which the Contextual Explorer extension is generated
* @return List of object to display in the parent category
* @generated
*/
public List<Object> compute(Object object_p) {
    List<Object> result = new ArrayList<Object>();
    Resource resource = ((EObject) object_p).eResource();
    if (resource != null) {
        for (TreeIterator<EObject> iter = resource.getAllContents(); iter.hasNext();) {
            EObject eObject = iter.next();

            if (eObject instanceof Alarm) {
                Alarm referencingElement = (Alarm) eObject;
                if (referencingElement.getTimers() != null && referencingElement.getTimers().contains(object_p))
                    result.add(eObject);
            }
        }
    }
    return result;
}
项目:time4sys    文件:ReferencingViewpointElementQuery.java   
/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * 
 * @param object_p:
 *            The model element for which the Contextual Explorer extension
 *            is generated
 * @return List of object to display in the parent category
 * @generated
 */
public List<Object> compute(Object object_p) {
    List<Object> result = new ArrayList<Object>();
    Resource resource = ((EObject) object_p).eResource();
    if (resource != null) {
        for (TreeIterator<EObject> iter = resource.getAllContents(); iter.hasNext();) {
            EObject eObject = iter.next();
            if (eObject instanceof Step) {
                Step referencingElement = (Step) eObject;
                if (referencingElement.getConcurRes() != null && referencingElement.getConcurRes().equals(object_p))
                    result.add(eObject);
            }
        }
    }
    return result;
}
项目:solidity-ide    文件:SoliditySemanticHighlighter.java   
@Override
public void provideHighlightingFor(XtextResource resource,
        org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor acceptor) {
    TreeIterator<EObject> allContents = resource.getAllContents();
    while (allContents.hasNext()) {
        EObject next = allContents.next();
        if (next.eIsProxy()) {
            continue;
        }
        if (next instanceof ElementReferenceExpression) {
            if (next instanceof ElementReferenceExpression) {
                ElementReferenceExpression expression = (ElementReferenceExpression) next;
                provideHighligtingFor(expression, acceptor);
            }
        }
    }
}
项目:solidity-ide    文件:SolidityImportedNamespaceAwareLocalScopeProvider.java   
protected List<ImportNormalizer> getSuperTypeImports(Resource res, EReference reference) {
    List<ImportNormalizer> result = Lists.newArrayList();
    TreeIterator<EObject> allContents = res.getAllContents();
    while (allContents.hasNext()) {
        EObject next = allContents.next();
        if (next instanceof ContractDefinition) {
            ContractDefinition contract = (ContractDefinition) next;
            EList<ComplexType> superTypes = contract.getSuperTypes();
            for (ComplexType complexType : superTypes) {
                // if (complexType.eIsProxy() || complexType.getName() ==
                // null)
                // continue;
                ImportNormalizer resolver = createImportedNamespaceResolver(complexType.getName() + ".*", false);
                result.add(resolver);
            }
            allContents.prune();
        }
    }
    return result;
}
项目:codegen-ecore    文件:EcoreCodegenViewer.java   
@Override
public void setSelection(ISelection selection, boolean reveal) {
    this.selection = selection;
    if (selection instanceof StructuredSelection) {
        Z: for (Object se: ((StructuredSelection) selection).toArray()) {
            if (se instanceof EcoreCodeGenerator) {
                generatorForm.setGenerator((EcoreCodeGenerator) se);
                break;
            }
            if (se instanceof Resource) {
                TreeIterator<EObject> tit = ((Resource) se).getAllContents();
                while (tit.hasNext()) {
                    EObject next = tit.next();
                    if (next instanceof EcoreCodeGenerator) {
                        generatorForm.setGenerator((EcoreCodeGenerator) next);
                        break Z;
                    }
                }
            }
        }
    }
}
项目:library-training    文件:NewChildTest.java   
/**
 * Check that referenced element type are in the registry
 */
@Test
public void checkMenuNewChildElementTypeIdRefs() {
    URI createPlatformPluginURI = URI.createPlatformPluginURI(NEW_CHILD_MENU_PATH, true);
    ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
    Resource resource = resourceSetImpl.getResource(createPlatformPluginURI, true);

    TreeIterator<EObject> allContents = resource.getAllContents();
    while (allContents.hasNext()) {
        EObject eObject = (EObject) allContents.next();
        if (eObject instanceof CreationMenu) {
            String iconPath = ((CreationMenu) eObject).getIcon();
             if (iconPath != null && !"".equals(iconPath)){
                    try {
                        Assert.assertNotNull("The icon "+iconPath+" can't be found", FileLocator.find(new URL(iconPath)));
                    } catch (MalformedURLException e) {
                        Assert.fail("The new child menu is refering to a malformed url "+iconPath);
                    }
             }
        }
    }
}
项目:xtext-extras    文件:XbaseValidator.java   
protected boolean hasConstructorCallWithThis(JvmConstructor constr) {
    XExpression associatedExpression = logicalContainerProvider.getAssociatedExpression(constr);
    if (associatedExpression == null) {
        return false;
    }
    TreeIterator<EObject> contents = associatedExpression.eAllContents();
    while (contents.hasNext()) {
        EObject next = contents.next();
        if (next instanceof XFeatureCall) {
            XFeatureCall featureCall = (XFeatureCall) next;
            if (featureCall.getFeature() instanceof JvmConstructor && featureCall.getConcreteSyntaxFeatureName().equals(IFeatureNames.THIS.toString())) {
                return true;
            }
        }
    }
    return false;
}
项目:xtext-extras    文件:XbaseValidator.java   
protected void checkIsValidConstructorArgument(XExpression argument, JvmType containerType) {
    TreeIterator<EObject> iterator = EcoreUtil2.eAll(argument);
    while(iterator.hasNext()) {
        EObject partOfArgumentExpression = iterator.next();
        if (partOfArgumentExpression instanceof XFeatureCall || partOfArgumentExpression instanceof XMemberFeatureCall) {               
            XAbstractFeatureCall featureCall = (XAbstractFeatureCall) partOfArgumentExpression;
            XExpression actualReceiver = featureCall.getActualReceiver();
            if(actualReceiver instanceof XFeatureCall && ((XFeatureCall)actualReceiver).getFeature() == containerType) {
                JvmIdentifiableElement feature = featureCall.getFeature();
                if (feature != null && !feature.eIsProxy()) {
                    if (feature instanceof JvmField) {
                        if (!((JvmField) feature).isStatic())
                            error("Cannot refer to an instance field " + feature.getSimpleName() + " while explicitly invoking a constructor", 
                                    partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT);
                    } else if (feature instanceof JvmOperation) {
                        if (!((JvmOperation) feature).isStatic())
                            error("Cannot refer to an instance method while explicitly invoking a constructor", 
                                    partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT);  
                    }
                }
            }
        } else if(isLocalClassSemantics(partOfArgumentExpression)) {
            iterator.prune();
        }
    }
}
项目:xtext-extras    文件:ClosureWithExpectationHelper.java   
protected boolean isImplicitReturn(ITypeComputationResult expressionResult) {
    int flags = expressionResult.getConformanceFlags();
    if ((ConformanceFlags.NO_IMPLICIT_RETURN & flags) != 0) {
        return false;
    }
    XExpression expression = expressionResult.getExpression();
    if (expression == null) {
        return true;
    }
    if (expression.eClass() == XbasePackage.Literals.XRETURN_EXPRESSION) {
        return false;
    }
    TreeIterator<EObject> contents = expression.eAllContents();
    while (contents.hasNext()) {
        EObject next = contents.next();
        if (next.eClass() == XbasePackage.Literals.XRETURN_EXPRESSION) {
            return false;
        }
        if (next.eClass() == XbasePackage.Literals.XCLOSURE) {
            contents.prune();
        }
    }
    return true;
}
项目:xtext-extras    文件:XbaseUsageCrossReferencer.java   
@Override
protected TreeIterator<Notifier> newContentsIterator() {
    return new ContentTreeIterator<Notifier>(emfObjects) {
        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<? extends EObject> getEObjectChildren(EObject eObject) {
            if(eObject instanceof XAbstractFeatureCall){
                Iterable<EObject> result = eObject.eContents();
                XAbstractFeatureCall featureCall = (XAbstractFeatureCall) eObject;
                XExpression implicitReceiver = featureCall.getImplicitReceiver();
                if(implicitReceiver != null) 
                    result = Iterables.concat(result, Collections.singleton(implicitReceiver));
                XExpression implicitFirstArgument = featureCall.getImplicitFirstArgument();
                if(implicitFirstArgument != null)
                    result = Iterables.concat(result, Collections.singleton(implicitFirstArgument));
                return result.iterator();
            } else 
                return super.getEObjectChildren(eObject);
        }
    };
}
项目:xtext-extras    文件:XbaseCompiler.java   
protected boolean canCompileToJavaLambda(XClosure closure, LightweightTypeReference typeRef, JvmOperation operation) {
    if (!typeRef.isInterfaceType())
        return false;

    if (!operation.getTypeParameters().isEmpty())
        return false;

    TreeIterator<EObject> iterator = closure.eAllContents();
    JvmType jvmType = typeRef.getType();
    while (iterator.hasNext()) {
        EObject obj = iterator.next();
        if (obj instanceof XClosure) {
            iterator.prune();
        } else if (obj instanceof XFeatureCall && isReferenceToSelf((XFeatureCall) obj, jvmType)) {
            return false;
        }
    }
    return true;
}
项目:xtext-extras    文件:DefaultImportsConfiguration.java   
@Override
public Iterable<JvmDeclaredType> getLocallyDefinedTypes(XtextResource resource) {
    final List<JvmDeclaredType> locallyDefinedTypes = newArrayList();
    for (TreeIterator<EObject> i = resource.getAllContents(); i.hasNext();) {
        EObject next = i.next();
        if (next instanceof JvmDeclaredType) {
            JvmDeclaredType declaredType = (JvmDeclaredType) next;
            locallyDefinedTypes.add(declaredType);
            addInnerTypes(declaredType, new IAcceptor<JvmDeclaredType>() {
                @Override
                public void accept(JvmDeclaredType t) {
                    locallyDefinedTypes.add(t);
                }
            });
            i.prune();
        }
        if(next instanceof XExpression) {
            i.prune();
        }
    }
    return locallyDefinedTypes;
}
项目:xtext-extras    文件:EMFGeneratorFragment.java   
private Map<String, EPackage> findAllUsedEPackages(List<EPackage> generatedPackages) {
    Map<String, EPackage> result = Maps.newHashMap();
    TreeIterator<EObject> packageContentIterator = EcoreUtil.<EObject>getAllContents(generatedPackages);
    while(packageContentIterator.hasNext()) {
        EObject current = packageContentIterator.next();
        for(EObject referenced: current.eCrossReferences()) {
            if (referenced.eIsProxy())
                throw new RuntimeException("Unresolved proxy: " + referenced + " in " + current);
            if (referenced instanceof EClassifier) {
                EPackage referencedPackage = ((EClassifier) referenced).getEPackage();
                if (!generatedPackages.contains(referencedPackage)) {
                    result.put(referencedPackage.getNsURI(), referencedPackage);
                }
            }
        }
    }
    return result;
}
项目:DarwinSPL    文件:HyEvolutionUtil.java   
/**
 * Returns a container for evolved elements (new and removed) of the given
 * model. Elements which are added and again removed between those dates are
 * not considered
 * 
 * @param model
 * @param originDate
 * @param evolvedDate
 * @return
 */
public static HyEvolvedElementsContainer getEvolvedElements(EObject model, Date originDate, Date evolvedDate) {
    List<EObject> newElements = new ArrayList<EObject>();
    List<EObject> removedElements = new ArrayList<EObject>();

    TreeIterator<EObject> modelIterator = model.eAllContents();
    while (modelIterator.hasNext()) {
        EObject modelObject = modelIterator.next();
        if (modelObject instanceof HyTemporalElement) {
            HyTemporalElement evolvedElement = (HyTemporalElement) modelObject;

            boolean validAtOriginDate = isValid(evolvedElement, originDate);
            boolean validAtEvolvedDate = isValid(evolvedElement, evolvedDate);

            if (validAtEvolvedDate && !validAtOriginDate) {
                newElements.add(evolvedElement);
            } else if (validAtOriginDate && !validAtEvolvedDate) {
                removedElements.add(evolvedElement);
            }
        }
    }

    HyEvolvedElementsContainer evolvedElements = new HyEvolvedElementsContainer(newElements, removedElements);
    return evolvedElements;
}
项目:DarwinSPL    文件:HyEvolutionUtil.java   
/**
 * Use with caution! Deletes elements from model with HyTemporalElements!
 * 
 * @param featureModel
 * @param date
 */
public static void removeAllInvalidElements(EObject model, Date date) {
    List<EObject> eObjectsToRemove = new ArrayList<EObject>();
    {
        TreeIterator<EObject> iterator = model.eAllContents();

        while (iterator.hasNext()) {
            EObject content = iterator.next();
            if (content instanceof HyTemporalElement) {
                if (!isValid(((HyTemporalElement) content), date)) {
                    // EcoreUtil.remove(content);
                    eObjectsToRemove.add(content);
                }
            }
        }

    }

    for (EObject eObjectToRemove : eObjectsToRemove) {
        EcoreUtil.delete(eObjectToRemove, true);
    }
}
项目:minitl    文件:MinitlTraceConstructor.java   
private void addInitialState() {
    if (lastState == null) {
        // Creation of the initial state
        Set<Resource> allResources = getAllExecutedModelResources();
        lastState = minitlTrace.States.StatesFactory.eINSTANCE.createSpecificState();
        for (Resource r : allResources) {
            for (TreeIterator<EObject> i = r.getAllContents(); i.hasNext();) {
                EObject o = i.next();

                if (o instanceof org.tetrabox.example.minitl.minitl.NamedElement) {
                    org.tetrabox.example.minitl.minitl.NamedElement o_cast = (org.tetrabox.example.minitl.minitl.NamedElement) o;
                    addNewObjectToState(o_cast, lastState);
                }
            }
        }
        this.traceRoot.getStates().add(lastState);
    }
}
项目:Vitruv    文件:EcoreBridge.java   
/**
 * Determines all objects that refer to <code>target</code> by the reference
 * <code>reference</code>
 * 
 * @param target
 *            the target of the references
 * @param reference
 *            the reference to search for
 * @return all (distinct) objects that refer to target by reference
 * @author Dominik Werle
 */
public static Set<EObject> findOppositeForFeature(EObject target, EReference reference) {
    Set<EObject> result = new HashSet<EObject>();

    Resource resource = target.eResource();
    TreeIterator<Object> iter = EcoreUtil.getAllProperContents(resource, true);
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof EObject) {
            EObject eobj = (EObject) obj;

            if (reference.getEContainingClass().isSuperTypeOf(eobj.eClass())) {
                Object referencedObject = eobj.eGet(reference);
                if ((referencedObject instanceof EList<?>) && (((EList<?>) referencedObject).contains(target))) {
                    result.add(eobj);
                } else if (referencedObject.equals(target)) {
                    result.add(eobj);
                }
            }
        }
    }

    return result;

}
项目:xtext-core    文件:ConcreteSyntaxConstraintProvider.java   
protected boolean ruleContainsAssignedAction(AbstractRule rule, Set<AbstractRule> visited) {
    if (!visited.add(rule))
        return false;
    TreeIterator<EObject> i = rule.eAllContents();
    while (i.hasNext()) {
        EObject o = i.next();
        if (o instanceof Action && ((Action) o).getFeature() != null)
            return true;
        else if (o instanceof Assignment)
            i.prune();
        else if (o instanceof RuleCall && isParserRule(((RuleCall) o).getRule())) {
            if (ruleContainsAssignedAction(((RuleCall) o).getRule(), visited))
                return true;
        }
    }
    return false;
}
项目:xtext-core    文件:PartialParsingHelper.java   
private boolean isRangePartOfExceedingLookAhead(CompositeNode node, ReplaceRegion replaceRegion) {
    TreeIterator<AbstractNode> iterator = node.basicIterator();
    int lookAhead = node.getLookAhead();
    if (lookAhead == 0) {
        return false;
    }
    while(iterator.hasNext()) {
        AbstractNode child = iterator.next();
        if (child instanceof CompositeNode) {
            if (child.getTotalOffset() < replaceRegion.getEndOffset())
                lookAhead = Math.max(((CompositeNode) child).getLookAhead(), lookAhead);
        } else if (!((ILeafNode) child).isHidden()) {
            lookAhead--;
            if (lookAhead == 0) {
                if (child.getTotalOffset() >= replaceRegion.getEndOffset())
                    return false;
            }
        }
    }
    return lookAhead > 0;
}
项目:xtext-core    文件:DefaultResourceDescription.java   
@Override
protected List<IEObjectDescription> computeExportedObjects() {
    if (!getResource().isLoaded()) {
        try {
            getResource().load(null);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            return Collections.<IEObjectDescription> emptyList();
        }
    }
    final List<IEObjectDescription> exportedEObjects = newArrayList();
    IAcceptor<IEObjectDescription> acceptor = new IAcceptor<IEObjectDescription>() {
        @Override
        public void accept(IEObjectDescription eObjectDescription) {
            exportedEObjects.add(eObjectDescription);
        }
    };
    TreeIterator<EObject> allProperContents = EcoreUtil.getAllProperContents(getResource(), false);
    while (allProperContents.hasNext()) {
        EObject content = allProperContents.next();
        if (!strategy.createEObjectDescriptions(content, acceptor))
            allProperContents.prune();
    }
    return exportedEObjects;
}
项目:xtext-core    文件:DefaultResourceDescription.java   
protected List<IReferenceDescription> computeReferenceDescriptions() {
    final List<IReferenceDescription> referenceDescriptions = Lists.newArrayList();
    IAcceptor<IReferenceDescription> acceptor = new IAcceptor<IReferenceDescription>() {
        @Override
        public void accept(IReferenceDescription referenceDescription) {
            referenceDescriptions.add(referenceDescription);
        }
    };
    EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
    Map<EObject, IEObjectDescription> eObject2exportedEObjects = createEObject2ExportedEObjectsMap(getExportedObjects());
    TreeIterator<EObject> contents = EcoreUtil.getAllProperContents(this.resource, true);
    while (contents.hasNext()) {
        EObject eObject = contents.next();
        URI exportedContainerURI = findExportedContainerURI(eObject, eObject2exportedEObjects);
        if (!strategy.createReferenceDescriptions(eObject, exportedContainerURI, acceptor))
            contents.prune();
    }
    return referenceDescriptions;
}
项目:xtext-core    文件:AbstractElementFinder.java   
public List<CrossReference> findCrossReferences(EClassifier... targetEClassifiers) {
    Set<EClassifier> classifiers = new HashSet<EClassifier>(Arrays.asList(targetEClassifiers));
    Collection<EClass> classes = Lists.newArrayList(Iterables.filter(classifiers, EClass.class));
    ArrayList<CrossReference> r = new ArrayList<CrossReference>();
    for (AbstractRule ar : getRules()) {
        TreeIterator<EObject> i = ar.eAllContents();
        while (i.hasNext()) {
            EObject o = i.next();
            if (o instanceof CrossReference) {
                CrossReference c = (CrossReference) o;
                if (classifiers.contains(c.getType().getClassifier()))
                    r.add(c);
                else if (c.getType().getClassifier() instanceof EClass)
                    for (EClass cls : classes)
                        if (EcoreUtil2.isAssignableFrom(cls,(EClass) c.getType().getClassifier())) {
                            r.add(c);
                            break;
                        }
                i.prune();
            }
        }
    }
    return r;

}
项目:xtext-core    文件:AbstractElementFinder.java   
public List<Pair<Keyword, Keyword>> findKeywordPairs(String leftKw, String rightKw) {
    ArrayList<Pair<Keyword, Keyword>> pairs = new ArrayList<Pair<Keyword, Keyword>>();
    for (AbstractRule ar : getRules())
        if (ar instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) ar)) {
            Stack<Keyword> openings = new Stack<Keyword>();
            TreeIterator<EObject> i = ar.eAllContents();
            while (i.hasNext()) {
                EObject o = i.next();
                if (o instanceof Keyword) {
                    Keyword k = (Keyword) o;
                    if (leftKw.equals(k.getValue()))
                        openings.push(k);
                    else if (rightKw.equals(k.getValue())) {
                        if (openings.size() > 0)
                            pairs.add(Tuples.create(openings.pop(), k));
                    }
                }
            }
        }
    return pairs;
}
项目:xtext-core    文件:AbstractElementFinder.java   
public List<Keyword> findKeywords(String... keywords) {
    Set<String> kwds = new HashSet<String>(Arrays.asList(keywords));
    ArrayList<Keyword> r = new ArrayList<Keyword>();
    for (AbstractRule ar : getRules()) {
        TreeIterator<EObject> i = ar.eAllContents();
        while (i.hasNext()) {
            EObject o = i.next();
            if (o instanceof Keyword) {
                Keyword k = (Keyword) o;
                if (kwds.contains(k.getValue()))
                    r.add(k);
            }
        }
    }
    return r;
}
项目:xtext-core    文件:GrammarElementDeclarationOrder.java   
protected GrammarElementDeclarationOrder(Grammar grammar) {
    elementIDCache = Maps.newHashMap();
    List<Grammar> grammars = Lists.newArrayList(grammar);
    grammars.addAll(GrammarUtil.allUsedGrammars(grammar));
    int counter = 0;
    for (Grammar g : grammars) {
        elementIDCache.put(g, counter++);
        for (AbstractRule rule : g.getRules()) {
            elementIDCache.put(rule, counter++);
            TreeIterator<EObject> iterator = rule.eAllContents();
            while (iterator.hasNext()) {
                elementIDCache.put(iterator.next(), counter++);
            }
        }
    }
}
项目:xtext-core    文件:ImportUriGlobalScopeProvider.java   
protected LinkedHashSet<URI> getImportedUris(final Resource resource) {
    return cache.get(ImportUriGlobalScopeProvider.class.getName(), resource, new Provider<LinkedHashSet<URI>>(){
        @Override
        public LinkedHashSet<URI> get() {
            final LinkedHashSet<URI> uniqueImportURIs = new LinkedHashSet<URI>(5);
            IAcceptor<String> collector = createURICollector(resource, uniqueImportURIs);
            TreeIterator<EObject> iterator = resource.getAllContents();
            while (iterator.hasNext()) {
                EObject object = iterator.next();
                collector.accept(importResolver.apply(object));
            }
            Iterator<URI> uriIter = uniqueImportURIs.iterator();
            while(uriIter.hasNext()) {
                if (!EcoreUtil2.isValidUri(resource, uriIter.next()))
                    uriIter.remove();
            }
            return uniqueImportURIs;
        }
    });
}
项目:xtext-core    文件:LazyLinkingResource.java   
/**
 * resolves any lazy cross references in this resource, adding Issues for unresolvable elements to this resource.
 * This resource might still contain resolvable proxies after this method has been called.
 * 
 * @param mon a {@link CancelIndicator} can be used to stop the resolution.
 */
public void resolveLazyCrossReferences(final CancelIndicator mon) {
    final CancelIndicator monitor = mon == null ? CancelIndicator.NullImpl : mon;
    TreeIterator<Object> iterator = EcoreUtil.getAllContents(this, true);
    while (iterator.hasNext()) {
        operationCanceledManager.checkCanceled(monitor);
        InternalEObject source = (InternalEObject) iterator.next();
        EStructuralFeature[] eStructuralFeatures = ((EClassImpl.FeatureSubsetSupplier) source.eClass()
                .getEAllStructuralFeatures()).crossReferences();
        if (eStructuralFeatures != null) {
            for (EStructuralFeature crossRef : eStructuralFeatures) {
                operationCanceledManager.checkCanceled(monitor);
                resolveLazyCrossReference(source, crossRef);
            }
        }
    }
}