예제 #1
0
    public PsiFile resolve() {
      final PsiFile referencedFile = getReferencedFile();
      if (referencedFile != null) {
        return referencedFile;
      }

      if (myPsiFile != null) {
        final PsiElement psiElement = myPsiFile.findElementAt(myLinkInfo.offset);
        if (psiElement != null) {
          final PsiElement parent = psiElement.getParent();
          if (parent instanceof XmlTag) {
            final XmlAttribute attribute = ((XmlTag) parent).getAttribute(HREF_ATTR);
            if (attribute != null) {
              final XmlAttributeValue value = attribute.getValueElement();
              if (value != null) {
                final PsiReference[] references = value.getReferences();
                for (PsiReference reference : references) {
                  final PsiElement element = reference.resolve();
                  if (element instanceof PsiFile) {
                    return (PsiFile) element;
                  }
                }
              }
            }
          }
        }
      }

      return null;
    }
예제 #2
0
  private static void mapJsp(FileContent inputData, final List<LinkInfo> result) {
    final FileViewProvider viewProvider = inputData.getPsiFile().getViewProvider();

    PsiFile psiFile = null;
    if (viewProvider instanceof TemplateLanguageFileViewProvider) {
      final Language dataLanguage =
          ((TemplateLanguageFileViewProvider) viewProvider).getTemplateDataLanguage();
      if (dataLanguage == HTMLLanguage.INSTANCE || dataLanguage == XHTMLLanguage.INSTANCE) {
        psiFile = viewProvider.getPsi(dataLanguage);
      }
    } else {
      psiFile = viewProvider.getPsi(viewProvider.getBaseLanguage());
    }

    if (psiFile != null) {
      final XmlRecursiveElementVisitor visitor =
          new XmlRecursiveElementVisitor() {
            @Override
            public void visitXmlTag(XmlTag tag) {
              if (LINK.equalsIgnoreCase(tag.getLocalName())) {

                final String href = getAttributeValue(tag, HREF_ATTR);
                final String media = getAttributeValue(tag, MEDIA_ATTR);
                final String type = getAttributeValue(tag, TYPE_ATTR);
                final String rel = getAttributeValue(tag, REL_ATTR);
                final String title = getAttributeValue(tag, TITLE_ATTR);

                addResult(
                    result,
                    tag.getTextOffset(),
                    href,
                    media,
                    type,
                    rel,
                    title,
                    isHrefScripted(tag));
              }

              super.visitXmlTag(tag);
            }
          };

      psiFile.accept(visitor);
    }
  }