Search in sources :

Example 1 with JvmFormalParameter

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

the class Oven method fireproof.

public void fireproof(final String input) throws Exception {
    try {
        final EObject file = this._parseHelper.parse(input);
        final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(file);
        Assert.assertNotNull(resolvedTypes);
        if ((file != null)) {
            Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(file.eAllContents());
            for (final EObject content : _iterable) {
                boolean _matched = false;
                if (content instanceof XAbstractFeatureCall) {
                    _matched = true;
                    this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                    XExpression _implicitReceiver = ((XAbstractFeatureCall) content).getImplicitReceiver();
                    boolean _tripleNotEquals = (_implicitReceiver != null);
                    if (_tripleNotEquals) {
                        this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitReceiver(), resolvedTypes);
                    }
                    XExpression _implicitFirstArgument = ((XAbstractFeatureCall) content).getImplicitFirstArgument();
                    boolean _tripleNotEquals_1 = (_implicitFirstArgument != null);
                    if (_tripleNotEquals_1) {
                        this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitFirstArgument(), resolvedTypes);
                    }
                }
                if (!_matched) {
                    if (content instanceof XClosure) {
                        _matched = true;
                        this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                        final Consumer<JvmFormalParameter> _function = (JvmFormalParameter it) -> {
                            this.assertIdentifiableTypeIsResolved(it, resolvedTypes);
                        };
                        ((XClosure) content).getImplicitFormalParameters().forEach(_function);
                    }
                }
                if (!_matched) {
                    if (content instanceof XExpression) {
                        _matched = true;
                        this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                    }
                }
                if (!_matched) {
                    if (content instanceof JvmIdentifiableElement) {
                        _matched = true;
                        this.assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
                    }
                }
            }
        }
    } catch (final Throwable _t) {
        if (_t instanceof Throwable) {
            final Throwable e = (Throwable) _t;
            String _message = e.getMessage();
            final ComparisonFailure error = new ComparisonFailure(_message, input, "");
            error.setStackTrace(e.getStackTrace());
            throw error;
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XClosure(org.eclipse.xtext.xbase.XClosure) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) ComparisonFailure(org.junit.ComparisonFailure) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 2 with JvmFormalParameter

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

the class JdtBasedTypeFactory method setParameterNamesAndAnnotations.

private void setParameterNamesAndAnnotations(IMethodBinding method, ITypeBinding[] parameterTypes, String[] parameterNames, JvmExecutable result) {
    InternalEList<JvmFormalParameter> parameters = (InternalEList<JvmFormalParameter>) result.getParameters();
    for (int i = 0; i < parameterTypes.length; i++) {
        IAnnotationBinding[] parameterAnnotations;
        try {
            parameterAnnotations = method.getParameterAnnotations(i);
        } catch (AbortCompilation aborted) {
            parameterAnnotations = null;
        }
        ITypeBinding parameterType = parameterTypes[i];
        String parameterName = parameterNames == null ? null : /* lazy */
        i < parameterNames.length ? parameterNames[i] : "arg" + i;
        JvmFormalParameter formalParameter = createFormalParameter(parameterType, parameterName, parameterAnnotations);
        parameters.addUnique(formalParameter);
    }
}
Also used : JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) IAnnotationBinding(org.eclipse.jdt.core.dom.IAnnotationBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) AbortCompilation(org.eclipse.jdt.internal.compiler.problem.AbortCompilation) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 3 with JvmFormalParameter

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

the class AbstractTypeProviderTest method testTypeParamEndsWithDollar_02.

@Test
public void testTypeParamEndsWithDollar_02() {
    String typeName = "org.eclipse.xtext.common.types.testSetups.TypeParamEndsWithDollar";
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation function = (JvmOperation) type.findAllFeaturesByName("function2").iterator().next();
    JvmFormalParameter parameter = function.getParameters().get(0);
    JvmType parameterType = parameter.getParameterType().getType();
    assertEquals(function.getTypeParameters().get(0), parameterType);
    JvmFormalParameter secondParameter = function.getParameters().get(1);
    JvmType secondParameterType = secondParameter.getParameterType().getType();
    assertEquals(type.getTypeParameters().get(0), secondParameterType);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 4 with JvmFormalParameter

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

the class AbstractTypeProviderTest method test_twoListParamsNoResult_02.

@Test
public void test_twoListParamsNoResult_02() {
    JvmOperation twoListParamsNoResult = getMethodFromParameterizedMethods("twoListParamsNoResult(java.util.List,java.util.List)");
    JvmFormalParameter firstParam = twoListParamsNoResult.getParameters().get(0);
    JvmTypeReference paramType = firstParam.getParameterType();
    assertNotNull(paramType);
    assertFalse(paramType.getType().eIsProxy());
    assertEquals("java.util.List<T>", paramType.getIdentifier());
    assertTrue(paramType instanceof JvmParameterizedTypeReference);
    JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType;
    JvmType rawType = parameterized.getType();
    assertFalse(rawType.eIsProxy());
    assertEquals("java.util.List", rawType.getIdentifier());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmType(org.eclipse.xtext.common.types.JvmType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Test(org.junit.Test)

Example 5 with JvmFormalParameter

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

the class AbstractTypeProviderTest method testTypeParamEndsWithDollar_01.

@Test
public void testTypeParamEndsWithDollar_01() {
    String typeName = "org.eclipse.xtext.common.types.testSetups.TypeParamEndsWithDollar";
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation function = (JvmOperation) type.findAllFeaturesByName("function1").iterator().next();
    JvmFormalParameter parameter = function.getParameters().get(0);
    JvmType parameterType = parameter.getParameterType().getType();
    assertEquals(function.getTypeParameters().get(0), parameterType);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Aggregations

JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)81 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)35 Test (org.junit.Test)30 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)19 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)15 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)15 JvmType (org.eclipse.xtext.common.types.JvmType)13 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)13 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)11 EObject (org.eclipse.emf.ecore.EObject)10 XClosure (org.eclipse.xtext.xbase.XClosure)10 XExpression (org.eclipse.xtext.xbase.XExpression)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)9 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)9 JvmMember (org.eclipse.xtext.common.types.JvmMember)8 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)8 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)7 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)7 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)6