Search in sources :

Example 61 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.

the class SliceNullnessAnalyzer method calcNullableLeaves.

@NotNull
static NullAnalysisResult calcNullableLeaves(@NotNull final SliceNode root, @NotNull AbstractTreeStructure treeStructure, @NotNull final Map<SliceNode, NullAnalysisResult> map) {
    final SliceLeafAnalyzer.SliceNodeGuide guide = new SliceLeafAnalyzer.SliceNodeGuide(treeStructure);
    WalkingState<SliceNode> walkingState = new WalkingState<SliceNode>(guide) {

        @Override
        public void visit(@NotNull final SliceNode element) {
            element.calculateDupNode();
            node(element, map).clear();
            SliceNode duplicate = element.getDuplicate();
            if (duplicate != null) {
                node(element, map).add(node(duplicate, map));
            } else {
                final PsiElement value = ApplicationManager.getApplication().runReadAction(new Computable<PsiElement>() {

                    @Override
                    public PsiElement compute() {
                        return element.getValue().getElement();
                    }
                });
                Nullness nullness = ApplicationManager.getApplication().runReadAction(new Computable<Nullness>() {

                    @Override
                    public Nullness compute() {
                        return checkNullness(value);
                    }
                });
                if (nullness == Nullness.NULLABLE) {
                    group(element, map, NullAnalysisResult.NULLS).add(value);
                } else if (nullness == Nullness.NOT_NULL) {
                    group(element, map, NullAnalysisResult.NOT_NULLS).add(value);
                } else {
                    Collection<? extends AbstractTreeNode> children = ApplicationManager.getApplication().runReadAction(new Computable<Collection<? extends AbstractTreeNode>>() {

                        @Override
                        public Collection<? extends AbstractTreeNode> compute() {
                            return element.getChildren();
                        }
                    });
                    if (children.isEmpty()) {
                        group(element, map, NullAnalysisResult.UNKNOWNS).add(value);
                    }
                    super.visit(element);
                }
            }
        }

        @Override
        public void elementFinished(@NotNull SliceNode element) {
            SliceNode parent = guide.getParent(element);
            if (parent != null) {
                node(parent, map).add(node(element, map));
            }
        }
    };
    walkingState.visit(root);
    return node(root, map);
}
Also used : WalkingState(com.intellij.util.WalkingState) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) NotNull(org.jetbrains.annotations.NotNull) Nullness(com.intellij.codeInspection.dataFlow.Nullness) Computable(com.intellij.openapi.util.Computable) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode 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 63 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project android by JetBrains.

the class ResourceTypeInspection method processValuesFlownTo.

@NotNull
private static InspectionResult processValuesFlownTo(@NotNull final PsiExpression argument, @NotNull PsiElement scope, @NotNull PsiManager manager, @NotNull final Function<PsiExpression, InspectionResult> processor) {
    SliceAnalysisParams params = new SliceAnalysisParams();
    params.dataFlowToThis = true;
    params.scope = new AnalysisScope(new LocalSearchScope(scope), manager.getProject());
    SliceLanguageSupportProvider languageSlicing = LanguageSlicing.getProvider(argument);
    assert languageSlicing != null;
    SliceRootNode rootNode = new SliceRootNode(manager.getProject(), new DuplicateMap(), languageSlicing.createRootUsage(argument, params));
    @SuppressWarnings("unchecked") Collection<? extends AbstractTreeNode> children = rootNode.getChildren().iterator().next().getChildren();
    for (AbstractTreeNode child : children) {
        SliceUsage usage = (SliceUsage) child.getValue();
        if (usage == null) {
            continue;
        }
        PsiElement element = usage.getElement();
        if (element instanceof PsiExpression) {
            // If we report an error, use the current expression being evaluated. This will mark the error in the argument as opposed to using
            // the original field or variable declaration.
            InspectionResult result = processor.fun((PsiExpression) element).useErrorNode(argument);
            if (result.isInvalid()) {
                return result;
            }
        }
    }
    return !children.isEmpty() ? InspectionResult.valid() : InspectionResult.uncertain();
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) AnalysisScope(com.intellij.analysis.AnalysisScope) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project android by JetBrains.

the class AndroidModuleNode method getChildren.

@NotNull
public static Collection<AbstractTreeNode> getChildren(@NotNull AndroidFacet facet, @NotNull ViewSettings settings, @NotNull AndroidProjectViewPane pane, @NotNull List<IdeaSourceProvider> providers) {
    Project project = facet.getModule().getProject();
    List<AbstractTreeNode> result = Lists.newArrayList();
    AndroidModuleModel androidModuleModel = AndroidModuleModel.get(facet);
    HashMultimap<AndroidSourceType, VirtualFile> sourcesByType = getSourcesBySourceType(providers, androidModuleModel);
    NdkModuleModel ndkModuleModel = NdkModuleModel.get(facet.getModule());
    for (AndroidSourceType sourceType : sourcesByType.keySet()) {
        if (sourceType == AndroidSourceType.CPP && ndkModuleModel != null) {
            // Native sources will be added separately from NativeAndroidGradleModel.
            continue;
        }
        if (sourceType == AndroidSourceType.MANIFEST) {
            result.add(new AndroidManifestsGroupNode(project, facet, settings, sourcesByType.get(sourceType)));
            continue;
        }
        if (sourceType == AndroidSourceType.RES) {
            result.add(new AndroidResFolderNode(project, facet, settings, sourcesByType.get(sourceType), pane));
            continue;
        }
        if (sourceType == AndroidSourceType.SHADERS) {
            if (androidModuleModel == null || !androidModuleModel.getFeatures().isShadersSupported()) {
                continue;
            }
        }
        result.add(new AndroidSourceTypeNode(project, facet, settings, sourceType, sourcesByType.get(sourceType), pane));
    }
    if (ndkModuleModel != null) {
        result.add(new AndroidJniFolderNode(project, ndkModuleModel, settings));
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) AndroidSourceType(org.jetbrains.android.facet.AndroidSourceType) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with AbstractTreeNode

use of com.intellij.ide.util.treeView.AbstractTreeNode in project android by JetBrains.

the class AndroidResFolderNode method getChildren.

/**
   * Returns the children of the res folder. Rather than showing the existing directory hierarchy, this merges together
   * all the folders by their {@link com.android.resources.ResourceFolderType}.
   */
@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
    // collect all res folders from all source providers
    List<PsiDirectory> resFolders = Lists.newArrayList();
    for (PsiDirectory directory : getSourceDirectories()) {
        resFolders.addAll(Lists.newArrayList(directory.getSubdirectories()));
    }
    // group all the res folders by their folder type
    HashMultimap<ResourceFolderType, PsiDirectory> foldersByResourceType = HashMultimap.create();
    for (PsiDirectory resFolder : resFolders) {
        ResourceFolderType type = ResourceFolderType.getFolderType(resFolder.getName());
        if (type == null) {
            // skip unknown folder types inside res
            continue;
        }
        foldersByResourceType.put(type, resFolder);
    }
    // create a node for each res folder type that actually has some resources
    AndroidProjectTreeBuilder treeBuilder = (AndroidProjectTreeBuilder) myProjectViewPane.getTreeBuilder();
    List<AbstractTreeNode> children = Lists.newArrayListWithExpectedSize(foldersByResourceType.size());
    for (ResourceFolderType type : foldersByResourceType.keySet()) {
        Set<PsiDirectory> folders = foldersByResourceType.get(type);
        final AndroidResFolderTypeNode androidResFolderTypeNode = new AndroidResFolderTypeNode(myProject, getValue(), Lists.newArrayList(folders), getSettings(), type, myProjectViewPane);
        children.add(androidResFolderTypeNode);
        // Inform the tree builder of the node that this particular virtual file maps to
        for (PsiDirectory folder : folders) {
            treeBuilder.createMapping(folder.getVirtualFile(), androidResFolderTypeNode);
        }
    }
    return children;
}
Also used : ResourceFolderType(com.android.resources.ResourceFolderType) PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) AndroidProjectTreeBuilder(com.android.tools.idea.navigator.AndroidProjectTreeBuilder) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)150 NotNull (org.jetbrains.annotations.NotNull)69 ArrayList (java.util.ArrayList)51 VirtualFile (com.intellij.openapi.vfs.VirtualFile)40 Project (com.intellij.openapi.project.Project)33 PsiFile (com.intellij.psi.PsiFile)30 Module (com.intellij.openapi.module.Module)27 PsiDirectory (com.intellij.psi.PsiDirectory)25 PsiElement (com.intellij.psi.PsiElement)16 Nullable (org.jetbrains.annotations.Nullable)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)10 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)9 PsiManager (com.intellij.psi.PsiManager)9 List (java.util.List)9 PresentationData (com.intellij.ide.projectView.PresentationData)6 ViewSettings (com.intellij.ide.projectView.ViewSettings)6 PsiFileNode (com.intellij.ide.projectView.impl.nodes.PsiFileNode)6 NamedLibraryElement (com.intellij.ide.projectView.impl.nodes.NamedLibraryElement)5 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)5