Java 类com.intellij.psi.impl.source.jsp.jspXml.JspTag 实例源码

项目:consulo-javaee    文件:JspReferenceContributor.java   
@Override
public void registerReferenceProviders(PsiReferenceRegistrar registrar)
{
    registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue(), new PsiReferenceProvider()
    {
        @NotNull
        @Override
        public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context)
        {
            XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class);
            if(xmlAttribute == null)
            {
                return PsiReference.EMPTY_ARRAY;
            }
            JspTag jspTag = PsiTreeUtil.getParentOfType(element, JspTag.class);
            if(jspTag == null)
            {
                return PsiReference.EMPTY_ARRAY;
            }

            if("include".equals(jspTag.getName()) && "file".equals(xmlAttribute.getName()))
            {
                FileReferenceSet set = new FileReferenceSet(element);
                set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, file ->
                {
                    Module module = ModuleUtilCore.findModuleForPsiElement(file);
                    if(module == null)
                    {
                        return Collections.emptyList();
                    }

                    ContentFolder[] contentFolders = ModuleRootManager.getInstance(module).getContentFolders(ContentFolderScopes.of(WebResourcesFolderTypeProvider.getInstance()));
                    PsiManager psiManager = PsiManager.getInstance(element.getProject());
                    return Arrays.stream(contentFolders).map(contentFolder -> psiManager.findDirectory(contentFolder.getFile())).filter(Objects::nonNull).collect(Collectors.toList());
                });
                return set.getAllReferences();
            }
            return PsiReference.EMPTY_ARRAY;
        }
    });
}