use of org.eclipse.xtext.AbstractElement 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.AbstractElement in project xtext-core by eclipse.
the class FormattingConfigBasedStream method collectLocators.
protected Set<ElementLocator> collectLocators(EObject ele) {
Set<ElementLocator> result = Sets.newHashSet(activeRangeLocators);
Collection<ElementLocator> loc = Sets.newHashSet();
if (ele instanceof AbstractElement)
for (ElementPattern pattern : matcher.matchNext((AbstractElement) ele)) loc.add(pattern.getLocator());
if ((last instanceof AbstractRule && hiddenTokenHelper.isComment((AbstractRule) last)) || (ele instanceof AbstractRule && hiddenTokenHelper.isComment((AbstractRule) ele)))
loc = collectLocatorsForComments(loc, last, ele);
last = ele;
for (ElementLocator locator : loc) if (locator.getType() == LocatorType.RANGE && !activeRangeLocators.add(locator))
activeRangeLocators.remove(locator);
result.addAll(loc);
for (ElementLocator locator : result) {
if (locator instanceof IndentationLocatorStart)
indentationLevel++;
else if (locator instanceof IndentationLocatorEnd)
indentationLevel--;
}
return result;
}
use of org.eclipse.xtext.AbstractElement 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.AbstractElement in project xtext-core by eclipse.
the class GrammarUtilTest method testFindCurrentType_01.
@Test
public void testFindCurrentType_01() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate g \'http://1\'");
_builder.newLine();
_builder.append("Rule:");
_builder.newLine();
_builder.append("\t");
_builder.append("Fragment;");
_builder.newLine();
_builder.append("fragment Fragment*: name=ID;");
_builder.newLine();
String model = _builder.toString();
final XtextResource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
final Grammar grammar = ((Grammar) _get);
final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
final AbstractElement fragmentCall = rule.getAlternatives();
final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
Assert.assertEquals("Rule", currentType.getName());
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class GrammarUtilTest method testFindCurrentType_06.
@Test
public void testFindCurrentType_06() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate g \'http://1\'");
_builder.newLine();
_builder.append("Rule:");
_builder.newLine();
_builder.append("\t");
_builder.append("Fragment;");
_builder.newLine();
_builder.append("fragment Fragment returns Rule:");
_builder.newLine();
_builder.append(" ");
_builder.append("name=ID Fragment?");
_builder.newLine();
_builder.append(";");
_builder.newLine();
String model = _builder.toString();
final XtextResource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
final Grammar grammar = ((Grammar) _get);
final AbstractRule rule = IterableExtensions.<AbstractRule>last(grammar.getRules());
AbstractElement _alternatives = rule.getAlternatives();
final AbstractElement fragmentCall = IterableExtensions.<AbstractElement>last(((Group) _alternatives).getElements());
final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
Assert.assertEquals("Rule", currentType.getName());
}
Aggregations