use of org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion in project xtext-xtend by eclipse.
the class RichStringToLineModel method announceNextLiteral.
@Override
public void announceNextLiteral(final RichStringLiteral object) {
super.announceNextLiteral(object);
if (((this.lastLiteralEndOffset > 0) && (this.contentStartOffset < 0))) {
this.contentStartOffset = this.lastLiteralEndOffset;
}
IEObjectRegion _regionForEObject = this.nodeModelAccess.regionForEObject(object);
ISemanticRegionsFinder _regionFor = null;
if (_regionForEObject != null) {
_regionFor = _regionForEObject.getRegionFor();
}
ISemanticRegion _feature = null;
if (_regionFor != null) {
_feature = _regionFor.feature(XbasePackage.Literals.XSTRING_LITERAL__VALUE);
}
final ISemanticRegion node = _feature;
if ((node != null)) {
int _offset = node.getOffset();
int _literalPrefixLenght = this.literalPrefixLenght(node);
int _plus = (_offset + _literalPrefixLenght);
this.offset = _plus;
int _endOffset = node.getEndOffset();
int _literalPostfixLenght = this.literalPostfixLenght(node);
int _minus = (_endOffset - _literalPostfixLenght);
this.lastLiteralEndOffset = _minus;
}
this.content = true;
}
use of org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion in project xtext-core by eclipse.
the class InsertionPointFinder method findInsertionPoint.
public IHiddenRegion findInsertionPoint(ISerializationContext ctx, IEObjectRegion obj, AbstractElement ins) {
ISerState insertionState = findState(ctx, ins);
Set<AbstractElement> followers = collectAdjacent(insertionState, s -> s.getFollowers());
Set<AbstractElement> precendents = collectAdjacent(insertionState, s -> s.getPrecedents());
List<IAstRegion> regions = Lists.newArrayList(obj.getAstRegions());
if (regions.isEmpty()) {
return obj.getPreviousHiddenRegion();
}
if (followers.contains(regions.get(0).getGrammarElement())) {
return obj.getPreviousHiddenRegion();
}
if (precendents.contains(regions.get(regions.size() - 1).getGrammarElement())) {
return obj.getNextHiddenRegion();
}
for (int i = 0; i < regions.size() - 1; i++) {
IAstRegion leading = regions.get(i);
IAstRegion trailing = regions.get(i + 1);
if (precendents.contains(leading.getGrammarElement()) && followers.contains(trailing.getGrammarElement())) {
return leading.getNextHiddenRegion();
}
}
return null;
}
use of org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion in project xtext-core by eclipse.
the class PartialSerializer method trySerializeSingleValue.
protected List<SerializationStrategy> trySerializeSingleValue(EObject owner, FeatureChange change, IEObjectRegion ownerRegion, IConstraint constraint) {
List<SerializationStrategy> result = Lists.newArrayList();
EStructuralFeature feature = change.getFeature();
IFeatureInfo featureInfo = constraint.getFeatures()[owner.eClass().getFeatureID(feature)];
List<IConstraintElement> assignments = featureInfo.getAssignments();
if (assignments.size() != 1) {
return null;
}
boolean optional = assignments.get(0).isOptional();
IAstRegion featureRegion = findRegion(ownerRegion, change);
ValueTransient valueTransient = transientValues.isValueTransient(owner, feature);
switch(valueTransient) {
case YES:
if (featureRegion != null) {
if (optional) {
result.add(new DeleteRegionStrategy(featureRegion));
} else {
return null;
}
}
break;
case PREFERABLY:
if (featureRegion != null) {
if (optional) {
result.add(new DeleteRegionStrategy(featureRegion));
} else {
SerializationStrategy update = updateSingleValue(owner, feature, featureRegion);
if (update != null) {
result.add(update);
} else {
return null;
}
}
}
break;
case NO:
if (featureRegion == null) {
return null;
}
SerializationStrategy update = updateSingleValue(owner, feature, featureRegion);
if (update != null) {
result.add(update);
} else {
return null;
}
break;
}
return result;
}
use of org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion in project xtext-core by eclipse.
the class PartialSerializer method findRegion.
protected IAstRegion findRegion(IEObjectRegion owner, FeatureChange change) {
EStructuralFeature feature = change.getFeature();
if (feature instanceof EReference && ((EReference) feature).isContainment()) {
ITextRegionAccess access = owner.getTextRegionAccess();
EObject oldValue = change.getReferenceValue();
if (oldValue != null) {
return access.regionForEObject(oldValue);
}
EObject value = (EObject) owner.getSemanticElement().eGet(feature);
if (value != null) {
return access.regionForEObject(value);
}
return null;
} else {
return owner.getRegionFor().feature(feature);
}
}
use of org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion in project xtext-core by eclipse.
the class PartialSerializer method serializeChanges.
public void serializeChanges(ResourceRecording changes, ITextRegionDiffBuilder result) {
assertLanguage(changes);
SerializationContextMap<IConstraint> constraints = constraintProvider.getConstraints(grammar.getGrammar());
List<EObjectChange> rootChanges = collectRootChanges(changes.getRootEObjectRecordings());
List<SerializationStrategy> strategies = Lists.newArrayList();
while (!rootChanges.isEmpty()) {
List<EObjectChange> nextRoots = Lists.newArrayList();
for (EObjectChange change : rootChanges) {
EObject obj = change.getEObject();
IEObjectRegion originalEObjectRegion = result.getOriginalTextRegionAccess().regionForEObject(obj);
ISerializationContext modified = getSerializationContext(obj);
if (originalEObjectRegion == null) {
strategies.add(new SerializeRecursiveStrategy(originalEObjectRegion, obj, modified));
continue;
}
ISerializationContext original = getSerializationContext(originalEObjectRegion);
if (!original.equals(modified)) {
strategies.add(new SerializeRecursiveStrategy(originalEObjectRegion, obj, modified));
// TODO: need to serialize container sometimes?
continue;
}
IConstraint constraint = constraints.get(modified);
List<SerializationStrategy> features = trySerializeIndividualFeatures(change, originalEObjectRegion, modified, constraint);
if (features != null) {
strategies.addAll(features);
nextRoots.addAll(change.getChildren());
} else {
strategies.add(new SerializeRecursiveStrategy(originalEObjectRegion, obj, modified));
}
}
rootChanges = collectRootChanges(nextRoots);
}
for (SerializationStrategy strategy : strategies) {
strategy.serialize(result);
}
}
Aggregations