use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AssignmentImpl 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.ASSIGNMENT__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 KeywordBasedValueConverter method setRule.
/**
* @throws IllegalArgumentException if the rule is not a datatype rule or does not fulfill
* the pattern <pre>RuleName: 'keyword' | 'other';</pre>
*/
@Override
public void setRule(AbstractRule rule) {
this.rule = rule;
if (!GrammarUtil.isDatatypeRule(rule))
throw new IllegalArgumentException(rule.getName() + " is not a data type rule");
if (!(rule.getAlternatives() instanceof Alternatives) && !(rule.getAlternatives() instanceof Keyword)) {
throw new IllegalArgumentException(rule.getName() + " is not a simple keyword nor an alternative");
}
if (rule.getAlternatives() instanceof Keyword) {
keywords = ImmutableSet.of(keywordToString((Keyword) rule.getAlternatives()));
} else {
Alternatives alternatives = (Alternatives) rule.getAlternatives();
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (AbstractElement element : alternatives.getElements()) {
if (!(element instanceof Keyword)) {
throw new IllegalArgumentException(rule.getName() + "'s body does not contain an alternative of keywords");
}
builder.add(keywordToString((Keyword) element));
}
keywords = builder.build();
}
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class TextRegionAccessToString method toString.
protected String toString(IEObjectRegion region) {
EObject obj = region.getSemanticElement();
StringBuilder builder = new StringBuilder(Strings.padEnd(toClassWithName(obj), textWidth, ' ') + " ");
EObject element = region.getGrammarElement();
if (element instanceof AbstractElement)
builder.append(grammarToString.apply((AbstractElement) element));
else if (element instanceof AbstractRule)
builder.append(((AbstractRule) element).getName());
else
builder.append(": ERROR: No grammar element.");
List<String> segments = Lists.newArrayList();
EObject current = obj;
while (current.eContainer() != null) {
EObject container = current.eContainer();
EStructuralFeature containingFeature = current.eContainingFeature();
StringBuilder segment = new StringBuilder();
segment.append(toClassWithName(container));
segment.append("/");
segment.append(containingFeature.getName());
if (containingFeature.isMany()) {
int index = ((List<?>) container.eGet(containingFeature)).indexOf(current);
segment.append("[" + index + "]");
}
current = container;
segments.add(segment.toString());
}
if (!segments.isEmpty()) {
builder.append(" path:");
builder.append(Joiner.on("=").join(segments));
}
return builder.toString();
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class GrammarAccessExtensions method getElementDescription.
private List<String> getElementDescription(final AbstractElement element) {
final ArrayList<String> result = new ArrayList<String>();
AbstractElement container = element;
while ((container != null)) {
{
result.addAll(0, this.getSingleElementDescription(container));
final EObject eContainer = container.eContainer();
AbstractElement _xifexpression = null;
if ((eContainer instanceof AbstractElement)) {
_xifexpression = ((AbstractElement) eContainer);
} else {
_xifexpression = null;
}
container = _xifexpression;
}
}
return result;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class GrammarAccessFragment2 method parserRuleClasses.
protected StringConcatenationClient parserRuleClasses(final ParserRule it) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it);
_builder.append(_gaRuleAccessorClassName);
_builder.append(" extends AbstractParserRuleElementFinder {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("private final ");
_builder.append(ParserRule.class, "\t");
_builder.append(" rule = (");
_builder.append(ParserRule.class, "\t");
_builder.append(") ");
_builder.append(GrammarUtil.class, "\t");
_builder.append(".findRuleForName(getGrammar(), \"");
String _qualifiedName = GrammarAccessFragment2.this.getQualifiedName(it);
_builder.append(_qualifiedName, "\t");
_builder.append("\");");
_builder.newLineIfNotEmpty();
{
List<AbstractElement> _containedAbstractElements = GrammarUtil.containedAbstractElements(it);
for (final AbstractElement e : _containedAbstractElements) {
_builder.append("\t");
_builder.append("private final ");
TypeReference _typeRef = TypeReference.typeRef(e.eClass(), GrammarAccessFragment2.this.getLanguage());
_builder.append(_typeRef, "\t");
_builder.append(" ");
String _gaElementAccessorLocalVarName = GrammarAccessFragment2.this.gaElementAccessorLocalVarName(e);
_builder.append(_gaElementAccessorLocalVarName, "\t");
_builder.append(" = ");
StringConcatenationClient _loadElementStatement = GrammarAccessFragment2.this.loadElementStatement(e);
_builder.append(_loadElementStatement, "\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
String _grammarFragmentToString = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(it, "//");
_builder.append(_grammarFragmentToString, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("@Override public ");
_builder.append(ParserRule.class, "\t");
_builder.append(" getRule() { return rule; }");
_builder.newLineIfNotEmpty();
{
List<AbstractElement> _containedAbstractElements_1 = GrammarUtil.containedAbstractElements(it);
for (final AbstractElement e_1 : _containedAbstractElements_1) {
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
String _grammarFragmentToString_1 = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(e_1, "//");
_builder.append(_grammarFragmentToString_1, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public ");
TypeReference _typeRef_1 = TypeReference.typeRef(e_1.eClass(), GrammarAccessFragment2.this.getLanguage());
_builder.append(_typeRef_1, "\t");
_builder.append(" ");
String _gaElementAccessMethodName = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementAccessMethodName(e_1);
_builder.append(_gaElementAccessMethodName, "\t");
_builder.append("() { return ");
String _gaElementAccessorLocalVarName_1 = GrammarAccessFragment2.this.gaElementAccessorLocalVarName(e_1);
_builder.append(_gaElementAccessorLocalVarName_1, "\t");
_builder.append("; }");
_builder.newLineIfNotEmpty();
}
}
_builder.append("}");
_builder.newLine();
}
};
return _client;
}
Aggregations