當前位置: 首頁>>代碼示例>>Java>>正文


Java ITypeBinding.isUpperbound方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.ITypeBinding.isUpperbound方法的典型用法代碼示例。如果您正苦於以下問題:Java ITypeBinding.isUpperbound方法的具體用法?Java ITypeBinding.isUpperbound怎麽用?Java ITypeBinding.isUpperbound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.dom.ITypeBinding的用法示例。


在下文中一共展示了ITypeBinding.isUpperbound方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: computeTypeProposal

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private String computeTypeProposal(ITypeBinding binding, ITypeParameter parameter) throws JavaModelException {
	final String name = TypeProposalUtils.getTypeQualifiedName(binding);
	if (binding.isWildcardType()) {

		if (binding.isUpperbound()) {
			// replace the wildcard ? with the type parameter name to get "E extends Bound" instead of "? extends Bound"
			//				String contextName= name.replaceFirst("\\?", parameter.getElementName()); //$NON-NLS-1$
			// upper bound - the upper bound is the bound itself
			return binding.getBound().getName();
		}

		// no or upper bound - use the type parameter of the inserted type, as it may be more
		// restrictive (eg. List<?> list= new SerializableList<Serializable>())
		return computeTypeProposal(parameter);
	}

	// not a wildcard but a type or type variable - this is unambigously the right thing to insert
	return name;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:20,代碼來源:CompletionProposalReplacementProvider.java

示例2: normalizeForDeclarationUse

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
 * Normalizes the binding so that it can be used as a type inside a declaration (e.g. variable
 * declaration, method return type, parameter type, ...).
 * For null bindings, java.lang.Object is returned.
 * For void bindings, <code>null</code> is returned.
 *
 * @param binding binding to normalize
 * @param ast current AST
 * @return the normalized type to be used in declarations, or <code>null</code>
 */
public static ITypeBinding normalizeForDeclarationUse(ITypeBinding binding, AST ast) {
	if (binding.isNullType())
	{
		return ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
	}
	if (binding.isPrimitive()) {
		return binding;
	}
	binding= normalizeTypeBinding(binding);
	if (binding == null) {
		return binding;
	}
	if (binding.isArray()) {
		return normalizeForDeclarationUse(binding.getComponentType(), ast).createArrayType(1);
	}
	if (!binding.isWildcardType()) {
		return binding;
	}
	ITypeBinding bound= binding.getBound();
	if (bound == null || !binding.isUpperbound()) {
		ITypeBinding[] typeBounds= binding.getTypeBounds();
		if (typeBounds.length > 0) {
			return typeBounds[0];
		} else {
			return binding.getErasure();
		}
	} else {
		return bound;
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:41,代碼來源:Bindings.java


注:本文中的org.eclipse.jdt.core.dom.ITypeBinding.isUpperbound方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。