Search in sources :

Example 1 with SegmentSequence

use of org.eclipse.emf.common.util.SegmentSequence 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 2 with SegmentSequence

use of org.eclipse.emf.common.util.SegmentSequence in project xtext-eclipse by eclipse.

the class JdtBasedTypeFactory method getSignatureAsSegmentSequence.

private SegmentSequence getSignatureAsSegmentSequence(IMethodBinding method) {
    String key = method.getKey();
    int start = key.indexOf('(');
    int end = key.lastIndexOf(')');
    SegmentSequence signaturex = SegmentSequence.create(";", key.substring(start + 1, end));
    return signaturex;
}
Also used : SegmentSequence(org.eclipse.emf.common.util.SegmentSequence) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Aggregations

SegmentSequence (org.eclipse.emf.common.util.SegmentSequence)2 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)2 InternalEList (org.eclipse.emf.ecore.util.InternalEList)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)1 JvmExecutableImplCustom (org.eclipse.xtext.common.types.impl.JvmExecutableImplCustom)1