Search in sources :

Example 41 with SmartList

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

the class AddVariableInitializerFix method suggestInitializer.

@NotNull
public static LookupElement[] suggestInitializer(final PsiVariable variable) {
    PsiType type = variable.getType();
    final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(variable.getProject());
    final List<LookupElement> result = new SmartList<>();
    final String defaultValue = PsiTypesUtil.getDefaultValueOfType(type);
    final ExpressionLookupItem defaultExpression = new ExpressionLookupItem(elementFactory.createExpressionFromText(defaultValue, variable));
    result.add(defaultExpression);
    if (type instanceof PsiClassType) {
        final PsiClass aClass = PsiTypesUtil.getPsiClass(type);
        if (aClass != null && PsiUtil.hasDefaultConstructor(aClass)) {
            final String expressionText = PsiKeyword.NEW + " " + type.getCanonicalText(false) + "()";
            ExpressionLookupItem newExpression = new ExpressionLookupItem(elementFactory.createExpressionFromText(expressionText, variable));
            result.add(newExpression);
        }
    }
    return result.toArray(new LookupElement[result.size()]);
}
Also used : ExpressionLookupItem(com.intellij.codeInsight.lookup.ExpressionLookupItem) SmartList(com.intellij.util.SmartList) LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with SmartList

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

the class VirtualFilePointerManagerImpl method after.

@Override
public void after(@NotNull final List<? extends VFileEvent> events) {
    incModificationCount();
    for (FilePointerPartNode node : myNodesToUpdateUrl) {
        synchronized (this) {
            String urlBefore = node.myFileAndUrl.second;
            Pair<VirtualFile, String> after = node.update();
            assert after != null : "can't invalidate inside modification";
            String urlAfter = after.second;
            if (URL_COMPARATOR.compare(urlBefore, urlAfter) != 0 || !urlAfter.endsWith(node.part)) {
                List<VirtualFilePointerImpl> myPointers = new SmartList<>();
                node.addAllPointersTo(myPointers);
                // url has changed, reinsert
                int useCount = node.useCount;
                FilePointerPartNode root = node.remove();
                FilePointerPartNode newNode = root.findPointerOrCreate(VfsUtilCore.urlToPath(urlAfter), 0, after, myPointers.size());
                VirtualFilePointer existingPointer = newNode.getAnyPointer();
                if (existingPointer != null) {
                    // merge two pointers
                    for (FilePointerPartNode n = newNode; n != null; n = n.parent) {
                        n.pointersUnder += myPointers.size();
                    }
                }
                newNode.addAllPointersTo(myPointers);
                VirtualFilePointerImpl[] newMyPointers = myPointers.toArray(new VirtualFilePointerImpl[myPointers.size()]);
                newNode.associate(newMyPointers, after);
                newNode.incrementUsageCount(useCount);
            }
        }
    }
    VirtualFilePointer[] pointersToFireArray = toPointers(myNodesToFire);
    for (VirtualFilePointer pointer : pointersToFireArray) {
        ((VirtualFilePointerImpl) pointer).myNode.update();
    }
    for (EventDescriptor event : myEvents) {
        event.fireAfter();
    }
    if (pointersToFireArray.length != 0) {
        myBus.syncPublisher(VirtualFilePointerListener.TOPIC).validityChanged(pointersToFireArray);
    }
    myNodesToUpdateUrl = Collections.emptyList();
    myEvents = Collections.emptyList();
    myNodesToFire = Collections.emptyList();
    assertConsistency();
}
Also used : SmartList(com.intellij.util.SmartList) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 43 with SmartList

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

the class AbstractCollectionBinding method serialize.

@Nullable
@Override
public Object serialize(@NotNull Object o, @Nullable Object context, @Nullable SerializationFilter filter) {
    Collection<Object> collection = getIterable(o);
    String tagName = getTagName(o);
    if (tagName == null) {
        List<Object> result = new SmartList<Object>();
        if (!ContainerUtil.isEmpty(collection)) {
            for (Object item : collection) {
                ContainerUtil.addAllNotNull(result, serializeItem(item, result, filter));
            }
        }
        return result;
    } else {
        Element result = new Element(tagName);
        if (!ContainerUtil.isEmpty(collection)) {
            for (Object item : collection) {
                Content child = (Content) serializeItem(item, result, filter);
                if (child != null) {
                    result.addContent(child);
                }
            }
        }
        return result;
    }
}
Also used : Content(org.jdom.Content) Element(org.jdom.Element) SmartList(com.intellij.util.SmartList) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with SmartList

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

the class AbstractCollectionBinding method deserialize.

@Override
@NotNull
public Object deserialize(@Nullable Object context, @NotNull Element element) {
    Collection result;
    if (getTagName(context) == null) {
        if (context instanceof Collection) {
            result = (Collection) context;
            result.clear();
        } else {
            result = new SmartList();
        }
        //noinspection unchecked
        result.add(deserializeItem(element, context));
        if (result == context) {
            return result;
        }
    } else {
        result = deserializeSingle(context, element);
    }
    //noinspection unchecked
    return processResult(result, context);
}
Also used : Collection(java.util.Collection) AbstractCollection(com.intellij.util.xmlb.annotations.AbstractCollection) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with SmartList

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

the class ModuleManagerImpl method loadModules.

protected void loadModules(@NotNull ModuleModelImpl moduleModel) {
    myFailedModulePaths.clear();
    if (myModulePathsToLoad == null || myModulePathsToLoad.isEmpty()) {
        return;
    }
    myFailedModulePaths.addAll(myModulePathsToLoad);
    ProgressIndicator globalIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
    ProgressIndicator progressIndicator = myProject.isDefault() || globalIndicator == null ? new EmptyProgressIndicator() : globalIndicator;
    progressIndicator.setText("Loading modules...");
    progressIndicator.setText2("");
    List<Module> modulesWithUnknownTypes = new SmartList<>();
    List<ModuleLoadingErrorDescription> errors = Collections.synchronizedList(new ArrayList<>());
    ModuleGroupInterner groupInterner = new ModuleGroupInterner();
    ExecutorService service = AppExecutorUtil.createBoundedApplicationPoolExecutor("modules loader", JobSchedulerImpl.CORES_COUNT);
    List<Pair<Future<Module>, ModulePath>> tasks = new ArrayList<>();
    Set<String> paths = new THashSet<>();
    boolean parallel = Registry.is("parallel.modules.loading");
    for (ModulePath modulePath : myModulePathsToLoad) {
        if (progressIndicator.isCanceled()) {
            break;
        }
        try {
            String path = modulePath.getPath();
            if (!paths.add(path))
                continue;
            if (!parallel) {
                tasks.add(Pair.create(null, modulePath));
                continue;
            }
            ThrowableComputable<Module, IOException> computable = moduleModel.loadModuleInternal(path);
            Future<Module> future = service.submit(() -> {
                progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
                try {
                    return computable.compute();
                } catch (IOException e) {
                    reportError(errors, modulePath, e);
                } catch (Exception e) {
                    LOG.error(e);
                }
                return null;
            });
            tasks.add(Pair.create(future, modulePath));
        } catch (IOException e) {
            reportError(errors, modulePath, e);
        }
    }
    for (Pair<Future<Module>, ModulePath> task : tasks) {
        if (progressIndicator.isCanceled()) {
            break;
        }
        try {
            Module module;
            if (parallel) {
                module = task.first.get();
            } else {
                module = moduleModel.loadModuleInternal(task.second.getPath()).compute();
                progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
            }
            if (module == null)
                continue;
            if (isUnknownModuleType(module)) {
                modulesWithUnknownTypes.add(module);
            }
            ModulePath modulePath = task.second;
            final String groupPathString = modulePath.getGroup();
            if (groupPathString != null) {
                // model should be updated too
                groupInterner.setModuleGroupPath(moduleModel, module, groupPathString.split(MODULE_GROUP_SEPARATOR));
            }
            myFailedModulePaths.remove(modulePath);
        } catch (IOException e) {
            reportError(errors, task.second, e);
        } catch (Exception e) {
            LOG.error(e);
        }
    }
    service.shutdown();
    progressIndicator.checkCanceled();
    Application app = ApplicationManager.getApplication();
    if (app.isInternal() || app.isEAP() || ApplicationInfo.getInstance().getBuild().isSnapshot()) {
        Map<String, Module> track = new THashMap<>();
        for (Module module : moduleModel.getModules()) {
            for (String url : ModuleRootManager.getInstance(module).getContentRootUrls()) {
                Module oldModule = track.put(url, module);
                if (oldModule != null) {
                    //Map<String, VirtualFilePointer> track1 = ContentEntryImpl.track;
                    //VirtualFilePointer pointer = track1.get(url);
                    LOG.error("duplicated content url: " + url);
                }
            }
        }
    }
    onModuleLoadErrors(moduleModel, errors);
    showUnknownModuleTypeNotification(modulesWithUnknownTypes);
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) THashMap(gnu.trove.THashMap) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) SmartList(com.intellij.util.SmartList) Application(com.intellij.openapi.application.Application)

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