use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class VarArgFeatureCallArgumentsTest method toArguments.
protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def void m(");
_builder.append(signature);
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("m(");
_builder.append(invocation, "\t");
_builder.append(")");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
final String functionString = _builder.toString();
final XtendFunction function = this.function(functionString);
XExpression _expression = function.getExpression();
final XBlockExpression body = ((XBlockExpression) _expression);
XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
final XFeatureCall featureCall = ((XFeatureCall) _head);
final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
final IFeatureCallArguments result = this.factory.createVarArgArguments(arguments, operation.getParameters(), receiver, this.getOwner());
Class<? extends IFeatureCallArguments> _class = result.getClass();
boolean _equals = Objects.equal(_class, VarArgFeatureCallArguments.class);
Assert.assertTrue(_equals);
return result;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method addQuickfixes.
@Override
public void addQuickfixes(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, IXtextDocument xtextDocument, XtextResource resource, EObject referenceOwner, EReference unresolvedReference) throws Exception {
if (referenceOwner instanceof XAbstractFeatureCall) {
XAbstractFeatureCall call = (XAbstractFeatureCall) referenceOwner;
String newMemberName = (issue.getData() != null && issue.getData().length > 0) ? issue.getData()[0] : null;
if (newMemberName != null) {
if (call instanceof XMemberFeatureCall) {
if (!call.isExplicitOperationCallOrBuilderSyntax()) {
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
}
newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
} else if (call instanceof XFeatureCall) {
if (!call.isExplicitOperationCallOrBuilderSyntax()) {
if (logicalContainerProvider.getNearestLogicalContainer(call) instanceof JvmExecutable)
newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
}
newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
} else if (call instanceof XAssignment) {
newSetterQuickfix(issue, issueResolutionAcceptor, newMemberName, call);
XAssignment assigment = (XAssignment) call;
if (assigment.getAssignable() == null) {
newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
} else if (isThis(assigment)) {
newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
}
}
}
if (call.isOperation()) {
JvmIdentifiableElement feature = call.getFeature();
if (feature.eIsProxy()) {
String operatorMethodName = getOperatorMethodName(call);
if (operatorMethodName != null)
newMethodQuickfixes(operatorMethodName, call, issue, issueResolutionAcceptor);
}
}
if (call instanceof XFeatureCall && call.getFeature() instanceof JvmConstructor) {
newConstructorQuickfix(issue, issueResolutionAcceptor, (XFeatureCall) call);
}
}
if (referenceOwner instanceof XConstructorCall) {
newConstructorQuickfix(issue, issueResolutionAcceptor, (XConstructorCall) referenceOwner);
}
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method getMethodBodyWithRenamedParameters.
protected String getMethodBodyWithRenamedParameters(ITextRegion expressionsRegion) throws BadLocationException {
String expressionsAsString = document.get(expressionsRegion.getOffset(), expressionsRegion.getLength());
List<ReplaceRegion> parameterRenames = newArrayList();
for (final String parameterName : externalFeatureCalls.keySet()) {
ParameterInfo parameter = find(parameterInfos, new Predicate<ParameterInfo>() {
@Override
public boolean apply(ParameterInfo info) {
return equal(info.getOldName(), parameterName);
}
});
if (parameter.isRenamed()) {
for (XFeatureCall featureCall : externalFeatureCalls.get(parameterName)) {
ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, -1);
parameterRenames.add(new ReplaceRegion(textRegion, parameter.getNewName()));
}
}
}
sort(parameterRenames, new Comparator<ReplaceRegion>() {
@Override
public int compare(ReplaceRegion o1, ReplaceRegion o2) {
return o2.getOffset() - o1.getOffset();
}
});
StringBuffer buffer = new StringBuffer(expressionsAsString);
for (ReplaceRegion parameterRename : parameterRenames) {
buffer.replace(parameterRename.getOffset() - expressionsRegion.getOffset(), parameterRename.getEndOffset() - expressionsRegion.getOffset(), parameterRename.getText());
}
expressionsAsString = buffer.toString();
return expressionsAsString;
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method calculateExpressions.
protected List<XExpression> calculateExpressions(final List<XExpression> expressions) {
final XExpression firstExpression = expressions.get(0);
// instead of the complete XVariableDeclaration
if (expressions.size() == 1 && firstExpression instanceof XVariableDeclaration) {
final XtendFunction originalMethod = EcoreUtil2.getContainerOfType(firstExpression, XtendFunction.class);
for (final EObject element : Iterables.filter(EcoreUtil2.eAllContents(originalMethod.getExpression()), new Predicate<EObject>() {
@Override
public boolean apply(EObject input) {
return !EcoreUtil.isAncestor(expressions, input);
}
})) {
if (element instanceof XFeatureCall) {
XFeatureCall featureCall = (XFeatureCall) element;
JvmIdentifiableElement feature = featureCall.getFeature();
if (EcoreUtil.isAncestor(expressions, feature)) {
return singletonList(((XVariableDeclaration) firstExpression).getRight());
}
}
}
}
return expressions;
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method createMethodCallEdit.
protected void createMethodCallEdit(DocumentRewriter.Section methodCallSection, ITextRegion expressionRegion) throws BadLocationException {
if (firstExpression.eContainer() instanceof RichString) {
methodCallSection.append("�");
}
if (isNeedsReturnExpression()) {
JvmIdentifiableElement returnFeature = ((XFeatureCall) returnExpression).getFeature();
if (isFinalFeature(returnFeature))
methodCallSection.append("val ");
else
methodCallSection.append("var ");
methodCallSection.append(returnFeature.getSimpleName()).append(" = ");
}
boolean needsSurroundingParentheses = false;
if (firstExpression.eContainer() instanceof XMemberFeatureCall) {
if (((XMemberFeatureCall) firstExpression.eContainer()).getMemberCallArguments().size() == 1) {
String expressionExpanded = document.get(expressionRegion.getOffset() - 1, expressionRegion.getLength() + 2);
if (!expressionExpanded.startsWith("(") || !expressionExpanded.endsWith(")")) {
needsSurroundingParentheses = true;
methodCallSection.append("(");
}
}
}
methodCallSection.append(methodName).append("(");
boolean isFirst = true;
for (ParameterInfo parameterInfo : getParameterInfos()) {
if (!isFirst)
methodCallSection.append(", ");
isFirst = false;
methodCallSection.append(parameterInfo.getOldName());
}
methodCallSection.append(")");
if (needsSurroundingParentheses)
methodCallSection.append(")");
if (lastExpression.eContainer() instanceof RichString) {
methodCallSection.append("�");
}
}
Aggregations