use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class AntResolveInspection method checkReferences.
private static void checkReferences(final XmlElement xmlElement, @NonNls final DomElementAnnotationHolder holder, DomElement domElement) {
if (xmlElement == null) {
return;
}
Set<PsiReference> processed = null;
// to be initialized lazily
Collection<PropertiesFile> propertyFiles = null;
for (final PsiReference ref : xmlElement.getReferences()) {
if (!(ref instanceof AntDomReference)) {
continue;
}
final AntDomReference antDomRef = (AntDomReference) ref;
if (antDomRef.shouldBeSkippedByAnnotator()) {
continue;
}
if (processed != null && processed.contains(ref)) {
continue;
}
if (!isResolvable(ref)) {
final List<LocalQuickFix> quickFixList = new SmartList<>();
quickFixList.add(new AntChangeContextLocalFix());
if (ref instanceof AntDomPropertyReference) {
final String canonicalText = ref.getCanonicalText();
quickFixList.add(new AntCreatePropertyFix(canonicalText, null));
final PsiFile containingFile = xmlElement.getContainingFile();
if (containingFile != null) {
if (propertyFiles == null) {
propertyFiles = getPropertyFiles(AntSupport.getAntDomProject(containingFile), xmlElement);
}
for (PropertiesFile propertyFile : propertyFiles) {
quickFixList.add(new AntCreatePropertyFix(canonicalText, propertyFile));
}
}
} else if (ref instanceof AntDomTargetReference) {
quickFixList.add(new AntCreateTargetFix(ref.getCanonicalText()));
}
holder.createProblem(domElement, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, antDomRef.getUnresolvedMessagePattern(), ref.getRangeInElement(), quickFixList.toArray((new LocalQuickFix[quickFixList.size()])));
if (ref instanceof AntDomFileReference) {
if (processed == null) {
processed = new HashSet<>();
}
ContainerUtil.addAll(processed, ((AntDomFileReference) ref).getFileReferenceSet().getAllReferences());
}
}
}
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class ExtensionPointImpl method collectMissingWithTags.
@Override
public List<PsiField> collectMissingWithTags() {
PsiClass beanClass = getBeanClass().getValue();
if (beanClass == null) {
return Collections.emptyList();
}
final List<PsiField> result = new SmartList<>();
for (PsiField field : beanClass.getAllFields()) {
if (ExtensionDomExtender.isClassField(field.getName()) && ExtensionDomExtender.findWithElement(getWithElements(), field) == null) {
result.add(field);
}
}
return result;
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class NestingTreeStructureProvider method getFilesShownAsChildrenInProjectView.
// Algorithm is similar to calcParentToChildren(), but a bit simpler, because we have one specific parentFile.
public static Collection<ChildFileInfo> getFilesShownAsChildrenInProjectView(@NotNull final Project project, @NotNull final VirtualFile parentFile) {
LOG.assertTrue(!parentFile.isDirectory());
final VirtualFile dir = parentFile.getParent();
if (dir == null)
return Collections.emptyList();
final Collection<NestingRule> rules = getNestingRulesStatic(project);
if (rules.isEmpty())
return Collections.emptyList();
final VirtualFile[] children = dir.getChildren();
if (children.length <= 1)
return Collections.emptyList();
final Collection<NestingRule> rulesWhereItCanBeParent = filterRules(rules, parentFile.getName(), true);
if (rulesWhereItCanBeParent.isEmpty())
return Collections.emptyList();
final Collection<NestingRule> rulesWhereItCanBeChild = filterRules(rules, parentFile.getName(), false);
final SmartList<ChildFileInfo> result = new SmartList<>();
for (VirtualFile child : children) {
if (child.isDirectory())
continue;
if (child.equals(parentFile))
continue;
// if given parentFile itself appears to be a child of some other file, it means that it is not shown as parent node in Project View
for (NestingRule rule : rulesWhereItCanBeChild) {
final String childName = child.getName();
final Couple<Boolean> c = checkMatchingAsParentOrChild(rule, childName);
final boolean matchesParent = c.first;
if (matchesParent) {
final String baseName = childName.substring(0, childName.length() - rule.myParentFileSuffix.length());
if (parentFile.getName().equals(baseName + rule.myChildFileSuffix)) {
// parentFile itself appears to be a child of childFile
return Collections.emptyList();
}
}
}
for (NestingRule rule : rulesWhereItCanBeParent) {
final String childName = child.getName();
final Couple<Boolean> c = checkMatchingAsParentOrChild(rule, childName);
final boolean matchesChild = c.second;
if (matchesChild) {
final String baseName = childName.substring(0, childName.length() - rule.myChildFileSuffix.length());
if (parentFile.getName().equals(baseName + rule.myParentFileSuffix)) {
result.add(new ChildFileInfo(child, baseName));
}
}
}
}
return result;
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class ProjectTreeBuilder method updateNodesContaining.
private void updateNodesContaining(@NotNull Collection<VirtualFile> filesToRefresh, @NotNull DefaultMutableTreeNode rootNode) {
if (!(rootNode.getUserObject() instanceof ProjectViewNode))
return;
ProjectViewNode node = (ProjectViewNode) rootNode.getUserObject();
Collection<VirtualFile> containingFiles = null;
for (VirtualFile virtualFile : filesToRefresh) {
if (!virtualFile.isValid()) {
// file must be deleted
addSubtreeToUpdate(rootNode);
return;
}
if (node.contains(virtualFile)) {
if (containingFiles == null)
containingFiles = new SmartList<>();
containingFiles.add(virtualFile);
}
}
if (containingFiles != null) {
updateNode(rootNode);
Enumeration children = rootNode.children();
while (children.hasMoreElements()) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
updateNodesContaining(containingFiles, child);
}
}
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class UsageFavoriteNodeProvider method getFavoriteNodes.
@Override
public Collection<AbstractTreeNode> getFavoriteNodes(DataContext context, ViewSettings viewSettings) {
final Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null) {
return null;
}
final Usage[] usages = UsageView.USAGES_KEY.getData(context);
if (usages != null) {
final List<AbstractTreeNode> result = new SmartList<>();
final MultiMap<VirtualFile, Usage> map = new MultiMap<>();
final List<Usage> nonMapped = new ArrayList<>();
for (Usage usage : usages) {
if (usage instanceof UsageInFile) {
map.putValue(((UsageInFile) usage).getFile(), usage);
} else if (usage instanceof UsageInFiles) {
final VirtualFile[] files = ((UsageInFiles) usage).getFiles();
for (VirtualFile file : files) {
map.putValue(file, usage);
}
} else {
nonMapped.add(usage);
}
}
final TreeSet<VirtualFile> keys = new TreeSet<>(VIRTUAL_FILE_COMPARATOR);
keys.addAll(map.keySet());
for (VirtualFile key : keys) {
final FileGroupingProjectNode grouping = new FileGroupingProjectNode(project, new File(key.getPath()), viewSettings);
result.add(grouping);
final Collection<Usage> subUsages = map.get(key);
for (Usage usage : subUsages) {
if (usage instanceof UsageInfo2UsageAdapter) {
final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
grouping.addChild(node);
} else if (NullUsage.INSTANCE.equals(usage)) {
continue;
} else {
grouping.addChild(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
}
}
}
for (Usage usage : nonMapped) {
if (usage instanceof UsageInfo2UsageAdapter) {
final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
result.add(node);
} else if (NullUsage.INSTANCE.equals(usage)) {
continue;
} else {
result.add(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
}
}
return result;
}
return null;
}
Aggregations