Search in sources :

Example 1 with AtomicNotNullLazyValue

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

the class BuildTargetStorages method getOrCreateStorage.

@NotNull
public <S extends StorageOwner> S getOrCreateStorage(@NotNull final StorageProvider<S> provider) throws IOException {
    NotNullLazyValue<? extends StorageOwner> lazyValue = myStorages.get(provider);
    if (lazyValue == null) {
        AtomicNotNullLazyValue<S> newValue = new AtomicNotNullLazyValue<S>() {

            @NotNull
            @Override
            protected S compute() {
                try {
                    return provider.createStorage(myPaths.getTargetDataRoot(myTarget));
                } catch (IOException e) {
                    throw new BuildDataCorruptedException(e);
                }
            }
        };
        lazyValue = myStorages.putIfAbsent(provider, newValue);
        if (lazyValue == null) {
            // just initialized
            lazyValue = newValue;
        }
    }
    //noinspection unchecked
    try {
        return (S) lazyValue.getValue();
    } catch (BuildDataCorruptedException e) {
        throw e.getCause();
    }
}
Also used : BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) AtomicNotNullLazyValue(com.intellij.openapi.util.AtomicNotNullLazyValue) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AtomicNotNullLazyValue

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

the class StrutsConstantHelper method getActionExtensions.

/**
   * Returns the current action extension(s) ("{@code .action}").
   *
   * @param psiElement Invocation element.
   * @return empty list on configuration problems.
   */
@NotNull
public static List<String> getActionExtensions(@NotNull final PsiElement psiElement) {
    final PsiFile psiFile = psiElement.getContainingFile().getOriginalFile();
    CachedValue<AtomicNotNullLazyValue<List<String>>> extensions = psiFile.getUserData(KEY_ACTION_EXTENSIONS);
    if (extensions == null) {
        final Project project = psiElement.getProject();
        extensions = CachedValuesManager.getManager(project).createCachedValue(() -> {
            final AtomicNotNullLazyValue<List<String>> lazyValue = new AtomicNotNullLazyValue<List<String>>() {

                @NotNull
                @Override
                protected List<String> compute() {
                    final List<String> extensions1 = ApplicationManager.getApplication().runReadAction((NullableComputable<List<String>>) () -> StrutsConstantManager.getInstance(project).getConvertedValue(psiFile, StrutsCoreConstantContributor.ACTION_EXTENSION));
                    if (extensions1 == null) {
                        return Collections.emptyList();
                    }
                    return ContainerUtil.map(extensions1, DOT_PATH_FUNCTION);
                }
            };
            return CachedValueProvider.Result.create(lazyValue, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT);
        }, false);
        psiFile.putUserData(KEY_ACTION_EXTENSIONS, extensions);
    }
    return extensions.getValue().getValue();
}
Also used : Project(com.intellij.openapi.project.Project) AtomicNotNullLazyValue(com.intellij.openapi.util.AtomicNotNullLazyValue) PsiFile(com.intellij.psi.PsiFile) List(java.util.List) NullableComputable(com.intellij.openapi.util.NullableComputable) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AtomicNotNullLazyValue (com.intellij.openapi.util.AtomicNotNullLazyValue)2 NotNull (org.jetbrains.annotations.NotNull)2 Project (com.intellij.openapi.project.Project)1 NullableComputable (com.intellij.openapi.util.NullableComputable)1 PsiFile (com.intellij.psi.PsiFile)1 IOException (java.io.IOException)1 List (java.util.List)1 BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)1