Search in sources :

Example 1 with CreateFileResourceQuickFix

use of org.jetbrains.android.inspections.CreateFileResourceQuickFix in project android by JetBrains.

the class ResourceReferenceConverter method getQuickFixes.

@Override
public LocalQuickFix[] getQuickFixes(ConvertContext context) {
    AndroidFacet facet = AndroidFacet.getInstance(context);
    if (facet != null) {
        final DomElement domElement = context.getInvocationElement();
        if (domElement instanceof GenericDomValue) {
            final String value = ((GenericDomValue) domElement).getStringValue();
            if (value != null) {
                ResourceValue resourceValue = ResourceValue.parse(value, false, myWithPrefix, true);
                if (resourceValue != null) {
                    String aPackage = resourceValue.getNamespace();
                    ResourceType resType = resourceValue.getType();
                    if (resType == null && myResourceTypes.size() == 1) {
                        resType = myResourceTypes.iterator().next();
                    }
                    final String resourceName = resourceValue.getResourceName();
                    if (aPackage == null && resType != null && resourceName != null && AndroidResourceUtil.isCorrectAndroidResourceName(resourceName)) {
                        final List<LocalQuickFix> fixes = new ArrayList<>();
                        ResourceFolderType folderType = AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.get(resType);
                        if (folderType != null) {
                            fixes.add(new CreateFileResourceQuickFix(facet, folderType, resourceName, context.getFile(), false));
                        }
                        if (VALUE_RESOURCE_TYPES.contains(resType) && resType != ResourceType.LAYOUT) {
                            // layouts: aliases only
                            fixes.add(new CreateValueResourceQuickFix(facet, resType, resourceName, context.getFile(), false));
                        }
                        return fixes.toArray(new LocalQuickFix[fixes.size()]);
                    }
                }
            }
        }
    }
    return LocalQuickFix.EMPTY_ARRAY;
}
Also used : CreateValueResourceQuickFix(org.jetbrains.android.inspections.CreateValueResourceQuickFix) ResourceFolderType(com.android.resources.ResourceFolderType) ResourceValue(org.jetbrains.android.dom.resources.ResourceValue) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) ResourceType(com.android.resources.ResourceType) AndroidResourceType(org.jetbrains.android.dom.AndroidResourceType) CreateFileResourceQuickFix(org.jetbrains.android.inspections.CreateFileResourceQuickFix) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

ResourceFolderType (com.android.resources.ResourceFolderType)1 ResourceType (com.android.resources.ResourceType)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 AndroidResourceType (org.jetbrains.android.dom.AndroidResourceType)1 ResourceValue (org.jetbrains.android.dom.resources.ResourceValue)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 CreateFileResourceQuickFix (org.jetbrains.android.inspections.CreateFileResourceQuickFix)1 CreateValueResourceQuickFix (org.jetbrains.android.inspections.CreateValueResourceQuickFix)1