com.intellij.psi.xml.XmlTag#findFirstSubTag ( )源码实例Demo

下面列出了com.intellij.psi.xml.XmlTag#findFirstSubTag ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private @NotNull
String extractDocumentation(XmlTag attributeTag) {
    StringBuilder attributeDocumentation = new StringBuilder();

    XmlTag attributeAnnotation = attributeTag.findFirstSubTag("xsd:annotation");
    if (attributeAnnotation != null) {
        XmlTag attributeDoc = attributeAnnotation.findFirstSubTag("xsd:documentation");
        if (attributeDoc != null) {
            for (XmlText textElement : attributeDoc.getValue().getTextElements()) {
                attributeDocumentation.append(textElement.getValue());
            }
        }
    }

    return attributeDocumentation.toString();
}
 
源代码2 项目: intellij-latte   文件: LatteXmlFileDataFactory.java
@Nullable
public static LatteXmlFileData parse(XmlFile file) {
    XmlDocument document = file.getDocument();
    if (document == null || document.getRootTag() == null) {
        return null;
    }

    XmlTag configuration = document.getRootTag();
    if (configuration == null) {
        return null;
    }

    LatteXmlFileData.VendorResult vendor = getVendor(document);
    if (vendor == null) {
        return null;
    }

    LatteXmlFileData data = new LatteXmlFileData(vendor);
    XmlTag tags = configuration.findFirstSubTag("tags");
    if (tags != null) {
        loadTags(tags, data);
    }
    XmlTag filters = configuration.findFirstSubTag("filters");
    if (filters != null) {
        loadFilters(filters, data);
    }
    XmlTag variables = configuration.findFirstSubTag("variables");
    if (variables != null) {
        loadVariables(variables, data);
    }
    XmlTag functions = configuration.findFirstSubTag("functions");
    if (functions != null) {
        loadFunctions(functions, data);
    }
    return data;
}
 
源代码3 项目: intellij-latte   文件: LatteXmlFileDataFactory.java
private static List<LatteArgumentSettings> getArguments(XmlTag tag) {
    XmlTag arguments = tag.findFirstSubTag("arguments");
    if (arguments == null) {
        return Collections.emptyList();
    }

    List<LatteArgumentSettings> out = new ArrayList<>();
    for (XmlTag argument : arguments.findSubTags("argument")) {
        XmlAttribute name = argument.getAttribute("name");
        XmlAttribute typesString = argument.getAttribute("types");
        if (name == null || typesString == null) {
            continue;
        }

        LatteArgumentSettings.Type[] types = LatteArgumentSettings.getTypes(typesString.getValue());
        if (types == null) {
            continue;
        }

        String validType = getTextValue(argument, "validType");
        LatteArgumentSettings instance = new LatteArgumentSettings(
                name.getValue(),
                types,
                validType.length() == 0 ? "mixed" : validType,
                isTrue(argument, "required"),
                isTrue(argument, "repeatable")
        );
        out.add(instance);
    }
    return out;
}
 
@Override
public void visitXmlTag(XmlTag tag) {
    if (!tag.getName().equals("xsd:element")) {
        super.visitXmlTag(tag);

        return;
    }

    XmlAttribute nameAttribute = tag.getAttribute("name");
    if (nameAttribute == null || nameAttribute.getValue() == null) {
        super.visitXmlTag(tag);

        return;
    }

    ViewHelper viewHelper = new ViewHelper(nameAttribute.getValue());
    viewHelper.setDocumentation(extractDocumentation(tag));

    XmlTag complexType = tag.findFirstSubTag("xsd:complexType");
    if (complexType != null) {
        XmlTag[] attributeTags = complexType.findSubTags("xsd:attribute");
        for (XmlTag attributeTag : attributeTags) {
            String argumentName = attributeTag.getAttributeValue("name");
            if (argumentName == null) {
                continue;
            }

            ViewHelperArgument argument = new ViewHelperArgument(argumentName);

            argument.setDocumentation(extractDocumentation(attributeTag));

            String attributeType = attributeTag.getAttributeValue("php:type");
            if (attributeType == null) {
                argument.setType("mixed");
            } else {
                argument.setType(attributeType);
            }

            String requiredAttribute = attributeTag.getAttributeValue("use");
            if (requiredAttribute != null && requiredAttribute.equals("required")) {
                argument.setRequired(true);
            }

            viewHelper.addArgument(argumentName, argument);
        }
    }

    viewHelpers.put(nameAttribute.getValue(), viewHelper);

    super.visitXmlTag(tag);
}
 
源代码5 项目: idea-php-shopware-plugin   文件: ConfigUtil.java
public static void visitNamespaceConfigurations(@NotNull Project project, @NotNull String namespace, @NotNull Consumer<Pair<String, XmlTag>> pairConsumer) {
    for(PhpClass phpClass: PhpIndex.getInstance(project).getAllSubclasses(ShopwareFQDN.PLUGIN_BOOTSTRAP)) {
        if(!namespace.equalsIgnoreCase(phpClass.getName())) {
            continue;
        }

        PsiDirectory parent = phpClass.getContainingFile().getParent();
        if(parent == null) {
            continue;
        }

        VirtualFile resources = VfsUtil.findRelativeFile(parent.getVirtualFile(), "Resources", "config.xml");
        if(resources == null) {
            continue;
        }

        PsiFile file = PsiManager.getInstance(project).findFile(resources);
        if(!(file instanceof XmlFile)) {
            continue;
        }

        XmlTag rootTag = ((XmlFile) file).getRootTag();
        if(rootTag == null) {
            continue;
        }

        XmlTag elements = rootTag.findFirstSubTag("elements");
        if(elements == null) {
            continue;
        }

        for (XmlTag element : elements.findSubTags("element")) {
            XmlTag xmlTag = element.findFirstSubTag("name");
            if(xmlTag != null) {
                String text = xmlTag.getValue().getText();
                if(StringUtils.isNotBlank(text)) {
                    pairConsumer.accept(Pair.create(text, xmlTag));
                }
            }
        }
    }
}
 
源代码6 项目: idea-php-symfony2-plugin   文件: EntityHelper.java
@NotNull
public static String getOrmClass(@NotNull PsiFile psiFile, @NotNull String className) {

    // force global namespace not need to search for class
    if(className.startsWith("\\")) {
        return className;
    }

    String entityName = null;

    // espend\Doctrine\ModelBundle\Entity\Bike:
    // ...
    // targetEntity: Foo
    if(psiFile instanceof YAMLFile) {
        YAMLDocument yamlDocument = PsiTreeUtil.getChildOfType(psiFile, YAMLDocument.class);
        if(yamlDocument != null) {
            YAMLKeyValue entityKeyValue = PsiTreeUtil.getChildOfType(yamlDocument, YAMLKeyValue.class);
            if(entityKeyValue != null) {
                entityName = entityKeyValue.getKeyText();
            }
        }
    } else if(psiFile instanceof XmlFile) {

        XmlTag rootTag = ((XmlFile) psiFile).getRootTag();
        if(rootTag != null) {
            XmlTag entity = rootTag.findFirstSubTag("entity");
            if(entity != null) {
                String name = entity.getAttributeValue("name");
                if(org.apache.commons.lang.StringUtils.isBlank(name)) {
                    entityName = name;
                }
            }
        }
    }

    if(entityName == null) {
        return className;
    }

    // trim class name
    int lastBackSlash = entityName.lastIndexOf("\\");
    if(lastBackSlash > 0) {
        String fqnClass = entityName.substring(0, lastBackSlash + 1) + className;
        if(PhpElementsUtil.getClass(psiFile.getProject(), fqnClass) != null) {
            return fqnClass;
        }
    }

    return className;
}
 
源代码7 项目: idea-php-symfony2-plugin   文件: ProfilerUtil.java
/**
 * ["foo/foo.html.twig": 1]
 *
 * <tr>
 *  <td>@Twig/Exception/traces_text.html.twig</td>
 *  <td class="font-normal">1</td>
 * </tr>
 */
public static Map<String, Integer> getRenderedElementTwigTemplates(@NotNull Project project, @NotNull String html) {
    HtmlFileImpl htmlFile = (HtmlFileImpl) PsiFileFactory.getInstance(project).createFileFromText(HTMLLanguage.INSTANCE, html);

    final XmlTag[] xmlTag = new XmlTag[1];
    PsiTreeUtil.processElements(htmlFile, psiElement -> {
        if(!(psiElement instanceof XmlTag) || !"h2".equals(((XmlTag) psiElement).getName())) {
            return true;
        }

        XmlTagValue keyTag = ((XmlTag) psiElement).getValue();
        String contents = StringUtils.trim(keyTag.getText());
        if(!"Rendered Templates".equalsIgnoreCase(contents)) {
            return true;
        }

        xmlTag[0] = (XmlTag) psiElement;

        return true;
    });

    if(xmlTag[0] == null) {
        return Collections.emptyMap();
    }

    XmlTag tableTag = PsiTreeUtil.getNextSiblingOfType(xmlTag[0], XmlTag.class);
    if(tableTag == null || !"table".equals(tableTag.getName())) {
        return Collections.emptyMap();
    }

    XmlTag tbody = tableTag.findFirstSubTag("tbody");
    if(tbody == null) {
        return Collections.emptyMap();
    }

    Map<String, Integer> templates = new HashMap<>();

    for (XmlTag tag : PsiTreeUtil.getChildrenOfTypeAsList(tbody, XmlTag.class)) {
        if(!"tr".equals(tag.getName())) {
            continue;
        }

        XmlTag[] tds = tag.findSubTags("td");
        if(tds.length < 2) {
            continue;
        }

        String template = stripHtmlTags(StringUtils.trim(tds[0].getValue().getText()));
        if(StringUtils.isBlank(template)) {
            continue;
        }

        Integer count;
        try {
            count = Integer.valueOf(stripHtmlTags(StringUtils.trim(tds[1].getValue().getText())));
        } catch (NumberFormatException e) {
            count = 0;
        }

        templates.put(template, count);
    }

    return templates;
}