PageRenderTime 51ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/aspectj-1.6.9/aspectjtools1.6.9/org/aspectj/org/eclipse/jdt/core/CompletionRequestor.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 305 lines | 72 code | 21 blank | 212 comment | 22 complexity | a8528f5217693b9c853d31f8bc70e384 MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2004, 2007 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.aspectj.org.eclipse.jdt.core;
  12. import org.aspectj.org.eclipse.jdt.core.compiler.IProblem;
  13. /**
  14. * Abstract base class for a completion requestor which is passed completion
  15. * proposals as they are generated in response to a code assist request.
  16. * <p>
  17. * This class is intended to be subclassed by clients.
  18. * </p>
  19. * <p>
  20. * The code assist engine normally invokes methods on completion
  21. * requestor in the following sequence:
  22. * <pre>
  23. * requestor.beginReporting();
  24. * requestor.acceptContext(context);
  25. * requestor.accept(proposal_1);
  26. * requestor.accept(proposal_2);
  27. * ...
  28. * requestor.endReporting();
  29. * </pre>
  30. * If, however, the engine is unable to offer completion proposals
  31. * for whatever reason, <code>completionFailure</code> is called
  32. * with a problem object describing why completions were unavailable.
  33. * In this case, the sequence of calls is:
  34. * <pre>
  35. * requestor.beginReporting();
  36. * requestor.acceptContext(context);
  37. * requestor.completionFailure(problem);
  38. * requestor.endReporting();
  39. * </pre>
  40. * In either case, the bracketing <code>beginReporting</code>
  41. * <code>endReporting</code> calls are always made as well as
  42. * <code>acceptContext</code> call.
  43. * </p>
  44. * <p>
  45. * The class was introduced in 3.0 as a more evolvable replacement
  46. * for the <code>ICompletionRequestor</code> interface.
  47. * </p>
  48. *
  49. * @see ICodeAssist
  50. * @since 3.0
  51. */
  52. public abstract class CompletionRequestor {
  53. /**
  54. * The set of CompletionProposal kinds that this requestor
  55. * ignores; <code>0</code> means the set is empty.
  56. * 1 << completionProposalKind
  57. */
  58. private int ignoreSet = 0;
  59. private String[] favoriteReferences;
  60. /**
  61. * The set of CompletionProposal kinds that this requestor
  62. * allows for required proposals; <code>0</code> means the set is empty.
  63. * 1 << completionProposalKind
  64. */
  65. private int requiredProposalAllowSet[] = null;
  66. /**
  67. * Creates a new completion requestor.
  68. * The requestor is interested in all kinds of completion
  69. * proposals; none will be ignored.
  70. */
  71. public CompletionRequestor() {
  72. // do nothing
  73. }
  74. /**
  75. * Returns whether the given kind of completion proposal is ignored.
  76. *
  77. * @param completionProposalKind one of the kind constants declared
  78. * on <code>CompletionProposal</code>
  79. * @return <code>true</code> if the given kind of completion proposal
  80. * is ignored by this requestor, and <code>false</code> if it is of
  81. * interest
  82. * @see #setIgnored(int, boolean)
  83. * @see CompletionProposal#getKind()
  84. */
  85. public boolean isIgnored(int completionProposalKind) {
  86. if (completionProposalKind < CompletionProposal.FIRST_KIND
  87. || completionProposalKind > CompletionProposal.LAST_KIND) {
  88. throw new IllegalArgumentException("Unknown kind of completion proposal: "+completionProposalKind); //$NON-NLS-1$
  89. }
  90. return 0 != (this.ignoreSet & (1 << completionProposalKind));
  91. }
  92. /**
  93. * Sets whether the given kind of completion proposal is ignored.
  94. *
  95. * @param completionProposalKind one of the kind constants declared
  96. * on <code>CompletionProposal</code>
  97. * @param ignore <code>true</code> if the given kind of completion proposal
  98. * is ignored by this requestor, and <code>false</code> if it is of
  99. * interest
  100. * @see #isIgnored(int)
  101. * @see CompletionProposal#getKind()
  102. */
  103. public void setIgnored(int completionProposalKind, boolean ignore) {
  104. if (completionProposalKind < CompletionProposal.FIRST_KIND
  105. || completionProposalKind > CompletionProposal.LAST_KIND) {
  106. throw new IllegalArgumentException("Unknown kind of completion proposal: "+completionProposalKind); //$NON-NLS-1$
  107. }
  108. if (ignore) {
  109. this.ignoreSet |= (1 << completionProposalKind);
  110. } else {
  111. this.ignoreSet &= ~(1 << completionProposalKind);
  112. }
  113. }
  114. /**
  115. * Returns whether a proposal of a given kind with a required proposal
  116. * of the given kind is allowed.
  117. *
  118. * @param proposalKind one of the kind constants declared
  119. * @param requiredProposalKind one of the kind constants declared
  120. * on <code>CompletionProposal</code>
  121. * @return <code>true</code> if a proposal of a given kind with a required proposal
  122. * of the given kind is allowed by this requestor, and <code>false</code>
  123. * if it isn't of interest.
  124. * <p>
  125. * By default, all kinds of required proposals aren't allowed.
  126. * </p>
  127. * @see #setAllowsRequiredProposals(int, int, boolean)
  128. * @see CompletionProposal#getKind()
  129. * @see CompletionProposal#getRequiredProposals()
  130. *
  131. * @since 3.3
  132. */
  133. public boolean isAllowingRequiredProposals(int proposalKind, int requiredProposalKind) {
  134. if (proposalKind < CompletionProposal.FIRST_KIND
  135. || proposalKind > CompletionProposal.LAST_KIND) {
  136. throw new IllegalArgumentException("Unknown kind of completion proposal: "+requiredProposalKind); //$NON-NLS-1$
  137. }
  138. if (requiredProposalKind < CompletionProposal.FIRST_KIND
  139. || requiredProposalKind > CompletionProposal.LAST_KIND) {
  140. throw new IllegalArgumentException("Unknown required kind of completion proposal: "+requiredProposalKind); //$NON-NLS-1$
  141. }
  142. if (this.requiredProposalAllowSet == null) return false;
  143. return 0 != (this.requiredProposalAllowSet[proposalKind] & (1 << requiredProposalKind));
  144. }
  145. /**
  146. * Sets whether a proposal of a given kind with a required proposal
  147. * of the given kind is allowed.
  148. *
  149. * Currently only a subset of kinds support required proposals. To see what combinations
  150. * are supported you must look at {@link CompletionProposal#getRequiredProposals()}
  151. * documentation.
  152. *
  153. * @param proposalKind one of the kind constants declared
  154. * @param requiredProposalKind one of the kind constants declared
  155. * on <code>CompletionProposal</code>
  156. * @param allow <code>true</code> if a proposal of a given kind with a required proposal
  157. * of the given kind is allowed by this requestor, and <code>false</code>
  158. * if it isn't of interest
  159. * @see #isAllowingRequiredProposals(int, int)
  160. * @see CompletionProposal#getKind()
  161. * @see CompletionProposal#getRequiredProposals()
  162. *
  163. * @since 3.3
  164. */
  165. public void setAllowsRequiredProposals(int proposalKind, int requiredProposalKind, boolean allow) {
  166. if (proposalKind < CompletionProposal.FIRST_KIND
  167. || proposalKind > CompletionProposal.LAST_KIND) {
  168. throw new IllegalArgumentException("Unknown kind of completion proposal: "+requiredProposalKind); //$NON-NLS-1$
  169. }
  170. if (requiredProposalKind < CompletionProposal.FIRST_KIND
  171. || requiredProposalKind > CompletionProposal.LAST_KIND) {
  172. throw new IllegalArgumentException("Unknown required kind of completion proposal: "+requiredProposalKind); //$NON-NLS-1$
  173. }
  174. if (this.requiredProposalAllowSet == null) {
  175. this.requiredProposalAllowSet = new int[CompletionProposal.LAST_KIND + 1];
  176. }
  177. if (allow) {
  178. this.requiredProposalAllowSet[proposalKind] |= (1 << requiredProposalKind);
  179. } else {
  180. this.requiredProposalAllowSet[proposalKind] &= ~(1 << requiredProposalKind);
  181. }
  182. }
  183. /**
  184. * Returns the favorite references which are used to compute some completion proposals.
  185. * <p>
  186. * A favorite reference is a qualified reference as it can be seen in an import statement.<br>
  187. * e.g. <code>{"java.util.Arrays"}</code><br>
  188. * It can be an on demand reference.<br>
  189. * e.g. <code>{"java.util.Arrays.*"}</code>
  190. * It can be a reference to a static method or field (as in a static import)<br>
  191. * e.g. <code>{"java.util.Arrays.equals"}</code>
  192. * </p>
  193. * <p>
  194. * Currently only on demand type references (<code>"java.util.Arrays.*"</code>),
  195. * references to a static method or a static field are used to compute completion proposals.
  196. * Other kind of reference could be used in the future.
  197. * </p>
  198. * @return favorite imports
  199. *
  200. * @since 3.3
  201. */
  202. public String[] getFavoriteReferences() {
  203. return this.favoriteReferences;
  204. }
  205. /**
  206. * Set the favorite references which will be used to compute some completion proposals.
  207. * A favorite reference is a qualified reference as it can be seen in an import statement.<br>
  208. *
  209. * @param favoriteImports
  210. *
  211. * @see #getFavoriteReferences()
  212. *
  213. * @since 3.3
  214. */
  215. public void setFavoriteReferences(String[] favoriteImports) {
  216. this.favoriteReferences = favoriteImports;
  217. }
  218. /**
  219. * Pro forma notification sent before reporting a batch of
  220. * completion proposals.
  221. * <p>
  222. * The default implementation of this method does nothing.
  223. * Clients may override.
  224. * </p>
  225. */
  226. public void beginReporting() {
  227. // do nothing
  228. }
  229. /**
  230. * Pro forma notification sent after reporting a batch of
  231. * completion proposals.
  232. * <p>
  233. * The default implementation of this method does nothing.
  234. * Clients may override.
  235. * </p>
  236. */
  237. public void endReporting() {
  238. // do nothing
  239. }
  240. /**
  241. * Notification of failure to produce any completions.
  242. * The problem object explains what prevented completing.
  243. * <p>
  244. * The default implementation of this method does nothing.
  245. * Clients may override to receive this kind of notice.
  246. * </p>
  247. *
  248. * @param problem the problem object
  249. */
  250. public void completionFailure(IProblem problem) {
  251. // default behavior is to ignore
  252. }
  253. /**
  254. * Proposes a completion. Has no effect if the kind of proposal
  255. * is being ignored by this requestor. Callers should consider
  256. * checking {@link #isIgnored(int)} before avoid creating proposal
  257. * objects that would only be ignored.
  258. * <p>
  259. * Similarly, implementers should check
  260. * {@link #isIgnored(int) isIgnored(proposal.getKind())}
  261. * and ignore proposals that have been declared as uninteresting.
  262. * The proposal object passed is only valid for the duration of
  263. * completion operation.
  264. *
  265. * @param proposal the completion proposal
  266. * @exception IllegalArgumentException if the proposal is null
  267. */
  268. public abstract void accept(CompletionProposal proposal);
  269. /**
  270. * Propose the context in which the completion occurs.
  271. * <p>
  272. * This method is called one and only one time before any call to
  273. * {@link #accept(CompletionProposal)}.
  274. * The default implementation of this method does nothing.
  275. * Clients may override.
  276. * </p>
  277. * @param context the completion context
  278. *
  279. * @since 3.1
  280. */
  281. public void acceptContext(CompletionContext context) {
  282. // do nothing
  283. }
  284. }