Java 类com.intellij.psi.impl.source.xml.XmlDocumentImpl 实例源码

项目:idea-php-symfony2-plugin    文件:RouteHelper.java   
@Nullable
public static PsiElement getXmlRouteNameTarget(@NotNull XmlFile psiFile,@NotNull String routeName) {

    XmlDocumentImpl document = PsiTreeUtil.getChildOfType(psiFile, XmlDocumentImpl.class);
    if(document == null) {
        return null;
    }

    for(XmlTag xmlTag: PsiTreeUtil.getChildrenOfTypeAsList(psiFile.getFirstChild(), XmlTag.class)) {
        if(xmlTag.getName().equals("routes")) {
            for(XmlTag routeTag: xmlTag.getSubTags()) {
                if(routeTag.getName().equals("route")) {
                    XmlAttribute xmlAttribute = routeTag.getAttribute("id");
                    if(xmlAttribute != null) {
                        String attrValue = xmlAttribute.getValue();
                        if(routeName.equals(attrValue)) {
                            return xmlAttribute;
                        }
                    }
                }
            }
        }
    }

    return null;
}
项目:intellij-ce-playground    文件:XmlMover.java   
private static boolean moveTags(MoveInfo info, XmlTag moved, XmlTag target, boolean down) {
  if (target.getParent() == moved) {
    // we are going to jump into our own children
    // this can mean that target computed incorrectly
    XmlTag next = down ? PsiTreeUtil.getNextSiblingOfType(moved, XmlTag.class) :
                         PsiTreeUtil.getPrevSiblingOfType(moved, XmlTag.class);
    if (next == null) return info.prohibitMove();
    info.toMove = new LineRange(moved);
    info.toMove2 = new LineRange(next);
    return true;
  }
  else if (moved.getParent() == target) {
    return false;
  }

  LineRange targetRange = new LineRange(target);
  if (targetRange.contains(info.toMove2)) {
    // we are going to jump into sibling tag
    XmlElementDescriptor descriptor = moved.getDescriptor();
    if (descriptor == null) return false;
    XmlNSDescriptor nsDescriptor = descriptor.getNSDescriptor();
    if (nsDescriptor == null) return false;
    XmlFile descriptorFile = nsDescriptor.getDescriptorFile();
    if (descriptorFile == null || XmlDocumentImpl.isAutoGeneratedSchema(descriptorFile)) return false;
    if (!TagNameVariantCollector.couldContain(target, moved)) {
      info.toMove = new LineRange(moved);
      info.toMove2 = targetRange;
      return true;
    }
  }

  return false;
}
项目:tools-idea    文件:XmlMover.java   
private static boolean moveTags(MoveInfo info, XmlTag moved, XmlTag target, boolean down) {
  if (target.getParent() == moved) {
    // we are going to jump into our own children
    // this can mean that target computed incorrectly
    XmlTag next = down ? PsiTreeUtil.getNextSiblingOfType(moved, XmlTag.class) :
                         PsiTreeUtil.getPrevSiblingOfType(moved, XmlTag.class);
    if (next == null) return info.prohibitMove();
    info.toMove = new LineRange(moved);
    info.toMove2 = new LineRange(next);
    return true;
  }
  else if (moved.getParent() == target) {
    return false;
  }

  LineRange targetRange = new LineRange(target);
  if (targetRange.contains(info.toMove2)) {
    // we are going to jump into sibling tag
    XmlElementDescriptor descriptor = moved.getDescriptor();
    if (descriptor == null) return false;
    XmlNSDescriptor nsDescriptor = descriptor.getNSDescriptor();
    if (nsDescriptor == null) return false;
    XmlFile descriptorFile = nsDescriptor.getDescriptorFile();
    if (descriptorFile == null || XmlDocumentImpl.isAutoGeneratedSchema(descriptorFile)) return false;
    if (!TagNameVariantCollector.couldContain(target, moved)) {
      info.toMove = new LineRange(moved);
      info.toMove2 = targetRange;
      return true;
    }
  }

  return false;
}
项目:idea-php-symfony2-plugin    文件:XmlHelper.java   
@Nullable
public static PsiElement getLocalParameterName(PsiFile psiFile, String serviceName) {

    if(!(psiFile.getFirstChild() instanceof XmlDocumentImpl)) {
        return null;
    }

    XmlTag xmlTags[] = PsiTreeUtil.getChildrenOfType(psiFile.getFirstChild(), XmlTag.class);
    if(xmlTags == null) {
        return null;
    }

    for(XmlTag xmlTag: xmlTags) {
        if(xmlTag.getName().equals("container")) {
            for(XmlTag servicesTag: xmlTag.getSubTags()) {
                if(servicesTag.getName().equals("parameters")) {
                    for(XmlTag serviceTag: servicesTag.getSubTags()) {
                        XmlAttribute attrValue = serviceTag.getAttribute("key");
                        if(attrValue != null) {
                            String serviceNameId = attrValue.getValue();
                            if(serviceNameId != null && serviceNameId.equals(serviceName)) {
                                return serviceTag;
                            }
                        }
                    }
                }
            }
        }
    }

    return null;
}
项目:consulo-xml    文件:XmlMover.java   
private static boolean moveTags(MoveInfo info, XmlTag moved, XmlTag target, boolean down) {
  if (target.getParent() == moved) {
    // we are going to jump into our own children
    // this can mean that target computed incorrectly
    XmlTag next = down ? PsiTreeUtil.getNextSiblingOfType(moved, XmlTag.class) :
                  PsiTreeUtil.getPrevSiblingOfType(moved, XmlTag.class);
    if (next == null) return info.prohibitMove();
    info.toMove = new LineRange(moved);
    info.toMove2 = new LineRange(next);
    return true;
  }
  else if (moved.getParent() == target) {
    return false;
  }

  LineRange targetRange = new LineRange(target);
  if (targetRange.contains(info.toMove2)) {
    // we are going to jump into sibling tag
    XmlElementDescriptor descriptor = moved.getDescriptor();
    if (descriptor == null) return false;
    XmlNSDescriptor nsDescriptor = descriptor.getNSDescriptor();
    if (nsDescriptor == null) return false;
    XmlFile descriptorFile = nsDescriptor.getDescriptorFile();
    if (descriptorFile == null || XmlDocumentImpl.isAutoGeneratedSchema(descriptorFile)) return false;
    if (!TagNameVariantCollector.couldContain(target, moved)) {
      info.toMove = new LineRange(moved);
      info.toMove2 = targetRange;
      return true;
    }
  }

  return false;
}
项目:catberry-idea-plugin    文件:CatberryComponentTagDescriptor.java   
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
  XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
  if (xmlDocument == null) return EMPTY_ARRAY;
  return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
项目:react-templates-plugin    文件:RTClassTagDescriptor.java   
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
项目:react-templates-plugin    文件:RTImportTagDescriptor.java   
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
项目:react-templates-plugin    文件:RTRequireTagDescriptor.java   
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
项目:intellij-demandware    文件:ISMLTagDescriptor.java   
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
项目:react-templates-plugin    文件:RTClassTagDescriptor.java   
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
项目:react-templates-plugin    文件:RTImportTagDescriptor.java   
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
项目:react-templates-plugin    文件:RTRequireTagDescriptor.java   
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
项目:emberjs-plugin    文件:EmberJSTagDescriptor.java   
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
项目:idea-php-symfony2-plugin    文件:FormUtil.java   
public static Map<String, Set<String>> getTags(XmlFile psiFile) {

        Map<String, Set<String>> map = new HashMap<>();

        XmlDocumentImpl document = PsiTreeUtil.getChildOfType(psiFile, XmlDocumentImpl.class);
        if(document == null) {
            return map;
        }

        /*
         * <services>
         *   <service id="espend_form.foo_type" class="%espend_form.foo_type.class%">
         *     <tag name="form.type" alias="foo_type_alias" />
         *   </service>
         * </services>
         */

        XmlTag xmlTags[] = PsiTreeUtil.getChildrenOfType(psiFile.getFirstChild(), XmlTag.class);
        if(xmlTags == null) {
            return map;
        }

        for(XmlTag xmlTag: xmlTags) {
            if(xmlTag.getName().equals("container")) {
                for(XmlTag servicesTag: xmlTag.getSubTags()) {
                    if(servicesTag.getName().equals("services")) {
                        for(XmlTag serviceTag: servicesTag.getSubTags()) {
                            XmlAttribute attrValue = serviceTag.getAttribute("id");
                            if(attrValue != null) {

                                // <service id="foo.bar" class="Class\Name">
                                String serviceNameId = attrValue.getValue();
                                if(serviceNameId != null) {

                                    Set<String> serviceTags = getTags(serviceTag);
                                    if(serviceTags.size() > 0) {
                                        map.put(serviceNameId, serviceTags);
                                    }
                                }

                            }
                        }
                    }
                }
            }
        }

        return map;
    }
项目:idea-php-symfony2-plugin    文件:RouteHelper.java   
public static Collection<StubIndexedRoute> getXmlRouteDefinitions(XmlFile psiFile) {

        XmlDocumentImpl document = PsiTreeUtil.getChildOfType(psiFile, XmlDocumentImpl.class);
        if(document == null) {
            return Collections.emptyList();
        }

        Collection<StubIndexedRoute> indexedRoutes = new ArrayList<>();

        /*
         * <routes>
         *   <route id="foo" path="/blog/{slug}" methods="GET">
         *     <default key="_controller">Foo</default>
         *   </route>
         *
         *   <route id="foo" path="/blog/{slug}" methods="GET" controller="AppBundle:Blog:list"/>
         * </routes>
         */
        for(XmlTag xmlTag: PsiTreeUtil.getChildrenOfTypeAsList(psiFile.getFirstChild(), XmlTag.class)) {
            if(xmlTag.getName().equals("routes")) {
                for(XmlTag servicesTag: xmlTag.getSubTags()) {
                    if(servicesTag.getName().equals("route")) {
                        XmlAttribute xmlAttribute = servicesTag.getAttribute("id");
                        if(xmlAttribute != null) {
                            String attrValue = xmlAttribute.getValue();
                            if(attrValue != null && StringUtils.isNotBlank(attrValue)) {

                                StubIndexedRoute route = new StubIndexedRoute(attrValue);
                                String pathAttribute = servicesTag.getAttributeValue("path");
                                if(pathAttribute == null) {
                                    pathAttribute = servicesTag.getAttributeValue("pattern");
                                }

                                if(pathAttribute != null && StringUtils.isNotBlank(pathAttribute) ) {
                                    route.setPath(pathAttribute);
                                }

                                String methods = servicesTag.getAttributeValue("methods");
                                if(methods != null && StringUtils.isNotBlank(methods))  {
                                    String[] split = methods.replaceAll(" +", "").toLowerCase().split("\\|");
                                    if(split.length > 0) {
                                        route.addMethod(split);
                                    }
                                }

                                // <route><default key="_controller"/></route>
                                //  <route controller="AppBundle:Blog:list"/>
                                String controller = getXmlController(servicesTag);
                                if(controller != null) {
                                    route.setController(normalizeRouteController(controller));
                                }

                                indexedRoutes.add(route);
                            }
                        }
                    }
                }
            }
        }

        return indexedRoutes;
    }
项目:idea-php-symfony2-plugin    文件:XmlHelper.java   
public static Map<String, String> getFileParameterMap(XmlFile psiFile) {

        Map<String, String> services = new HashMap<>();

        if(!(psiFile.getFirstChild() instanceof XmlDocumentImpl)) {
            return services;
        }

        XmlTag xmlTags[] = PsiTreeUtil.getChildrenOfType(psiFile.getFirstChild(), XmlTag.class);
        if(xmlTags == null) {
            return services;
        }

        for(XmlTag xmlTag: xmlTags) {
            if(xmlTag.getName().equals("container")) {
                for(XmlTag servicesTag: xmlTag.getSubTags()) {
                    if(servicesTag.getName().equals("parameters")) {
                        for(XmlTag parameterTag: servicesTag.getSubTags()) {

                            // <parameter key="fos_user.user_manager.class">FOS\UserBundle\Doctrine\UserManager</parameter>
                            // <parameter key="fos_rest.formats" type="collection">
                            //    <parameter key="json">false</parameter>
                            // </parameter>

                            if(parameterTag.getName().equals("parameter")) {
                                XmlAttribute keyAttr = parameterTag.getAttribute("key");
                                if(keyAttr != null) {
                                    String parameterName = keyAttr.getValue();
                                    if(parameterName != null && StringUtils.isNotBlank(parameterName)) {

                                        String parameterValue = null;

                                        String typeAttr = parameterTag.getAttributeValue("type");

                                        // get value of parameter if we have a text value
                                        if(!"collection".equals(typeAttr) && parameterTag.getSubTags().length == 0) {
                                            XmlTagValue attrClass = parameterTag.getValue();
                                            String myParameterValue = attrClass.getText();

                                            // dont index long values
                                            if(myParameterValue.length() < 150) {
                                                parameterValue = myParameterValue;
                                            }
                                        }

                                        services.put(parameterName.toLowerCase(), parameterValue);
                                    }

                                }
                            }
                        }
                    }
                }
            }
        }

        return services;
    }