[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Fix for bug # 40520
|
All,
This patch cleans up the code completion of an exception error which was
being
generated if the input to the FunctionPrototypeSummary class wasn't "well
defined".
This patch does two things. It cleans up the logic in the
FunctionPrototypeSummary
so that it no longer throws an exception if you pass it something which is
"not well
formed" (see the constructor description for more details). The downside of
this
of course is that you must know that what you are providing to the
constructor is
always going to be a function so if your applications depended on an
exception being
thrown (which was _not_ part of the API, but the behaviour) then buyer
beware.
The second part of this patch adjusts the CCompletionProcessor code so that
(using the old indexer still) it only tries to make function summaries out
of functions
and prototypes.
For the ChangeLog:
Adjustments to the FunctionPrototypeSummary to make it more tolerant of
the
input string, which is always assumed to be a function.
Improvements to the CTags Indexer generated completion to only generate
FunctionPrototypesSummaries for functions/prototypes.
Some minor "description" information for CTags indexed completions was
added.
Index: src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java,v
retrieving revision 1.8
diff -u -r1.8 CCompletionProcessor.java
--- src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java 24 Jun 2003 14:22:14 -0000 1.8
+++ src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java 25 Jul 2003 11:48:02 -0000
@@ -417,42 +417,61 @@
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
+ CCompletionProposal proposal;
+ proposal = new CCompletionProposal(fname,
+ region.getOffset(),
+ region.getLength(),
+ getTagImage(kind),
+ fdisplay,
+ 3);
+ completions.add(proposal);
- String fargs = fproto.getArguments();
- if(fargs != null && fargs.length() > 0) {
- proposal.setContextInformation(new ContextInformation(fname, fargs));
- }
+ if(fdesc != null) {
+ proposal.setAdditionalProposalInfo(fdesc);
+ }
+
+ if(fargs != null && fargs.length() > 0) {
+ proposal.setContextInformation(new ContextInformation(fname, fargs));
}
}
}
Index: src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java,v
retrieving revision 1.1
diff -u -r1.1 FunctionPrototypeSummary.java
--- src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java 24 Jun 2003 14:22:14 -0000 1.1
+++ src/org/eclipse/cdt/ui/FunctionPrototypeSummary.java 25 Jul 2003 11:48:03 -0000
@@ -10,26 +10,48 @@
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();