Search in sources :

Example 96 with SmartList

use of com.intellij.util.SmartList in project intellij-community by JetBrains.

the class ExternalAnnotationsManagerImpl method setupRootAndAnnotateExternally.

private boolean setupRootAndAnnotateExternally(@NotNull final OrderEntry entry, @NotNull final Project project, @NotNull final PsiModifierListOwner listOwner, @NotNull final String annotationFQName, @NotNull final PsiFile fromFile, @NotNull final String packageName, @Nullable final PsiNameValuePair[] value) {
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    descriptor.setTitle(ProjectBundle.message("external.annotations.root.chooser.title", entry.getPresentableName()));
    descriptor.setDescription(ProjectBundle.message("external.annotations.root.chooser.description"));
    final VirtualFile newRoot = FileChooser.chooseFile(descriptor, project, null);
    if (newRoot == null) {
        notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
        return false;
    }
    new WriteCommandAction(project) {

        @Override
        protected void run(@NotNull final Result result) throws Throwable {
            appendChosenAnnotationsRoot(entry, newRoot);
            XmlFile xmlFileInRoot = findXmlFileInRoot(findExternalAnnotationsXmlFiles(listOwner), newRoot);
            if (xmlFileInRoot != null) {
                //file already exists under appeared content root
                if (!FileModificationService.getInstance().preparePsiElementForWrite(xmlFileInRoot)) {
                    notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
                    return;
                }
                annotateExternally(listOwner, annotationFQName, xmlFileInRoot, fromFile, value);
            } else {
                final XmlFile annotationsXml = createAnnotationsXml(newRoot, packageName);
                if (annotationsXml != null) {
                    List<PsiFile> createdFiles = new SmartList<>(annotationsXml);
                    cacheExternalAnnotations(packageName, fromFile, createdFiles);
                }
                annotateExternally(listOwner, annotationFQName, annotationsXml, fromFile, value);
            }
        }
    }.execute();
    return true;
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) SmartList(com.intellij.util.SmartList) List(java.util.List) ArrayList(java.util.ArrayList) Result(com.intellij.openapi.application.Result)

Example 97 with SmartList

use of com.intellij.util.SmartList in project intellij-community by JetBrains.

the class StubTreeBuilder method getStubbedRoots.

/** Order is deterministic. First element matches {@link FileViewProvider#getStubBindingRoot()} */
@NotNull
public static List<Pair<IStubFileElementType, PsiFile>> getStubbedRoots(@NotNull FileViewProvider viewProvider) {
    final List<Trinity<Language, IStubFileElementType, PsiFile>> roots = new SmartList<>();
    final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
    for (Language language : viewProvider.getLanguages()) {
        final PsiFile file = viewProvider.getPsi(language);
        if (file instanceof PsiFileImpl) {
            final IElementType type = ((PsiFileImpl) file).getElementTypeForStubBuilder();
            if (type != null) {
                roots.add(Trinity.create(language, (IStubFileElementType) type, file));
            }
        }
    }
    ContainerUtil.sort(roots, (o1, o2) -> {
        if (o1.third == stubBindingRoot)
            return o2.third == stubBindingRoot ? 0 : -1;
        else if (o2.third == stubBindingRoot)
            return 1;
        else
            return StringUtil.compare(o1.first.getID(), o2.first.getID(), false);
    });
    return ContainerUtil.map(roots, trinity -> Pair.create(trinity.second, trinity.third));
}
Also used : IElementType(com.intellij.psi.tree.IElementType) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) Trinity(com.intellij.openapi.util.Trinity) Language(com.intellij.lang.Language) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) PsiFile(com.intellij.psi.PsiFile) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 98 with SmartList

use of com.intellij.util.SmartList in project intellij-community by JetBrains.

the class LightTreeUtil method getChildrenOfType.

@NotNull
public static List<LighterASTNode> getChildrenOfType(@NotNull LighterAST tree, @NotNull LighterASTNode node, @NotNull TokenSet types) {
    List<LighterASTNode> children = tree.getChildren(node);
    List<LighterASTNode> result = null;
    for (int i = 0, size = children.size(); i < size; ++i) {
        LighterASTNode child = children.get(i);
        if (types.contains(child.getTokenType())) {
            if (result == null)
                result = new SmartList<>();
            result.add(child);
        }
    }
    return result != null ? result : Collections.<LighterASTNode>emptyList();
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 99 with SmartList

use of com.intellij.util.SmartList in project intellij-community by JetBrains.

the class InspectionTree method getSelectedDescriptors.

@NotNull
public CommonProblemDescriptor[] getSelectedDescriptors(boolean sortedByPosition, @Nullable Set<VirtualFile> readOnlyFilesSink, boolean allowResolved, boolean allowSuppressed) {
    final TreePath[] paths = getSelectionPaths();
    if (paths == null)
        return CommonProblemDescriptor.EMPTY_ARRAY;
    final TreePath[] selectionPaths = TreeUtil.selectMaximals(paths);
    final List<CommonProblemDescriptor> descriptors = new ArrayList<>();
    MultiMap<Object, ProblemDescriptionNode> parentToChildNode = new MultiMap<>();
    final List<InspectionTreeNode> nonDescriptorNodes = new SmartList<>();
    for (TreePath path : selectionPaths) {
        final Object[] pathAsArray = path.getPath();
        final int length = pathAsArray.length;
        final Object node = pathAsArray[length - 1];
        if (node instanceof ProblemDescriptionNode) {
            if (isNodeValidAndIncluded((ProblemDescriptionNode) node, allowResolved, allowSuppressed)) {
                if (length >= 2) {
                    parentToChildNode.putValue(pathAsArray[length - 2], (ProblemDescriptionNode) node);
                } else {
                    parentToChildNode.putValue(node, (ProblemDescriptionNode) node);
                }
            }
        } else {
            nonDescriptorNodes.add((InspectionTreeNode) node);
        }
    }
    for (InspectionTreeNode node : nonDescriptorNodes) {
        processChildDescriptorsDeep(node, descriptors, sortedByPosition, allowResolved, allowSuppressed, readOnlyFilesSink);
    }
    for (Map.Entry<Object, Collection<ProblemDescriptionNode>> entry : parentToChildNode.entrySet()) {
        final Collection<ProblemDescriptionNode> siblings = entry.getValue();
        if (siblings.size() == 1) {
            final ProblemDescriptionNode descriptorNode = ContainerUtil.getFirstItem(siblings);
            LOG.assertTrue(descriptorNode != null);
            CommonProblemDescriptor descriptor = descriptorNode.getDescriptor();
            if (descriptor != null) {
                descriptors.add(descriptor);
                if (readOnlyFilesSink != null) {
                    collectReadOnlyFiles(descriptor, readOnlyFilesSink);
                }
            }
        } else {
            List<CommonProblemDescriptor> currentDescriptors = new ArrayList<>();
            for (ProblemDescriptionNode sibling : siblings) {
                final CommonProblemDescriptor descriptor = sibling.getDescriptor();
                if (descriptor != null) {
                    if (readOnlyFilesSink != null) {
                        collectReadOnlyFiles(descriptor, readOnlyFilesSink);
                    }
                    currentDescriptors.add(descriptor);
                }
            }
            if (sortedByPosition) {
                Collections.sort(currentDescriptors, DESCRIPTOR_COMPARATOR);
            }
            descriptors.addAll(currentDescriptors);
        }
    }
    return descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]);
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) TreePath(javax.swing.tree.TreePath) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) SmartList(com.intellij.util.SmartList) MultiMap(com.intellij.util.containers.MultiMap) NotNull(org.jetbrains.annotations.NotNull)

Example 100 with SmartList

use of com.intellij.util.SmartList in project intellij-community by JetBrains.

the class NullParameterConstraintChecker method checkMethodParameters.

@NotNull
static PsiParameter[] checkMethodParameters(PsiMethod method) {
    if (method.getBody() == null)
        return PsiParameter.EMPTY_ARRAY;
    final Collection<PsiParameter> nullableParameters = new SmartList<>();
    final PsiParameter[] parameters = method.getParameterList().getParameters();
    for (int index = 0; index < parameters.length; index++) {
        PsiParameter parameter = parameters[index];
        if (!(parameter.getType() instanceof PsiPrimitiveType) && !NullableNotNullManager.isNotNull(parameter) && !NullableNotNullManager.isNullable(parameter) && JavaNullMethodArgumentUtil.hasNullArgument(method, index)) {
            nullableParameters.add(parameter);
        }
    }
    if (nullableParameters.isEmpty())
        return PsiParameter.EMPTY_ARRAY;
    final NullParameterConstraintChecker checker = new NullParameterConstraintChecker(nullableParameters);
    checker.analyzeMethod(method.getBody(), new StandardInstructionVisitor());
    return checker.myPossiblyViolatedParameters.stream().filter(checker.myUsedParameters::contains).toArray(PsiParameter[]::new);
}
Also used : PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiParameter(com.intellij.psi.PsiParameter) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SmartList (com.intellij.util.SmartList)163 NotNull (org.jetbrains.annotations.NotNull)70 Nullable (org.jetbrains.annotations.Nullable)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)24 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)14 TextRange (com.intellij.openapi.util.TextRange)12 PsiElement (com.intellij.psi.PsiElement)12 List (java.util.List)12 Element (org.jdom.Element)12 File (java.io.File)11 THashSet (gnu.trove.THashSet)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)8 ArrayList (java.util.ArrayList)8 Collection (java.util.Collection)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)6 IOException (java.io.IOException)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 IElementType (com.intellij.psi.tree.IElementType)5