use of org.jetbrains.android.inspections.CreateValueResourceQuickFix in project android by JetBrains.
the class AndroidValueResourcesTest method doCreateValueResourceFromUsage.
private void doCreateValueResourceFromUsage(VirtualFile virtualFile) {
myFixture.configureFromExistingVirtualFile(virtualFile);
List<HighlightInfo> infos = myFixture.doHighlighting();
List<IntentionAction> actions = new ArrayList<>();
for (HighlightInfo info : infos) {
List<Pair<HighlightInfo.IntentionActionDescriptor, TextRange>> ranges = info.quickFixActionRanges;
if (ranges != null) {
for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : ranges) {
IntentionAction action = pair.getFirst().getAction();
if (action instanceof CreateValueResourceQuickFix) {
actions.add(action);
}
}
}
}
assertEquals(1, actions.size());
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
actions.get(0).invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
}
}.execute();
}
use of org.jetbrains.android.inspections.CreateValueResourceQuickFix 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;
}
use of org.jetbrains.android.inspections.CreateValueResourceQuickFix in project android by JetBrains.
the class AndroidLayoutDomTest method testCreateResourceFromUsage.
public void testCreateResourceFromUsage() throws Throwable {
VirtualFile virtualFile = copyFileToProject(getTestName(true) + ".xml");
myFixture.configureFromExistingVirtualFile(virtualFile);
List<HighlightInfo> infos = myFixture.doHighlighting();
List<IntentionAction> actions = new ArrayList<>();
for (HighlightInfo info : infos) {
List<Pair<HighlightInfo.IntentionActionDescriptor, TextRange>> ranges = info.quickFixActionRanges;
if (ranges != null) {
for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : ranges) {
IntentionAction action = pair.getFirst().getAction();
if (action instanceof CreateValueResourceQuickFix) {
actions.add(action);
}
}
}
}
assertEquals(1, actions.size());
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
actions.get(0).invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
}
}.execute();
myFixture.checkResultByFile("res/values/drawables.xml", myTestFolder + '/' + getTestName(true) + "_drawable_after.xml", true);
}
Aggregations