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));
}
}
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]++;
}
}
}
Aggregations