use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class CrossReferenceImpl 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.CROSS_REFERENCE__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 Xtext2EcoreTransformer method deriveFeatures.
private Xtext2EcoreInterpretationContext deriveFeatures(final Xtext2EcoreInterpretationContext context, AbstractElement element) {
XtextSwitch<Xtext2EcoreInterpretationContext> visitor = new XtextSwitch<Xtext2EcoreInterpretationContext>() {
/*
* Used for Alternatives and UnorderedGroups
*/
@Override
public Xtext2EcoreInterpretationContext caseCompoundElement(CompoundElement object) {
List<Xtext2EcoreInterpretationContext> contexts = new ArrayList<Xtext2EcoreInterpretationContext>();
for (AbstractElement group : object.getElements()) {
contexts.add(deriveFeatures(context, group));
}
Xtext2EcoreInterpretationContext result = context;
if (!contexts.isEmpty()) {
if (GrammarUtil.isOptionalCardinality(object)) {
contexts.add(0, result);
} else {
result = contexts.get(0);
}
result = result.mergeSpawnedContexts(contexts);
}
return result;
}
@Override
public Xtext2EcoreInterpretationContext caseAssignment(Assignment object) {
try {
context.addFeature(object);
} catch (TransformationException ex) {
reportError(ex);
}
return context;
}
@Override
public Xtext2EcoreInterpretationContext caseGroup(Group object) {
return visitElements(object, object.getElements());
}
private Xtext2EcoreInterpretationContext visitElements(AbstractElement caller, List<AbstractElement> elementsToProcess) {
Xtext2EcoreInterpretationContext result = deriveFeatures(context.spawnContextForGroup(), elementsToProcess);
if (GrammarUtil.isMultipleCardinality(caller)) {
result = deriveFeatures(result.spawnContextForGroup(), elementsToProcess);
}
if (GrammarUtil.isOptionalCardinality(caller)) {
result = result.mergeSpawnedContexts(Arrays.asList(context, result));
}
return result;
}
@Override
public Xtext2EcoreInterpretationContext caseAlternatives(Alternatives object) {
List<Xtext2EcoreInterpretationContext> contexts = newArrayList();
if (GrammarUtil.isOptionalCardinality(object)) {
contexts.add(context);
}
for (AbstractElement alternative : object.getElements()) {
contexts.add(deriveFeatures(context.spawnContextForGroup(), alternative));
}
Xtext2EcoreInterpretationContext result = context.mergeSpawnedContexts(contexts);
if (GrammarUtil.isMultipleCardinality(object)) {
for (AbstractElement alternative : object.getElements()) {
deriveFeatures(result.spawnContextForGroup(), alternative);
}
}
return result;
}
@Override
public Xtext2EcoreInterpretationContext caseRuleCall(RuleCall object) {
AbstractRule calledRule = object.getRule();
if (isWildcardFragment(calledRule)) {
AbstractElement ruleBody = calledRule.getAlternatives();
if (ruleBody != null) {
return visitElements(object, Collections.singletonList(ruleBody));
}
return context;
}
if (isParserRuleFragment(calledRule)) {
return context;
}
if (!GrammarUtil.isOptionalCardinality(object)) {
// announced during the first iteration
if (calledRule != null && calledRule instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) calledRule)) {
try {
EClassifierInfo eClassifierInfo = findOrCreateEClassifierInfo(calledRule);
return context.spawnContextWithCalledRule(eClassifierInfo, object);
} catch (TransformationException e) {
reportError(e);
}
}
}
return context;
}
@Override
public Xtext2EcoreInterpretationContext caseAction(Action object) {
try {
TypeRef actionTypeRef = object.getType();
EClassifierInfo actionType = findOrCreateEClassifierInfo(actionTypeRef, null, true);
EClassifierInfo currentCompatibleType = context.getCurrentCompatibleType();
Xtext2EcoreInterpretationContext ctx = context.spawnContextWithReferencedType(actionType, object);
if (object.getFeature() != null) {
ctx.addFeature(object.getFeature(), currentCompatibleType, GrammarUtil.isMultipleAssignment(object), true, object);
}
return ctx;
} catch (TransformationException e) {
reportError(e);
}
return context;
}
@Override
public Xtext2EcoreInterpretationContext defaultCase(EObject object) {
return context;
}
};
return visitor.doSwitch(element);
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class CardinalityAwareEcoreFactory method set.
@Override
public void set(EObject object, String feature, Object value, String ruleName, INode node) throws ValueConverterException {
if (object instanceof AbstractElement && XtextPackage.Literals.ABSTRACT_ELEMENT__CARDINALITY.getName().equals(feature)) {
AbstractElement casted = (AbstractElement) object;
String knownCardinality = casted.getCardinality();
if (knownCardinality != null) {
String newCardinality = String.valueOf(getTokenAsStringIfPossible(value));
if ("*".equals(newCardinality)) {
casted.setCardinality("*");
} else if ("*".equals(knownCardinality)) {
// nothing to do
} else if ("+".equals(knownCardinality)) {
if ("?".equals(newCardinality)) {
casted.setCardinality("*");
}
} else if ("?".equals(knownCardinality)) {
if ("+".equals(newCardinality)) {
casted.setCardinality("*");
}
}
throw new MoreThanOneCardinalityException(newCardinality, casted.getCardinality(), node);
}
}
super.set(object, feature, value, ruleName, node);
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class Context2NameFunction method getUniqueActionName.
public String getUniqueActionName(Action action) {
List<Integer> indices = Lists.newArrayList();
EObject current = action;
while (current.eContainer() instanceof AbstractElement) {
indices.add(current.eContainer().eContents().indexOf(current));
current = current.eContainer();
}
Collections.reverse(indices);
return action.getType().getClassifier().getName() + "_" + Joiner.on('_').join(indices);
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class SemanticSequencerNfaProvider method initContentValidationNeeded.
protected void initContentValidationNeeded(EClass clazz, Nfa<ISemState> nfa) {
Multimap<EStructuralFeature, AbstractElement> assignments = LinkedHashMultimap.create();
Set<ISemState> states = new NfaUtil().collect(nfa);
for (ISemState state : states) if (state.getFeature() != null)
assignments.put(state.getFeature(), state.getAssignedGrammarElement());
boolean[] validationNeeded = new boolean[clazz.getFeatureCount()];
for (EStructuralFeature feature : clazz.getEAllStructuralFeatures()) validationNeeded[clazz.getFeatureID(feature)] = isContentValidationNeeded(assignments.get(feature));
for (ISemState state : states) if (state.getFeature() != null && validationNeeded[state.getFeatureID()])
((SemState) state).contentValidationNeeded = Lists.newArrayList(assignments.get(state.getFeature()));
else
((SemState) state).contentValidationNeeded = Collections.emptyList();
}
Aggregations