use of org.eclipse.xtext.RuleCall in project xtext-xtend by eclipse.
the class Linker method afterCreateAndSetProxy.
@Override
protected void afterCreateAndSetProxy(EObject obj, INode node, EReference eRef, CrossReference xref, IDiagnosticProducer diagnosticProducer) {
AbstractElement terminal = xref.getTerminal();
if (!(terminal instanceof RuleCall)) {
throw new IllegalArgumentException(String.valueOf(xref));
}
AbstractRule rule = ((RuleCall) terminal).getRule();
try {
String tokenText = NodeModelUtils.getTokenText(node);
valueConverterService.toValue(tokenText, rule.getName(), node);
} catch (ValueConverterException e) {
diagnosticProducer.addDiagnostic(new DiagnosticMessage(e.getMessage(), Severity.ERROR, Diagnostic.SYNTAX_DIAGNOSTIC, Strings.EMPTY_ARRAY));
}
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class EntryPointFinder method shouldUseParent.
protected boolean shouldUseParent(ICompositeNode result, int offset, ILeafNode leaf) {
if (leaf.getTotalEndOffset() == offset) {
return true;
}
if (result.getGrammarElement() instanceof RuleCall) {
RuleCall rc = (RuleCall) result.getGrammarElement();
if (!rc.getArguments().isEmpty()) {
return true;
}
Assignment assignment = GrammarUtil.containingAssignment(rc);
if (assignment != null && (GrammarUtil.isMultipleCardinality(assignment) || (assignment.eContainer() instanceof AbstractElement && GrammarUtil.isMultipleCardinality((AbstractElement) assignment.eContainer())))) {
return true;
}
}
return false;
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class FollowElementComputer method computeFollowElements.
protected void computeFollowElements(FollowElementCalculator calculator, FollowElement element, Multimap<Integer, List<AbstractElement>> visited) {
List<AbstractElement> currentState = Lists.newArrayList(element.getLocalTrace());
if (currentState.isEmpty() || currentState.get(currentState.size() - 1) != element.getGrammarElement()) {
currentState.add(element.getGrammarElement());
}
if (!visited.put(element.getLookAhead(), currentState))
return;
if (element.getLookAhead() <= 1) {
List<Integer> paramStack = element.getParamStack();
int paramIndex = computeParamStackOffset(currentState, paramStack);
for (AbstractElement abstractElement : currentState) {
paramIndex = setParamConfigAndUpdateOffset(calculator, paramStack, paramIndex, abstractElement);
Assignment ass = EcoreUtil2.getContainerOfType(abstractElement, Assignment.class);
if (ass != null)
calculator.doSwitch(ass);
else {
if (abstractElement instanceof UnorderedGroup && abstractElement == element.getGrammarElement()) {
calculator.doSwitch((UnorderedGroup) abstractElement, element.getHandledUnorderedGroupElements());
} else {
calculator.doSwitch(abstractElement);
if (GrammarUtil.isOptionalCardinality(abstractElement)) {
EObject container = abstractElement.eContainer();
if (container instanceof Group) {
Group group = (Group) container;
int idx = group.getElements().indexOf(abstractElement);
if (idx == group.getElements().size() - 1) {
if (!currentState.contains(group) && GrammarUtil.isMultipleCardinality(group)) {
calculator.doSwitch(group);
}
} else if (idx < group.getElements().size() - 1 && "?".equals(abstractElement.getCardinality())) {
// loops are fine
AbstractElement nextElement = group.getElements().get(idx + 1);
if (!currentState.contains(nextElement)) {
calculator.doSwitch(nextElement);
}
}
}
} else if (isAlternativeWithEmptyPath(abstractElement)) {
EObject container = abstractElement.eContainer();
if (container instanceof Group) {
Group group = (Group) container;
int idx = group.getElements().indexOf(abstractElement);
if (!currentState.contains(group) && idx != group.getElements().size() - 1) {
AbstractElement next = group.getElements().get(idx + 1);
if (!currentState.contains(next)) {
calculator.doSwitch(next);
}
}
}
}
}
}
}
// we need a synthetic rule call
if (element.getTrace().equals(element.getLocalTrace())) {
ParserRule parserRule = GrammarUtil.containingParserRule(element.getGrammarElement());
if (parserRule != null) {
RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
ruleCall.setRule(parserRule);
calculator.doSwitch(ruleCall);
}
}
return;
}
Collection<FollowElement> followElements = parser.getFollowElements(element);
for (FollowElement newElement : followElements) {
if (newElement.getLookAhead() != element.getLookAhead() || newElement.getGrammarElement() != element.getGrammarElement()) {
if (newElement.getLookAhead() == element.getLookAhead()) {
int originalTraceSize = element.getLocalTrace().size();
List<AbstractElement> newTrace = newElement.getLocalTrace();
if (newTrace.size() > originalTraceSize) {
if (Collections.indexOfSubList(element.getLocalTrace(), newTrace.subList(originalTraceSize, newTrace.size())) != -1) {
continue;
}
}
}
computeFollowElements(calculator, newElement, visited);
}
}
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class PartialSerializer method updateSingleValue.
protected SerializationStrategy updateSingleValue(EObject object, EStructuralFeature feature, IAstRegion region) {
Preconditions.checkArgument(!feature.isMany());
Object value = object.eGet(feature);
EObject grammarElement = region.getGrammarElement();
if (feature instanceof EAttribute) {
if (grammarElement instanceof RuleCall) {
RuleCall rc = (RuleCall) grammarElement;
String newValue = valueSerializer.serializeAssignedValue(object, rc, value, null, errorAcceptor);
if (newValue != null) {
return new ReplaceRegionStrategy((ISemanticRegion) region, newValue);
}
}
return null;
} else if (feature instanceof EReference) {
if (((EReference) feature).isContainment()) {
IEObjectRegion reg = (IEObjectRegion) region;
EObject newEObject = (EObject) object.eGet(feature);
ISerializationContext newContext = getSerializationContext(newEObject);
ISerializationContext oldContext = getSerializationContext(reg);
if (!oldContext.equals(newContext)) {
return null;
}
return new SerializeRecursiveStrategy(reg, newEObject, newContext);
} else {
CrossReference cr = GrammarUtil.containingCrossReference(grammarElement);
if (cr != null) {
EObject target = (EObject) value;
String newValue = crossRefSerializer.serializeCrossRef(object, cr, target, null, errorAcceptor);
if (newValue != null) {
return new ReplaceRegionStrategy((ISemanticRegion) region, newValue);
}
}
}
return null;
}
return null;
}
use of org.eclipse.xtext.RuleCall 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));
}
}
}
}
Aggregations