11
11
import com .intellij .psi .xml .XmlFile ;
12
12
import com .intellij .psi .xml .XmlTag ;
13
13
import io .github .linyimin .plugin .utils .MapperDomUtils ;
14
+ import org .apache .commons .lang3 .StringUtils ;
14
15
15
16
import java .util .*;
16
17
@@ -26,9 +27,11 @@ public class MybatisXmlContentCache {
26
27
27
28
private static final Map <Project , Map <String /* namespace */ , List <String > /* method name list */ >> projectMybatisMapperMap = new HashMap <>();
28
29
29
- private static final Map <Project , Map <String /* namespace */ , List <XmlTag >>> projectMapperNamespaceMap = new HashMap <>();
30
+ private static final Map <Project , Map <String /* namespace */ , Set <XmlTag >>> projectMapperNamespaceMap = new HashMap <>();
30
31
31
- private static final Map <Project , Map <String /* method qualified name */ , List <XmlTag >>> projectMapperMethodMap = new HashMap <>();
32
+ private static final Map <Project , Map <String /* method qualified name */ , Set <XmlTag >>> projectMapperMethodMap = new HashMap <>();
33
+
34
+ private static final Map <Project , Map <String /* method qualified name */ , String /* mapper xml string */ >> projectMethodToMapperFilePath = new HashMap <>();
32
35
33
36
34
37
public static List <String > acquireConfigurations (Project project ) {
@@ -48,22 +51,28 @@ public static List<String> acquireByNamespace(Project project) {
48
51
return new ArrayList <>(namespaces );
49
52
}
50
53
51
- public static List <XmlTag > acquireByNamespace (Project project , String namespace ) {
54
+ public static String acquireMapperPathByMethodName (Project project , String methodName ) {
55
+ addXmlCache (project );
56
+
57
+ return projectMethodToMapperFilePath .getOrDefault (project , new HashMap <>()).get (methodName );
58
+ }
59
+
60
+ public static Set <XmlTag > acquireByNamespace (Project project , String namespace ) {
52
61
53
62
addXmlCache (project );
54
63
55
- Map <String /* namespace */ , List <XmlTag >> cache = projectMapperNamespaceMap .getOrDefault (project , new HashMap <>());
64
+ Map <String /* namespace */ , Set <XmlTag >> cache = projectMapperNamespaceMap .getOrDefault (project , new HashMap <>());
56
65
57
- return cache .getOrDefault (namespace , new ArrayList <>());
66
+ return cache .getOrDefault (namespace , new HashSet <>());
58
67
}
59
68
60
- public static List <XmlTag > acquireByMethodName (Project project , String methodQualifiedName ) {
69
+ public static Set <XmlTag > acquireByMethodName (Project project , String methodQualifiedName ) {
61
70
62
71
addXmlCache (project );
63
72
64
- Map <String /* namespace */ , List <XmlTag >> cache = projectMapperMethodMap .getOrDefault (project , new HashMap <>());
73
+ Map <String /* namespace */ , Set <XmlTag >> cache = projectMapperMethodMap .getOrDefault (project , new HashMap <>());
65
74
66
- return cache .getOrDefault (methodQualifiedName , new ArrayList <>());
75
+ return cache .getOrDefault (methodQualifiedName , new HashSet <>());
67
76
}
68
77
69
78
private static void addXmlCache (Project project ) {
@@ -124,6 +133,8 @@ private static void addMapperCache(Project project, PsiFile psiFile) {
124
133
125
134
String id = subAttribute .getValue ();
126
135
136
+ addMethodToMapperCache (project , namespace , id , psiFile );
137
+
127
138
addMethodXmlTagCache (project , namespace , id , subTag );
128
139
129
140
addNamespaceCache (project , namespace , id );
@@ -132,11 +143,30 @@ private static void addMapperCache(Project project, PsiFile psiFile) {
132
143
133
144
}
134
145
146
+ private static void addMethodToMapperCache (Project project , String namespace , String id , PsiFile psiFile ) {
147
+ Map <String , String > methodCacheMap = projectMethodToMapperFilePath .getOrDefault (project , new HashMap <>());
148
+
149
+ String methodQualifiedName = namespace + "." + id ;
150
+
151
+ String path = psiFile .getVirtualFile ().getPath ();
152
+
153
+ if (StringUtils .isBlank (path )) {
154
+ return ;
155
+ }
156
+
157
+ path = path .substring (path .indexOf ("resources/" ) + "resources/" .length ());
158
+
159
+ methodCacheMap .put (methodQualifiedName , path );
160
+
161
+ projectMethodToMapperFilePath .put (project , methodCacheMap );
162
+
163
+ }
164
+
135
165
private static void addNamespaceXmlTagCache (Project project , String namespace , XmlTag xmlTag ) {
136
166
137
- Map <String , List <XmlTag >> namespaceCacheMap = projectMapperNamespaceMap .getOrDefault (project , new HashMap <>());
167
+ Map <String , Set <XmlTag >> namespaceCacheMap = projectMapperNamespaceMap .getOrDefault (project , new HashMap <>());
138
168
139
- List <XmlTag > tags = namespaceCacheMap .getOrDefault (namespace , new ArrayList <>());
169
+ Set <XmlTag > tags = namespaceCacheMap .getOrDefault (namespace , new HashSet <>());
140
170
tags .add (xmlTag );
141
171
142
172
namespaceCacheMap .put (namespace , tags );
@@ -147,11 +177,11 @@ private static void addNamespaceXmlTagCache(Project project, String namespace, X
147
177
148
178
private static void addMethodXmlTagCache (Project project , String namespace , String id , XmlTag xmlTag ) {
149
179
150
- Map <String , List <XmlTag >> methodCacheMap = projectMapperMethodMap .getOrDefault (project , new HashMap <>());
180
+ Map <String , Set <XmlTag >> methodCacheMap = projectMapperMethodMap .getOrDefault (project , new HashMap <>());
151
181
152
182
String methodQualifiedName = namespace + "." + id ;
153
183
154
- List <XmlTag > tags = methodCacheMap .getOrDefault (methodQualifiedName , new ArrayList <>());
184
+ Set <XmlTag > tags = methodCacheMap .getOrDefault (methodQualifiedName , new HashSet <>());
155
185
tags .add (xmlTag );
156
186
157
187
methodCacheMap .put (methodQualifiedName , tags );
0 commit comments