package biz.paluch.atsoundtrack;

import org.jetbrains.annotations.NotNull;

import com.intellij.codeInsight.completion.CompletionContributor;
import com.intellij.codeInsight.completion.CompletionParameters;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.codeInsight.lookup.LookupElement;

/**
 * @author <a href="mailto:mpaluch@paluch.biz">Mark Paluch</a>
 * @since 13.05.15 11:49
 */
public class AtSoundtrackContributor extends CompletionContributor {

    @Override
    public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {


        if (AtSoundtrack.getName() != null) {
            result.addElement(new LookupElement() {
                @NotNull
                @Override
                public String getLookupString() {
                    return "@soundtrack " + AtSoundtrack.getName();
                }
            });
        }
        super.fillCompletionVariants(parameters, result);
    }
}

@@ -38,41 +38,58 @@
 ort 
-org.jetbrains.annotations.NotNull
+static com.intellij.openapi.util.text.StringUtil.*
 ;%0A%0Ai
@@ -334,16 +334,180 @@
 pElement
+Builder;%0Aimport com.intellij.psi.PsiComment;%0Aimport com.intellij.psi.PsiDocCommentBase;%0Aimport com.intellij.psi.xml.XmlComment;%0Aimport com.intellij.psi.xml.XmlToken
 ;%0A%0A/**%0A 
@@ -788,237 +788,1207 @@
  %7B%0A%0A
-%0A        if (AtSoundtrack.getName() != null) %7B%0A            result.addElement(new LookupElement() %7B%0A                @NotNull%0A                @Override%0A                public String getLookupString() %7B%0A                    return %22@
+        String prefix = parameters.getOriginalPosition().getText();%0A%0A        if (!prefix.contains(%22soundtrack%22)) %7B%0A%0A            if (!isEmpty(AtSoundtrack.getName())) %7B%0A%0A                boolean qualified = false;%0A                if (parameters.getOriginalPosition() instanceof PsiComment%0A                        %7C%7C parameters.getOriginalPosition().getContext() instanceof PsiDocCommentBase%0A                        %7C%7C parameters.getOriginalPosition().getClass().getName().contains(%22PsiDocToken%22)) %7B%0A%0A                    qualified = true;%0A                %7D%0A                if (parameters.getOriginalPosition() instanceof XmlToken) %7B%0A                    XmlToken xmlToken = (XmlToken) parameters.getOriginalPosition();%0A%0A                    if (xmlToken instanceof XmlComment %7C%7C xmlToken.getContext() instanceof XmlComment) %7B%0A                        qualified = true;%0A                    %7D%0A                %7D%0A%0A                if (qualified) %7B%0A                    if (!prefix.contains(%22@%22)) %7B%0A                        result.addElement(LookupElementBuilder.create(%22@soundtrack %22 + AtSoundtrack.getName()));%0A                    %7D else %7B%0A                        result.addElement(LookupElementBuilder.create(%22
 soun
@@ -2020,16 +2020,18 @@
 etName()
+))
 ;%0A      
@@ -2032,32 +2032,36 @@
                 
+ 
+   
 %7D%0A            %7D)
@@ -2062,11 +2062,27 @@
     
-%7D);
+    %7D%0A            %7D
 %0A   
@@ -2080,32 +2080,33 @@
     %7D%0A        %7D%0A
+%0A
         super.fi

Use code completion in multiple places and compatibility with PyCharm, RubyMine, PhpStorm