Search in sources :

Example 11 with StandardTypeReferenceOwner

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

the class CreateMemberQuickfixes method getReceiverType.

/* @Nullable */
protected LightweightTypeReference getReceiverType(XAbstractFeatureCall featureCall) {
    XExpression actualReceiver = featureCall.getActualReceiver();
    ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, featureCall);
    if (actualReceiver == null) {
        JvmDeclaredType callersType = getCallersType(featureCall);
        if (callersType != null)
            return owner.newParameterizedTypeReference(callersType);
    } else if (actualReceiver instanceof XAbstractFeatureCall && ((XAbstractFeatureCall) actualReceiver).isTypeLiteral()) {
        JvmType type = (JvmType) ((XAbstractFeatureCall) actualReceiver).getFeature();
        ParameterizedTypeReference reference = owner.newParameterizedTypeReference(type);
        return reference;
    } else {
        LightweightTypeReference typeRef = typeResolver.resolveTypes(featureCall).getActualType(actualReceiver);
        if (typeRef != null && typeRef.getType() instanceof JvmDeclaredType)
            return typeRef;
    }
    return null;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) ParameterizedTypeReference(org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall)

Example 12 with StandardTypeReferenceOwner

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

the class ExtractMethodRefactoring method calculateReturnType.

protected LightweightTypeReference calculateReturnType(IResolvedTypes resolvedTypes) {
    List<LightweightTypeReference> returnTypes = newArrayList();
    for (XExpression expression : expressions) {
        LightweightTypeReference expressionReturnType = resolvedTypes.getReturnType(expression, expression != lastExpression);
        if (expressionReturnType != null)
            returnTypes.add(expressionReturnType);
    }
    StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(typeComputationServices, xtendClass);
    return typeComputationServices.getTypeConformanceComputer().getCommonSuperType(returnTypes, owner);
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XExpression(org.eclipse.xtext.xbase.XExpression) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 13 with StandardTypeReferenceOwner

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

the class SuperMemberImplementorTest method getContextType.

protected LightweightTypeReference getContextType() {
    JvmGenericType inferredType = associations.getInferredType(xtendClass);
    ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, inferredType);
    ParameterizedTypeReference contextType = owner.newParameterizedTypeReference(inferredType);
    for (JvmTypeParameter typeParamter : inferredType.getTypeParameters()) {
        contextType.addTypeArgument(owner.newParameterizedTypeReference(typeParamter));
    }
    return contextType;
}
Also used : ParameterizedTypeReference(org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 14 with StandardTypeReferenceOwner

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

the class ReplacingAppendableTest method insertListField.

protected XtextDocument insertListField(final String model, final String fieldName) throws Exception {
    final int cursorPosition = model.indexOf('|');
    String actualModel = model.replace("|", " ");
    final XtendFile file = testHelper.xtendFile("Foo", actualModel);
    final XtextDocument document = documentProvider.get();
    document.set(actualModel);
    XtextResource xtextResource = (XtextResource) file.eResource();
    document.setInput(xtextResource);
    final EObject context = eObjectAtOffsetHelper.resolveElementAt(xtextResource, cursorPosition);
    document.modify(new IUnitOfWork.Void<XtextResource>() {

        @Override
        public void process(XtextResource state) throws Exception {
            ReplacingAppendable a = appendableFactory.create(document, state, cursorPosition, 1);
            ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context);
            LightweightTypeReference typeRef = owner.toLightweightTypeReference(services.getTypeReferences().getTypeForName(List.class, context, typesFactory.createJvmWildcardTypeReference()));
            a.append(typeRef);
            a.append(" ").append(fieldName);
            a.commitChanges();
        }
    });
    return document;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) EObject(org.eclipse.emf.ecore.EObject) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 15 with StandardTypeReferenceOwner

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

the class AbstractOverloadedInstanceMethodTest method linksTo.

protected void linksTo(final String invocation, final String method) {
    try {
        final XtendFile file = this.file(this.inMethodBody(invocation), false);
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        final XtendClass c = ((XtendClass) _head);
        XtendMember _head_1 = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head_1);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _last = IterableExtensions.<XExpression>last(body.getExpressions());
        final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
        JvmIdentifiableElement _feature = featureCall.getFeature();
        final JvmOperation operation = ((JvmOperation) _feature);
        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, file);
        final ParameterizedTypeReference declaration = owner.newParameterizedTypeReference(operation.getDeclaringType());
        final BottomResolvedOperation resolved = new BottomResolvedOperation(operation, declaration, this.overrideTester);
        Assert.assertEquals(method, resolved.getSimpleSignature());
        Assert.assertTrue(IterableExtensions.join(file.eResource().getErrors(), "\n"), file.eResource().getErrors().isEmpty());
        Assert.assertNotNull(featureCall.getImplicitReceiver());
        Assert.assertNull(featureCall.getImplicitFirstArgument());
    } 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) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) ParameterizedTypeReference(org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) BottomResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Aggregations

StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)22 ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)8 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)8 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)5 XExpression (org.eclipse.xtext.xbase.XExpression)5 ParameterizedTypeReference (org.eclipse.xtext.xbase.typesystem.references.ParameterizedTypeReference)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 CommonTypeComputationServices (org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices)4 Injector (com.google.inject.Injector)3 List (java.util.List)3 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)3 JvmType (org.eclipse.xtext.common.types.JvmType)3 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)3 ClasspathTypeProvider (org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)3 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)3 XbaseStandaloneSetup (org.eclipse.xtext.xbase.XbaseStandaloneSetup)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)2