use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class TreeConstructionReportImpl method getDiagnosticMessage.
protected String getDiagnosticMessage(AssignmentToken token) {
Assignment ass = (Assignment) token.getGrammarElement();
Object value = token.getEObjectConsumer().getConsumable(ass.getFeature(), false);
if (value == null) {
EStructuralFeature f = token.getEObjectConsumer().getEObject().eClass().getEStructuralFeature(ass.getFeature());
if (f == null)
return "The current object of type '" + token.getEObjectConsumer().getEObject().eClass().getName() + "' does not have a feature named '" + ass.getFeature() + "'";
String cls = f.getEContainingClass() == token.getEObjectConsumer().getEObject().eClass() ? f.getEContainingClass().getName() : f.getEContainingClass().getName() + "(" + token.getEObjectConsumer().getEObject().eClass().getName() + ")";
String feat = cls + "." + f.getName();
if (f.isMany()) {
int size = ((List<?>) token.getEObjectConsumer().getEObject().eGet(f)).size();
return "All " + size + " values of " + feat + " have been consumed. " + "More are needed to continue here.";
} else
return feat + " is not set.";
} else {
ErrorAcceptor err = new ErrorAcceptor();
for (RuleCall ruleCall : GrammarUtil.containedRuleCalls(token.getGrammarElement())) {
if (ruleCall.getRule() instanceof EnumRule) {
if (enumSerializer.isValid(token.getEObject(), ruleCall, value, err))
return null;
} else if (ruleCall.getRule().getType().getClassifier() instanceof EDataType) {
if (valueSerializer.isValid(token.getEObject(), ruleCall, value, err))
return null;
}
}
return err.getMessage();
}
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class DefaultLocationInFileProvider method getLocationNodes.
protected List<INode> getLocationNodes(EObject obj) {
final EStructuralFeature nameFeature = getIdentifierFeature(obj);
if (nameFeature != null) {
List<INode> result = NodeModelUtils.findNodesForFeature(obj, nameFeature);
if (!result.isEmpty())
return result;
}
List<INode> resultNodes = Lists.newArrayList();
final ICompositeNode startNode = findNodeFor(obj);
INode keywordNode = null;
// use LeafNodes instead of children?
for (INode child : startNode.getChildren()) {
EObject grammarElement = child.getGrammarElement();
if (grammarElement instanceof RuleCall) {
RuleCall ruleCall = (RuleCall) grammarElement;
String ruleName = ruleCall.getRule().getName();
if (ruleName.equals("ID")) {
resultNodes.add(child);
}
} else if (grammarElement instanceof Keyword) {
// TODO use only keywords, that aren't symbols like '=' ?
if (keywordNode == null && useKeyword((Keyword) grammarElement, obj)) {
keywordNode = child;
}
}
}
if (resultNodes.isEmpty() && keywordNode != null)
resultNodes.add(keywordNode);
return resultNodes;
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class Linker method ensureLinked.
private void ensureLinked(EObject obj, IDiagnosticProducer producer, ICompositeNode node, Set<EReference> handledReferences, boolean dontCheckParent) {
for (INode abstractNode = node.getFirstChild(); abstractNode != null; abstractNode = abstractNode.getNextSibling()) {
EObject grammarElement = abstractNode.getGrammarElement();
if (grammarElement instanceof CrossReference) {
CrossReference ref = (CrossReference) grammarElement;
producer.setNode(abstractNode);
ensureIsLinked(obj, abstractNode, ref, handledReferences, producer);
} else if (grammarElement instanceof RuleCall && abstractNode instanceof ICompositeNode) {
RuleCall ruleCall = (RuleCall) grammarElement;
AbstractRule calledRule = ruleCall.getRule();
if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
ensureLinked(obj, producer, (ICompositeNode) abstractNode, handledReferences, true);
}
}
}
if (!dontCheckParent && shouldCheckParentNode(node)) {
ensureLinked(obj, producer, node.getParent(), handledReferences, false);
}
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class KeywordAlternativeConverter method setRule.
/**
* @throws IllegalArgumentException if the rule is not a datatype rule or does not match
* the pattern <pre>RuleName: 'keyword' | 'other';</pre>
*/
@Override
public void setRule(AbstractRule rule) {
if (!GrammarUtil.isDatatypeRule(rule))
throw new IllegalArgumentException(rule.getName() + " is not a data type rule");
if (!(rule.getAlternatives() instanceof Alternatives)) {
if (rule.getAlternatives() instanceof RuleCall) {
delegateRule = ((RuleCall) rule.getAlternatives()).getRule();
keywords = Collections.emptySet();
return;
}
throw mismatchedRuleBody(rule);
}
Alternatives alternatives = (Alternatives) rule.getAlternatives();
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (AbstractElement element : alternatives.getElements()) {
processElement(element, rule, builder);
}
keywords = builder.build();
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class AbstractFormattingConfig method getAbstractElements.
protected List<AbstractElement> getAbstractElements(EObject obj) {
if (obj instanceof AbstractElement)
return Collections.singletonList((AbstractElement) obj);
if (obj instanceof AbstractRule) {
AbstractRule rule = (AbstractRule) obj;
if (rule.getType().getClassifier() instanceof EClass)
return Collections.singletonList(rule.getAlternatives());
List<AbstractElement> result = Lists.newArrayList();
for (RuleCall rc : grammarAccess.findRuleCalls(rule)) {
CrossReference cr = GrammarUtil.containingCrossReference(rc);
result.add(cr == null ? rc : cr);
}
return result;
}
return null;
}
Aggregations