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


Java ITypeBinding.isWildcardType方法代碼示例

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


在下文中一共展示了ITypeBinding.isWildcardType方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: containsTypeVariables

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public 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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:19,代碼來源:Bindings.java

示例3: evaluateVariableType

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private Type evaluateVariableType(AST ast, ImportRewrite imports, ImportRewriteContext importRewriteContext, IBinding targetContext, TypeLocation location) {
	if (fOriginalNode.getParent() instanceof MethodInvocation) {
		MethodInvocation parent= (MethodInvocation) fOriginalNode.getParent();
		if (parent.getExpression() == fOriginalNode) {
			// _x_.foo() -> guess qualifier type by looking for a type with method 'foo'
			ITypeBinding[] bindings= ASTResolving.getQualifierGuess(fOriginalNode.getRoot(), parent.getName().getIdentifier(), parent.arguments(), targetContext);
			if (bindings.length > 0) {
				return imports.addImport(bindings[0], ast, importRewriteContext, location);
			}
		}
	}

	ITypeBinding binding= ASTResolving.guessBindingForReference(fOriginalNode);
	if (binding != null) {
		if (binding.isWildcardType()) {
			binding= ASTResolving.normalizeWildcardType(binding, isVariableAssigned(), ast);
			if (binding == null) {
				// only null binding applies
				binding= ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
			}
		}

		return imports.addImport(binding, ast, importRewriteContext, location);
	}
	// no binding, find type AST node instead -> ABC a= x-> use 'ABC' as is
	Type type = ASTResolving.guessTypeForReference(ast, fOriginalNode);
	if (type != null) {
		return type;
	}
	if (fVariableKind == CONST_FIELD) {
		return ast.newSimpleType(ast.newSimpleName("String")); //$NON-NLS-1$
	}
	return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:35,代碼來源:NewVariableCorrectionProposal.java

示例4: createSignatureChangeDescription

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private static ChangeDescription[] createSignatureChangeDescription(int[] indexOfDiff, int nDiffs, ITypeBinding[] paramTypes, List<Expression> arguments, ITypeBinding[] argTypes) {
	ChangeDescription[] changeDesc= new ChangeDescription[paramTypes.length];
	for (int i= 0; i < nDiffs; i++) {
		int diffIndex= indexOfDiff[i];
		Expression arg= arguments.get(diffIndex);
		String name= getExpressionBaseName(arg);
		ITypeBinding argType= argTypes[diffIndex];
		if (argType.isWildcardType()) {
			argType= ASTResolving.normalizeWildcardType(argType, true, arg.getAST());
			if (argType== null) {
				return null;
			}
		}
		changeDesc[diffIndex]= new EditDescription(argType, name);
	}
	return changeDesc;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:18,代碼來源:UnresolvedElementsSubProcessor.java

示例5: 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

示例6: removeUnwantedTypeAnnotations

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public IAnnotationBinding[] removeUnwantedTypeAnnotations(IAnnotationBinding[] annotations, TypeLocation location, ITypeBinding type) {
	if (location == TypeLocation.OTHER) {
		return NO_ANNOTATIONS;
	}
	if(type.isTypeVariable() || type.isWildcardType()) {
		return annotations;
	}
	boolean excludeAllNullAnnotations = NEVER_NULLNESS_LOCATIONS.contains(location);
	if (excludeAllNullAnnotations || fNonNullByDefaultLocations.contains(location)) {
		ArrayList<IAnnotationBinding> list= new ArrayList<>(annotations.length);
		for (IAnnotationBinding annotation : annotations) {
			ITypeBinding annotationType= annotation.getAnnotationType();
			if (annotationType != null) {
				if (annotationType.getQualifiedName().equals(fNonNullAnnotationName)) {
					// ignore @NonNull
				} else if (excludeAllNullAnnotations && annotationType.getQualifiedName().equals(fNullableAnnotationName)) {
					// also ignore @Nullable
				} else {
					list.add(annotation);
				}
			} else {
				list.add(annotation);
			}
		}
		return list.size() == annotations.length ? annotations : list.toArray(new IAnnotationBinding[list.size()]);
	} else {
		return annotations;
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:30,代碼來源:RedundantNullnessTypeAnnotationsFilter.java

示例7: replaceWildcardsAndCaptures

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public static ITypeBinding replaceWildcardsAndCaptures(ITypeBinding type) {
	while (type.isWildcardType() || type.isCapture() || (type.isArray() && type.getElementType().isCapture())) {
		ITypeBinding bound = type.getBound();
		type = (bound != null) ? bound : type.getErasure();
	}
	return type;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:8,代碼來源:StubUtility2.java

示例8: getParameterTypes

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private static ITypeBinding[] getParameterTypes(List<Expression> args) {
	ITypeBinding[] params= new ITypeBinding[args.size()];
	for (int i= 0; i < args.size(); i++) {
		Expression expr= args.get(i);
		ITypeBinding curr= Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
		if (curr != null && curr.isWildcardType()) {
			curr= ASTResolving.normalizeWildcardType(curr, true, expr.getAST());
		}
		if (curr == null) {
			curr= expr.getAST().resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
		}
		params[i]= curr;
	}
	return params;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:16,代碼來源:UnresolvedElementsSubProcessor.java

示例9: evaluateParameterType

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private Type evaluateParameterType(AST ast, Expression elem, String key, ImportRewriteContext context) {
	ITypeBinding binding= Bindings.normalizeTypeBinding(elem.resolveTypeBinding());
	if (binding != null && binding.isWildcardType()) {
		binding= ASTResolving.normalizeWildcardType(binding, true, ast);
	}
	if (binding != null) {
		return getImportRewrite().addImport(binding, ast, context, TypeLocation.PARAMETER);
	}
	return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:11,代碼來源:NewMethodCorrectionProposal.java

示例10: addMissingReturnTypeProposals

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public static void addMissingReturnTypeProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) {
	ICompilationUnit cu= context.getCompilationUnit();

	CompilationUnit astRoot= context.getASTRoot();
	ASTNode selectedNode= problem.getCoveringNode(astRoot);
	if (selectedNode == null) {
		return;
	}
	BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
	if (decl instanceof MethodDeclaration) {
		MethodDeclaration methodDeclaration= (MethodDeclaration) decl;

		ReturnStatementCollector eval= new ReturnStatementCollector();
		decl.accept(eval);

		AST ast= astRoot.getAST();

		ITypeBinding typeBinding= eval.getTypeBinding(decl.getAST());
		typeBinding= Bindings.normalizeTypeBinding(typeBinding);
		if (typeBinding == null) {
			typeBinding= ast.resolveWellKnownType("void"); //$NON-NLS-1$
		}
		if (typeBinding.isWildcardType()) {
			typeBinding= ASTResolving.normalizeWildcardType(typeBinding, true, ast);
		}

		ASTRewrite rewrite= ASTRewrite.create(ast);

		String label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_missingreturntype_description, BindingLabelProvider.getBindingLabel(typeBinding, BindingLabelProvider.DEFAULT_TEXTFLAGS));
		LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.MISSING_RETURN_TYPE);

		ImportRewrite imports= proposal.createImportRewrite(astRoot);
		ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
		Type type= imports.addImport(typeBinding, ast, importRewriteContext, TypeLocation.RETURN_TYPE);

		rewrite.set(methodDeclaration, MethodDeclaration.RETURN_TYPE2_PROPERTY, type, null);
		rewrite.set(methodDeclaration, MethodDeclaration.CONSTRUCTOR_PROPERTY, Boolean.FALSE, null);

		Javadoc javadoc= methodDeclaration.getJavadoc();
		if (javadoc != null && typeBinding != null) {
			TagElement newTag= ast.newTagElement();
			newTag.setTagName(TagElement.TAG_RETURN);
			TextElement commentStart= ast.newTextElement();
			newTag.fragments().add(commentStart);

			JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
			proposal.addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); //$NON-NLS-1$
		}

		String key= "return_type"; //$NON-NLS-1$
		proposal.addLinkedPosition(rewrite.track(type), true, key);
		if (typeBinding != null) {
			ITypeBinding[] bindings= ASTResolving.getRelaxingTypes(ast, typeBinding);
			for (int i= 0; i < bindings.length; i++) {
				proposal.addLinkedPositionProposal(key, bindings[i]);
			}
		}

		proposals.add(proposal);

		// change to constructor
		ASTNode parentType= ASTResolving.findParentType(decl);
		if (parentType instanceof AbstractTypeDeclaration) {
			boolean isInterface= parentType instanceof TypeDeclaration && ((TypeDeclaration) parentType).isInterface();
			if (!isInterface) {
				String constructorName= ((AbstractTypeDeclaration) parentType).getName().getIdentifier();
				ASTNode nameNode= methodDeclaration.getName();
				label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_wrongconstructorname_description, BasicElementLabels.getJavaElementName(constructorName));
				proposals.add(new ReplaceCorrectionProposal(label, cu, nameNode.getStartPosition(), nameNode.getLength(), constructorName, IProposalRelevance.CHANGE_TO_CONSTRUCTOR));
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:74,代碼來源:ReturnTypeSubProcessor.java


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