use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class GrammarUtilTest method testFindCurrentType_03.
@Test
public void testFindCurrentType_03() 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 SecondFragment;");
_builder.newLine();
_builder.append("fragment SecondFragment: {SubRule.named=current} value=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("SubRule", currentType.getName());
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class GrammarAccessExtensions method gaTypeAccessor.
/**
* Returns the invocation of an element or rule accessor, including the .getType() call.
* Example1: getFooRule().getType()
* Example2: getBarRule().getFooAction().getType()
*/
public String gaTypeAccessor(final TypeRef ele) {
String _switchResult = null;
EObject _eContainer = ele.eContainer();
final EObject cnt = _eContainer;
boolean _matched = false;
if (cnt instanceof AbstractElement) {
_matched = true;
String _gaRuleElementAccessor = this.gaRuleElementAccessor(((AbstractElement) cnt));
_switchResult = (_gaRuleElementAccessor + ".getType()");
}
if (!_matched) {
if (cnt instanceof AbstractRule) {
_matched = true;
String _gaRuleAccessor = this.gaRuleAccessor(((AbstractRule) cnt));
_switchResult = (_gaRuleAccessor + ".getType()");
}
}
if (!_matched) {
String _name = ele.eContainer().eClass().getName();
String _plus = ("<error: unknown type " + _name);
_switchResult = (_plus + ">");
}
return _switchResult;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AntlrGrammarGenUtil method doGetPredicatedElement.
private static AbstractElement doGetPredicatedElement(final AbstractElement element) {
if (element instanceof Alternatives || element instanceof Group) {
EcoreUtil.Copier copier = new EcoreUtil.Copier(true, true) {
private static final long serialVersionUID = 1L;
@Override
public EObject copy(EObject eObject) {
if (eObject instanceof AbstractElement) {
if (((AbstractElement) eObject).isFirstSetPredicated() && isLastInGroup(eObject)) {
Collection<AbstractElement> firstSet = EcoreUtil.copyAll(getFirstSet((AbstractElement) eObject));
if (firstSet.size() == 1) {
AbstractElement result = firstSet.iterator().next();
result.setCardinality(((AbstractElement) eObject).getCardinality());
return result;
}
Alternatives result = XtextFactory.eINSTANCE.createAlternatives();
for (AbstractElement firstElement : firstSet) {
firstElement.setCardinality(null);
}
result.getElements().addAll(firstSet);
result.setCardinality(((AbstractElement) eObject).getCardinality());
return result;
}
}
return super.copy(eObject);
}
private boolean isLastInGroup(EObject eObject) {
if (eObject == element) {
return true;
}
EObject container = eObject.eContainer();
if (container instanceof Group) {
List<AbstractElement> siblings = ((Group) container).getElements();
if (siblings.get(siblings.size() - 1) == eObject) {
return isLastInGroup(container);
}
}
if (container instanceof Alternatives) {
return isLastInGroup(container);
}
return false;
}
};
AbstractElement clone = (AbstractElement) copier.copy(element);
copier.copyReferences();
return clone;
}
return element;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AbstractNegatedTokenImpl method basicSetTerminal.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetTerminal(AbstractElement newTerminal, NotificationChain msgs) {
AbstractElement oldTerminal = terminal;
terminal = newTerminal;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtextPackage.ABSTRACT_NEGATED_TOKEN__TERMINAL, oldTerminal, newTerminal);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AbstractRuleImpl method basicSetAlternatives.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetAlternatives(AbstractElement newAlternatives, NotificationChain msgs) {
AbstractElement oldAlternatives = alternatives;
alternatives = newAlternatives;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtextPackage.ABSTRACT_RULE__ALTERNATIVES, oldAlternatives, newAlternatives);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
Aggregations