コード例 #1
0
    @Override
    public void visitDefine(RncDefine pattern) {
      final RncGrammar grammar = PsiTreeUtil.getParentOfType(pattern, RncGrammar.class);
      final PsiFile file = pattern.getContainingFile();
      if (grammar != null) {
        if (processRncUsages(pattern, new LocalSearchScope(grammar))) return;
      } else {
        if (processRncUsages(pattern, new LocalSearchScope(file))) return;
      }

      final PsiElementProcessor.CollectElements<XmlFile> collector =
          new PsiElementProcessor.CollectElements<XmlFile>();
      RelaxIncludeIndex.processBackwardDependencies((XmlFile) file, collector);

      if (processRncUsages(pattern, new LocalSearchScope(collector.toArray()))) return;

      final ASTNode astNode = ((RncDefineImpl) pattern).getNameNode();
      myHolder.registerProblem(
          astNode.getPsi(),
          "Unreferenced define",
          ProblemHighlightType.LIKE_UNUSED_SYMBOL,
          new MyFix<RncDefine>(pattern));
    }
コード例 #2
0
    public void visitXmlTag(XmlTag tag) {
      final PsiFile file = tag.getContainingFile();
      if (file.getFileType() != StdFileTypes.XML) {
        return;
      }
      if (!tag.getLocalName().equals("define")) {
        return;
      }
      if (!tag.getNamespace().equals(ApplicationLoader.RNG_NAMESPACE)) {
        return;
      }
      if (tag.getAttribute("combine") != null) {
        return; // ?
      }

      final XmlAttribute attr = tag.getAttribute("name");
      if (attr == null) return;

      final XmlAttributeValue value = attr.getValueElement();
      if (value == null) return;

      final String s = value.getValue();
      if (s == null || s.length() == 0) {
        return;
      }
      final PsiElement parent = value.getParent();
      if (!(parent instanceof XmlAttribute)) {
        return;
      }
      if (!"name".equals(((XmlAttribute) parent).getName())) {
        return;
      }
      final PsiElement grandParent = parent.getParent();
      if (!(grandParent instanceof XmlTag)) {
        return;
      }

      final DomElement element = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
      if (element == null) {
        return;
      }

      final RngGrammar rngGrammar = element.getParentOfType(RngGrammar.class, true);
      if (rngGrammar != null) {
        if (processUsages(tag, value, new LocalSearchScope(rngGrammar.getXmlTag()))) return;
      } else {
        if (processUsages(tag, value, new LocalSearchScope(file))) return;
      }

      final PsiElementProcessor.CollectElements<XmlFile> collector =
          new PsiElementProcessor.CollectElements<XmlFile>();
      RelaxIncludeIndex.processBackwardDependencies((XmlFile) file, collector);

      if (processUsages(tag, value, new LocalSearchScope(collector.toArray()))) return;

      myHolder.registerProblem(
          value,
          "Unreferenced define",
          ProblemHighlightType.LIKE_UNUSED_SYMBOL,
          new MyFix<XmlTag>(tag));
    }