private Collection<IBinding> cppRemoveSecondaryBindings( Set<IBinding> primaryBindings, IASTName sourceName) { List<IBinding> result = new ArrayList<IBinding>(); String[] sourceQualifiedName = null; int funcArgCount = -1; if (sourceName != null) { final IBinding binding = sourceName.resolveBinding(); if (binding != null) { sourceQualifiedName = CPPVisitor.getQualifiedName(binding); if (binding instanceof ICPPUnknownBinding) { LookupData data = CPPSemantics.createLookupData(sourceName); if (data.isFunctionCall()) { funcArgCount = data.getFunctionArgumentCount(); } } } } for (Iterator<IBinding> iterator = primaryBindings.iterator(); iterator.hasNext(); ) { IBinding binding = iterator.next(); if (sourceQualifiedName != null) { String[] qualifiedName = CPPVisitor.getQualifiedName(binding); if (!Arrays.equals(qualifiedName, sourceQualifiedName)) { iterator.remove(); continue; } } if (funcArgCount != -1) { // For c++ we can check the number of parameters. if (binding instanceof ICPPFunction) { ICPPFunction f = (ICPPFunction) binding; if (f.getRequiredArgumentCount() > funcArgCount) { iterator.remove(); result.add(binding); continue; } if (!f.takesVarArgs() && !f.hasParameterPack()) { final IType[] parameterTypes = f.getType().getParameterTypes(); int maxArgs = parameterTypes.length; if (maxArgs == 1 && SemanticUtil.isVoidType(parameterTypes[0])) { maxArgs = 0; } if (maxArgs < funcArgCount) { iterator.remove(); result.add(binding); continue; } } } } } return result; }
/** Constructs a string in the format: (paramName1,paramName2,...) */ private static String getFunctionParameterString(IFunctionType functionType) throws DOMException { IType[] types = functionType.getParameterTypes(); if (types.length == 1 && SemanticUtil.isVoidType(types[0])) { types = new IType[0]; } StringBuilder result = new StringBuilder(); result.append('('); for (int i = 0; i < types.length; i++) { if (i > 0) { result.append(','); } ASTTypeUtil.appendType(types[i], true, result); } if (functionType instanceof ICPPFunctionType && ((ICPPFunctionType) functionType).takesVarArgs()) { if (types.length != 0) { result.append(','); } result.append("..."); // $NON-NLS-1$ } result.append(')'); return result.toString(); }