Search in sources :

Example 6 with SmartList

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

the class PySkeletonRefresher method regenerateSkeletons.

public List<String> regenerateSkeletons(@Nullable SkeletonVersionChecker cachedChecker) throws InvalidSdkException {
    final List<String> errorList = new SmartList<>();
    final String homePath = mySdk.getHomePath();
    final String skeletonsPath = getSkeletonsPath();
    final File skeletonsDir = new File(skeletonsPath);
    if (!skeletonsDir.exists()) {
        //noinspection ResultOfMethodCallIgnored
        skeletonsDir.mkdirs();
    }
    final String readablePath = FileUtil.getLocationRelativeToUserHome(homePath);
    mySkeletonsGenerator.prepare();
    myBlacklist = loadBlacklist();
    indicate(PyBundle.message("sdk.gen.querying.$0", readablePath));
    // get generator version and binary libs list in one go
    final String extraSysPath = calculateExtraSysPath(mySdk, getSkeletonsPath());
    final PySkeletonGenerator.ListBinariesResult binaries = mySkeletonsGenerator.listBinaries(mySdk, extraSysPath);
    myGeneratorVersion = binaries.generatorVersion;
    myPregeneratedSkeletons = findPregeneratedSkeletons();
    indicate(PyBundle.message("sdk.gen.reading.versions.file"));
    if (cachedChecker != null) {
        myVersionChecker = cachedChecker.withDefaultVersionIfUnknown(myGeneratorVersion);
    } else {
        myVersionChecker = new SkeletonVersionChecker(myGeneratorVersion);
    }
    // check builtins
    final String builtinsFileName = PythonSdkType.getBuiltinsFileName(mySdk);
    final File builtinsFile = new File(skeletonsPath, builtinsFileName);
    final SkeletonHeader oldHeader = readSkeletonHeader(builtinsFile);
    final boolean oldOrNonExisting = oldHeader == null || oldHeader.getVersion() == 0;
    if (myPregeneratedSkeletons != null && oldOrNonExisting) {
        unpackPreGeneratedSkeletons();
    }
    if (oldOrNonExisting) {
        copyBaseSdkSkeletonsToVirtualEnv(skeletonsPath, binaries);
    }
    final boolean builtinsUpdated = updateSkeletonsForBuiltins(readablePath, builtinsFile);
    if (!binaries.modules.isEmpty()) {
        indicate(PyBundle.message("sdk.gen.updating.$0", readablePath));
        final List<UpdateResult> updateErrors = updateOrCreateSkeletons(binaries.modules);
        if (updateErrors.size() > 0) {
            indicateMinor(BLACKLIST_FILE_NAME);
            for (UpdateResult error : updateErrors) {
                if (error.isFresh())
                    errorList.add(error.getName());
                myBlacklist.put(error.getPath(), new Pair<>(myGeneratorVersion, error.getTimestamp()));
            }
            storeBlacklist(skeletonsDir, myBlacklist);
        } else {
            removeBlacklist(skeletonsDir);
        }
    }
    indicate(PyBundle.message("sdk.gen.reloading"));
    mySkeletonsGenerator.refreshGeneratedSkeletons();
    if (!oldOrNonExisting) {
        indicate(PyBundle.message("sdk.gen.cleaning.$0", readablePath));
        cleanUpSkeletons(skeletonsDir);
    }
    if ((builtinsUpdated || PySdkUtil.isRemote(mySdk)) && myProject != null) {
        ApplicationManager.getApplication().invokeLater(() -> DaemonCodeAnalyzer.getInstance(myProject).restart(), myProject.getDisposed());
    }
    return errorList;
}
Also used : SkeletonVersionChecker.fromVersionString(com.jetbrains.python.sdk.skeletons.SkeletonVersionChecker.fromVersionString) SmartList(com.intellij.util.SmartList) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 7 with SmartList

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

the class XmlBlock method buildChildren.

@Override
protected List<Block> buildChildren() {
    //
    if (myNode.getElementType() == XmlElementType.XML_ATTRIBUTE_VALUE) {
        return splitAttribute(myNode, myXmlFormattingPolicy);
    }
    if (myNode.getElementType() == XmlElementType.XML_COMMENT) {
        List<Block> result = new SmartList<>();
        if (buildInjectedPsiBlocks(result, myNode, myWrap, null, Indent.getNoneIndent())) {
            return result;
        }
        return splitComment();
    }
    if (myNode.getFirstChildNode() != null) {
        boolean keepWhitespaces = shouldKeepWhitespaces();
        final ArrayList<Block> result = new ArrayList<>(5);
        ASTNode child = myNode.getFirstChildNode();
        while (child != null) {
            if (child.getTextLength() > 0) {
                if (containsWhiteSpacesOnly(child)) {
                    if (keepWhitespaces) {
                        result.add(new ReadOnlyBlock(child));
                    }
                } else {
                    child = processChild(result, child, getDefaultWrap(child), null, getChildDefaultIndent());
                }
            }
            if (child != null) {
                LOG.assertTrue(child.getTreeParent() == myNode);
                child = child.getTreeNext();
            }
        }
        return result;
    } else {
        return EMPTY;
    }
}
Also used : ArrayList(java.util.ArrayList) ASTNode(com.intellij.lang.ASTNode) AbstractBlock(com.intellij.psi.formatter.common.AbstractBlock) SmartList(com.intellij.util.SmartList)

Example 8 with SmartList

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

the class PropertiesUtil method findAllProperties.

/**
   * @deprecated use PropertiesUtil.findAllProperties(ResourceBundle resourceBundle, String key)
   */
@NotNull
@Deprecated
public static List<IProperty> findAllProperties(Project project, @NotNull ResourceBundle resourceBundle, String key) {
    List<IProperty> result = new SmartList<>();
    List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
    for (PropertiesFile propertiesFile : propertiesFiles) {
        result.addAll(propertiesFile.findPropertiesByKey(key));
    }
    return result;
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with SmartList

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

the class SvnQuickMergeTest method testSelectRevisionsWithQuickSelectCheckForLocalChanges.

@Test
public void testSelectRevisionsWithQuickSelectCheckForLocalChanges() throws Exception {
    // get revision #
    final SVNInfo info = myVcs.getSvnKitManager().createWCClient().doInfo(virtualToIoFile(myBranchTree.myS1File), WORKING);
    Assert.assertNotNull(info);
    final long numberBefore = info.getRevision().getNumber();
    final int totalChanges = 3;
    final StringBuilder sb = new StringBuilder(FileUtil.loadFile(virtualToIoFile(myBranchTree.myS1File)));
    for (int i = 0; i < totalChanges; i++) {
        sb.append("\nedited in branch ").append(i);
        VcsTestUtil.editFileInCommand(myProject, myBranchTree.myS1File, sb.toString());
        runInAndVerifyIgnoreOutput(myBranchRoot, "ci", "-m", "change in branch " + i, myBranchTree.myS1File.getPath());
        Thread.sleep(10);
    }
    AtomicReference<String> selectionError = new AtomicReference<>();
    QuickMergeTestInteraction testInteraction = new QuickMergeTestInteraction(true, lists -> {
        if (lists.get(3).getNumber() != numberBefore) {
            selectionError.set("wrong revision for copy statement: " + lists.get(3).getNumber());
        }
        return new SmartList<>(lists.get(2));
    });
    testInteraction.setMergeVariant(QuickMergeContentsVariants.showLatest);
    waitQuickMerge(myBranchUrl, testInteraction);
    if (selectionError.get() != null) {
        throw new RuntimeException(selectionError.get());
    }
    VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
    myChangeListManager.ensureUpToDate(false);
    // should have changed svn:mergeinfo on wc root and s1 file
    final Change fileChange = myChangeListManager.getChange(myTree.myS1File);
    Assert.assertNotNull(fileChange);
    Assert.assertEquals(FileStatus.MODIFIED, fileChange.getFileStatus());
    final Change dirChange = myChangeListManager.getChange(myWorkingCopyDir);
    Assert.assertNotNull(dirChange);
    Assert.assertEquals(FileStatus.MODIFIED, dirChange.getFileStatus());
    final SVNPropertyData data = myVcs.getSvnKitManager().createWCClient().doGetProperty(virtualToIoFile(myWorkingCopyDir), "svn:mergeinfo", UNDEFINED, WORKING);
    System.out.println(data.getValue().getString());
    Assert.assertEquals("/branches/b1:" + (numberBefore + 1), data.getValue().getString());
}
Also used : SVNPropertyData(org.tmatesoft.svn.core.wc.SVNPropertyData) SVNInfo(org.tmatesoft.svn.core.wc.SVNInfo) AtomicReference(java.util.concurrent.atomic.AtomicReference) Change(com.intellij.openapi.vcs.changes.Change) SmartList(com.intellij.util.SmartList) Test(org.junit.Test)

Example 10 with SmartList

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

the class SvnQuickMergeTest method testSelectRevisionsWithQuickSelect.

// this test is mainly to check revisions selection. at the moment we are not sure whether we support
// trunk->b1->b2 merges between trunk and b2
@Test
public void testSelectRevisionsWithQuickSelect() throws Exception {
    // get revision #
    final SVNInfo info = myVcs.getSvnKitManager().createWCClient().doInfo(virtualToIoFile(myBranchTree.myS1File), WORKING);
    Assert.assertNotNull(info);
    final long numberBefore = info.getRevision().getNumber();
    final int totalChanges = 3;
    final StringBuilder sb = new StringBuilder(FileUtil.loadFile(virtualToIoFile(myBranchTree.myS1File)));
    for (int i = 0; i < totalChanges; i++) {
        sb.append("\nedited in branch ").append(i);
        VcsTestUtil.editFileInCommand(myProject, myBranchTree.myS1File, sb.toString());
        runInAndVerifyIgnoreOutput(myBranchRoot, "ci", "-m", "change in branch " + i, myBranchTree.myS1File.getPath());
        Thread.sleep(10);
    }
    // before copy
    final SVNInfo info2 = myVcs.getSvnKitManager().createWCClient().doInfo(virtualToIoFile(myBranchTree.myS1File), WORKING);
    Assert.assertNotNull(info2);
    final long numberBeforeCopy = info2.getRevision().getNumber();
    runInAndVerifyIgnoreOutput("copy", "-q", "-m", "copy1", myBranchUrl, myRepoUrl + "/branches/b2");
    // switch b1 to b2
    runInAndVerifyIgnoreOutput(myBranchRoot, "switch", myRepoUrl + "/branches/b2", myBranchRoot.getPath());
    //reload
    myBranchTree = new SubTree(myBranchVf);
    // one commit in b2 in s2 file
    VcsTestUtil.editFileInCommand(myProject, myBranchTree.myS2File, "completely changed");
    runInAndVerifyIgnoreOutput(myBranchRoot, "ci", "-m", "change in b2", myBranchTree.myS2File.getPath());
    AtomicReference<String> selectionError = new AtomicReference<>();
    QuickMergeTestInteraction testInteraction = new QuickMergeTestInteraction(true, lists -> {
        if (lists.get(1).getNumber() != numberBeforeCopy + 1) {
            selectionError.set("wrong revision for copy statement: " + lists.get(1).getNumber());
        }
        return new SmartList<>(lists.get(0));
    });
    testInteraction.setMergeVariant(QuickMergeContentsVariants.showLatest);
    waitQuickMerge(myRepoUrl + "/branches/b2", testInteraction);
    if (selectionError.get() != null) {
        throw new RuntimeException(selectionError.get());
    }
    VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
    myChangeListManager.ensureUpToDate(false);
    // should have changed svn:mergeinfo on wc root and s1 file
    final Change fileChange = myChangeListManager.getChange(myTree.myS2File);
    Assert.assertNotNull(fileChange);
    Assert.assertEquals(FileStatus.MODIFIED, fileChange.getFileStatus());
    final Change dirChange = myChangeListManager.getChange(myWorkingCopyDir);
    Assert.assertNotNull(dirChange);
    Assert.assertEquals(FileStatus.MODIFIED, dirChange.getFileStatus());
    final SVNPropertyData data = myVcs.getSvnKitManager().createWCClient().doGetProperty(virtualToIoFile(myWorkingCopyDir), "svn:mergeinfo", UNDEFINED, WORKING);
    System.out.println(data.getValue().getString());
    Assert.assertEquals("/branches/b2:" + (numberBeforeCopy + 2), data.getValue().getString());
}
Also used : SVNPropertyData(org.tmatesoft.svn.core.wc.SVNPropertyData) SVNInfo(org.tmatesoft.svn.core.wc.SVNInfo) AtomicReference(java.util.concurrent.atomic.AtomicReference) Change(com.intellij.openapi.vcs.changes.Change) SmartList(com.intellij.util.SmartList) Test(org.junit.Test)

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