use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendClass source, JvmGenericType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
boolean isStatic = source.isStatic() && !isTopLevel(source);
if (!isStatic) {
JvmDeclaredType declaringType = inferredJvmType.getDeclaringType();
if (declaringType instanceof JvmGenericType) {
if (((JvmGenericType) declaringType).isInterface())
isStatic = true;
} else if (declaringType instanceof JvmAnnotationType) {
isStatic = true;
}
}
inferredJvmType.setStatic(isStatic);
inferredJvmType.setAbstract(source.isAbstract());
inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
if (!inferredJvmType.isAbstract()) {
inferredJvmType.setFinal(source.isFinal());
}
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
JvmTypeReference extendsClause = source.getExtends();
if (extendsClause == null || extendsClause.getType() == null) {
JvmTypeReference typeRefToObject = typeReferences.getTypeForName(Object.class, source);
if (typeRefToObject != null)
inferredJvmType.getSuperTypes().add(typeRefToObject);
} else {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(extendsClause));
}
for (JvmTypeReference intf : source.getImplements()) {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
}
fixTypeParameters(inferredJvmType);
addDefaultConstructor(source, inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) {
transform(member, inferredJvmType, true);
}
}
appendSyntheticDispatchMethods(source, inferredJvmType);
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
nameClashResolver.resolveNameClashes(inferredJvmType);
}
use of org.eclipse.xtend.core.xtend.XtendFunction 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.xtend.core.xtend.XtendFunction 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.xtend.core.xtend.XtendFunction 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.xtend.core.xtend.XtendFunction 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);
}
}
Aggregations