use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class CreateResourceFileAction method getActionByDir.
private CreateTypedResourceFileAction getActionByDir(PsiDirectory directory) {
String baseDirName = directory.getName();
ResourceFolderType folderType = ResourceFolderType.getFolderType(baseDirName);
if (folderType == null) {
return null;
}
return mySubactions.get(folderType);
}
use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class CreateResourceFileDialogBase method setupSubActions.
protected String setupSubActions(@NotNull Collection<CreateTypedResourceFileAction> actions, @NotNull TemplateKindCombo resourceTypeCombo, @Nullable ResourceFolderType folderType) {
CreateTypedResourceFileAction[] actionArray = actions.toArray(new CreateTypedResourceFileAction[actions.size()]);
Arrays.sort(actionArray, (a1, a2) -> a1.toString().compareTo(a2.toString()));
String selectedTemplate = null;
for (CreateTypedResourceFileAction action : actionArray) {
ResourceFolderType resType = action.getResourceFolderType();
assert !myResType2ActionMap.containsKey(resType);
myResType2ActionMap.put(resType, action);
resourceTypeCombo.addItem(action.toString(), null, resType.getName());
if (folderType != null && folderType == resType) {
selectedTemplate = resType.getName();
}
}
return selectedTemplate;
}
use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class UnusedResourcesProcessor method computeUnusedDeclarationElements.
@NotNull
private List<PsiElement> computeUnusedDeclarationElements(Map<Issue, Map<File, List<ProblemData>>> map) {
final List<PsiElement> elements = Lists.newArrayList();
// Make sure lint didn't put extra issues into the map
for (Issue issue : Lists.newArrayList(map.keySet())) {
if (issue != UnusedResourceDetector.ISSUE && issue != UnusedResourceDetector.ISSUE_IDS) {
map.remove(issue);
}
}
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiManager manager = PsiManager.getInstance(myProject);
for (Issue issue : new Issue[] { UnusedResourceDetector.ISSUE, UnusedResourceDetector.ISSUE_IDS }) {
Map<File, List<ProblemData>> fileListMap = map.get(issue);
if (fileListMap != null && !fileListMap.isEmpty()) {
Map<File, PsiFile> files = Maps.newHashMap();
for (File file : fileListMap.keySet()) {
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (virtualFile != null) {
if (!virtualFile.isDirectory()) {
// Gradle model errors currently don't have source positions
PsiFile psiFile = manager.findFile(virtualFile);
if (psiFile != null) {
files.put(file, psiFile);
}
}
}
}
if (!files.isEmpty()) {
for (File file : files.keySet()) {
PsiFile psiFile = files.get(file);
if (psiFile == null) {
// where we only had the project directory as the location from the Gradle model
continue;
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, psiFile)) {
continue;
}
List<ProblemData> problems = fileListMap.get(file);
if (psiFile.getFileType().isBinary()) {
// Delete the whole file
if (matchesFilter(fileListMap, file)) {
elements.add(psiFile);
}
} else {
ResourceFolderType folderType = ResourceHelper.getFolderType(psiFile);
if (folderType == null) {
// file; see for example http://b.android.com/220069.)
if (psiFile.getFileType() == GroovyFileType.GROOVY_FILE_TYPE && psiFile instanceof GroovyFile) {
((GroovyFile) psiFile).accept(new GroovyRecursiveElementVisitor() {
@Override
public void visitApplicationStatement(GrApplicationStatement applicationStatement) {
super.visitApplicationStatement(applicationStatement);
PsiMethod method = applicationStatement.resolveMethod();
if (method != null && method.getName().equals("resValue")) {
GrExpression[] args = applicationStatement.getArgumentList().getExpressionArguments();
if (args.length >= 3) {
Object typeString = GroovyConstantExpressionEvaluator.evaluate(args[0]);
Object nameString = GroovyConstantExpressionEvaluator.evaluate(args[1]);
// See if this is one of the unused resources
if (typeString != null && nameString != null) {
List<ProblemData> problems = fileListMap.get(VfsUtilCore.virtualToIoFile(psiFile.getVirtualFile()));
if (problems != null) {
for (ProblemData problem : problems) {
String unusedResource = UnusedResourceDetector.getUnusedResource(problem.getMessage(), TextFormat.RAW);
if (unusedResource != null && unusedResource.equals(SdkConstants.R_PREFIX + typeString + '.' + nameString)) {
elements.add(applicationStatement);
}
}
}
}
}
}
}
});
}
continue;
}
if (folderType != ResourceFolderType.VALUES) {
// also being deleted as unused
if (issue == UnusedResourceDetector.ISSUE_IDS) {
Map<File, List<ProblemData>> m = map.get(UnusedResourceDetector.ISSUE);
if (m != null && m.containsKey(file)) {
// Yes - skip
continue;
}
// Delete ranges within the file
addElementsInFile(elements, psiFile, problems);
} else {
// Unused non-value resource file: Delete the whole file
if (matchesFilter(fileListMap, file)) {
elements.add(psiFile);
}
}
} else {
addElementsInFile(elements, psiFile, problems);
}
}
}
}
}
}
return elements;
}
use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class ResourceMergerTreeStructureProvider method mergeResourceDirectories.
private static Collection<AbstractTreeNode> mergeResourceDirectories(Collection<AbstractTreeNode> children, ViewSettings settings) {
List<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
Map<ResourceFolderType, ResourceDirectoryNode> resourceDirectories = new HashMap<ResourceFolderType, ResourceDirectoryNode>();
for (AbstractTreeNode child : children) {
if (!(child instanceof PsiDirectoryNode)) {
result.add(child);
continue;
}
PsiDirectoryNode directoryNode = (PsiDirectoryNode) child;
PsiDirectory directory = directoryNode.getValue();
ResourceFolderType type = ResourceFolderType.getFolderType(directory.getName());
if (type == null) {
result.add(child);
continue;
}
ResourceDirectoryNode node = resourceDirectories.get(type);
if (node == null || !directory.getName().contains("-")) {
node = new ResourceDirectoryNode(directoryNode.getProject(), directoryNode, settings);
resourceDirectories.put(type, node);
}
}
for (ResourceDirectoryNode node : resourceDirectories.values()) {
node.collectChildren();
result.add(node);
}
return result;
}
use of com.android.resources.ResourceFolderType in project android by JetBrains.
the class AndroidEditorTitleProvider method getEditorTabTitle.
@Nullable
@Override
public String getEditorTabTitle(Project project, VirtualFile file) {
if (DumbService.isDumb(project)) {
return null;
}
if (file.getFileType() != StdFileTypes.XML) {
return null;
}
// Resource file?
if (file.getName().equals(FN_ANDROID_MANIFEST_XML)) {
return null;
}
VirtualFile parent = file.getParent();
if (parent == null) {
return null;
}
String parentName = parent.getName();
int index = parentName.indexOf('-');
if (index == -1 || index == parentName.length() - 1) {
return null;
}
ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName);
if (folderType == null) {
return null;
}
return parentName.substring(index + 1) + File.separator + file.getPresentableName();
}
Aggregations