use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class SyntacticSequencerTest method getNodeSequence.
@SuppressWarnings("deprecation")
private List<String> getNodeSequence(EObject model) {
List<String> result = Lists.newArrayList();
GrammarElementTitleSwitch titleSwitch = new GrammarElementTitleSwitch().showAssignments();
org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator ni = new org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator(NodeModelUtils.findActualNodeFor(model));
while (ni.hasNext()) {
INode next = ni.next();
EObject ele = next.getGrammarElement() instanceof CrossReference ? ((CrossReference) next.getGrammarElement()).getTerminal() : next.getGrammarElement();
if (next instanceof ILeafNode || GrammarUtil.isDatatypeRuleCall(ele))
result.add(titleSwitch.doSwitch(ele) + " -> " + next.getText().trim());
else if (next instanceof ICompositeNode)
result.add(titleSwitch.doSwitch(ele));
}
return result;
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class XtextTransientValueService method isTransient.
@Override
public boolean isTransient(EObject owner, EStructuralFeature feature, int index) {
if (feature == XtextPackage.eINSTANCE.getTypeRef_Metamodel()) {
final TypeRef typeRef = (TypeRef) owner;
final AbstractMetamodelDeclaration m = typeRef.getMetamodel();
if (m == null || Strings.isEmpty(m.getAlias()))
return true;
} else if (feature == XtextPackage.eINSTANCE.getAbstractRule_Type()) {
final AbstractRule rule = (AbstractRule) owner;
if (rule instanceof ParserRule || rule instanceof EnumRule) {
final TypeRef returnType = rule.getType();
if (returnType == null || returnType.getClassifier() == null)
return true;
else if (rule.getName().equals(returnType.getClassifier().getName())) {
return isTransient(returnType, XtextPackage.eINSTANCE.getTypeRef_Metamodel(), -1);
} else if (GrammarUtil.isDatatypeRule(rule)) {
return NodeModelUtils.getNode(returnType) == null;
}
} else if (rule instanceof TerminalRule) {
final TypeRef returnType = rule.getType();
return ((TerminalRule) rule).isFragment() || returnType == null || GrammarUtil.findEString(GrammarUtil.getGrammar(owner)).equals(rule.getType().getClassifier());
}
} else if (feature == XtextPackage.eINSTANCE.getCrossReference_Terminal()) {
final CrossReference ref = (CrossReference) owner;
if (ref.getTerminal() instanceof RuleCall && ((RuleCall) ref.getTerminal()).getRule() != null && "ID".equals(((RuleCall) ref.getTerminal()).getRule().getName()))
return true;
} else if (feature == XtextPackage.eINSTANCE.getEnumLiteralDeclaration_Literal()) {
final EnumLiteralDeclaration decl = (EnumLiteralDeclaration) owner;
return decl.getEnumLiteral() != null && decl.getLiteral() != null && Strings.equal(decl.getLiteral().getValue(), decl.getEnumLiteral().getName());
} else if (feature == XtextPackage.eINSTANCE.getRuleCall_ExplicitlyCalled()) {
return true;
} else if (feature == XtextPackage.eINSTANCE.getNamedArgument_Parameter()) {
return !((NamedArgument) owner).isCalledByName();
}
return super.isTransient(owner, feature, index);
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class XtextValidationTest method testCheckCrossReferenceTerminal_01.
@Test
public void testCheckCrossReferenceTerminal_01() throws Exception {
XtextValidator validator = get(XtextValidator.class);
CrossReference reference = XtextFactory.eINSTANCE.createCrossReference();
RuleCall call = XtextFactory.eINSTANCE.createRuleCall();
reference.setTerminal(call);
ParserRule rule = XtextFactory.eINSTANCE.createParserRule();
call.setRule(rule);
TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
rule.setType(typeRef);
typeRef.setClassifier(EcorePackage.Literals.ESTRING);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkCrossReferenceTerminal(reference);
messageAcceptor.validate();
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class XtextParserTest method testParseCrossRef.
@Test
public void testParseCrossRef() throws Exception {
Grammar model = (Grammar) getModel("grammar foo with org.eclipse.xtext.common.Terminals " + "generate foo 'bar' as boo " + "Model returns boo::Model : 'a' stuff+=Stuff*; " + "Stuff returns boo::Stuff : 'stuff' name=ID refersTo=[boo::Stuff];");
AbstractRule rule = model.getRules().get(1);
Group group = (Group) rule.getAlternatives();
Assignment assignment = (Assignment) group.getElements().get(2);
CrossReference reference = (CrossReference) assignment.getTerminal();
assertEquals("boo", reference.getType().getMetamodel().getAlias());
// assertWithXtend("'boo'", "eAllContents.typeSelect(xtext::CrossReference).first().type.metamodel.alias", model);
assertEquals("Stuff", reference.getType().getClassifier().getName());
// assertWithXtend("'Stuff'", "eAllContents.typeSelect(xtext::CrossReference).first().type.classifier.name", model);
}
Aggregations