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