Example usage for org.eclipse.jdt.core.dom Type isIntersectionType

List of usage examples for org.eclipse.jdt.core.dom Type isIntersectionType

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Type isIntersectionType.

Prototype

public final boolean isIntersectionType() 

Source Link

Document

Returns whether this type is an intersection type ( IntersectionType ).

Usage

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

protected String typeName(final org.eclipse.jdt.core.dom.Type t) {
    if (t.isArrayType())
        return typeName((ArrayType) t);
    if (t.isParameterizedType())
        return typeName((ParameterizedType) t);
    if (t.isPrimitiveType())
        return typeName((PrimitiveType) t);
    if (t.isQualifiedType())
        return typeName((QualifiedType) t);
    if (t.isIntersectionType())
        return typeName((IntersectionType) t);
    if (t.isUnionType())
        return typeName((UnionType) t);
    if (t.isWildcardType())
        return typeName((WildcardType) t);
    return typeName((SimpleType) t);
}

From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java

License:Open Source License

@SuppressWarnings("unchecked")
private String getTypeFqn(Type type) {
    if (type == null) {
        logger.log(Level.SEVERE, "Attempt to get type fqn of null type!");
        throw new NullPointerException("Attempt to get type fqn of null type!");
    }/*from w w  w .  ja  v  a 2s  .co  m*/
    ITypeBinding binding = safeResolve(type);
    if (binding == null || binding.isRecovered()) {
        if (type.isPrimitiveType()) {
            return ((PrimitiveType) type).getPrimitiveTypeCode().toString();
        } else if (type.isSimpleType()) {
            return createUnknownFqn(((SimpleType) type).getName().getFullyQualifiedName());
        } else if (type.isArrayType()) {
            ArrayType arrayType = (ArrayType) type;
            Type elementType = arrayType.getElementType();
            if (elementType == null) {
                return createUnknownFqn(BRACKETS.substring(0, 2 * arrayType.getDimensions()));
            } else {
                return getTypeFqn(elementType) + BRACKETS.substring(0, 2 * arrayType.getDimensions());
            }
        } else if (type.isParameterizedType()) {
            ParameterizedType pType = (ParameterizedType) type;
            StringBuilder fqn = new StringBuilder(getTypeFqn(pType.getType()));
            fqn.append("<");
            boolean isFirst = true;
            for (Type arg : (List<Type>) pType.typeArguments()) {
                if (isFirst) {
                    isFirst = false;
                } else {
                    fqn.append(",");
                }
                try {
                    fqn.append(getTypeFqn(arg));
                } catch (NullPointerException e) {
                    logger.log(Level.WARNING, "Eclipse NPE bug in parametrized type", e);
                    fqn.append(UNKNOWN);
                }
            }
            fqn.append(">");
            return fqn.toString();
        } else if (type.isWildcardType()) {
            WildcardType wType = (WildcardType) type;
            Type bound = wType.getBound();
            if (bound == null) {
                return "<?>";
            } else {
                return "<?" + (wType.isUpperBound() ? "+" : "-") + getTypeFqn(bound) + ">";
            }
        } else {
            if (type.isIntersectionType()) {
                IntersectionType iType = (IntersectionType) type;

                List<Type> list_types = iType.types();
                String res = "";
                for (Type tt : list_types) {
                    res += getTypeFqn(tt) + "&";
                }

                res = res.substring(0, res.length() - 1);
                return res;
            } else {
                logger.log(Level.SEVERE, "2 - Unexpected node type for unresolved type!" + type.toString());
                return UNKNOWN;
            }
        }
    } else {
        return getTypeFqn(binding);
    }
}