use of com.android.ide.common.res2.ResourceFile in project kotlin by JetBrains.
the class ViewTypeDetector method getViewTags.
@Nullable
protected Collection<String> getViewTags(@NonNull Context context, @NonNull ResourceItem item) {
// Check view tag in this file. Can I do it cheaply? Try with
// an XML pull parser. Or DOM if we have multiple resources looked
// up?
ResourceFile source = item.getSource();
if (source != null) {
File file = source.getFile();
Multimap<String, String> map = getIdToTagsIn(context, file);
if (map != null) {
return map.get(item.getName());
}
}
return null;
}
use of com.android.ide.common.res2.ResourceFile in project kotlin by JetBrains.
the class LayoutInflationDetector method hasLayoutParams.
private static boolean hasLayoutParams(@NonNull JavaContext context, String name) {
LintClient client = context.getClient();
if (!client.supportsProjectResources()) {
// not certain
return true;
}
Project project = context.getProject();
AbstractResourceRepository resources = client.getProjectResources(project, true);
if (resources == null) {
// not certain
return true;
}
List<ResourceItem> items = resources.getResourceItem(ResourceType.LAYOUT, name);
if (items == null || items.isEmpty()) {
return false;
}
for (ResourceItem item : items) {
ResourceFile source = item.getSource();
if (source == null) {
// not certain
return true;
}
File file = source.getFile();
if (file.exists()) {
try {
String s = context.getClient().readFile(file);
if (hasLayoutParams(new StringReader(s))) {
return true;
}
} catch (Exception e) {
context.log(e, "Could not read/parse inflated layout");
// not certain
return true;
}
}
}
return false;
}
use of com.android.ide.common.res2.ResourceFile in project android by JetBrains.
the class PsiResourceItem method getSource.
@Nullable
@Override
public ResourceFile getSource() {
ResourceFile source = super.getSource();
// Temporary safety workaround
if (source == null && myFile != null && myFile.getParent() != null) {
PsiDirectory parent = myFile.getParent();
if (parent != null) {
String name = parent.getName();
ResourceFolderType folderType = ResourceFolderType.getFolderType(name);
FolderConfiguration configuration = FolderConfiguration.getConfigForFolder(name);
int index = name.indexOf('-');
String qualifiers = index == -1 ? "" : name.substring(index + 1);
source = new PsiResourceFile(myFile, Collections.<ResourceItem>singletonList(this), qualifiers, folderType, configuration);
setSource(source);
}
}
return source;
}
use of com.android.ide.common.res2.ResourceFile in project android by JetBrains.
the class LocalResourceRepository method getItemPsiFile.
/** Returns the {@link PsiFile} corresponding to the source of the given resource item, if possible */
@Nullable
public static PsiFile getItemPsiFile(@NonNull Project project, @NonNull ResourceItem item) {
if (project.isDisposed()) {
return null;
}
if (item instanceof PsiResourceItem) {
PsiResourceItem psiResourceItem = (PsiResourceItem) item;
return psiResourceItem.getPsiFile();
}
ResourceFile source = item.getSource();
if (source == null) {
// most likely a dynamically defined value
return null;
}
if (source instanceof PsiResourceFile) {
PsiResourceFile prf = (PsiResourceFile) source;
return prf.getPsiFile();
}
File file = source.getFile();
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (virtualFile != null) {
PsiManager psiManager = PsiManager.getInstance(project);
return psiManager.findFile(virtualFile);
}
return null;
}
use of com.android.ide.common.res2.ResourceFile in project android by JetBrains.
the class ConfiguredThemeEditorStyle method getConfiguredValues.
/**
* Returns all the style attributes and its values. For each attribute, multiple {@link ConfiguredElement} can be returned
* representing the multiple values in different configurations for each item.
* TODO: needs to be deleted, as we don't use this method except tests
*/
@NotNull
public ImmutableCollection<ConfiguredElement<ItemResourceValue>> getConfiguredValues() {
// Get a list of all the items indexed by the item name. Each item contains a list of the
// possible values in this theme in different configurations.
//
// If item1 has multiple values in different configurations, there will be an
// item1 = {folderConfiguration1 -> value1, folderConfiguration2 -> value2}
final ImmutableList.Builder<ConfiguredElement<ItemResourceValue>> itemResourceValues = ImmutableList.builder();
if (isFramework()) {
assert myConfiguration.getFrameworkResources() != null;
com.android.ide.common.resources.ResourceItem styleItem = myConfiguration.getFrameworkResources().getResourceItem(ResourceType.STYLE, myStyleResourceValue.getName());
// Go over all the files containing the resource.
for (ResourceFile file : styleItem.getSourceFileList()) {
ResourceValue styleResourceValue = file.getValue(ResourceType.STYLE, styleItem.getName());
FolderConfiguration folderConfiguration = file.getConfiguration();
if (styleResourceValue instanceof StyleResourceValue) {
for (final ItemResourceValue value : ((StyleResourceValue) styleResourceValue).getValues()) {
itemResourceValues.add(ConfiguredElement.create(folderConfiguration, value));
}
}
}
} else {
for (ResourceItem styleDefinition : getStyleResourceItems()) {
ResourceValue styleResourceValue = styleDefinition.getResourceValue(isFramework());
FolderConfiguration folderConfiguration = styleDefinition.getConfiguration();
if (styleResourceValue instanceof StyleResourceValue) {
for (final ItemResourceValue value : ((StyleResourceValue) styleResourceValue).getValues()) {
// We use the qualified name since apps and libraries can use the same attribute name twice with and without "android:"
itemResourceValues.add(ConfiguredElement.create(folderConfiguration, value));
}
}
}
}
return itemResourceValues.build();
}
Aggregations