Search in sources :

Example 16 with SmartList

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

the class HgHistoryUtil method loadMetadata.

@NotNull
public static List<VcsCommitMetadata> loadMetadata(@NotNull final Project project, @NotNull final VirtualFile root, int limit, @NotNull List<String> parameters) throws VcsException {
    final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
    if (factory == null) {
        return Collections.emptyList();
    }
    HgVcs hgvcs = HgVcs.getInstance(project);
    assert hgvcs != null;
    HgVersion version = hgvcs.getVersion();
    List<String> templateList = HgBaseLogParser.constructDefaultTemplate(version);
    templateList.add("{desc}");
    String[] templates = ArrayUtil.toStringArray(templateList);
    HgCommandResult result = getLogResult(project, root, version, limit, parameters, HgChangesetUtil.makeTemplate(templates));
    HgBaseLogParser<VcsCommitMetadata> baseParser = new HgBaseLogParser<VcsCommitMetadata>() {

        @Override
        protected VcsCommitMetadata convertDetails(@NotNull String rev, @NotNull String changeset, @NotNull SmartList<HgRevisionNumber> parents, @NotNull Date revisionDate, @NotNull String author, @NotNull String email, @NotNull List<String> attributes) {
            String message = parseAdditionalStringAttribute(attributes, MESSAGE_INDEX);
            String subject = extractSubject(message);
            List<Hash> parentsHash = new SmartList<>();
            for (HgRevisionNumber parent : parents) {
                parentsHash.add(factory.createHash(parent.getChangeset()));
            }
            return factory.createCommitMetadata(factory.createHash(changeset), parentsHash, revisionDate.getTime(), root, subject, author, email, message, author, email, revisionDate.getTime());
        }
    };
    return getCommitRecords(project, result, baseParser);
}
Also used : NotNull(org.jetbrains.annotations.NotNull) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) SmartList(com.intellij.util.SmartList) HgVersion(org.zmlx.hg4idea.util.HgVersion) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with SmartList

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

the class ResourceBundleReference method getVariants.

@Override
@NotNull
public Object[] getVariants() {
    final ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(getElement().getProject());
    final PropertiesReferenceManager referenceManager = PropertiesReferenceManager.getInstance(getElement().getProject());
    final Set<String> bundleNames = new HashSet<>();
    final List<LookupElement> variants = new SmartList<>();
    PropertiesFileProcessor processor = new PropertiesFileProcessor() {

        @Override
        public boolean process(String baseName, PropertiesFile propertiesFile) {
            if (!bundleNames.add(baseName))
                return true;
            final LookupElementBuilder builder = LookupElementBuilder.create(baseName).withIcon(AllIcons.Nodes.ResourceBundle);
            boolean isInContent = projectFileIndex.isInContent(propertiesFile.getVirtualFile());
            variants.add(isInContent ? PrioritizedLookupElement.withPriority(builder, Double.MAX_VALUE) : builder);
            return true;
        }
    };
    referenceManager.processPropertiesFiles(myElement.getResolveScope(), processor, this);
    return variants.toArray(new LookupElement[variants.size()]);
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) SmartList(com.intellij.util.SmartList) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PrioritizedLookupElement(com.intellij.codeInsight.completion.PrioritizedLookupElement) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with SmartList

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

the class MavenArtifactIndex method findArtifacts.

@NotNull
public List<MavenArtifact> findArtifacts(@Nullable String groupId, @Nullable String artifactId, @Nullable String version) {
    Map<String, List<MavenArtifact>> groupMap = myData.get(groupId);
    if (groupMap == null)
        return Collections.emptyList();
    List<MavenArtifact> artifacts = groupMap.get(artifactId);
    if (artifacts == null)
        return Collections.emptyList();
    List<MavenArtifact> res = new SmartList<>();
    for (MavenArtifact artifact : artifacts) {
        if (Comparing.equal(version, artifact.getVersion())) {
            res.add(artifact);
        }
    }
    return res;
}
Also used : List(java.util.List) SmartList(com.intellij.util.SmartList) SmartList(com.intellij.util.SmartList) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with SmartList

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

the class HtmlFileTreeElement method getChildrenBase.

@Override
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
    if (isHtml5SectionsMode()) {
        // Html5SectionsNodeProvider will return its structure
        return Collections.emptyList();
    }
    final XmlFile xmlFile = getElement();
    final XmlDocument document = xmlFile == null ? null : xmlFile.getDocument();
    if (document == null) {
        return Collections.emptyList();
    }
    final List<XmlTag> rootTags = new SmartList<>();
    document.processElements(new FilterElementProcessor(XmlTagFilter.INSTANCE, rootTags), document);
    if (rootTags.isEmpty()) {
        return Collections.emptyList();
    } else if (rootTags.size() == 1) {
        final XmlTag rootTag = rootTags.get(0);
        if ("html".equalsIgnoreCase(rootTag.getLocalName())) {
            final XmlTag[] subTags = rootTag.getSubTags();
            if (subTags.length == 1 && ("head".equalsIgnoreCase(subTags[0].getLocalName()) || "body".equalsIgnoreCase(subTags[0].getLocalName()))) {
                return new HtmlTagTreeElement(subTags[0]).getChildrenBase();
            }
            return new HtmlTagTreeElement(rootTag).getChildrenBase();
        }
        return Collections.<StructureViewTreeElement>singletonList(new HtmlTagTreeElement(rootTag));
    } else {
        final Collection<StructureViewTreeElement> result = new ArrayList<>(rootTags.size());
        for (XmlTag tag : rootTags) {
            result.add(new HtmlTagTreeElement(tag));
        }
        return result;
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) FilterElementProcessor(com.intellij.psi.scope.processor.FilterElementProcessor) Collection(java.util.Collection) XmlDocument(com.intellij.psi.xml.XmlDocument) SmartList(com.intellij.util.SmartList) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with SmartList

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

the class JavaLineBreakpointType method computeVariants.

@NotNull
@Override
public List<JavaBreakpointVariant> computeVariants(@NotNull Project project, @NotNull XSourcePosition position) {
    PsiFile file = PsiManager.getInstance(project).findFile(position.getFile());
    if (file == null) {
        return Collections.emptyList();
    }
    SourcePosition pos = SourcePosition.createFromLine(file, position.getLine());
    List<PsiLambdaExpression> lambdas = DebuggerUtilsEx.collectLambdas(pos, true);
    if (lambdas.isEmpty()) {
        return Collections.emptyList();
    }
    PsiElement startMethod = DebuggerUtilsEx.getContainingMethod(pos);
    //noinspection SuspiciousMethodCalls
    if (lambdas.contains(startMethod) && lambdas.size() == 1) {
        return Collections.emptyList();
    }
    Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    if (document == null) {
        return Collections.emptyList();
    }
    List<JavaBreakpointVariant> res = new SmartList<>();
    if (!(startMethod instanceof PsiLambdaExpression)) {
        // base method
        res.add(new LineJavaBreakpointVariant(position, startMethod, -1));
    }
    int ordinal = 0;
    for (PsiLambdaExpression lambda : lambdas) {
        //lambdas
        PsiElement firstElem = DebuggerUtilsEx.getFirstElementOnTheLine(lambda, document, position.getLine());
        XSourcePositionImpl elementPosition = XSourcePositionImpl.createByElement(firstElem);
        if (elementPosition != null) {
            if (lambda == startMethod) {
                res.add(0, new LineJavaBreakpointVariant(elementPosition, lambda, ordinal++));
            } else {
                res.add(new LambdaJavaBreakpointVariant(elementPosition, lambda, ordinal++));
            }
        }
    }
    //all
    res.add(new JavaBreakpointVariant(position));
    return res;
}
Also used : Document(com.intellij.openapi.editor.Document) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XSourcePositionImpl(com.intellij.xdebugger.impl.XSourcePositionImpl) XSourcePosition(com.intellij.xdebugger.XSourcePosition) SourcePosition(com.intellij.debugger.SourcePosition) 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