com.intellij.psi.impl.source.xml.XmlDocumentImpl Java Examples

The following examples show how to use com.intellij.psi.impl.source.xml.XmlDocumentImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RouteHelper.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@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;
}
 
Example #2
Source File: XmlHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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;
}
 
Example #3
Source File: XmlDescriptorUtil.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
public static XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return ContainerUtil.map2Array(xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument),
        XmlElementDescriptor.class, descriptor -> wrapInDelegating(descriptor));
}
 
Example #4
Source File: RTClassTagDescriptor.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #5
Source File: RTImportTagDescriptor.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #6
Source File: RTRequireTagDescriptor.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #7
Source File: ISMLTagDescriptor.java    From intellij-demandware with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #8
Source File: RTClassTagDescriptor.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #9
Source File: RTImportTagDescriptor.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #10
Source File: RTRequireTagDescriptor.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    XmlDocumentImpl xmlDocument = PsiTreeUtil.getParentOfType(context, XmlDocumentImpl.class);
    if (xmlDocument == null) return EMPTY_ARRAY;
    return xmlDocument.getRootTagNSDescriptor().getRootElementsDescriptors(xmlDocument);
}
 
Example #11
Source File: FormUtil.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public static Map<String, Set<String>> getTags(@NotNull 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;
}
 
Example #12
Source File: RouteHelper.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
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;
    }
 
Example #13
Source File: XmlHelper.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
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;
    }