1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

Bug 217043 - ContentAssist: Position cursor behind ')' if method has no arguments, patch by Jens Elementhaler

This commit is contained in:
Anton Leherbauer 2008-12-18 08:26:32 +00:00
parent 33d0e3da07
commit 8fcdbb9e32
3 changed files with 50 additions and 9 deletions

View file

@ -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.CPPASTTypeId;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; 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.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 * 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 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 * Returns a string representation for the type array. The representation is
* a comma-separated list of the normalized string representations of the * a comma-separated list of the normalized string representations of the

View file

@ -238,7 +238,11 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
CCompletionProposal proposal = createProposal(repString, descString, prefix.length(), image, baseRelevance + RelevanceConstants.MACRO_TYPE_RELEVANCE, context); CCompletionProposal proposal = createProposal(repString, descString, prefix.length(), image, baseRelevance + RelevanceConstants.MACRO_TYPE_RELEVANCE, context);
if (!context.isContextInformationStyle()) { if (!context.isContextInformationStyle()) {
if (argString.length() > 0) {
proposal.setCursorPosition(repString.length() - 1); proposal.setCursorPosition(repString.length() - 1);
} else {
proposal.setCursorPosition(repString.length());
}
} }
if (argString.length() > 0) { if (argString.length() > 0) {
@ -336,8 +340,9 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
repStringBuff.append(function.getName()); repStringBuff.append(function.getName());
repStringBuff.append('('); repStringBuff.append('(');
StringBuilder dispargs = new StringBuilder(); // for the displayString StringBuilder dispargs = new StringBuilder(); // for the dispargString
StringBuilder idargs = new StringBuilder(); // for the idString StringBuilder idargs = new StringBuilder(); // for the idargString
boolean hasArgs = true;
String returnTypeStr = null; String returnTypeStr = null;
try { try {
IParameter[] params = function.getParameters(); IParameter[] params = function.getParameters();
@ -376,12 +381,14 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
if (returnType != null) if (returnType != null)
returnTypeStr = ASTTypeUtil.getType(returnType, false); returnTypeStr = ASTTypeUtil.getType(returnType, false);
} }
hasArgs = ASTTypeUtil.functionTakesParameters(function);
} catch (DOMException e) { } catch (DOMException e) {
} }
String dispargString = dispargs.toString(); String dispargString = dispargs.toString();
String idargString = idargs.toString(); String idargString = idargs.toString();
String contextDispargString = hasArgs ? dispargString : null;
StringBuilder dispStringBuff = new StringBuilder(repStringBuff.toString()); StringBuilder dispStringBuff = new StringBuilder(repStringBuff.toString());
dispStringBuff.append(dispargString); dispStringBuff.append(dispargString);
dispStringBuff.append(')'); 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; 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); CCompletionProposal proposal = createProposal(repString, dispString, idString, context.getCompletionNode().getLength(), image, baseRelevance + relevance, context);
if (!context.isContextInformationStyle()) { if (!context.isContextInformationStyle()) {
proposal.setCursorPosition(repString.length() - 1); int cursorPosition = hasArgs ? (repString.length() - 1) : repString.length();
proposal.setCursorPosition(cursorPosition);
} }
if (dispargString.length() > 0) { if (contextDispargString != null) {
CProposalContextInformation info = new CProposalContextInformation(image, dispString, dispargString); CProposalContextInformation info = new CProposalContextInformation(image, dispString, contextDispargString);
info.setContextInformationPosition(context.getContextInformationOffset()); info.setContextInformationPosition(context.getContextInformationOffset());
proposal.setContextInformation(info); proposal.setContextInformation(info);
} }

View file

@ -110,8 +110,13 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
} }
if (!cContext.isContextInformationStyle()) { if (!cContext.isContextInformationStyle()) {
if (fargs != null && fargs.length() > 0) {
// set the cursor before the closing bracket // set the cursor before the closing bracket
proposal.setCursorPosition(fname.length() - 1); proposal.setCursorPosition(fname.length() - 1);
} else {
// set the cursor behind the closing bracked
proposal.setCursorPosition(fname.length());
}
} }
if (fargs != null && fargs.length() > 0) { if (fargs != null && fargs.length() > 0) {