use of org.eclipse.xtext.CrossReference 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.CrossReference 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;
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class XtextValidationTest method testBug318424_01.
@Test
public void testBug318424_01() throws Exception {
XtextValidator validator = get(XtextValidator.class);
CrossReference reference = XtextFactory.eINSTANCE.createCrossReference();
TypeRef typeRef = XtextFactory.eINSTANCE.createTypeRef();
reference.setType(typeRef);
typeRef.setClassifier(EcorePackage.Literals.EBOOLEAN);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(typeRef, true, false);
validator.setMessageAcceptor(messageAcceptor);
validator.checkCrossReferenceType(reference);
messageAcceptor.validate();
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class GrammarUtilTest method testGetReference.
@Test
public void testGetReference() throws Exception {
this.with(LangATestLanguageStandaloneSetup.class);
XtextResource resource = this.getResourceFromStringAndExpect("type A extends B", 1);
Assignment asExtends = this.<LangATestLanguageGrammarAccess>get(LangATestLanguageGrammarAccess.class).getTypeAccess().getExtendsAssignment_2_1();
AbstractElement _terminal = asExtends.getTerminal();
CrossReference xref = ((CrossReference) _terminal);
EObject _model = this.getModel(resource);
Main model = ((Main) _model);
EObject typeA = model.getTypes().get(0);
EReference ref = GrammarUtil.getReference(xref, typeA.eClass());
Assert.assertNotNull(ref);
Assert.assertEquals("extends", ref.getName());
Assert.assertFalse(ref.isMany());
Assert.assertEquals(typeA.eClass(), ref.getEReferenceType());
}
use of org.eclipse.xtext.CrossReference in project xtext-core by eclipse.
the class GrammarAccessExtensions method getSingleElementDescription.
private List<String> getSingleElementDescription(final AbstractElement ele) {
final ArrayList<String> r = new ArrayList<String>(2);
boolean _matched = false;
if (ele instanceof Keyword) {
_matched = true;
String _value = ((Keyword) ele).getValue();
r.add(_value);
}
if (!_matched) {
if (ele instanceof Assignment) {
_matched = true;
String _feature = ((Assignment) ele).getFeature();
r.add(_feature);
}
}
if (!_matched) {
if (ele instanceof RuleCall) {
_matched = true;
String _name = ((RuleCall) ele).getRule().getName();
r.add(_name);
}
}
if (!_matched) {
if (ele instanceof Action) {
_matched = true;
TypeRef _type = ((Action) ele).getType();
EClassifier _classifier = null;
if (_type != null) {
_classifier = _type.getClassifier();
}
boolean _tripleNotEquals = (_classifier != null);
if (_tripleNotEquals) {
String _name = ((Action) ele).getType().getClassifier().getName();
r.add(_name);
}
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(((Action) ele).getFeature());
boolean _not = (!_isNullOrEmpty);
if (_not) {
String _feature = ((Action) ele).getFeature();
r.add(_feature);
}
}
}
if (!_matched) {
if (ele instanceof CrossReference) {
_matched = true;
TypeRef _type = ((CrossReference) ele).getType();
EClassifier _classifier = null;
if (_type != null) {
_classifier = _type.getClassifier();
}
boolean _tripleNotEquals = (_classifier != null);
if (_tripleNotEquals) {
String _name = ((CrossReference) ele).getType().getClassifier().getName();
r.add(_name);
}
}
}
if (!_matched) {
if (ele instanceof EnumLiteralDeclaration) {
_matched = true;
String _name = ((EnumLiteralDeclaration) ele).getEnumLiteral().getName();
r.add(_name);
}
}
return r;
}
Aggregations