Java Code Examples for org.eclipse.jdt.core.dom.ITypeBinding#isCapture()

The following examples show how to use org.eclipse.jdt.core.dom.ITypeBinding#isCapture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Normalizes a type binding received from an expression to a type binding that can be used inside a
 * declaration signature, but <em>not</em> as type of a declaration (use {@link #normalizeForDeclarationUse(ITypeBinding, AST)} for that).
 * <p>
 * Anonymous types are normalized to the super class or interface. For
 * null or void bindings, <code>null</code> is returned.
 * </p>
 * 
 * @param binding the binding to normalize
 * @return the normalized binding, can be <code>null</code>
 * 
 * @see #normalizeForDeclarationUse(ITypeBinding, AST)
 */
public static ITypeBinding normalizeTypeBinding(ITypeBinding binding) {
	if (binding != null && !binding.isNullType() && !isVoidType(binding)) {
		if (binding.isAnonymous()) {
			ITypeBinding[] baseBindings= binding.getInterfaces();
			if (baseBindings.length > 0) {
				return baseBindings[0];
			}
			return binding.getSuperclass();
		}
		if (binding.isCapture()) {
			return binding.getWildcard();
		}
		return binding;
	}
	return null;
}
 
Example 2
Source File: BindingLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static ImageDescriptor getBaseImageDescriptor(IBinding binding, int flags) {
	if (binding instanceof ITypeBinding) {
		ITypeBinding typeBinding= (ITypeBinding) binding;
		if (typeBinding.isArray()) {
			typeBinding= typeBinding.getElementType();
		}
		if (typeBinding.isCapture()) {
			typeBinding.getWildcard();
		}
		return getTypeImageDescriptor(typeBinding.getDeclaringClass() != null, typeBinding, flags);
	} else if (binding instanceof IMethodBinding) {
		ITypeBinding type= ((IMethodBinding) binding).getDeclaringClass();
		int modifiers= binding.getModifiers();
		if (type.isEnum() && (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers) && !Modifier.isPrivate(modifiers)) && ((IMethodBinding) binding).isConstructor())
			return JavaPluginImages.DESC_MISC_PRIVATE;
		return getMethodImageDescriptor(binding.getModifiers());
	} else if (binding instanceof IVariableBinding)
		return getFieldImageDescriptor((IVariableBinding) binding);
	return JavaPluginImages.DESC_OBJS_UNKNOWN;
}
 
Example 3
Source File: JdtUtils.java    From j2cl with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a type descriptor for the given type binding, taking into account nullability.
 *
 * @param typeBinding the type binding, used to create the type descriptor.
 * @param elementAnnotations the annotations on the element
 */
private static TypeDescriptor createTypeDescriptorWithNullability(
    ITypeBinding typeBinding, IAnnotationBinding[] elementAnnotations) {
  if (typeBinding == null) {
    return null;
  }

  if (typeBinding.isPrimitive()) {
    return PrimitiveTypes.get(typeBinding.getName());
  }

  if (isIntersectionType(typeBinding)) {
    return createIntersectionType(typeBinding);
  }

  if (typeBinding.isNullType()) {
    return TypeDescriptors.get().javaLangObject;
  }

  if (typeBinding.isTypeVariable() || typeBinding.isCapture() || typeBinding.isWildcardType()) {
    return createTypeVariable(typeBinding);
  }

  boolean isNullable = isNullable(typeBinding, elementAnnotations);
  if (typeBinding.isArray()) {
    TypeDescriptor componentTypeDescriptor = createTypeDescriptor(typeBinding.getComponentType());
    return ArrayTypeDescriptor.newBuilder()
        .setComponentTypeDescriptor(componentTypeDescriptor)
        .setNullable(isNullable)
        .build();
  }

  return withNullability(createDeclaredType(typeBinding), isNullable);
}
 
Example 4
Source File: JdtUtils.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private static boolean isIntersectionType(ITypeBinding binding) {
  return binding.isIntersectionType()
      // JDT returns true for isIntersectionType() for type variables, wildcards and captures
      // with intersection type bounds.
      && !binding.isCapture()
      && !binding.isTypeVariable()
      && !binding.isWildcardType();
}
 
Example 5
Source File: TypeEnvironment.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public TType create(ITypeBinding binding) {
	if (binding.isPrimitive()) {
		return createPrimitiveType(binding);
	} else if (binding.isArray()) {
		return createArrayType(binding);
	} else if (binding.isRawType()) {
		return createRawType(binding);
	} else if (binding.isGenericType()) {
		return createGenericType(binding);
	} else if (binding.isParameterizedType()) {
		return createParameterizedType(binding);
	} else if (binding.isTypeVariable()) {
		return createTypeVariable(binding);
	} else if (binding.isWildcardType()) {
		if (binding.getBound() == null) {
			return createUnboundWildcardType(binding);
		} else if (binding.isUpperbound()) {
			return createExtendsWildCardType(binding);
		} else {
			return createSuperWildCardType(binding);
		}
	} else if (binding.isCapture()) {
		if (fRemoveCapures) {
			return create(binding.getWildcard());
		} else {
			return createCaptureType(binding);
		}
	}
	if ("null".equals(binding.getName())) //$NON-NLS-1$
		return NULL;
	return createStandardType(binding);
}
 
Example 6
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
static boolean containsTypeVariables(ITypeBinding type) {
	if (type.isTypeVariable())
		return true;
	if (type.isArray())
		return containsTypeVariables(type.getElementType());
	if (type.isCapture())
		return containsTypeVariables(type.getWildcard());
	if (type.isParameterizedType())
		return containsTypeVariables(type.getTypeArguments());
	if (type.isWildcardType() && type.getBound() != null)
		return containsTypeVariables(type.getBound());
	return false;
}
 
Example 7
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isUseableTypeInContext(ITypeBinding type, IBinding context, boolean noWildcards) {
	if (type.isArray()) {
		type= type.getElementType();
	}
	if (type.isAnonymous()) {
		return false;
	}
	if (type.isRawType() || type.isPrimitive()) {
		return true;
	}
	if (type.isTypeVariable()) {
		return isVariableDefinedInContext(context, type);
	}
	if (type.isGenericType()) {
		ITypeBinding[] typeParameters= type.getTypeParameters();
		for (int i= 0; i < typeParameters.length; i++) {
			if (!isUseableTypeInContext(typeParameters[i], context, noWildcards)) {
				return false;
			}
		}
		return true;
	}
	if (type.isParameterizedType()) {
		ITypeBinding[] typeArguments= type.getTypeArguments();
		for (int i= 0; i < typeArguments.length; i++) {
			if (!isUseableTypeInContext(typeArguments[i], context, noWildcards)) {
				return false;
			}
		}
		return true;
	}
	if (type.isCapture()) {
		type= type.getWildcard();
	}

	if (type.isWildcardType()) {
		if (noWildcards) {
			return false;
		}
		if (type.getBound() != null) {
			return isUseableTypeInContext(type.getBound(), context, noWildcards);
		}
	}
	return true;
}