use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.
the class AbstractSmokeTest method testSkipNodesInBetween.
@Test
public void testSkipNodesInBetween() throws Exception {
for (String string : getSmokeTestModels()) {
LazyLinkingResource resource = createResource(string);
if (resource != null) {
ICompositeNode rootNode = resource.getParseResult().getRootNode();
ReplaceRegion replaceRegion = null;
for (INode node : rootNode.getAsTreeIterable()) {
int offset = node.getTotalOffset();
int length = node.getTotalLength();
if (replaceRegion == null || replaceRegion.getOffset() != offset || replaceRegion.getLength() != length) {
replaceRegion = new ReplaceRegion(offset, length, "");
StringBuilder builder = new StringBuilder(string);
replaceRegion.applyTo(builder);
processModel(builder.toString());
}
}
}
}
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.
the class DefaultTextEditComposer method beginRecording.
@Override
public void beginRecording(Resource newResource) {
reset();
if (newResource != resource) {
if (resource != null)
resource.eAdapters().remove(this);
newResource.eAdapters().add(this);
resource = newResource;
}
if (resource.getContents().isEmpty()) {
resourceSize = 0;
} else {
final EObject root = resource.getContents().get(0);
ICompositeNode rootNode = NodeModelUtils.getNode(root);
if (rootNode == null) {
throw new IllegalStateException("Cannot find root node in resource " + resource.getURI());
}
resourceSize = rootNode.getTotalLength();
}
recording = true;
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.
the class XbaseProposalProvider method completeXFeatureCall_Feature.
@Override
public void completeXFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (model != null) {
if (typeResolver.resolveTypes(model).hasExpressionScope(model, IExpressionScope.Anchor.WITHIN)) {
return;
}
}
if (model instanceof XMemberFeatureCall) {
ICompositeNode node = NodeModelUtils.getNode(model);
int endOffset = node.getEndOffset();
if (isInMemberFeatureCall(model, endOffset, context)) {
return;
}
}
createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor);
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.
the class XtextOutlineTreeProvider method createRuleNode.
protected void createRuleNode(IOutlineNode parentNode, AbstractRule rule, boolean isShowGrammar, boolean isLocalRule) {
StyledString text = (StyledString) textDispatcher.invoke(rule);
if (isShowGrammar) {
EObject grammar = rule.eContainer();
if (grammar instanceof Grammar)
text.append(new StyledString(" (" + ((Grammar) grammar).getName() + ")", StyledString.COUNTER_STYLER));
}
Image image = imageDispatcher.invoke(rule);
RuleNode ruleNode = new RuleNode(rule, parentNode, image, text, isLeafDispatcher.invoke(rule));
ruleNode.setFullText(new StyledString().append(text).append(getReturnTypeText(rule)));
if (isLocalRule) {
ICompositeNode parserNode = NodeModelUtils.getNode(rule);
if (parserNode != null)
ruleNode.setTextRegion(parserNode.getTextRegion());
ruleNode.setShortTextRegion(locationInFileProvider.getSignificantTextRegion(rule));
}
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.
the class XtextGrammarQuickfixProvider method fixUnresolvedRule.
@Fix(XtextLinkingDiagnosticMessageProvider.UNRESOLVED_RULE)
public void fixUnresolvedRule(final Issue issue, IssueResolutionAcceptor acceptor) {
final String ruleName = issue.getData()[0];
acceptor.accept(issue, "Create rule '" + ruleName + "'", "Create rule '" + ruleName + "'", NULL_QUICKFIX_IMAGE, new ISemanticModification() {
@Override
public void apply(final EObject element, IModificationContext context) throws BadLocationException {
AbstractRule abstractRule = EcoreUtil2.getContainerOfType(element, ParserRule.class);
ICompositeNode node = NodeModelUtils.getNode(abstractRule);
int offset = node.getEndOffset();
StringBuilder builder = new StringBuilder("\n\n");
if (abstractRule instanceof TerminalRule)
builder.append("terminal ");
String newRule = builder.append(ruleName).append(":\n\t\n;").toString();
context.getXtextDocument().replace(offset, 0, newRule);
}
});
createLinkingIssueResolutions(issue, acceptor);
}
Aggregations