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

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

Introduction

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

Prototype

public String getBinaryName();

Source Link

Document

Returns the binary name of this type binding.

Usage

From source file:astview.Binding.java

License:Open Source License

@Override
public Object[] getChildren() {
    try {//from w w w. j  av a2s  .co  m
        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.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private IDSModel processComponent(TypeDeclaration type, ITypeBinding typeBinding, Annotation annotation,
        IAnnotationBinding annotationBinding, Collection<DSAnnotationProblem> problems) {
    HashMap<String, Object> params = new HashMap<String, Object>();
    for (IMemberValuePairBinding pair : annotationBinding.getDeclaredMemberValuePairs()) {
        params.put(pair.getName(), pair.getValue());
    }// w  w w. j  a  v a 2  s  .c o  m

    boolean requiresV12 = false;

    String implClass = typeBinding.getBinaryName();

    String name = implClass;
    Object value;
    if ((value = params.get("name")) instanceof String) { //$NON-NLS-1$
        name = (String) value;
        validateComponentName(annotation, name, problems);
    }

    Collection<String> services;
    if ((value = params.get("service")) instanceof Object[]) { //$NON-NLS-1$
        Object[] elements = (Object[]) value;
        services = new LinkedHashSet<String>(elements.length);
        Map<String, Integer> serviceDuplicates = errorLevel.isNone() ? null : new HashMap<String, Integer>();
        for (int i = 0; i < elements.length; ++i) {
            ITypeBinding serviceType = (ITypeBinding) elements[i];
            String serviceName = serviceType.getBinaryName();
            if (!errorLevel.isNone()) {
                if (serviceDuplicates.containsKey(serviceName)) {
                    reportProblem(annotation, "service", i, problems, //$NON-NLS-1$
                            Messages.AnnotationProcessor_duplicateServiceDeclaration, serviceName);
                    Integer pos = serviceDuplicates.put(serviceName, null);
                    if (pos != null)
                        reportProblem(annotation, "service", pos.intValue(), problems, //$NON-NLS-1$
                                Messages.AnnotationProcessor_duplicateServiceDeclaration, serviceName);
                } else {
                    serviceDuplicates.put(serviceName, i);
                }
            }

            services.add(serviceName);
            validateComponentService(annotation, typeBinding, serviceType, i, problems);
        }
    } else {
        ITypeBinding[] serviceTypes = typeBinding.getInterfaces();
        services = new ArrayList<String>(serviceTypes.length);
        for (int i = 0; i < serviceTypes.length; ++i) {
            services.add(serviceTypes[i].getBinaryName());
        }
    }

    String factory = null;
    if ((value = params.get("factory")) instanceof String) { //$NON-NLS-1$
        factory = (String) value;
        validateComponentFactory(annotation, factory, problems);
    }

    Boolean serviceFactory = null;
    if ((value = params.get("servicefactory")) instanceof Boolean) { //$NON-NLS-1$
        serviceFactory = (Boolean) value;
    }

    Boolean enabled = null;
    if ((value = params.get("enabled")) instanceof Boolean) { //$NON-NLS-1$
        enabled = (Boolean) value;
    }

    Boolean immediate = null;
    if ((value = params.get("immediate")) instanceof Boolean) { //$NON-NLS-1$
        immediate = (Boolean) value;
    }

    String[] properties;
    if ((value = params.get("property")) instanceof Object[]) { //$NON-NLS-1$
        Object[] elements = (Object[]) value;
        ArrayList<String> list = new ArrayList<String>(elements.length);
        for (int i = 0; i < elements.length; ++i) {
            if (elements[i] instanceof String)
                list.add((String) elements[i]);
        }

        properties = list.toArray(new String[list.size()]);
    } else {
        properties = new String[0];
    }

    String[] propertyFiles;
    if ((value = params.get("properties")) instanceof Object[]) { //$NON-NLS-1$
        Object[] elements = (Object[]) value;
        ArrayList<String> list = new ArrayList<String>(elements.length);
        for (int i = 0; i < elements.length; ++i) {
            if (elements[i] instanceof String)
                list.add((String) elements[i]);
        }

        propertyFiles = list.toArray(new String[list.size()]);
        validateComponentPropertyFiles(annotation,
                ((IType) typeBinding.getJavaElement()).getJavaProject().getProject(), propertyFiles, problems);
    } else {
        propertyFiles = new String[0];
    }

    String configPolicy = null;
    if ((value = params.get("configurationPolicy")) instanceof IVariableBinding) { //$NON-NLS-1$
        IVariableBinding configPolicyBinding = (IVariableBinding) value;
        ConfigurationPolicy configPolicyLiteral = ConfigurationPolicy.valueOf(configPolicyBinding.getName());
        if (configPolicyLiteral != null)
            configPolicy = configPolicyLiteral.toString();
    }

    String configPid = null;
    if ((value = params.get("configurationPid")) instanceof String) { //$NON-NLS-1$
        configPid = (String) value;
        validateComponentConfigPID(annotation, configPid, problems);
        requiresV12 = true;
    }

    DSModel model = new DSModel(new Document(), false);
    IDSComponent component = model.getDSComponent();

    if (name != null)
        component.setAttributeName(name);

    if (factory != null)
        component.setFactory(factory);

    if (enabled != null)
        component.setEnabled(enabled.booleanValue());

    if (immediate != null)
        component.setImmediate(immediate.booleanValue());

    if (configPolicy != null)
        component.setConfigurationPolicy(configPolicy);

    if (configPid != null)
        component.setXMLAttribute("configuration-pid", configPid); //$NON-NLS-1$

    IDSDocumentFactory dsFactory = component.getModel().getFactory();
    IDSImplementation impl = dsFactory.createImplementation();
    component.setImplementation(impl);
    impl.setClassName(implClass);

    if (!services.isEmpty()) {
        IDSService service = dsFactory.createService();
        component.setService(service);
        for (String serviceName : services) {
            IDSProvide provide = dsFactory.createProvide();
            service.addProvidedService(provide);
            provide.setInterface(serviceName);
        }

        if (serviceFactory != null)
            service.setServiceFactory(serviceFactory.booleanValue());
    }

    if (properties.length > 0) {
        HashMap<String, IDSProperty> map = new HashMap<String, IDSProperty>(properties.length);
        for (int i = 0; i < properties.length; ++i) {
            String propertyStr = properties[i];
            String[] pair = propertyStr.split("=", 2); //$NON-NLS-1$
            int colon = pair[0].indexOf(':');
            String propertyName, propertyType;
            if (colon == -1) {
                propertyName = pair[0];
                propertyType = null;
            } else {
                propertyName = pair[0].substring(0, colon);
                propertyType = pair[0].substring(colon + 1);
            }

            String propertyValue = pair.length > 1 ? pair[1].trim() : null;

            IDSProperty property = map.get(propertyName);
            if (property == null) {
                // create a new property
                property = dsFactory.createProperty();
                component.addPropertyElement(property);
                map.put(propertyName, property);
                property.setPropertyName(propertyName);
                property.setPropertyType(propertyType);
                property.setPropertyValue(propertyValue);
                validateComponentProperty(annotation, propertyName, propertyType, propertyValue, i, problems);
            } else {
                // property exists; make it multi-valued
                String content = property.getPropertyElemBody();
                if (content == null) {
                    content = property.getPropertyValue();
                    property.setPropertyElemBody(content);
                    property.setPropertyValue(null);
                }

                if (!errorLevel.isNone()) {
                    String expected = property.getPropertyType() == null || property.getPropertyType().isEmpty()
                            || String.class.getSimpleName().equals(property.getPropertyType())
                                    ? Messages.AnnotationProcessor_stringOrEmpty
                                    : property.getPropertyType();
                    String actual = propertyType == null || String.class.getSimpleName().equals(propertyType)
                            ? Messages.AnnotationProcessor_stringOrEmpty
                            : propertyType;
                    if (!actual.equals(expected))
                        reportProblem(annotation, "property", i, problems, //$NON-NLS-1$
                                NLS.bind(Messages.AnnotationProcessor_inconsistentComponentPropertyType, actual,
                                        expected),
                                actual);
                    else
                        validateComponentProperty(annotation, propertyName, propertyType, propertyValue, i,
                                problems);
                }

                if (propertyValue != null)
                    property.setPropertyElemBody(content + "\n" + pair[1]); //$NON-NLS-1$
            }
        }
    }

    if (propertyFiles.length > 0) {
        for (String propertyFile : propertyFiles) {
            IDSProperties propertiesElement = dsFactory.createProperties();
            component.addPropertiesElement(propertiesElement);
            propertiesElement.setEntry(propertyFile);
        }
    }

    String activate = null;
    Annotation activateAnnotation = null;
    String deactivate = null;
    Annotation deactivateAnnotation = null;
    String modified = null;
    Annotation modifiedAnnotation = null;

    ArrayList<IDSReference> references = new ArrayList<IDSReference>();
    HashMap<String, Annotation> referenceNames = new HashMap<String, Annotation>();

    for (MethodDeclaration method : type.getMethods()) {
        for (Object modifier : method.modifiers()) {
            if (!(modifier instanceof Annotation))
                continue;

            Annotation methodAnnotation = (Annotation) modifier;
            IAnnotationBinding methodAnnotationBinding = methodAnnotation.resolveAnnotationBinding();
            if (methodAnnotationBinding == null) {
                if (debug.isDebugging())
                    debug.trace(
                            String.format("Unable to resolve binding for annotation: %s", methodAnnotation)); //$NON-NLS-1$

                continue;
            }

            String annotationName = methodAnnotationBinding.getAnnotationType().getQualifiedName();

            if (ACTIVATE_ANNOTATION.equals(annotationName)) {
                if (activate == null) {
                    activate = method.getName().getIdentifier();
                    activateAnnotation = methodAnnotation;
                    validateLifeCycleMethod(methodAnnotation, "activate", method, problems); //$NON-NLS-1$
                } else if (!errorLevel.isNone()) {
                    reportProblem(methodAnnotation, null, problems,
                            Messages.AnnotationProcessor_duplicateActivateMethod,
                            method.getName().getIdentifier());
                    if (activateAnnotation != null) {
                        reportProblem(activateAnnotation, null, problems,
                                Messages.AnnotationProcessor_duplicateActivateMethod, activate);
                        activateAnnotation = null;
                    }
                }

                continue;
            }

            if (DEACTIVATE_ANNOTATION.equals(annotationName)) {
                if (deactivate == null) {
                    deactivate = method.getName().getIdentifier();
                    deactivateAnnotation = methodAnnotation;
                    validateLifeCycleMethod(methodAnnotation, "deactivate", method, problems); //$NON-NLS-1$
                } else if (!errorLevel.isNone()) {
                    reportProblem(methodAnnotation, null, problems,
                            Messages.AnnotationProcessor_duplicateDeactivateMethod,
                            method.getName().getIdentifier());
                    if (deactivateAnnotation != null) {
                        reportProblem(deactivateAnnotation, null, problems,
                                Messages.AnnotationProcessor_duplicateDeactivateMethod, deactivate);
                        deactivateAnnotation = null;
                    }
                }

                continue;
            }

            if (MODIFIED_ANNOTATION.equals(annotationName)) {
                if (modified == null) {
                    modified = method.getName().getIdentifier();
                    modifiedAnnotation = methodAnnotation;
                    validateLifeCycleMethod(methodAnnotation, "modified", method, problems); //$NON-NLS-1$
                } else if (!errorLevel.isNone()) {
                    reportProblem(methodAnnotation, null, problems,
                            Messages.AnnotationProcessor_duplicateModifiedMethod,
                            method.getName().getIdentifier());
                    if (modifiedAnnotation != null) {
                        reportProblem(modifiedAnnotation, null, problems,
                                Messages.AnnotationProcessor_duplicateModifiedMethod, modified);
                        modifiedAnnotation = null;
                    }
                }

                continue;
            }

            if (REFERENCE_ANNOTATION.equals(annotationName)) {
                IMethodBinding methodBinding = method.resolveBinding();
                if (methodBinding == null) {
                    if (debug.isDebugging())
                        debug.trace(String.format("Unable to resolve binding for method: %s", method)); //$NON-NLS-1$
                } else {
                    requiresV12 |= processReference(method, methodBinding, methodAnnotation,
                            methodAnnotationBinding, dsFactory, references, referenceNames, problems);
                }

                continue;
            }
        }
    }

    if (activate != null)
        component.setActivateMethod(activate);

    if (deactivate != null)
        component.setDeactivateMethod(deactivate);

    if (modified != null)
        component.setModifiedeMethod(modified);

    if (!references.isEmpty()) {
        // references must be declared in ascending lexicographical order of their names
        Collections.sort(references, REF_NAME_COMPARATOR);
        for (IDSReference reference : references) {
            component.addReference(reference);
        }
    }

    String xmlns = null;
    if ((value = params.get("xmlns")) instanceof String) { //$NON-NLS-1$
        xmlns = (String) value;
        validateComponentXMLNS(annotation, xmlns, requiresV12, problems);
    } else if (requiresV12) {
        xmlns = NAMESPACE_1_2;
    }

    if (xmlns != null)
        component.setNamespace(xmlns);

    return model;
}

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private boolean processReference(MethodDeclaration method, IMethodBinding methodBinding, Annotation annotation,
        IAnnotationBinding annotationBinding, IDSDocumentFactory factory, Collection<IDSReference> collector,
        Map<String, Annotation> names, Collection<DSAnnotationProblem> problems) {
    HashMap<String, Object> params = new HashMap<String, Object>();
    for (IMemberValuePairBinding pair : annotationBinding.getDeclaredMemberValuePairs()) {
        params.put(pair.getName(), pair.getValue());
    }//ww  w  .  j  a va  2s  . c  o  m

    boolean requiresV12 = false;

    ITypeBinding[] argTypes = methodBinding.getParameterTypes();

    ITypeBinding serviceType;
    Object value;
    if ((value = params.get("service")) instanceof ITypeBinding) { //$NON-NLS-1$
        serviceType = (ITypeBinding) value;
        if (!errorLevel.isNone() && argTypes.length > 0) {
            ITypeBinding[] typeArgs;
            if (!(ServiceReference.class.getName().equals(argTypes[0].getErasure().getQualifiedName())
                    && ((typeArgs = argTypes[0].getTypeArguments()).length == 0
                            || serviceType.isAssignmentCompatible(typeArgs[0])))
                    && !serviceType.isAssignmentCompatible(argTypes[0]))
                reportProblem(annotation, "service", problems, //$NON-NLS-1$
                        NLS.bind(Messages.AnnotationProcessor_invalidReferenceService, argTypes[0].getName(),
                                serviceType.getName()),
                        serviceType.getName());
        }
    } else if (argTypes.length > 0) {
        if (ServiceReference.class.getName().equals(argTypes[0].getErasure().getQualifiedName())) {
            ITypeBinding[] typeArgs = argTypes[0].getTypeArguments();
            if (typeArgs.length > 0)
                serviceType = typeArgs[0];
            else
                serviceType = null;
        } else {
            serviceType = argTypes[0].isPrimitive() ? getObjectType(method.getAST(), argTypes[0]) : argTypes[0];
        }
    } else {
        serviceType = null;
    }

    if (serviceType == null) {
        reportProblem(annotation, null, problems, Messages.AnnotationProcessor_invalidReferenceServiceUnknown);

        serviceType = method.getAST().resolveWellKnownType(Object.class.getName());
    }

    validateReferenceBindMethod(annotation, serviceType, methodBinding, problems);

    String service = serviceType == null ? null : serviceType.getBinaryName();

    String methodName = methodBinding.getName();
    String name;
    if ((value = params.get("name")) instanceof String) { //$NON-NLS-1$
        name = (String) value;
    } else if (methodName.startsWith("bind")) { //$NON-NLS-1$
        name = methodName.substring("bind".length()); //$NON-NLS-1$
    } else if (methodName.startsWith("set")) { //$NON-NLS-1$
        name = methodName.substring("set".length()); //$NON-NLS-1$
    } else if (methodName.startsWith("add")) { //$NON-NLS-1$
        name = methodName.substring("add".length()); //$NON-NLS-1$
    } else {
        name = methodName;
    }

    if (!errorLevel.isNone()) {
        if (names.containsKey(name)) {
            reportProblem(annotation, "name", problems, //$NON-NLS-1$
                    NLS.bind(Messages.AnnotationProcessor_duplicateReferenceName, name), name);
            Annotation duplicate = names.put(name, null);
            if (duplicate != null)
                reportProblem(duplicate, "name", problems, //$NON-NLS-1$
                        NLS.bind(Messages.AnnotationProcessor_duplicateReferenceName, name), name);
        } else {
            names.put(name, annotation);
        }
    }

    String cardinality = null;
    if ((value = params.get("cardinality")) instanceof IVariableBinding) { //$NON-NLS-1$
        IVariableBinding cardinalityBinding = (IVariableBinding) value;
        ReferenceCardinality cardinalityLiteral = ReferenceCardinality.valueOf(cardinalityBinding.getName());
        if (cardinalityLiteral != null)
            cardinality = cardinalityLiteral.toString();
    }

    String policy = null;
    if ((value = params.get("policy")) instanceof IVariableBinding) { //$NON-NLS-1$
        IVariableBinding policyBinding = (IVariableBinding) value;
        ReferencePolicy policyLiteral = ReferencePolicy.valueOf(policyBinding.getName());
        if (policyLiteral != null)
            policy = policyLiteral.toString();
    }

    String target = null;
    if ((value = params.get("target")) instanceof String) { //$NON-NLS-1$
        target = (String) value;
        validateReferenceTarget(annotation, target, problems);
    }

    String unbind;
    if ((value = params.get("unbind")) instanceof String) { //$NON-NLS-1$
        String unbindValue = (String) value;
        if ("-".equals(unbindValue)) { //$NON-NLS-1$
            unbind = null;
        } else {
            unbind = unbindValue;
            if (!errorLevel.isNone() && serviceType != null) {
                IMethodBinding unbindMethod = findReferenceMethod(methodBinding.getDeclaringClass(),
                        serviceType, unbind);
                if (unbindMethod == null)
                    reportProblem(annotation, "unbind", problems, //$NON-NLS-1$
                            NLS.bind(Messages.AnnotationProcessor_invalidReferenceUnbind, unbind), unbind);
            }
        }
    } else if (serviceType != null) {
        String unbindCandidate;
        if (methodName.startsWith("add")) { //$NON-NLS-1$
            unbindCandidate = "remove" + methodName.substring("add".length()); //$NON-NLS-1$ //$NON-NLS-2$
        } else {
            unbindCandidate = "un" + methodName; //$NON-NLS-1$
        }

        IMethodBinding unbindMethod = findReferenceMethod(methodBinding.getDeclaringClass(), serviceType,
                unbindCandidate);
        if (unbindMethod == null)
            unbind = null;
        else
            unbind = unbindMethod.getName();
    } else {
        unbind = null;
    }

    String policyOption = null;
    if ((value = params.get("policyOption")) instanceof IVariableBinding) { //$NON-NLS-1$
        IVariableBinding policyOptionBinding = (IVariableBinding) value;
        ReferencePolicyOption policyOptionLiteral = ReferencePolicyOption
                .valueOf(policyOptionBinding.getName());
        if (policyOptionLiteral != null) {
            policyOption = policyOptionLiteral.toString();
            requiresV12 = true;
        }
    }

    String updated;
    if ((value = params.get("updated")) instanceof String) { //$NON-NLS-1$
        String updatedValue = (String) value;
        if ("-".equals(updatedValue)) { //$NON-NLS-1$
            updated = null;
        } else {
            updated = updatedValue;
            if (!errorLevel.isNone() && serviceType != null) {
                IMethodBinding updatedMethod = findReferenceMethod(methodBinding.getDeclaringClass(),
                        serviceType, updated);
                if (updatedMethod == null)
                    reportProblem(annotation, "updated", problems, //$NON-NLS-1$
                            NLS.bind(Messages.AnnotationProcessor_invalidReferenceUpdated, updated), updated);
            }
        }

        requiresV12 = true;
    } else if (serviceType != null) {
        String updatedCandidate;
        if (methodName.startsWith("bind")) { //$NON-NLS-1$
            updatedCandidate = "updated" + methodName.substring("bind".length()); //$NON-NLS-1$ //$NON-NLS-2$
        } else if (methodName.startsWith("set")) { //$NON-NLS-1$
            updatedCandidate = "updated" + methodName.substring("set".length()); //$NON-NLS-1$ //$NON-NLS-2$
        } else if (methodName.startsWith("add")) { //$NON-NLS-1$
            updatedCandidate = "updated" + methodName.substring("add".length()); //$NON-NLS-1$ //$NON-NLS-2$
        } else {
            updatedCandidate = "updated" + methodName; //$NON-NLS-1$
        }

        IMethodBinding updatedMethod = findReferenceMethod(methodBinding.getDeclaringClass(), serviceType,
                updatedCandidate);
        if (updatedMethod == null)
            updated = null;
        else
            updated = updatedMethod.getName();
    } else {
        updated = null;
    }

    IDSReference reference = factory.createReference();
    collector.add(reference);

    reference.setReferenceBind(methodName);

    if (name != null)
        reference.setReferenceName(name);

    if (service != null)
        reference.setReferenceInterface(service);

    if (cardinality != null)
        reference.setReferenceCardinality(cardinality);

    if (policy != null)
        reference.setReferencePolicy(policy);

    if (target != null)
        reference.setReferenceTarget(target);

    if (unbind != null)
        reference.setReferenceUnbind(unbind);

    if (policyOption != null)
        reference.setXMLAttribute("policy-option", policyOption); //$NON-NLS-1$

    if (updated != null)
        reference.setXMLAttribute("updated", updated); //$NON-NLS-1$

    return requiresV12;
}

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

License:Open Source License

/**
 * Converts a type binding to a class element or an enum element.
 * // w ww  . ja v  a2 s  .  com
 * @param pBinding
 *            The binding to convert. Cannot be null.
 * @return A class or enum element representing this binding. Cannot be
 *         null.
 */
private static IElement convertBinding(final ITypeBinding pBinding) {
    ASTCrawler.checkForNull(pBinding);
    IJavaElement elem = null;
    try {
        elem = pBinding.getJavaElement();
    } catch (final NullPointerException E) {
        System.out.println("Bug in eclipse encountered for: " + pBinding.getName());
        return null;
    }
    return FlyweightElementFactory.getElement(Category.CLASS, pBinding.getBinaryName());
}

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 v  a2s . 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();
    }/* w w w. ja va  2  s.  c  om*/
    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:changetypes.ASTVisitorAtomicChange.java

License:Open Source License

private static String getSimpleName(ITypeBinding itb) {
    if (itb.isNested()) {
        if (itb.isAnonymous()) {
            String binname = itb.getBinaryName();
            int index = binname.indexOf('$');
            String name = binname.substring(index + 1, binname.length());
            return getSimpleName(itb.getDeclaringClass()) + "#" + name;
        }/*  w ww.jav  a2 s  .co m*/
        return getSimpleName(itb.getDeclaringClass()) + "#" + itb.getName();
    }
    return itb.getName();
}

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  .j a  v a  2s . 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));//from w  ww  .j av a2  s.  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.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

/**
 * Converts a string concatenation expression into a NSString format string and a
 * list of arguments for it, containing all the non-literal expressions.  If the
 * expression is all literals, then a string concatenation is printed.  If not,
 * then a NSString stringWithFormat: message is output.
 *///from  ww w .  ja va2s. c  o  m
@SuppressWarnings("fallthrough")
private void printStringConcatenation(Expression leftOperand, Expression rightOperand,
        List<Expression> extendedOperands, boolean needRetainRhs) {
    // Copy all operands into a single list.
    List<Expression> operands = Lists.newArrayList(leftOperand, rightOperand);
    operands.addAll(extendedOperands);

    String format = "@\"";
    List<Expression> args = Lists.newArrayList();
    for (Expression operand : operands) {
        if (operand instanceof BooleanLiteral || operand instanceof CharacterLiteral
                || operand instanceof NullLiteral) {
            format += operand.toString();
        } else if (operand instanceof StringLiteral) {
            StringLiteral literal = (StringLiteral) operand;
            if (isValidCppString(literal)) {
                String s = (((StringLiteral) operand).getEscapedValue());
                s = s.substring(1, s.length() - 1); // remove surrounding double-quotes
                s = UnicodeUtils.escapeUnicodeSequences(s);
                format += s.replace("%", "%%"); // escape % character
            } else {
                // Convert to NSString invocation when printing args.
                format += "%@";
                args.add(operand);
            }
        } else if (operand instanceof NumberLiteral) {
            format += ((NumberLiteral) operand).getToken();
        } else {
            args.add(operand);

            // Append format specifier.
            ITypeBinding operandType = Types.getTypeBinding(operand);
            if (operandType.isPrimitive()) {
                String type = operandType.getBinaryName();
                assert type.length() == 1;
                switch (type.charAt(0)) {
                case 'B': // byte
                case 'I': // int
                case 'S': // short
                    format += "%d";
                    break;
                case 'J': // long
                    format += "%qi";
                    break;
                case 'D': // double
                case 'F': // float
                    format += "%f";
                    break;
                case 'C': // char
                    format += "%c";
                    break;
                case 'Z': // boolean
                    format += "%@";
                    break;
                default:
                    throw new AssertionError("unknown primitive type: " + type);
                }
            } else {
                format += "%@";
            }
        }
    }
    format += '"';

    if (args.isEmpty()) {
        buffer.append(format.replace("%%", "%")); // unescape % character
        return;
    }

    if (needRetainRhs) {
        buffer.append("[[NSString alloc] initWithFormat:");
    } else {
        buffer.append("[NSString stringWithFormat:");
    }
    buffer.append(format);
    buffer.append(", ");
    for (Iterator<Expression> iter = args.iterator(); iter.hasNext();) {
        Expression arg = iter.next();
        if (Types.getTypeBinding(arg).isEqualTo(arg.getAST().resolveWellKnownType("boolean"))) {
            buffer.append("[JavaLangBoolean toStringWithBOOL:");
            arg.accept(this);
            buffer.append(']');
        } else if (arg instanceof StringLiteral) {
            // Strings with all valid C99 characters were previously converted,
            // so this literal needs to be defined with a char array.
            buffer.append(buildStringFromChars(((StringLiteral) arg).getLiteralValue()));
        } else {
            arg.accept(this);
        }
        if (iter.hasNext()) {
            buffer.append(", ");
        }
    }
    buffer.append(']');
}