forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXmlModuleNameQuickFix.java
59 lines (49 loc) · 1.75 KB
/
XmlModuleNameQuickFix.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.inspections.xml.fix;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.project.Project;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
import org.jetbrains.annotations.NotNull;
public class XmlModuleNameQuickFix implements LocalQuickFix {
private final String expectedModuleName;
public XmlModuleNameQuickFix(final String expectedModuleName) {
this.expectedModuleName = expectedModuleName;
}
@NotNull
@Override
public String getFamilyName() {
final InspectionBundle inspectionBundle = new InspectionBundle();
return inspectionBundle.message(
"inspection.moduleDeclaration.fix"
);
}
@Override
public void applyFix(
@NotNull final Project project,
@NotNull final ProblemDescriptor descriptor
) {
final XmlAttributeValue value = (XmlAttributeValue) descriptor.getPsiElement();
applyFix(value);
}
private void applyFix(final XmlAttributeValue value) {
WriteCommandAction.writeCommandAction(
value.getManager().getProject(),
value.getContainingFile()
).run(() ->
doFix(value)
);
}
protected void doFix(
final XmlAttributeValue value
) {
final XmlAttribute xmlAttribute = (XmlAttribute) value.getParent();
xmlAttribute.setValue(expectedModuleName);
}
}