Search in sources :

Example 36 with SmartList

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

the class BaseExternalAnnotationsManager method findExternalAnnotationsFiles.

@Override
@Nullable
public List<PsiFile> findExternalAnnotationsFiles(@NotNull PsiModifierListOwner listOwner) {
    final PsiFile containingFile = PsiUtil.preferCompiledElement(listOwner).getContainingFile();
    if (!(containingFile instanceof PsiJavaFile))
        return null;
    final VirtualFile virtualFile = containingFile.getVirtualFile();
    if (virtualFile == null)
        return null;
    final List<PsiFile> files = myExternalAnnotationsCache.get(virtualFile);
    if (files == NULL_LIST)
        return null;
    if (files != null) {
        boolean allValid = true;
        for (PsiFile file : files) {
            if (!file.isValid()) {
                allValid = false;
                break;
            }
        }
        if (allValid) {
            return files;
        }
    }
    Set<PsiFile> possibleAnnotationXmls = new THashSet<>();
    String relativePath = ((PsiJavaFile) containingFile).getPackageName().replace('.', '/') + '/' + ANNOTATIONS_XML;
    for (VirtualFile root : getExternalAnnotationsRoots(virtualFile)) {
        VirtualFile ext = root.findFileByRelativePath(relativePath);
        if (ext != null && ext.isValid()) {
            PsiFile psiFile = myPsiManager.findFile(ext);
            if (psiFile != null) {
                possibleAnnotationXmls.add(psiFile);
            }
        }
    }
    if (possibleAnnotationXmls.isEmpty()) {
        myExternalAnnotationsCache.put(virtualFile, NULL_LIST);
        return null;
    }
    List<PsiFile> result = new SmartList<>(possibleAnnotationXmls);
    // writable go first
    result.sort((f1, f2) -> {
        boolean w1 = f1.isWritable();
        boolean w2 = f2.isWritable();
        return w1 == w2 ? 0 : w1 ? -1 : 1;
    });
    myExternalAnnotationsCache.put(virtualFile, result);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) SmartList(com.intellij.util.SmartList) THashSet(gnu.trove.THashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 37 with SmartList

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

the class ModuleTestCase method tearDown.

@Override
protected void tearDown() throws Exception {
    try {
        if (!myModulesToDispose.isEmpty()) {
            List<Throwable> errors = new SmartList<>();
            WriteAction.run(() -> {
                ModuleManager moduleManager = ModuleManager.getInstance(myProject);
                for (Module module : myModulesToDispose) {
                    try {
                        String moduleName = module.getName();
                        if (moduleManager.findModuleByName(moduleName) != null) {
                            moduleManager.disposeModule(module);
                        }
                    } catch (Throwable e) {
                        errors.add(e);
                    }
                }
            });
            CompoundRuntimeException.throwIfNotEmpty(errors);
        }
    } finally {
        myModulesToDispose.clear();
        super.tearDown();
    }
}
Also used : SmartList(com.intellij.util.SmartList) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 38 with SmartList

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

the class GeneralHighlightingPass method convertToProblems.

private static List<Problem> convertToProblems(@NotNull Collection<HighlightInfo> infos, @NotNull VirtualFile file, final boolean hasErrorElement) {
    List<Problem> problems = new SmartList<>();
    for (HighlightInfo info : infos) {
        if (info.getSeverity() == HighlightSeverity.ERROR) {
            Problem problem = new ProblemImpl(file, info, hasErrorElement);
            problems.add(problem);
        }
    }
    return problems;
}
Also used : ProblemImpl(com.intellij.codeInsight.problems.ProblemImpl) Problem(com.intellij.problems.Problem) SmartList(com.intellij.util.SmartList)

Example 39 with SmartList

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

the class PsiFileStubImpl method getStubRoots.

@NotNull
@Override
public PsiFileStub[] getStubRoots() {
    if (myStubRoots != null)
        return myStubRoots;
    final T psi = getPsi();
    if (psi == null) {
        return new PsiFileStub[] { this };
    }
    final FileViewProvider viewProvider = psi.getViewProvider();
    final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
    StubTree baseTree = getOrCalcStubTree(stubBindingRoot);
    if (baseTree != null) {
        final List<PsiFileStub> roots = new SmartList<>(baseTree.getRoot());
        final List<Pair<IStubFileElementType, PsiFile>> stubbedRoots = StubTreeBuilder.getStubbedRoots(viewProvider);
        for (Pair<IStubFileElementType, PsiFile> stubbedRoot : stubbedRoots) {
            if (stubbedRoot.second == stubBindingRoot)
                continue;
            final StubTree secondaryStubTree = getOrCalcStubTree(stubbedRoot.second);
            if (secondaryStubTree != null) {
                final PsiFileStub root = secondaryStubTree.getRoot();
                roots.add(root);
            }
        }
        final PsiFileStub[] rootsArray = roots.toArray(new PsiFileStub[roots.size()]);
        for (PsiFileStub root : rootsArray) {
            if (root instanceof PsiFileStubImpl) {
                ((PsiFileStubImpl) root).setStubRoots(rootsArray);
            }
        }
        myStubRoots = rootsArray;
        return rootsArray;
    }
    return PsiFileStub.EMPTY_ARRAY;
}
Also used : IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) FileViewProvider(com.intellij.psi.FileViewProvider) PsiFile(com.intellij.psi.PsiFile) SmartList(com.intellij.util.SmartList) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 40 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 IElementType type) {
    List<LighterASTNode> result = null;
    List<LighterASTNode> children = tree.getChildren(node);
    for (int i = 0, size = children.size(); i < size; ++i) {
        LighterASTNode child = children.get(i);
        if (child.getTokenType() == type) {
            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)

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