Search in sources :

Example 21 with JvmConstructor

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

the class XtendHoverSignatureProvider method _signature.

protected String _signature(XtendConstructor constructor, boolean typeAtEnd) {
    JvmConstructor inferredConstructor = associations.getInferredConstructor(constructor);
    XtendClass xtendClazz = EcoreUtil2.getContainerOfType(constructor, XtendClass.class);
    return xtendClazz.getName() + hoverUiStrings.parameters(inferredConstructor) + getThrowsDeclaration(inferredConstructor);
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor)

Example 22 with JvmConstructor

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

the class XtendHoverSignatureProvider method getSimpleSignature.

@Override
protected String getSimpleSignature(EObject container) {
    if (container instanceof XtendFunction) {
        XtendFunction function = (XtendFunction) container;
        JvmOperation inferredOperation = associations.getDirectlyInferredOperation(function);
        if (inferredOperation != null) {
            return function.getName() + uiStrings.parameters(inferredOperation);
        }
    } else if (container instanceof XtendConstructor) {
        XtendConstructor constructor = (XtendConstructor) container;
        XtendClass xtendClazz = EcoreUtil2.getContainerOfType(constructor, XtendClass.class);
        JvmConstructor inferredConstructor = associations.getInferredConstructor(constructor);
        return xtendClazz.getName() + " " + uiStrings.parameters(inferredConstructor);
    }
    return super.getSimpleSignature(container);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor)

Example 23 with JvmConstructor

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

the class DependentElementsCalculatorTests method testPolymorphicDispatch.

@Test
public void testPolymorphicDispatch() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def dispatch foo(Number it) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def dispatch foo(String it) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile fooFile = this.testHelper.xtendFile("Foo", _builder.toString());
        IResourcesSetupUtil.waitForBuild();
        XtendTypeDeclaration _get = fooFile.getXtendTypes().get(0);
        final XtendClass fooClass = ((XtendClass) _get);
        final XtendMember fooMethod1 = fooClass.getMembers().get(1);
        NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
        final Iterable<URI> dependentElementURIs = this.dependentElementsCalculator.getDependentElementURIs(fooMethod1, _nullProgressMonitor);
        Assert.assertEquals(5, IterableExtensions.size(dependentElementURIs));
        EList<XtendMember> _members = fooClass.getMembers();
        EList<JvmMember> _members_1 = this.associations.getInferredType(fooClass).getMembers();
        final Function1<EObject, Boolean> _function = (EObject it) -> {
            return Boolean.valueOf((!(it instanceof JvmConstructor)));
        };
        final Consumer<EObject> _function_1 = (EObject it) -> {
            final Function1<URI, Boolean> _function_2 = (URI element) -> {
                URI _uRI = EcoreUtil.getURI(it);
                return Boolean.valueOf(Objects.equal(element, _uRI));
            };
            Assert.assertTrue(it.toString(), IterableExtensions.<URI>exists(dependentElementURIs, _function_2));
        };
        IterableExtensions.<EObject>toList(IterableExtensions.<EObject>filter(Iterables.<EObject>concat(_members, _members_1), _function)).forEach(_function_1);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) URI(org.eclipse.emf.common.util.URI) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmMember(org.eclipse.xtext.common.types.JvmMember) Test(org.junit.Test)

Example 24 with JvmConstructor

use of org.eclipse.xtext.common.types.JvmConstructor 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 25 with JvmConstructor

use of org.eclipse.xtext.common.types.JvmConstructor 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)

Aggregations

JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)42 Test (org.junit.Test)21 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)19 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)16 EObject (org.eclipse.emf.ecore.EObject)13 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 JvmMember (org.eclipse.xtext.common.types.JvmMember)8 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)6 XtextResource (org.eclipse.xtext.resource.XtextResource)5 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)4 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)3 MockAcceptor (org.eclipse.xtend.ide.tests.findrefs.FindReferencesTestUtil.MockAcceptor)3 JvmField (org.eclipse.xtext.common.types.JvmField)3 URI (org.eclipse.emf.common.util.URI)2 JvmConstructorDeclarationImpl (org.eclipse.xtend.core.macro.declaration.JvmConstructorDeclarationImpl)2