Search in sources :

Example 21 with JSQualifiedNamedElement

use of com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement 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)

Example 22 with JSQualifiedNamedElement

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

the class FlexCssElementDescriptorProvider method isPossibleSelector.

public boolean isPossibleSelector(@NotNull String selector, @NotNull PsiElement context) {
    if (selector.equals("global"))
        return true;
    GlobalSearchScope scope = FlexCssUtil.getResolveScope(context);
    Collection<JSQualifiedNamedElement> classes = JSResolveUtil.findElementsByName(selector, context.getProject(), scope);
    for (JSQualifiedNamedElement c : classes) {
        if (c instanceof JSClass) {
            return true;
        }
    }
    return false;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Example 23 with JSQualifiedNamedElement

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

the class FlexCssElementDescriptorProvider method getDeclarationsForSimpleSelector.

@NotNull
private static PsiElement[] getDeclarationsForSimpleSelector(@NotNull String className, @Nullable PsiElement context) {
    Collection<JSQualifiedNamedElement> elements = getClasses(className, context);
    if (elements != null && elements.size() > 0) {
        List<PsiElement> result = new ArrayList<>();
        Set<String> qNames = ContainerUtil.newLinkedHashSet();
        for (JSQualifiedNamedElement c : elements) {
            if (c instanceof JSClass) {
                // do not add classes with same qualified names
                String qName = c.getQualifiedName();
                if (qNames.add(qName)) {
                    result.add(getReferencedElement(c));
                }
            }
        }
        return toPsiElementArray(result);
    }
    return PsiElement.EMPTY_ARRAY;
}
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) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with JSQualifiedNamedElement

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

the class FlexMoveInnerClassTest method performAction.

private void performAction(VirtualFile rootDir, String fromFilePath, String className, final String targetPackage, boolean searchInStringsAndComments, boolean searchTextOccurences, String[] conflicts) {
    PsiFile sourceFile = myPsiManager.findFile(rootDir.findFileByRelativePath(fromFilePath));
    final EditorInfo editorInfo = new EditorInfo(sourceFile.getText());
    assertEquals("Wrong number of carets", 1, editorInfo.caretState.carets.size());
    assertNotNull("No caret specified", editorInfo.caretState.carets.get(0).position);
    final Document doc = PsiDocumentManager.getInstance(myProject).getDocument(sourceFile);
    final PsiDirectory targetDirectory = WriteAction.compute(() -> {
        doc.setText(editorInfo.getNewFileText());
        PsiDocumentManager.getInstance(myProject).commitDocument(doc);
        final VirtualFile srcRootFile = ModuleRootManager.getInstance(myModule).getSourceRoots()[0];
        final VirtualFile file = VfsUtilCore.findRelativeFile(targetPackage.replace('.', File.separatorChar), srcRootFile);
        if (file != null) {
            return myPsiManager.findDirectory(file);
        } else {
            PsiDirectory srcRoot = myPsiManager.findDirectory(srcRootFile);
            return DirectoryUtil.createSubdirectories(targetPackage, srcRoot, ".");
        }
    });
    PsiElement element = sourceFile.findElementAt(editorInfo.caretState.carets.get(0).getCaretOffset(doc));
    while (true) {
        assertFalse("inner element to move not found", element instanceof JSFile);
        final JSQualifiedNamedElement adjusted = FlexMoveFileRefactoringHandler.adjustForMove(element);
        if (adjusted != null) {
            element = adjusted;
            break;
        }
        element = element.getParent();
    }
    try {
        new FlexMoveInnerClassProcessor((JSQualifiedNamedElement) element, targetDirectory, className, targetPackage, searchInStringsAndComments, searchTextOccurences, null).run();
        assertEquals("Conflicts expected:\n" + StringUtil.join(conflicts, "\n"), 0, conflicts.length);
    } catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
        assertTrue("Conflicts not expected but found:" + e.getMessage(), conflicts.length > 0);
        assertSameElements(e.getMessages(), conflicts);
        myDoCompare = false;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlexMoveInnerClassProcessor(com.intellij.javascript.flex.refactoring.moveClass.FlexMoveInnerClassProcessor) BaseRefactoringProcessor(com.intellij.refactoring.BaseRefactoringProcessor) EditorInfo(com.intellij.codeInsight.EditorInfo) PsiDirectory(com.intellij.psi.PsiDirectory) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiElement(com.intellij.psi.PsiElement)

Example 25 with JSQualifiedNamedElement

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

the class FlashUmlVfsResolver method getQualifiedNameStatic.

@Nullable
public static String getQualifiedNameStatic(Object element) {
    if (element == null) {
        return null;
    }
    if (element instanceof PsiElement) {
        if (((PsiElement) element).getProject().isDisposed()) {
            return null;
        }
        if (element instanceof JSQualifiedNamedElement) {
            JSQualifiedNamedElement qualifiedNamedElement = (JSQualifiedNamedElement) element;
            String qName = qualifiedNamedElement.getQualifiedName();
            if (qName == null)
                return null;
            return combineWithModuleName(qualifiedNamedElement, fixVectorTypeName(qName));
        } else if (element instanceof JSFile) {
            return getQualifiedNameStatic(JSPsiImplUtils.findQualifiedElement((JSFile) element));
        } else if (element instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) element)) {
            //noinspection ConstantConditions
            return getQualifiedNameStatic(XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) element));
        } else if (element instanceof PsiDirectory) {
            PsiDirectory directory = (PsiDirectory) element;
            return JSResolveUtil.getExpectedPackageNameFromFile(directory.getVirtualFile(), directory.getProject());
        }
    } else if (element instanceof String) {
        return (String) element;
    }
    LOG.error("can't get qualified name of " + element);
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PsiDirectory(com.intellij.psi.PsiDirectory) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)27 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)13 PsiElement (com.intellij.psi.PsiElement)12 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiFile (com.intellij.psi.PsiFile)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)8 JSFile (com.intellij.lang.javascript.psi.JSFile)4 Project (com.intellij.openapi.project.Project)4 XmlFile (com.intellij.psi.xml.XmlFile)4 Nullable (org.jetbrains.annotations.Nullable)4 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)3 Module (com.intellij.openapi.module.Module)3 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 ArrayList (java.util.ArrayList)3 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)2 JSFunction (com.intellij.lang.javascript.psi.JSFunction)2 Attachment (com.intellij.openapi.diagnostic.Attachment)2