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(); }
/** * creates the feature scope for {@link XAbstractFeatureCall}, including the local variables in * case it is a feature call without receiver (XFeatureCall). */ protected IScope createFeatureCallScope(final XAbstractFeatureCall call, EReference reference) { if (call instanceof XFeatureCall || ((call instanceof XAssignment) && ((XAssignment) call).getAssignable() == null)) { IScope result = createSimpleFeatureCallScope(call, reference, call.eResource(), false, -1); return result; } final XExpression syntacticalReceiver = getSyntacticalReceiver(call); IScope result = createFeatureCallScopeForReceiver(call, syntacticalReceiver, reference); return result; }