Search in sources :

Example 1 with JSNamedElement

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

the class FlexGotoImplementationsTest method check.

private static void check(String expected, PsiElement[] implementations) {
    List<String> strings = new ArrayList<>(implementations.length);
    for (PsiElement element : implementations) {
        assertTrue("unexpected result item: " + element, element instanceof JSNamedElement);
        strings.add(((JSNamedElement) element).getName());
    }
    Collections.sort(strings);
    assertEquals(expected, StringUtil.join(strings, ","));
}
Also used : ArrayList(java.util.ArrayList) JSNamedElement(com.intellij.lang.javascript.psi.JSNamedElement) PsiElement(com.intellij.psi.PsiElement)

Example 2 with JSNamedElement

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

the class FlexXmlBackedMembersIndex method getItemsByName.

public static Collection<NavigationItem> getItemsByName(final String name, Project project) {
    Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NAME, name, GlobalSearchScope.projectScope(project));
    final Collection<NavigationItem> result = new ArrayList<>();
    for (VirtualFile vFile : files) {
        PsiFile file = PsiManager.getInstance(project).findFile(vFile);
        if (!(file instanceof XmlFile)) {
            continue;
        }
        process((XmlFile) file, element -> {
            if (name.equals(getName(element))) {
                if (element instanceof JSNamedElement) {
                    result.add((JSNamedElement) element);
                } else {
                    XmlAttribute id = ((XmlTag) element).getAttribute("id");
                    if (id != null) {
                        XmlAttributeValue valueElement = id.getValueElement();
                        PsiElement[] children;
                        if (valueElement != null && (children = valueElement.getChildren()).length == 3) {
                            result.add(new TagNavigationItem(children[1], name));
                        }
                    }
                }
            }
        }, true);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) NavigationItem(com.intellij.navigation.NavigationItem) PsiElementNavigationItem(com.intellij.navigation.PsiElementNavigationItem) JSNamedElement(com.intellij.lang.javascript.psi.JSNamedElement) FakePsiElement(com.intellij.psi.impl.FakePsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 3 with JSNamedElement

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

the class FlexIconProvider method getIcon.

@Override
public Icon getIcon(@NotNull PsiElement element, int flags) {
    int transformedFlags = ElementBase.transformFlags(element, flags);
    Icon icon = null;
    if (element instanceof XmlFile) {
        if (JavaScriptSupportLoader.isFlexMxmFile((PsiFile) element)) {
            final JSClass jsClass = XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) element);
            if (jsClass != null) {
                icon = jsClass.getIcon(flags);
            }
        }
    } else if (element instanceof JSFileImpl) {
        final JSNamedElement mainDeclaredElement = ActionScriptResolveUtil.findMainDeclaredElement((JSFileImpl) element);
        if (mainDeclaredElement != null) {
            icon = mainDeclaredElement.getIcon(transformedFlags);
        }
    }
    if (icon != null) {
        final PsiFile psiFile = element.getContainingFile();
        final VirtualFile vFile = psiFile == null ? null : psiFile.getVirtualFile();
        CompilerManager compilerManager = CompilerManager.getInstance(element.getProject());
        if (vFile != null && compilerManager != null && compilerManager.isExcludedFromCompilation(vFile)) {
            icon = new LayeredIcon(icon, PlatformIcons.EXCLUDED_FROM_COMPILE_ICON);
        }
    }
    return icon;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LayeredIcon(com.intellij.ui.LayeredIcon) XmlFile(com.intellij.psi.xml.XmlFile) CompilerManager(com.intellij.openapi.compiler.CompilerManager) JSNamedElement(com.intellij.lang.javascript.psi.JSNamedElement) PsiFile(com.intellij.psi.PsiFile) LayeredIcon(com.intellij.ui.LayeredIcon) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) JSFileImpl(com.intellij.lang.javascript.psi.impl.JSFileImpl)

Example 4 with JSNamedElement

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

the class ActionScriptImportHandler method resolveTypeNameInTheSamePackage.

private static JSNamedElement resolveTypeNameInTheSamePackage(@NotNull final String str, final PsiElement context) {
    JSNamedElement fileLocalElement = JSResolveUtil.findFileLocalElement(str, context);
    if (fileLocalElement != null)
        return fileLocalElement;
    final String packageQualifierText = JSResolveUtil.findPackageStatementQualifier(context);
    PsiElement byQName;
    if (packageQualifierText != null) {
        byQName = JSClassResolver.findClassFromNamespace(packageQualifierText + "." + str, context);
        if (byQName instanceof JSQualifiedNamedElement) {
            return (JSQualifiedNamedElement) byQName;
        }
    }
    byQName = JSDialectSpecificHandlersFactory.forElement(context).getClassResolver().findClassByQName(str, context);
    if (byQName instanceof JSQualifiedNamedElement && JSResolveUtil.acceptableSymbol((JSQualifiedNamedElement) byQName, JSResolveUtil.GlobalSymbolsAcceptanceState.WHATEVER, false, context)) {
        return (JSQualifiedNamedElement) byQName;
    }
    return null;
}
Also used : JSNamedElement(com.intellij.lang.javascript.psi.JSNamedElement) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

JSNamedElement (com.intellij.lang.javascript.psi.JSNamedElement)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiElement (com.intellij.psi.PsiElement)2 XmlFile (com.intellij.psi.xml.XmlFile)2 ArrayList (java.util.ArrayList)2 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)1 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)1 JSFileImpl (com.intellij.lang.javascript.psi.impl.JSFileImpl)1 NavigationItem (com.intellij.navigation.NavigationItem)1 PsiElementNavigationItem (com.intellij.navigation.PsiElementNavigationItem)1 CompilerManager (com.intellij.openapi.compiler.CompilerManager)1 PsiFile (com.intellij.psi.PsiFile)1 FakePsiElement (com.intellij.psi.impl.FakePsiElement)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 XmlTag (com.intellij.psi.xml.XmlTag)1 LayeredIcon (com.intellij.ui.LayeredIcon)1