Example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding isBoundParameterizedType

List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding isBoundParameterizedType

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding isBoundParameterizedType.

Prototype

public boolean isBoundParameterizedType() 

Source Link

Document

Returns true if parameterized type AND not of the form List

Usage

From source file:org.eclipse.recommenders.utils.rcp.CompilerBindings.java

License:Open Source License

/**
 * TODO nested anonymous types are not resolved correctly. JDT uses line numbers for inner types instead of $1,..,$n
 */// www  . j  a v a2s . c o  m
public static Optional<ITypeName> toTypeName(@Nullable TypeBinding binding) {
    // XXX generics fail
    if (binding == null) {
        return absent();
    }
    //
    final boolean boundParameterizedType = binding.isBoundParameterizedType();
    final boolean parameterizedType = binding.isParameterizedType();

    // if (binding.isBoundParameterizedType()) {
    // return null;
    // }

    if (binding.isArrayType()) {
        final int dimensions = binding.dimensions();
        final TypeBinding leafComponentType = binding.leafComponentType();
        final String arrayDimensions = StringUtils.repeat("[", dimensions);
        final Optional<ITypeName> typeName = toTypeName(leafComponentType);
        if (!typeName.isPresent()) {
            return absent();
        }
        final ITypeName res = VmTypeName.get(arrayDimensions + typeName.get().getIdentifier());
        return fromNullable(res);
    }
    // TODO: handling of generics is bogus!
    if (binding instanceof TypeVariableBinding) {
        final TypeVariableBinding generic = (TypeVariableBinding) binding;
        if (generic.declaringElement instanceof TypeBinding) {
            // XXX: for this?
            binding = (TypeBinding) generic.declaringElement;
        } else if (generic.superclass != null) {
            // example Tuple<T1 extends List, T2 extends Number) --> for
            // generic.superclass (T2)=Number
            // we replace the generic by its superclass
            binding = generic.superclass;
        }
    }

    String signature = String.valueOf(binding.genericTypeSignature());
    // if (binding instanceof BinaryTypeBinding) {
    // signature = StringUtils.substringBeforeLast(signature, ";");
    // }

    if (signature.length() == 1) {
        // no handling needed. primitives always look the same.
    } else if (signature.endsWith(";")) {
        signature = StringUtils.substringBeforeLast(signature, ";");
    } else {
        signature = "L" + SignatureUtil.stripSignatureToFQN(signature);
    }
    final ITypeName res = VmTypeName.get(signature);
    return fromNullable(res);
}