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


Java ITypeBinding.getTypeArguments方法代碼示例

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


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

示例1: newCreationType

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
 * Create a Type suitable as the creationType in a ClassInstanceCreation expression.
 * @param ast The AST to create the nodes for.
 * @param typeBinding binding representing the given class type
 * @param importRewrite the import rewrite to use
 * @param importContext the import context used to determine which (null) annotations to consider
 * @return a Type suitable as the creationType in a ClassInstanceCreation expression.
 */
public static Type newCreationType(AST ast, ITypeBinding typeBinding, ImportRewrite importRewrite, ImportRewriteContext importContext) {
	if (typeBinding.isParameterizedType()) {
		Type baseType= newCreationType(ast, typeBinding.getTypeDeclaration(), importRewrite, importContext);
		IAnnotationBinding[] typeAnnotations= importContext.removeRedundantTypeAnnotations(typeBinding.getTypeAnnotations(), TypeLocation.NEW, typeBinding);
		for (IAnnotationBinding typeAnnotation : typeAnnotations) {
			((AnnotatableType)baseType).annotations().add(importRewrite.addAnnotation(typeAnnotation, ast, importContext));
		}
		ParameterizedType parameterizedType= ast.newParameterizedType(baseType);
		for (ITypeBinding typeArgument : typeBinding.getTypeArguments()) {
			typeArgument= StubUtility2.replaceWildcardsAndCaptures(typeArgument);
			parameterizedType.typeArguments().add(importRewrite.addImport(typeArgument, ast, importContext, TypeLocation.TYPE_ARGUMENT));
		}
		return parameterizedType;
	} else {
		return importRewrite.addImport(typeBinding, ast, importContext, TypeLocation.NEW);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:26,代碼來源:ASTNodeFactory.java

示例2: typeFtoA

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
 * Perform generic type substitution...
 * Currently, just uses string substitution.
 * Could be problematic (e.g., if it constructs invalid types).
 * 
 * @return
 */
public static String typeFtoA(ITypeBinding typeBinding) {
	String formalType = "";
	if(typeBinding.isParameterizedType()){
		ITypeBinding genericTypeBinding = typeBinding.getTypeDeclaration();
		ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
		ITypeBinding[] typeParameters = genericTypeBinding.getTypeParameters();
		formalType = typeBinding.getQualifiedName();
		int i =0;
		for (ITypeBinding iTypeBinding : typeParameters) {
			String typeParameterName = iTypeBinding.getQualifiedName();
			String typeArgumentName = typeArguments[i].getQualifiedName();
			formalType = formalType.replace(typeArgumentName, typeParameterName);
		}
	}
	else{
		formalType = typeBinding.getQualifiedName();
	}
	return formalType;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:27,代碼來源:PushIntoOwnedTransferFunctions.java

示例3: appendRawTypes

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private void appendRawTypes(List<ITypeBinding> rawTypes, Set<String> dejavu, ITypeBinding typeBinding, boolean includeTypeParameters) {
String key = typeBinding.getKey();
if (dejavu.contains(key)) {
	return;
}
dejavu.add(key);
ITypeBinding erasure = typeBinding.getErasure();
rawTypes.add(erasure);

if (!includeTypeParameters) {
	return;
}

ITypeBinding elementType = typeBinding.getElementType();
if (elementType != null) {
	this.appendRawTypes(rawTypes, dejavu, elementType, includeTypeParameters);
}

ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
if (typeArguments != null) {
	for (ITypeBinding typeArgument : typeArguments) {
		this.appendRawTypes(rawTypes, dejavu, typeArgument, includeTypeParameters);
	}
}

ITypeBinding[] typeBounds = typeBinding.getTypeBounds();
if (typeBounds != null) {
	for (ITypeBinding typeBound : typeBounds) {
		this.appendRawTypes(rawTypes, dejavu, typeBound, includeTypeParameters);
	}
}
  }
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:33,代碼來源:DependenciesAstVisitor.java

示例4: isContainerOfGeneralType

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public boolean isContainerOfGeneralType(String fullyQualifiedName) {
	boolean oneItf = false;

	model = m.getModel();
	Set<String> containerList = model.getContainerTypes();
	// Get the type of container;
	String containerType = getRawTypeName(fullyQualifiedName);
	if (containerList.contains(containerType)) {
		ITypeBinding typeBinding = getTypeBinding(fullyQualifiedName);
		if (typeBinding != null) {
			ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
			if (typeArguments != null) {
				for (int ii = 0; ii < typeArguments.length; ii++) {
					ITypeBinding typeArgument = typeArguments[ii];
					// Changed this to container of a general type
					// (Interface and Abstract classes)
					if (typeArgument != null && typeArgument.isInterface()
					        || Modifier.isAbstract(typeArgument.getModifiers())
					        || isJavaTypes(typeArgument.getQualifiedName())) {
						// TODO: Are we checking that at least one is an
						// interface; or that all are interfaces?
						oneItf = true;
						break;
					}
				}
			}
		}
	}

	return oneItf;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:32,代碼來源:QualUtils.java

示例5: isContainerType

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public boolean isContainerType(String fullyQualifiedName) {
	boolean containerType = false;
	String containerofType = getRawTypeName(fullyQualifiedName);

	model = m.getModel();
	Set<String> containerList = model.getContainerTypes();

	// Check if ArrayList and other containers are containers of TYPE(CLASS)
	if (containerList.contains(containerofType)) {
		ITypeBinding typeBinding = getTypeBinding(fullyQualifiedName);
		if (typeBinding != null) {
			ITypeBinding[] typeArguments = typeBinding.getTypeArguments();

			if (typeArguments != null) {
				for (int ii = 0; ii < typeArguments.length; ii++) {
					ITypeBinding typeArgument = typeArguments[ii];
					if (typeArgument != null && typeArgument.isClass()) {
						containerType = true;
						break;
					}
				}
			}
		}
	}

	return containerType;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:28,代碼來源:QualUtils.java

示例6: getElementOfContainer

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
public ITypeBinding getElementOfContainer(String fullyQualifiedName) {
	ITypeBinding typeBinding = getTypeBinding(fullyQualifiedName);
	ITypeBinding typeArg = null;
	if (typeBinding != null) {
		ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
		if (typeArguments != null) {
			for (int ii = 0; ii < typeArguments.length; ii++) {
				ITypeBinding typeArgument = typeArguments[ii];
				typeArg = typeArgument;
			}
		}
	}
	return typeArg;

}
 
開發者ID:aroog,項目名稱:code,代碼行數:16,代碼來源:Util.java

示例7: computeTypeArgumentProposals

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
private String[] computeTypeArgumentProposals(CompletionProposal proposal) {
	try {
		IType type = (IType) resolveJavaElement(
				compilationUnit.getJavaProject(), proposal);
		if (type == null) {
			return new String[0];
		}

		ITypeParameter[] parameters = type.getTypeParameters();
		if (parameters.length == 0) {
			return new String[0];
		}

		String[] arguments = new String[parameters.length];

		ITypeBinding expectedTypeBinding = getExpectedTypeForGenericParameters();
		if (expectedTypeBinding != null && expectedTypeBinding.isParameterizedType()) {
			// in this case, the type arguments we propose need to be compatible
			// with the corresponding type parameters to declared type

			IType expectedType= (IType) expectedTypeBinding.getJavaElement();

			IType[] path= TypeProposalUtils.computeInheritancePath(type, expectedType);
			if (path == null) {
				// proposed type does not inherit from expected type
				// the user might be looking for an inner type of proposed type
				// to instantiate -> do not add any type arguments
				return new String[0];
			}

			int[] indices= new int[parameters.length];
			for (int paramIdx= 0; paramIdx < parameters.length; paramIdx++) {
				indices[paramIdx]= TypeProposalUtils.mapTypeParameterIndex(path, path.length - 1, paramIdx);
			}

			// for type arguments that are mapped through to the expected type's
			// parameters, take the arguments of the expected type
			ITypeBinding[] typeArguments= expectedTypeBinding.getTypeArguments();
			for (int paramIdx= 0; paramIdx < parameters.length; paramIdx++) {
				if (indices[paramIdx] != -1) {
					// type argument is mapped through
					ITypeBinding binding= typeArguments[indices[paramIdx]];
					arguments[paramIdx]= computeTypeProposal(binding, parameters[paramIdx]);
				}
			}
		}

		// for type arguments that are not mapped through to the expected type,
		// take the lower bound of the type parameter
		for (int i = 0; i < arguments.length; i++) {
			if (arguments[i] == null) {
				arguments[i] = computeTypeProposal(parameters[i]);
			}
		}
		return arguments;
	} catch (JavaModelException e) {
		return new String[0];
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:60,代碼來源:CompletionProposalReplacementProvider.java

示例8: apply

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
@Override
public boolean apply(TM tm, TMSolutionType solIndex){
	boolean isHeuristicApplied = false;
	boolean isPublicParam = false;
	Set<Entry<Variable, Set<OType>>> entrySet = tm.entrySet();
	Set<OType> newSourceTyping = new HashSet<OType>();
	// XXX. Can we replace iteration with just 1 lookup: entrySet.get()?
	for (Entry<Variable, Set<OType>> entry : entrySet) {
		Variable var = entry.getKey();	
		if(var.equals(this.changedVar) /*au.isTypeEqual(auType) && au.isEnclosingTypeEqual(auEnclosingType)*/){
			
			if(var instanceof TACVariable || var instanceof SourceVariable){
   				Variable srcVariable = null;
   				IVariableBinding srcVariableBinding = null;
   				if(var instanceof TACVariable){
   					srcVariable = (TACVariable)var;
   					srcVariableBinding = ((TACVariable)srcVariable).getVarDecl();
   					if(srcVariableBinding.isParameter()){
   						if(Modifier.isPublic(srcVariableBinding.getModifiers())){
   							isPublicParam = true;
   						}
   					}
   				}
   				else{
   					srcVariable = (SourceVariable)var;
   					srcVariableBinding = ((SourceVariable)srcVariable).getBinding();
   				}
				if(!isPublicParam){
					boolean isMain = srcVariableBinding.getDeclaringClass().getQualifiedName().equals(Config.MAINCLASS);
					String solAlpha = SolutionManager.getSolution(solIndex, this.getRefinementType(), isMain);
					if(solAlpha != null ) {
						OType newSrcTyping = null;
						ITypeBinding sourceType = srcVariableBinding.getType();
						if(sourceType.isParameterizedType()){
							ITypeBinding[] typeArguments = sourceType.getTypeArguments();
							for (ITypeBinding iTypeBinding : typeArguments) {
								for (Variable paramTypeAu : tm.keySet()) {
									if(paramTypeAu.resolveType().equals(iTypeBinding)){
										Set<OType> paramAUTyping = tm.getTypeMapping(paramTypeAu);
										for (OType oType : paramAUTyping) {
											newSrcTyping = new OType("this.owned", oType.getOwner(), oType.getAlpha());
											newSourceTyping.add(newSrcTyping);
										}
										break;
									}
								}
							}
						}
						else{
							newSrcTyping = new OType("this.owned", solAlpha);
							newSourceTyping.add(newSrcTyping);
						}
						Set<OType> analysisResult = new HashSet<OType>(newSourceTyping);
						tm.putTypeMapping(var, analysisResult);

						// Record the AU being modified directly based on the refinement
						//this.addAU(au);
						this.putVariableMap(var, newSourceTyping);

						// Record the new set of typings
						this.setNewTyping(solIndex, newSrcTyping); 

						isHeuristicApplied = true;
					}
				}
			}
		}
	}

	return isHeuristicApplied;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:72,代碼來源:InferOwnedHeuristic.java

示例9: translateFtoA

import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
 * Translate a typeBinding with a formal type parameter into one with fully substituted type
 * based on the enclosing type
 * @param typeBinding: e.g., virtual field of type <E extends java.lang.Object>
 * @param actualBinding: the enclosing type, e.g., class ArrayList<courses.Course> 
 * 						where the generic type declaration is class ArrayList<E> {...}
 * @return typeBinding with the type substitution performed, e.g., courses.Course
 */
public static ITypeBinding translateFtoA(ITypeBinding typeBinding, ITypeBinding actualBinding) {
	ITypeBinding toTypeBindingActual = typeBinding;

	// HACK: Introduced bugs!		
	// Check that it is a generic type, to avoid generating a type that does not exist!
	// if(!typeBinding.isGenericType()) {
	// 	return typeBinding;
	// }
	
	// HACK: Introduced bugs!
	 if (typeBinding.isEqualTo(actualBinding)) {
		return typeBinding;
	 }
	
	// Instantiate generic types...
	if (actualBinding.isParameterizedType()) {
		ITypeBinding[] typeParameters = actualBinding.getErasure().getTypeParameters();
		int pIndex = -1;
		int index = 0;
		for(ITypeBinding typeParameter : typeParameters ) {
			if ( typeParameter.isEqualTo(typeBinding) ) {
				pIndex = index;
				break;
			}
			index++;
		}
		ITypeBinding[] typeArguments = actualBinding.getTypeArguments();
		if ( typeBinding.isTypeVariable() && typeArguments != null && pIndex != -1  && pIndex < typeArguments.length) {
			toTypeBindingActual = typeArguments[pIndex];
		}
		else {
			String[] typeArgumentString = getParameters(typeArguments);
			String bindingKey = BindingKey.createParameterizedTypeBindingKey(typeBinding.getKey(), typeArgumentString);
			toTypeBindingActual = GenHelper.mapBindingKeyToTypeBinding(bindingKey);
		}
	}
	


	return toTypeBindingActual;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:50,代碼來源:GenHelper.java


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