1 11 12 package org.eclipse.jdt.internal.ui.text.java; 13 14 15 import org.eclipse.core.runtime.Assert; 16 17 import org.eclipse.swt.graphics.Image; 18 19 import org.eclipse.jface.text.IDocument; 20 21 import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext; 22 23 24 public class JavaCompletionProposal extends AbstractJavaCompletionProposal { 25 26 37 public JavaCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, int relevance) { 38 this(replacementString, replacementOffset, replacementLength, image, displayString, relevance, false); 39 } 40 41 55 public JavaCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, int relevance, boolean inJavadoc) { 56 this(replacementString, replacementOffset, replacementLength, image, displayString, relevance, inJavadoc, null); 57 } 58 59 74 public JavaCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, int relevance, boolean inJavadoc, JavaContentAssistInvocationContext invocationContext) { 75 super(invocationContext); 76 Assert.isNotNull(replacementString); 77 Assert.isTrue(replacementOffset >= 0); 78 Assert.isTrue(replacementLength >= 0); 79 80 setReplacementString(replacementString); 81 setReplacementOffset(replacementOffset); 82 setReplacementLength(replacementLength); 83 setImage(image); 84 setDisplayString(displayString == null ? replacementString : displayString); 85 setRelevance(relevance); 86 setCursorPosition(replacementString.length()); 87 setInJavadoc(inJavadoc); 88 setSortString(displayString == null ? replacementString : displayString); 89 } 90 91 94 protected boolean isValidPrefix(String prefix) { 95 String word= getDisplayString(); 96 if (isInJavadoc()) { 97 int idx = word.indexOf("{@link "); if (idx==0) { 99 word = word.substring(7); 100 } else { 101 idx = word.indexOf("{@value "); if (idx==0) { 103 word = word.substring(8); 104 } 105 } 106 } else if (word.indexOf("this.") != -1) { word= word.substring(word.indexOf("this.") + 5); } 109 return isPrefix(prefix, word); 110 } 111 112 115 public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) { 116 String string= getReplacementString(); 117 int pos= string.indexOf('('); 118 if (pos > 0) 119 return string.subSequence(0, pos); 120 else if (string.startsWith("this.")) return string.substring(5); 122 else 123 return string; 124 } 125 } 126 | Popular Tags |