Java Code Examples for com.intellij.psi.xml.XmlFile#getRootTag()
The following examples show how to use
com.intellij.psi.xml.XmlFile#getRootTag() .
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: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
public static List<XmlTag> findFlowRefsForFlow(@NotNull XmlTag flow) { List<XmlTag> flowRefs = new ArrayList<>(); final Project project = flow.getProject(); final String flowName = flow.getAttributeValue(MuleConfigConstants.NAME_ATTRIBUTE); Collection<VirtualFile> vFiles = FileTypeIndex.getFiles(StdFileTypes.XML, ProjectScope.getContentScope(project)); for (VirtualFile virtualFile : vFiles) { PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); if (psiFile != null) { XmlFile xmlFile = (XmlFile) psiFile; XmlTag mule = xmlFile.getRootTag(); FlowRefsFinder finder = new FlowRefsFinder(flowName); mule.accept(finder); flowRefs.addAll(finder.getFlowRefs()); } } return flowRefs; }
Example 2
Source File: MuleSchemaUtils.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
public static void insertSchemaLocationLookup(XmlFile xmlFile, String namespace, String locationLookup) { final XmlTag rootTag = xmlFile.getRootTag(); if (rootTag == null) return; final XmlAttribute attribute = rootTag.getAttribute("xsi:schemaLocation", HTTP_WWW_W3_ORG_2001_XMLSCHEMA); if (attribute != null) { final String value = attribute.getValue(); attribute.setValue(value + "\n\t\t\t" + namespace + " " + locationLookup); } else { final XmlElementFactory elementFactory = XmlElementFactory.getInstance(xmlFile.getProject()); final XmlAttribute schemaLocation = elementFactory.createXmlAttribute("xsi:schemaLocation", XmlUtil.XML_SCHEMA_INSTANCE_URI); schemaLocation.setValue(namespace + " " + locationLookup); rootTag.add(schemaLocation); } }
Example 3
Source File: XmlCamelIdeaUtils.java From camel-idea-plugin with Apache License 2.0 | 6 votes |
@Override public boolean isPlaceForEndpointUri(PsiElement location) { XmlFile file = PsiTreeUtil.getParentOfType(location, XmlFile.class); if (file == null || file.getRootTag() == null || !isAcceptedNamespace(file.getRootTag().getNamespace())) { return false; } XmlAttributeValue value = PsiTreeUtil.getParentOfType(location, XmlAttributeValue.class, false); if (value == null) { return false; } XmlAttribute attr = PsiTreeUtil.getParentOfType(location, XmlAttribute.class); if (attr == null) { return false; } return attr.getLocalName().equals("uri") && isInsideCamelRoute(location, false); }
Example 4
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 5
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
public static boolean isMuleFile(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(); return isMuleTag(rootTag); }
Example 6
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 7
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
@Nullable public static XmlTag getXmlTagAt(Project project, XSourcePosition sourcePosition) { final VirtualFile file = sourcePosition.getFile(); final XmlFile xmlFile = (XmlFile) PsiManager.getInstance(project).findFile(file); final XmlTag rootTag = xmlFile.getRootTag(); return findXmlTag(sourcePosition, rootTag); }
Example 8
Source File: WeaveEditor.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private boolean isMuleFile(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(); return rootTag.getLocalName().equalsIgnoreCase("mule"); }
Example 9
Source File: MuleElementInsertHandler.java From mule-intellij-plugins with Apache License 2.0 | 4 votes |
@Nullable public static String getPrefixByNamespace(XmlFile file, final String namespace) { final XmlTag tag = file.getRootTag(); return tag == null ? null : tag.getPrefixByNamespace(namespace); }
Example 10
Source File: DoctrineUtil.java From idea-php-symfony2-plugin with MIT License | 4 votes |
/** * Extract class and repository from xml meta files * We support orm and all odm syntax here */ @Nullable private static Collection<Pair<String, String>> getClassRepositoryPair(@NotNull XmlFile xmlFile) { XmlTag rootTag = xmlFile.getRootTag(); if(rootTag == null || !rootTag.getName().toLowerCase().startsWith("doctrine")) { return null; } Collection<Pair<String, String>> pairs = new ArrayList<>(); for (XmlTag xmlTag : (XmlTag[]) ArrayUtils.addAll(rootTag.findSubTags("document"), rootTag.findSubTags("entity"))) { XmlAttribute attr = xmlTag.getAttribute("name"); if(attr == null) { continue; } String value = attr.getValue(); if(StringUtils.isBlank(value)) { continue; } // extract repository-class; allow nullable String repositoryClass = null; XmlAttribute repositoryClassAttribute = xmlTag.getAttribute("repository-class"); if(repositoryClassAttribute != null) { String repositoryClassAttributeValue = repositoryClassAttribute.getValue(); if(StringUtils.isNotBlank(repositoryClassAttributeValue)) { repositoryClass = repositoryClassAttributeValue; } } pairs.add(Pair.create(value, repositoryClass)); } if(pairs.size() == 0) { return null; } return pairs; }