|
22 | 22 | import com.intellij.psi.impl.source.xml.TagNameReference; |
23 | 23 | import com.intellij.psi.xml.XmlAttribute; |
24 | 24 | import com.intellij.psi.xml.XmlDocument; |
| 25 | +import com.intellij.psi.xml.XmlFile; |
25 | 26 | import com.intellij.psi.xml.XmlTag; |
26 | 27 | import com.intellij.xml.HtmlXmlExtension; |
| 28 | +import java.util.List; |
27 | 29 | import java.util.Optional; |
| 30 | +import org.jetbrains.annotations.NotNull; |
28 | 31 | import org.jetbrains.annotations.Nullable; |
29 | 32 |
|
30 | 33 | public class VueGWTXmlExtension extends HtmlXmlExtension { |
31 | 34 |
|
32 | 35 | @Override |
33 | 36 | public boolean isAvailable(PsiFile psiFile) { |
34 | | - return psiFile.getLanguage() == HtmlTemplateLanguage.INSTANCE; |
| 37 | + if (psiFile.getLanguage() != HtmlTemplateLanguage.INSTANCE) { |
| 38 | + return false; |
| 39 | + } |
| 40 | + |
| 41 | + Optional<PsiJavaFile> optionalPsiJavaFile = getJavaFileForTemplate(psiFile); |
| 42 | + return optionalPsiJavaFile.isPresent(); |
35 | 43 | } |
36 | 44 |
|
37 | 45 | @Override |
@@ -78,21 +86,12 @@ public String[][] getNamespacesFromDocument(XmlDocument parent, boolean declarat |
78 | 86 | public TagNameReference createTagNameReference(ASTNode astNode, boolean b) { |
79 | 87 | PsiFile templateFile = astNode.getTreeParent().getPsi().getContainingFile(); |
80 | 88 |
|
81 | | - // Get the Java file for the template |
82 | | - Optional<PsiFile> optionalJavaFile = VueGWTPluginUtil.findJavaFromTemplate(templateFile); |
83 | | - if (!optionalJavaFile.isPresent()) { |
| 89 | + Optional<PsiJavaFile> optionalPsiJavaFile = getJavaFileForTemplate(templateFile); |
| 90 | + if (!optionalPsiJavaFile.isPresent()) { |
84 | 91 | return super.createTagNameReference(astNode, b); |
85 | 92 | } |
86 | 93 |
|
87 | | - // Find the project for the current file |
88 | | - Project project = astNode.getPsi().getProject(); |
89 | | - PsiFile file = PsiManager.getInstance(project) |
90 | | - .findFile(optionalJavaFile.get().getVirtualFile()); |
91 | | - if (!(file instanceof PsiJavaFile)) { |
92 | | - return super.createTagNameReference(astNode, b); |
93 | | - } |
94 | | - |
95 | | - PsiJavaFile psiJavaFile = (PsiJavaFile) file; |
| 94 | + PsiJavaFile psiJavaFile = optionalPsiJavaFile.get(); |
96 | 95 | String tagName = astNode.getText(); // Tag name of the current element |
97 | 96 |
|
98 | 97 | return getComponentAnnotationFromJavaFile(psiJavaFile) |
@@ -168,4 +167,27 @@ private Optional<PsiFile> getComponentTemplateForClassObjectAccess( |
168 | 167 |
|
169 | 168 | return findHtmlTemplate(componentClass.getContainingFile()); |
170 | 169 | } |
| 170 | + |
| 171 | + @Override |
| 172 | + public boolean isSelfClosingTagAllowed(@NotNull XmlTag tag) { |
| 173 | + return true; |
| 174 | + } |
| 175 | + |
| 176 | + private Optional<PsiJavaFile> getJavaFileForTemplate(PsiFile templateFile) { |
| 177 | + // Get the Java file for the template |
| 178 | + Optional<PsiFile> optionalJavaFile = VueGWTPluginUtil.findJavaFromTemplate(templateFile); |
| 179 | + if (!optionalJavaFile.isPresent()) { |
| 180 | + return Optional.empty(); |
| 181 | + } |
| 182 | + |
| 183 | + // Find the project for the current file |
| 184 | + Project project = templateFile.getProject(); |
| 185 | + PsiFile file = PsiManager.getInstance(project) |
| 186 | + .findFile(optionalJavaFile.get().getVirtualFile()); |
| 187 | + if (!(file instanceof PsiJavaFile)) { |
| 188 | + return Optional.empty(); |
| 189 | + } |
| 190 | + |
| 191 | + return Optional.of((PsiJavaFile) file); |
| 192 | + } |
171 | 193 | } |
0 commit comments