|
From: <caw...@us...> - 2007-02-07 22:00:24
|
Revision: 1938
http://svn.sourceforge.net/rubyeclipse/?rev=1938&view=rev
Author: cawilliams
Date: 2007-02-07 14:00:20 -0800 (Wed, 07 Feb 2007)
Log Message:
-----------
start making completion proposals show more information about the proposal (type names, method parameters, declaring types, etc)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/CompletionProposal.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/AbstractRubyCompletionProposal.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/CompletionProposalLabelProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyScriptCompletion.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/CompletionProposal.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/CompletionProposal.java 2007-02-07 18:18:08 UTC (rev 1937)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/CompletionProposal.java 2007-02-07 22:00:20 UTC (rev 1938)
@@ -85,6 +85,8 @@
*/
private String name = null;
private int flags;
+ private String type;
+ private String declaringType;
public CompletionProposal(int kind, String completion, int relevance) {
this.completionKind = kind;
@@ -194,4 +196,31 @@
this.replaceStart = startIndex;
this.replaceEnd = endIndex;
}
+
+ public String[] getParameterNames() {
+ // TODO Auto-generated method stub
+ return parameterNames;
+ }
+
+ public String getType() {
+ if (type != null) return type;
+ return "";
+ }
+
+ public String getDeclaringType() {
+ if (declaringType != null) return declaringType;
+ return "";
+ }
+
+ public void setType(String name) {
+ this.type = name;
+ }
+
+ public void setDeclaringType(String elementName) {
+ this.declaringType = elementName;
+ }
+
+ public void setName(String newName) {
+ this.name = newName;
+ }
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-02-07 18:18:08 UTC (rev 1937)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-02-07 22:00:20 UTC (rev 1938)
@@ -95,7 +95,8 @@
for (String name : globals) {
if (!context.prefixStartsWith(name))
continue;
- addProposal(context.getReplaceStart(), CompletionProposal.FIELD_REF, name);
+ CompletionProposal proposal = createProposal(context.getReplaceStart(), CompletionProposal.FIELD_REF, name);
+ requestor.accept(proposal);
}
}
@@ -105,14 +106,15 @@
for (String name : types) {
if (!context.prefixStartsWith(name))
continue;
- addProposal(context.getReplaceStart(), CompletionProposal.TYPE_REF, name);
+ CompletionProposal proposal = createProposal(context.getReplaceStart(), CompletionProposal.TYPE_REF, name);
+ proposal.setType(name);
+ requestor.accept(proposal);
}
}
- private CompletionProposal addProposal(int replaceStart, int type, String name) {
+ private CompletionProposal createProposal(int replaceStart, int type, String name) {
CompletionProposal proposal = new CompletionProposal(type, name, 100);
proposal.setReplaceRange(replaceStart, replaceStart + name.length());
- requestor.accept(proposal);
return proposal;
}
@@ -122,7 +124,8 @@
for (String name : types) {
if (!context.prefixStartsWith(name))
continue;
- addProposal(context.getReplaceStart(), CompletionProposal.FIELD_REF, name);
+ CompletionProposal proposal = createProposal(context.getReplaceStart(), CompletionProposal.FIELD_REF, name);
+ requestor.accept(proposal);
}
}
@@ -160,6 +163,8 @@
CompletionProposal proposal = new CompletionProposal(CompletionProposal.METHOD_REF, name, confidence);
proposal.setReplaceRange(start, start + name.length());
proposal.setFlags(flags);
+ proposal.setName(name);
+ proposal.setDeclaringType(type.getElementName());
requestor.accept(proposal);
}
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/AbstractRubyCompletionProposal.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/AbstractRubyCompletionProposal.java 2007-02-07 18:18:08 UTC (rev 1937)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/AbstractRubyCompletionProposal.java 2007-02-07 22:00:20 UTC (rev 1938)
@@ -69,7 +69,7 @@
/**
*
- * @since 3.2
+ * @since 0.8.0
*/
public abstract class AbstractRubyCompletionProposal implements IRubyCompletionProposal, ICompletionProposalExtension, ICompletionProposalExtension2, ICompletionProposalExtension3, ICompletionProposalExtension5 {
/**
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/CompletionProposalLabelProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/CompletionProposalLabelProvider.java 2007-02-07 18:18:08 UTC (rev 1937)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/CompletionProposalLabelProvider.java 2007-02-07 22:00:20 UTC (rev 1938)
@@ -18,6 +18,7 @@
import org.rubypeople.rdt.internal.ui.RubyPluginImages;
import org.rubypeople.rdt.internal.ui.viewsupport.RubyElementImageProvider;
import org.rubypeople.rdt.ui.RubyElementImageDescriptor;
+import org.rubypeople.rdt.ui.RubyElementLabels;
/**
* Provides labels for ruby content assist proposals. The functionality is
@@ -25,7 +26,7 @@
* but based on signatures and {@link CompletionProposal}s.
*
* @see Signature
- * @since 3.1
+ * @since 0.8.0
*/
public class CompletionProposalLabelProvider {
/**
@@ -93,4 +94,139 @@
return new RubyElementImageDescriptor(descriptor, adornments, RubyElementImageProvider.SMALL_SIZE);
}
+ public String createLabel(CompletionProposal proposal) {
+ switch (proposal.getKind()) {
+ case CompletionProposal.METHOD_NAME_REFERENCE:
+ case CompletionProposal.METHOD_REF:
+ case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
+ return createMethodProposalLabel(proposal);
+// case CompletionProposal.METHOD_DECLARATION:
+// return createOverrideMethodProposalLabel(proposal);
+ case CompletionProposal.TYPE_REF:
+ return createTypeProposalLabel(proposal);
+ case CompletionProposal.FIELD_REF:
+ case CompletionProposal.LOCAL_VARIABLE_REF:
+ case CompletionProposal.VARIABLE_DECLARATION:
+ case CompletionProposal.METHOD_DECLARATION:
+ return createSimpleLabelWithType(proposal);
+ case CompletionProposal.KEYWORD:
+ return createSimpleLabel(proposal);
+ default:
+ Assert.isTrue(false);
+ return null;
+ }
+ }
+
+ /**
+ * Creates a display label for a given type proposal. The display label
+ * consists of:
+ * <ul>
+ * <li>the simple type name (erased when the context is in javadoc)</li>
+ * <li>the package name</li>
+ * </ul>
+ * <p>
+ * Examples:
+ * A proposal for the generic type <code>java.util.List<E></code>, the display label
+ * is: <code>List<E> - java.util</code>.
+ * </p>
+ *
+ * @param typeProposal the method proposal to display
+ * @return the display label for the given type proposal
+ */
+ String createTypeProposalLabel(CompletionProposal typeProposal) {
+ String typeName= typeProposal.getType();
+ return createTypeProposalLabel(typeName);
+ }
+
+ /**
+ * Creates a display label for the given method proposal. The display label
+ * consists of:
+ * <ul>
+ * <li>the method name</li>
+ * <li>the parameter list (see {@link #createParameterList(CompletionProposal)})</li>
+ * <li>the upper bound of the return type (see {@link SignatureUtil#getUpperBound(String)})</li>
+ * <li>the raw simple name of the declaring type</li>
+ * </ul>
+ * <p>
+ * Examples:
+ * For the <code>get(int)</code> method of a variable of type <code>List<? extends Number></code>, the following
+ * display name is returned: <code>get(int index) Number - List</code>.<br>
+ * For the <code>add(E)</code> method of a variable of type <code>List<? super Number></code>, the following
+ * display name is returned: <code>add(Number o) void - List</code>.<br>
+ * </p>
+ *
+ * @param methodProposal the method proposal to display
+ * @return the display label for the given method proposal
+ */
+ String createMethodProposalLabel(CompletionProposal methodProposal) {
+ StringBuffer nameBuffer= new StringBuffer();
+
+ // method name
+ nameBuffer.append(methodProposal.getName());
+
+ // parameters
+ appendUnboundedParameterList(nameBuffer, methodProposal);
+
+ // declaring type
+ nameBuffer.append(RubyElementLabels.CONCAT_STRING);
+ String declaringType= methodProposal.getDeclaringType();
+ nameBuffer.append(declaringType);
+
+ return nameBuffer.toString();
+ }
+
+ private final StringBuffer appendUnboundedParameterList(StringBuffer buffer, CompletionProposal methodProposal) {
+ String[] names = methodProposal.getParameterNames();
+ if (names == null) return buffer;
+ if (names.length > 0) {
+ buffer.append('(');
+ }
+ for (int i = 0; i < names.length; i++) {
+ if (i > 0) {
+ buffer.append(',');
+ buffer.append(' ');
+ }
+ buffer.append(names[i]);
+ }
+ if (names.length > 0) {
+ buffer.append(')');
+ }
+ return buffer;
+ }
+
+ String createSimpleLabel(CompletionProposal proposal) {
+ return String.valueOf(proposal.getCompletion());
+ }
+
+ String createSimpleLabelWithType(CompletionProposal proposal) {
+ StringBuffer buf= new StringBuffer();
+ buf.append(proposal.getCompletion());
+ String typeName= proposal.getType();
+ if (typeName.length() > 0) {
+ buf.append(" "); //$NON-NLS-1$
+ buf.append(typeName);
+ }
+ return buf.toString();
+ }
+
+ String createTypeProposalLabel(String fullName) {
+ // only display innermost type name as type name, using any
+ // enclosing types as qualification
+ int qIndex= findSimpleNameStart(fullName);
+
+ StringBuffer buf= new StringBuffer();
+ buf.append(fullName, qIndex, fullName.length() - qIndex);
+ if (qIndex > 0) {
+ buf.append(RubyElementLabels.CONCAT_STRING);
+ buf.append(fullName, 0, qIndex - 1);
+ }
+ return buf.toString();
+ }
+
+ private int findSimpleNameStart(String fullName) {
+ int index = fullName.lastIndexOf("::");
+ if (index == -1) return 0;
+ return index;
+ }
+
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyScriptCompletion.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyScriptCompletion.java 2007-02-07 18:18:08 UTC (rev 1937)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyScriptCompletion.java 2007-02-07 22:00:20 UTC (rev 1938)
@@ -237,7 +237,7 @@
String completion= proposal.getCompletion();
int start= proposal.getReplaceStart();
int length= getLength(proposal);
- String label= proposal.getName();
+ String label= fLabelProvider.createLabel(proposal);
int relevance= computeRelevance(proposal);
Image image = getImage(fLabelProvider.createImageDescriptor(proposal));
return new RubyCompletionProposal(completion, start, length, image, label, relevance);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|