use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class ProjectResourceCachedValueProvider method compute.
@Nullable
@Override
public final Result<T> compute() {
AndroidFacet[] facets = myComponent.getDataBindingEnabledFacets();
List<V> values = Lists.newArrayList();
List<ModificationTracker> newDependencies = Lists.newArrayList();
newDependencies.add(myComponent);
Collections.addAll(newDependencies, myAdditionalTrackers);
for (AndroidFacet facet : facets) {
CachedValue<V> cachedValue = getCachedValue(facet);
// we know this for sure since it is created from createCacheProvider
if (cachedValue.getValueProvider() instanceof ModificationTracker) {
newDependencies.add((ModificationTracker) cachedValue.getValueProvider());
}
V result = cachedValue.getValue();
if (result != null) {
values.add(result);
}
}
myDependencies = Collections.unmodifiableList(newDependencies);
myDependencyModificationCountOnCompute = calculateModificationCountFrom(myDependencies);
return Result.create(merge(values), this);
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class DependenciesModuleSetupStep method updateDependency.
private static void updateDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull JavaModuleDependency dependency) {
DependencySetupErrors setupErrors = DependencySetupErrors.getInstance(module.getProject());
String moduleName = dependency.getModuleName();
Module found = null;
for (Module m : modelsProvider.getModules()) {
if (moduleName.equals(m.getName())) {
found = m;
}
}
ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
if (found != null) {
AndroidFacet androidFacet = findFacet(found, modelsProvider, AndroidFacet.ID);
if (androidFacet == null) {
ModuleOrderEntry entry = moduleModel.addModuleOrderEntry(found);
entry.setExported(true);
} else {
// If it depends on an android module, we should skip that.
setupErrors.addInvalidModuleDependency(moduleModel.getModule(), found.getName(), "Java modules cannot depend on Android modules");
}
return;
}
setupErrors.addMissingModule(moduleName, module.getName(), null);
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AndroidLintConvertToWebpInspection method getQuickFixes.
@Override
@NotNull
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
return new AndroidLintQuickFix[] { new DefaultLintQuickFix("Convert images to WebP...") {
@Override
public boolean isApplicable(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.ContextType contextType) {
return AndroidFacet.getInstance(startElement) != null;
}
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
AndroidFacet facet = AndroidFacet.getInstance(startElement);
if (facet != null) {
AndroidModuleInfo info = AndroidModuleInfo.get(facet);
int minSdkVersion = info.getMinSdkVersion().getApiLevel();
List<VirtualFile> folders = facet.getResourceFolderManager().getFolders();
ConvertToWebpAction action = new ConvertToWebpAction();
action.perform(startElement.getProject(), minSdkVersion, folders.toArray(VirtualFile.EMPTY_ARRAY));
}
}
} };
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class BuildVariantUpdater method updateSelectedVariant.
/**
* Updates a module's structure when the user selects a build variant from the tool window.
*
* @param project the module's project.
* @param moduleName the module's name.
* @param buildVariantName the name of the selected build variant.
* @return {@code true} if the module update was successful, {@code false} otherwise.
*/
boolean updateSelectedVariant(@NotNull Project project, @NotNull String moduleName, @NotNull String buildVariantName) {
List<AndroidFacet> affectedAndroidFacets = new ArrayList<>();
List<NdkFacet> affectedNdkFacets = new ArrayList<>();
executeProjectChanges(project, () -> {
Module updatedModule = doUpdate(project, moduleName, buildVariantName, affectedAndroidFacets, affectedNdkFacets);
if (updatedModule != null) {
ConflictSet conflicts = findConflicts(project);
conflicts.showSelectionConflicts();
}
PostSyncProjectSetup.Request setupRequest = new PostSyncProjectSetup.Request();
setupRequest.setGenerateSourcesAfterSync(false).setCleanProjectAfterSync(false);
PostSyncProjectSetup.getInstance(project).setUpProject(setupRequest, null);
generateSourcesIfNeeded(affectedAndroidFacets);
});
return !affectedAndroidFacets.isEmpty() || !affectedNdkFacets.isEmpty();
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class BuildVariantView method updateContents.
public void updateContents() {
GradleSyncState syncState = GradleSyncState.getInstance(myProject);
if (syncState.isSyncInProgress() && !syncState.isSyncSkipped()) {
projectImportStarted();
return;
}
final List<Object[]> rows = Lists.newArrayList();
final List<BuildVariantItem[]> variantNamesPerRow = Lists.newArrayList();
for (Module module : getGradleModulesWithAndroidProjects()) {
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
NdkFacet ndkFacet = NdkFacet.getInstance(module);
// getGradleModules() returns only relevant modules.
assert androidFacet != null || ndkFacet != null;
String variantName = null;
if (androidFacet != null) {
JpsAndroidModuleProperties facetProperties = androidFacet.getProperties();
variantName = facetProperties.SELECTED_BUILD_VARIANT;
}
BuildVariantItem[] variantNames = getVariantItems(module);
if (variantNames != null) {
if (androidFacet != null) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
// AndroidModel may be null when applying a quick fix (e.g. "Fix Gradle version")
if (androidModel != null) {
variantName = androidModel.getSelectedVariant().getName();
}
} else {
// As only the modules backed by either AndroidGradleModel or NativeAndroidGradleModel are shown in the Build Variants View,
// when a module is not backed by AndroidGradleModel, it surely contains a valid NativeAndroidGradleModel.
NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
if (ndkModuleModel != null) {
variantName = ndkModuleModel.getSelectedVariant().getName();
}
}
variantNamesPerRow.add(variantNames);
}
if (variantName != null) {
Object[] row = { module, variantName };
rows.add(row);
}
}
Runnable setModelTask = () -> getVariantsTable().setModel(rows, variantNamesPerRow);
Application application = ApplicationManager.getApplication();
if (application.isDispatchThread()) {
setModelTask.run();
} else {
application.invokeLater(setModelTask);
}
}
Aggregations