Search in sources :

Example 6 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 7 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 8 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)

Example 9 with ProcessingContext

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

the class StandardPatternsTest method testSave.

public void testSave() {
    Key<String> key = Key.create("abc");
    final ProcessingContext context = new ProcessingContext();
    assertFalse(string().contains("abc").save(key).accepts(null));
    assertNull(context.get(key));
    assertFalse(string().contains("abc").save(key).accepts("def"));
    assertNull(context.get(key));
    final String s = "defabcdef";
    assertTrue(string().contains("abc").save(key).accepts(s, context));
    assertSame(s, context.get(key));
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext)

Example 10 with ProcessingContext

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

the class JstdConfigFileReferenceContributor method registerReferenceProviders.

@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
    registrar.registerReferenceProvider(JstdConfigFileUtils.CONFIG_FILE_ELEMENT_PATTERN, new PsiReferenceProvider() {

        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
            final YAMLKeyValue keyValue = ObjectUtils.tryCast(element, YAMLKeyValue.class);
            if (keyValue == null) {
                return PsiReference.EMPTY_ARRAY;
            }
            final YAMLDocument yamlDocument = ObjectUtils.tryCast(keyValue.getParent(), YAMLDocument.class);
            if (yamlDocument == null) {
                return PsiReference.EMPTY_ARRAY;
            }
            final BasePathInfo basePathInfo = new BasePathInfo(yamlDocument);
            if (BasePathInfo.isBasePathKey(keyValue)) {
                PsiReference basePathRef = createBasePathRef(basePathInfo);
                if (basePathRef != null) {
                    return new PsiReference[] { basePathRef };
                }
            } else if (JstdConfigFileUtils.isTopLevelKeyWithInnerFileSequence(keyValue)) {
                VirtualFile basePath = basePathInfo.getBasePath();
                if (basePath != null) {
                    List<PsiReference> references = Lists.newArrayList();
                    addReferencesForKeyValueWithInnerFileSequence(basePathInfo, keyValue, references);
                    return references.toArray(new PsiReference[references.size()]);
                }
            }
            return PsiReference.EMPTY_ARRAY;
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessingContext(com.intellij.util.ProcessingContext) YAMLDocument(org.jetbrains.yaml.psi.YAMLDocument) YAMLKeyValue(org.jetbrains.yaml.psi.YAMLKeyValue) NotNull(org.jetbrains.annotations.NotNull)

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