use of com.android.ide.common.res2.ResourceFile in project android by JetBrains.
the class LocalResourceRepository method getMatchingFiles.
@NonNull
public List<VirtualFile> getMatchingFiles(@NonNull VirtualFile file, @NonNull ResourceType type, @NonNull FolderConfiguration config) {
List<ResourceFile> matches = super.getMatchingFiles(ResourceHelper.getResourceName(file), type, config);
List<VirtualFile> matchesFiles = new ArrayList<VirtualFile>(matches.size());
for (ResourceFile match : matches) {
if (match != null) {
if (match instanceof PsiResourceFile) {
matchesFiles.add(((PsiResourceFile) match).getPsiFile().getVirtualFile());
} else {
matchesFiles.add(LocalFileSystem.getInstance().findFileByIoFile(match.getFile()));
}
}
}
return matchesFiles;
}
use of com.android.ide.common.res2.ResourceFile in project android by JetBrains.
the class ResourceFolderRepositoryTest method testMoveResourceFileBetweenDensityFolders.
public void testMoveResourceFileBetweenDensityFolders() throws Exception {
// Regression test for https://code.google.com/p/android/issues/detail?id=61648
// Make sure we flush resource values when reusing resource items incrementally
// Move a file-based resource file from one configuration to another; verify that
// items are preserved, generation changed (since it can affect config matching),
// and resource files updated.
final VirtualFile file1 = myFixture.copyFileToProject(DRAWABLE, "res/drawable-mdpi/picture.png");
final VirtualFile file2 = myFixture.copyFileToProject(DRAWABLE, "res/drawable-hdpi/dummy.ignore");
PsiFile psiFile1 = PsiManager.getInstance(getProject()).findFile(file1);
assertNotNull(psiFile1);
ResourceFolderRepository resources = createRepository();
assertNotNull(resources);
ResourceItem item = getOnlyItem(resources, ResourceType.DRAWABLE, "picture");
ResourceFile source = item.getSource();
assertNotNull(source);
assertEquals("mdpi", source.getQualifiers());
ResourceValue resourceValue = item.getResourceValue(false);
assertNotNull(resourceValue);
String valuePath = resourceValue.getValue().replace(File.separatorChar, '/');
assertTrue(valuePath, valuePath.endsWith("res/drawable-mdpi/picture.png"));
long generation = resources.getModificationCount();
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
try {
// Move file from one location to another
file1.move(this, file2.getParent());
} catch (IOException e) {
fail(e.toString());
}
}
});
assertTrue(generation < resources.getModificationCount());
assertTrue(resources.hasResourceItem(ResourceType.DRAWABLE, "picture"));
item = getOnlyItem(resources, ResourceType.DRAWABLE, "picture");
source = item.getSource();
assertNotNull(source);
assertEquals("hdpi", source.getQualifiers());
resourceValue = item.getResourceValue(false);
assertNotNull(resourceValue);
valuePath = resourceValue.getValue().replace(File.separatorChar, '/');
assertTrue(valuePath, valuePath.endsWith("res/drawable-hdpi/picture.png"));
}
Aggregations