mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 217043 - ContentAssist: Position cursor behind ')' if method has no arguments, patch by Jens Elementhaler
This commit is contained in:
parent
33d0e3da07
commit
8fcdbb9e32
3 changed files with 50 additions and 9 deletions
|
@ -44,6 +44,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||
|
||||
/**
|
||||
* This is a utility class to help convert AST elements to Strings corresponding to the
|
||||
|
@ -77,6 +78,33 @@ public class ASTTypeUtil {
|
|||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether the function matching the given function binding takes
|
||||
* parameters or not.
|
||||
* @throws DOMException
|
||||
*
|
||||
* @since 5.1
|
||||
*/
|
||||
public static boolean functionTakesParameters(IFunction function)
|
||||
throws DOMException {
|
||||
IParameter[] parameters = function.getParameters();
|
||||
|
||||
if (parameters.length == 0) {
|
||||
return false;
|
||||
} else if (parameters.length == 1) {
|
||||
IType ultimateType = SemanticUtil
|
||||
.getUltimateTypeViaTypedefs(parameters[0].getType());
|
||||
|
||||
if (ultimateType instanceof IBasicType) {
|
||||
if (((IBasicType) ultimateType).getType() == IBasicType.t_void) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation for the type array. The representation is
|
||||
* a comma-separated list of the normalized string representations of the
|
||||
|
|
|
@ -238,7 +238,11 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
|
||||
CCompletionProposal proposal = createProposal(repString, descString, prefix.length(), image, baseRelevance + RelevanceConstants.MACRO_TYPE_RELEVANCE, context);
|
||||
if (!context.isContextInformationStyle()) {
|
||||
proposal.setCursorPosition(repString.length() - 1);
|
||||
if (argString.length() > 0) {
|
||||
proposal.setCursorPosition(repString.length() - 1);
|
||||
} else {
|
||||
proposal.setCursorPosition(repString.length());
|
||||
}
|
||||
}
|
||||
|
||||
if (argString.length() > 0) {
|
||||
|
@ -336,8 +340,9 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
repStringBuff.append(function.getName());
|
||||
repStringBuff.append('(');
|
||||
|
||||
StringBuilder dispargs = new StringBuilder(); // for the displayString
|
||||
StringBuilder idargs = new StringBuilder(); // for the idString
|
||||
StringBuilder dispargs = new StringBuilder(); // for the dispargString
|
||||
StringBuilder idargs = new StringBuilder(); // for the idargString
|
||||
boolean hasArgs = true;
|
||||
String returnTypeStr = null;
|
||||
try {
|
||||
IParameter[] params = function.getParameters();
|
||||
|
@ -376,12 +381,14 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
if (returnType != null)
|
||||
returnTypeStr = ASTTypeUtil.getType(returnType, false);
|
||||
}
|
||||
|
||||
hasArgs = ASTTypeUtil.functionTakesParameters(function);
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
|
||||
String dispargString = dispargs.toString();
|
||||
String idargString = idargs.toString();
|
||||
|
||||
String contextDispargString = hasArgs ? dispargString : null;
|
||||
StringBuilder dispStringBuff = new StringBuilder(repStringBuff.toString());
|
||||
dispStringBuff.append(dispargString);
|
||||
dispStringBuff.append(')');
|
||||
|
@ -402,11 +409,12 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
final int relevance = function instanceof ICPPMethod ? RelevanceConstants.METHOD_TYPE_RELEVANCE : RelevanceConstants.FUNCTION_TYPE_RELEVANCE;
|
||||
CCompletionProposal proposal = createProposal(repString, dispString, idString, context.getCompletionNode().getLength(), image, baseRelevance + relevance, context);
|
||||
if (!context.isContextInformationStyle()) {
|
||||
proposal.setCursorPosition(repString.length() - 1);
|
||||
int cursorPosition = hasArgs ? (repString.length() - 1) : repString.length();
|
||||
proposal.setCursorPosition(cursorPosition);
|
||||
}
|
||||
|
||||
if (dispargString.length() > 0) {
|
||||
CProposalContextInformation info = new CProposalContextInformation(image, dispString, dispargString);
|
||||
if (contextDispargString != null) {
|
||||
CProposalContextInformation info = new CProposalContextInformation(image, dispString, contextDispargString);
|
||||
info.setContextInformationPosition(context.getContextInformationOffset());
|
||||
proposal.setContextInformation(info);
|
||||
}
|
||||
|
|
|
@ -110,8 +110,13 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
}
|
||||
|
||||
if (!cContext.isContextInformationStyle()) {
|
||||
// set the cursor before the closing bracket
|
||||
proposal.setCursorPosition(fname.length() - 1);
|
||||
if (fargs != null && fargs.length() > 0) {
|
||||
// set the cursor before the closing bracket
|
||||
proposal.setCursorPosition(fname.length() - 1);
|
||||
} else {
|
||||
// set the cursor behind the closing bracked
|
||||
proposal.setCursorPosition(fname.length());
|
||||
}
|
||||
}
|
||||
|
||||
if (fargs != null && fargs.length() > 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue