Search in sources :

Example 11 with IPackageBinding

use of org.eclipse.jdt.core.dom.IPackageBinding in project eclipse.jdt.ls by eclipse.

the class BindingLabelProvider method getTypeLabel.

private static void getTypeLabel(ITypeBinding binding, long flags, StringBuffer buffer) {
    if ((flags & JavaElementLabels.T_FULLY_QUALIFIED) != 0) {
        final IPackageBinding pack = binding.getPackage();
        if (pack != null && !pack.isUnnamed()) {
            buffer.append(pack.getName());
            buffer.append('.');
        }
    }
    if ((flags & (JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.T_CONTAINER_QUALIFIED)) != 0) {
        final ITypeBinding declaring = binding.getDeclaringClass();
        if (declaring != null) {
            getTypeLabel(declaring, JavaElementLabels.T_CONTAINER_QUALIFIED | (flags & JavaElementLabels.P_COMPRESSED), buffer);
            buffer.append('.');
        }
        final IMethodBinding declaringMethod = binding.getDeclaringMethod();
        if (declaringMethod != null) {
            getMethodLabel(declaringMethod, 0, buffer);
            buffer.append('.');
        }
    }
    if (binding.isCapture()) {
        getTypeLabel(binding.getWildcard(), flags & JavaElementLabels.T_TYPE_PARAMETERS, buffer);
    } else if (binding.isWildcardType()) {
        buffer.append('?');
        ITypeBinding bound = binding.getBound();
        if (bound != null) {
            if (binding.isUpperbound()) {
                // $NON-NLS-1$
                buffer.append(" extends ");
            } else {
                // $NON-NLS-1$
                buffer.append(" super ");
            }
            getTypeLabel(bound, flags & JavaElementLabels.T_TYPE_PARAMETERS, buffer);
        }
    } else if (binding.isArray()) {
        getTypeLabel(binding.getElementType(), flags & JavaElementLabels.T_TYPE_PARAMETERS, buffer);
        appendDimensions(binding.getDimensions(), buffer);
    } else {
        // type variables, primitive, reftype
        String name = binding.getTypeDeclaration().getName();
        if (name.length() == 0) {
            if (binding.isEnum()) {
                buffer.append('{' + JavaElementLabels.ELLIPSIS_STRING + '}');
            } else if (binding.isAnonymous()) {
                ITypeBinding[] superInterfaces = binding.getInterfaces();
                ITypeBinding baseType;
                if (superInterfaces.length > 0) {
                    baseType = superInterfaces[0];
                } else {
                    baseType = binding.getSuperclass();
                }
                if (baseType != null) {
                    StringBuffer anonymBaseType = new StringBuffer();
                    getTypeLabel(baseType, flags & JavaElementLabels.T_TYPE_PARAMETERS, anonymBaseType);
                    buffer.append(Messages.format("new {0}() '{'...}", anonymBaseType.toString()));
                } else {
                    buffer.append("new Anonymous");
                }
            } else {
                // $NON-NLS-1$
                buffer.append("UNKNOWN");
            }
        } else {
            buffer.append(name);
        }
        if ((flags & JavaElementLabels.T_TYPE_PARAMETERS) != 0) {
            if (binding.isGenericType()) {
                getTypeParametersLabel(binding.getTypeParameters(), buffer);
            } else if (binding.isParameterizedType()) {
                getTypeArgumentsLabel(binding.getTypeArguments(), flags, buffer);
            }
        }
    }
    if ((flags & JavaElementLabels.T_POST_QUALIFIED) != 0) {
        final IMethodBinding declaringMethod = binding.getDeclaringMethod();
        final ITypeBinding declaringType = binding.getDeclaringClass();
        if (declaringMethod != null) {
            buffer.append(JavaElementLabels.CONCAT_STRING);
            getMethodLabel(declaringMethod, JavaElementLabels.T_FULLY_QUALIFIED | (flags & JavaElementLabels.P_COMPRESSED), buffer);
        } else if (declaringType != null) {
            buffer.append(JavaElementLabels.CONCAT_STRING);
            getTypeLabel(declaringType, JavaElementLabels.T_FULLY_QUALIFIED | (flags & JavaElementLabels.P_COMPRESSED), buffer);
        } else {
            final IPackageBinding pack = binding.getPackage();
            if (pack != null && !pack.isUnnamed()) {
                buffer.append(JavaElementLabels.CONCAT_STRING);
                buffer.append(pack.getName());
            }
        }
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IPackageBinding(org.eclipse.jdt.core.dom.IPackageBinding)

Aggregations

IPackageBinding (org.eclipse.jdt.core.dom.IPackageBinding)11 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)7 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)4 IJavaElement (org.eclipse.jdt.core.IJavaElement)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 UnhandledException (org.autorefactor.util.UnhandledException)2 CoreException (org.eclipse.core.runtime.CoreException)2 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)2 IAnnotationBinding (org.eclipse.jdt.core.dom.IAnnotationBinding)2 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)2 SearchEngine (org.eclipse.jdt.core.search.SearchEngine)2 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)2 SearchRequestor (org.eclipse.jdt.core.search.SearchRequestor)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IType (org.eclipse.jdt.core.IType)1 AST (org.eclipse.jdt.core.dom.AST)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 Annotation (org.eclipse.jdt.core.dom.Annotation)1 Block (org.eclipse.jdt.core.dom.Block)1