diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java index 8c39a78220c1..2722aa6f2c8d 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ import java.util.List; * A: Define a completion.contributor extension of type {@link CompletionContributor}. * Or, if the place you want to complete in contains a {@link PsiReference}, just return the variants * you want to suggest from its {@link PsiReference#getVariants()} method as {@link String}s, - * {@link com.intellij.psi.PsiElement}s, or better {@link LookupElement}s.

+ * {@link PsiElement}s, or better {@link LookupElement}s.

* * Q: OK, but what to do with CompletionContributor?
* A: There are two ways. The easier and preferred one is to provide constructor in your contributor and register completion providers there: @@ -57,7 +57,7 @@ import java.util.List; * Q: What does the {@link CompletionParameters#getPosition()} return?
* A: When completion is invoked, the file being edited is first copied (the original file can be accessed from {@link com.intellij.psi.PsiFile#getOriginalFile()} * and {@link CompletionParameters#getOriginalFile()}. Then a special 'dummy identifier' string is inserted to the copied file at caret offset (removing the selection). - * Most often this string is an identifier (see {@link com.intellij.codeInsight.completion.CompletionInitializationContext#DUMMY_IDENTIFIER}). + * Most often this string is an identifier (see {@link CompletionInitializationContext#DUMMY_IDENTIFIER}). * This is usually done to guarantee that there'll always be some non-empty element there, which will be easy to describe via {@link ElementPattern}s. * Also a reference can suddenly appear in that position, which will certainly help invoking its {@link PsiReference#getVariants()}. * Dummy identifier string can be easily changed in {@link #beforeCompletion(CompletionInitializationContext)} method.

@@ -66,10 +66,10 @@ import java.util.List; * A: When you return variants from reference ({@link PsiReference#getVariants()}), the filtering will be done * automatically, with prefix taken as the reference text from its start ({@link PsiReference#getRangeInElement()}) to * the caret position. - * In {@link CompletionContributor} you will be given a {@link com.intellij.codeInsight.completion.CompletionResultSet} + * In {@link CompletionContributor} you will be given a {@link CompletionResultSet} * which will match {@link LookupElement}s against its prefix matcher {@link CompletionResultSet#getPrefixMatcher()}. - * If the default prefix calculated by IntelliJ IDEA doesn't satisfy you, you can obtain another result set via - * {@link com.intellij.codeInsight.completion.CompletionResultSet#withPrefixMatcher(PrefixMatcher)} and feed your lookup elements to the latter. + * If the default prefix calculated by the IDE doesn't satisfy you, you can obtain another result set via + * {@link CompletionResultSet#withPrefixMatcher(PrefixMatcher)} and feed your lookup elements to the latter. * It's one of the item's lookup strings ({@link LookupElement#getAllLookupStrings()} that is matched against prefix matcher.

* * Q: How do I plug into those funny texts below the items in shown lookup?
@@ -82,27 +82,27 @@ import java.util.List; * Q: How do I affect lookup element's appearance (icon, text attributes, etc.)?
* A: See {@link LookupElement#renderElement(LookupElementPresentation)}.

* - * Q: I'm not satisfied that completion just inserts the item's lookup string on item selection. How make IDEA write something else?
+ * Q: I'm not satisfied that completion just inserts the item's lookup string on item selection. How to make it write something else?
* A: See {@link LookupElement#handleInsert(InsertionContext)}.

* - * Q: What if I select item with a Tab key?
+ * Q: What if I select item with TAB key?
* A: Semantics is, that the identifier that you're standing inside gets removed completely, and then the lookup string is inserted. You can change * the deleting range end offset, do it in {@link CompletionContributor#beforeCompletion(CompletionInitializationContext)} - * by putting new offset to {@link CompletionInitializationContext#getOffsetMap()} as {@link com.intellij.codeInsight.completion.CompletionInitializationContext#IDENTIFIER_END_OFFSET}.

+ * by putting new offset to {@link CompletionInitializationContext#getOffsetMap()} as {@link CompletionInitializationContext#IDENTIFIER_END_OFFSET}.

* - * Q: I know about my environment more than IDEA does, and I can swear that those 239 variants that IDEA suggest me in some place aren't all that relevant, + * Q: I know more about my environment than the IDE does, and I can swear that those 239 variants it suggests me in some place aren't all that relevant, * so I'd be happy to filter out 42 of them. How do I do this?
* A: This is a bit harder than just adding variants. First, you should invoke - * {@link com.intellij.codeInsight.completion.CompletionResultSet#runRemainingContributors(CompletionParameters, com.intellij.util.Consumer)}. - * The consumer you provide should pass all the lookup elements to the {@link com.intellij.codeInsight.completion.CompletionResultSet} + * {@link CompletionResultSet#runRemainingContributors(CompletionParameters, Consumer)}. + * The consumer you provide should pass all the lookup elements to the {@link CompletionResultSet} * given to you, except for the ones you wish to filter out. Be careful: it's too easy to break completion this way. Since you've * ordered to invoke remaining contributors yourself, they won't be invoked automatically after yours finishes (see * {@link CompletionResultSet#stopHere()} and {@link CompletionResultSet#isStopped()}). - * Calling {@link CompletionResultSet#stopHere()} explicitly will stop other contributors, that happened to be loaded after yours, + * Calling {@link CompletionResultSet#stopHere()} explicitly will stop other contributors (which happened to be loaded after yours) * from execution, and the user will never see their so useful and precious completion variants, so please be careful with this method.

* - * Q: How are the lookup elements sorted?
- * A: Basically in lexicographic order, ascending, by lookup string ({@link LookupElement#getLookupString()}. But some of elements + * Q: How are lookup elements sorted?
+ * A: Basically in lexicographic order, ascending, by lookup string ({@link LookupElement#getLookupString()}. But some of the elements * may be considered more relevant, i.e. having a bigger probability of being chosen by user. Such elements (no more than 5) may be moved to * the top of lookup and highlighted with green background. This is done by hooking into lookup elements comparator via creating your own * {@link CompletionWeigher} and registering it as a "weigher" extension under "completion" key.

@@ -116,7 +116,7 @@ import java.util.List; * is the 'final' consumer, it will pass your lookup elements directly to the lookup.
* If your contributor isn't even invoked, probably there was another contributor that said 'stop' to the system, and yours happened to be ordered after * that contributor. To test this hypothesis, put a breakpoint to - * {@link CompletionService#getVariantsFromContributors(CompletionParameters, CompletionContributor, com.intellij.util.Consumer)}, + * {@link CompletionService#getVariantsFromContributors(CompletionParameters, CompletionContributor, Consumer)}, * to the 'return false' line.

* * @author peter @@ -132,17 +132,17 @@ public abstract class CompletionContributor { } /** - * The main contributor method that is supposed to provide completion variants to result, basing on completion parameters. - * The default implementation looks for {@link com.intellij.codeInsight.completion.CompletionProvider}s you could register by - * invoking {@link #extend(CompletionType, ElementPattern, CompletionProvider)} from you contributor constructor, + * The main contributor method that is supposed to provide completion variants to result, based on completion parameters. + * The default implementation looks for {@link CompletionProvider}s you could register by + * invoking {@link #extend(CompletionType, ElementPattern, CompletionProvider)} from your contributor constructor, * matches the desired completion type and {@link ElementPattern} with actual ones, and, depending on it, invokes those * completion providers.

* * If you want to implement this functionality directly by overriding this method, the following is for you. * Always check that parameters match your situation, and that completion type ({@link CompletionParameters#getCompletionType()} * is of your favourite kind. This method is run inside a read action. If you do any long activity non-related to PSI in it, please - * ensure you call {@link com.intellij.openapi.progress.ProgressManager#checkCanceled()} often enough so that the completion process - * can be cancelled smoothly when the user begins to type in the editor. + * ensure you call {@link com.intellij.openapi.progress.ProgressManager#checkCanceled()} often enough so that the completion process + * can be cancelled smoothly when the user begins to type in the editor. */ public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull CompletionResultSet result) { for (final Pair, CompletionProvider> pair : myMap.get(parameters.getCompletionType())) { @@ -172,7 +172,7 @@ public abstract class CompletionContributor { } /** - * @deprecated use {@link com.intellij.codeInsight.completion.CompletionResultSet#addLookupAdvertisement(String)} + * @deprecated use {@link CompletionResultSet#addLookupAdvertisement(String)} * @return text to be shown at the bottom of lookup list */ @Nullable @@ -206,7 +206,7 @@ public abstract class CompletionContributor { /** * Invoked in a read action in parallel to the completion process. Used to calculate the replacement offset - * (see {@link com.intellij.codeInsight.completion.CompletionInitializationContext#setReplacementOffset(int)}) + * (see {@link CompletionInitializationContext#setReplacementOffset(int)}) * if it takes too much time to spend it in {@link #beforeCompletion(CompletionInitializationContext)}, * e.g. doing {@link com.intellij.psi.PsiFile#findReferenceAt(int)} * @@ -216,7 +216,7 @@ public abstract class CompletionContributor { */ public void duringCompletion(@NotNull CompletionInitializationContext context) { } - + /** * @return String representation of action shortcut. Useful while advertising something * @see #advertise(CompletionParameters)