use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class SemanticSequencerNfaProvider method isContentValidationNeeded.
protected boolean isContentValidationNeeded(Collection<AbstractElement> ass) {
if (ass == null || ass.size() < 2)
return false;
Iterator<AbstractElement> it = ass.iterator();
AbstractElement first = it.next();
CrossReference firstRef = GrammarUtil.containingCrossReference(first);
while (it.hasNext()) {
AbstractElement next = it.next();
if (next instanceof Action)
return true;
if (!EcoreUtil.equals(first, next))
return true;
if (firstRef != null) {
CrossReference nextRef = GrammarUtil.containingCrossReference(next);
if (nextRef != null && nextRef.getType().getClassifier() != firstRef.getType().getClassifier())
return true;
}
}
return false;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AssignmentFinder method findAssignmentsByValue.
@Override
public Set<AbstractElement> findAssignmentsByValue(EObject semanticObj, Multimap<AbstractElement, ISerializationContext> assignments, Object value, INode node) {
List<AbstractElement> assignedElements = Lists.newArrayList(assignments.keySet());
EStructuralFeature feature = FeatureFinderUtil.getFeature(assignedElements.iterator().next(), semanticObj.eClass());
if (feature instanceof EAttribute) {
Class<?> clazz = feature.getEType().getInstanceClass();
if (clazz == Boolean.class || clazz == boolean.class)
return findValidBooleanAssignments(semanticObj, assignedElements, value);
else
return findValidValueAssignments(semanticObj, assignedElements, value);
} else if (feature instanceof EReference) {
EReference ref = (EReference) feature;
if (ref.isContainment())
return findValidAssignmentsForContainmentRef(semanticObj, assignments, (EObject) value);
else
return findValidAssignmentsForCrossRef(semanticObj, assignedElements, (EObject) value, node);
}
throw new RuntimeException("unknown feature type");
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class ContextFinder method collectAssignments.
protected Multimap<AbstractElement, ISerializationContext> collectAssignments(Multimap<IConstraint, ISerializationContext> constraints, EStructuralFeature feature) {
Multimap<AbstractElement, ISerializationContext> result = ArrayListMultimap.create();
for (Entry<IConstraint, Collection<ISerializationContext>> e : constraints.asMap().entrySet()) {
IConstraint constraint = e.getKey();
Collection<ISerializationContext> contexts = e.getValue();
IFeatureInfo featureInfo = constraint.getFeatures()[constraint.getType().getFeatureID(feature)];
List<IConstraintElement> assignments = featureInfo.getAssignments();
for (IConstraintElement assignment : assignments) {
result.putAll(assignment.getGrammarElement(), contexts);
}
}
return result;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class ContextFinder method findByContents.
@Override
public Set<ISerializationContext> findByContents(EObject semanticObject, Iterable<ISerializationContext> contextCandidates) {
if (semanticObject == null)
throw new NullPointerException();
initConstraints();
Multimap<IConstraint, ISerializationContext> constraints;
if (contextCandidates != null)
constraints = getConstraints(semanticObject, contextCandidates);
else
constraints = getConstraints(semanticObject);
if (constraints.size() < 2)
return Sets.newLinkedHashSet(constraints.values());
for (IConstraint cand : Lists.newArrayList(constraints.keySet())) if (!isValidValueQuantity(cand, semanticObject))
constraints.removeAll(cand);
if (constraints.size() < 2)
return Sets.newLinkedHashSet(constraints.values());
LinkedHashSet<ISerializationContext> result = Sets.newLinkedHashSet(constraints.values());
for (EStructuralFeature feat : semanticObject.eClass().getEAllStructuralFeatures()) {
if (transientValueUtil.isTransient(semanticObject, feat) != ValueTransient.NO)
continue;
if (feat.isMany() && ((List<?>) semanticObject.eGet(feat)).isEmpty())
continue;
Multimap<AbstractElement, ISerializationContext> assignments = collectAssignments(constraints, feat);
Set<AbstractElement> assignedElements = findAssignedElements(semanticObject, feat, assignments);
Set<ISerializationContext> keep = Sets.newHashSet();
for (AbstractElement ele : assignedElements) keep.addAll(assignments.get(ele));
result.retainAll(keep);
}
return result;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class NodeModelSemanticSequencer method createSequence.
@Override
public void createSequence(ISerializationContext context, EObject semanticObject) {
SemanticNodeIterator ni = new SemanticNodeIterator(semanticObject);
while (ni.hasNext()) {
Triple<INode, AbstractElement, EObject> node = ni.next();
if (node.getSecond() instanceof RuleCall) {
RuleCall rc = (RuleCall) node.getSecond();
TypeRef ruleType = rc.getRule().getType();
if (ruleType == null || ruleType.getClassifier() instanceof EClass)
acceptSemantic(semanticObject, rc, node.getThird(), node.getFirst());
else if (GrammarUtil.containingCrossReference(node.getSecond()) != null) {
EStructuralFeature feature = FeatureFinderUtil.getFeature(node.getSecond(), semanticObject.eClass());
acceptSemantic(semanticObject, rc, semanticObject.eGet(feature), node.getFirst());
} else {
String strVal = NodeModelUtils.getTokenText(node.getFirst());
Object val = valueConverter.toValue(strVal, ruleNames.getQualifiedName(rc.getRule()), node.getFirst());
acceptSemantic(semanticObject, rc, val, node.getFirst());
}
} else if (node.getSecond() instanceof Keyword)
acceptSemantic(semanticObject, node.getSecond(), node.getFirst().getText(), node.getFirst());
else if (node.getSecond() instanceof Action) {
acceptSemantic(semanticObject, node.getSecond(), semanticObject, node.getFirst());
}
}
}
Aggregations