Search in sources :

Example 1 with InternalEList

use of org.eclipse.emf.ecore.util.InternalEList in project xtext-eclipse by eclipse.

the class JdtBasedTypeFactory method createTypeParameter.

protected JvmTypeParameter createTypeParameter(ITypeBinding parameter, JvmMember container) {
    resolveTypeParams.start();
    JvmTypeParameter result = TypesFactory.eINSTANCE.createJvmTypeParameter();
    result.setName(parameter.getName());
    InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>) result.getConstraints();
    ITypeBinding[] typeBounds = parameter.getTypeBounds();
    if (typeBounds.length != 0) {
        for (ITypeBinding bound : typeBounds) {
            JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
            upperBound.setTypeReference(createTypeReference(bound));
            constraints.addUnique(upperBound);
        }
    } else {
        JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
        upperBound.setTypeReference(createObjectClassReference());
        constraints.addUnique(upperBound);
    }
    resolveTypeParams.stop();
    return result;
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 2 with InternalEList

use of org.eclipse.emf.ecore.util.InternalEList in project xtext-eclipse by eclipse.

the class JdtBasedTypeFactory method setSuperTypes.

/**
 * @since 2.4
 */
protected void setSuperTypes(ITypeBinding binding, String qualifiedName, JvmDeclaredType result) {
    ITypeBinding superclass = binding.getSuperclass();
    InternalEList<JvmTypeReference> superTypes = (InternalEList<JvmTypeReference>) result.getSuperTypes();
    if (superclass != null) {
        superTypes.addUnique(createTypeReference(superclass));
    }
    for (ITypeBinding intf : binding.getInterfaces()) {
        superTypes.addUnique(createTypeReference(intf));
    }
    if (superTypes.isEmpty() && !OBJECT_CLASS_NAME.equals(qualifiedName)) {
        superTypes.addUnique(createObjectClassReference());
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList)

Example 3 with InternalEList

use of org.eclipse.emf.ecore.util.InternalEList in project xtext-eclipse by eclipse.

the class JdtBasedTypeFactory method createType.

/**
 * @since 2.4
 */
protected JvmDeclaredType createType(ITypeBinding typeBinding, String handleIdentifier, List<String> path, StringBuilder fqn) {
    if (typeBinding.isAnonymous() || typeBinding.isSynthetic())
        throw new IllegalStateException("Cannot create type for anonymous or synthetic classes");
    // Creates the right type of instance based on the type of binding.
    // 
    JvmGenericType jvmGenericType;
    JvmDeclaredType result;
    if (typeBinding.isAnnotation()) {
        jvmGenericType = null;
        result = TypesFactory.eINSTANCE.createJvmAnnotationType();
    } else if (typeBinding.isEnum()) {
        jvmGenericType = null;
        result = TypesFactory.eINSTANCE.createJvmEnumerationType();
    } else {
        result = jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
        jvmGenericType.setInterface(typeBinding.isInterface());
    }
    // Populate the information computed from the modifiers.
    // 
    int modifiers = typeBinding.getModifiers();
    setTypeModifiers(result, modifiers);
    result.setDeprecated(typeBinding.isDeprecated());
    setVisibility(result, modifiers);
    // Determine the simple name and compose the fully qualified name and path, remembering the fqn length and path size so we can reset them.
    // 
    String simpleName = typeBinding.getName();
    fqn.append(simpleName);
    int length = fqn.length();
    int size = path.size();
    path.add(simpleName);
    String qualifiedName = fqn.toString();
    result.internalSetIdentifier(qualifiedName);
    result.setSimpleName(simpleName);
    // Traverse the nested types using '$' as the qualified name separator.
    // 
    fqn.append('$');
    createNestedTypes(typeBinding, result, handleIdentifier, path, fqn);
    // Traverse the methods using '.'as the qualifed name separator.
    // 
    fqn.setLength(length);
    fqn.append('.');
    createMethods(typeBinding, handleIdentifier, path, fqn, result);
    createFields(typeBinding, fqn, result);
    // Set the super types.
    // 
    setSuperTypes(typeBinding, qualifiedName, result);
    // 
    if (jvmGenericType != null) {
        ITypeBinding[] typeParameterBindings = typeBinding.getTypeParameters();
        if (typeParameterBindings.length > 0) {
            InternalEList<JvmTypeParameter> typeParameters = (InternalEList<JvmTypeParameter>) jvmGenericType.getTypeParameters();
            for (ITypeBinding variable : typeParameterBindings) {
                typeParameters.addUnique(createTypeParameter(variable, result));
            }
        }
    }
    // Populate the annotation values.
    // 
    createAnnotationValues(typeBinding, result);
    // Restore the path.
    // 
    path.remove(size);
    return result;
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 4 with InternalEList

use of org.eclipse.emf.ecore.util.InternalEList in project xtext-eclipse by eclipse.

the class JdtBasedTypeFactory method enhanceExecutable.

/**
 * @since 2.4
 */
protected void enhanceExecutable(StringBuilder fqn, String handleIdentifier, String[] path, JvmExecutable result, IMethodBinding method) {
    String name = method.getName();
    fqn.append(name);
    fqn.append('(');
    ITypeBinding[] parameterTypes = method.getParameterTypes();
    for (int i = 0; i < parameterTypes.length; i++) {
        if (i != 0)
            fqn.append(',');
        fqn.append(getQualifiedName(parameterTypes[i]));
    }
    fqn.append(')');
    result.internalSetIdentifier(fqn.toString());
    result.setSimpleName(name);
    setVisibility(result, method.getModifiers());
    result.setDeprecated(method.isDeprecated());
    if (parameterTypes.length > 0) {
        result.setVarArgs(method.isVarargs());
        String[] parameterNames = null;
        // If the method is derived from source, we can efficiently determine the parameter names now.
        // 
        ITypeBinding declaringClass = method.getDeclaringClass();
        if (declaringClass.isFromSource()) {
            parameterNames = getParameterNamesFromSource(fqn, method);
        } else {
            // Use the key to determine the signature for the method.
            // 
            SegmentSequence signaturex = getSignatureAsSegmentSequence(method);
            ParameterNameInitializer initializer = jdtCompliance.createParameterNameInitializer(method, workingCopyOwner, result, handleIdentifier, path, name, signaturex);
            ((JvmExecutableImplCustom) result).setParameterNameInitializer(initializer);
        }
        setParameterNamesAndAnnotations(method, parameterTypes, parameterNames, result);
    }
    ITypeBinding[] exceptionTypes = method.getExceptionTypes();
    if (exceptionTypes.length > 0) {
        InternalEList<JvmTypeReference> exceptions = (InternalEList<JvmTypeReference>) result.getExceptions();
        for (ITypeBinding exceptionType : exceptionTypes) {
            exceptions.addUnique(createTypeReference(exceptionType));
        }
    }
}
Also used : SegmentSequence(org.eclipse.emf.common.util.SegmentSequence) JvmExecutableImplCustom(org.eclipse.xtext.common.types.impl.JvmExecutableImplCustom) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 5 with InternalEList

use of org.eclipse.emf.ecore.util.InternalEList in project xtext-eclipse by eclipse.

the class JdtBasedTypeFactory method createTypeReference.

/**
 * Returns a type reference for the given type binding. If the binding is null, an {@link JvmUnknownTypeReference unknown}
 * type reference is returned.
 */
// @NonNull
protected JvmTypeReference createTypeReference(/* @Nullable */
ITypeBinding typeBinding) {
    if (typeBinding == null) {
        return TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
    }
    if (typeBinding.isArray()) {
        ITypeBinding componentType = typeBinding.getComponentType();
        JvmTypeReference componentTypeReference = createTypeReference(componentType);
        JvmGenericArrayTypeReference typeReference = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference();
        typeReference.setComponentType(componentTypeReference);
        return typeReference;
    }
    ITypeBinding outer = null;
    if (typeBinding.isMember() && !Modifier.isStatic(typeBinding.getModifiers())) {
        outer = typeBinding.getDeclaringClass();
    }
    JvmParameterizedTypeReference result;
    if (outer != null) {
        JvmParameterizedTypeReference outerReference = (JvmParameterizedTypeReference) createTypeReference(outer);
        result = TypesFactory.eINSTANCE.createJvmInnerTypeReference();
        ((JvmInnerTypeReference) result).setOuter(outerReference);
    } else {
        result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
    }
    ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
    if (typeArguments.length != 0) {
        ITypeBinding erasure = typeBinding.getErasure();
        result.setType(createProxy(erasure));
        InternalEList<JvmTypeReference> arguments = (InternalEList<JvmTypeReference>) result.getArguments();
        for (int i = 0; i < typeArguments.length; i++) {
            JvmTypeReference argument = createTypeArgument(typeArguments[i]);
            arguments.addUnique(argument);
        }
    } else {
        result.setType(createProxy(typeBinding));
    }
    return result;
}
Also used : JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmInnerTypeReference(org.eclipse.xtext.common.types.JvmInnerTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Aggregations

InternalEList (org.eclipse.emf.ecore.util.InternalEList)24 EObject (org.eclipse.emf.ecore.EObject)9 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)9 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)9 InternalEObject (org.eclipse.emf.ecore.InternalEObject)7 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)4 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)4 Iterator (java.util.Iterator)3 ListIterator (java.util.ListIterator)3 RandomAccess (java.util.RandomAccess)3 AbstractSequentialInternalEList (org.eclipse.emf.ecore.util.AbstractSequentialInternalEList)3 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)3 IAnnotationBinding (org.eclipse.jdt.core.dom.IAnnotationBinding)3 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)3 JvmMember (org.eclipse.xtext.common.types.JvmMember)3 List (java.util.List)2 URI (org.eclipse.emf.common.util.URI)2 EReference (org.eclipse.emf.ecore.EReference)2 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)2 AbortCompilation (org.eclipse.jdt.internal.compiler.problem.AbortCompilation)2