Search in sources :

Example 1 with ElementPattern

use of com.intellij.patterns.ElementPattern in project intellij-community by JetBrains.

the class MavenPropertyPsiReferenceContributor method registerReferenceProviders.

@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
    ElementPattern pattern = XmlPatterns.xmlTag().withParent(DomPatterns.tagWithDom("properties", DomPatterns.domElement(MavenDomProperties.class)));
    registrar.registerReferenceProvider(pattern, new MavenPropertyPsiReferenceProvider(), PsiReferenceRegistrar.DEFAULT_PRIORITY);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(), new MavenFilteredPropertyPsiReferenceProvider(), PsiReferenceRegistrar.DEFAULT_PRIORITY);
}
Also used : ElementPattern(com.intellij.patterns.ElementPattern)

Example 2 with ElementPattern

use of com.intellij.patterns.ElementPattern in project intellij-community by JetBrains.

the class FrameworkDetectionIndex method getIndexer.

@NotNull
@Override
public DataIndexer<Integer, Void, FileContent> getIndexer() {
    final MultiMap<FileType, Pair<ElementPattern<FileContent>, Integer>> detectors = new MultiMap<>();
    FrameworkDetectorRegistry registry = FrameworkDetectorRegistry.getInstance();
    for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
        detectors.putValue(detector.getFileType(), Pair.create(detector.createSuitableFilePattern(), registry.getDetectorId(detector)));
    }
    return new DataIndexer<Integer, Void, FileContent>() {

        @NotNull
        @Override
        public Map<Integer, Void> map(@NotNull FileContent inputData) {
            final FileType fileType = inputData.getFileType();
            if (!detectors.containsKey(fileType)) {
                return Collections.emptyMap();
            }
            Map<Integer, Void> result = null;
            for (Pair<ElementPattern<FileContent>, Integer> pair : detectors.get(fileType)) {
                if (pair.getFirst().accepts(inputData)) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(inputData.getFile() + " accepted by detector " + pair.getSecond());
                    }
                    if (result == null) {
                        result = new HashMap<>();
                    }
                    myDispatcher.getMulticaster().fileUpdated(inputData.getFile(), pair.getSecond());
                    result.put(pair.getSecond(), null);
                }
            }
            return result != null ? result : Collections.<Integer, Void>emptyMap();
        }
    };
}
Also used : FrameworkDetector(com.intellij.framework.detection.FrameworkDetector) ElementPattern(com.intellij.patterns.ElementPattern) NotNull(org.jetbrains.annotations.NotNull) MultiMap(com.intellij.util.containers.MultiMap) FileType(com.intellij.openapi.fileTypes.FileType) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ElementPattern

use of com.intellij.patterns.ElementPattern 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 4 with ElementPattern

use of com.intellij.patterns.ElementPattern in project intellij-community by JetBrains.

the class XmlLanguageInjector method getXmlAnnotatedElementsValue.

private Trinity<Long, Pattern, Collection<String>> getXmlAnnotatedElementsValue() {
    Trinity<Long, Pattern, Collection<String>> index = myXmlIndex;
    if (index == null || myConfiguration.getModificationCount() != index.first.longValue()) {
        final Map<ElementPattern<?>, BaseInjection> map = new THashMap<>();
        for (BaseInjection injection : myConfiguration.getInjections(XmlLanguageInjectionSupport.XML_SUPPORT_ID)) {
            for (InjectionPlace place : injection.getInjectionPlaces()) {
                if (!place.isEnabled() || place.getElementPattern() == null)
                    continue;
                map.put(place.getElementPattern(), injection);
            }
        }
        final Collection<String> stringSet = PatternValuesIndex.buildStringIndex(map.keySet());
        index = Trinity.create(myConfiguration.getModificationCount(), buildPattern(stringSet), stringSet);
        myXmlIndex = index;
    }
    return index;
}
Also used : ElementPattern(com.intellij.patterns.ElementPattern) Pattern(java.util.regex.Pattern) THashMap(gnu.trove.THashMap) ElementPattern(com.intellij.patterns.ElementPattern) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 5 with ElementPattern

use of com.intellij.patterns.ElementPattern in project intellij-community by JetBrains.

the class CompletionProgressIndicator method prefixUpdated.

public void prefixUpdated() {
    final int caretOffset = myEditor.getCaretModel().getOffset();
    if (caretOffset < myStartCaret) {
        scheduleRestart();
        myRestartingPrefixConditions.clear();
        return;
    }
    final CharSequence text = myEditor.getDocument().getCharsSequence();
    for (Pair<Integer, ElementPattern<String>> pair : myRestartingPrefixConditions) {
        int start = pair.first;
        if (caretOffset >= start && start >= 0) {
            final String newPrefix = text.subSequence(start, caretOffset).toString();
            if (pair.second.accepts(newPrefix)) {
                scheduleRestart();
                myRestartingPrefixConditions.clear();
                return;
            }
        }
    }
    hideAutopopupIfMeaningless();
}
Also used : ElementPattern(com.intellij.patterns.ElementPattern) LightweightHint(com.intellij.ui.LightweightHint)

Aggregations

ElementPattern (com.intellij.patterns.ElementPattern)8 XmlTagPattern (com.intellij.patterns.XmlTagPattern)2 ProcessingContext (com.intellij.util.ProcessingContext)2 NotNull (org.jetbrains.annotations.NotNull)2 FrameworkDetector (com.intellij.framework.detection.FrameworkDetector)1 FileType (com.intellij.openapi.fileTypes.FileType)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Pair (com.intellij.openapi.util.Pair)1 IElementType (com.intellij.psi.tree.IElementType)1 LightweightHint (com.intellij.ui.LightweightHint)1 MultiMap (com.intellij.util.containers.MultiMap)1 THashMap (gnu.trove.THashMap)1 Pattern (java.util.regex.Pattern)1 BaseInjection (org.intellij.plugins.intelliLang.inject.config.BaseInjection)1 InjectionPlace (org.intellij.plugins.intelliLang.inject.config.InjectionPlace)1