Java Code Examples for org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable#append()
The following examples show how to use
org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable#append() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XbaseQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private void addTypeCastToImplicitReceiver(XFeatureCall featureCall, IModificationContext context, JvmType declaringType) throws BadLocationException { String receiver; if (featureCall.getImplicitReceiver() instanceof XAbstractFeatureCall) receiver = ((XAbstractFeatureCall) featureCall.getImplicitReceiver()).getFeature().getSimpleName(); else return; List<INode> nodes = NodeModelUtils.findNodesForFeature(featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE); if (nodes.isEmpty()) return; INode firstNode = IterableExtensions.head(nodes); int offset = firstNode.getOffset(); ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) featureCall.eResource(), offset, 0); appendable.append("("); appendable.append(receiver); appendable.append(" as "); appendable.append(declaringType); appendable.append(")."); appendable.commitChanges(); }
Example 2
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void internalDoAddAbstractKeyword(EObject element, IModificationContext context) throws BadLocationException { if (element instanceof XtendFunction) { element = element.eContainer(); } if (element instanceof XtendClass) { XtendClass clazz = (XtendClass) element; IXtextDocument document = context.getXtextDocument(); ICompositeNode clazzNode = NodeModelUtils.findActualNodeFor(clazz); if (clazzNode == null) throw new IllegalStateException("Cannot determine node for clazz " + clazz.getName()); int offset = -1; for (ILeafNode leafNode : clazzNode.getLeafNodes()) { if (leafNode.getText().equals("class")) { offset = leafNode.getOffset(); break; } } ReplacingAppendable appendable = appendableFactory.create(document, (XtextResource) clazz.eResource(), offset, 0); appendable.append("abstract "); appendable.commitChanges(); } }
Example 3
Source File: ActionAddModification.java From sarl with Apache License 2.0 | 6 votes |
@Override public void apply(EObject element, IModificationContext context) throws Exception { final XtendTypeDeclaration container = EcoreUtil2.getContainerOfType(element, XtendTypeDeclaration.class); if (container != null) { final int insertOffset = getTools().getInsertOffset(container); final IXtextDocument document = context.getXtextDocument(); final int length = getTools().getSpaceSize(document, insertOffset); final ReplacingAppendable appendable = getTools().getAppendableFactory().create(document, (XtextResource) element.eResource(), insertOffset, length); final boolean changeIndentation = container.getMembers().isEmpty(); if (changeIndentation) { appendable.increaseIndentation(); } appendable.newLine(); appendable.append( getTools().getGrammarAccess().getDefKeyword()); appendable.append(" "); //$NON-NLS-1$ appendable.append(this.actionName); if (changeIndentation) { appendable.decreaseIndentation(); } appendable.newLine(); appendable.commitChanges(); } }
Example 4
Source File: SuppressWarningsAddModification.java From sarl with Apache License 2.0 | 6 votes |
/** Add SuppressWarnings annotation. * * @param element the element to receive the annotation. * @param context the modification context. * @param suppressWarningsAnnotation the type for the suppress warning annotation. * @throws Exception if the document cannot be changed. */ protected void addAnnotation(EObject element, IModificationContext context, JvmType suppressWarningsAnnotation) throws Exception { final ICompositeNode node = NodeModelUtils.findActualNodeFor(element); if (node != null) { final int insertOffset = node.getOffset(); final IXtextDocument document = context.getXtextDocument(); final int length = getTools().getSpaceSize(document, insertOffset); final ReplacingAppendable appendable = getTools().getAppendableFactory().create(document, (XtextResource) element.eResource(), insertOffset, length); appendable.append(getTools().getGrammarAccess().getCommercialAtKeyword()); appendable.append(suppressWarningsAnnotation); appendable.append("(\""); //$NON-NLS-1$ appendable.append(extractId(this.code)); appendable.append("\")"); //$NON-NLS-1$ appendable.newLine(); appendable.commitChanges(); } }
Example 5
Source File: SuppressWarningsAddModification.java From sarl with Apache License 2.0 | 6 votes |
/** Add SuppressWarnings annotation. * * @param element the element to receive the annotation. * @param annotation the suppress-warning annotation. * @param context the modification context. * @throws Exception if the document cannot be changed. */ protected void addAnnotation(EObject element, XAnnotation annotation, IModificationContext context) throws Exception { final ICompositeNode node = NodeModelUtils.findActualNodeFor(annotation); if (node != null) { final IXtextDocument document = context.getXtextDocument(); final int startOffset = node.getOffset(); final int parameterOffset = getTools().getOffsetForPattern(document, startOffset, "@\\s*" + toPattern(annotation.getAnnotationType().getQualifiedName()) //$NON-NLS-1$ + "\\s*\\(\\s*"); //$NON-NLS-1$ final int insertOffset; if (document.getChar(parameterOffset) == '{') { insertOffset = parameterOffset + getTools().getSpaceSize(document, parameterOffset + 1) + 1; } else { insertOffset = parameterOffset; } final ReplacingAppendable appendable = getTools().getAppendableFactory().create(document, (XtextResource) element.eResource(), insertOffset, 0); appendable.append("\""); //$NON-NLS-1$ appendable.append(extractId(this.code)); appendable.append("\", "); //$NON-NLS-1$ appendable.commitChanges(); } }
Example 6
Source File: XbaseQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private void addTypeCastToExplicitReceiver(XAbstractFeatureCall featureCall, IModificationContext context, JvmType declaringType, EReference structuralFeature) throws BadLocationException { List<INode> nodes = NodeModelUtils.findNodesForFeature(featureCall, structuralFeature); if (nodes.isEmpty()) return; INode firstNode = IterableExtensions.head(nodes); INode lastNode = IterableExtensions.last(nodes); int offset = firstNode.getOffset(); int length = lastNode.getEndOffset() - offset; ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) featureCall.eResource(), offset, length); appendable.append("("); ListIterator<INode> nodeIter = nodes.listIterator(); while (nodeIter.hasNext()) { String text = nodeIter.next().getText(); if (nodeIter.previousIndex() == 0) appendable.append(Strings.removeLeadingWhitespace(text)); else if (nodeIter.nextIndex() == nodes.size()) appendable.append(Strings.trimTrailingLineBreak(text)); else appendable.append(text); } appendable.append(" as "); appendable.append(declaringType); appendable.append(")"); appendable.commitChanges(); }
Example 7
Source File: ReturnTypeAddModification.java From sarl with Apache License 2.0 | 5 votes |
@Override public void apply(EObject element, IModificationContext context) throws Exception { final XtendExecutable xtendExecutable = EcoreUtil2.getContainerOfType(element, XtendExecutable.class); final int insertPosition; if (xtendExecutable.getExpression() == null) { final ICompositeNode functionNode = NodeModelUtils.findActualNodeFor(xtendExecutable); if (functionNode == null) { throw new IllegalStateException("functionNode may not be null"); //$NON-NLS-1$ } insertPosition = functionNode.getEndOffset(); } else { final ICompositeNode expressionNode = NodeModelUtils.findActualNodeFor(xtendExecutable.getExpression()); if (expressionNode == null) { throw new IllegalStateException("expressionNode may not be null"); //$NON-NLS-1$ } insertPosition = expressionNode.getOffset(); } final ReplacingAppendable appendable = getTools().getAppendableFactory().create(context.getXtextDocument(), (XtextResource) xtendExecutable.eResource(), insertPosition, 0); if (xtendExecutable.getExpression() == null) { appendable.append(" "); //$NON-NLS-1$ } appendable.append(getTools().getGrammarAccess().getColonKeyword()); appendable.append(" "); //$NON-NLS-1$ appendable.append(this.expectedType); if (xtendExecutable.getExpression() != null) { appendable.append(" "); //$NON-NLS-1$ } appendable.commitChanges(); }