Search in sources :

Example 1 with SmartCompletionContextType

use of com.intellij.codeInsight.template.SmartCompletionContextType in project intellij-community by JetBrains.

the class BasicExpressionCompletionContributor method fillCompletionVariants.

public static void fillCompletionVariants(JavaSmartCompletionParameters parameters, final Consumer<LookupElement> result, PrefixMatcher matcher) {
    final PsiElement element = parameters.getPosition();
    if (JavaKeywordCompletion.isAfterTypeDot(element)) {
        addKeyword(result, element, PsiKeyword.CLASS);
        addKeyword(result, element, PsiKeyword.THIS);
    }
    if (!JavaKeywordCompletion.AFTER_DOT.accepts(element)) {
        if (parameters.getParameters().getInvocationCount() <= 1) {
            new CollectionsUtilityMethodsProvider(parameters.getPosition(), parameters.getExpectedType(), parameters.getDefaultType(), result).addCompletions(StringUtil.isNotEmpty(matcher.getPrefix()));
        }
        ClassLiteralGetter.addCompletions(parameters, result, matcher);
        final PsiElement position = parameters.getPosition();
        final PsiType expectedType = parameters.getExpectedType();
        for (final TemplateImpl template : TemplateSettings.getInstance().getTemplates()) {
            if (!template.isDeactivated() && template.getTemplateContext().isEnabled(new SmartCompletionContextType())) {
                result.consume(new SmartCompletionTemplateItem(template, position));
            }
        }
        addKeyword(result, position, PsiKeyword.TRUE);
        addKeyword(result, position, PsiKeyword.FALSE);
        final PsiElement parent = position.getParent();
        if (parent != null && !(parent.getParent() instanceof PsiSwitchLabelStatement)) {
            for (final PsiExpression expression : ThisGetter.getThisExpressionVariants(position)) {
                result.consume(new ExpressionLookupItem(expression));
            }
        }
        processDataflowExpressionTypes(position, expectedType, matcher, result);
    }
}
Also used : TemplateImpl(com.intellij.codeInsight.template.impl.TemplateImpl) SmartCompletionContextType(com.intellij.codeInsight.template.SmartCompletionContextType) ExpressionLookupItem(com.intellij.codeInsight.lookup.ExpressionLookupItem)

Example 2 with SmartCompletionContextType

use of com.intellij.codeInsight.template.SmartCompletionContextType in project intellij-community by JetBrains.

the class SmartTypeCompletionTest method testLiveTemplate.

public void testLiveTemplate() throws Throwable {
    final Template template = TemplateManager.getInstance(getProject()).createTemplate("foo", "zzz");
    template.addTextSegment("FooFactory.createFoo()");
    final SmartCompletionContextType completionContextType = ContainerUtil.findInstance(TemplateContextType.EP_NAME.getExtensions(), SmartCompletionContextType.class);
    ((TemplateImpl) template).getTemplateContext().setEnabled(completionContextType, true);
    CodeInsightTestUtil.addTemplate(template, myFixture.getTestRootDisposable());
    doTest();
}
Also used : SmartCompletionContextType(com.intellij.codeInsight.template.SmartCompletionContextType) Template(com.intellij.codeInsight.template.Template)

Aggregations

SmartCompletionContextType (com.intellij.codeInsight.template.SmartCompletionContextType)2 ExpressionLookupItem (com.intellij.codeInsight.lookup.ExpressionLookupItem)1 Template (com.intellij.codeInsight.template.Template)1 TemplateImpl (com.intellij.codeInsight.template.impl.TemplateImpl)1