Search in sources :

Example 1 with ISequentialRegion

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

the class RegionAccessBuilderTest method assertToStringDoesNotCrash.

private void assertToStringDoesNotCrash(final ITextRegionAccess access) {
    IHiddenRegion _previousHiddenRegion = access.regionForRootEObject().getPreviousHiddenRegion();
    ISequentialRegion current = ((ISequentialRegion) _previousHiddenRegion);
    while ((current != null)) {
        {
            Assert.assertNotNull(current.toString());
            boolean _matched = false;
            if (current instanceof IHiddenRegion) {
                _matched = true;
                current = ((IHiddenRegion) current).getNextSemanticRegion();
            }
            if (!_matched) {
                if (current instanceof ISemanticRegion) {
                    _matched = true;
                    Assert.assertNotNull(((ISemanticRegion) current).getEObjectRegion().toString());
                    current = ((ISemanticRegion) current).getNextHiddenRegion();
                }
            }
        }
    }
}
Also used : ISequentialRegion(org.eclipse.xtext.formatting2.regionaccess.ISequentialRegion) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 2 with ISequentialRegion

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

the class TextRegionAccessToString method toTokenAndGapList.

protected List<ITextSegment> toTokenAndGapList() {
    final int range = this.hightlightOrigin ? 4 : (Integer.MAX_VALUE / 2);
    ITextSegment first = null;
    {
        ITextSegment current = origin;
        for (int i = 0; i < range && current != null; i++) {
            first = current;
            if (current instanceof ITextRegionAccess)
                current = ((ITextRegionAccess) current).regionForRootEObject().getPreviousHiddenRegion();
            else if (current instanceof ISequentialRegion)
                current = ((ISequentialRegion) current).getPreviousHiddenRegion();
            else if (current instanceof IHiddenRegionPart)
                current = ((IHiddenRegionPart) current).getHiddenRegion();
            else
                throw new IllegalStateException("Unexpected Type: " + current.getClass());
        }
    }
    if (first == null)
        return Collections.emptyList();
    List<ITextSegment> result = Lists.newArrayList();
    {
        ITextSegment current = first;
        for (int i = 0; i <= (range * 2) && current != null; i++) {
            result.add(current);
            if (current instanceof ISemanticRegion)
                current = ((ISemanticRegion) current).getNextHiddenRegion();
            else if (current instanceof IHiddenRegion)
                current = ((IHiddenRegion) current).getNextSemanticRegion();
            else
                throw new IllegalStateException("Unexpected Type: " + current.getClass());
        }
    }
    return result;
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ISequentialRegion(org.eclipse.xtext.formatting2.regionaccess.ISequentialRegion) IHiddenRegionPart(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegionPart) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) ITextSegment(org.eclipse.xtext.formatting2.regionaccess.ITextSegment) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 3 with ISequentialRegion

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

the class PartialSerializer method trySerializeMultiValue.

protected List<SerializationStrategy> trySerializeMultiValue(EObject owner, FeatureChange change, IEObjectRegion ownerRegion, IConstraint constraint) {
    EStructuralFeature feature = change.getFeature();
    List<SerializationStrategy> result = Lists.newArrayList();
    IFeatureInfo featureInfo = constraint.getFeatures()[owner.eClass().getFeatureID(feature)];
    List<IConstraintElement> assignments = featureInfo.getAssignments();
    if (assignments.size() != 1) {
        return null;
    }
    IConstraintElement assignment = assignments.get(0);
    if (!assignment.isMany()) {
        return null;
    }
    List<IAstRegion> originals = findRegions(ownerRegion, change);
    EList<ListChange> listChanges = change.getListChanges();
    if (listChanges.isEmpty() && originals.isEmpty()) {
        ISerializationContext ctx = getSerializationContext(owner);
        AbstractElement ins = assignment.getGrammarElement();
        IHiddenRegion insertAt = insertionPointFinder.findInsertionPoint(ctx, ownerRegion, ins);
        if (insertAt == null) {
            return null;
        }
        for (Object value : (List<?>) owner.eGet(feature)) {
            EObject obj = (EObject) value;
            ISerializationContext context = getSerializationContext(obj);
            result.add(new SerializeRecursiveStrategy(insertAt, obj, context));
        }
        return result;
    }
    // ListTransient listTransient = transientValues.isListTransient(owner, feature);
    List<Object> modifying = Lists.newArrayList(((List<?>) owner.eGet(feature)));
    for (ListChange lc : listChanges) {
        ChangeKind kind = lc.getKind();
        if (kind == ADD_LITERAL) {
            IAstRegion region = originals.get(lc.getIndex());
            result.add(new DeleteRegionStrategy(region));
        } else if (kind == MOVE_LITERAL || kind == REMOVE_LITERAL) {
            if (originals.isEmpty()) {
                return null;
            }
            int index = lc.getIndex();
            IHiddenRegion insertAt;
            if (index >= originals.size()) {
                insertAt = ((ISequentialRegion) originals.get(originals.size() - 1)).getNextHiddenRegion();
            } else {
                insertAt = ((ISequentialRegion) originals.get(index)).getPreviousHiddenRegion();
            }
            EObject value = (EObject) modifying.get(index);
            modifying.remove(index);
            if (kind == REMOVE_LITERAL) {
                ISerializationContext context = getSerializationContext(value);
                result.add(new SerializeRecursiveStrategy(insertAt, value, context));
            } else if (kind == ChangeKind.MOVE_LITERAL) {
                int moveToIndex = lc.getMoveToIndex();
                IAstRegion source = originals.get(moveToIndex);
                result.add(new DeleteRegionStrategy(source));
                result.add(new InsertRegionStrategy(insertAt, source));
            }
        }
    }
    return result;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IConstraint(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint) IFeatureInfo(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IFeatureInfo) IConstraintElement(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraintElement) ISequentialRegion(org.eclipse.xtext.formatting2.regionaccess.ISequentialRegion) IAstRegion(org.eclipse.xtext.formatting2.regionaccess.IAstRegion) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) EObject(org.eclipse.emf.ecore.EObject) IHiddenRegion(org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion) 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) ChangeKind(org.eclipse.emf.ecore.change.ChangeKind)

Aggregations

IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)3 ISequentialRegion (org.eclipse.xtext.formatting2.regionaccess.ISequentialRegion)3 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)2 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 ChangeKind (org.eclipse.emf.ecore.change.ChangeKind)1 ListChange (org.eclipse.emf.ecore.change.ListChange)1 AbstractElement (org.eclipse.xtext.AbstractElement)1 IAstRegion (org.eclipse.xtext.formatting2.regionaccess.IAstRegion)1 IHiddenRegionPart (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegionPart)1 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)1 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)1 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)1 IConstraint (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint)1 IConstraintElement (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraintElement)1 IFeatureInfo (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IFeatureInfo)1