use of com.intellij.psi.util.CachedValueProvider in project android by JetBrains.
the class AndroidXmlSchemaProvider method getSchema.
@Override
public XmlFile getSchema(@NotNull @NonNls String url, @Nullable final Module module, @NotNull PsiFile baseFile) {
if (module == null || AndroidFacet.getInstance(module) == null)
return null;
Map<String, CachedValue<XmlFile>> descriptors = module.getUserData(DESCRIPTORS_MAP_IN_MODULE);
if (descriptors == null) {
descriptors = new THashMap<String, CachedValue<XmlFile>>();
module.putUserData(DESCRIPTORS_MAP_IN_MODULE, descriptors);
}
CachedValue<XmlFile> reference = descriptors.get(url);
if (reference != null) {
return reference.getValue();
}
CachedValuesManager manager = CachedValuesManager.getManager(module.getProject());
reference = manager.createCachedValue(new CachedValueProvider<XmlFile>() {
@Override
public Result<XmlFile> compute() {
final URL resource = AndroidXmlSchemaProvider.class.getResource("android.xsd");
final VirtualFile fileByURL = VfsUtil.findFileByURL(resource);
XmlFile result = (XmlFile) PsiManager.getInstance(module.getProject()).findFile(fileByURL).copy();
return new Result<XmlFile>(result, PsiModificationTracker.MODIFICATION_COUNT);
}
}, false);
descriptors.put(url, reference);
return reference.getValue();
}
use of com.intellij.psi.util.CachedValueProvider in project kotlin by JetBrains.
the class ProjectStructureUtil method getCachedPlatformForModule.
@NotNull
static /* package */
TargetPlatform getCachedPlatformForModule(@NotNull final Module module) {
CachedValue<TargetPlatform> result = module.getUserData(PLATFORM_FOR_MODULE);
if (result == null) {
result = CachedValuesManager.getManager(module.getProject()).createCachedValue(new CachedValueProvider<TargetPlatform>() {
@Override
public Result<TargetPlatform> compute() {
TargetPlatform configuredInFacet = getPlatformConfiguredInFacet(module);
TargetPlatform platform = configuredInFacet != null ? configuredInFacet : hasJsStandardLibraryInDependencies(module) ? JsPlatform.INSTANCE : JvmPlatform.INSTANCE;
return Result.create(platform, ProjectRootModificationTracker.getInstance(module.getProject()));
}
}, false);
module.putUserData(PLATFORM_FOR_MODULE, result);
}
return result.getValue();
}
use of com.intellij.psi.util.CachedValueProvider in project android by JetBrains.
the class ManifestInnerClass method getFields.
@NotNull
@Override
public PsiField[] getFields() {
if (myFieldsCache == null) {
myFieldsCache = CachedValuesManager.getManager(getProject()).createCachedValue(new CachedValueProvider<PsiField[]>() {
@Override
public Result<PsiField[]> compute() {
final Manifest manifest = myFacet.getManifest();
if (manifest == null) {
return Result.create(PsiField.EMPTY_ARRAY, PsiModificationTracker.MODIFICATION_COUNT);
}
final List<Pair<String, String>> pairs = doGetFields(manifest);
final PsiField[] result = new PsiField[pairs.size()];
final PsiClassType stringType = PsiType.getJavaLangString(myManager, GlobalSearchScope.allScope(getProject()));
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject());
int i = 0;
for (Pair<String, String> pair : pairs) {
final AndroidLightField field = new AndroidLightField(pair.getFirst(), ManifestInnerClass.this, stringType, true, pair.getSecond());
field.setInitializer(factory.createExpressionFromText("\"" + pair.getSecond() + "\"", field));
result[i++] = field;
}
final XmlElement xmlElement = manifest.getXmlElement();
final PsiFile psiManifestFile = xmlElement != null ? xmlElement.getContainingFile() : null;
return Result.create(result, psiManifestFile != null ? psiManifestFile : PsiModificationTracker.MODIFICATION_COUNT);
}
});
}
return myFieldsCache.getValue();
}
Aggregations