use of org.eclipse.xtext.CompoundElement in project xtext-core by eclipse.
the class GrammarElementTitleSwitch method addQualified.
protected String addQualified(String result, AbstractElement ele) {
if (!showQualified && !showRule)
return result;
AbstractRule rule = GrammarUtil.containingRule(ele);
if (rule == null)
return "<AbstractElement not contained in AbstractRule!>:" + result;
if (!showQualified)
return result + ":" + rule.getName();
GrammarElementTitleSwitch others = copy();
others.showQualified = false;
others.showRule = false;
List<AbstractElement> elementsWithSameName = Lists.newArrayList();
for (AbstractElement candidate : EcoreUtil2.getAllContentsOfType(rule, ele.getClass())) if (candidate == ele || result.equals(others.doSwitch(candidate)))
elementsWithSameName.add(candidate);
if (elementsWithSameName.size() < 2) {
if (showRule)
return rule.getName() + ":" + result;
return result;
}
Map<CompoundElement, Node> nodes = Maps.newHashMap();
for (AbstractElement collision : elementsWithSameName) {
EObject current = EcoreUtil2.getContainerOfType(collision, CompoundElement.class);
Node node = new Node(null, collision == ele ? result : "");
while (current instanceof CompoundElement) {
CompoundElement container = (CompoundElement) current;
Node cntNode = nodes.get(container);
if (cntNode == null)
nodes.put(container, cntNode = new Node(container, null));
if (!cntNode.children.contains(node))
cntNode.children.add(node);
node = cntNode;
current = current.eContainer();
}
}
if (showRule)
return rule.getName() + ":" + nodes.get(rule.getAlternatives());
return nodes.get(rule.getAlternatives()).toString();
}
use of org.eclipse.xtext.CompoundElement in project xtext-core by eclipse.
the class CardinalityAwareSyntacticSequencer method emit_ParenthesizedElement_LeftParenthesisKeyword_0_a.
@Override
protected void emit_ParenthesizedElement_LeftParenthesisKeyword_0_a(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
if (semanticObject instanceof CompoundElement) {
CompoundElement ele = (CompoundElement) semanticObject;
if (!Strings.isNullOrEmpty(ele.getCardinality()) && ele.getElements().size() > 1) {
Keyword kw = grammarAccess.getParenthesizedElementAccess().getLeftParenthesisKeyword_0();
acceptUnassignedKeyword(kw, kw.getValue(), nodes == null || nodes.isEmpty() ? null : (ILeafNode) nodes.get(0));
}
}
super.emit_ParenthesizedCondition_LeftParenthesisKeyword_0_a(semanticObject, transition, nodes);
}
use of org.eclipse.xtext.CompoundElement in project xtext-core by eclipse.
the class XtextValidationTest method testDuplicateFeatures_02.
@Test
public void testDuplicateFeatures_02() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "A : (b+=B)*;\n" + "B : C | D;\n" + "C : 'c' name=ID ('e' e+=E)+;\n" + "E : name=ID;\n" + "F : C | E;\n" + "D : 'd' name=ID 'ref' ref=[F];";
Grammar grammar = (Grammar) getModel(grammarAsText);
AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
messageAcceptor.expectedContext(grammar.getRules().get(1).getType(), grammar.getRules().get(2).getType(), grammar.getRules().get(4).getType(), ((CompoundElement) grammar.getRules().get(2).getAlternatives()).getElements().get(1), grammar.getRules().get(3).getAlternatives(), ((CompoundElement) grammar.getRules().get(5).getAlternatives()).getElements().get(1));
validator.setMessageAcceptor(messageAcceptor);
validator.checkGeneratedPackage((GeneratedMetamodel) metamodelDeclaration, Diagnostician.INSTANCE, Collections.EMPTY_MAP);
messageAcceptor.validate();
}
use of org.eclipse.xtext.CompoundElement in project xtext-core by eclipse.
the class XtextValidationTest method testNameClash_02.
@Test
public void testNameClash_02() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Class returns Class: {Class_} name=ID;\n";
Grammar grammar = (Grammar) getModel(grammarAsText);
AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
CompoundElement element = (CompoundElement) grammar.getRules().get(0).getAlternatives();
messageAcceptor.expectedContext(grammar.getRules().get(0).getType(), ((Action) element.getElements().get(0)).getType());
validator.setMessageAcceptor(messageAcceptor);
validator.checkGeneratedPackage((GeneratedMetamodel) metamodelDeclaration, Diagnostician.INSTANCE, Collections.EMPTY_MAP);
messageAcceptor.validate();
}
use of org.eclipse.xtext.CompoundElement in project xtext-core by eclipse.
the class XtextValidationTest method testPredicatedUnorderedGroup_01.
@Test
public void testPredicatedUnorderedGroup_01() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: =>(name=ID & value=STRING);\n";
Grammar grammar = (Grammar) getModel(grammarAsText);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
messageAcceptor.expectedContext(grammar.getRules().get(0).getAlternatives(), ((CompoundElement) grammar.getRules().get(0).getAlternatives()).getElements().get(0));
PredicateUsesUnorderedGroupInspector inspector = new PredicateUsesUnorderedGroupInspector(messageAcceptor);
inspector.inspect(grammar);
messageAcceptor.validate();
}
Aggregations