Search in sources :

Example 51 with LightweightTypeReference

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

the class CreateMemberQuickfixes method getResolvedArgumentTypes.

protected List<LightweightTypeReference> getResolvedArgumentTypes(EObject context, JvmIdentifiableElement logicalContainer, List<XExpression> arguments) {
    List<LightweightTypeReference> argumentTypes = newArrayList();
    IResolvedTypes resolvedTypes = typeResolver.resolveTypes(context);
    for (XExpression argument : arguments) {
        LightweightTypeReference resolved = resolvedTypes.getActualType(argument);
        if (resolved == null) {
            StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context);
            argumentTypes.add(owner.newReferenceToObject());
        } else {
            LocalTypeSubstitutor substitutor = new LocalTypeSubstitutor(resolved.getOwner(), logicalContainer);
            argumentTypes.add(substitutor.withoutLocalTypes(resolved));
        }
    }
    return argumentTypes;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XExpression(org.eclipse.xtext.xbase.XExpression) LocalTypeSubstitutor(org.eclipse.xtext.xbase.typesystem.util.LocalTypeSubstitutor) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 52 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference 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 53 with LightweightTypeReference

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

the class CreateMemberQuickfixes method newMethodQuickfix.

protected void newMethodQuickfix(JvmDeclaredType containerType, String name, /* @Nullable */
LightweightTypeReference returnType, List<LightweightTypeReference> parameterTypes, boolean isStatic, boolean isAbstract, boolean isExtension, boolean isLocal, XAbstractFeatureCall call, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
    AbstractMethodBuilder methodBuilder = codeBuilderFactory.createMethodBuilder(containerType);
    methodBuilder.setMethodName(name);
    methodBuilder.setReturnType(returnType);
    for (LightweightTypeReference parameterType : parameterTypes) methodBuilder.newParameterBuilder().setType(parameterType);
    methodBuilder.setContext(call);
    methodBuilder.setVisibility(JvmVisibility.PUBLIC);
    methodBuilder.setStaticFlag(isStatic);
    methodBuilder.setAbstractFlag(isAbstract);
    StringBuffer label = new StringBuffer("Create ");
    if (isStatic)
        label.append("static ");
    if (isExtension)
        label.append("extension ");
    label.append("method '").append(name).append("(");
    boolean isFirst = true;
    for (LightweightTypeReference parameterType : parameterTypes) {
        if (!isFirst)
            label.append(", ");
        isFirst = false;
        label.append(parameterType.getSimpleName());
    }
    label.append(")'");
    if (!isLocal)
        label.append(" in '" + containerType.getSimpleName() + "'");
    quickfixFactory.addQuickfix(methodBuilder, label.toString(), issue, issueResolutionAcceptor);
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) AbstractMethodBuilder(org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder)

Example 54 with LightweightTypeReference

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

the class CreateMemberQuickfixes method newFieldQuickfix.

protected void newFieldQuickfix(String name, XAbstractFeatureCall call, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
    JvmDeclaredType callersType = getCallersType(call);
    LightweightTypeReference receiverType = getReceiverType(call);
    LightweightTypeReference fieldType = getNewMemberType(call);
    if (callersType != null && receiverType != null && callersType == receiverType.getType())
        newFieldQuickfix(callersType, name, fieldType, isStaticAccess(call), call, issue, issueResolutionAcceptor);
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 55 with LightweightTypeReference

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

the class CreateMemberQuickfixes method newConstructorQuickfix.

protected void newConstructorQuickfix(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, JvmDeclaredType ownerType, XExpression call, List<XExpression> arguments) {
    if (ownerType != null) {
        List<LightweightTypeReference> parameterTypes = getResolvedArgumentTypes(call, logicalContainerProvider.getNearestLogicalContainer(call), arguments);
        AbstractConstructorBuilder constructorBuilder = codeBuilderFactory.createConstructorBuilder(ownerType);
        constructorBuilder.setContext(call);
        for (LightweightTypeReference parameterType : parameterTypes) constructorBuilder.newParameterBuilder().setType(parameterType);
        constructorBuilder.setVisibility(JvmVisibility.PUBLIC);
        StringBuffer label = new StringBuffer("Create constructor '");
        if (constructorBuilder.getOwnerSource() instanceof XtendClass)
            label.append("new");
        else
            label.append(ownerType.getSimpleName());
        label.append("(");
        boolean isFirst = true;
        for (LightweightTypeReference parameterType : parameterTypes) {
            if (!isFirst)
                label.append(", ");
            isFirst = false;
            label.append(parameterType.getSimpleName());
        }
        label.append(")'");
        if (getCallersType(call) != ownerType)
            label.append(" in '").append(ownerType.getSimpleName()).append("'");
        quickfixFactory.addQuickfix(constructorBuilder, label.toString(), issue, issueResolutionAcceptor);
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) AbstractConstructorBuilder(org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder) XtendClass(org.eclipse.xtend.core.xtend.XtendClass)

Aggregations

LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)83 Test (org.junit.Test)28 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)23 XExpression (org.eclipse.xtext.xbase.XExpression)22 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)20 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)19 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)16 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)13 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)10 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)10 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)10 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)9 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)9 JvmType (org.eclipse.xtext.common.types.JvmType)8 ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)8 EObject (org.eclipse.emf.ecore.EObject)7 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)7 StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)7 RichString (org.eclipse.xtend.core.xtend.RichString)6 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)6