2
2
3
3
import com .intellij .lang .annotation .AnnotationHolder ;
4
4
import com .intellij .lang .annotation .Annotator ;
5
- import com .intellij .openapi .project .Project ;
6
5
import com .intellij .psi .PsiElement ;
7
- import com .intellij .psi .PsiFile ;
8
- import com .intellij .psi .search .GlobalSearchScope ;
9
- import com .intellij .util .indexing .FileBasedIndex ;
10
6
import fr .adrienbrault .idea .symfony2plugin .Settings ;
11
7
import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
12
8
import fr .adrienbrault .idea .symfony2plugin .TwigHelper ;
13
9
import fr .adrienbrault .idea .symfony2plugin .asset .dic .AssetDirectoryReader ;
14
10
import fr .adrienbrault .idea .symfony2plugin .asset .dic .AssetFile ;
15
11
import fr .adrienbrault .idea .symfony2plugin .routing .PhpRoutingAnnotator ;
16
- import fr .adrienbrault .idea .symfony2plugin .stubs .indexes .YamlTranslationStubIndex ;
17
12
import fr .adrienbrault .idea .symfony2plugin .templating .assets .TwigNamedAssetsServiceParser ;
18
13
import fr .adrienbrault .idea .symfony2plugin .templating .util .TwigUtil ;
19
- import fr .adrienbrault .idea .symfony2plugin .translation .TranslationKeyIntentionAndQuickFixAction ;
20
- import fr .adrienbrault .idea .symfony2plugin .translation .dict .TranslationUtil ;
21
14
import fr .adrienbrault .idea .symfony2plugin .util .service .ServiceXmlParserFactory ;
22
15
import org .apache .commons .lang .StringUtils ;
23
16
import org .jetbrains .annotations .NotNull ;
24
17
25
- import java .util .Collection ;
26
- import java .util .List ;
27
18
import java .util .Set ;
28
- import java .util .stream .Collectors ;
29
19
30
20
/**
31
21
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -54,30 +44,6 @@ public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolde
54
44
if (Settings .getInstance (element .getProject ()).twigAnnotateTemplate ) {
55
45
this .annotateTemplate (element , holder );
56
46
}
57
-
58
- this .annotateTranslationKey (element , holder );
59
- }
60
-
61
- private void annotateTranslationKey (@ NotNull PsiElement psiElement , @ NotNull AnnotationHolder holder ) {
62
- if (!TwigHelper .getTranslationPattern ("trans" , "transchoice" ).accepts (psiElement )) {
63
- return ;
64
- }
65
-
66
- String text = psiElement .getText ();
67
- if (StringUtils .isBlank (text )) {
68
- return ;
69
- }
70
-
71
- // get domain on file scope or method parameter
72
- String domainName = TwigUtil .getPsiElementTranslationDomain (psiElement );
73
-
74
- // inspection will take care of complete unknown key
75
- if (!TranslationUtil .hasTranslationKey (psiElement .getProject (), text , domainName )) {
76
- return ;
77
- }
78
-
79
- holder .createInfoAnnotation (psiElement , "Create translation key" )
80
- .registerFix (new TranslationKeyIntentionAndQuickFixAction (text , domainName , new MyKeyDomainNotExistingCollector ()));
81
47
}
82
48
83
49
private void annotateRoute (@ NotNull final PsiElement element , @ NotNull AnnotationHolder holder ) {
@@ -166,31 +132,4 @@ private boolean isKnownAssetFileOrFolder(PsiElement element, String templateName
166
132
167
133
return TwigHelper .resolveAssetsFiles (element .getProject (), templateName , fileTypes ).size () > 0 ;
168
134
}
169
-
170
- /**
171
- * Collect all domain files that are not providing the given key
172
- * Known VirtualFiles are filtered out based on the index
173
- */
174
- private static class MyKeyDomainNotExistingCollector implements TranslationKeyIntentionAndQuickFixAction .DomainCollector {
175
- @ NotNull
176
- @ Override
177
- public Collection <PsiFile > collect (@ NotNull Project project , @ NotNull String key , @ NotNull String domain ) {
178
- return TranslationUtil .getDomainPsiFiles (project , domain ).stream ()
179
- .filter (psiFile -> !isDomainAndKeyInPsi (psiFile , key , domain ))
180
- .collect (Collectors .toList ());
181
- }
182
-
183
- private boolean isDomainAndKeyInPsi (@ NotNull PsiFile psiFile , @ NotNull String key , @ NotNull String domain ) {
184
- List <Set <String >> values = FileBasedIndex .getInstance ()
185
- .getValues (YamlTranslationStubIndex .KEY , domain , GlobalSearchScope .fileScope (psiFile ));
186
-
187
- for (Set <String > value : values ) {
188
- if (value .contains (key )) {
189
- return true ;
190
- }
191
- }
192
-
193
- return false ;
194
- }
195
- }
196
135
}
0 commit comments