use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AbstractFollowElementFactory method createFollowElement.
public FollowElement createFollowElement(AbstractElement current, int lookAhead) {
if (logger.isDebugEnabled())
logger.debug("Creating FollowElement for: " + current);
FollowElement result = doCreateElement();
result.setLookAhead(lookAhead);
if (lookAhead != 1) {
int from = parser.input.index();
int to = parser.input.size();
if (parser.marked > 0) {
from = parser.firstMarker;
}
List<LookAheadTerminal> lookAheadTerminals = Lists.newArrayListWithExpectedSize(to - from);
for (int tokenIndex = from; tokenIndex < to; tokenIndex++) {
Token token = parser.input.get(tokenIndex);
if (token != null) {
LookAheadTerminal lookAheadTerminal = doCreateLookAheadTerminal(token);
lookAheadTerminals.add(lookAheadTerminal);
}
}
result.setLookAheadTerminals(lookAheadTerminals);
result.setLookAhead(lookAheadTerminals.size() + 1);
}
result.setGrammarElement(current);
result.setTrace(Lists.newArrayList(Iterators.filter(parser.grammarElements.iterator(), AbstractElement.class)));
result.setLocalTrace(Lists.newArrayList(Iterators.filter(parser.localTrace.iterator(), AbstractElement.class)));
result.setParamStack(Lists.newArrayList(parser.paramStack));
if (current instanceof UnorderedGroup) {
if (parser.indexToHandledElements != null) {
int index = parser.grammarElements.lastIndexOf(current);
List<AbstractElement> alreadyHandled = Lists.newArrayList(Iterators.filter(parser.indexToHandledElements.get(index).iterator(), AbstractElement.class));
result.setHandledUnorderedGroupElements(alreadyHandled);
} else {
result.setHandledUnorderedGroupElements(Collections.<AbstractElement>emptyList());
}
}
if (logger.isDebugEnabled()) {
logger.debug("FollowElement is: " + current);
logger.debug("==================================");
}
return result;
}
use of org.eclipse.xtext.AbstractElement 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;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class IdeContentProposalProvider method _createProposals.
protected void _createProposals(final Assignment assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
final AbstractElement terminal = assignment.getTerminal();
if ((terminal instanceof CrossReference)) {
this.createProposals(terminal, context, acceptor);
} else {
if ((terminal instanceof RuleCall)) {
final AbstractRule rule = ((RuleCall) terminal).getRule();
if (((rule instanceof TerminalRule) && context.getPrefix().isEmpty())) {
String _xifexpression = null;
String _name = rule.getName();
boolean _equals = Objects.equal(_name, "STRING");
if (_equals) {
String _feature = assignment.getFeature();
String _plus = ("\"" + _feature);
_xifexpression = (_plus + "\"");
} else {
_xifexpression = assignment.getFeature();
}
final String proposal = _xifexpression;
final Procedure1<ContentAssistEntry> _function = (ContentAssistEntry it) -> {
String _name_1 = rule.getName();
boolean _equals_1 = Objects.equal(_name_1, "STRING");
if (_equals_1) {
ArrayList<TextRegion> _editPositions = it.getEditPositions();
int _offset = context.getOffset();
int _plus_1 = (_offset + 1);
int _length = proposal.length();
int _minus = (_length - 2);
TextRegion _textRegion = new TextRegion(_plus_1, _minus);
_editPositions.add(_textRegion);
it.setKind(ContentAssistEntry.KIND_TEXT);
} else {
ArrayList<TextRegion> _editPositions_1 = it.getEditPositions();
int _offset_1 = context.getOffset();
int _length_1 = proposal.length();
TextRegion _textRegion_1 = new TextRegion(_offset_1, _length_1);
_editPositions_1.add(_textRegion_1);
it.setKind(ContentAssistEntry.KIND_VALUE);
}
it.setDescription(rule.getName());
};
final ContentAssistEntry entry = this.proposalCreator.createProposal(proposal, context, _function);
acceptor.accept(entry, this.proposalPriorities.getDefaultPriority(entry));
}
}
}
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class BaseContentAssistParser method getEntryGrammarElement.
protected AbstractElement getEntryGrammarElement(ICompositeNode entryPoint) {
EObject grammarElement = entryPoint.getGrammarElement();
if (grammarElement instanceof RuleCall) {
AbstractRule rule = ((RuleCall) grammarElement).getRule();
if (rule instanceof ParserRule) {
if (!GrammarUtil.isMultipleCardinality(rule.getAlternatives())) {
grammarElement = rule.getAlternatives();
}
}
} else if (grammarElement instanceof ParserRule) {
grammarElement = ((ParserRule) grammarElement).getAlternatives();
} else if (grammarElement instanceof CrossReference) {
grammarElement = GrammarUtil.containingAssignment(grammarElement);
}
AbstractElement result = (AbstractElement) grammarElement;
if (result instanceof Action) {
return getEntryGrammarElement((ICompositeNode) entryPoint.getFirstChild());
}
return result;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class CallHierarchyHelper method caseAlternatives.
public Boolean caseAlternatives(List<AbstractElement> elements) {
EObject wasGrammarElement = this.grammarElement;
Set<AbstractRule> visiting = Sets.newHashSet(this.visiting);
boolean foundSomething = false;
for (AbstractElement group : elements) {
this.grammarElement = wasGrammarElement;
this.visiting = Sets.newHashSet(visiting);
if (doSwitch(group))
return true;
if (wasGrammarElement != this.grammarElement) {
foundSomething = true;
}
}
if (foundSomething) {
this.grammarElement = nextGrammarElement;
this.visiting.clear();
this.visited.clear();
}
return Boolean.FALSE;
}
Aggregations