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());
}
}
}
}
Aggregations