Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2003-08-27 13:17:47 +0000
committerAlain Magloire2003-08-27 13:17:47 +0000
commitf62e609968d027d969c8ffcd4ed36b3a93220956 (patch)
tree92f12fb58aff375a4e05686629dd47cf192312b1
parent397cfb21214b87254a58758c1f47610537908f94 (diff)
downloadorg.eclipse.cdt-f62e609968d027d969c8ffcd4ed36b3a93220956.tar.gz
org.eclipse.cdt-f62e609968d027d969c8ffcd4ed36b3a93220956.tar.xz
org.eclipse.cdt-f62e609968d027d969c8ffcd4ed36b3a93220956.zip
Update code completion to include for functions and
methods and to position the cursor appropiately.
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java99
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java28
2 files changed, 86 insertions, 41 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
index a40ce0e8d88..070a23a22bf 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
@@ -15,7 +15,6 @@ import java.util.Map;
import org.eclipse.cdt.core.index.TagFlags;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.IField;
import org.eclipse.cdt.core.model.IFunction;
import org.eclipse.cdt.core.model.IFunctionDeclaration;
import org.eclipse.cdt.core.model.IMember;
@@ -591,31 +590,36 @@ public class CCompletionProcessor implements IContentAssistProcessor {
Iterator i = elementsFound.iterator();
while (i.hasNext()){
CCompletionProposal proposal;
- FunctionPrototypeSummary fproto = null;
- String fname = "";
+ String replaceString = "";
String displayString = "";
Image image = null;
StringBuffer infoString = new StringBuffer();
BasicSearchMatch match = (BasicSearchMatch)i.next();
- fproto = getPrototype(match);
- fname = (fproto == null) ? match.getName() : fproto.getName();
- displayString = (fproto == null) ? fname : fproto.getPrototypeString(true);
+
+ //Make sure we replace with the appropriate string for functions and methods
+ FunctionPrototypeSummary fproto = getPrototype(match);
+ if(fproto != null) {
+ replaceString = fproto.getName() + "()";
+ displayString = fproto.getPrototypeString(true);
+ } else {
+ replaceString =
+ displayString = match.getName();;
+ }
+
image = labelProvider.getImage(match);
infoString.append(displayString);
if(match.getParentName().length() > 0) {
infoString.append(" - Parent: ");
infoString.append(match.getParentName());
}
-
-
proposal = new CCompletionProposal(
- fname, // replacement string
+ replaceString, // Replacement string
region.getOffset(),
region.getLength(),
image,
- displayString, // displayString
+ displayString, // Display string
calculateRelevance(match)
);
completions.add(proposal);
@@ -625,7 +629,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
if(fproto != null){
String fargs = fproto.getArguments();
if(fargs != null && fargs.length() > 0) {
- proposal.setContextInformation(new ContextInformation(fname, fargs));
+ proposal.setContextInformation(new ContextInformation(replaceString, fargs));
}
}
@@ -642,42 +646,61 @@ public class CCompletionProcessor implements IContentAssistProcessor {
ITagEntry[] tags = model.query(project, frag + "*", false, false);
if (tags != null && tags.length > 0) {
for (int i = 0; i < tags.length; i++) {
- String fname = tags[i].getTagName();
FunctionPrototypeSummary fproto = null;
+ String fargs = null;
+ String fdisplay = null;
+ String fdesc = null;
+ String fname = tags[i].getTagName();
int kind = tags[i].getKind();
+ //No member completion yet
+ if (kind == TagFlags.T_MEMBER) {
+ continue;
+ }
+
+ //This doesn't give you a nice "function" look to macros, but is safe
if (kind == TagFlags.T_FUNCTION || kind == TagFlags.T_PROTOTYPE) {
fname = fname + "()";
- }
-
- if(tags[i].getPattern() != null) {
- try {
- fproto = new FunctionPrototypeSummary(tags[i].getPattern());
- } catch(Exception ex) {
- fproto = null;
+
+ String pattern = tags[i].getPattern();
+ if(pattern != null) {
+ fproto = new FunctionPrototypeSummary(pattern);
+ }
+
+ if(fproto == null) {
+ fproto = new FunctionPrototypeSummary(fname);
}
- }
- if(fproto == null) {
- fproto = new FunctionPrototypeSummary(fname);
+ }
+
+ if(fproto != null) {
+ fargs = fproto.getArguments();
+ fdisplay = fproto.getPrototypeString(true);
+ } else {
+ fdisplay = fname;
}
+ //@@@ In the future something more usefull could go in here (ie Doxygen/JavaDoc)
+ fdesc = "<b>" + fname + "</b><br>" + "Defined in:<br> " + tags[i].getFileName();
+ if(tags[i].getClassName() != null) {
+ fdesc = fdesc + "<br>Class:<br> " + tags[i].getClassName();
+ }
+
//System.out.println("tagmatch " + fname + " proto " + proto + " type" + tags[i].getKind());
- if (kind != TagFlags.T_MEMBER) {
- CCompletionProposal proposal;
- proposal = new CCompletionProposal(fname,
- region.getOffset(),
- region.getLength(),
- getTagImage(kind),
- fproto.getPrototypeString(true),
- 3);
- completions.add(proposal);
-
- //No summary information available yet
-
- String fargs = fproto.getArguments();
- if(fargs != null && fargs.length() > 0) {
- proposal.setContextInformation(new ContextInformation(fname, fargs));
- }
+ CCompletionProposal proposal;
+ proposal = new CCompletionProposal(fname,
+ region.getOffset(),
+ region.getLength(),
+ getTagImage(kind),
+ fdisplay,
+ 3);
+ completions.add(proposal);
+
+ if(fdesc != null) {
+ proposal.setAdditionalProposalInfo(fdesc);
+ }
+
+ if(fargs != null && fargs.length() > 0) {
+ proposal.setContextInformation(new ContextInformation(fname, fargs));
}
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java
index 34d6e81dfd6..2719d367a72 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java
@@ -10,26 +10,48 @@ public class FunctionPrototypeSummary implements IFunctionSummary.IFunctionProto
String farguments;
/**
- * Creates a prototype which matches the format
- * returntype function(arguments)
- * @param properProto
+ * Create a function prototype summary based on a prototype string.
+ * @param The string describing the prototype which is properly
+ * formed with following format -- returntype function(arguments)
+ * The following formats will be converted as follows:
+ * function(arguments) --> void function(arguments)
+ * returntype function --> returntype function()
+ * function --> void function()
*/
public FunctionPrototypeSummary(String proto) {
int leftbracket = proto.indexOf('(');
int rightbracket = proto.lastIndexOf(')');
+
+ //If there are brackets missing, then assume void parameters
+ if(leftbracket == -1 || rightbracket == -1) {
+ if(leftbracket != -1) {
+ proto = proto.substring(leftbracket) + ")";
+ } else if(rightbracket != -1) {
+ proto = proto.substring(rightbracket - 1) + "()";
+ } else {
+ proto = proto + "()";
+ }
+
+ leftbracket = proto.indexOf('(');
+ rightbracket = proto.lastIndexOf(')');
+ }
+
farguments = proto.substring(leftbracket + 1, rightbracket);
int nameend = leftbracket - 1;
while(proto.charAt(nameend) == ' ') {
nameend--;
}
+
int namestart = nameend;
while(namestart > 0 && proto.charAt(namestart) != ' ') {
namestart--;
}
+
fname = proto.substring(namestart, nameend + 1).trim();
if(namestart == 0) {
+ //@@@ Should this be int instead?
freturn = "void";
} else {
freturn = proto.substring(0, namestart).trim();

Back to the top