use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.
the class XtextLabelProvider method getLiteralName.
private String getLiteralName(EnumLiteralDeclaration declaration) {
if (declaration.getEnumLiteral() != null) {
return declaration.getEnumLiteral().getName();
}
ICompositeNode node = NodeModelUtils.getNode(declaration);
String literalName = UNKNOWN;
if (node != null) {
for (ILeafNode leaf : node.getLeafNodes()) {
if (!leaf.isHidden()) {
literalName = leaf.getText();
break;
}
}
}
return literalName;
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.
the class XtextLabelProvider method getLabel.
private String getLabel(RuleCall ruleCall) {
if (ruleCall.getRule() != null) {
return ruleCall.getRule().getName();
}
ICompositeNode node = NodeModelUtils.getNode(ruleCall);
String ruleName = UNKNOWN;
if (node != null) {
for (ILeafNode leaf : node.getLeafNodes()) {
if (!leaf.isHidden()) {
ruleName = leaf.getText();
break;
}
}
}
return ruleName;
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.
the class XtextProposalProvider method completeTypeRef_Classifier.
@Override
public void completeTypeRef_Classifier(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
Grammar grammar = GrammarUtil.getGrammar(model);
ContentAssistContext.Builder myContextBuilder = context.copy();
myContextBuilder.setMatcher(new ClassifierPrefixMatcher(context.getMatcher(), classifierQualifiedNameConverter));
if (model instanceof TypeRef) {
ICompositeNode node = NodeModelUtils.getNode(model);
if (node != null) {
int offset = node.getOffset();
Region replaceRegion = new Region(offset, context.getReplaceRegion().getLength() + context.getReplaceRegion().getOffset() - offset);
myContextBuilder.setReplaceRegion(replaceRegion);
myContextBuilder.setLastCompleteNode(node);
StringBuilder availablePrefix = new StringBuilder(4);
for (ILeafNode leaf : node.getLeafNodes()) {
if (leaf.getGrammarElement() != null && !leaf.isHidden()) {
if ((leaf.getTotalLength() + leaf.getTotalOffset()) < context.getOffset())
availablePrefix.append(leaf.getText());
else
availablePrefix.append(leaf.getText().substring(0, context.getOffset() - leaf.getTotalOffset()));
}
if (leaf.getTotalOffset() >= context.getOffset())
break;
}
myContextBuilder.setPrefix(availablePrefix.toString());
}
}
ContentAssistContext myContext = myContextBuilder.toContext();
for (AbstractMetamodelDeclaration declaration : grammar.getMetamodelDeclarations()) {
if (declaration.getEPackage() != null) {
createClassifierProposals(declaration, model, myContext, acceptor);
}
}
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.
the class DomainmodelCodeMiningProvider method createCodeMinings.
@Override
protected void createCodeMinings(IDocument document, XtextResource resource, CancelIndicator indicator, IAcceptor<? super ICodeMining> acceptor) throws BadLocationException {
// get all operations to open document
List<Operation> allOperations = EcoreUtil2.eAllOfType(resource.getContents().get(0), Operation.class);
// get keyword for ')'
Keyword rightParenthesisKeyword_4 = grammar.getOperationAccess().getRightParenthesisKeyword_4();
for (Operation o : allOperations) {
// inline annotations only for methods with no return type
if (o.getType() != null) {
continue;
}
// get return type name from operation
JvmOperation inferredOp = (JvmOperation) jvmModelAssociations.getPrimaryJvmElement(o);
if (inferredOp == null || inferredOp.getReturnType() == null) {
// broken model
continue;
}
String returnTypeName = inferredOp.getReturnType().getSimpleName();
// find document offset for inline annotation
ICompositeNode node = NodeModelUtils.findActualNodeFor(o);
for (Iterator<INode> it = node.getAsTreeIterable().iterator(); it.hasNext(); ) {
INode child = it.next();
if (rightParenthesisKeyword_4.equals(child.getGrammarElement())) {
// create line content code mining for inline annotation after grammarElement ')'
String annotationText = " : " + returnTypeName;
acceptor.accept(createNewLineContentCodeMining(child.getTotalOffset() + 1, annotationText));
}
}
}
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-eclipse by eclipse.
the class XtextReconcilerDebugger method assertResouceParsedCorrectly.
public void assertResouceParsedCorrectly(XtextResource resource, final ReconcilerReplaceRegion region) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
ICompositeNode rootNode = parseResult.getRootNode();
final String resourceContent = rootNode.getText();
IParseResult reparseResult = parser.parse(new StringReader(resourceContent));
if (!emfStructureComparator.isSameStructure(parseResult.getRootASTElement(), reparseResult.getRootASTElement())) {
new DisplayRunnable() {
@Override
protected void run() throws Exception {
LOG.error("PartialParsing produced wrong model");
LOG.error("Events: \n\t" + Joiner.on("\n\t").join(region.getDocumentEvents()));
LOG.error("ReplaceRegion: \n\t'" + region + "'");
MessageDialog.openError(Display.getCurrent().getActiveShell(), "XtextReconcilerDebugger", "PartialParsing produced wrong model." + "\n\nSee log for details.");
}
};
}
}
}
Aggregations