Search in sources :

Example 76 with JvmTypeReference

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

the class DispatchHelper method compare.

protected int compare(JvmOperation o1, JvmOperation o2) {
    int params = o1.getParameters().size();
    for (int i = 0; i < params; i++) {
        final JvmTypeReference p1 = o1.getParameters().get(i).getParameterType();
        final JvmTypeReference p2 = o2.getParameters().get(i).getParameterType();
        int distance1 = p1 == null ? Integer.MAX_VALUE : getMaxDistanceToObject(p1);
        int distance2 = p2 == null ? Integer.MAX_VALUE : getMaxDistanceToObject(p2);
        if (distance1 != distance2) {
            return distance2 - distance1;
        }
    }
    String identifier1 = o1.getIdentifier();
    String parameterTypes1 = identifier1.substring(identifier1.indexOf('('));
    String identifier2 = o2.getIdentifier();
    String parameterTypes2 = identifier2.substring(identifier2.indexOf('('));
    return parameterTypes1.compareTo(parameterTypes2);
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference)

Example 77 with JvmTypeReference

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

the class XtendJvmModelInferrer method computeFieldName.

/* @Nullable */
protected String computeFieldName(XtendField field) {
    if (field.getName() != null)
        return field.getName();
    JvmTypeReference type = field.getType();
    String name = null;
    if (type != null) {
        while (type instanceof JvmGenericArrayTypeReference) {
            type = ((JvmGenericArrayTypeReference) type).getComponentType();
        }
        if (type instanceof JvmParameterizedTypeReference) {
            List<INode> nodes = NodeModelUtils.findNodesForFeature(type, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
            if (!nodes.isEmpty()) {
                String typeName = nodes.get(0).getText().trim();
                int lastDot = typeName.lastIndexOf('.');
                if (lastDot != -1) {
                    typeName = typeName.substring(lastDot + 1);
                }
                name = "_" + Strings.toFirstLower(typeName);
            }
        }
    }
    return name;
}
Also used : JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) INode(org.eclipse.xtext.nodemodel.INode) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 78 with JvmTypeReference

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

the class XtendJvmModelInferrer method transform.

protected void transform(XtendConstructor source, JvmGenericType container) {
    JvmConstructor constructor = typesFactory.createJvmConstructor();
    container.getMembers().add(constructor);
    associator.associatePrimary(source, constructor);
    JvmVisibility visibility = source.getVisibility();
    constructor.setSimpleName(container.getSimpleName());
    constructor.setVisibility(visibility);
    for (XtendParameter parameter : source.getParameters()) {
        translateParameter(constructor, parameter);
    }
    copyAndFixTypeParameters(source.getTypeParameters(), constructor);
    for (JvmTypeReference exception : source.getExceptions()) {
        constructor.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
    }
    translateAnnotationsTo(source.getAnnotations(), constructor);
    setBody(constructor, source.getExpression());
    jvmTypesBuilder.copyDocumentationTo(source, constructor);
}
Also used : XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmVisibility(org.eclipse.xtext.common.types.JvmVisibility)

Example 79 with JvmTypeReference

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

the class XtendJvmModelInferrer method transform.

protected void transform(XtendFunction source, JvmGenericType container, boolean allowDispatch) {
    JvmOperation operation = typesFactory.createJvmOperation();
    operation.setAbstract(source.isAbstract());
    operation.setNative(source.isNative());
    operation.setSynchronized(source.isSynchonized());
    operation.setStrictFloatingPoint(source.isStrictFloatingPoint());
    if (!source.isAbstract())
        operation.setFinal(source.isFinal());
    container.getMembers().add(operation);
    associator.associatePrimary(source, operation);
    String sourceName = source.getName();
    JvmVisibility visibility = source.getVisibility();
    if (allowDispatch && source.isDispatch()) {
        if (source.getDeclaredVisibility() == null)
            visibility = JvmVisibility.PROTECTED;
        sourceName = "_" + sourceName;
    }
    operation.setSimpleName(sourceName);
    operation.setVisibility(visibility);
    operation.setStatic(source.isStatic());
    if (!operation.isAbstract() && !operation.isStatic() && container.isInterface())
        operation.setDefault(true);
    for (XtendParameter parameter : source.getParameters()) {
        translateParameter(operation, parameter);
    }
    XExpression expression = source.getExpression();
    CreateExtensionInfo createExtensionInfo = source.getCreateExtensionInfo();
    JvmTypeReference returnType = null;
    if (source.getReturnType() != null) {
        returnType = jvmTypesBuilder.cloneWithProxies(source.getReturnType());
    } else if (createExtensionInfo != null) {
        returnType = jvmTypesBuilder.inferredType(createExtensionInfo.getCreateExpression());
    } else if (expression != null) {
        returnType = jvmTypesBuilder.inferredType(expression);
    } else {
        returnType = jvmTypesBuilder.inferredType();
    }
    operation.setReturnType(returnType);
    copyAndFixTypeParameters(source.getTypeParameters(), operation);
    for (JvmTypeReference exception : source.getExceptions()) {
        operation.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
    }
    translateAnnotationsTo(source.getAnnotations(), operation);
    if (source.isOverride() && generatorConfig.getJavaSourceVersion().isAtLeast(JAVA6) && !containsAnnotation(operation, Override.class) && typeReferences.findDeclaredType(Override.class, source) != null) {
        operation.getAnnotations().add(_annotationTypesBuilder.annotationRef(Override.class));
    }
    if (createExtensionInfo != null) {
        transformCreateExtension(source, createExtensionInfo, container, operation, returnType);
    } else {
        setBody(operation, expression);
    }
    jvmTypesBuilder.copyDocumentationTo(source, operation);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmVisibility(org.eclipse.xtext.common.types.JvmVisibility) XExpression(org.eclipse.xtext.xbase.XExpression) CreateExtensionInfo(org.eclipse.xtend.core.xtend.CreateExtensionInfo)

Example 80 with JvmTypeReference

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

the class XtendClassImpl method basicSetExtends.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetExtends(JvmTypeReference newExtends, NotificationChain msgs) {
    JvmTypeReference oldExtends = extends_;
    extends_ = newExtends;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtendPackage.XTEND_CLASS__EXTENDS, oldExtends, newExtends);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)130 Test (org.junit.Test)58 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)46 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)38 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 JvmType (org.eclipse.xtext.common.types.JvmType)28 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)23 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)18 XExpression (org.eclipse.xtext.xbase.XExpression)18 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)17 EObject (org.eclipse.emf.ecore.EObject)15 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)12 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)12 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)8