Java 类com.intellij.psi.XmlRecursiveElementVisitor 实例源码

项目:intellij-ce-playground    文件:MicrodataUtil.java   
private static Map<String, XmlTag> findScopesWithItemRef(@Nullable PsiFile file) {
  if (!(file instanceof XmlFile)) return Collections.emptyMap();
  final Map<String, XmlTag> result = new THashMap<String, XmlTag>();
  file.accept(new XmlRecursiveElementVisitor() {
    @Override
    public void visitXmlTag(final XmlTag tag) {
      super.visitXmlTag(tag);
      XmlAttribute refAttr = tag.getAttribute(ITEM_REF);
      if (refAttr != null && tag.getAttribute(ITEM_SCOPE) != null) {
        getReferencesForAttributeValue(refAttr.getValueElement(), new PairFunction<String, Integer, PsiReference>() {
          @Nullable
          @Override
          public PsiReference fun(String t, Integer v) {
            result.put(t, tag);
            return null;
          }
        });
      }
    }
  });
  return result;
}
项目:tools-idea    文件:MicrodataUtil.java   
private static Map<String, XmlTag> findScopesWithItemRef(@Nullable PsiFile file) {
  if (!(file instanceof XmlFile)) return Collections.emptyMap();
  final Map<String, XmlTag> result = new THashMap<String, XmlTag>();
  file.accept(new XmlRecursiveElementVisitor() {
    @Override
    public void visitXmlTag(final XmlTag tag) {
      super.visitXmlTag(tag);
      XmlAttribute refAttr = tag.getAttribute(ITEM_REF);
      if (refAttr != null && tag.getAttribute(ITEM_SCOPE) != null) {
        getReferencesForAttributeValue(refAttr.getValueElement(), new PairFunction<String, Integer, PsiReference>() {
          @Nullable
          @Override
          public PsiReference fun(String t, Integer v) {
            result.put(t, tag);
            return null;
          }
        });
      }
    }
  });
  return result;
}
项目:emberjs-plugin    文件:EmberTemplateCacheIndex.java   
public static void processTemplates(final PsiFile psiFile, final Processor<XmlAttribute> processor) {
    if (psiFile instanceof XmlFile) {
        psiFile.accept(new XmlRecursiveElementVisitor() {
            @Override
            public void visitXmlTag(XmlTag tag) {
                // TODO: Fix to correct handlebars script type
                if (HtmlUtil.isScriptTag(tag) && "text/x-handlebars".equals(tag.getAttributeValue("type"))) {
                    final XmlAttribute id = tag.getAttribute("id");
                    if (id != null) {
                        processor.process(id);
                        return;
                    }
                }
                super.visitXmlTag(tag);
            }
        });
    }
}
项目:intellij-ce-playground    文件:XmlHighlightVisitorBasedInspection.java   
@Override
public void checkFile(@NotNull final PsiFile file,
                      @NotNull final InspectionManager manager,
                      @NotNull ProblemsHolder problemsHolder,
                      @NotNull final GlobalInspectionContext globalContext,
                      @NotNull final ProblemDescriptionsProcessor problemDescriptionsProcessor) {
  HighlightInfoHolder myHolder = new HighlightInfoHolder(file) {
    @Override
    public boolean add(@Nullable HighlightInfo info) {
      if (info != null) {
        GlobalInspectionUtil.createProblem(
          file,
          info,
          new TextRange(info.startOffset, info.endOffset),
          null,
          manager,
          problemDescriptionsProcessor,
          globalContext
        );
      }
      return true;
    }
  };
  final XmlHighlightVisitor highlightVisitor = new XmlHighlightVisitor();
  highlightVisitor.analyze(file, true, myHolder, new Runnable() {
    @Override
    public void run() {
      file.accept(new XmlRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
          highlightVisitor.visit(element);
          super.visitElement(element);
        }
      });
    }
  });

}
项目:intellij-ce-playground    文件:AndroidProcessChooserDialog.java   
private static void collectProcessNames(XmlElement xmlElement, final Set<String> result) {
  xmlElement.accept(new XmlRecursiveElementVisitor() {
    @Override
    public void visitXmlAttribute(XmlAttribute attribute) {
      if ("process".equals(attribute.getLocalName())) {
        final String value = attribute.getValue();

        if (value != null) {
          result.add(value.toLowerCase());
        }
      }
    }
  });
}
项目:intellij-ce-playground    文件:IdResourceInfo.java   
@Override
public XmlAttributeValue computeXmlElement() {
  final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile);

  if (!(psiFile instanceof XmlFile)) {
    return null;
  }
  final Ref<XmlAttributeValue> result = Ref.create();

  psiFile.accept(new XmlRecursiveElementVisitor() {
    @Override
    public void visitXmlAttributeValue(XmlAttributeValue attributeValue) {
      if (!result.isNull()) {
        return;
      }

      if (AndroidResourceUtil.isIdDeclaration(attributeValue)) {
        final String idInAttr = AndroidResourceUtil.getResourceNameByReferenceText(attributeValue.getValue());

        if (myName.equals(idInAttr)) {
          result.set(attributeValue);
        }
      }
    }
  });
  return result.get();
}
项目:intellij-ce-playground    文件:AndroidFindStyleApplicationsProcessor.java   
public void collectPossibleStyleApplications(PsiFile layoutFile, final List<UsageInfo> usages) {
  layoutFile.accept(new XmlRecursiveElementVisitor() {
    @Override
    public void visitXmlTag(XmlTag tag) {
      super.visitXmlTag(tag);

      if (isPossibleApplicationOfStyle(tag)) {
        usages.add(new UsageInfo(tag));
      }
    }
  });
}
项目:tools-idea    文件:XmlHighlightVisitorBasedInspection.java   
@Override
public void checkFile(@NotNull final PsiFile file,
                      @NotNull final InspectionManager manager,
                      @NotNull ProblemsHolder problemsHolder,
                      @NotNull final GlobalInspectionContext globalContext,
                      @NotNull final ProblemDescriptionsProcessor problemDescriptionsProcessor) {
  HighlightInfoHolder myHolder = new HighlightInfoHolder(file) {
    @Override
    public boolean add(@Nullable HighlightInfo info) {
      if (info != null) {
        GlobalInspectionUtil.createProblem(
          file,
          info,
          new TextRange(info.startOffset, info.endOffset),
          null,
          manager,
          problemDescriptionsProcessor,
          globalContext
        );
      }
      return true;
    }
  };
  final XmlHighlightVisitor highlightVisitor = new XmlHighlightVisitor();
  highlightVisitor.analyze(file, true, myHolder, new Runnable() {
    @Override
    public void run() {
      file.accept(new XmlRecursiveElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
          highlightVisitor.visit(element);
          super.visitElement(element);
        }
      });
    }
  });

}
项目:consulo-xml    文件:XmlHighlightVisitorBasedInspection.java   
@Override
public void checkFile(@NotNull final PsiFile file,
        @NotNull final InspectionManager manager,
        @NotNull ProblemsHolder problemsHolder,
        @NotNull final GlobalInspectionContext globalContext,
        @NotNull final ProblemDescriptionsProcessor problemDescriptionsProcessor)
{
    HighlightInfoHolder myHolder = new HighlightInfoHolder(file)
    {
        @Override
        public boolean add(@Nullable HighlightInfo info)
        {
            if(info != null)
            {
                GlobalInspectionUtil.createProblem(file, info, new TextRange(info.startOffset, info.endOffset), null, manager, problemDescriptionsProcessor, globalContext);
            }
            return true;
        }
    };
    final XmlHighlightVisitor highlightVisitor = new XmlHighlightVisitor();
    highlightVisitor.analyze(file, true, myHolder, new Runnable()
    {
        @Override
        public void run()
        {
            file.accept(new XmlRecursiveElementVisitor()
            {
                @Override
                public void visitElement(PsiElement element)
                {
                    highlightVisitor.visit(element);
                    super.visitElement(element);
                }
            });
        }
    });

}
项目:consulo-xml    文件:MicrodataUtil.java   
private static Map<String, XmlTag> findScopesWithItemRef(@Nullable final PsiFile file)
{
    if(!(file instanceof XmlFile))
    {
        return Collections.emptyMap();
    }
    return CachedValuesManager.getCachedValue(file, new CachedValueProvider<Map<String, XmlTag>>()
    {
        @Nullable
        @Override
        public Result<Map<String, XmlTag>> compute()
        {
            final Map<String, XmlTag> result = new THashMap<>();
            file.accept(new XmlRecursiveElementVisitor()
            {
                @Override
                public void visitXmlTag(final XmlTag tag)
                {
                    super.visitXmlTag(tag);
                    XmlAttribute refAttr = tag.getAttribute(ITEM_REF);
                    if(refAttr != null && tag.getAttribute(ITEM_SCOPE) != null)
                    {
                        getReferencesForAttributeValue(refAttr.getValueElement(), (t, v) ->
                        {
                            result.put(t, tag);
                            return null;
                        });
                    }
                }
            });
            return Result.create(result, file);
        }
    });
}
项目:consulo-javascript    文件:XmlBackedJSClassImpl.java   
@Override
protected CachedValue<Map<String, String>> compute(final XmlFile file, final Object p)
{
    return CachedValuesManager.getManager(file.getProject()).createCachedValue(new CachedValueProvider<Map<String, String>>()
    {
        @Override
        public Result<Map<String, String>> compute()
        {
            final Map<String, String> cachedComponentImports = new THashMap<String, String>();
            final List<PsiFile> dependencies = new ArrayList<PsiFile>();
            dependencies.add(file);

            file.acceptChildren(new XmlRecursiveElementVisitor()
            {
                @Override
                public void visitXmlTag(XmlTag tag)
                {
                    XmlElementDescriptor descriptor = tag.getDescriptor();
                    if(descriptor != null)
                    {
                        PsiElement declaration = descriptor.getDeclaration();
                        if(declaration instanceof XmlFile)
                        {
                            declaration = XmlBackedJSClassImpl.getXmlBackedClass((XmlFile) declaration);
                        }
                        if(declaration instanceof JSClass)
                        {
                            JSClass jsClass = (JSClass) declaration;

                            cachedComponentImports.put(jsClass.getName(), jsClass.getQualifiedName());
                            dependencies.add(declaration.getContainingFile());
                        }
                    }
                    super.visitXmlTag(tag);
                }
            });
            return new Result<Map<String, String>>(cachedComponentImports, dependencies.toArray());
        }
    }, false);
}
项目:intellij-ce-playground    文件:AndroidValueResourcesIndex.java   
@Override
@NotNull
public Map<ResourceEntry, Set<MyResourceInfo>> map(@NotNull FileContent inputData) {
  if (!isSimilarFile(inputData)) {
    return Collections.emptyMap();
  }
  final PsiFile file = inputData.getPsiFile();

  if (!(file instanceof XmlFile)) {
    return Collections.emptyMap();
  }
  final Map<ResourceEntry, Set<MyResourceInfo>> result = new HashMap<ResourceEntry, Set<MyResourceInfo>>();

  file.accept(new XmlRecursiveElementVisitor() {
    @Override
    public void visitXmlTag(XmlTag tag) {
      super.visitXmlTag(tag);
      final String resName = tag.getAttributeValue(NAME_ATTRIBUTE_VALUE);

      if (resName == null) {
        return;
      }
      final String tagName = tag.getName();
      final String resTypeStr;

      if ("item".equals(tagName)) {
        resTypeStr = tag.getAttributeValue(TYPE_ATTRIBUTE_VALUE);
      }
      else {
        resTypeStr = AndroidCommonUtils.getResourceTypeByTagName(tagName);
      }
      final ResourceType resType = resTypeStr != null ? ResourceType.getEnum(resTypeStr) : null;

      if (resType == null) {
        return;
      }
      final int offset = tag.getTextRange().getStartOffset();

      if (resType == ResourceType.ATTR) {
        final XmlTag parentTag = tag.getParentTag();
        final String contextName = parentTag != null ? parentTag.getAttributeValue(NAME_ATTRIBUTE_VALUE) : null;
        processResourceEntry(new ResourceEntry(resTypeStr, resName, contextName != null ? contextName : ""), result, offset);
      }
      else {
        processResourceEntry(new ResourceEntry(resTypeStr, resName, ""), result, offset);
      }
    }
  });

  return result;
}
项目:android-viewbyid-generator    文件:Utils.java   
/**
 * Obtain all IDs from layout
 *
 * @param file
 * @return
 */
public static ArrayList<Element> getIDsFromLayout(final PsiFile file, final ArrayList<Element> elements) {
    file.accept(new XmlRecursiveElementVisitor() {

        @Override
        public void visitElement(final PsiElement element) {
            super.visitElement(element);

            if (element instanceof XmlTag) {
                XmlTag tag = (XmlTag) element;

                if (tag.getName().equalsIgnoreCase("include")) {
                    XmlAttribute layout = tag.getAttribute("layout", null);

                    if (layout != null) {
                        Project project = file.getProject();
                        PsiFile include = findLayoutResource(project, getLayoutName(layout.getValue()));

                        if (include != null) {
                            getIDsFromLayout(include, elements);

                            return;
                        }
                    }
                }

                // get element ID
                XmlAttribute id = tag.getAttribute("android:id", null);
                if (id == null) {
                    return; // missing android:id attribute
                }
                String value = id.getValue();
                if (value == null) {
                    return; // empty value
                }

                // check if there is defined custom class
                String name = tag.getName();
                XmlAttribute clazz = tag.getAttribute("class", null);
                if (clazz != null) {
                    name = clazz.getValue();
                }

                elements.add(new Element(name, value));
            }
        }
    });

    return elements;
}
项目:holdr    文件:HoldrLayoutIndex.java   
@Override
@NotNull
public Map<File, SingleLayout> map(@NotNull final FileContent inputData) {
    Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {
        @Override
        public Module compute() {
            return ModuleUtilCore.findModuleForFile(inputData.getFile(), inputData.getProject());
        }
    });
    if (module == null) {
        return Collections.emptyMap();
    }

    final HoldrModel holdrModel = HoldrModel.getInstance(module);
    if (holdrModel == null) {
        return Collections.emptyMap();
    }

    // For some bizarre reason, just inputData.getPsiFile() will sometimes not allow you to get the parent directory.
    final PsiFile file = inputData.getPsiFile().getManager().findFile(inputData.getFile());
    if (file == null) {
        return Collections.emptyMap();
    }
    if (!AndroidResourceUtil.isInResourceSubdirectory(file, "layout")) {
        return Collections.emptyMap();
    }

    if (!(file instanceof XmlFile)) {
        return Collections.emptyMap();
    }

    final File path = new File(inputData.getFile().getPath());
    final Map<File, SingleLayout> result = new HashMap<File, SingleLayout>();
    final ParserUtils.IncludeIgnoreState state = new ParserUtils.IncludeIgnoreState();
    final SingleLayout.Builder layoutBuilder = SingleLayout.of(path);
    final TagParser tagParser = new TagParser();

    file.accept(new XmlRecursiveElementVisitor() {
        @Override
        public void visitXmlTag(final XmlTag tag) {
            tagParser.tag = tag;
            ParserUtils.parseTag(holdrModel.getConfig(), layoutBuilder, state, tagParser);
            super.visitXmlTag(tag);
            state.tagEnd(tag.getName());
        }
    });

    SingleLayout layout = layoutBuilder.build();

    result.put(path, layout);
    return result;
}
项目:afinal-view-helper    文件:Utils.java   
/**
 * Obtain all IDs from layout
 *
 * @param file
 * @return
 */
public static ArrayList<Element> getIDsFromLayout(final PsiFile file, final ArrayList<Element> elements) {
    file.accept(new XmlRecursiveElementVisitor() {

        @Override
        public void visitElement(final PsiElement element) {
            super.visitElement(element);

            if (element instanceof XmlTag) {
                XmlTag tag = (XmlTag) element;

                if (tag.getName().equalsIgnoreCase("include")) {
                    XmlAttribute layout = tag.getAttribute("layout", null);

                    if (layout != null) {
                        Project project = file.getProject();
                        PsiFile include = findLayoutResource(project, getLayoutName(layout.getValue()));

                        if (include != null) {
                            getIDsFromLayout(include, elements);

                            return;
                        }
                    }
                }

                // get element ID
                XmlAttribute id = tag.getAttribute("android:id", null);
                if (id == null) {
                    return; // missing android:id attribute
                }
                String value = id.getValue();
                if (value == null) {
                    return; // empty value
                }

                // check if there is defined custom class
                String name = tag.getName();
                XmlAttribute clazz = tag.getAttribute("class", null);
                if (clazz != null) {
                    name = clazz.getValue();
                }

                elements.add(new Element(name, value));
            }
        }
    });

    return elements;
}