Search in sources :

Example 16 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class ValidationBug433213Test method test_04.

@Test
public void test_04() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("def <T> m2() {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t\t\t");
        _builder.append("def T m3() {}");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head_1 = IterableExtensions.<XExpression>head(body.getExpressions());
        final AnonymousClass anon = ((AnonymousClass) _head_1);
        XtendMember _head_2 = IterableExtensions.<XtendMember>head(anon.getMembers());
        final XtendFunction m2 = ((XtendFunction) _head_2);
        XExpression _expression_1 = m2.getExpression();
        final XBlockExpression body2 = ((XBlockExpression) _expression_1);
        XExpression _head_3 = IterableExtensions.<XExpression>head(body2.getExpressions());
        final AnonymousClass anon2 = ((AnonymousClass) _head_3);
        XtendMember _head_4 = IterableExtensions.<XtendMember>head(anon2.getMembers());
        final XtendFunction m3 = ((XtendFunction) _head_4);
        final JvmTypeReference returnType = m3.getReturnType();
        final JvmType t = returnType.getType();
        Assert.assertNotNull("notNull", t);
        Assert.assertFalse("t.eIsProxy", t.eIsProxy());
        this.helper.assertNoErrors(file);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 17 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class ValidationBug433213Test method test_02.

@Test
public void test_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <T> m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("def T m2() {}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head_1 = IterableExtensions.<XExpression>head(body.getExpressions());
        final AnonymousClass anon = ((AnonymousClass) _head_1);
        XtendMember _head_2 = IterableExtensions.<XtendMember>head(anon.getMembers());
        final XtendFunction m2 = ((XtendFunction) _head_2);
        final JvmTypeReference returnType = m2.getReturnType();
        final JvmType t = returnType.getType();
        Assert.assertNotNull("notNull", t);
        Assert.assertFalse("t.eIsProxy", t.eIsProxy());
        this.helper.assertNoErrors(file);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 18 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class ValidationBug433213Test method test_05.

@Test
public void test_05() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <T> m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("def m2() {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t\t\t");
        _builder.append("def T m3() {}");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head_1 = IterableExtensions.<XExpression>head(body.getExpressions());
        final AnonymousClass anon = ((AnonymousClass) _head_1);
        XtendMember _head_2 = IterableExtensions.<XtendMember>head(anon.getMembers());
        final XtendFunction m2 = ((XtendFunction) _head_2);
        XExpression _expression_1 = m2.getExpression();
        final XBlockExpression body2 = ((XBlockExpression) _expression_1);
        XExpression _head_3 = IterableExtensions.<XExpression>head(body2.getExpressions());
        final AnonymousClass anon2 = ((AnonymousClass) _head_3);
        XtendMember _head_4 = IterableExtensions.<XtendMember>head(anon2.getMembers());
        final XtendFunction m3 = ((XtendFunction) _head_4);
        final JvmTypeReference returnType = m3.getReturnType();
        final JvmType t = returnType.getType();
        Assert.assertNotNull("notNull", t);
        Assert.assertFalse("t.eIsProxy", t.eIsProxy());
        this.helper.assertNoErrors(file);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 19 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class AnnotationReferenceBuildContextImpl method findOperation.

protected JvmOperation findOperation(final String name, final boolean mustBeArray) {
    final JvmOperation result = this.findOperation(name);
    JvmTypeReference _returnType = result.getReturnType();
    JvmType _type = null;
    if (_returnType != null) {
        _type = _returnType.getType();
    }
    final JvmType returnType = _type;
    boolean _and = false;
    if (!mustBeArray) {
        _and = false;
    } else {
        EClass _eClass = null;
        if (returnType != null) {
            _eClass = returnType.eClass();
        }
        boolean _notEquals = (!Objects.equal(_eClass, TypesPackage.Literals.JVM_ARRAY_TYPE));
        _and = _notEquals;
    }
    if (_and) {
        throw new IllegalArgumentException("Cannot assign array value to simple annotation property");
    }
    return result;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EClass(org.eclipse.emf.ecore.EClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 20 with JvmTypeReference

use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.

the class CompilationUnitImpl method translateAnnotationValue.

public Object translateAnnotationValue(final JvmAnnotationValue value, final boolean isArray) {
    Pair<List<?>, Class<?>> _switchResult = null;
    boolean _matched = false;
    if (value instanceof JvmCustomAnnotationValue) {
        if ((((JvmCustomAnnotationValue) value).getValues().isEmpty() && isArray)) {
            _matched = true;
            List<Object> _emptyList = CollectionLiterals.<Object>emptyList();
            Class<?> _arrayComponentType = this.toArrayComponentType(this.findExpectedType(value));
            _switchResult = Pair.<List<?>, Class<?>>of(_emptyList, _arrayComponentType);
        }
    }
    if (!_matched) {
        if (value instanceof JvmCustomAnnotationValue) {
            _matched = true;
            final JvmTypeReference expectedType = this.findExpectedType(value);
            final Function1<XExpression, Object> _function = (XExpression it) -> {
                return this.evaluate(it, expectedType);
            };
            final Object result = IterableExtensions.<Object>head(IterableExtensions.<XExpression, Object>map(Iterables.<XExpression>filter(((JvmCustomAnnotationValue) value).getValues(), XExpression.class), _function));
            return this.translateAnnotationValue(result, expectedType, isArray);
        }
    }
    if (!_matched) {
        if (value instanceof JvmTypeAnnotationValue) {
            _matched = true;
            final Function1<JvmTypeReference, TypeReference> _function = (JvmTypeReference it) -> {
                return this.toTypeReference(it);
            };
            List<TypeReference> _map = ListExtensions.<JvmTypeReference, TypeReference>map(((JvmTypeAnnotationValue) value).getValues(), _function);
            _switchResult = Pair.<List<?>, Class<?>>of(_map, TypeReference.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmAnnotationAnnotationValue) {
            _matched = true;
            final Function1<JvmAnnotationReference, AnnotationReference> _function = (JvmAnnotationReference it) -> {
                return this.toAnnotationReference(it);
            };
            List<AnnotationReference> _map = ListExtensions.<JvmAnnotationReference, AnnotationReference>map(((JvmAnnotationAnnotationValue) value).getValues(), _function);
            _switchResult = Pair.<List<?>, Class<?>>of(_map, AnnotationReference.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmStringAnnotationValue) {
            _matched = true;
            EList<String> _values = ((JvmStringAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, String.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmBooleanAnnotationValue) {
            _matched = true;
            EList<Boolean> _values = ((JvmBooleanAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, boolean.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmIntAnnotationValue) {
            _matched = true;
            EList<Integer> _values = ((JvmIntAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, int.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmByteAnnotationValue) {
            _matched = true;
            EList<Byte> _values = ((JvmByteAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, byte.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmCharAnnotationValue) {
            _matched = true;
            EList<Character> _values = ((JvmCharAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, char.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmDoubleAnnotationValue) {
            _matched = true;
            EList<Double> _values = ((JvmDoubleAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, double.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmEnumAnnotationValue) {
            _matched = true;
            final Function1<JvmEnumerationLiteral, NamedElement> _function = (JvmEnumerationLiteral it) -> {
                return this.toNamedElement(it);
            };
            List<NamedElement> _map = ListExtensions.<JvmEnumerationLiteral, NamedElement>map(((JvmEnumAnnotationValue) value).getValues(), _function);
            _switchResult = Pair.<List<?>, Class<?>>of(_map, EnumerationValueDeclaration.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmFloatAnnotationValue) {
            _matched = true;
            EList<Float> _values = ((JvmFloatAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, float.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmLongAnnotationValue) {
            _matched = true;
            EList<Long> _values = ((JvmLongAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, long.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmShortAnnotationValue) {
            _matched = true;
            EList<Short> _values = ((JvmShortAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, short.class);
        }
    }
    if (!_matched) {
        List<Object> _emptyList = CollectionLiterals.<Object>emptyList();
        _switchResult = Pair.<List<?>, Class<?>>of(_emptyList, Object.class);
    }
    final Pair<List<?>, Class<?>> result = _switchResult;
    if (isArray) {
        return this.toArrayOfType(result.getKey(), result.getValue());
    } else {
        return IterableExtensions.head(result.getKey());
    }
}
Also used : JvmEnumAnnotationValue(org.eclipse.xtext.common.types.JvmEnumAnnotationValue) JvmByteAnnotationValue(org.eclipse.xtext.common.types.JvmByteAnnotationValue) JvmCustomAnnotationValue(org.eclipse.xtext.common.types.JvmCustomAnnotationValue) JvmLongAnnotationValue(org.eclipse.xtext.common.types.JvmLongAnnotationValue) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) JvmStringAnnotationValue(org.eclipse.xtext.common.types.JvmStringAnnotationValue) JvmFloatAnnotationValue(org.eclipse.xtext.common.types.JvmFloatAnnotationValue) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) NamedElement(org.eclipse.xtend.lib.macro.declaration.NamedElement) EnumerationValueDeclaration(org.eclipse.xtend.lib.macro.declaration.EnumerationValueDeclaration) JvmTypeAnnotationValue(org.eclipse.xtext.common.types.JvmTypeAnnotationValue) JvmBooleanAnnotationValue(org.eclipse.xtext.common.types.JvmBooleanAnnotationValue) JvmIntAnnotationValue(org.eclipse.xtext.common.types.JvmIntAnnotationValue) JvmCharAnnotationValue(org.eclipse.xtext.common.types.JvmCharAnnotationValue) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmShortAnnotationValue(org.eclipse.xtext.common.types.JvmShortAnnotationValue) JvmDoubleAnnotationValue(org.eclipse.xtext.common.types.JvmDoubleAnnotationValue) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) XExpression(org.eclipse.xtext.xbase.XExpression) JvmAnnotationAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue)

Aggregations

JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)194 Test (org.junit.Test)98 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)68 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)47 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)46 JvmType (org.eclipse.xtext.common.types.JvmType)43 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)41 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)27 XExpression (org.eclipse.xtext.xbase.XExpression)22 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)18 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)18 EObject (org.eclipse.emf.ecore.EObject)17 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)16 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)14 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 JvmField (org.eclipse.xtext.common.types.JvmField)12 JvmWildcardTypeReference (org.eclipse.xtext.common.types.JvmWildcardTypeReference)12