Example usage for org.eclipse.jdt.core.dom ITypeBinding getDimensions

List of usage examples for org.eclipse.jdt.core.dom ITypeBinding getDimensions

Introduction

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

Prototype

public int getDimensions();

Source Link

Document

Returns the dimensionality of this array type, or 0 if this is not an array type binding.

Usage

From source file:astview.Binding.java

License:Open Source License

@Override
public Object[] getChildren() {
    try {/*from   ww  w .  j a  v  a 2  s.  c  om*/
        if (fBinding != null) {
            fBinding.getKey();
        }
    } catch (RuntimeException e) {
        return new Object[] { new Error(this, "BrokenBinding: " + fBinding, null) };
    }
    if (fBinding != null) {
        ArrayList<ASTAttribute> res = new ArrayList<>();
        res.add(new BindingProperty(this, "NAME", fBinding.getName(), true)); //$NON-NLS-1$
        res.add(new BindingProperty(this, "KEY", fBinding.getKey(), true)); //$NON-NLS-1$
        res.add(new BindingProperty(this, "IS RECOVERED", fBinding.isRecovered(), true)); //$NON-NLS-1$
        switch (fBinding.getKind()) {
        case IBinding.VARIABLE:
            IVariableBinding variableBinding = (IVariableBinding) fBinding;
            res.add(new BindingProperty(this, "IS FIELD", variableBinding.isField(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS ENUM CONSTANT", variableBinding.isEnumConstant(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS PARAMETER", variableBinding.isParameter(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "VARIABLE ID", variableBinding.getVariableId(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "MODIFIERS", getModifiersString(fBinding.getModifiers(), false), //$NON-NLS-1$
                    true));
            res.add(new Binding(this, "TYPE", variableBinding.getType(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "DECLARING CLASS", variableBinding.getDeclaringClass(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "DECLARING METHOD", variableBinding.getDeclaringMethod(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "VARIABLE DECLARATION", variableBinding.getVariableDeclaration(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "CONSTANT VALUE", variableBinding.getConstantValue(), true)); //$NON-NLS-1$ //$NON-NLS-2$
            res.add(new BindingProperty(this, "IS EFFECTIVELY FINAL", variableBinding.isEffectivelyFinal(), //$NON-NLS-1$
                    true));
            break;

        case IBinding.PACKAGE:
            IPackageBinding packageBinding = (IPackageBinding) fBinding;
            res.add(new BindingProperty(this, "IS UNNAMED", packageBinding.isUnnamed(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$
            break;

        case IBinding.TYPE:
            ITypeBinding typeBinding = (ITypeBinding) fBinding;
            res.add(new BindingProperty(this, "QUALIFIED NAME", typeBinding.getQualifiedName(), true)); //$NON-NLS-1$

            int typeKind = getTypeKind(typeBinding);
            boolean isRefType = isType(typeKind, REF_TYPE);
            final boolean isNonPrimitive = !isType(typeKind, PRIMITIVE_TYPE);

            StringBuffer kinds = new StringBuffer("KIND:"); //$NON-NLS-1$
            if (typeBinding.isArray())
                kinds.append(" isArray"); //$NON-NLS-1$
            if (typeBinding.isCapture())
                kinds.append(" isCapture"); //$NON-NLS-1$
            if (typeBinding.isNullType())
                kinds.append(" isNullType"); //$NON-NLS-1$
            if (typeBinding.isPrimitive())
                kinds.append(" isPrimitive"); //$NON-NLS-1$
            if (typeBinding.isTypeVariable())
                kinds.append(" isTypeVariable"); //$NON-NLS-1$
            if (typeBinding.isWildcardType())
                kinds.append(" isWildcardType"); //$NON-NLS-1$
            // ref types
            if (typeBinding.isAnnotation())
                kinds.append(" isAnnotation"); //$NON-NLS-1$
            if (typeBinding.isClass())
                kinds.append(" isClass"); //$NON-NLS-1$
            if (typeBinding.isInterface())
                kinds.append(" isInterface"); //$NON-NLS-1$
            if (typeBinding.isEnum())
                kinds.append(" isEnum"); //$NON-NLS-1$
            res.add(new BindingProperty(this, kinds, true)); //$NON-NLS-1$

            StringBuffer generics = new StringBuffer("GENERICS:"); //$NON-NLS-1$
            if (typeBinding.isRawType())
                generics.append(" isRawType"); //$NON-NLS-1$
            if (typeBinding.isGenericType())
                generics.append(" isGenericType"); //$NON-NLS-1$
            if (typeBinding.isParameterizedType())
                generics.append(" isParameterizedType"); //$NON-NLS-1$
            if (!isType(typeKind, GENERIC | PARAMETRIZED)) {
                generics.append(" (non-generic, non-parameterized)");
            }
            res.add(new BindingProperty(this, generics, isRefType)); //$NON-NLS-1$

            res.add(new Binding(this, "ELEMENT TYPE", typeBinding.getElementType(), //$NON-NLS-1$
                    isType(typeKind, ARRAY_TYPE)));
            res.add(new Binding(this, "COMPONENT TYPE", typeBinding.getComponentType(), //$NON-NLS-1$
                    isType(typeKind, ARRAY_TYPE)));
            res.add(new BindingProperty(this, "DIMENSIONS", typeBinding.getDimensions(), //$NON-NLS-1$
                    isType(typeKind, ARRAY_TYPE)));
            final String createArrayTypeLabel = "CREATE ARRAY TYPE (+1)";
            try {
                ITypeBinding arrayType = typeBinding.createArrayType(1);
                res.add(new Binding(this, createArrayTypeLabel, arrayType, true));
            } catch (RuntimeException e) {
                String msg = e.getClass().getName() + ": " + e.getLocalizedMessage();
                boolean isRelevant = !typeBinding.getName().equals(PrimitiveType.VOID.toString())
                        && !typeBinding.isRecovered();
                if (isRelevant) {
                    res.add(new Error(this, createArrayTypeLabel + ": " + msg, e));
                } else {
                    res.add(new BindingProperty(this, createArrayTypeLabel, msg, false));
                }
            }

            StringBuffer origin = new StringBuffer("ORIGIN:"); //$NON-NLS-1$
            if (typeBinding.isTopLevel())
                origin.append(" isTopLevel"); //$NON-NLS-1$
            if (typeBinding.isNested())
                origin.append(" isNested"); //$NON-NLS-1$
            if (typeBinding.isLocal())
                origin.append(" isLocal"); //$NON-NLS-1$
            if (typeBinding.isMember())
                origin.append(" isMember"); //$NON-NLS-1$
            if (typeBinding.isAnonymous())
                origin.append(" isAnonymous"); //$NON-NLS-1$
            res.add(new BindingProperty(this, origin, isRefType));

            res.add(new BindingProperty(this, "IS FROM SOURCE", typeBinding.isFromSource(), //$NON-NLS-1$
                    isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE)));

            res.add(new Binding(this, "PACKAGE", typeBinding.getPackage(), isRefType)); //$NON-NLS-1$
            res.add(new Binding(this, "DECLARING CLASS", typeBinding.getDeclaringClass(), //$NON-NLS-1$
                    isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE)));
            res.add(new Binding(this, "DECLARING METHOD", typeBinding.getDeclaringMethod(), //$NON-NLS-1$
                    isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE)));
            //               res.add(new Binding(this, "DECLARING MEMBER", typeBinding.getDeclaringMember(), typeBinding.isLocal())); //$NON-NLS-1$
            res.add(new BindingProperty(this, "MODIFIERS", getModifiersString(fBinding.getModifiers(), false), //$NON-NLS-1$
                    isRefType));
            res.add(new BindingProperty(this, "BINARY NAME", typeBinding.getBinaryName(), true)); //$NON-NLS-1$

            String isTypeDeclaration = typeBinding == typeBinding.getTypeDeclaration() ? " ( == this)"
                    : " ( != this)";
            res.add(new Binding(this, "TYPE DECLARATION" + isTypeDeclaration, typeBinding.getTypeDeclaration(), //$NON-NLS-1$
                    true));
            String isErasure = typeBinding == typeBinding.getErasure() ? " ( == this)" : " ( != this)";
            res.add(new Binding(this, "ERASURE" + isErasure, typeBinding.getErasure(), isNonPrimitive)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "TYPE PARAMETERS", typeBinding.getTypeParameters(), //$NON-NLS-1$
                    isType(typeKind, GENERIC)));
            res.add(new BindingProperty(this, "TYPE ARGUMENTS", typeBinding.getTypeArguments(), //$NON-NLS-1$
                    isType(typeKind, PARAMETRIZED)));
            res.add(new BindingProperty(this, "TYPE BOUNDS", typeBinding.getTypeBounds(), //$NON-NLS-1$
                    isType(typeKind, VARIABLE_TYPE | WILDCARD_TYPE | CAPTURE_TYPE)));
            res.add(new Binding(this, "BOUND", typeBinding.getBound(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS UPPERBOUND", typeBinding.isUpperbound(), //$NON-NLS-1$
                    isType(typeKind, WILDCARD_TYPE)));
            res.add(new Binding(this, "GENERIC TYPE OF WILDCARD TYPE", //$NON-NLS-1$
                    typeBinding.getGenericTypeOfWildcardType(), isType(typeKind, WILDCARD_TYPE)));
            res.add(new BindingProperty(this, "RANK", typeBinding.getRank(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$
            res.add(new Binding(this, "WILDCARD", typeBinding.getWildcard(), isType(typeKind, CAPTURE_TYPE))); //$NON-NLS-1$

            res.add(new Binding(this, "SUPERCLASS", typeBinding.getSuperclass(), isRefType)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "INTERFACES", typeBinding.getInterfaces(), isRefType)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "DECLARED TYPES", typeBinding.getDeclaredTypes(), isRefType)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "DECLARED FIELDS", typeBinding.getDeclaredFields(), isRefType)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "DECLARED METHODS", typeBinding.getDeclaredMethods(), isRefType)); //$NON-NLS-1$
            res.add(new Binding(this, "FUNCTIONAL INTERFACE METHOD", typeBinding.getFunctionalInterfaceMethod(), //$NON-NLS-1$
                    typeBinding.isInterface()));
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), isNonPrimitive)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), isRefType)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "TYPE ANNOTATIONS", typeBinding.getTypeAnnotations(), true)); //$NON-NLS-1$
            break;

        case IBinding.METHOD:
            IMethodBinding methodBinding = (IMethodBinding) fBinding;
            res.add(new BindingProperty(this, "IS CONSTRUCTOR", methodBinding.isConstructor(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEFAULT CONSTRUCTOR", methodBinding.isDefaultConstructor(), //$NON-NLS-1$
                    true));
            res.add(new Binding(this, "DECLARING CLASS", methodBinding.getDeclaringClass(), true)); //$NON-NLS-1$
            //               res.add(new Binding(this, "DECLARING MEMBER", methodBinding.getDeclaringMember(), methodBinding.getDeclaringMember() != null)); //$NON-NLS-1$
            res.add(new Binding(this, "RETURN TYPE", methodBinding.getReturnType(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "MODIFIERS", getModifiersString(fBinding.getModifiers(), true), //$NON-NLS-1$
                    true));
            res.add(new BindingProperty(this, "PARAMETER TYPES", methodBinding.getParameterTypes(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS VARARGS", methodBinding.isVarargs(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "EXCEPTION TYPES", methodBinding.getExceptionTypes(), true)); //$NON-NLS-1$

            StringBuffer genericsM = new StringBuffer("GENERICS:"); //$NON-NLS-1$
            if (methodBinding.isRawMethod())
                genericsM.append(" isRawMethod"); //$NON-NLS-1$
            if (methodBinding.isGenericMethod())
                genericsM.append(" isGenericMethod"); //$NON-NLS-1$
            if (methodBinding.isParameterizedMethod())
                genericsM.append(" isParameterizedMethod"); //$NON-NLS-1$
            res.add(new BindingProperty(this, genericsM, true));

            String isMethodDeclaration = methodBinding == methodBinding.getMethodDeclaration() ? " ( == this)"
                    : " ( != this)";
            res.add(new Binding(this, "METHOD DECLARATION" + isMethodDeclaration, //$NON-NLS-1$
                    methodBinding.getMethodDeclaration(), true));
            res.add(new BindingProperty(this, "TYPE PARAMETERS", methodBinding.getTypeParameters(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "TYPE ARGUMENTS", methodBinding.getTypeArguments(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$

            res.add(new BindingProperty(this, "IS ANNOTATION MEMBER", methodBinding.isAnnotationMember(), //$NON-NLS-1$
                    true));
            res.add(Binding.createValueAttribute(this, "DEFAULT VALUE", methodBinding.getDefaultValue()));

            int parameterCount = methodBinding.getParameterTypes().length;
            BindingProperty[] parametersAnnotations = new BindingProperty[parameterCount];
            for (int i = 0; i < parameterCount; i++) {
                parametersAnnotations[i] = new BindingProperty(this, "Parameter " + String.valueOf(i),
                        methodBinding.getParameterAnnotations(i), true);
            }
            res.add(new BindingProperty(this, "PARAMETER ANNOTATIONS", parametersAnnotations, true));
            break;

        case IBinding.ANNOTATION:
            IAnnotationBinding annotationBinding = (IAnnotationBinding) fBinding;
            res.add(new Binding(this, "ANNOTATION TYPE", annotationBinding.getAnnotationType(), true));
            res.add(new BindingProperty(this, "DECLARED MEMBER VALUE PAIRS",
                    annotationBinding.getDeclaredMemberValuePairs(), true));
            res.add(new BindingProperty(this, "ALL MEMBER VALUE PAIRS",
                    annotationBinding.getAllMemberValuePairs(), true));
            break;

        case IBinding.MEMBER_VALUE_PAIR:
            IMemberValuePairBinding memberValuePairBinding = (IMemberValuePairBinding) fBinding;
            res.add(new Binding(this, "METHOD BINDING", memberValuePairBinding.getMethodBinding(), true));
            res.add(new BindingProperty(this, "IS DEFAULT", memberValuePairBinding.isDefault(), true));
            res.add(Binding.createValueAttribute(this, "VALUE", memberValuePairBinding.getValue()));
            break;
        }
        try {
            IAnnotationBinding[] annotations = fBinding.getAnnotations();
            res.add(new BindingProperty(this, "ANNOTATIONS", annotations, true)); //$NON-NLS-1$
        } catch (RuntimeException e) {
            String label = "Error in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\"";
            res.add(new Error(this, label, e));
        }

        try {
            IJavaElement javaElement = fBinding.getJavaElement();
        } catch (RuntimeException e) {
            String label = ">java element: " + e.getClass().getName() + " for \"" + fBinding.getKey() + "\""; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            res.add(new Error(this, label, e));
        }

        return res.toArray();
    }
    return EMPTY;
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

/**
 * Converts a type binding into a parameter-style binding Please see JVM
 * Specification 4.3.2//from w  w  w  .  j a  va 2s . c  om
 * {@link http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#84645}
 * .
 * 
 * @param pBinding
 *            The binding to convert. Cannot be null.
 * @return A class element representing this binding. Cannot be null.
 */
private static IElement convertParameterTypeBinding(final ITypeBinding pBinding) {
    ASTCrawler.checkForNull(pBinding);
    if (pBinding.getDimensions() == 0 && !pBinding.isPrimitive())
        return FlyweightElementFactory.getElement(Category.CLASS,
                Signature.C_RESOLVED + pBinding.getBinaryName() + Signature.C_SEMICOLON);
    else
        return FlyweightElementFactory.getElement(Category.CLASS, pBinding.getBinaryName());
}

From source file:changetypes.ASTVisitorAtomicChange.java

License:Open Source License

private static String getQualifiedName(ITypeBinding itb) {
    if (itb.isPrimitive()) {
        return itb.getName();
    }//from w  w  w  .jav a2  s .c o m
    if (itb.isArray()) {
        try {
            StringBuilder suffix = new StringBuilder();
            for (int i = 0; i < itb.getDimensions(); i++) {
                suffix.append("[]");
            }
            return getQualifiedName(itb.getElementType()) + suffix.toString();
        } catch (NullPointerException localNullPointerException1) {
            return null;
        }
    }
    if (itb.isNullType()) {
        return "null";
    }
    if ((itb.isClass()) || (itb.isInterface())) {
        if (itb.isNested()) {
            String name = itb.getName();
            if (itb.isAnonymous()) {
                String binname = itb.getBinaryName();
                int index = binname.indexOf('$');
                name = binname.substring(index + 1, binname.length());
            }
            return getQualifiedName(itb.getDeclaringClass()) + "#" + name;
        }
        try {
            String pkg = itb.getPackage().getName();
            String name = itb.getName();

            name = removeParameters(itb.getName());
            return pkg + "%." + name;
        } catch (NullPointerException localNullPointerException2) {
            return null;
        }
    }
    return "java.lang%.Object";
}

From source file:cideplus.ui.astview.Binding.java

License:Open Source License

public Object[] getChildren() {
    if (fBinding != null) {
        ArrayList res = new ArrayList();
        res.add(new BindingProperty(this, "NAME", fBinding.getName(), true)); //$NON-NLS-1$
        res.add(new BindingProperty(this, "KEY", fBinding.getKey(), true)); //$NON-NLS-1$
        res.add(new BindingProperty(this, "IS RECOVERED", fBinding.isRecovered(), true)); //$NON-NLS-1$
        switch (fBinding.getKind()) {
        case IBinding.VARIABLE:
            IVariableBinding variableBinding = (IVariableBinding) fBinding;
            res.add(new BindingProperty(this, "IS FIELD", variableBinding.isField(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS ENUM CONSTANT", variableBinding.isEnumConstant(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS PARAMETER", variableBinding.isParameter(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "VARIABLE ID", variableBinding.getVariableId(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), true)); //$NON-NLS-1$
            res.add(new Binding(this, "TYPE", variableBinding.getType(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "DECLARING CLASS", variableBinding.getDeclaringClass(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "DECLARING METHOD", variableBinding.getDeclaringMethod(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "VARIABLE DECLARATION", variableBinding.getVariableDeclaration(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "CONSTANT VALUE", variableBinding.getConstantValue(), true)); //$NON-NLS-1$ //$NON-NLS-2$
            break;

        case IBinding.PACKAGE:
            IPackageBinding packageBinding = (IPackageBinding) fBinding;
            res.add(new BindingProperty(this, "IS UNNAMED", packageBinding.isUnnamed(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$
            break;

        case IBinding.TYPE:
            if (1 == 1) {
                break;//no iremos mostrar todas essas informaes da classe
            }/* w  ww .  jav a2s  . c  om*/
            ITypeBinding typeBinding = (ITypeBinding) fBinding;
            res.add(new BindingProperty(this, "QUALIFIED NAME", typeBinding.getQualifiedName(), true)); //$NON-NLS-1$

            int typeKind = getTypeKind(typeBinding);
            boolean isRefType = isType(typeKind, REF_TYPE);
            final boolean isNonPrimitive = !isType(typeKind, PRIMITIVE_TYPE);

            StringBuffer kinds = new StringBuffer("KIND:"); //$NON-NLS-1$
            if (typeBinding.isArray())
                kinds.append(" isArray"); //$NON-NLS-1$
            if (typeBinding.isCapture())
                kinds.append(" isCapture"); //$NON-NLS-1$
            if (typeBinding.isNullType())
                kinds.append(" isNullType"); //$NON-NLS-1$
            if (typeBinding.isPrimitive())
                kinds.append(" isPrimitive"); //$NON-NLS-1$
            if (typeBinding.isTypeVariable())
                kinds.append(" isTypeVariable"); //$NON-NLS-1$
            if (typeBinding.isWildcardType())
                kinds.append(" isWildcardType"); //$NON-NLS-1$
            // ref types
            if (typeBinding.isAnnotation())
                kinds.append(" isAnnotation"); //$NON-NLS-1$
            if (typeBinding.isClass())
                kinds.append(" isClass"); //$NON-NLS-1$
            if (typeBinding.isInterface())
                kinds.append(" isInterface"); //$NON-NLS-1$
            if (typeBinding.isEnum())
                kinds.append(" isEnum"); //$NON-NLS-1$
            res.add(new BindingProperty(this, kinds, true)); //$NON-NLS-1$

            StringBuffer generics = new StringBuffer("GENERICS:"); //$NON-NLS-1$
            if (typeBinding.isRawType())
                generics.append(" isRawType"); //$NON-NLS-1$
            if (typeBinding.isGenericType())
                generics.append(" isGenericType"); //$NON-NLS-1$
            if (typeBinding.isParameterizedType())
                generics.append(" isParameterizedType"); //$NON-NLS-1$
            if (!isType(typeKind, GENERIC | PARAMETRIZED)) {
                generics.append(" (non-generic, non-parameterized)");
            }
            res.add(new BindingProperty(this, generics, isRefType)); //$NON-NLS-1$

            res.add(new Binding(this, "ELEMENT TYPE", typeBinding.getElementType(), //$NON-NLS-1$
                    isType(typeKind, ARRAY_TYPE)));
            res.add(new Binding(this, "COMPONENT TYPE", typeBinding.getComponentType(), //$NON-NLS-1$
                    isType(typeKind, ARRAY_TYPE)));
            res.add(new BindingProperty(this, "DIMENSIONS", typeBinding.getDimensions(), //$NON-NLS-1$
                    isType(typeKind, ARRAY_TYPE)));
            final String createArrayTypeLabel = "CREATE ARRAY TYPE (+1)";
            try {
                ITypeBinding arrayType = typeBinding.createArrayType(1);
                res.add(new Binding(this, createArrayTypeLabel, arrayType, true));
            } catch (RuntimeException e) {
                String msg = e.getClass().getName() + ": " + e.getLocalizedMessage();
                boolean isRelevant = !typeBinding.getName().equals(PrimitiveType.VOID.toString())
                        && !typeBinding.isRecovered();
                if (isRelevant) {
                    res.add(new Error(this, createArrayTypeLabel + ": " + msg, e));
                } else {
                    res.add(new BindingProperty(this, createArrayTypeLabel, msg, false));
                }
            }

            res.add(new BindingProperty(this, "TYPE BOUNDS", typeBinding.getTypeBounds(), //$NON-NLS-1$
                    isType(typeKind, VARIABLE_TYPE | CAPTURE_TYPE)));

            StringBuffer origin = new StringBuffer("ORIGIN:"); //$NON-NLS-1$
            if (typeBinding.isTopLevel())
                origin.append(" isTopLevel"); //$NON-NLS-1$
            if (typeBinding.isNested())
                origin.append(" isNested"); //$NON-NLS-1$
            if (typeBinding.isLocal())
                origin.append(" isLocal"); //$NON-NLS-1$
            if (typeBinding.isMember())
                origin.append(" isMember"); //$NON-NLS-1$
            if (typeBinding.isAnonymous())
                origin.append(" isAnonymous"); //$NON-NLS-1$
            res.add(new BindingProperty(this, origin, isRefType));

            res.add(new BindingProperty(this, "IS FROM SOURCE", typeBinding.isFromSource(), //$NON-NLS-1$
                    isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE)));

            res.add(new Binding(this, "PACKAGE", typeBinding.getPackage(), isRefType)); //$NON-NLS-1$
            res.add(new Binding(this, "DECLARING CLASS", typeBinding.getDeclaringClass(), //$NON-NLS-1$
                    isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE)));
            res.add(new Binding(this, "DECLARING METHOD", typeBinding.getDeclaringMethod(), //$NON-NLS-1$
                    isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE)));
            res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), isRefType)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "BINARY NAME", typeBinding.getBinaryName(), true)); //$NON-NLS-1$

            res.add(new Binding(this, "TYPE DECLARATION", typeBinding.getTypeDeclaration(), isNonPrimitive)); //$NON-NLS-1$
            res.add(new Binding(this, "ERASURE", typeBinding.getErasure(), isNonPrimitive)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "TYPE PARAMETERS", typeBinding.getTypeParameters(), //$NON-NLS-1$
                    isType(typeKind, GENERIC)));
            res.add(new BindingProperty(this, "TYPE ARGUMENTS", typeBinding.getTypeArguments(), //$NON-NLS-1$
                    isType(typeKind, PARAMETRIZED)));
            res.add(new Binding(this, "BOUND", typeBinding.getBound(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS UPPERBOUND", typeBinding.isUpperbound(), //$NON-NLS-1$
                    isType(typeKind, WILDCARD_TYPE)));
            res.add(new Binding(this, "GENERIC TYPE OF WILDCARD TYPE", //$NON-NLS-1$
                    typeBinding.getGenericTypeOfWildcardType(), isType(typeKind, WILDCARD_TYPE)));
            res.add(new BindingProperty(this, "RANK", typeBinding.getRank(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$
            res.add(new Binding(this, "WILDCARD", typeBinding.getWildcard(), isType(typeKind, CAPTURE_TYPE))); //$NON-NLS-1$

            res.add(new Binding(this, "SUPERCLASS", typeBinding.getSuperclass(), isRefType)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "INTERFACES", typeBinding.getInterfaces(), isRefType)); //$NON-NLS-1$         
            res.add(new BindingProperty(this, "DECLARED TYPES", typeBinding.getDeclaredTypes(), isRefType)); //$NON-NLS-1$         
            res.add(new BindingProperty(this, "DECLARED FIELDS", typeBinding.getDeclaredFields(), isRefType)); //$NON-NLS-1$         
            res.add(new BindingProperty(this, "DECLARED METHODS", typeBinding.getDeclaredMethods(), isRefType)); //$NON-NLS-1$         
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), isNonPrimitive)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), isRefType)); //$NON-NLS-1$
            break;

        case IBinding.METHOD:
            IMethodBinding methodBinding = (IMethodBinding) fBinding;
            res.add(new BindingProperty(this, "IS CONSTRUCTOR", methodBinding.isConstructor(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEFAULT CONSTRUCTOR", methodBinding.isDefaultConstructor(), //$NON-NLS-1$
                    true));
            res.add(new Binding(this, "DECLARING CLASS", methodBinding.getDeclaringClass(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "RETURN TYPE", methodBinding.getReturnType(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "PARAMETER TYPES", methodBinding.getParameterTypes(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS VARARGS", methodBinding.isVarargs(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "EXCEPTION TYPES", methodBinding.getExceptionTypes(), true)); //$NON-NLS-1$

            StringBuffer genericsM = new StringBuffer("GENERICS:"); //$NON-NLS-1$
            if (methodBinding.isRawMethod())
                genericsM.append(" isRawMethod"); //$NON-NLS-1$
            if (methodBinding.isGenericMethod())
                genericsM.append(" isGenericMethod"); //$NON-NLS-1$
            if (methodBinding.isParameterizedMethod())
                genericsM.append(" isParameterizedMethod"); //$NON-NLS-1$
            res.add(new BindingProperty(this, genericsM, true));

            res.add(new Binding(this, "METHOD DECLARATION", methodBinding.getMethodDeclaration(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "TYPE PARAMETERS", methodBinding.getTypeParameters(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "TYPE ARGUMENTS", methodBinding.getTypeArguments(), true)); //$NON-NLS-1$         
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$

            res.add(new BindingProperty(this, "IS ANNOTATION MEMBER", methodBinding.isAnnotationMember(), //$NON-NLS-1$
                    true));
            res.add(Binding.createValueAttribute(this, "DEFAULT VALUE", methodBinding.getDefaultValue()));

            int parameterCount = methodBinding.getParameterTypes().length;
            GeneralAttribute[] parametersAnnotations = new GeneralAttribute[parameterCount];
            for (int i = 0; i < parameterCount; i++) {
                parametersAnnotations[i] = new GeneralAttribute(this, "Parameter " + String.valueOf(i),
                        methodBinding.getParameterAnnotations(i));
            }
            res.add(new GeneralAttribute(this, "PARAMETER ANNOTATIONS", parametersAnnotations));
            break;

        case IBinding.ANNOTATION:
            IAnnotationBinding annotationBinding = (IAnnotationBinding) fBinding;
            res.add(new Binding(this, "ANNOTATION TYPE", annotationBinding.getAnnotationType(), true));
            res.add(new BindingProperty(this, "DECLARED MEMBER VALUE PAIRS",
                    annotationBinding.getDeclaredMemberValuePairs(), true));
            res.add(new BindingProperty(this, "ALL MEMBER VALUE PAIRS",
                    annotationBinding.getAllMemberValuePairs(), true));
            break;

        case IBinding.MEMBER_VALUE_PAIR:
            IMemberValuePairBinding memberValuePairBinding = (IMemberValuePairBinding) fBinding;
            res.add(new Binding(this, "METHOD BINDING", memberValuePairBinding.getMethodBinding(), true));
            res.add(new BindingProperty(this, "IS DEFAULT", memberValuePairBinding.isDefault(), true));
            res.add(Binding.createValueAttribute(this, "VALUE", memberValuePairBinding.getValue()));
            break;
        }
        try {
            IAnnotationBinding[] annotations = fBinding.getAnnotations();
            res.add(new BindingProperty(this, "ANNOTATIONS", annotations, true)); //$NON-NLS-1$
        } catch (RuntimeException e) {
            String label = "Error in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\"";
            res.add(new Error(this, label, e));
            ASTViewPlugin.log("Exception thrown in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\"",
                    e);
        }
        try {
            IJavaElement javaElement = fBinding.getJavaElement();
            res.add(new JavaElement(this, javaElement));
        } catch (RuntimeException e) {
            String label = ">java element: " + e.getClass().getName() + " for \"" + fBinding.getKey() + "\""; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            res.add(new Error(this, label, e));
            ASTViewPlugin.log("Exception thrown in IBinding#getJavaElement() for \"" + fBinding.getKey() + "\"",
                    e);
        }
        return res.toArray();
    }
    return EMPTY;
}

From source file:coloredide.astview.internal.Binding.java

License:Open Source License

public Object[] getChildren() {

    if (fBinding != null) {
        ArrayList res = new ArrayList();
        res.add(new BindingProperty(this, "NAME", fBinding.getName(), true)); //$NON-NLS-1$
        res.add(new BindingProperty(this, "KEY", fBinding.getKey(), true)); //$NON-NLS-1$
        switch (fBinding.getKind()) {
        case IBinding.VARIABLE:
            IVariableBinding variableBinding = (IVariableBinding) fBinding;
            res.add(new BindingProperty(this, "IS FIELD", variableBinding.isField(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS ENUM CONSTANT", variableBinding.isEnumConstant(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS PARAMETER", variableBinding.isParameter(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "VARIABLE ID", variableBinding.getVariableId(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), true)); //$NON-NLS-1$
            res.add(new Binding(this, "TYPE", variableBinding.getType(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "DECLARING CLASS", variableBinding.getDeclaringClass(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "DECLARING METHOD", variableBinding.getDeclaringMethod(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "VARIABLE DECLARATION", variableBinding.getVariableDeclaration(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$
            Object constVal = variableBinding.getConstantValue();
            res.add(new BindingProperty(this, "CONSTANT VALUE", constVal == null ? "null" : constVal.toString(), //$NON-NLS-1$//$NON-NLS-2$
                    true));// w w  w . j  av  a2s.c  o m
            break;

        case IBinding.PACKAGE:
            IPackageBinding packageBinding = (IPackageBinding) fBinding;
            res.add(new BindingProperty(this, "IS UNNAMED", packageBinding.isUnnamed(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$
            break;

        case IBinding.TYPE:
            ITypeBinding typeBinding = (ITypeBinding) fBinding;
            res.add(new BindingProperty(this, "QUALIFIED NAME", typeBinding.getQualifiedName(), true)); //$NON-NLS-1$

            int typeKind = getTypeKind(typeBinding);
            boolean isRefType = isType(typeKind, REF_TYPE);
            final boolean isNonPrimitive = !isType(typeKind, PRIMITIVE_TYPE);

            StringBuffer kinds = new StringBuffer("KIND:"); //$NON-NLS-1$
            if (typeBinding.isArray())
                kinds.append(" isArray"); //$NON-NLS-1$
            if (typeBinding.isCapture())
                kinds.append(" isCapture"); //$NON-NLS-1$
            if (typeBinding.isNullType())
                kinds.append(" isNullType"); //$NON-NLS-1$
            if (typeBinding.isPrimitive())
                kinds.append(" isPrimitive"); //$NON-NLS-1$
            if (typeBinding.isTypeVariable())
                kinds.append(" isTypeVariable"); //$NON-NLS-1$
            if (typeBinding.isWildcardType())
                kinds.append(" isWildcardType"); //$NON-NLS-1$
            // ref types
            if (typeBinding.isAnnotation())
                kinds.append(" isAnnotation"); //$NON-NLS-1$
            if (typeBinding.isClass())
                kinds.append(" isClass"); //$NON-NLS-1$
            if (typeBinding.isInterface())
                kinds.append(" isInterface"); //$NON-NLS-1$
            if (typeBinding.isEnum())
                kinds.append(" isEnum"); //$NON-NLS-1$
            res.add(new BindingProperty(this, kinds, true)); //$NON-NLS-1$

            StringBuffer generics = new StringBuffer("GENERICS:"); //$NON-NLS-1$
            if (typeBinding.isRawType())
                generics.append(" isRawType"); //$NON-NLS-1$
            if (typeBinding.isGenericType())
                generics.append(" isGenericType"); //$NON-NLS-1$
            if (typeBinding.isParameterizedType())
                generics.append(" isParameterizedType"); //$NON-NLS-1$
            if (!isType(typeKind, GENERIC | PARAMETRIZED)) {
                generics.append(" (non-generic, non-parameterized)");
            }
            res.add(new BindingProperty(this, generics, isRefType)); //$NON-NLS-1$

            res.add(new Binding(this, "ELEMENT TYPE", typeBinding.getElementType(), //$NON-NLS-1$
                    isType(typeKind, ARRAY_TYPE)));
            res.add(new Binding(this, "COMPONENT TYPE", typeBinding.getComponentType(), //$NON-NLS-1$
                    isType(typeKind, ARRAY_TYPE)));
            res.add(new BindingProperty(this, "DIMENSIONS", typeBinding.getDimensions(), //$NON-NLS-1$
                    isType(typeKind, ARRAY_TYPE)));

            res.add(new BindingProperty(this, "TYPE BOUNDS", typeBinding.getTypeBounds(), //$NON-NLS-1$
                    isType(typeKind, VARIABLE_TYPE | CAPTURE_TYPE)));

            StringBuffer origin = new StringBuffer("ORIGIN:"); //$NON-NLS-1$
            if (typeBinding.isTopLevel())
                origin.append(" isTopLevel"); //$NON-NLS-1$
            if (typeBinding.isNested())
                origin.append(" isNested"); //$NON-NLS-1$
            if (typeBinding.isLocal())
                origin.append(" isLocal"); //$NON-NLS-1$
            if (typeBinding.isMember())
                origin.append(" isMember"); //$NON-NLS-1$
            if (typeBinding.isAnonymous())
                origin.append(" isAnonymous"); //$NON-NLS-1$
            res.add(new BindingProperty(this, origin, isRefType));

            res.add(new BindingProperty(this, "IS FROM SOURCE", typeBinding.isFromSource(), //$NON-NLS-1$
                    isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE)));

            res.add(new Binding(this, "PACKAGE", typeBinding.getPackage(), isRefType)); //$NON-NLS-1$
            res.add(new Binding(this, "DECLARING CLASS", typeBinding.getDeclaringClass(), //$NON-NLS-1$
                    isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE)));
            res.add(new Binding(this, "DECLARING METHOD", typeBinding.getDeclaringMethod(), //$NON-NLS-1$
                    isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE)));
            res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), isRefType)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "BINARY NAME", typeBinding.getBinaryName(), true)); //$NON-NLS-1$

            res.add(new Binding(this, "TYPE DECLARATION", typeBinding.getTypeDeclaration(), isNonPrimitive)); //$NON-NLS-1$
            res.add(new Binding(this, "ERASURE", typeBinding.getErasure(), isNonPrimitive)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "TYPE PARAMETERS", typeBinding.getTypeParameters(), //$NON-NLS-1$
                    isType(typeKind, GENERIC)));
            res.add(new BindingProperty(this, "TYPE ARGUMENTS", typeBinding.getTypeArguments(), //$NON-NLS-1$
                    isType(typeKind, PARAMETRIZED)));
            res.add(new Binding(this, "BOUND", typeBinding.getBound(), isType(typeKind, WILDCARD_TYPE))); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS UPPERBOUND", typeBinding.isUpperbound(), //$NON-NLS-1$
                    isType(typeKind, WILDCARD_TYPE)));
            res.add(new Binding(this, "WILDCARD", typeBinding.getWildcard(), isType(typeKind, CAPTURE_TYPE))); //$NON-NLS-1$

            res.add(new Binding(this, "SUPERCLASS", typeBinding.getSuperclass(), isRefType)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "INTERFACES", typeBinding.getInterfaces(), isRefType)); //$NON-NLS-1$         
            res.add(new BindingProperty(this, "DECLARED TYPES", typeBinding.getDeclaredTypes(), isRefType)); //$NON-NLS-1$         
            res.add(new BindingProperty(this, "DECLARED FIELDS", typeBinding.getDeclaredFields(), isRefType)); //$NON-NLS-1$         
            res.add(new BindingProperty(this, "DECLARED METHODS", typeBinding.getDeclaredMethods(), isRefType)); //$NON-NLS-1$         
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), isNonPrimitive)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), isRefType)); //$NON-NLS-1$
            break;

        case IBinding.METHOD:
            IMethodBinding methodBinding = (IMethodBinding) fBinding;
            res.add(new BindingProperty(this, "IS CONSTRUCTOR", methodBinding.isConstructor(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEFAULT CONSTRUCTOR", methodBinding.isDefaultConstructor(), //$NON-NLS-1$
                    true));
            res.add(new Binding(this, "DECLARING CLASS", methodBinding.getDeclaringClass(), true)); //$NON-NLS-1$
            res.add(new Binding(this, "RETURN TYPE", methodBinding.getReturnType(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "PARAMETER TYPES", methodBinding.getParameterTypes(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS VARARGS", methodBinding.isVarargs(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "EXCEPTION TYPES", methodBinding.getExceptionTypes(), true)); //$NON-NLS-1$

            StringBuffer genericsM = new StringBuffer("GENERICS:"); //$NON-NLS-1$
            if (methodBinding.isRawMethod())
                genericsM.append(" isRawMethod"); //$NON-NLS-1$
            if (methodBinding.isGenericMethod())
                genericsM.append(" isGenericMethod"); //$NON-NLS-1$
            if (methodBinding.isParameterizedMethod())
                genericsM.append(" isParameterizedMethod"); //$NON-NLS-1$
            res.add(new BindingProperty(this, genericsM, true));

            res.add(new Binding(this, "METHOD DECLARATION", methodBinding.getMethodDeclaration(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "TYPE PARAMETERS", methodBinding.getTypeParameters(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "TYPE ARGUMENTS", methodBinding.getTypeArguments(), true)); //$NON-NLS-1$         
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$

            res.add(new BindingProperty(this, "IS ANNOTATION MEMBER", methodBinding.isAnnotationMember(), //$NON-NLS-1$
                    true));
            res.add(Binding.createValueAttribute(this, "DEFAULT VALUE", methodBinding.getDefaultValue()));

            int parameterCount = methodBinding.getParameterTypes().length;
            GeneralAttribute[] parametersAnnotations = new GeneralAttribute[parameterCount];
            for (int i = 0; i < parameterCount; i++) {
                parametersAnnotations[i] = new GeneralAttribute(this, "Parameter " + String.valueOf(i),
                        methodBinding.getParameterAnnotations(i));
            }
            res.add(new GeneralAttribute(this, "PARAMETER ANNOTATIONS", parametersAnnotations));
            break;

        case IBinding.ANNOTATION:
            IAnnotationBinding annotationBinding = (IAnnotationBinding) fBinding;
            res.add(new Binding(this, "ANNOTATION TYPE", annotationBinding.getAnnotationType(), true));
            res.add(new BindingProperty(this, "DECLARED MEMBER VALUE PAIRS",
                    annotationBinding.getDeclaredMemberValuePairs(), true));
            res.add(new BindingProperty(this, "ALL MEMBER VALUE PAIRS",
                    annotationBinding.getAllMemberValuePairs(), true));
            break;

        case IBinding.MEMBER_VALUE_PAIR:
            IMemberValuePairBinding memberValuePairBinding = (IMemberValuePairBinding) fBinding;
            res.add(new Binding(this, "METHOD BINDING", memberValuePairBinding.getMethodBinding(), true));
            res.add(new BindingProperty(this, "IS DEFAULT", memberValuePairBinding.isDefault(), true));
            res.add(Binding.createValueAttribute(this, "VALUE", memberValuePairBinding.getValue()));
            break;
        }
        try {
            IAnnotationBinding[] annotations = fBinding.getAnnotations();
            res.add(new BindingProperty(this, "ANNOTATIONS", annotations, true)); //$NON-NLS-1$
        } catch (RuntimeException e) {
            String label = "Error in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\"";
            res.add(new Error(this, label, e));
            ColoredIDEPlugin
                    .log("Exception thrown in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\"", e);
        }
        try {
            IJavaElement javaElement = fBinding.getJavaElement();
            res.add(new JavaElement(this, javaElement));
        } catch (RuntimeException e) {
            String label = ">java element: " + e.getClass().getName() + " for \"" + fBinding.getKey() + "\""; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            res.add(new Error(this, label, e));
            ColoredIDEPlugin
                    .log("Exception thrown in IBinding#getJavaElement() for \"" + fBinding.getKey() + "\"", e);
        }
        return res.toArray();
    }
    return EMPTY;
}

From source file:com.google.dart.java2dart.util.JavaUtils.java

License:Open Source License

/**
 * @param binding the {@link ITypeBinding} to analyze.
 * @param runtime flag <code>true</code> if we need name for class loading, <code>false</code> if
 *          we need name for source generation.
 * @param withGenerics flag <code>true</code> if generics type arguments should be appended.
 * @return the fully qualified name of given {@link ITypeBinding}, or
 *         {@link #NO_TYPE_BINDING_NAME} .
 *///from  w ww .  j av a  2  s .  c  om
public static String getFullyQualifiedName(ITypeBinding binding, boolean runtime, boolean withGenerics) {
    // check if no binding
    if (binding == null) {
        return NO_TYPE_BINDING_NAME;
    }
    // check for primitive type
    if (binding.isPrimitive()) {
        return binding.getName();
    }
    // array
    if (binding.isArray()) {
        StringBuilder sb = new StringBuilder();
        // append element type qualified name
        ITypeBinding elementType = binding.getElementType();
        String elementTypeQualifiedName = getFullyQualifiedName(elementType, runtime);
        sb.append(elementTypeQualifiedName);
        // append dimensions
        for (int i = 0; i < binding.getDimensions(); i++) {
            sb.append("[]");
        }
        // done
        return sb.toString();
    }
    // object
    {
        String scope;
        ITypeBinding declaringType = binding.getDeclaringClass();
        if (declaringType == null) {
            IPackageBinding packageBinding = binding.getPackage();
            if (packageBinding == null || packageBinding.isUnnamed()) {
                scope = "";
            } else {
                scope = packageBinding.getName() + ".";
            }
        } else if (binding.isTypeVariable()) {
            return binding.getName();
        } else {
            // use '$', because we use this class name for loading class
            scope = getFullyQualifiedName(declaringType, runtime);
            if (runtime) {
                scope += "$";
            } else {
                scope += ".";
            }
        }
        // prepare "simple" name, without scope
        String jdtName = binding.getName();
        String name = StringUtils.substringBefore(jdtName, "<");
        if (withGenerics) {
            ITypeBinding[] typeArguments = binding.getTypeArguments();
            if (typeArguments.length != 0) {
                StringBuilder sb = new StringBuilder(name);
                sb.append("<");
                for (ITypeBinding typeArgument : typeArguments) {
                    if (sb.charAt(sb.length() - 1) != '<') {
                        sb.append(",");
                    }
                    String typeArgumentName = getFullyQualifiedName(typeArgument, runtime, withGenerics);
                    sb.append(typeArgumentName);
                }
                sb.append(">");
                name = sb.toString();
            }
        }
        // qualified name is scope plus "simple" name
        return scope + name;
    }
}

From source file:com.google.devtools.j2cpp.translate.DeadCodeEliminator.java

License:Open Source License

/**
 * Create a new Type for the given type binding.  If the binding
 * represents a parameterized type reference, the returned Type
 * is a ParameterizedType with the same type parameters.  Otherwise
 * the returned Type is a SimpleType.//from w  w w  . j  av  a 2  s  .c om
 */
@SuppressWarnings("unchecked")
private Type createType(AST ast, ITypeBinding scope, ITypeBinding type) {
    Type newType;
    if (type.isArray()) {
        newType = ast.newArrayType(createType(ast, scope, type.getElementType()), type.getDimensions());
    } else if (type.isPrimitive()) {
        newType = ast.newPrimitiveType(PrimitiveType.toCode(type.getName()));
    } else if (type.isWildcardType()) {
        WildcardType wildType = ast.newWildcardType();
        ITypeBinding bound = type.getBound();
        if (bound != null) {
            wildType.setBound(createType(ast, scope, bound), type.isUpperbound());
        }
        newType = wildType;
    } else if (!type.isParameterizedType()) {
        String name = inScope(type, scope) ? type.getName() : type.getQualifiedName();
        newType = ast.newSimpleType(ast.newName(name));
    } else {
        ITypeBinding erasure = type.getErasure();
        String name = inScope(type, scope) ? erasure.getName() : erasure.getQualifiedName();
        Type rawType = ast.newSimpleType(ast.newName(name));
        ParameterizedType paramType = ast.newParameterizedType(rawType);
        ITypeBinding[] typeArgs = type.getTypeArguments();
        for (ITypeBinding param : typeArgs) {
            paramType.typeArguments().add(createType(ast, scope, param));
        }
        newType = paramType;
    }
    generatedTypes.put(newType, type);
    return newType;
}

From source file:com.google.devtools.j2cpp.translate.Rewriter.java

License:Open Source License

/**
 * Convert an array initializer into a init method on the equivalent
 * IOSArray. This init method takes a C array and count, like
 * NSArray.arrayWithObjects:count:. For example, "int[] a = { 1, 2, 3 };"
 * translates to "[IOSIntArray initWithInts:(int[]){ 1, 2, 3 } count:3];".
 *//*from  w ww.j  a  va2  s  .co  m*/
private MethodInvocation createIOSArrayInitializer(ITypeBinding arrayType, ArrayInitializer arrayInit) {
    AST ast = arrayInit.getAST();

    int dimensions = arrayType.getDimensions();
    ITypeBinding componentType;
    IOSArrayTypeBinding iosArrayBinding;
    if (dimensions > 2) {
        // This gets resolved into IOSObjectArray, for an array of arrays.
        componentType = iosArrayBinding = Types.resolveArrayType(arrayType);
    } else if (dimensions == 2) {
        // Creates a single-dimension array type.
        componentType = Types.resolveArrayType(arrayType.getElementType());
        iosArrayBinding = Types.resolveArrayType(componentType);
    } else {
        componentType = Types.getTypeBinding(arrayInit).getComponentType();
        iosArrayBinding = Types.resolveArrayType(componentType);
    }

    // Create IOS message.
    MethodInvocation message = ast.newMethodInvocation();
    SimpleName receiver = ast.newSimpleName(iosArrayBinding.getName());
    Types.addBinding(receiver, iosArrayBinding);
    message.setExpression(receiver);
    String methodName = iosArrayBinding.getInitMethod();
    SimpleName messageName = ast.newSimpleName(methodName);
    GeneratedMethodBinding methodBinding = new GeneratedMethodBinding(methodName,
            Modifier.PUBLIC | Modifier.STATIC, iosArrayBinding, iosArrayBinding, false, false, true);
    Types.addBinding(messageName, methodBinding);
    message.setName(messageName);
    Types.addBinding(message, methodBinding);

    // Pass array initializer as C-style array to message.
    @SuppressWarnings("unchecked")
    List<Expression> args = message.arguments(); // safe by definition
    ArrayInitializer newArrayInit = NodeCopier.copySubtree(ast, arrayInit);
    @SuppressWarnings("unchecked")
    List<Expression> exprs = newArrayInit.expressions();
    for (int i = 0; i < exprs.size(); i++) {
        // Convert any elements that are also array initializers.
        Expression expr = exprs.get(i);
        if (expr instanceof ArrayInitializer) {
            exprs.set(i, createIOSArrayInitializer(componentType, (ArrayInitializer) expr));
        }
    }
    args.add(newArrayInit);
    GeneratedVariableBinding argBinding = new GeneratedVariableBinding(arrayType, false, true, null,
            methodBinding);
    methodBinding.addParameter(argBinding);
    NumberLiteral arraySize = ast.newNumberLiteral(Integer.toString(arrayInit.expressions().size()));
    Types.addBinding(arraySize, ast.resolveWellKnownType("int"));
    args.add(arraySize);
    argBinding = new GeneratedVariableBinding(ast.resolveWellKnownType("int"), false, true, null,
            methodBinding);
    methodBinding.addParameter(argBinding);

    // Specify type for object arrays.
    if (iosArrayBinding.getName().equals("IOSObjectArray")) {
        TypeLiteral typeLiteral = ast.newTypeLiteral();
        typeLiteral.setType(Types.makeType(componentType));
        Types.addBinding(typeLiteral, Types.getIOSClass());
        args.add(typeLiteral);
        argBinding = new GeneratedVariableBinding("type", 0, Types.getIOSClass(), false, true, null,
                methodBinding);
        methodBinding.addParameter(argBinding);
    }

    return message;
}

From source file:com.google.devtools.j2objc.translate.ArrayRewriter.java

License:Apache License

private FunctionInvocation newTypeLiteralInvocation(ITypeBinding type) {
    assert type.isArray();
    ITypeBinding elementType = type.getElementType();
    ITypeBinding iosClassType = typeEnv.getIOSClass();
    String funcName = elementType.isPrimitive() ? String.format("IOSClass_%sArray", elementType.getName())
            : "IOSClass_arrayType";
    FunctionInvocation invocation = new FunctionInvocation(funcName, iosClassType, iosClassType, iosClassType);
    if (!elementType.isPrimitive()) {
        invocation.getArguments().add(new TypeLiteral(elementType, typeEnv));
    }/* w w w  .j a v a2 s  .  c o  m*/
    invocation.getArguments().add(NumberLiteral.newIntLiteral(type.getDimensions(), typeEnv));
    return invocation;
}

From source file:com.google.devtools.j2objc.util.NameTable.java

License:Open Source License

private String getParameterTypeKeyword(ITypeBinding type) {
    if (isIdType(type) || type.isTypeVariable()) {
        ITypeBinding[] bounds = type.getTypeBounds();
        if (bounds.length > 0) {
            return getParameterTypeKeyword(bounds[0]);
        }/*from ww w. jav a  2  s  .c  o  m*/
        return ID_TYPE;
    } else if (type.isPrimitive()) {
        return type.getName();
    } else if (type.isArray()) {
        return getArrayTypeParameterKeyword(type.getElementType(), type.getDimensions());
    }
    return getFullName(type);
}