Search in sources :

Example 6 with IAstRegion

use of org.eclipse.xtext.formatting2.regionaccess.IAstRegion in project xtext-core by eclipse.

the class PartialSerializer method findRegions.

protected List<IAstRegion> findRegions(IEObjectRegion owner, FeatureChange change) {
    EStructuralFeature feature = change.getFeature();
    if (feature instanceof EReference && ((EReference) feature).isContainment()) {
        ITextRegionAccess access = owner.getTextRegionAccess();
        Set<EObject> children = Sets.newHashSet();
        for (ListChange lc : change.getListChanges()) {
            children.addAll(lc.getReferenceValues());
        }
        for (Object obj : (List<?>) owner.getSemanticElement().eGet(feature)) {
            children.add((EObject) obj);
        }
        List<IEObjectRegion> result = Lists.newArrayList();
        for (EObject obj : children) {
            IEObjectRegion region = access.regionForEObject(obj);
            if (region != null) {
                result.add(region);
            }
        }
        Collections.sort(result, (a, b) -> a.getOffset() - b.getOffset());
        return ImmutableList.copyOf(result);
    } else {
        return ImmutableList.copyOf(owner.getRegionFor().features(feature));
    }
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) EList(org.eclipse.emf.common.util.EList) ListChange(org.eclipse.emf.ecore.change.ListChange) EReference(org.eclipse.emf.ecore.EReference)

Example 7 with IAstRegion

use of org.eclipse.xtext.formatting2.regionaccess.IAstRegion in project xtext-core by eclipse.

the class AbstractEObjectRegion method initChildrenFeatureIndexes.

protected void initChildrenFeatureIndexes() {
    EClass clazz = semanticElement.eClass();
    int[] indices = new int[clazz.getFeatureCount()];
    Arrays.fill(indices, 0);
    for (IAstRegion ele : children) {
        EStructuralFeature feat = ele.getContainingFeature();
        if (feat != null && feat.isMany()) {
            int id = clazz.getFeatureID(feat);
            if (ele instanceof AbstractEObjectRegion) {
                ((AbstractEObjectRegion) ele).indexInFeature = indices[id];
            } else if (ele instanceof NodeSemanticRegion) {
                ((NodeSemanticRegion) ele).indexInFeature = indices[id];
            } else if (ele instanceof StringSemanticRegion) {
                ((StringSemanticRegion) ele).indexInFeature = indices[id];
            }
            indices[id]++;
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IAstRegion(org.eclipse.xtext.formatting2.regionaccess.IAstRegion) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Aggregations

EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)5 EObject (org.eclipse.emf.ecore.EObject)4 IAstRegion (org.eclipse.xtext.formatting2.regionaccess.IAstRegion)4 EReference (org.eclipse.emf.ecore.EReference)3 ImmutableList (com.google.common.collect.ImmutableList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 EList (org.eclipse.emf.common.util.EList)2 ListChange (org.eclipse.emf.ecore.change.ListChange)2 AbstractElement (org.eclipse.xtext.AbstractElement)2 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)2 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)2 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)2 IConstraintElement (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraintElement)2 IFeatureInfo (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IFeatureInfo)2 EAttribute (org.eclipse.emf.ecore.EAttribute)1 EClass (org.eclipse.emf.ecore.EClass)1 ChangeKind (org.eclipse.emf.ecore.change.ChangeKind)1 CrossReference (org.eclipse.xtext.CrossReference)1 RuleCall (org.eclipse.xtext.RuleCall)1