Java Code Examples for com.intellij.psi.xml.XmlTag#findSubTags()
The following examples show how to use
com.intellij.psi.xml.XmlTag#findSubTags() .
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: FileResourceVisitorUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * <routes><import resource="FOO" /></routes> */ private static void visitXmlFile(@NotNull XmlFile psiFile, @NotNull Consumer<FileResourceConsumer> consumer) { XmlTag rootTag = psiFile.getRootTag(); if(rootTag == null || !"routes".equals(rootTag.getName())) { return; } for (XmlTag xmlTag : rootTag.findSubTags("import")) { String resource = xmlTag.getAttributeValue("resource"); if(StringUtils.isBlank(resource)) { continue; } consumer.consume(new FileResourceConsumer(xmlTag, xmlTag, normalize(resource))); } }
Example 2
Source File: TranslationInsertUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private static int getIdForNewXlfUnit(@NotNull XmlTag body, @NotNull String subTag) { int lastId = 0; for (XmlTag transUnit : body.findSubTags(subTag)) { String id = transUnit.getAttributeValue("id"); if(id == null) { continue; } Integer integer; try { integer = Integer.valueOf(id); } catch (NumberFormatException e) { continue; } // next safe id if(integer >= lastId) { lastId = integer + 1; } } return lastId; }
Example 3
Source File: ServiceTagFactory.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable private static Collection<ServiceTagInterface> create(@NotNull String serviceId, @NotNull XmlTag xmlTag) { final Collection<ServiceTagInterface> tags = new ArrayList<>(); for (XmlTag tag : xmlTag.findSubTags("tag")) { String name = tag.getAttributeValue("name"); if(name == null) { continue; } ServiceTagInterface serviceTagInterface = XmlServiceTag.create(serviceId, tag); if(serviceTagInterface == null) { continue; } tags.add(serviceTagInterface); } return tags; }
Example 4
Source File: LatteXmlFileDataFactory.java From intellij-latte with MIT License | 6 votes |
private static void loadTags(XmlTag customTags, LatteXmlFileData data) { for (XmlTag tag : customTags.findSubTags("tag")) { XmlAttribute name = tag.getAttribute("name"); XmlAttribute type = tag.getAttribute("type"); if (name == null || type == null || !LatteTagSettings.isValidType(type.getValue())) { continue; } LatteTagSettings macro = new LatteTagSettings( name.getValue(), LatteTagSettings.Type.valueOf(type.getValue()), isTrue(tag, "allowedFilters"), getTextValue(tag, "arguments"), isTrue(tag, "multiLine"), getTextValue(tag, "deprecatedMessage").trim(), getArguments(tag) ); data.addTag(macro); } }
Example 5
Source File: LatteXmlFileDataFactory.java From intellij-latte with MIT License | 6 votes |
private static void loadFilters(XmlTag customFilters, LatteXmlFileData data) { for (XmlTag filterData : customFilters.findSubTags("filter")) { XmlAttribute name = filterData.getAttribute("name"); if (name == null) { continue; } LatteFilterSettings filter = new LatteFilterSettings( name.getValue(), getTextValue(filterData, "description"), getTextValue(filterData, "arguments"), getTextValue(filterData, "insertColons") ); data.addFilter(filter); } }
Example 6
Source File: LatteXmlFileDataFactory.java From intellij-latte with MIT License | 6 votes |
private static void loadFunctions(XmlTag customFunctions, LatteXmlFileData data) { for (XmlTag filter : customFunctions.findSubTags("function")) { XmlAttribute name = filter.getAttribute("name"); if (name == null) { continue; } String returnType = getTextValue(filter, "returnType"); LatteFunctionSettings instance = new LatteFunctionSettings( name.getValue(), returnType.length() == 0 ? "mixed" : returnType, getTextValue(filter, "arguments"), getTextValue(filter, "description") ); data.addFunction(instance); } }
Example 7
Source File: LatteXmlFileDataFactory.java From intellij-latte with MIT License | 5 votes |
private static void loadVariables(XmlTag customVariables, LatteXmlFileData data) { for (XmlTag filter : customVariables.findSubTags("variable")) { XmlAttribute name = filter.getAttribute("name"); if (name == null ) { continue; } String varType = getTextValue(filter, "type"); LatteVariableSettings variable = new LatteVariableSettings( name.getValue(), varType.length() == 0 ? "mixed" : varType ); data.addVariable(variable); } }
Example 8
Source File: ServiceActionUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public static boolean isValidXmlParameterInspectionService(@NotNull XmlTag xmlTag) { // we dont support some attributes right now for(String s : INVALID_ARGUMENT_ATTRIBUTES) { if(xmlTag.getAttribute(s) != null) { return false; } } // <service autowire="[false|true]"/> String autowire = xmlTag.getAttributeValue("autowire"); if("true".equalsIgnoreCase(autowire)) { return false; } else if("false".equalsIgnoreCase(autowire)) { return true; } // <service><factory/></service> // symfony2 >= 2.6 if(xmlTag.findSubTags("factory").length > 0) { return false; } // <services autowire="true"><defaults/></services> PsiElement servicesTag = xmlTag.getParent(); if(servicesTag instanceof XmlTag && "services".equals(((XmlTag) servicesTag).getName())) { // <defaults autowire="true" /> for (XmlTag defaults : ((XmlTag) servicesTag).findSubTags("defaults")) { if("true".equalsIgnoreCase(defaults.getAttributeValue("autowire"))) { return false; } } } return true; }
Example 9
Source File: HaxelibUtil.java From intellij-haxe with Apache License 2.0 | 5 votes |
/** * Retrieves the list of dependent haxe libraries from an XML-based * configuration file. * * @param psiFile name of the configuration file to read * @return a list of dependent libraries; may be empty, won't have duplicates. */ @NotNull public static HaxeLibraryList getHaxelibsFromXmlFile(@NotNull XmlFile psiFile, HaxelibLibraryCache libraryManager) { List<HaxeLibraryReference> haxelibNewItems = new ArrayList<HaxeLibraryReference>(); XmlFile xmlFile = (XmlFile)psiFile; XmlDocument document = xmlFile.getDocument(); if (document != null) { XmlTag rootTag = document.getRootTag(); if (rootTag != null) { XmlTag[] haxelibTags = rootTag.findSubTags("haxelib"); for (XmlTag haxelibTag : haxelibTags) { String name = haxelibTag.getAttributeValue("name"); String ver = haxelibTag.getAttributeValue("version"); HaxelibSemVer semver = HaxelibSemVer.create(ver); if (name != null) { HaxeLibrary lib = libraryManager.getLibrary(name, semver); if (lib != null) { haxelibNewItems.add(lib.createReference(semver)); } else { LOG.warn("Library specified in XML file is not known to haxelib: " + name); } } } } } return new HaxeLibraryList(libraryManager.getSdk(), haxelibNewItems); }
Example 10
Source File: LatteXmlFileDataFactory.java From intellij-latte with MIT License | 5 votes |
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; }
Example 11
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
public static boolean isMUnitFile(PsiFile psiFile) { if (!(psiFile instanceof XmlFile)) { return false; } if (psiFile.getFileType() != StdFileTypes.XML) { return false; } final XmlFile psiFile1 = (XmlFile) psiFile; final XmlTag rootTag = psiFile1.getRootTag(); if (rootTag == null || !isMuleTag(rootTag)) { return false; } final XmlTag[] munitTags = rootTag.findSubTags(MUNIT_TEST_LOCAL_NAME, rootTag.getNamespaceByPrefix(MUNIT_NAMESPACE)); return munitTags.length > 0; }
Example 12
Source File: DefaultViewHelpersProvider.java From idea-php-typo3-plugin with MIT License | 4 votes |
@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); }
Example 13
Source File: ConfigUtil.java From idea-php-shopware-plugin with MIT License | 4 votes |
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)); } } } } }
Example 14
Source File: MuleSchemaUtils.java From mule-intellij-plugins with Apache License 2.0 | 4 votes |
@Nullable private static XmlTag getComplexContents(XmlTag complexTypeTag) { final XmlTag[] complexContents = complexTypeTag.findSubTags("complexContent", HTTP_WWW_W3_ORG_2001_XMLSCHEMA); return complexContents.length > 0 ? complexContents[0] : null; }
Example 15
Source File: ProfilerUtil.java From idea-php-symfony2-plugin with MIT License | 4 votes |
/** * ["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; }
Example 16
Source File: MuleSchemaUtils.java From mule-intellij-plugins with Apache License 2.0 | 4 votes |
@Nullable private static XmlTag getExtensions(XmlTag complexContent) { final XmlTag[] complexContents = complexContent.findSubTags("extension", HTTP_WWW_W3_ORG_2001_XMLSCHEMA); return complexContents.length > 0 ? complexContents[0] : null; }
Example 17
Source File: MuleElementDefinitionService.java From mule-intellij-plugins with Apache License 2.0 | 4 votes |
@NotNull private List<MuleModuleDefinition> getModuleDefinitions(Project project, GlobalSearchScope searchScope) { final List<MuleModuleDefinition> result = new ArrayList<>(); final Collection<VirtualFile> files = FileTypeIndex.getFiles(XmlFileType.INSTANCE, searchScope); for (VirtualFile file : files) { final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file); if (xmlFile != null && isMuleSchema(xmlFile)) { // System.out.println("xmlFile = " + xmlFile.getName()); final PsiElement[] children = xmlFile.getChildren(); final XmlTag rootTag = ((XmlDocument) children[0]).getRootTag(); if (rootTag != null) { final String namespace = getNamespace(rootTag); final String name = ArrayUtil.getLastElement(namespace.split("/")); // System.out.println("namespace = " + namespace); // System.out.println("name = " + name); final XmlTag[] elements = rootTag.findSubTags("element", MuleSchemaUtils.HTTP_WWW_W3_ORG_2001_XMLSCHEMA); final List<MuleElementDefinition> definitions = new ArrayList<>(); for (XmlTag element : elements) { final String elementName = element.getAttributeValue("name"); // System.out.println("name = " + elementName); final MuleElementType muleElementType = MuleSchemaUtils.getMuleElementTypeFromElement(element); if (muleElementType != null) { String description = ""; final XmlTag annotation = ArrayUtil.getFirstElement(element.findSubTags("annotation", MuleSchemaUtils.HTTP_WWW_W3_ORG_2001_XMLSCHEMA)); if (annotation != null) { final XmlTag documentation = ArrayUtil.getFirstElement(annotation.findSubTags("documentation", MuleSchemaUtils.HTTP_WWW_W3_ORG_2001_XMLSCHEMA)); if (documentation != null) { description = documentation.getValue().getText(); } } definitions.add(new MuleElementDefinition(element, elementName, description, muleElementType)); // System.out.println("muleElementType = " + muleElementType); // System.out.println("description = " + description); } } result.add(new MuleModuleDefinition(name, StringUtil.capitalize(name), namespace, xmlFile, definitions)); } } } return result; }