Search in sources :

Example 11 with JSQualifiedNamedElement

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

the class FlexTreeStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    List<AbstractTreeNode> result = new ArrayList<>();
    if (parent instanceof SwfQualifiedNamedElementNode || parent instanceof FlexFileNode) {
        if (((ProjectViewNode) parent).getSettings().isShowMembers()) {
            JSQualifiedNamedElement parentElement = getElement(parent);
            if (parentElement != null) {
                JSStructureViewElement structureViewElement = parentElement instanceof XmlBackedJSClassImpl ? new FlexStructureViewElement(((XmlBackedJSClassImpl) parentElement), (XmlFile) parentElement.getContainingFile(), false) : new JSStructureViewElement(parentElement, false, true);
                StructureViewTreeElement[] structureViewChildren = structureViewElement.getChildren();
                for (final StructureViewTreeElement structureViewChild : structureViewChildren) {
                    if (structureViewChild instanceof JSStructureViewElement) {
                        PsiElement childElement = ((JSStructureViewElement) structureViewChild).getValue();
                        result.add(new FlexClassMemberNode((JSElement) childElement, ((ProjectViewNode) parent).getSettings()));
                    } else {
                        result.add(new UnknownNode(parentElement.getProject(), structureViewChild, ((ProjectViewNode) parent).getSettings()));
                    }
                }
            }
        }
    } else {
        for (final AbstractTreeNode child : children) {
            Object o = child.getValue();
            if (o instanceof JSFileImpl && !(o instanceof PsiCompiledFile) && DialectDetector.isActionScript((PsiFile) o) || o instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) o)) {
                result.add(new FlexFileNode((PsiFile) o, ((ProjectViewNode) parent).getSettings()));
                continue;
            }
            result.add(child);
        }
    }
    return result;
}
Also used : XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSStructureViewElement(com.intellij.lang.javascript.structureView.JSStructureViewElement) FlexStructureViewElement(com.intellij.lang.javascript.flex.presentation.FlexStructureViewProvider.FlexStructureViewElement) JSFileImpl(com.intellij.lang.javascript.psi.impl.JSFileImpl) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) PsiCompiledFile(com.intellij.psi.PsiCompiledFile) JSElement(com.intellij.lang.javascript.psi.JSElement) StructureViewTreeElement(com.intellij.ide.structureView.StructureViewTreeElement) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with JSQualifiedNamedElement

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

the class SwfProjectViewStructureProvider method findDecompiledElement.

@Nullable
private static PsiElement findDecompiledElement(JSQualifiedNamedElement element) {
    if (DumbService.isDumb(element.getProject())) {
        return null;
    }
    JSQualifiedNamedElement mainElement = JSUtils.getMemberContainingClass(element);
    if (mainElement == null) {
        mainElement = element;
    }
    final String qName = mainElement.getQualifiedName();
    if (qName == null) {
        return null;
    }
    VirtualFile elementVFile = mainElement.getContainingFile().getVirtualFile();
    if (elementVFile == null) {
        return null;
    }
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(mainElement.getProject()).getFileIndex();
    GlobalSearchScope searchScope = JSResolveUtil.getResolveScope(mainElement);
    Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, qName.hashCode(), mainElement.getProject(), searchScope, JSQualifiedNamedElement.class);
    List<OrderEntry> sourceFileEntries = projectFileIndex.getOrderEntriesForFile(elementVFile);
    for (JSQualifiedNamedElement candidate : candidates) {
        if (candidate == mainElement || !qName.equals(candidate.getQualifiedName())) {
            continue;
        }
        VirtualFile vFile = candidate.getContainingFile().getVirtualFile();
        if (vFile != null && projectFileIndex.getClassRootForFile(vFile) != null) {
            List<OrderEntry> candidateEntries = projectFileIndex.getOrderEntriesForFile(vFile);
            if (ContainerUtil.intersects(sourceFileEntries, candidateEntries)) {
                if (element == mainElement) {
                    return candidate;
                } else {
                    LOG.assertTrue(candidate instanceof JSClass, candidate);
                    if (element instanceof JSVariable) {
                        return ((JSClass) candidate).findFieldByName(element.getName());
                    } else {
                        LOG.assertTrue(element instanceof JSFunction, element);
                        return ((JSClass) candidate).findFunctionByNameAndKind(element.getName(), ((JSFunction) element).getKind());
                    }
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderEntry(com.intellij.openapi.roots.OrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with JSQualifiedNamedElement

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

the class SwfQualifiedNamedElementNode method update.

@Override
protected void update(PresentationData presentation) {
    final JSQualifiedNamedElement value = getValue();
    if (value != null && value.isValid()) {
        presentation.setPresentableText(value.getName());
        presentation.setIcon(value.getIcon(Iconable.ICON_FLAG_VISIBILITY));
    }
}
Also used : JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)

Example 14 with JSQualifiedNamedElement

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

the class ActionScriptClassResolver method doFindClassByQName.

protected PsiElement doFindClassByQName(@NotNull String link, final JavaScriptIndex index, GlobalSearchScope searchScope, boolean allowFileLocalSymbols, @NotNull DialectOptionHolder dialect) {
    Project project = index.getProject();
    boolean clazzShouldBeTakenFromOurLibrary = OBJECT_CLASS_NAME.equals(link) || "Arguments".equals(link);
    if (clazzShouldBeTakenFromOurLibrary && !(searchScope instanceof AdditionalIndexedRootsScope)) {
        // object from swf do not contain necessary members!
        searchScope = new AdditionalIndexedRootsScope(searchScope, JSIndexedRootProvider.class);
    }
    final Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, link.hashCode(), project, searchScope, JSQualifiedNamedElement.class);
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    JSQualifiedNamedElement resultFromSourceContent = null;
    JSQualifiedNamedElement resultFromLibraries = null;
    long resultFromLibrariesTimestamp = 0;
    for (JSQualifiedNamedElement classCandidate : candidates) {
        if (!(classCandidate instanceof JSQualifiedNamedElement))
            continue;
        if (JSResolveUtil.isConstructorFunction(classCandidate))
            continue;
        JSQualifiedNamedElement clazz = classCandidate;
        if (link.equals(clazz.getQualifiedName())) {
            PsiFile file = clazz.getContainingFile();
            if (!file.getLanguage().isKindOf(JavaScriptSupportLoader.ECMA_SCRIPT_L4))
                continue;
            VirtualFile vFile = file.getVirtualFile();
            if (clazzShouldBeTakenFromOurLibrary && // object from swf do not contain necessary members!
            !JavaScriptIndex.ECMASCRIPT_JS2.equals(vFile.getName())) {
                continue;
            }
            if (!allowFileLocalSymbols && JSResolveUtil.isFileLocalSymbol(clazz)) {
                continue;
            }
            if (projectFileIndex.isInSourceContent(vFile)) {
                // the absolute preference is for classes from sources
                resultFromSourceContent = clazz;
                continue;
            }
            // choose the right class in the same way as compiler does: with the latest timestamp in catalog.xml file
            if (resultFromLibraries == null) {
                resultFromLibraries = clazz;
            // do not initialize resultFromLibrariesTimestamp here, it is expensive and may be not required if only 1 candidate
            } else if (JSCommonTypeNames.VECTOR_CLASS_NAME.equals(link)) {
                if (clazz instanceof JSClass && resultFromLibraries instanceof JSClass && ((JSClass) clazz).getFunctions().length > ((JSClass) resultFromLibraries).getFunctions().length) {
                    resultFromLibraries = clazz;
                }
            } else {
                if (resultFromLibrariesTimestamp == 0) {
                    // was not initialized yet
                    resultFromLibrariesTimestamp = getResolveResultTimestamp(resultFromLibraries);
                }
                final long classTimestamp = getResolveResultTimestamp(clazz);
                if (classTimestamp > resultFromLibrariesTimestamp) {
                    resultFromLibraries = clazz;
                    resultFromLibrariesTimestamp = classTimestamp;
                }
            }
        }
    }
    PsiElement result = resultFromSourceContent != null ? resultFromSourceContent : resultFromLibraries;
    if (result == null) {
        String className = link.substring(link.lastIndexOf('.') + 1);
        if (className.length() > 0 && !isBuiltInClassName(className) && (Character.isLetter(className.charAt(0)) || '_' == className.charAt(0))) {
            // TODO optimization, remove when packages will be properly handled
            result = findClassByQNameViaHelper(link, project, className, searchScope);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) JSIndexedRootProvider(com.intellij.lang.javascript.index.JSIndexedRootProvider) AdditionalIndexedRootsScope(com.intellij.util.indexing.AdditionalIndexedRootsScope) PsiFile(com.intellij.psi.PsiFile) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 15 with JSQualifiedNamedElement

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

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