use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class AbstractParseTreeConstructor method serializeSubtree.
@Override
public TreeConstructionReport serializeSubtree(EObject object, ITokenStream out) throws IOException {
TreeConstructionReportImpl report = createReport(object);
AbstractToken root = serialize(object, report);
Set<ICompositeNode> roots = Sets.newHashSet();
Map<EObject, AbstractToken> obj2token = Maps.newHashMap();
collectRootsAndEObjects(root, obj2token, roots);
// dump("", root);
Map<ILeafNode, EObject> comments = commentAssociater.associateCommentsWithSemanticEObjects(object, roots);
for (ICompositeNode r : roots) assignNodesByMatching(obj2token, r, comments);
WsMergerStream wsout = new WsMergerStream(out);
// dump("", root);
// System.out.println(EmfFormatter.objToStr(roots.iterator().next(),
// ParsetreePackage.Literals.ABSTRACT_NODE__TOTAL_LENGTH,
// ParsetreePackage.Literals.ABSTRACT_NODE__TOTAL_OFFSET,
// ParsetreePackage.Literals.ABSTRACT_NODE__TOTAL_LINE, ParsetreePackage.Literals.ABSTRACT_NODE__PARENT));
ITextRegion previousLocation = ITextRegion.EMPTY_REGION;
initStream(root, wsout);
previousLocation = write(root, wsout, previousLocation);
wsout.flush();
report.setPreviousLocation(previousLocation);
return report;
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class NodeIterator method findNextSibling.
protected INode findNextSibling(INode node) {
ICompositeNode parent = node.getParent();
if (parent == null) {
return null;
}
INode successor = node.getNextSibling();
if (successor != null) {
return successor;
}
return findNextSibling(parent);
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class DefaultLocationInFileProvider method getLocationNodes.
protected List<INode> getLocationNodes(EObject obj) {
final EStructuralFeature nameFeature = getIdentifierFeature(obj);
if (nameFeature != null) {
List<INode> result = NodeModelUtils.findNodesForFeature(obj, nameFeature);
if (!result.isEmpty())
return result;
}
List<INode> resultNodes = Lists.newArrayList();
final ICompositeNode startNode = findNodeFor(obj);
INode keywordNode = null;
// use LeafNodes instead of children?
for (INode child : startNode.getChildren()) {
EObject grammarElement = child.getGrammarElement();
if (grammarElement instanceof RuleCall) {
RuleCall ruleCall = (RuleCall) grammarElement;
String ruleName = ruleCall.getRule().getName();
if (ruleName.equals("ID")) {
resultNodes.add(child);
}
} else if (grammarElement instanceof Keyword) {
// TODO use only keywords, that aren't symbols like '=' ?
if (keywordNode == null && useKeyword((Keyword) grammarElement, obj)) {
keywordNode = child;
}
}
}
if (resultNodes.isEmpty() && keywordNode != null)
resultNodes.add(keywordNode);
return resultNodes;
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class Linker method ensureLinked.
public void ensureLinked(EObject obj, IDiagnosticProducer producer) {
ICompositeNode node = NodeModelUtils.getNode(obj);
if (node == null)
return;
Set<EReference> handledReferences = new HashSet<EReference>();
ensureLinked(obj, producer, node, handledReferences, false);
producer.setNode(node);
setDefaultValues(obj, handledReferences, producer);
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class Linker method ensureLinked.
private void ensureLinked(EObject obj, IDiagnosticProducer producer, ICompositeNode node, Set<EReference> handledReferences, boolean dontCheckParent) {
for (INode abstractNode = node.getFirstChild(); abstractNode != null; abstractNode = abstractNode.getNextSibling()) {
EObject grammarElement = abstractNode.getGrammarElement();
if (grammarElement instanceof CrossReference) {
CrossReference ref = (CrossReference) grammarElement;
producer.setNode(abstractNode);
ensureIsLinked(obj, abstractNode, ref, handledReferences, producer);
} else if (grammarElement instanceof RuleCall && abstractNode instanceof ICompositeNode) {
RuleCall ruleCall = (RuleCall) grammarElement;
AbstractRule calledRule = ruleCall.getRule();
if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
ensureLinked(obj, producer, (ICompositeNode) abstractNode, handledReferences, true);
}
}
}
if (!dontCheckParent && shouldCheckParentNode(node)) {
ensureLinked(obj, producer, node.getParent(), handledReferences, false);
}
}
Aggregations