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;
}
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();
}
}
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;
}
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;
}
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();
}
Aggregations