Search in sources :

Example 16 with FileBasedIndex

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

the class LibraryStyleInfoCollector method collectInherited.

private byte[] collectInherited(final VirtualFile jarFile) {
    bytes.allocateShort();
    final VirtualFile libraryFile = Library.getSwfFile(jarFile);
    final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
    final GlobalSearchScope searchScope = GlobalSearchScope.fileScope(module.getProject(), libraryFile);
    final List<String> dataKeys = new ArrayList<>(32);
    fileBasedIndex.processAllKeys(FlexStyleIndex.INDEX_ID, dataKey -> {
        dataKeys.add(dataKey);
        return true;
    }, module.getProject());
    final THashSet<String> uniqueGuard = new THashSet<>();
    final FileBasedIndex.ValueProcessor<Set<FlexStyleIndexInfo>> processor = (file, value) -> {
        final FlexStyleIndexInfo firstInfo = value.iterator().next();
        if (firstInfo.getInherit().charAt(0) == 'y' && uniqueGuard.add(firstInfo.getAttributeName())) {
            bytes.writeUInt29(stringWriter.getReference(firstInfo.getAttributeName()) - 1);
        }
        // may not be in a class stylePName be inherited, and another class of the same library not inherited
        return false;
    };
    for (String dataKey : dataKeys) {
        fileBasedIndex.processValues(FlexStyleIndex.INDEX_ID, dataKey, libraryFile, processor, searchScope);
    }
    if (uniqueGuard.isEmpty()) {
        return null;
    } else {
        bytes.putShort(uniqueGuard.size(), 0);
        return bytes.getByteArrayOut().toByteArray();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ByteArrayOutputStreamEx(com.intellij.flex.uiDesigner.io.ByteArrayOutputStreamEx) StringWriter(com.intellij.flex.uiDesigner.io.StringRegistry.StringWriter) FlexStyleIndex(com.intellij.javascript.flex.css.FlexStyleIndex) AssetCounter(com.intellij.flex.uiDesigner.AssetCounter) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PrimitiveAmfOutputStream(com.intellij.flex.uiDesigner.io.PrimitiveAmfOutputStream) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) THashSet(gnu.trove.THashSet) ArrayList(java.util.ArrayList) List(java.util.List) CssWriter(com.intellij.flex.uiDesigner.css.CssWriter) ProblemsHolder(com.intellij.flex.uiDesigner.ProblemsHolder) FlexStyleIndexInfo(com.intellij.javascript.flex.css.FlexStyleIndexInfo) Module(com.intellij.openapi.module.Module) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) Set(java.util.Set) THashSet(gnu.trove.THashSet) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) FlexStyleIndexInfo(com.intellij.javascript.flex.css.FlexStyleIndexInfo) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) THashSet(gnu.trove.THashSet)

Example 17 with FileBasedIndex

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

the class FlexCssElementDescriptorProvider method getPropertyDescriptorsDynamically.

@NotNull
private static Collection<? extends CssPropertyDescriptor> getPropertyDescriptorsDynamically(@NotNull List<CssSimpleSelector> selectors, @NotNull Module module) {
    FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
    GlobalSearchScope scope = module.getModuleWithDependenciesAndLibrariesScope(false);
    Set<JSClass> visited = ContainerUtil.newLinkedHashSet();
    Set<CssPropertyDescriptor> result = ContainerUtil.newLinkedHashSet();
    Project project = module.getProject();
    for (CssSimpleSelector selector : selectors) {
        final JSClass jsClass = getClassFromMxmlDescriptor(selector, module);
        if (jsClass != null) {
            fillPropertyDescriptorsDynamically(jsClass, visited, result);
            continue;
        }
        final String shortClassName = selector.getElementName();
        Collection<JSQualifiedNamedElement> candidates = JSResolveUtil.findElementsByName(shortClassName, project, scope);
        for (JSQualifiedNamedElement candidate : candidates) {
            if (candidate instanceof JSClass) {
                fillPropertyDescriptorsDynamically((JSClass) candidate, visited, result);
            }
        }
    }
    for (Iterator<CssPropertyDescriptor> iterator = result.iterator(); iterator.hasNext(); ) {
        CssPropertyDescriptor propertyDescriptor = iterator.next();
        List<Set<FlexStyleIndexInfo>> values = fileBasedIndex.getValues(FlexStyleIndex.INDEX_ID, propertyDescriptor.getPropertyName(), scope);
        if (values.size() == 0) {
            iterator.remove();
        }
    }
    return result;
}
Also used : JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with FileBasedIndex

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

the class FlexCssElementDescriptorProvider method getAllPropertyDescriptors.

@NotNull
public Collection<? extends CssPropertyDescriptor> getAllPropertyDescriptors(@Nullable PsiElement context) {
    if (context == null || DumbService.getInstance(context.getProject()).isDumb()) {
        return Collections.emptyList();
    }
    Module module = findModuleForPsiElement(context);
    List<CssSimpleSelector> simpleSelectors = findSimpleSelectorsAbove(context);
    if (simpleSelectors.size() > 0 && !containsGlobalSelectors(simpleSelectors)) {
        if (module != null) {
            return getPropertyDescriptorsDynamically(simpleSelectors, module);
        }
    }
    FileBasedIndex index = FileBasedIndex.getInstance();
    Collection<String> keys = ContainerUtil.sorted(index.getAllKeys(FlexStyleIndex.INDEX_ID, context.getProject()));
    List<FlexCssPropertyDescriptor> result = new ArrayList<>();
    GlobalSearchScope scope = FlexCssUtil.getResolveScope(context);
    for (String key : keys) {
        if (!isInClassicForm(key)) {
            for (Set<FlexStyleIndexInfo> infos : index.getValues(FlexStyleIndex.INDEX_ID, key, scope)) {
                result.add(new FlexCssPropertyDescriptor(infos));
            }
        }
    }
    return result;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)9 NotNull (org.jetbrains.annotations.NotNull)7 PsiFile (com.intellij.psi.PsiFile)4 Project (com.intellij.openapi.project.Project)3 Nullable (org.jetbrains.annotations.Nullable)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 DetectedFrameworkDescription (com.intellij.framework.detection.DetectedFrameworkDescription)2 DetectionExcludesConfiguration (com.intellij.framework.detection.DetectionExcludesConfiguration)2 JSOffsetBasedImplicitElement (com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement)2 JSImplicitElementImpl (com.intellij.lang.javascript.psi.stubs.impl.JSImplicitElementImpl)2 Module (com.intellij.openapi.module.Module)2 PsiElement (com.intellij.psi.PsiElement)2 XmlFile (com.intellij.psi.xml.XmlFile)2 HashMap (com.intellij.util.containers.HashMap)2 HashSet (com.intellij.util.containers.HashSet)2 THashSet (gnu.trove.THashSet)2 InsertHandler (com.intellij.codeInsight.completion.InsertHandler)1 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)1