Search in sources :

Example 46 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class VarArgFeatureCallArgumentsTest method testBug457779_02.

@Test
public void testBug457779_02() {
    final IFeatureCallArguments arguments = this.toArgumentsWithReceiver("String s, int[] i", "\"\", 1");
    final XExpression first = arguments.getArgument(0);
    Assert.assertNull(first);
    final LightweightTypeReference firstType = arguments.getDeclaredTypeForLambda(0);
    Assert.assertNull(firstType);
    final XExpression second = arguments.getArgument(1);
    Assert.assertTrue((second instanceof XStringLiteral));
    final LightweightTypeReference secondType = arguments.getDeclaredTypeForLambda(1);
    Assert.assertEquals("String", secondType.getSimpleName());
    final XExpression third = arguments.getArgument(2);
    Assert.assertTrue((third instanceof XNumberLiteral));
    final LightweightTypeReference thirdType = arguments.getDeclaredTypeForLambda(2);
    Assert.assertEquals("int", thirdType.getSimpleName());
    try {
        arguments.getArgument(3);
        Assert.fail("Expected exception");
    } catch (final Throwable _t) {
        if (_t instanceof IndexOutOfBoundsException) {
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
    try {
        arguments.getDeclaredTypeForLambda(3);
        Assert.fail("Expected exception");
    } catch (final Throwable _t_1) {
        if (_t_1 instanceof IndexOutOfBoundsException) {
        } else {
            throw Exceptions.sneakyThrow(_t_1);
        }
    }
}
Also used : XStringLiteral(org.eclipse.xtext.xbase.XStringLiteral) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XExpression(org.eclipse.xtext.xbase.XExpression) XNumberLiteral(org.eclipse.xtext.xbase.XNumberLiteral) IFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments) Test(org.junit.Test)

Example 47 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class AnonymousClassTypeTest method testAnonymousWithAdditionalMember.

@Test
public void testAnonymousWithAdditionalMember() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val foo = new Runnable() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("int bar");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("override run() {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("foo");
        _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("Runnable", resolvedTypes.getActualType(operation).toString());
        XExpression _expression = function.getExpression();
        final XExpression variable = IterableExtensions.<XExpression>last(((XBlockExpression) _expression).getExpressions());
        final LightweightTypeReference variableType = resolvedTypes.getActualType(variable);
        Assert.assertEquals("__Foo_1", variableType.toString());
        Assert.assertTrue(variableType.isSubtypeOf(Runnable.class));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 48 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class AbstractExecutableBuilder method appendThrowsClause.

protected ISourceAppender appendThrowsClause(final ISourceAppender appendable) {
    ISourceAppender _xblockexpression = null;
    {
        final Iterator<LightweightTypeReference> iterator = this.exceptions.iterator();
        boolean _hasNext = iterator.hasNext();
        if (_hasNext) {
            appendable.append(" throws ");
            do {
                {
                    final LightweightTypeReference typeRef = iterator.next();
                    if ((typeRef != null)) {
                        this.appendType(appendable, typeRef, "Exception");
                    }
                    boolean _hasNext_1 = iterator.hasNext();
                    if (_hasNext_1) {
                        appendable.append(", ");
                    }
                }
            } while (iterator.hasNext());
        }
        _xblockexpression = appendable;
    }
    return _xblockexpression;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) Iterator(java.util.Iterator) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender)

Example 49 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class MemberFromSuperImplementor method initializeExecutableBuilder.

protected void initializeExecutableBuilder(final AbstractExecutableBuilder builder, final JvmDeclaredType overrider, final IResolvedExecutable overridden) {
    final JvmExecutable executable = overridden.getDeclaration();
    builder.setContext(overrider);
    builder.setVisibility(overridden.getDeclaration().getVisibility());
    final Procedure2<LightweightTypeReference, Integer> _function = (LightweightTypeReference it, Integer index) -> {
        final JvmFormalParameter declaredParameter = executable.getParameters().get((index).intValue());
        final AbstractParameterBuilder parameterBuilder = builder.newParameterBuilder();
        parameterBuilder.setName(declaredParameter.getSimpleName());
        parameterBuilder.setType(it);
        JvmAnnotationReference _findAnnotation = this.annotationLookup.findAnnotation(declaredParameter, Extension.class);
        boolean _tripleNotEquals = (_findAnnotation != null);
        parameterBuilder.setExtensionFlag(_tripleNotEquals);
    };
    IterableExtensions.<LightweightTypeReference>forEach(overridden.getResolvedParameterTypes(), _function);
    builder.setVarArgsFlag(executable.isVarArgs());
    builder.setExceptions(overridden.getResolvedExceptions());
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) AbstractParameterBuilder(org.eclipse.xtend.ide.codebuilder.AbstractParameterBuilder) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 50 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class CreateMemberQuickfixes method newMethodQuickfixes.

protected void newMethodQuickfixes(LightweightTypeReference containerType, String name, /* @Nullable */
LightweightTypeReference returnType, List<LightweightTypeReference> argumentTypes, XAbstractFeatureCall call, JvmDeclaredType callersType, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
    boolean isLocal = callersType == containerType.getType();
    boolean isStatic = isStaticAccess(call);
    boolean isAbstract = true;
    if (containerType.getType() instanceof JvmGenericType) {
        isAbstract = !((JvmGenericType) containerType.getType()).isInstantiateable();
    } else if (containerType.getType() instanceof JvmDeclaredType) {
        isAbstract = ((JvmDeclaredType) containerType.getType()).isAbstract();
    }
    if (containerType.getType() instanceof JvmDeclaredType) {
        JvmDeclaredType declaredType = (JvmDeclaredType) containerType.getType();
        newMethodQuickfix(declaredType, name, returnType, argumentTypes, isStatic, isAbstract, false, isLocal, call, issue, issueResolutionAcceptor);
    }
    if (!isLocal && !isStatic) {
        List<LightweightTypeReference> extensionMethodParameterTypes = newArrayList(argumentTypes);
        extensionMethodParameterTypes.add(0, containerType);
        newMethodQuickfix(callersType, name, returnType, extensionMethodParameterTypes, false, isAbstract, true, true, call, issue, issueResolutionAcceptor);
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Aggregations

LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)83 Test (org.junit.Test)28 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)23 XExpression (org.eclipse.xtext.xbase.XExpression)22 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)20 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)19 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)16 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)13 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)10 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)10 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)10 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)9 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)9 JvmType (org.eclipse.xtext.common.types.JvmType)8 ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)8 EObject (org.eclipse.emf.ecore.EObject)7 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)7 StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)7 RichString (org.eclipse.xtend.core.xtend.RichString)6 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)6