use of com.android.ide.common.repository.ResourceVisibilityLookup in project kotlin by JetBrains.
the class PrivateResourceDetector method getLibraryName.
/** Pick a suitable name to describe the library defining the private resource */
@Nullable
private static String getLibraryName(@NonNull Context context, @NonNull ResourceType type, @NonNull String name) {
ResourceVisibilityLookup lookup = context.getProject().getResourceVisibility();
AndroidLibrary library = lookup.getPrivateIn(type, name);
if (library != null) {
String libraryName = library.getProject();
if (libraryName != null) {
return libraryName;
}
MavenCoordinates coordinates = library.getResolvedCoordinates();
if (coordinates != null) {
return coordinates.getGroupId() + ':' + coordinates.getArtifactId();
}
}
return "the library";
}
use of com.android.ide.common.repository.ResourceVisibilityLookup in project android by JetBrains.
the class AppResourceRepository method getResourceVisibility.
@NotNull
public ResourceVisibilityLookup getResourceVisibility(@NotNull AndroidFacet facet) {
// TODO: b/23032391
AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
if (androidModel != null) {
ResourceVisibilityLookup.Provider provider = getResourceVisibilityProvider();
if (provider != null) {
AndroidProject androidProject = androidModel.getAndroidProject();
Variant variant = androidModel.getSelectedVariant();
return provider.get(androidProject, variant);
}
}
return ResourceVisibilityLookup.NONE;
}
use of com.android.ide.common.repository.ResourceVisibilityLookup in project android by JetBrains.
the class AndroidJavaCompletionContributor method filterPrivateResources.
public void filterPrivateResources(@NotNull CompletionParameters parameters, @NotNull final CompletionResultSet resultSet, AndroidFacet facet) {
final ResourceVisibilityLookup lookup = AppResourceRepository.getAppResources(facet, true).getResourceVisibility(facet);
if (lookup.isEmpty()) {
return;
}
resultSet.runRemainingContributors(parameters, new Consumer<CompletionResult>() {
@Override
public void consume(CompletionResult result) {
final Object obj = result.getLookupElement().getObject();
if (obj instanceof PsiField) {
PsiField field = (PsiField) obj;
PsiClass containingClass = field.getContainingClass();
if (containingClass != null) {
PsiClass rClass = containingClass.getContainingClass();
if (rClass != null && rClass.getName().equals(R_CLASS)) {
ResourceType type = ResourceType.getEnum(containingClass.getName());
if (type != null && lookup.isPrivate(type, field.getName())) {
return;
}
}
}
}
resultSet.passResult(result);
}
});
}
use of com.android.ide.common.repository.ResourceVisibilityLookup in project android by JetBrains.
the class ResourceHelper method getCompletionFromTypes.
/**
* Returns the list of all resource names that can be used as a value for one of the {@link ResourceType} in completionTypes,
* optionally sorting/not sorting the results.
*/
@NotNull
public static List<String> getCompletionFromTypes(@NotNull AndroidFacet facet, @NotNull EnumSet<ResourceType> completionTypes, boolean sort) {
EnumSet<ResourceType> types = Sets.newEnumSet(completionTypes, ResourceType.class);
// Use drawables for mipmaps
if (types.contains(ResourceType.MIPMAP)) {
types.add(ResourceType.DRAWABLE);
} else if (types.contains(ResourceType.DRAWABLE)) {
types.add(ResourceType.MIPMAP);
}
boolean completionTypesContainsColor = types.contains(ResourceType.COLOR);
if (types.contains(ResourceType.DRAWABLE)) {
// The Drawable type accepts colors as value but not color state lists.
types.add(ResourceType.COLOR);
}
AppResourceRepository repository = AppResourceRepository.getAppResources(facet, true);
ResourceVisibilityLookup lookup = repository.getResourceVisibility(facet);
AndroidPlatform androidPlatform = AndroidPlatform.getInstance(facet.getModule());
FrameworkResources frameworkResources = null;
if (androidPlatform != null) {
AndroidTargetData targetData = androidPlatform.getSdkData().getTargetData(androidPlatform.getTarget());
try {
frameworkResources = targetData.getFrameworkResources(true);
} catch (IOException ignore) {
}
}
List<String> resources = Lists.newArrayListWithCapacity(500);
for (ResourceType type : types) {
// If type == ResourceType.COLOR, we want to include file resources (i.e. color state lists) only in the case where
// color was present in completionTypes, and not if we added it because of the presence of ResourceType.DRAWABLES.
// For any other ResourceType, we always include file resources.
boolean includeFileResources = (type != ResourceType.COLOR) || completionTypesContainsColor;
if (frameworkResources != null) {
addFrameworkItems(resources, type, includeFileResources, frameworkResources);
}
addProjectItems(resources, type, includeFileResources, repository, lookup);
}
if (sort) {
Collections.sort(resources, ResourceHelper::compareResourceReferences);
}
return resources;
}
Aggregations