Search in sources :

Example 21 with XtendFunction

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);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 22 with XtendFunction

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 23 with XtendFunction

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);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)

Example 24 with XtendFunction

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);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 25 with XtendFunction

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);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Aggregations

XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)441 Test (org.junit.Test)374 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)248 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)198 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)182 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)116 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)101 XExpression (org.eclipse.xtext.xbase.XExpression)95 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)91 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)78 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)72 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)60 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)46 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)39 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)30 EObject (org.eclipse.emf.ecore.EObject)28 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)23 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)23 RichString (org.eclipse.xtend.core.xtend.RichString)17 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)16