Search in sources :

Example 11 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class XtendHoverSignatureProviderTest method testSignatureForXtendDefaultConstructor.

@Test
public void testSignatureForXtendDefaultConstructor() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(){");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new Foo()");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
        XtendMember _get = clazz.getMembers().get(0);
        final XtendFunction xtendFunction = ((XtendFunction) _get);
        XExpression _expression = xtendFunction.getExpression();
        XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
        final XConstructorCall constructorCall = ((XConstructorCall) _get_1);
        final String signature = this.signatureProvider.getSignature(constructorCall.getConstructor());
        Assert.assertEquals("Foo()", signature);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 12 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class XtendEObjectAtOffsetHelper method resolveCrossReferencedElement.

@Override
protected EObject resolveCrossReferencedElement(INode node) {
    EObject referencedElement = super.resolveCrossReferencedElement(node);
    EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
    if (referenceOwner instanceof XConstructorCall) {
        if (referenceOwner.eContainer() instanceof AnonymousClass) {
            AnonymousClass anon = (AnonymousClass) referenceOwner.eContainer();
            JvmGenericType superType = anonymousClassUtil.getSuperType(anon);
            if (superType != null) {
                if (referencedElement instanceof JvmGenericType)
                    return superType;
                else if (referencedElement instanceof JvmConstructor) {
                    if (superType.isInterface())
                        return superType;
                    JvmConstructor superConstructor = anonymousClassUtil.getSuperTypeConstructor(anon);
                    if (superConstructor != null)
                        return superConstructor;
                }
            }
        }
    }
    return referencedElement;
}
Also used : AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall)

Example 13 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class XtendSyntacticSequencer method emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a.

/**
 * Syntax: '('*
 */
@Override
protected void emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
    Keyword kw = grammarAccess.getXParenthesizedExpressionAccess().getLeftParenthesisKeyword_0();
    if (nodes == null) {
        if (semanticObject instanceof XIfExpression || semanticObject instanceof XTryCatchFinallyExpression) {
            EObject cnt = semanticObject.eContainer();
            if (cnt instanceof XExpression && !(cnt instanceof XBlockExpression) && !(cnt instanceof XForLoopExpression))
                acceptUnassignedKeyword(kw, kw.getValue(), null);
        }
        if (semanticObject instanceof XConstructorCall) {
            XConstructorCall call = (XConstructorCall) semanticObject;
            if (!call.isExplicitConstructorCall() && call.getArguments().isEmpty()) {
                acceptUnassignedKeyword(kw, kw.getValue(), null);
            }
        }
    }
    acceptNodes(transition, nodes);
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XIfExpression(org.eclipse.xtext.xbase.XIfExpression) Keyword(org.eclipse.xtext.Keyword) EObject(org.eclipse.emf.ecore.EObject) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) XTryCatchFinallyExpression(org.eclipse.xtext.xbase.XTryCatchFinallyExpression) XForLoopExpression(org.eclipse.xtext.xbase.XForLoopExpression)

Example 14 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class XtendReentrantTypeResolver method doPrepareLocalTypes.

protected void doPrepareLocalTypes(final ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmFeature container, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
    List<JvmGenericType> localClasses = container.getLocalClasses();
    for (final JvmGenericType localClass : localClasses) {
        JvmTypeReference superType = localClass.getSuperTypes().get(0);
        final IFeatureScopeSession nestedSession = featureScopeSession;
        if (InferredTypeIndicator.isInferred(superType)) {
            final XComputedTypeReference casted = (XComputedTypeReference) superType;
            InferredTypeIndicator typeProvider = (InferredTypeIndicator) casted.getTypeProvider();
            final AnonymousClass anonymousClass = (AnonymousClass) typeProvider.getExpression();
            XConstructorCall constructorCall = anonymousClass.getConstructorCall();
            IScope typeScope = featureScopeSession.getScope(constructorCall, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, resolvedTypes);
            final JvmDeclaredType type = anonymousClassUtil.getSuperTypeNonResolving(anonymousClass, typeScope);
            if (type == null) {
                JvmUnknownTypeReference superTypeReference = TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
                requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {

                    @Override
                    public void accept(JvmTypeReference capturingTypeReference) {
                        casted.setEquivalent(capturingTypeReference);
                        inferAnonymousClassConstructor(anonymousClass, localClass);
                    }
                });
            } else {
                final JvmParameterizedTypeReference superTypeReference = createSuperTypeReference(type, constructorCall);
                requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {

                    @Override
                    @SuppressWarnings("deprecation")
                    public void accept(JvmTypeReference capturingTypeReference) {
                        casted.setEquivalent(capturingTypeReference);
                        IFeatureScopeSession mySession = addThisAndSuper(nestedSession, resolvedTypes.getReferenceOwner(), localClass, superTypeReference, false);
                        if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE && ((JvmGenericType) type).isInterface()) {
                            localClass.getSuperTypes().add(0, typesBuilder.newTypeRef(localClass, Object.class));
                            inferAnonymousClassConstructor(anonymousClass, localClass);
                        } else {
                            for (JvmMember superMember : type.getMembers()) {
                                if (superMember instanceof JvmConstructor) {
                                    JvmConstructor superTypeConstructor = (JvmConstructor) superMember;
                                    boolean visible = mySession.isVisible(superTypeConstructor);
                                    inferAnonymousClassConstructor(anonymousClass, localClass, superTypeConstructor, visible);
                                }
                            }
                        }
                    }
                });
            }
        }
    }
}
Also used : IFeatureScopeSession(org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmUnknownTypeReference(org.eclipse.xtext.common.types.JvmUnknownTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) InferredTypeIndicator(org.eclipse.xtext.xbase.typesystem.InferredTypeIndicator) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) IScope(org.eclipse.xtext.scoping.IScope) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Example 15 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class XtendCompiler method _toJavaExpression.

protected void _toJavaExpression(AnonymousClass anonymousClass, ITreeAppendable b) {
    String varName = getReferenceName(anonymousClass, b);
    if (varName != null) {
        b.trace(anonymousClass, false).append(varName);
    } else {
        XConstructorCall constructorCall = anonymousClass.getConstructorCall();
        constructorCallToJavaExpression(constructorCall, b);
        JvmDeclaredType declaringType = constructorCall.getConstructor().getDeclaringType();
        compileAnonymousClassBody(anonymousClass, declaringType, b);
    }
}
Also used : XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) RichString(org.eclipse.xtend.core.xtend.RichString)

Aggregations

XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)24 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)12 Test (org.junit.Test)11 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)9 XExpression (org.eclipse.xtext.xbase.XExpression)9 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)8 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)8 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)7 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)6 EObject (org.eclipse.emf.ecore.EObject)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)5 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)3 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)3 RichString (org.eclipse.xtend.core.xtend.RichString)2 XtendField (org.eclipse.xtend.core.xtend.XtendField)2 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)2 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)2