]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.ui.text.java; | |
12 | ||
13 | import org.eclipse.osgi.util.TextProcessor; | |
14 | ||
15 | import org.eclipse.swt.graphics.Image; | |
16 | ||
17 | import org.eclipse.core.runtime.Assert; | |
18 | ||
19 | import org.eclipse.jface.viewers.StyledString; | |
20 | ||
21 | import org.eclipse.jface.text.IDocument; | |
22 | import org.eclipse.jface.text.contentassist.ICompletionProposal; | |
23 | ||
24 | import org.eclipse.jdt.core.CompletionProposal; | |
25 | ||
26 | import org.eclipse.jdt.ui.text.java.CompletionProposalCollector; | |
27 | import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; | |
28 | import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext; | |
29 | ||
30 | import org.eclipse.jdt.internal.ui.refactoring.contentassist.CUPositionCompletionProcessor.CUPositionCompletionRequestor; | |
31 | ||
32 | ||
33 | public class JavaCompletionProposal extends AbstractJavaCompletionProposal { | |
34 | ||
35 | /** | |
36 | * Creates a new completion proposal. All fields are initialized based on the provided | |
37 | * information. | |
38 | * | |
39 | * @param replacementString the actual string to be inserted into the document | |
40 | * @param replacementOffset the offset of the text to be replaced | |
41 | * @param replacementLength the length of the text to be replaced | |
42 | * @param image the image to display for this proposal | |
43 | * @param displayString the string to be displayed for the proposal If set to <code>null</code>, the replacement string will be taken as display string. | |
44 | * @param relevance the relevance | |
45 | */ | |
46 | public JavaCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, int relevance) { | |
47 | this(replacementString, replacementOffset, replacementLength, image, new StyledString(displayString), relevance, false); | |
48 | } | |
49 | ||
50 | /** | |
51 | * Creates a new completion proposal. All fields are initialized based on the provided | |
52 | * information. | |
53 | * | |
54 | * @param replacementString the actual string to be inserted into the document | |
55 | * @param replacementOffset the offset of the text to be replaced | |
56 | * @param replacementLength the length of the text to be replaced | |
57 | * @param image the image to display for this proposal | |
58 | * @param displayString the string to be displayed for the proposal If set to <code>null</code>, the replacement string will be taken as display string. | |
59 | * @param relevance the relevance | |
60 | */ | |
61 | public JavaCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, StyledString displayString, int relevance) { | |
62 | this(replacementString, replacementOffset, replacementLength, image, displayString, relevance, false); | |
63 | } | |
64 | ||
65 | /** | |
66 | * Creates a new completion proposal. All fields are initialized based on the provided | |
67 | * information. | |
68 | * | |
69 | * @param replacementString the actual string to be inserted into the document | |
70 | * @param replacementOffset the offset of the text to be replaced | |
71 | * @param replacementLength the length of the text to be replaced | |
72 | * @param image the image to display for this proposal | |
73 | * @param displayString the string to be displayed for the proposal If set to <code>null</code>, | |
74 | * the replacement string will be taken as display string. | |
75 | * @param relevance the relevance | |
76 | * @param inJavadoc <code>true</code> for a javadoc proposal | |
77 | */ | |
78 | public JavaCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, StyledString displayString, int relevance, boolean inJavadoc) { | |
79 | this(replacementString, replacementOffset, replacementLength, image, displayString, relevance, inJavadoc, null); | |
80 | } | |
81 | ||
82 | /** | |
83 | * Creates a new completion proposal. All fields are initialized based on the provided | |
84 | * information. | |
85 | * | |
86 | * @param replacementString the actual string to be inserted into the document | |
87 | * @param replacementOffset the offset of the text to be replaced | |
88 | * @param replacementLength the length of the text to be replaced | |
89 | * @param image the image to display for this proposal | |
90 | * @param displayString the string to be displayed for the proposal If set to <code>null</code>, | |
91 | * the replacement string will be taken as display string. | |
92 | * @param relevance the relevance | |
93 | * @param inJavadoc <code>true</code> for a javadoc proposal | |
94 | * @param invocationContext the invocation context of this completion proposal or <code>null</code> not available | |
95 | */ | |
96 | public JavaCompletionProposal(String replacementString, int replacementOffset, int replacementLength, Image image, StyledString displayString, int relevance, boolean inJavadoc, JavaContentAssistInvocationContext invocationContext) { | |
97 | super(invocationContext); | |
98 | Assert.isNotNull(replacementString); | |
99 | Assert.isTrue(replacementOffset >= 0); | |
100 | Assert.isTrue(replacementLength >= 0); | |
101 | ||
102 | setReplacementString(replacementString); | |
103 | setReplacementOffset(replacementOffset); | |
104 | setReplacementLength(replacementLength); | |
105 | setImage(image); | |
106 | setStyledDisplayString(displayString == null ? new StyledString(replacementString) : displayString); | |
107 | setRelevance(relevance); | |
108 | setCursorPosition(replacementString.length()); | |
109 | setInJavadoc(inJavadoc); | |
110 | setSortString(displayString == null ? replacementString : displayString.getString()); | |
111 | } | |
112 | ||
113 | /* | |
114 | * @see org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal#isValidPrefix(java.lang.String) | |
115 | */ | |
116 | @Override | |
117 | protected boolean isValidPrefix(String prefix) { | |
118 | String word= TextProcessor.deprocess(getDisplayString()); | |
119 | if (isInJavadoc()) { | |
120 | int idx = word.indexOf("{@link "); //$NON-NLS-1$ | |
121 | if (idx==0) { | |
122 | word = word.substring(7); | |
123 | } else { | |
124 | idx = word.indexOf("{@value "); //$NON-NLS-1$ | |
125 | if (idx==0) { | |
126 | word = word.substring(8); | |
127 | } | |
128 | } | |
129 | } else if (word.indexOf("this.") != -1) { //$NON-NLS-1$ | |
130 | word= word.substring(word.indexOf("this.") + 5); //$NON-NLS-1$ | |
131 | } | |
132 | return isPrefix(prefix, word); | |
133 | } | |
134 | ||
135 | /* | |
136 | * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension3#getReplacementText() | |
137 | */ | |
138 | @Override | |
139 | public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) { | |
140 | String string= getReplacementString(); | |
141 | int pos= string.indexOf('('); | |
142 | if (pos > 0) | |
143 | return string.subSequence(0, pos); | |
144 | else if (string.startsWith("this.")) //$NON-NLS-1$ | |
145 | return string.substring(5); | |
146 | else | |
147 | return string; | |
148 | } | |
149 | ||
150 | public ICompletionProposal[] generated_2597104358469167081(boolean isLastParameter) { | |
151 | ICompletionProposal[] argumentProposals; | |
152 | if (isLastParameter) | |
153 | setTriggerCharacters(new char[] { ',' }); | |
154 | argumentProposals= new ICompletionProposal[] { this }; | |
155 | return argumentProposals; | |
156 | } | |
157 | ||
158 | public JavaCompletionProposal generated_5644859788046834410() { | |
159 | setTriggerCharacters( new char[] { '>' }); | |
160 | return this; | |
161 | } | |
162 | ||
163 | public IJavaCompletionProposal generated_1085805144306456903(CompletionProposal proposal, CompletionProposalCollector completionproposalcollector) { | |
164 | if (completionproposalcollector.fJavaProject != null) | |
165 | setProposalInfo(new AnnotationAtttributeProposalInfo(completionproposalcollector.fJavaProject, proposal)); | |
166 | return this; | |
167 | } | |
168 | ||
169 | public IJavaCompletionProposal generated_8710977922227765588(CompletionProposal proposal, CompletionProposalCollector completionproposalcollector) { | |
170 | setProposalInfo(new AnonymousTypeProposalInfo(completionproposalcollector.fJavaProject, proposal)); | |
171 | return this; | |
172 | } | |
173 | ||
174 | public IJavaCompletionProposal generated_6169036862569312000(CompletionProposal proposal, CompletionProposalCollector completionproposalcollector) { | |
175 | if (completionproposalcollector.fJavaProject != null) | |
176 | setProposalInfo(new FieldProposalInfo(completionproposalcollector.fJavaProject, proposal)); | |
177 | ||
178 | setTriggerCharacters(CompletionProposalCollector.VAR_TRIGGER); | |
179 | ||
180 | return this; | |
181 | } | |
182 | ||
183 | public IJavaCompletionProposal generated_90604847485554564(CompletionProposal proposal, CompletionProposalCollector completionproposalcollector) { | |
184 | if (completionproposalcollector.fJavaProject != null) | |
185 | setProposalInfo(new FieldProposalInfo(completionproposalcollector.fJavaProject, proposal)); | |
186 | ||
187 | setTriggerCharacters(CompletionProposalCollector.VAR_TRIGGER); | |
188 | ||
189 | return this; | |
190 | } | |
191 | ||
192 | public IJavaCompletionProposal generated_8118086481586854877() { | |
193 | setTriggerCharacters(CompletionProposalCollector.VAR_TRIGGER); | |
194 | return this; | |
195 | } | |
196 | ||
197 | public void generated_3970434028007335647(CUPositionCompletionRequestor cupositioncompletionrequestor) { | |
198 | setTriggerCharacters(CUPositionCompletionRequestor.TRIGGER_CHARACTERS); | |
199 | cupositioncompletionrequestor.fProposals.add(this); | |
200 | } | |
201 | } |