diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuesser.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuesser.java index 828c38769c4..0a844ada7ca 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuesser.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuesser.java @@ -25,6 +25,9 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.swt.graphics.Image; import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; @@ -51,6 +54,11 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.Context; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMode; +import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Cost; + import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; /** @@ -104,12 +112,13 @@ public class ParameterGuesser { } } - private Collection evaluateVisibleMatches(IType expectedType, List suggestions) + private Collection evaluateVisibleMatches(IType expectedType, List suggestions, + IASTTranslationUnit ast) throws CModelException { Set res = new HashSet<>(); int size = suggestions.size(); for (int i = 0; i < size; i++) { - Variable variable = createVariable(suggestions.get(i), expectedType, i); + Variable variable = createVariable(suggestions.get(i), expectedType, i, ast); if (variable != null) { if (fAlreadyMatchedNames.contains(variable.name)) { variable.alreadyMatched = true; @@ -131,13 +140,15 @@ public class ParameterGuesser { return null; } - private Variable createVariable(IBinding element, IType enclosingType, int positionScore) + private Variable createVariable(IBinding element, IType enclosingType, int positionScore, + IASTTranslationUnit ast) throws CModelException { IType elementType = getType(element); String elementName = element.getName(); if (elementType != null && (elementType.toString().equals(enclosingType.toString()) - || elementType.isSameType(enclosingType) + || elementType.isSameType(enclosingType) + || isImplicitlyConvertible(enclosingType, elementType, ast) || isParent(elementType, enclosingType) || isReferenceTo(enclosingType, elementType) || isReferenceTo(elementType, enclosingType))) { @@ -175,6 +186,18 @@ public class ParameterGuesser { } return false; } + + private boolean isImplicitlyConvertible(IType orginType, IType candidateType, IASTNode point) { + try { + Cost cost = Conversions.checkImplicitConversionSequence(orginType, candidateType, + ValueCategory.LVALUE, UDCMode.ALLOWED, Context.ORDINARY, point); + if (cost.converts()) + return true; + } catch (DOMException e) { + return false; + } + return false; + } /** * Returns true, if the parent type is a direct/indirect parent of the child type @@ -267,9 +290,9 @@ public class ParameterGuesser { * @return returns the name of the best match, or null if no match found */ public ICompletionProposal[] parameterProposals(IType expectedType, String paramName, Position pos, - List suggestions, boolean isLastParameter) + List suggestions, boolean isLastParameter, IASTTranslationUnit ast) throws CModelException { - List typeMatches = new ArrayList<>(evaluateVisibleMatches(expectedType, suggestions)); + List typeMatches = new ArrayList<>(evaluateVisibleMatches(expectedType, suggestions, ast)); orderMatches(typeMatches, paramName); ICompletionProposal[] ret = new ICompletionProposal[typeMatches.size()]; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java index a23febdadca..1817b5e7f98 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java @@ -294,7 +294,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { boolean isLastParameter = i == count - 1; ArrayList allProposals = new ArrayList<>(); ICompletionProposal[] argumentProposals = guesser.parameterProposals(fParametersTypes[i], - paramName, position, fAssignableElements, isLastParameter); + paramName, position, fAssignableElements, isLastParameter, ast); allProposals.addAll(Arrays.asList(argumentProposals)); fPositions[i] = position; fChoices[i] = argumentProposals;