Search in sources :

Example 36 with JvmDeclaredType

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

the class CreateMemberQuickfixes method newMethodQuickfixes.

protected void newMethodQuickfixes(String newMemberName, XAbstractFeatureCall call, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
    JvmDeclaredType callersType = getCallersType(call);
    LightweightTypeReference receiverType = getReceiverType(call);
    LightweightTypeReference returnType = getNewMemberType(call);
    if (callersType == null || receiverType == null)
        return;
    List<LightweightTypeReference> argumentTypes = getResolvedArgumentTypes(call, logicalContainerProvider.getNearestLogicalContainer(call), call.getActualArguments());
    newMethodQuickfixes(receiverType, newMemberName, returnType, argumentTypes, call, callersType, issue, issueResolutionAcceptor);
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 37 with JvmDeclaredType

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

the class CreateMemberQuickfixes method newConstructorQuickfix.

protected void newConstructorQuickfix(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, XConstructorCall call) {
    JvmDeclaredType ownerType = call.getConstructor().getDeclaringType();
    newConstructorQuickfix(issue, issueResolutionAcceptor, ownerType, call, call.getArguments());
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 38 with JvmDeclaredType

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

the class MemberFromSuperImplementor method appendOverrideFunction.

public void appendOverrideFunction(final XtendTypeDeclaration overrider, final IResolvedOperation overriddenOperation, final ISourceAppender appendable) {
    final JvmDeclaredType inferredType = this.associations.getInferredType(overrider);
    final AbstractMethodBuilder methodBuilder = this.codeBuilderFactory.createMethodBuilder(inferredType);
    this.initializeExecutableBuilder(methodBuilder, inferredType, overriddenOperation);
    methodBuilder.setOverrideFlag(true);
    methodBuilder.setMethodName(overriddenOperation.getDeclaration().getSimpleName());
    methodBuilder.setReturnType(overriddenOperation.getResolvedReturnType());
    boolean _isSynchronized = overriddenOperation.getDeclaration().isSynchronized();
    if (_isSynchronized) {
        methodBuilder.setSynchronizedFlag(true);
    }
    boolean _isEmpty = overriddenOperation.getResolvedTypeParameters().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        final ArrayList<JvmTypeParameter> typeParameters = CollectionLiterals.<JvmTypeParameter>newArrayList();
        final Procedure2<JvmTypeParameter, Integer> _function = (JvmTypeParameter typeParam, Integer idx) -> {
            final JvmTypeParameter newTypeParam = this.typesFactory.createJvmTypeParameter();
            newTypeParam.setName(typeParam.getName());
            final Consumer<LightweightTypeReference> _function_1 = (LightweightTypeReference it) -> {
                final JvmUpperBound upperBound = this.typesFactory.createJvmUpperBound();
                upperBound.setTypeReference(it.toJavaCompliantTypeReference());
                EList<JvmTypeConstraint> _constraints = newTypeParam.getConstraints();
                _constraints.add(upperBound);
            };
            overriddenOperation.getResolvedTypeParameterConstraints((idx).intValue()).forEach(_function_1);
            typeParameters.add(newTypeParam);
        };
        IterableExtensions.<JvmTypeParameter>forEach(overriddenOperation.getResolvedTypeParameters(), _function);
        methodBuilder.setTypeParameters(typeParameters);
    }
    boolean _isAbstract = overriddenOperation.getDeclaration().isAbstract();
    boolean _not_1 = (!_isAbstract);
    if (_not_1) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("super.");
        {
            List<JvmTypeParameter> _resolvedTypeParameters = overriddenOperation.getResolvedTypeParameters();
            boolean _hasElements = false;
            for (final JvmTypeParameter typeParam : _resolvedTypeParameters) {
                if (!_hasElements) {
                    _hasElements = true;
                    _builder.append("<");
                } else {
                    _builder.appendImmediate(", ", "");
                }
                String _simpleName = typeParam.getSimpleName();
                _builder.append(_simpleName);
            }
            if (_hasElements) {
                _builder.append(">");
            }
        }
        String _simpleName_1 = overriddenOperation.getDeclaration().getSimpleName();
        _builder.append(_simpleName_1);
        _builder.append("(");
        final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it) -> {
            return it.getSimpleName();
        };
        String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(overriddenOperation.getDeclaration().getParameters(), _function_1), ", ");
        _builder.append(_join);
        _builder.append(")");
        final String body = _builder.toString();
        final Procedure1<? super ISourceAppender> superTypeRef = this.getImplementedInterface(inferredType, overriddenOperation.getDeclaration().getDeclaringType());
        final Procedure1<ISourceAppender> _function_2 = (ISourceAppender it) -> {
            if (superTypeRef != null) {
                superTypeRef.apply(it);
            }
            it.append(body);
        };
        methodBuilder.setBodyGenerator(_function_2);
    }
    boolean _isValid = methodBuilder.isValid();
    if (_isValid) {
        methodBuilder.build(appendable);
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender) JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) Consumer(java.util.function.Consumer) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) AbstractMethodBuilder(org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder)

Example 39 with JvmDeclaredType

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

the class AbstractKnownTypesScope method findNestedType.

protected JvmType findNestedType(JvmType result, int index, QualifiedName name) {
    List<String> segments = name.getSegmentCount() == 1 ? Strings.split(name.getFirstSegment(), '$') : name.getSegments();
    for (int i = 1; i < segments.size() && result instanceof JvmDeclaredType; i++) {
        JvmDeclaredType declaredType = (JvmDeclaredType) result;
        String simpleName = segments.get(i);
        // TODO handle ambiguous types
        for (JvmMember member : declaredType.findAllNestedTypesByName(simpleName)) {
            result = (JvmType) member;
            break;
        }
        if (declaredType == result) {
            return null;
        }
    }
    return result;
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 40 with JvmDeclaredType

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

the class NestedTypesScope method findNestedTypeInLocalTypeNonResolving.

/**
 * We have to be careful to keep the unresolved super type of a local type which may depend on type resolution.
 * Therefore these types are treated differently from other types.
 */
protected IEObjectDescription findNestedTypeInLocalTypeNonResolving(JvmDeclaredType localType, QualifiedName name, String firstSegment, int dollarIndex) {
    List<JvmMember> members = localType.getMembers();
    for (int i = 0; i < members.size(); i++) {
        JvmMember member = members.get(i);
        if (member instanceof JvmDeclaredType) {
            JvmDeclaredType nestedType = (JvmDeclaredType) member;
            if (firstSegment.equals(nestedType.getSimpleName())) {
                JvmType candidate = findNestedType(nestedType, 0, name);
                if (candidate != null) {
                    return toDescription(name, candidate, dollarIndex, 0);
                }
            }
        }
    }
    JvmDeclaredType superType = typeScopeProvider.getSuperTypeOfLocalTypeNonResolving(localType);
    if (superType == null) {
        return null;
    }
    return doGetSingleElement(superType, name, firstSegment, dollarIndex);
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmType(org.eclipse.xtext.common.types.JvmType)

Aggregations

JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)74 EObject (org.eclipse.emf.ecore.EObject)21 JvmType (org.eclipse.xtext.common.types.JvmType)18 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)12 JvmMember (org.eclipse.xtext.common.types.JvmMember)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 Test (org.junit.Test)8 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)7 Resource (org.eclipse.emf.ecore.resource.Resource)5 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)5 XExpression (org.eclipse.xtext.xbase.XExpression)5 List (java.util.List)4 EList (org.eclipse.emf.common.util.EList)4 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)4