summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuriy Solodkyy <solodkyy@google.com>2022-07-01 18:28:05 +0100
committerTreeHugger Robot <treehugger-gerrit@google.com>2022-07-08 18:03:53 +0000
commitfeed154c2f93ce69a3127d41a383c6c9d78cd4e1 (patch)
tree0d9c02c5be9b3f9e9c107ba1ce9de1d3e98bef95
parent16cf3524adc9ceed4752b5b2c6df48a00605cbbe (diff)
downloadidea-feed154c2f93ce69a3127d41a383c6c9d78cd4e1.tar.gz
Make caching of Lint models simpler
`CacheValueManager` is unhappy about two different invocations with different `GradleAndroidModel`'s returning the same `LintModuleModel` without it being invalidated. It looks like there might be issues with sync updating models asynchronously. Do not depend on models and depend on a facet only. This will hide the problem with asynchronously updated models and cache any already built lint models until next sync. Bug: 237298753 Test: n/a (existing) Change-Id: I76dccf3cc7756c1cb1bd8335cb21e5c4461fa839
-rw-r--r--android-lint/src/com/android/tools/idea/lint/AndroidLintIdeProject.java23
1 files changed, 16 insertions, 7 deletions
diff --git a/android-lint/src/com/android/tools/idea/lint/AndroidLintIdeProject.java b/android-lint/src/com/android/tools/idea/lint/AndroidLintIdeProject.java
index 1dc68a26959..88c4dab016f 100644
--- a/android-lint/src/com/android/tools/idea/lint/AndroidLintIdeProject.java
+++ b/android-lint/src/com/android/tools/idea/lint/AndroidLintIdeProject.java
@@ -60,6 +60,7 @@ import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.util.CachedValueProvider;
+import com.intellij.psi.util.CachedValueProvider.Result;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.util.graph.Graph;
import java.io.File;
@@ -333,7 +334,7 @@ public class AndroidLintIdeProject extends LintIdeProject {
GradleAndroidModel model = (GradleAndroidModel)androidModel;
String variantName = model.getSelectedVariantName();
- LintModelModule lintModel = getLintModuleModel(facet, model, dir, shallowModel);
+ LintModelModule lintModel = getLintModuleModel(facet, shallowModel);
LintModelVariant variant = lintModel.findVariant(variantName);
if (variant == null) {
variant = lintModel.getVariants().get(0);
@@ -356,14 +357,22 @@ public class AndroidLintIdeProject extends LintIdeProject {
}
@NotNull
- private static LintModelModule getLintModuleModel(AndroidFacet facet, @NotNull GradleAndroidModel model, File dir, boolean shallowModel) {
+ private static LintModelModule getLintModuleModel(AndroidFacet facet, boolean shallowModel) {
final var project = facet.getModule().getProject();
final var cacheValueManager = CachedValuesManager.getManager(project);
- return cacheValueManager.getCachedValue(facet, () -> {
- IdeAndroidProject builderModelProject = model.getAndroidProject();
- LintModelModule module = new LintModelFactory().create(builderModelProject, model.getVariants(), dir, !shallowModel);
- return CachedValueProvider.Result.create(module, ProjectSyncModificationTracker.getInstance(project));
- });
+ return cacheValueManager.getCachedValue(facet, () -> buildModuleModel(facet, shallowModel));
+ }
+
+ @NotNull
+ private static Result<LintModelModule> buildModuleModel(AndroidFacet facet, boolean shallowModel) {
+ GradleAndroidModel model = GradleAndroidModel.get(facet);
+ if (model == null) throw new IllegalStateException("GradleAndroidModel not available for " + facet);
+ IdeAndroidProject builderModelProject = model.getAndroidProject();
+ String externalProjectPath = ExternalSystemApiUtil.getExternalProjectPath(facet.getModule());
+ if (externalProjectPath == null) throw new IllegalStateException("No external project path for " + facet.getModule());
+ File dir = new File(externalProjectPath);
+ LintModelModule module = new LintModelFactory().create(builderModelProject, model.getVariants(), dir, !shallowModel);
+ return Result.create(module, ProjectSyncModificationTracker.getInstance(facet.getModule().getProject()));
}
/**