use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method checkInitialConditions.
@Override
public RefactoringStatus checkInitialConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
StatusWrapper status = statusProvider.get();
IResolvedTypes resolvedTypes = typeResolver.resolveTypes(firstExpression, new CancelIndicator() {
@Override
public boolean isCanceled() {
return pm.isCanceled();
}
});
try {
Set<String> calledExternalFeatureNames = newHashSet();
returnType = calculateReturnType(resolvedTypes);
if (returnType != null && !equal("void", returnType.getIdentifier()))
returnExpression = lastExpression;
boolean isReturnAllowed = isEndOfOriginalMethod();
for (EObject element : EcoreUtil2.eAllContents(originalMethod.getExpression())) {
if (pm.isCanceled()) {
throw new OperationCanceledException();
}
boolean isLocalExpression = EcoreUtil.isAncestor(expressions, element);
if (element instanceof XFeatureCall) {
XFeatureCall featureCall = (XFeatureCall) element;
JvmIdentifiableElement feature = featureCall.getFeature();
LightweightTypeReference featureType = resolvedTypes.getActualType(featureCall);
boolean isLocalFeature = EcoreUtil.isAncestor(expressions, feature);
if (!isLocalFeature && isLocalExpression) {
// call-out
if (feature instanceof JvmFormalParameter || feature instanceof XVariableDeclaration) {
if (!calledExternalFeatureNames.contains(feature.getSimpleName())) {
calledExternalFeatureNames.add(feature.getSimpleName());
ParameterInfo parameterInfo = new ParameterInfo(featureType.getIdentifier(), feature.getSimpleName(), parameterInfos.size());
parameterInfos.add(parameterInfo);
parameter2type.put(parameterInfo, featureType);
}
externalFeatureCalls.put(feature.getSimpleName(), featureCall);
}
} else if (isLocalFeature && !isLocalExpression) {
// call-in
if (returnExpression != null) {
status.add(RefactoringStatus.FATAL, "Ambiguous return value: Multiple local variables are accessed in subsequent code.");
break;
}
returnExpression = featureCall;
returnType = featureType;
}
} else if (isLocalExpression) {
if (element instanceof XReturnExpression && !isReturnAllowed) {
status.add(RefactoringStatus.FATAL, "Extracting method would break control flow due to return statements.");
break;
} else if (element instanceof JvmTypeReference) {
JvmType type = ((JvmTypeReference) element).getType();
if (type instanceof JvmTypeParameter) {
JvmOperation operation = associations.getDirectlyInferredOperation(originalMethod);
if (operation != null) {
List<JvmTypeParameter> typeParameters = operation.getTypeParameters();
if (typeParameters.contains(type))
neededTypeParameters.add((JvmTypeParameter) type);
}
}
} else if (element instanceof JvmFormalParameter)
localFeatureNames.add(((JvmFormalParameter) element).getName());
else if (element instanceof XVariableDeclaration)
localFeatureNames.add(((XVariableDeclaration) element).getIdentifier());
}
}
} catch (OperationCanceledException e) {
throw e;
} catch (Exception exc) {
handleException(exc, status);
}
return status.getRefactoringStatus();
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method test381185.
@Test
public void test381185() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.append("class Foo{");
_builder.newLine();
_builder.append("\t");
_builder.append("Bar b");
_builder.newLine();
_builder.append("\t");
_builder.append("def bar(){ ");
_builder.newLine();
_builder.append("\t\t");
_builder.append("b.foo");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class Bar {");
_builder.newLine();
_builder.append("\t");
_builder.append("Foo f");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("f.bar");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
final XtendClass clazz2 = IterableExtensions.<XtendClass>head(IterableExtensions.<XtendClass>drop(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class), 1));
XtendMember _get = clazz.getMembers().get(1);
final XtendFunction function1 = ((XtendFunction) _get);
XtendMember _get_1 = clazz2.getMembers().get(1);
final XtendFunction function2 = ((XtendFunction) _get_1);
XExpression _expression = function1.getExpression();
final XBlockExpression expression1 = ((XBlockExpression) _expression);
XExpression _expression_1 = function2.getExpression();
final XBlockExpression expression2 = ((XBlockExpression) _expression_1);
XExpression _get_2 = expression1.getExpressions().get(0);
final XMemberFeatureCall call1 = ((XMemberFeatureCall) _get_2);
XExpression _get_3 = expression2.getExpressions().get(0);
final XMemberFeatureCall call2 = ((XMemberFeatureCall) _get_3);
Assert.assertEquals("Object Bar.foo()", this.signatureProvider.getSignature(call1.getFeature()));
Assert.assertEquals("Object Foo.bar()", this.signatureProvider.getSignature(call2.getFeature()));
XExpression _memberCallTarget = call1.getMemberCallTarget();
Assert.assertEquals("Bar Foo.b", this.signatureProvider.getSignature(((XFeatureCall) _memberCallTarget).getFeature()));
XExpression _memberCallTarget_1 = call2.getMemberCallTarget();
Assert.assertEquals("Foo Bar.f", this.signatureProvider.getSignature(((XFeatureCall) _memberCallTarget_1).getFeature()));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method testSignatureDelegateConstructorCall_02.
@Ignore
@Test
public void testSignatureDelegateConstructorCall_02() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.append("class Foo<S extends CharSequence> {");
_builder.newLine();
_builder.append("\t");
_builder.append("new(int i) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("this(StringBuilder)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("new<X>(Class<X> c) {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
XtendMember _get = clazz.getMembers().get(0);
final XtendConstructor xtendConstructor = ((XtendConstructor) _get);
XExpression _expression = xtendConstructor.getExpression();
XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
final XFeatureCall featureCall = ((XFeatureCall) _get_1);
final String signature = this.signatureProvider.getSignature(featureCall);
Assert.assertEquals("Foo<S>()", signature);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method testSignatureDelegateConstructorCall_01.
@Ignore
@Test
public void testSignatureDelegateConstructorCall_01() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.append("class Foo<S extends CharSequence> {");
_builder.newLine();
_builder.append("\t");
_builder.append("new(int i) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("this()");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("new() {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
XtendMember _get = clazz.getMembers().get(0);
final XtendConstructor xtendConstructor = ((XtendConstructor) _get);
XExpression _expression = xtendConstructor.getExpression();
XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
final XFeatureCall featureCall = ((XFeatureCall) _get_1);
final String signature = this.signatureProvider.getSignature(featureCall);
Assert.assertEquals("Foo<S>()", signature);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XFeatureCall in project xtext-xtend by eclipse.
the class LinkingTest method testStaticImports_12.
@Test
public void testStaticImports_12() throws Exception {
String fileAsText = "import static extension com.google.common.collect.Iterables.*\n" + "import static java.util.Collections.*\n" + "class Clazz { def void method() { find(singletonList(''), [e|e.length!=0])} }";
XtendFile file = file(fileAsText, true);
XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0);
XFeatureCall featureCall = (XFeatureCall) ((XBlockExpression) function.getExpression()).getExpressions().get(0);
String identifier = featureCall.getFeature().getIdentifier();
assertEquals("com.google.common.collect.Iterables.find(java.lang.Iterable,com.google.common.base.Predicate)", identifier);
}
Aggregations