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();
}
}
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();
}
Aggregations