Search in sources :

Example 6 with InternalEList

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

the class JdtBasedTypeFactory method setParameterNamesAndAnnotations.

private void setParameterNamesAndAnnotations(IMethodBinding method, ITypeBinding[] parameterTypes, String[] parameterNames, JvmExecutable result) {
    InternalEList<JvmFormalParameter> parameters = (InternalEList<JvmFormalParameter>) result.getParameters();
    for (int i = 0; i < parameterTypes.length; i++) {
        IAnnotationBinding[] parameterAnnotations;
        try {
            parameterAnnotations = method.getParameterAnnotations(i);
        } catch (AbortCompilation aborted) {
            parameterAnnotations = null;
        }
        ITypeBinding parameterType = parameterTypes[i];
        String parameterName = parameterNames == null ? null : /* lazy */
        i < parameterNames.length ? parameterNames[i] : "arg" + i;
        JvmFormalParameter formalParameter = createFormalParameter(parameterType, parameterName, parameterAnnotations);
        parameters.addUnique(formalParameter);
    }
}
Also used : JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) IAnnotationBinding(org.eclipse.jdt.core.dom.IAnnotationBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) AbortCompilation(org.eclipse.jdt.internal.compiler.problem.AbortCompilation) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 7 with InternalEList

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

the class JdtBasedTypeFactory method createTypeArgument.

protected JvmTypeReference createTypeArgument(ITypeBinding argument) {
    if (argument.isWildcardType()) {
        JvmWildcardTypeReference result = TypesFactory.eINSTANCE.createJvmWildcardTypeReference();
        InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>) result.getConstraints();
        JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
        ITypeBinding bound = argument.getBound();
        if (argument.isUpperbound()) {
            JvmTypeReference reference = createTypeReference(bound);
            upperBound.setTypeReference(reference);
            constraints.addUnique(upperBound);
        } else {
            JvmTypeReference objectReference = createObjectClassReference();
            upperBound.setTypeReference(objectReference);
            constraints.addUnique(upperBound);
            if (bound != null) {
                JvmLowerBound lowerBound = TypesFactory.eINSTANCE.createJvmLowerBound();
                JvmTypeReference reference = createTypeReference(bound);
                lowerBound.setTypeReference(reference);
                constraints.addUnique(lowerBound);
            }
        }
        return result;
    } else {
        return createTypeReference(argument);
    }
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmWildcardTypeReference(org.eclipse.xtext.common.types.JvmWildcardTypeReference) JvmLowerBound(org.eclipse.xtext.common.types.JvmLowerBound) 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 8 with InternalEList

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

the class JdtBasedTypeFactory method createFields.

/**
 * @since 2.4
 */
protected void createFields(ITypeBinding typeBinding, StringBuilder qualifiedName, JvmDeclaredType result) {
    resolveMembers.start();
    IVariableBinding[] declaredFields = typeBinding.getDeclaredFields();
    if (declaredFields.length > 0) {
        int length = qualifiedName.length();
        InternalEList<JvmMember> members = (InternalEList<JvmMember>) result.getMembers();
        for (IVariableBinding field : declaredFields) {
            if (!field.isSynthetic()) {
                members.addUnique(createField(qualifiedName, field));
                qualifiedName.setLength(length);
            }
        }
    }
    resolveMembers.stop();
}
Also used : InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmMember(org.eclipse.xtext.common.types.JvmMember) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 9 with InternalEList

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

the class JdtBasedTypeFactory method createMethods.

/**
 * @since 2.4
 */
protected void createMethods(ITypeBinding typeBinding, String handleIdentifier, List<String> path, StringBuilder qualifiedName, JvmDeclaredType result) {
    resolveMembers.start();
    IMethodBinding[] declaredMethods = typeBinding.getDeclaredMethods();
    if (declaredMethods.length > 0) {
        int length = qualifiedName.length();
        InternalEList<JvmMember> members = (InternalEList<JvmMember>) result.getMembers();
        String[] subpath = subpath(path);
        boolean intf = typeBinding.isInterface() && !typeBinding.isAnnotation();
        for (IMethodBinding method : declaredMethods) {
            if (!method.isSynthetic() && !"<clinit>".equals(method.getName())) {
                if (method.isConstructor()) {
                    members.addUnique(createConstructor(qualifiedName, handleIdentifier, subpath, method));
                } else {
                    JvmOperation operation = createOperation(qualifiedName, handleIdentifier, subpath, method);
                    if (typeBinding.isAnnotation()) {
                        setDefaultValue(operation, method);
                    } else if (intf && !operation.isAbstract() && !operation.isStatic()) {
                        operation.setDefault(true);
                    }
                    members.addUnique(operation);
                }
                qualifiedName.setLength(length);
            }
        }
    }
    resolveMembers.stop();
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 10 with InternalEList

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

the class JdtBasedTypeFactory method createAnnotationReference.

/**
 * @since 2.4
 */
protected JvmAnnotationReference createAnnotationReference(/* @NonNull */
IAnnotationBinding annotation) {
    JvmAnnotationReference annotationReference = TypesFactory.eINSTANCE.createJvmAnnotationReference();
    ITypeBinding annotationType = annotation.getAnnotationType();
    annotationReference.setAnnotation(createAnnotationProxy(annotationType));
    InternalEList<JvmAnnotationValue> values = (InternalEList<JvmAnnotationValue>) annotationReference.getExplicitValues();
    IMemberValuePairBinding[] allMemberValuePairs = annotation.getDeclaredMemberValuePairs();
    for (IMemberValuePairBinding memberValuePair : allMemberValuePairs) {
        IMethodBinding methodBinding = memberValuePair.getMethodBinding();
        if (methodBinding != null) {
            try {
                values.addUnique(createAnnotationValue(annotationType, memberValuePair.getValue(), methodBinding));
            } catch (NullPointerException npe) {
                // memberValuePair#getValue may throw an NPE if the methodBinding has no return type
                if (methodBinding.getReturnType() != null) {
                    throw npe;
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug(npe.getMessage(), npe);
                    }
                }
            }
        }
    }
    return annotationReference;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) IMemberValuePairBinding(org.eclipse.jdt.core.dom.IMemberValuePairBinding) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

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