Search in sources :

Example 11 with ProcessingContext

use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.

the class WordCompletionTest method testNoWordCompletionForNonSoftReference.

public void testNoWordCompletionForNonSoftReference() throws Throwable {
    final PsiReferenceProvider softProvider = new PsiReferenceProvider() {

        @Override
        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
            return new PsiReference[] { new PsiReferenceBase<PsiElement>(element, true) {

                @Override
                public PsiElement resolve() {
                    return null;
                }

                @Override
                @NotNull
                public Object[] getVariants() {
                    return new Object[] { "MySoftVariant" };
                }
            } };
        }
    };
    final PsiReferenceProvider hardProvider = new PsiReferenceProvider() {

        @Override
        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
            return new PsiReference[] { new PsiReferenceBase<PsiElement>(element, false) {

                @Override
                public PsiElement resolve() {
                    return null;
                }

                @Override
                @NotNull
                public Object[] getVariants() {
                    return new Object[] { "MyHardVariant" };
                }
            } };
        }
    };
    PsiReferenceRegistrarImpl registrar = (PsiReferenceRegistrarImpl) ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA);
    try {
        registrar.registerReferenceProvider(PsiLiteralExpression.class, softProvider);
        registrar.registerReferenceProvider(PsiLiteralExpression.class, hardProvider);
        configureByFile(BASE_PATH + "3.java");
        checkResultByFile(BASE_PATH + "3_after.java");
    } finally {
        registrar.unregisterReferenceProvider(PsiLiteralExpression.class, softProvider);
        registrar.unregisterReferenceProvider(PsiLiteralExpression.class, hardProvider);
    }
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) NotNull(org.jetbrains.annotations.NotNull) PsiReferenceRegistrarImpl(com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl)

Example 12 with ProcessingContext

use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.

the class StringPattern method matches.

@NotNull
public StringPattern matches(@NonNls @NotNull final String s) {
    final String escaped = StringUtil.escapeToRegexp(s);
    if (escaped.equals(s)) {
        return equalTo(s);
    }
    // may throw PatternSyntaxException here
    final Pattern pattern = Pattern.compile(s);
    return with(new ValuePatternCondition<String>("matches") {

        @Override
        public boolean accepts(@NotNull final String str, final ProcessingContext context) {
            return pattern.matcher(newBombedCharSequence(str)).matches();
        }

        @Override
        public Collection<String> getValues() {
            return Collections.singleton(s);
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) ProcessingContext(com.intellij.util.ProcessingContext) Collection(java.util.Collection) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ProcessingContext

use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.

the class StringPattern method matchesBrics.

@NotNull
public StringPattern matchesBrics(@NonNls @NotNull final String s) {
    final String escaped = StringUtil.escapeToRegexp(s);
    if (escaped.equals(s)) {
        return equalTo(s);
    }
    StringBuilder sb = new StringBuilder(s.length() * 5);
    for (int i = 0; i < s.length(); i++) {
        final char c = s.charAt(i);
        if (c == ' ') {
            sb.append("<whitespacechar>");
        } else //This is really stupid and inconvenient builder - it breaks any normal pattern with uppercase
        if (Character.isUpperCase(c)) {
            sb.append('[').append(Character.toUpperCase(c)).append(Character.toLowerCase(c)).append(']');
        } else {
            sb.append(c);
        }
    }
    final RegExp regExp = new RegExp(sb.toString());
    final Automaton automaton = regExp.toAutomaton(new DatatypesAutomatonProvider());
    final RunAutomaton runAutomaton = new RunAutomaton(automaton, true);
    return with(new ValuePatternCondition<String>("matchesBrics") {

        @Override
        public boolean accepts(@NotNull String str, final ProcessingContext context) {
            return runAutomaton.run(str);
        }

        @Override
        public Collection<String> getValues() {
            return Collections.singleton(s);
        }
    });
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) RunAutomaton(dk.brics.automaton.RunAutomaton) Automaton(dk.brics.automaton.Automaton) RegExp(dk.brics.automaton.RegExp) DatatypesAutomatonProvider(dk.brics.automaton.DatatypesAutomatonProvider) Collection(java.util.Collection) RunAutomaton(dk.brics.automaton.RunAutomaton) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with ProcessingContext

use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.

the class InlineToAnonymousConstructorProcessor method addSuperConstructorArguments.

private void addSuperConstructorArguments(PsiExpressionList argumentList) throws IncorrectOperationException {
    final PsiCodeBlock body = myConstructor.getBody();
    assert body != null;
    PsiStatement[] statements = body.getStatements();
    if (statements.length == 0) {
        return;
    }
    ProcessingContext context = new ProcessingContext();
    if (!ourSuperCallPattern.accepts(statements[0], context)) {
        return;
    }
    PsiExpressionList superArguments = context.get(ourCallKey).getArgumentList();
    if (superArguments != null) {
        for (PsiExpression argument : superArguments.getExpressions()) {
            final PsiElement superArgument = replaceParameterReferences(argument.copy(), new ArrayList<>(), true);
            argumentList.add(superArgument);
        }
    }
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext)

Example 15 with ProcessingContext

use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.

the class NamedObjectProviderBinding method addMatchingProviders.

static void addMatchingProviders(@NotNull PsiElement position, @Nullable final List<ProviderInfo<ElementPattern>> providerList, @NotNull Collection<ProviderInfo<ProcessingContext>> output, @NotNull PsiReferenceService.Hints hints) {
    if (providerList == null)
        return;
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < providerList.size(); i++) {
        ProviderInfo<ElementPattern> info = providerList.get(i);
        if (hints != PsiReferenceService.Hints.NO_HINTS && !info.provider.acceptsHints(position, hints)) {
            continue;
        }
        final ProcessingContext context = new ProcessingContext();
        if (hints != PsiReferenceService.Hints.NO_HINTS) {
            context.put(PsiReferenceService.HINTS, hints);
        }
        boolean suitable = false;
        try {
            suitable = info.processingContext.accepts(position, context);
        } catch (IndexNotReadyException ignored) {
        }
        if (suitable) {
            output.add(new ProviderInfo<>(info.provider, context, info.priority));
        }
    }
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ElementPattern(com.intellij.patterns.ElementPattern)

Aggregations

ProcessingContext (com.intellij.util.ProcessingContext)33 NotNull (org.jetbrains.annotations.NotNull)20 XmlAttribute (com.intellij.psi.xml.XmlAttribute)4 CompletionSorterImpl (com.intellij.codeInsight.completion.impl.CompletionSorterImpl)3 Module (com.intellij.openapi.module.Module)3 Project (com.intellij.openapi.project.Project)3 Collection (java.util.Collection)3 LiveTemplateLookupElement (com.intellij.codeInsight.template.impl.LiveTemplateLookupElement)2 CssClassValueReference (com.intellij.javascript.flex.css.CssClassValueReference)2 Logger (com.intellij.openapi.diagnostic.Logger)2 ModuleUtilCore.findModuleForPsiElement (com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiElement (com.intellij.psi.PsiElement)2 PsiReference (com.intellij.psi.PsiReference)2 JavaClassReferenceProvider (com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider)2 XmlElement (com.intellij.psi.xml.XmlElement)2 XmlTag (com.intellij.psi.xml.XmlTag)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Configuration (org.intellij.plugins.intelliLang.Configuration)2