use of com.android.ide.common.res2.ResourceItem in project android by JetBrains.
the class PsiResourceFile method removeItem.
@Override
public void removeItem(ResourceItem item) {
String key = item.getKey();
if (myDuplicates != null) {
Collection<ResourceItem> prev = myDuplicates.get(key);
if (prev != null && prev.contains(item)) {
myDuplicates.remove(key, item);
if (myDuplicates.isEmpty()) {
myDuplicates = null;
}
item.setSource(null);
return;
}
}
mItems.remove(key);
item.setSource(null);
// If we removed an item and we have duplicates in the wings, shift one of those into the prime position
if (myDuplicates != null) {
Collection<ResourceItem> prev = myDuplicates.get(key);
if (prev != null && !prev.isEmpty()) {
ResourceItem first = prev.iterator().next();
myDuplicates.remove(key, first);
mItems.put(key, first);
if (myDuplicates.isEmpty()) {
myDuplicates = null;
}
}
}
}
use of com.android.ide.common.res2.ResourceItem 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.ResourceItem 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.ResourceItem in project android by JetBrains.
the class LayoutDataBindingInfo method getViewsWithIds.
@Override
public List<ViewWithId> getViewsWithIds() {
Collection<ResourceItem> resourceItems = myPsiResourceFile.getItems();
List<ViewWithId> result = Lists.newArrayList();
for (ResourceItem item : resourceItems) {
if (!ResourceType.ID.equals(item.getType())) {
continue;
}
if (!(item instanceof PsiResourceItem)) {
continue;
}
PsiResourceItem psiResourceItem = (PsiResourceItem) item;
if (psiResourceItem.getTag() == null) {
continue;
}
String name = item.getName();
if (StringUtil.isEmpty(name)) {
continue;
}
result.add(new ViewWithId(DataBindingUtil.convertToJavaFieldName(name.trim()), psiResourceItem.getTag()));
}
return result;
}
use of com.android.ide.common.res2.ResourceItem in project android by JetBrains.
the class GradleDependencyManagerTest method ignore_testDependencyAarIsExplodedForLayoutLib.
@SuppressWarnings("unused")
public void ignore_testDependencyAarIsExplodedForLayoutLib() throws Exception {
loadSimpleApplication();
List<GradleCoordinate> dependencies = Collections.singletonList(RECYCLER_VIEW_DEPENDENCY);
GradleDependencyManager dependencyManager = GradleDependencyManager.getInstance(getProject());
assertThat(dependencyManager.findMissingDependencies(myModules.getAppModule(), dependencies)).isNotEmpty();
Messages.setTestDialog(new TestMessagesDialog(Messages.OK));
boolean found = dependencyManager.ensureLibraryIsIncluded(myModules.getAppModule(), dependencies, null);
assertThat(found).isTrue();
List<ResourceItem> items = AppResourceRepository.getAppResources(myAndroidFacet, true).getResourceItem(ResourceType.DECLARE_STYLEABLE, "RecyclerView");
assertThat(items).isNotEmpty();
assertThat(dependencyManager.findMissingDependencies(myModules.getAppModule(), dependencies)).isEmpty();
}
Aggregations