Search in sources :

Example 96 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlexStyleIndex method getIndexer.

@NotNull
@Override
public DataIndexer<String, Set<FlexStyleIndexInfo>, FileContent> getIndexer() {
    return new DataIndexer<String, Set<FlexStyleIndexInfo>, FileContent>() {

        @Override
        @NotNull
        public Map<String, Set<FlexStyleIndexInfo>> map(@NotNull FileContent inputData) {
            final THashMap<String, Set<FlexStyleIndexInfo>> map = new THashMap<>();
            if (JavaScriptSupportLoader.isFlexMxmFile(inputData.getFileName())) {
                PsiFile file = inputData.getPsiFile();
                VirtualFile virtualFile = inputData.getFile();
                if (file instanceof XmlFile) {
                    indexMxmlFile((XmlFile) file, virtualFile, map);
                }
            } else {
                StubTree tree = JSPackageIndex.getStubTree(inputData);
                if (tree != null) {
                    for (StubElement e : tree.getPlainList()) {
                        if (e instanceof JSClassStub) {
                            final PsiElement psiElement = e.getPsi();
                            if (psiElement instanceof JSClass) {
                                final String qName = ((JSClass) psiElement).getQualifiedName();
                                indexAttributes(psiElement, qName, true, map);
                            }
                        } else if (e instanceof PsiFileStub) {
                            PsiElement psiElement = e.getPsi();
                            if (psiElement instanceof JSFile) {
                                String name = ((JSFile) psiElement).getName();
                                indexAttributes(psiElement, name, false, map);
                            }
                        }
                    }
                }
            }
            return map;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Set(java.util.Set) XmlFile(com.intellij.psi.xml.XmlFile) StubTree(com.intellij.psi.stubs.StubTree) StubElement(com.intellij.psi.stubs.StubElement) NotNull(org.jetbrains.annotations.NotNull) THashMap(gnu.trove.THashMap) JSClassStub(com.intellij.lang.javascript.psi.stubs.JSClassStub) PsiFileStub(com.intellij.psi.stubs.PsiFileStub) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass 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 98 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlexCssElementDescriptorProvider method getClassFromMxmlDescriptor.

@Nullable
private static JSClass getClassFromMxmlDescriptor(@NotNull CssSimpleSelector selector, @NotNull Module module) {
    final XmlElementDescriptor xmlElementDescriptor = getTypeSelectorDescriptor(selector, module);
    if (xmlElementDescriptor == null) {
        return null;
    }
    final PsiElement declaration = xmlElementDescriptor.getDeclaration();
    return declaration instanceof JSClass ? (JSClass) declaration : null;
}
Also used : XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) ModuleUtilCore.findModuleForPsiElement(com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 99 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlexCssElementDescriptorProvider method generateDocForSelector.

public String generateDocForSelector(@NotNull String selectorName, @Nullable PsiElement context) {
    PsiElement[] declarations = getDeclarationsForSimpleSelector(selectorName, context);
    JSClass[] classes = new JSClass[declarations.length];
    for (int i = 0; i < declarations.length; i++) {
        PsiElement declaration = declarations[i];
        assert declaration instanceof JSClass;
        classes[i] = (JSClass) declaration;
    }
    Arrays.sort(classes, (c1, c2) -> Comparing.compare(c1.getQualifiedName(), c2.getQualifiedName()));
    StringBuilder builder = new StringBuilder();
    for (int i = 0, n = classes.length; i < n; i++) {
        JSClass jsClass = classes[i];
        PsiFile file = jsClass.getContainingFile();
        if (file != null) {
            DocumentationProvider provider = DocumentationManager.getProviderFromElement(jsClass);
            String docForDeclaration = provider.generateDoc(jsClass, jsClass);
            if (docForDeclaration != null) {
                builder.append(docForDeclaration);
                if (i != n - 1) {
                    builder.append("<br><br>\n\n");
                }
            }
        }
    }
    return builder.toString();
}
Also used : PsiFile(com.intellij.psi.PsiFile) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) ModuleUtilCore.findModuleForPsiElement(com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Example 100 with JSClass

use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.

the class FlexCssElementDescriptorProvider method filter.

private static List<FlexStyleIndexInfo> filter(Collection<? extends Collection<FlexStyleIndexInfo>> collections, List<CssSimpleSelector> selectors, @NotNull GlobalSearchScope scope, @Nullable Module module) {
    Set<String> allNames = ContainerUtil.newLinkedHashSet();
    for (Collection<FlexStyleIndexInfo> collection : collections) {
        for (FlexStyleIndexInfo info : collection) {
            allNames.add(info.getClassOrFileName());
        }
    }
    Set<String> namesFromSelectors = null;
    if (selectors.size() > 0 && !containsGlobalSelectors(selectors)) {
        namesFromSelectors = ContainerUtil.newLinkedHashSet();
        for (CssSimpleSelector selector : selectors) {
            if (module != null) {
                final JSClass jsClass = getClassFromMxmlDescriptor(selector, module);
                if (jsClass != null) {
                    String classOrFileName = findJsClassOrFile(jsClass, ContainerUtil.newLinkedHashSet(), allNames);
                    if (classOrFileName != null) {
                        namesFromSelectors.add(classOrFileName);
                    }
                    continue;
                }
            }
            final String selectorName = selector.getElementName();
            Collection<JSQualifiedNamedElement> elements = JSResolveUtil.findElementsByName(selectorName, scope.getProject(), scope);
            for (PsiElement element : elements) {
                if (element instanceof JSClass) {
                    String classOrFileName = findJsClassOrFile((JSClass) element, ContainerUtil.newLinkedHashSet(), allNames);
                    if (classOrFileName != null) {
                        namesFromSelectors.add(classOrFileName);
                    }
                }
            }
        }
    }
    List<FlexStyleIndexInfo> result = new ArrayList<>();
    for (Collection<FlexStyleIndexInfo> collection : collections) {
        for (FlexStyleIndexInfo info : collection) {
            if (namesFromSelectors == null || namesFromSelectors.contains(info.getClassOrFileName())) {
                result.add(info);
            }
        }
    }
    return result;
}
Also used : JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) ModuleUtilCore.findModuleForPsiElement(com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement)

Aggregations

JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)141 PsiElement (com.intellij.psi.PsiElement)65 Nullable (org.jetbrains.annotations.Nullable)27 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)23 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)22 JSFunction (com.intellij.lang.javascript.psi.JSFunction)18 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)18 Module (com.intellij.openapi.module.Module)17 XmlFile (com.intellij.psi.xml.XmlFile)17 Project (com.intellij.openapi.project.Project)16 PsiFile (com.intellij.psi.PsiFile)16 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)15 ArrayList (java.util.ArrayList)14 PsiDirectory (com.intellij.psi.PsiDirectory)11 XmlTag (com.intellij.psi.xml.XmlTag)11 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)8 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)8 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)7