1
- package com .magento .idea .magento2plugin .xml ;
1
+ package com .magento .idea .magento2plugin .xml . di ;
2
2
3
3
import com .intellij .patterns .*;
4
4
import com .intellij .psi .PsiElement ;
5
5
import com .intellij .psi .PsiFile ;
6
+ import com .intellij .psi .xml .XmlAttribute ;
6
7
import com .intellij .psi .xml .XmlTag ;
7
8
import com .intellij .psi .xml .XmlTokenType ;
8
9
@@ -15,24 +16,24 @@ public class XmlHelper {
15
16
*/
16
17
public static XmlAttributeValuePattern getDiTypePattern () {
17
18
return XmlPatterns
18
- .xmlAttributeValue ()
19
- .withParent (
20
- XmlPatterns
21
- .xmlAttribute ("name" )
22
- .withParent (
23
- XmlPatterns
24
- .xmlTag ()
25
- .withName ("type" )
26
- )
27
- ).inside (
28
- XmlHelper .getInsideTagPattern ("type" )
29
- ).inFile (XmlHelper .getXmlFilePattern ());
19
+ .xmlAttributeValue ()
20
+ .withParent (
21
+ XmlPatterns
22
+ .xmlAttribute ("name" )
23
+ .withParent (
24
+ XmlPatterns
25
+ .xmlTag ()
26
+ .withName ("type" )
27
+ )
28
+ ).inside (
29
+ XmlHelper .getInsideTagPattern ("type" )
30
+ ).inFile (XmlHelper .getXmlFilePattern ());
30
31
}
31
32
32
33
/**
33
34
* <preference type="\Namespace\Class">
34
35
*/
35
- public static XmlAttributeValuePattern getDiPreferencePattern () {
36
+ public static XmlAttributeValuePattern getDiPreferenceTypePattern () {
36
37
return XmlPatterns
37
38
.xmlAttributeValue ()
38
39
.withParent (
@@ -48,6 +49,44 @@ public static XmlAttributeValuePattern getDiPreferencePattern() {
48
49
).inFile (XmlHelper .getXmlFilePattern ());
49
50
}
50
51
52
+ /**
53
+ * <preference for="\Namespace\Type">
54
+ */
55
+ public static XmlAttributeValuePattern getDiPreferenceForPattern () {
56
+ return XmlPatterns
57
+ .xmlAttributeValue ()
58
+ .withParent (
59
+ XmlPatterns
60
+ .xmlAttribute ("for" )
61
+ .withParent (
62
+ XmlPatterns
63
+ .xmlTag ()
64
+ .withName ("preference" )
65
+ )
66
+ ).inside (
67
+ XmlHelper .getInsideTagPattern ("preference" )
68
+ ).inFile (XmlHelper .getXmlFilePattern ());
69
+ }
70
+
71
+ /**
72
+ * <virtualType type="\Namespace\Class">
73
+ */
74
+ public static XmlAttributeValuePattern getDiVirtualTypePattern () {
75
+ return XmlPatterns
76
+ .xmlAttributeValue ()
77
+ .withParent (
78
+ XmlPatterns
79
+ .xmlAttribute ("type" )
80
+ .withParent (
81
+ XmlPatterns
82
+ .xmlTag ()
83
+ .withName ("virtualType" )
84
+ )
85
+ ).inside (
86
+ XmlHelper .getInsideTagPattern ("virtualType" )
87
+ ).inFile (XmlHelper .getXmlFilePattern ());
88
+ }
89
+
51
90
/**
52
91
* <argument name="argumentName" xsi:type="object">\Namespace\Class</argument>
53
92
*/
@@ -82,46 +121,34 @@ public static PsiElementPattern.Capture<PsiElement> getItemObjectPattern() {
82
121
).inFile (XmlHelper .getXmlFilePattern ());
83
122
}
84
123
85
- /**
86
- * <virtualType type="\Namespace\Class">
87
- */
88
- public static XmlAttributeValuePattern getDiVirtualTypePattern () {
89
- return XmlPatterns
90
- .xmlAttributeValue ()
91
- .withParent (
92
- XmlPatterns
93
- .xmlAttribute ("type" )
94
- .withParent (
95
- XmlPatterns
96
- .xmlTag ()
97
- .withName ("virtualType" )
98
- )
99
- ).inside (
100
- XmlHelper .getInsideTagPattern ("virtualType" )
101
- ).inFile (XmlHelper .getXmlFilePattern ());
102
- }
103
-
104
124
public static PsiFilePattern .Capture <PsiFile > getXmlFilePattern () {
105
125
return XmlPatterns .psiFile ()
106
- .withName (XmlPatterns
107
- .string ().endsWith (".xml" )
108
- );
126
+ .withName (XmlPatterns .string ().equalTo ("di.xml" ));
109
127
}
110
128
111
129
public static PsiElementPattern .Capture <XmlTag > getInsideTagPattern (String insideTagName ) {
112
130
return XmlPatterns .psiElement (XmlTag .class ).withName (insideTagName );
113
131
}
114
132
115
- public static PsiElementPattern .Capture <PsiElement > getTagPattern (String ... tags ) {
133
+ /**
134
+ * <tag attributeNames="|"/>
135
+ *
136
+ * @param tag tagname
137
+ * @param attributeNames attribute values listen for
138
+ */
139
+ public static PsiElementPattern .Capture <PsiElement > getTagAttributePattern (String tag , String ... attributeNames ) {
116
140
return XmlPatterns
117
141
.psiElement ()
118
142
.inside (XmlPatterns
119
143
.xmlAttributeValue ()
120
144
.inside (XmlPatterns
121
145
.xmlAttribute ()
122
- .withName (StandardPatterns .string ().oneOfIgnoreCase (tags )
146
+ .withName (StandardPatterns .string ().oneOfIgnoreCase (attributeNames ))
147
+ .withParent (XmlPatterns
148
+ .xmlTag ()
149
+ .withName (tag )
123
150
)
124
151
)
125
- );
152
+ ). inFile ( getXmlFilePattern ()) ;
126
153
}
127
154
}
0 commit comments