Search in sources :

Example 11 with SmartList

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

the class MvcModuleStructureUtil method removeAuxiliaryModule.

public static void removeAuxiliaryModule(Module toRemove) {
    List<ModifiableRootModel> usingModels = new SmartList<>();
    Project project = toRemove.getProject();
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    for (Module module : moduleManager.getModules()) {
        if (module == toRemove) {
            continue;
        }
        ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        for (OrderEntry entry : moduleRootManager.getOrderEntries()) {
            if (entry instanceof ModuleOrderEntry && toRemove == ((ModuleOrderEntry) entry).getModule()) {
                usingModels.add(moduleRootManager.getModifiableModel());
                break;
            }
        }
    }
    final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
    ModuleDeleteProvider.removeModule(toRemove, null, usingModels, moduleModel);
    ModifiableModelCommitter.multiCommit(usingModels, moduleModel);
}
Also used : Project(com.intellij.openapi.project.Project) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) SmartList(com.intellij.util.SmartList) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 12 with SmartList

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

the class BaseSplitter method excludeByPattern.

@NotNull
protected static List<TextRange> excludeByPattern(String text, TextRange range, @NotNull Pattern toExclude, int groupToInclude) {
    List<TextRange> toCheck = new SmartList<>();
    int from = range.getStartOffset();
    int till;
    boolean addLast = true;
    Matcher matcher = toExclude.matcher(StringUtil.newBombedCharSequence(range.substring(text), 500));
    try {
        while (matcher.find()) {
            checkCancelled();
            TextRange found = matcherRange(range, matcher);
            till = found.getStartOffset();
            if (range.getEndOffset() - found.getEndOffset() < MIN_RANGE_LENGTH) {
                addLast = false;
            }
            if (!badSize(from, till)) {
                toCheck.add(new TextRange(from, till));
            }
            if (groupToInclude > 0) {
                TextRange contentFound = matcherRange(range, matcher, groupToInclude);
                if (badSize(contentFound.getEndOffset(), contentFound.getStartOffset())) {
                    toCheck.add(TextRange.create(contentFound));
                }
            }
            from = found.getEndOffset();
        }
        till = range.getEndOffset();
        if (badSize(from, till)) {
            return toCheck;
        }
        if (addLast) {
            toCheck.add(new TextRange(from, till));
        }
        return toCheck;
    } catch (ProcessCanceledException e) {
        return Collections.singletonList(range);
    }
}
Also used : Matcher(java.util.regex.Matcher) TextRange(com.intellij.openapi.util.TextRange) SmartList(com.intellij.util.SmartList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with SmartList

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

the class OverriddenDefineRenderer method getClickAction.

@Override
@Nullable
public AnAction getClickAction() {
    return new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final PsiElement element = myDefine.getPsiElement();
            if (element == null || !element.isValid())
                return;
            final PsiElementProcessor.CollectElements<XmlFile> collector = new PsiElementProcessor.CollectElements<>();
            final XmlFile localFile = (XmlFile) element.getContainingFile();
            RelaxIncludeIndex.processBackwardDependencies(localFile, collector);
            final Collection<XmlFile> files = collector.getCollection();
            final List<Define> result = new SmartList<>();
            final OverriddenDefineSearcher searcher = new OverriddenDefineSearcher(myDefine, localFile, result);
            for (XmlFile file : files) {
                final Grammar grammar = GrammarFactory.getGrammar(file);
                if (grammar == null)
                    continue;
                grammar.acceptChildren(searcher);
            }
            if (result.size() > 0) {
                OverridingDefineRenderer.doClickAction(e, result, "Go to overriding define(s)");
            }
        }
    };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) Grammar(org.intellij.plugins.relaxNG.model.Grammar) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) Define(org.intellij.plugins.relaxNG.model.Define) SmartList(com.intellij.util.SmartList) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with SmartList

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

the class HgBaseLogParser method parseParentRevisions.

@NotNull
protected static SmartList<HgRevisionNumber> parseParentRevisions(@NotNull String parentsString, @NotNull String currentRevisionString) {
    SmartList<HgRevisionNumber> parents = new SmartList<>();
    if (StringUtil.isEmptyOrSpaces(parentsString)) {
        // parents shouldn't be empty  only if not supported
        Long revision = Long.valueOf(currentRevisionString);
        HgRevisionNumber parentRevision = HgRevisionNumber.getLocalInstance(String.valueOf(revision - 1));
        parents.add(parentRevision);
        return parents;
    }
    //hg returns parents in the format 'rev:node rev:node ' (note the trailing space)
    List<String> parentStrings = StringUtil.split(parentsString.trim(), " ");
    for (String parentString : parentStrings) {
        List<String> parentParts = StringUtil.split(parentString, ":");
        // its second parent has revision number  -1
        if (Integer.valueOf(parentParts.get(0)) >= 0) {
            parents.add(HgRevisionNumber.getInstance(parentParts.get(0), parentParts.get(1)));
        }
    }
    return parents;
}
Also used : HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with SmartList

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

the class HgHistoryUtil method readMiniDetails.

@NotNull
public static List<? extends VcsShortCommitDetails> readMiniDetails(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull List<String> hashes) throws VcsException {
    final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
    if (factory == null) {
        return Collections.emptyList();
    }
    HgVcs hgvcs = HgVcs.getInstance(project);
    assert hgvcs != null;
    final HgVersion version = hgvcs.getVersion();
    List<String> templateList = HgBaseLogParser.constructDefaultTemplate(version);
    templateList.add("{desc}");
    final String[] templates = ArrayUtil.toStringArray(templateList);
    return VcsFileUtil.foreachChunk(prepareHashes(hashes), 2, strings -> {
        HgCommandResult logResult = getLogResult(project, root, version, -1, strings, HgChangesetUtil.makeTemplate(templates));
        return getCommitRecords(project, logResult, new HgBaseLogParser<VcsShortCommitDetails>() {

            @Override
            protected VcsShortCommitDetails 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.createShortDetails(factory.createHash(changeset), parentsHash, revisionDate.getTime(), root, subject, author, email, author, email, revisionDate.getTime());
            }
        });
    });
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) SmartList(com.intellij.util.SmartList) HgVersion(org.zmlx.hg4idea.util.HgVersion) 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