use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class OverrideHelperTest method checkFindOverriddenOperation_03.
@Test
public void checkFindOverriddenOperation_03() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("import java.util.Map");
_builder.newLine();
_builder.newLine();
_builder.append("class Foo implements Bar {");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("override bar(Map<?, ?> map) {}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("interface Bar {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void bar(Map<?, ?> map)");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.file(_builder.toString());
EObject _primaryJvmElement = this._iJvmModelAssociations.getPrimaryJvmElement(IterableExtensions.<XtendFunction>head(Iterables.<XtendFunction>filter(IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes()).getMembers(), XtendFunction.class)));
final JvmOperation operation = ((JvmOperation) _primaryJvmElement);
Assert.assertNotNull(this.overrideHelper.findOverriddenOperation(operation));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class StandardFeatureCallArgumentsTest 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.createStandardArguments(arguments, operation.getParameters(), receiver, this.getOwner());
Class<? extends IFeatureCallArguments> _class = result.getClass();
boolean _equals = Objects.equal(_class, StandardFeatureCallArguments.class);
Assert.assertTrue(_equals);
return result;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class AnonymousClassTypeTest method testOverriddenMethodTypeArgumentInference.
@Test
public void testOverriddenMethodTypeArgumentInference() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("new Iterable<String>() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override iterator() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFunction function = this.function(_builder.toString());
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(operation.eResource());
Assert.assertEquals("Iterable<String>", resolvedTypes.getActualType(operation).toString());
XExpression _expression = function.getExpression();
XExpression _head = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
final AnonymousClass anonymousClass = ((AnonymousClass) _head);
XtendMember _last = IterableExtensions.<XtendMember>last(anonymousClass.getMembers());
final JvmOperation overriding = this._iXtendJvmAssociations.getDirectlyInferredOperation(((XtendFunction) _last));
Assert.assertEquals("Iterator<String>", resolvedTypes.getActualType(overriding).toString());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class AnonymousClassTypeTest method testOverriddenMethodTypeArgumentInference_2.
@Test
public void testOverriddenMethodTypeArgumentInference_2() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def <T> foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("new Iterable<T>() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override iterator() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFunction function = this.function(_builder.toString());
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(operation.eResource());
Assert.assertEquals("Iterable<T>", resolvedTypes.getActualType(operation).toString());
XExpression _expression = function.getExpression();
XExpression _head = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
final AnonymousClass anonymousClass = ((AnonymousClass) _head);
XtendMember _last = IterableExtensions.<XtendMember>last(anonymousClass.getMembers());
final JvmOperation overriding = this._iXtendJvmAssociations.getDirectlyInferredOperation(((XtendFunction) _last));
Assert.assertEquals("Iterator<T>", resolvedTypes.getActualType(overriding).toString());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.
the class NonOverridableTypesProviderTest method testInheritMiddle_02.
@Test
public void testInheritMiddle_02() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("import types.OuterClass");
_builder.newLine();
_builder.newLine();
_builder.append("class Foo extends OuterClass.MiddleClass {");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo() ");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendClass xtendClass = this.clazz(_builder.toString());
final JvmGenericType inferredType = this.associations.getInferredType(xtendClass);
this.assertTypeInScope("Foo", inferredType);
this.assertTypeInScope("InnerMostClass", inferredType);
this.assertNotInScope("OuterClass.MiddleClass", inferredType);
this.assertNotInScope("MiddleClass", inferredType);
this.assertNotInScope("OuterClass", inferredType);
this.assertNotInScope("PrivateMiddleClass", inferredType);
final XtendMember method = xtendClass.getMembers().get(0);
final JvmOperation operation = this.associations.getDirectlyInferredOperation(((XtendFunction) method));
this.assertTypeInScope("Foo", operation);
this.assertTypeInScope("InnerMostClass", operation);
this.assertNotInScope("OuterClass.MiddleClass", operation);
this.assertNotInScope("MiddleClass", operation);
this.assertNotInScope("OuterClass", operation);
this.assertNotInScope("PrivateMiddleClass", inferredType);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations