Search in sources :

Example 1 with UserDataHolder

use of com.intellij.openapi.util.UserDataHolder in project kotlin by JetBrains.

the class SlicedMapImpl method getSliceContents.

@NotNull
@Override
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
    ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
    for (Map.Entry<Object, UserDataHolderImpl> entry : map.entrySet()) {
        UserDataHolder holder = entry.getValue();
        V value = holder.getUserData(slice.getKey());
        if (value != null) {
            //noinspection unchecked
            builder.put((K) entry.getKey(), value);
        }
    }
    return builder.build();
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) THashMap(gnu.trove.THashMap) ImmutableMap(com.google.common.collect.ImmutableMap) UserDataHolder(com.intellij.openapi.util.UserDataHolder) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with UserDataHolder

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

the class ProjectFacetsConfigurator method getSharedModuleData.

private UserDataHolder getSharedModuleData(final Module module) {
    UserDataHolder dataHolder = mySharedModuleData.get(module);
    if (dataHolder == null) {
        dataHolder = new UserDataHolderBase();
        mySharedModuleData.put(module, dataHolder);
    }
    return dataHolder;
}
Also used : UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) UserDataHolder(com.intellij.openapi.util.UserDataHolder)

Example 3 with UserDataHolder

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

the class TextFilePatchInProgress method getDiffRequestProducers.

@NotNull
@Override
public DiffRequestProducer getDiffRequestProducers(final Project project, final PatchReader patchReader) {
    final PatchChange change = getChange();
    final FilePatch patch = getPatch();
    final String path = patch.getBeforeName() == null ? patch.getAfterName() : patch.getBeforeName();
    final Getter<CharSequence> baseContentGetter = new Getter<CharSequence>() {

        @Override
        public CharSequence get() {
            return patchReader.getBaseRevision(project, path);
        }
    };
    return new DiffRequestProducer() {

        @NotNull
        @Override
        public DiffRequest process(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException {
            if (myCurrentBase != null && myCurrentBase.getFileType() == UnknownFileType.INSTANCE) {
                return new UnknownFileTypeDiffRequest(myCurrentBase, getName());
            }
            if (isConflictingChange()) {
                final VirtualFile file = getCurrentBase();
                Getter<ApplyPatchForBaseRevisionTexts> getter = new Getter<ApplyPatchForBaseRevisionTexts>() {

                    @Override
                    public ApplyPatchForBaseRevisionTexts get() {
                        return ApplyPatchForBaseRevisionTexts.create(project, file, VcsUtil.getFilePath(file), getPatch(), baseContentGetter);
                    }
                };
                String afterTitle = getPatch().getAfterVersionId();
                if (afterTitle == null)
                    afterTitle = "Patched Version";
                return PatchDiffRequestFactory.createConflictDiffRequest(project, file, getPatch(), afterTitle, getter, getName(), context, indicator);
            } else {
                return PatchDiffRequestFactory.createDiffRequest(project, change, getName(), context, indicator);
            }
        }

        @NotNull
        @Override
        public String getName() {
            final File ioCurrentBase = getIoCurrentBase();
            return ioCurrentBase == null ? getCurrentPath() : ioCurrentBase.getPath();
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Getter(com.intellij.openapi.util.Getter) DiffRequestProducer(com.intellij.diff.chains.DiffRequestProducer) UnknownFileTypeDiffRequest(com.intellij.diff.requests.UnknownFileTypeDiffRequest) TextFilePatch(com.intellij.openapi.diff.impl.patch.TextFilePatch) FilePatch(com.intellij.openapi.diff.impl.patch.FilePatch) NotNull(org.jetbrains.annotations.NotNull) UserDataHolder(com.intellij.openapi.util.UserDataHolder) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with UserDataHolder

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

the class FactorTree method cache.

public void cache(GroovyClassDescriptor descriptor, CustomMembersHolder holder) {
    Map current = null;
    for (Factor factor : descriptor.affectingFactors) {
        Object key;
        switch(factor) {
            case placeElement:
                key = descriptor.getPlace();
                break;
            case placeFile:
                key = descriptor.getPlaceFile();
                break;
            case qualifierType:
                key = descriptor.getPsiType().getCanonicalText(false);
                break;
            default:
                throw new IllegalStateException("Unknown variant: " + factor);
        }
        if (current == null) {
            if (key instanceof UserDataHolder) {
                final Project project = descriptor.getProject();
                current = CachedValuesManager.getManager(project).getCachedValue((UserDataHolder) key, GDSL_MEMBER_CACHE, myProvider, false);
                continue;
            }
            current = myTopLevelCache.getValue();
        }
        Map next = (Map) current.get(key);
        if (next == null) {
            //noinspection unchecked
            current.put(key, next = ContainerUtil.newConcurrentMap());
            if (key instanceof String) {
                // type
                //noinspection unchecked
                current.put(CONTAINS_TYPE, true);
            }
        }
        current = next;
    }
    if (current == null)
        current = myTopLevelCache.getValue();
    //noinspection unchecked
    current.put(myExecutor, holder);
}
Also used : Project(com.intellij.openapi.project.Project) Map(java.util.Map) UserDataHolder(com.intellij.openapi.util.UserDataHolder)

Example 5 with UserDataHolder

use of com.intellij.openapi.util.UserDataHolder in project intellij-plugins by JetBrains.

the class DartResolveScopeProvider method getDartResolveScope.

@Nullable
private static GlobalSearchScope getDartResolveScope(@NotNull final Module module, @NotNull final VirtualFile pubspecFile, @Nullable final VirtualFile contextSubdir) {
    final Project project = module.getProject();
    final UserDataHolder dataHolder = contextSubdir != null ? PsiManager.getInstance(project).findDirectory(contextSubdir) : PsiManager.getInstance(project).findFile(pubspecFile);
    if (dataHolder == null) {
        // unlikely as contextSubdir and pubspecFile are checked to be in project
        return null;
    }
    return CachedValuesManager.getManager(project).getCachedValue(dataHolder, () -> {
        final Collection<VirtualFile> pathPackageRoots = getPathPackageRoots(module.getProject(), pubspecFile);
        final VirtualFile dartRoot = pubspecFile.getParent();
        final GlobalSearchScope scope;
        if (contextSubdir == null || "test".equals(contextSubdir.getName())) {
            // the biggest scope
            scope = createDirectoriesScope(project, pathPackageRoots, dartRoot);
        } else if ("lib".equals(contextSubdir.getName()) || PACKAGES_FOLDER_NAME.equals(contextSubdir.getName())) {
            // the smallest scope
            scope = createDirectoriesScope(project, pathPackageRoots, dartRoot.findChild("lib"), dartRoot.findChild(PACKAGES_FOLDER_NAME));
        } else {
            scope = createDirectoriesScope(project, pathPackageRoots, contextSubdir, dartRoot.findChild("lib"), dartRoot.findChild(PACKAGES_FOLDER_NAME));
        }
        final GlobalSearchScope scopeWithLibs = scope.intersectWith(GlobalSearchScope.projectScope(project)).union(getModuleLibrariesClassesScope(module));
        return new CachedValueProvider.Result<>(scopeWithLibs, PsiModificationTracker.MODIFICATION_COUNT);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) UserDataHolder(com.intellij.openapi.util.UserDataHolder) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

UserDataHolder (com.intellij.openapi.util.UserDataHolder)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 NotNull (org.jetbrains.annotations.NotNull)4 UnknownFileTypeDiffRequest (com.intellij.diff.requests.UnknownFileTypeDiffRequest)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Project (com.intellij.openapi.project.Project)3 File (java.io.File)3 DiffRequestProducerException (com.intellij.diff.chains.DiffRequestProducerException)2 DiffRequest (com.intellij.diff.requests.DiffRequest)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 Getter (com.intellij.openapi.util.Getter)2 FilePath (com.intellij.openapi.vcs.FilePath)2 Change (com.intellij.openapi.vcs.changes.Change)2 Map (java.util.Map)2 Nullable (org.jetbrains.annotations.Nullable)2 GoFile (com.goide.psi.GoFile)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 DiffRequestProducer (com.intellij.diff.chains.DiffRequestProducer)1 FilePatch (com.intellij.openapi.diff.impl.patch.FilePatch)1 TextFilePatch (com.intellij.openapi.diff.impl.patch.TextFilePatch)1