Example usage for org.eclipse.jdt.core Flags toString

List of usage examples for org.eclipse.jdt.core Flags toString

Introduction

In this page you can find the example usage for org.eclipse.jdt.core Flags toString.

Prototype

public static String toString(int flags) 

Source Link

Document

Returns a standard string describing the given modifier flags.

Usage

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  w  w  .  j  a va 2 s.  co  m*/
            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));/*  ww w .  jav  a2s .  co  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.curlap.orb.plugin.generator.impl.CurlDataClassGeneratorImpl.java

License:Open Source License

protected List<Field> getAllSuperclassFields(Set<String> importPackages, String superclass)
        throws JavaModelException {
    List<Field> fields = new ArrayList<Field>();
    TypeNameMatch typeNameMatch = new JavaElementSearcher(iCompilationUnit).searchClassInfo(superclass);
    if (typeNameMatch == null)
        return fields;
    IType iType = typeNameMatch.getType();
    for (IField iField : iType.getFields()) {
        // skip static field
        if (Flags.isStatic(iField.getFlags()))
            continue;
        String name = iField.getElementName();
        Field field = new Field();
        field.setName(name);/*from  ww  w. j a v a2 s . co m*/
        field.setType(CurlSpecUtil.marshalCurlTypeWithSignature(
                addImportedPackageIfNecessaryWithSignature(importPackages, iField.getTypeSignature())));
        field.setDefaultValue(CurlSpecUtil.getDefaultValue(field.getType()));
        field.setIsTransient(Flags.isTransient(iField.getFlags()));
        String modifier = Flags.toString(iField.getFlags());
        if (modifier.length() == 0)
            modifier = "package";
        field.setGetterModifier(modifier + "-get");
        field.setSetterModifier(modifier + "-set");
        field.setComment("");
        fields.add(field);
    }
    // more superclasses
    if (iType.getSuperclassName() != null)
        fields.addAll(getAllSuperclassFields(importPackages, iType.getSuperclassName()));
    return fields;
}

From source file:com.curlap.orb.plugin.generator.impl.CurlDataClassGeneratorImpl.java

License:Open Source License

@Override
public VelocityContext generateClass() throws CurlGenerateException {
    ICompilationUnit source = iCompilationUnit;
    try {//  w  w w  . ja  v a  2s .c  om
        Set<String> importPackages = new HashSet<String>();
        List<Field> fields = new ArrayList<Field>();
        List<Field> superClassFields = null;

        String packageName = null;
        String className = null;
        String superClassName = null;
        JavadocContent classJavadoc = null;

        for (IType iType : source.getAllTypes()) {
            // package
            IPackageFragment iPackageFragment = iType.getPackageFragment();
            packageName = (iPackageFragment != null ? iPackageFragment.getElementName().toUpperCase() : "");

            // class name
            className = iType.getElementName();
            if (className == null)
                throw new CurlGenerateException("There is no class name.");

            // javadoc
            classJavadoc = JavaElementAnalyzer.getJavaDoc(iType);

            // superclass
            if (iType.getSuperclassName() != null) {
                superClassName = addImportedPackageIfNecessary(importPackages, iType.getSuperclassName());
                // fields of superclass
                superClassFields = getAllSuperclassFields(importPackages, superClassName);
            }

            // fields
            for (IField iField : iType.getFields()) {
                // skip static field
                if (Flags.isStatic(iField.getFlags()))
                    continue;
                String name = iField.getElementName();
                Field field = new Field();
                field.setName(name);
                field.setType(CurlSpecUtil.marshalCurlTypeWithSignature(
                        addImportedPackageIfNecessaryWithSignature(importPackages, iField.getTypeSignature())));
                field.setDefaultValue(CurlSpecUtil.getDefaultValue(field.getType()));
                field.setIsTransient(Flags.isTransient(iField.getFlags()));
                String modifier = CurlSpecUtil.getCurlModifier(Flags.toString(iField.getFlags()));
                field.setGetterModifier(modifier + "-get");
                field.setSetterModifier(modifier + "-set");
                field.setJavadocContent(JavaElementAnalyzer.getJavaDoc(iField));
                field.setComment((CurlSpecUtil.isCurlGenericsType(field.getType()) ? "|| "
                        + CurlSpecUtil.marshalCurlTypeWithSignature(addImportedPackageIfNecessaryWithSignature(
                                importPackages, iField.getTypeSignature()), true, true)
                        : ""));
                fields.add(field);
            }

            // methods 
            // NOTE: Extract getter and setter. The other methods is skipped.
            for (IMethod method : iType.getMethods()) {
                // skip static method
                if (Flags.isStatic(method.getFlags()))
                    continue;
                String name = method.getElementName();
                // getter into field
                if (CurlSpecUtil.isGetter(name)) {
                    if (method.getParameterNames().length == 0) {
                        String returnType = CurlSpecUtil.marshalCurlTypeWithSignature(
                                addImportedPackageIfNecessaryWithSignature(importPackages,
                                        method.getReturnType()));
                        String modifier = CurlSpecUtil.getCurlModifier(Flags.toString(method.getFlags()));
                        for (Field field : fields) {
                            String fieldName = CurlSpecUtil.getGetterOrSetterName(name);
                            if (fieldName.equals(field.getName()) && returnType.equals(field.getType()))
                                field.setGetterModifier(modifier + "-get");
                        }
                    }
                }
                // setter into field
                if (CurlSpecUtil.isSetter(name)) {
                    if (CurlSpecUtil.marshalCurlTypeWithSignature(method.getReturnType()).equals("void")
                            && method.getParameterNames().length == 1) {
                        String argumentType = CurlSpecUtil.marshalCurlTypeWithSignature(
                                addImportedPackageIfNecessaryWithSignature(importPackages,
                                        method.getParameterTypes()[0]));
                        String modifier = CurlSpecUtil.getCurlModifier(Flags.toString(method.getFlags()));
                        for (Field field : fields) {
                            String fieldName = CurlSpecUtil.getGetterOrSetterName(name);
                            if (fieldName.equals(field.getName()) && argumentType.equals(field.getType()))
                                field.setSetterModifier(modifier + "-set");
                        }
                    }
                }
            }
        }

        // merge to velocity.
        VelocityContext context = new VelocityContext();
        context.put("package_name", packageName);
        context.put("import_packages", importPackages);
        context.put("class_name", className);
        context.put("classJavadoc", classJavadoc);
        if (superClassName != null) {
            context.put("has_superclass", true);
            context.put("superclass_name", superClassName);
            context.put("superclass_fields", superClassFields);
        } else {
            context.put("has_superclass", false);
        }
        context.put("fields", fields);
        return context;
    } catch (JavaModelException e) {
        throw new CurlGenerateException(e);
    }
}

From source file:com.curlap.orb.plugin.generator.impl.CurlServiceClassGenerator.java

License:Open Source License

protected List<Method> getMethodsFromIType(IType iType, Set<String> importPackages,
        boolean returnTypeIsNullable) throws JavaModelException, IllegalArgumentException {
    // NOTE: Extract getter and setter. The other methods is skipped.
    List<Method> methods = new ArrayList<Method>();
    for (IMethod iMethod : iType.getMethods()) {
        // NOTE: generate only "public" method. 
        if (!Flags.toString(iMethod.getFlags()).equals("public"))
            continue;
        Method method = new Method();
        String methodName = iMethod.getElementName();
        method.setMethodName(methodName);
        method.setMethodName4Curl(CurlSpecUtil.marshalCurlName(methodName, true));
        boolean returnTypeOfMethodIsNullable = returnTypeIsNullable;
        if (returnTypeOfMethodIsNullable) {
            if (iMethod.getAnnotation("NotNull").exists())
                returnTypeOfMethodIsNullable = false;
        } else {//www. j  a v a  2 s.  c o  m
            if (iMethod.getAnnotation("Nullable").exists())
                returnTypeOfMethodIsNullable = true;
        }
        method.setMethodReturnType(CurlSpecUtil.marshalCurlTypeWithSignature(
                addImportedPackageIfNecessaryWithSignature(importPackages, iMethod.getReturnType()),
                returnTypeOfMethodIsNullable, false));
        String[] paramNames = iMethod.getParameterNames();
        String[] paramTypes = iMethod.getParameterTypes();
        StringBuffer buf = new StringBuffer();
        StringBuffer invokeBuf = new StringBuffer();
        for (int i = 0; i < paramNames.length; i++) {
            if (i != 0) {
                buf.append(", ");
                invokeBuf.append(", ");
            }
            String paramName = CurlSpecUtil.marshalCurlName(paramNames[i], true);
            buf.append(paramName);
            buf.append(':');
            buf.append(CurlSpecUtil.marshalCurlTypeWithSignature(
                    addImportedPackageIfNecessaryWithSignature(importPackages, paramTypes[i])));
            invokeBuf.append(paramName);
        }
        method.setMethodParams(buf.toString());
        method.setMethodArguments4Curl(invokeBuf.toString());
        methods.add(method);
    }
    return methods;
}

From source file:com.iw.plugins.spindle.ui.wizards.factories.ClassFactory.java

License:Mozilla Public License

private String constructTypeStub(ImportsManager imports, String lineDelimiter) {
    StringBuffer buf = new StringBuffer();

    int modifiers = fModifiers;
    buf.append(Flags.toString(modifiers));
    if (modifiers != 0) {
        buf.append(' ');
    }/*from w w w .  j  a v  a 2s  .c om*/
    //      buf.append(fIsClass ? "class " : "interface "); //$NON-NLS-2$
    // //$NON-NLS-1$
    buf.append("class");
    buf.append(fTypeName);
    writeSuperClass(buf, imports);
    writeSuperInterfaces(buf, imports);
    buf.append('{');
    buf.append(lineDelimiter);
    buf.append(lineDelimiter);
    buf.append('}');
    buf.append(lineDelimiter);
    return buf.toString();
}

From source file:es.bsc.servicess.ide.model.ServiceElement.java

License:Apache License

public IMethod generateElementMethodInType(IType t, boolean isInterface, IProgressMonitor arg0)
        throws JavaModelException {

    String signature = generateAnnotations(t, arg0);
    if (isInterface)
        signature = signature.concat(Flags.toString(Flags.AccPublic) + " ");
    else/*  w  w w. j  av a 2 s .  c om*/
        signature = signature.concat(Flags.toString(getMethodModifier()) + " ");

    String[] parameterTypes = new String[getParameters().size()];
    String[] parameterNames = new String[getParameters().size()];
    generateParametersAndReturn(t, parameterTypes, parameterNames, arg0);
    /*for (int i = 0; i < getParameters().size(); i++) {
       parameterNames[i] = getParameters().get(i).getName();
       parameterTypes[i] = getParameters().get(i).getTypeAsSignature();
       if (!parameterTypes[i].equals("Type.FILE")) {
    if (Signature.getTypeSignatureKind(parameterTypes[i]) == Signature.CLASS_TYPE_SIGNATURE) {
       if (!Signature.getQualifier(parameterTypes[i])
             .equalsIgnoreCase("java.lang")&& Signature.getQualifier(parameterTypes[i]).length()>0)) {
          if (t.getCompilationUnit().getImport(
                Signature.toString(parameterTypes[i])) == null) {
             t.getCompilationUnit().createImport(
                   Signature.toString(parameterTypes[i]),
                   null, Flags.AccDefault, arg0);
          } else if (!t
                .getCompilationUnit()
                .getImport(
                      Signature.toString(parameterTypes[i]))
                .exists()) {
             t.getCompilationUnit().createImport(
                   Signature.toString(parameterTypes[i]),
                   null, Flags.AccDefault, arg0);
          } else
             System.out.println(Signature
                   .toString(parameterTypes[i])
                   + " already exist in the import container");
       }
    }
       }
    }
    if (Signature.getTypeSignatureKind(getReturnTypeAsSignature()) == Signature.CLASS_TYPE_SIGNATURE) {
       if (!Signature.getQualifier(getReturnTypeAsSignature())
       .equalsIgnoreCase("java.lang")) {
    System.out.println("Return type: " + getReturnType());
    if (t.getCompilationUnit().getImport(getReturnType()) == null) {
       t.getCompilationUnit().createImport(getReturnType(), null,
             Flags.AccDefault, arg0);
    } else if (!t.getCompilationUnit().getImport(getReturnType())
          .exists()) {
       t.getCompilationUnit().createImport(getReturnType(), null,
             Flags.AccDefault, arg0);
    }
       }
    }*/

    String[] paramAnnotations = generateParametersAnnotations(t, parameterTypes, parameterNames, null, arg0);
    signature = signature.concat(createMethodSignature(getReturnTypeAsSignature(), this.getMethodName(),
            paramAnnotations, parameterTypes, parameterNames, true));
    if (isInterface) {
        signature = signature.concat(";");
    } else {
        signature = signature.concat("{\n\n}");
    }
    IMethod m = t.createMethod(signature, null, true, arg0);
    this.setMethodReference(m);
    return m;
}

From source file:es.bsc.servicess.ide.model.ServiceElement.java

License:Apache License

public IMethod generateSimpleMethodInType(IType t, boolean isInterface, String methodCode,
        IProgressMonitor arg0) throws JavaModelException {
    String signature = new String();
    if (isInterface)
        signature = signature.concat(Flags.toString(Flags.AccPublic) + " ");
    else//ww  w .  j av a2 s.c  o m
        signature = signature.concat(Flags.toString(getMethodModifier()) + " ");
    String[] parameterTypes = new String[getParameters().size()];
    String[] parameterNames = new String[getParameters().size()];
    generateParametersAndReturn(t, parameterTypes, parameterNames, arg0);
    /*for (int i = 0; i < getParameters().size(); i++) {
       parameterNames[i] = getParameters().get(i).getName();
       parameterTypes[i] = getParameters().get(i).getTypeAsSignature();
       if (!parameterTypes[i].equals("Type.FILE")) {
    if (Signature.getTypeSignatureKind(parameterTypes[i]) == Signature.CLASS_TYPE_SIGNATURE) {
       System.out.println("Type qualifier for parameter " + parameterNames[i] +" is "+ Signature.getQualifier(parameterTypes[i]));
       if (!Signature.getQualifier(parameterTypes[i])
             .equalsIgnoreCase("java.lang")&& Signature.getQualifier(parameterTypes[i]).length()>0)  {
          if (t.getCompilationUnit().getImport(
                Signature.toString(parameterTypes[i])) == null) {
             t.getCompilationUnit().createImport(
                   Signature.toString(parameterTypes[i]),
                   null, Flags.AccDefault, arg0);
          } else if (!t
                .getCompilationUnit()
                .getImport(
                      Signature.toString(parameterTypes[i]))
                .exists()) {
             t.getCompilationUnit().createImport(
                   Signature.toString(parameterTypes[i]),
                   null, Flags.AccDefault, arg0);
          } else
             System.out.println(Signature
                   .toString(parameterTypes[i])
                   + " already exist in the import container");
       }
    }
       }
    }
    if (Signature.getTypeSignatureKind(getReturnTypeAsSignature()) == Signature.CLASS_TYPE_SIGNATURE) {
       System.out.println("Type qualifier for parameter return type is "+ Signature.getQualifier(getReturnTypeAsSignature()));
       if (!Signature.getQualifier(getReturnTypeAsSignature())
       .equalsIgnoreCase("java.lang")&& Signature.getQualifier(getReturnTypeAsSignature()).length()>0) {
    System.out.println("Return type: " + getReturnType());
    if (t.getCompilationUnit().getImport(getReturnType()) == null) {
       t.getCompilationUnit().createImport(getReturnType(), null,
             Flags.AccDefault, arg0);
    } else if (!t.getCompilationUnit().getImport(getReturnType())
          .exists()) {
       t.getCompilationUnit().createImport(getReturnType(), null,
             Flags.AccDefault, arg0);
    }
       }
    }*/
    signature = signature.concat(createMethodSignature(getReturnTypeAsSignature(), this.getMethodName(), null,
            parameterTypes, parameterNames, true));
    if (isInterface) {
        signature = signature.concat(";");
    } else {
        signature = signature.concat("{\n" + methodCode + "\n}");
    }
    IMethod m = t.createMethod(signature, null, true, arg0);
    this.setMethodReference(m);
    return m;
}

From source file:fromastview.Binding.java

License:Open Source License

public Object[] getChildren() {
    if (fBinding != null) {
        ArrayList<ASTAttribute> res = new ArrayList<ASTAttribute>();
        res.add(new BindingProperty(this, "NAME", fBinding.getName(), true));
        res.add(new BindingProperty(this, "KEY", fBinding.getKey(), true));
        res.add(new BindingProperty(this, "IS RECOVERED", fBinding.isRecovered(), true));
        switch (fBinding.getKind()) {
        case IBinding.VARIABLE:
            IVariableBinding variableBinding = (IVariableBinding) fBinding;
            res.add(new BindingProperty(this, "IS FIELD", variableBinding.isField(), true));
            res.add(new BindingProperty(this, "IS ENUM CONSTANT", variableBinding.isEnumConstant(), true));
            res.add(new BindingProperty(this, "IS PARAMETER", variableBinding.isParameter(), true));
            res.add(new BindingProperty(this, "VARIABLE ID", variableBinding.getVariableId(), true));
            res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), true));
            res.add(new Binding(this, "TYPE", variableBinding.getType(), true));
            res.add(new Binding(this, "DECLARING CLASS", variableBinding.getDeclaringClass(), true));
            res.add(new Binding(this, "DECLARING METHOD", variableBinding.getDeclaringMethod(), true));
            res.add(new Binding(this, "VARIABLE DECLARATION", variableBinding.getVariableDeclaration(), true));
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true));
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true));
            res.add(new BindingProperty(this, "CONSTANT VALUE", variableBinding.getConstantValue(), true)); //$NON-NLS-2$
            break;
        case IBinding.PACKAGE:
            IPackageBinding packageBinding = (IPackageBinding) fBinding;
            res.add(new BindingProperty(this, "IS UNNAMED", packageBinding.isUnnamed(), true));
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true));
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true));
            break;
        case IBinding.TYPE:
            ITypeBinding typeBinding = (ITypeBinding) fBinding;
            res.add(new BindingProperty(this, "QUALIFIED NAME", typeBinding.getQualifiedName(), true));
            int typeKind = getTypeKind(typeBinding);
            boolean isRefType = isType(typeKind, REF_TYPE);
            final boolean isNonPrimitive = !isType(typeKind, PRIMITIVE_TYPE);

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

            StringBuffer generics = new StringBuffer("GENERICS:");
            if (typeBinding.isRawType())
                generics.append(" isRawType");
            if (typeBinding.isGenericType())
                generics.append(" isGenericType");
            if (typeBinding.isParameterizedType())
                generics.append(" isParameterizedType");
            if (!isType(typeKind, GENERIC | PARAMETRIZED)) {
                generics.append(" (non-generic, non-parameterized)");
            }//from   w  w  w  . ja  v a  2s. co m
            res.add(new BindingProperty(this, generics, isRefType));

            res.add(new Binding(this, "ELEMENT TYPE", typeBinding.getElementType(),
                    isType(typeKind, ARRAY_TYPE)));
            res.add(new Binding(this, "COMPONENT TYPE", typeBinding.getComponentType(),
                    isType(typeKind, ARRAY_TYPE)));
            res.add(new BindingProperty(this, "DIMENSIONS", typeBinding.getDimensions(),
                    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(),
                    isType(typeKind, VARIABLE_TYPE | CAPTURE_TYPE)));

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

            res.add(new BindingProperty(this, "IS FROM SOURCE", typeBinding.isFromSource(),
                    isType(typeKind, REF_TYPE | VARIABLE_TYPE | CAPTURE_TYPE)));

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

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

            res.add(new Binding(this, "SUPERCLASS", typeBinding.getSuperclass(), isRefType));
            res.add(new BindingProperty(this, "INTERFACES", typeBinding.getInterfaces(), isRefType));
            res.add(new BindingProperty(this, "DECLARED TYPES", typeBinding.getDeclaredTypes(), isRefType));
            res.add(new BindingProperty(this, "DECLARED FIELDS", typeBinding.getDeclaredFields(), isRefType));
            res.add(new BindingProperty(this, "DECLARED METHODS", typeBinding.getDeclaredMethods(), isRefType));
            res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), isNonPrimitive));
            res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), isRefType));
            break;
        case IBinding.METHOD:
            IMethodBinding methodBinding = (IMethodBinding) fBinding;
            res.add(new BindingProperty(this, "IS CONSTRUCTOR", methodBinding.isConstructor(), true));
            res.add(new BindingProperty(this, "IS DEFAULT CONSTRUCTOR", methodBinding.isDefaultConstructor(),
                    true));
            res.add(new Binding(this, "DECLARING CLASS", methodBinding.getDeclaringClass(), true));
            res.add(new Binding(this, "RETURN TYPE", methodBinding.getReturnType(), true));
            res.add(new BindingProperty(this, "MODIFIERS", Flags.toString(fBinding.getModifiers()), true));
            res.add(new BindingProperty(this, "PARAMETER TYPES", methodBinding.getParameterTypes(), true));
            res.add(new BindingProperty(this, "IS VARARGS", methodBinding.isVarargs(), true));
            res.add(new BindingProperty(this, "EXCEPTION TYPES", methodBinding.getExceptionTypes(), true));

            StringBuffer genericsM = new StringBuffer("GENERICS:");
            if (methodBinding.isRawMethod())
                genericsM.append(" isRawMethod");
            if (methodBinding.isGenericMethod())
                genericsM.append(" isGenericMethod");
            if (methodBinding.isParameterizedMethod())
                genericsM.append(" isParameterizedMethod");
            res.add(new BindingProperty(this, genericsM, true));

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

            res.add(new BindingProperty(this, "IS ANNOTATION MEMBER", methodBinding.isAnnotationMember(),
                    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));
        } catch (RuntimeException e) {
            String label = "Error in IBinding#getAnnotations() for \"" + fBinding.getKey() + "\"";
            res.add(new Error(this, label, 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() + "\"";
            res.add(new Error(this, label, e));
        }
        return res.toArray();
    }
    return EMPTY;
}

From source file:org.eclipse.ajdt.internal.ui.wizards.NewTypeWizardPage.java

License:Open Source License

private String constructTypeStub(ICompilationUnit parentCU, ImportsManager imports, String lineDelimiter)
        throws CoreException {
    StringBuffer buf = new StringBuffer();

    int modifiers = getModifiers();
    buf.append(Flags.toString(modifiers));
    if (modifiers != 0) {
        buf.append(' ');
    }//from   ww  w  . j ava  2  s  .  c  o m
    String type = ""; //$NON-NLS-1$
    String templateID = ""; //$NON-NLS-1$
    switch (fTypeKind) {
    case CLASS_TYPE:
        type = "class "; //$NON-NLS-1$
        templateID = CodeGeneration.CLASS_BODY_TEMPLATE_ID;
        break;
    case INTERFACE_TYPE:
        type = "interface "; //$NON-NLS-1$
        templateID = CodeGeneration.INTERFACE_BODY_TEMPLATE_ID;
        break;
    case ENUM_TYPE:
        type = "enum "; //$NON-NLS-1$
        templateID = CodeGeneration.ENUM_BODY_TEMPLATE_ID;
        break;
    case ANNOTATION_TYPE:
        type = "@interface "; //$NON-NLS-1$
        templateID = CodeGeneration.ANNOTATION_BODY_TEMPLATE_ID;
        break;
    }
    buf.append(type);
    buf.append(getTypeName());
    writeSuperClass(buf, imports);
    writeSuperInterfaces(buf, imports);

    buf.append(" {").append(lineDelimiter); //$NON-NLS-1$
    String typeBody = CodeGeneration.getTypeBody(templateID, parentCU, getTypeName(), lineDelimiter);
    if (typeBody != null) {
        buf.append(typeBody);
    } else {
        buf.append(lineDelimiter);
    }
    buf.append('}').append(lineDelimiter);
    return buf.toString();
}