com.intellij.psi.xml.XmlTag Java Examples
The following examples show how to use
com.intellij.psi.xml.XmlTag.
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: 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 #2
Source File: Transformer.java From svgtoandroid with MIT License | 6 votes |
private String decideFillColor(XmlTag group, XmlTag self) { String result = Configuration.getDefaultTint(); XmlAttribute groupFill; if ((groupFill = group.getAttribute("fill")) != null) { result = StdColorUtil.formatColor(groupFill.getValue()); } XmlAttribute selfFill; if ((selfFill = self.getAttribute("fill")) != null) { result = StdColorUtil.formatColor(selfFill.getValue()); } XmlAttribute id = self.getAttribute("class"); String colorFromStyle; if (id != null && id.getValue() != null && (colorFromStyle = styleParser.getFillColor(id.getValue())) != null) { result = colorFromStyle; } return result; }
Example #3
Source File: DefaultViewHelpersProvider.java From idea-php-typo3-plugin with MIT License | 6 votes |
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(); }
Example #4
Source File: ShopwareXmlCompletion.java From idea-php-shopware-plugin with MIT License | 6 votes |
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement psiElement = completionParameters.getOriginalPosition(); if(psiElement == null || !ShopwareProjectComponent.isValidForProject(psiElement)) { return; } PsiElement parent = psiElement.getParent(); if(!(parent instanceof XmlTag)) { return; } String controllerName = getControllerOnScope((XmlTag) parent); if (controllerName == null) { return; } ShopwareUtil.collectControllerAction(psiElement.getProject(), controllerName, (method, methodStripped, moduleName, controllerName1) -> { LookupElementBuilder lookupElement = LookupElementBuilder.create(methodStripped) .withIcon(method.getIcon()) .withTypeText(method.getName(), true); completionResultSet.addElement(lookupElement); }, "Backend"); }
Example #5
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 #6
Source File: XmlServiceArgumentIntention.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) throws IncorrectOperationException { XmlTag xmlTag = getServiceTagValid(psiElement); if(xmlTag == null) { return; } final List<String> args = ServiceActionUtil.getXmlMissingArgumentTypes(xmlTag, true, new ContainerCollectionResolver.LazyServiceCollector(project)); if (args.size() == 0) { return; } ServiceActionUtil.fixServiceArgument(args, xmlTag); }
Example #7
Source File: XmlHelperTest.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * @see XmlHelper#getArgumentIndex */ public void testGetArgumentIndexOnIndex() { myFixture.configureByText(XmlFileType.INSTANCE, "" + "<service class=\"Foo\\Bar\">\n" + " <argum<caret>ent index=\"2\" />\n" + "</service>" ); PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); assertEquals(2, XmlHelper.getArgumentIndex((XmlTag) psiElement.getParent())); myFixture.configureByText(XmlFileType.INSTANCE, "" + "<service class=\"Foo\\Bar\">\n" + " <argum<caret>ent index=\"foobar\" />\n" + "</service>" ); psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); assertEquals(-1, XmlHelper.getArgumentIndex((XmlTag) psiElement.getParent())); }
Example #8
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 #9
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 #10
Source File: TranslationUtilTest.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public void testGetTargetForXlfAsXmlFileInVersion12() { PsiFile fileFromText = PsiFileFactory.getInstance(getProject()).createFileFromText(XMLLanguage.INSTANCE, "" + "<?xml version=\"1.0\"?>\n" + "<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\">\n" + " <file source-language=\"en\" datatype=\"plaintext\" original=\"file.ext\">\n" + " <body>\n" + " <trans-unit id=\"1\">\n" + " <source>This value should be false.</source>\n" + " </trans-unit>\n" + " </body>\n" + " </file>\n" + "</xliff>\n" ); Collection<PsiElement> files = TranslationUtil.getTargetForXlfAsXmlFile((XmlFile) fileFromText, "This value should be false."); assertNotNull(ContainerUtil.find(files, psiElement -> psiElement instanceof XmlTag && "This value should be false.".equals(((XmlTag) psiElement).getValue().getText())) ); }
Example #11
Source File: WeexAttrDescriptorProvider.java From weex-language-support with MIT License | 6 votes |
@Override public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag xmlTag) { if (!WeexFileUtil.isOnWeexFile(xmlTag)) { return new XmlAttributeDescriptor[0]; } final Map<String, XmlAttributeDescriptor> result = new LinkedHashMap<String, XmlAttributeDescriptor>(); WeexTag tag = DirectiveLint.getWeexTag(xmlTag.getName()); if (tag == null) { return new XmlAttributeDescriptor[0]; } for (String attributeName : tag.getExtAttrs()) { result.put(attributeName, new WeexAttrDescriptor(attributeName, tag.getAttribute(attributeName).valueEnum, null)); } return result.values().toArray(new XmlAttributeDescriptor[result.size()]); }
Example #12
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
private static XmlTag findChildMessageProcessorByPath(MessageProcessorPath messageProcessorPath, XmlTag xmlTag) { final List<MessageProcessorPathNode> nodes = messageProcessorPath.getNodes(); for (MessageProcessorPathNode node : nodes) { final String elementName = node.getElementName(); final int i = Integer.parseInt(elementName); final XmlTag[] subTags = xmlTag.getSubTags(); int index = -1; for (XmlTag subTag : subTags) { final MuleElementType muleElementType = getMuleElementTypeFromXmlElement(subTag); if (muleElementType == MuleElementType.MESSAGE_PROCESSOR) { xmlTag = subTag; index = index + 1; } if (index == i) { break; } } } return xmlTag; }
Example #13
Source File: XmlLineMarkerProvider.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> result) { if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) { return; } LazyDecoratedParentServiceValues lazyDecoratedParentServiceValues = null; for (PsiElement psiElement : psiElements) { if(!XmlHelper.getXmlTagNameLeafStartPattern().accepts(psiElement)) { continue; } PsiElement xmlTag = psiElement.getParent(); if(!(xmlTag instanceof XmlTag) || !getServiceIdPattern().accepts(xmlTag)) { continue; } if(lazyDecoratedParentServiceValues == null) { lazyDecoratedParentServiceValues = new LazyDecoratedParentServiceValues(psiElement.getProject()); } // <services><service id="foo"/></services> visitServiceId(psiElement, (XmlTag) xmlTag, result, lazyDecoratedParentServiceValues); } }
Example #14
Source File: StringTableKey.java From arma-intellij-plugin with MIT License | 6 votes |
/** * Get documentation html for the given StringTable key XmlTag (this should be one returned from {@link #getIDXmlTag()}) * * @param element key's tag * @return html showing all languages' values, or null if element was null, or null if element wasn't a key tag */ @Nullable public static String getKeyDoc(@Nullable XmlTag element) { if (element == null) { return null; } if (!element.getName().equalsIgnoreCase("key")) { return null; } final String format = "<div><b>%s</b> : <pre>%s</pre></div>"; StringBuilder doc = new StringBuilder(); for (XmlTag childTag : element.getSubTags()) { doc.append(String.format(format, childTag.getName(), childTag.getText())); } return doc.toString(); }
Example #15
Source File: RouteHelper.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * <route controller="Foo"/> * <route> * <default key="_controller">Foo</default> * </route> */ @Nullable public static String getXmlController(@NotNull XmlTag serviceTag) { for(XmlTag subTag :serviceTag.getSubTags()) { if("default".equalsIgnoreCase(subTag.getName())) { String keyValue = subTag.getAttributeValue("key"); if(keyValue != null && "_controller".equals(keyValue)) { String actionName = subTag.getValue().getTrimmedText(); if(StringUtils.isNotBlank(actionName)) { return actionName; } } } } String controller = serviceTag.getAttributeValue("controller"); if(controller != null && StringUtils.isNotBlank(controller)) { return controller; } return null; }
Example #16
Source File: XmlServiceArgumentIntention.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public static XmlTag getServiceTagValid(@NotNull PsiElement psiElement) { XmlTag xmlTag = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class); if(xmlTag == null) { return null; } if("service".equals(xmlTag.getName())) { return xmlTag; } xmlTag = PsiTreeUtil.getParentOfType(xmlTag, XmlTag.class); if(xmlTag != null && "service".equals(xmlTag.getName())) { return xmlTag; } return null; }
Example #17
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 #18
Source File: RTErrorFilter.java From react-templates-plugin with MIT License | 6 votes |
@Override public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement error) { final Project project = error.getProject(); final Language language = error.getLanguage(); // if ("CSS".equals(language.getID()) && PsiTreeUtil.getParentOfType(error, XmlAttribute.class) != null && // AngularIndexUtil.hasAngularJS(project)) { // final PsiFile file = error.getContainingFile(); // // PsiErrorElement nextError = error; // while (nextError != null) { // if (hasAngularInjectionAt(project, file, nextError.getTextOffset())) return false; // nextError = PsiTreeUtil.getNextSiblingOfType(nextError, PsiErrorElement.class); // } // } if (HTMLLanguage.INSTANCE.is(language) && error.getErrorDescription().endsWith("not closed")) { System.out.println(error.getErrorDescription()); final PsiElement parent = error.getParent(); final XmlElementDescriptor descriptor = parent instanceof XmlTag ? ((XmlTag) parent).getDescriptor() : null; return !(descriptor instanceof RTRequireTagDescriptor); } return true; }
Example #19
Source File: StringTableKey.java From arma-intellij-plugin with MIT License | 6 votes |
/** * Get documentation html for the given StringTable key XmlTag (this should be one returned from {@link #getIDXmlTag()}) * * @param element key's tag * @return html showing all languages' values, or null if element was null, or null if element wasn't a key tag */ @Nullable public static String getKeyDoc(@Nullable XmlTag element) { if (element == null) { return null; } if (!element.getName().equalsIgnoreCase("key")) { return null; } final String format = "<div><b>%s</b> : <pre>%s</pre></div>"; StringBuilder doc = new StringBuilder(); for (XmlTag childTag : element.getSubTags()) { doc.append(String.format(format, childTag.getName(), childTag.getText())); } return doc.toString(); }
Example #20
Source File: FlowRefPsiReference.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
public boolean isReferenceTo(PsiElement element) { if (element == null) return false; PsiElement parent = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (parent != null && parent instanceof XmlTag && (MuleConfigConstants.FLOW_TAG_NAME.equals(((XmlTag)parent).getName()) || MuleConfigConstants.SUB_FLOW_TAG_NAME.equals(((XmlTag)parent).getName()))) { //It's a <flow> tag or <sub-flow> tag if (element instanceof XmlAttributeValue && ((XmlAttributeValue)element).getValue().equals(getFlowName())) { return true; } } return false; }
Example #21
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
@Nullable private static XmlTag findFlowInFile(Project project, String flowName, VirtualFile file) { final DomManager manager = DomManager.getDomManager(project); final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file); if (isMuleFile(xmlFile)) { final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class); if (fileElement != null) { final Mule rootElement = fileElement.getRootElement(); final List<Flow> flows = rootElement.getFlows(); for (Flow flow : flows) { if (flowName.equals(flow.getName().getValue())) { return flow.getXmlTag(); } } final List<SubFlow> subFlows = rootElement.getSubFlows(); for (SubFlow subFlow : subFlows) { if (flowName.equals(subFlow.getName().getValue())) { return subFlow.getXmlTag(); } } } } return null; }
Example #22
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
private static XmlTag findXmlTag(XSourcePosition sourcePosition, XmlTag rootTag) { final XmlTag[] subTags = rootTag.getSubTags(); for (int i = 0; i < subTags.length; i++) { XmlTag subTag = subTags[i]; final int subTagLineNumber = getLineNumber(sourcePosition.getFile(), subTag); if (subTagLineNumber == sourcePosition.getLine()) { return subTag; } else if (subTagLineNumber > sourcePosition.getLine() && i > 0 && subTags[i - 1].getSubTags().length > 0) { return findXmlTag(sourcePosition, subTags[i - 1]); } } if (subTags.length > 0) { final XmlTag lastElement = subTags[subTags.length - 1]; return findXmlTag(sourcePosition, lastElement); } else { return null; } }
Example #23
Source File: TranslationUtilTest.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public void testGetTargetForXlfAsXmlFileInVersion20() { PsiFile fileFromText = PsiFileFactory.getInstance(getProject()).createFileFromText(XMLLanguage.INSTANCE, "" + "<?xml version=\"1.0\"?>\n" + "<xliff xmlns=\"urn:oasis:names:tc:xliff:document:2.0\"\n" + " version=\"2.0\" srcLang=\"en-US\" trgLang=\"ja-JP\">\n" + " <file id=\"f1\" original=\"Graphic Example.psd\">\n" + " <skeleton href=\"Graphic Example.psd.skl\"/>\n" + " <group id=\"1\">\n" + " <unit id=\"1\">\n" + " <segment>\n" + " <source>foo</source>\n" + " </segment>\n" + " </unit>\n" + " </group>\n" + " </file>\n" + "</xliff>" ); Collection<PsiElement> files = TranslationUtil.getTargetForXlfAsXmlFile((XmlFile) fileFromText, "foo"); assertNotNull(ContainerUtil.find(files, psiElement -> psiElement instanceof XmlTag && "foo".equals(((XmlTag) psiElement).getValue().getText())) ); }
Example #24
Source File: FlowRenameDialog.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
protected void doAction() { LOG.assertTrue(this.myElement.isValid()); CommandProcessor.getInstance().executeCommand(this.myProject, () -> { ApplicationManager.getApplication().runWriteAction(() -> { try { final List<XmlTag> refs = MuleConfigUtils.findFlowRefsForFlow(this.myTag); this.myTag.getAttribute(MuleConfigConstants.NAME_ATTRIBUTE).setValue(this.getNewName()); for (XmlTag ref : refs) { ref.getAttribute(MuleConfigConstants.NAME_ATTRIBUTE).setValue(this.getNewName()); } } catch (IncorrectOperationException var2) { LOG.error(var2); } }); }, RefactoringBundle.message("rename.title"), (Object)null); this.close(0); }
Example #25
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 #26
Source File: BeanUtils.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public PsiClass getPropertyBeanClass(XmlTag propertyTag) { XmlTag beanTag = propertyTag.getParentTag(); if (beanTag != null && isBeanDeclaration(beanTag)) { IdeaUtils ideaUtils = IdeaUtils.getService(); JavaClassUtils javaClassUtils = JavaClassUtils.getService(); return ideaUtils.findAttributeValue(beanTag, "class") .map(javaClassUtils::findClassReference) .map(javaClassUtils::resolveClassReference) .orElse(null); } return null; }
Example #27
Source File: ServiceActionUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public static void addServices(List<String> items, XmlTag xmlTag) { for (String item : items) { if(StringUtils.isBlank(item)) { item = "?"; } XmlTag tag = XmlElementFactory.getInstance(xmlTag.getProject()).createTagFromText(String.format("<argument type=\"service\" id=\"%s\"/>", item), xmlTag.getLanguage()); xmlTag.addSubTag(tag, false); } }
Example #28
Source File: CamelDirectEndpointReferenceTest.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
public void testXmlDirectEndpointReference() { myFixture.configureByText("route-with-references.xml", XML_ROUTE_WITH_REFERENCE); PsiElement element = TestReferenceUtil.getParentElementAtCaret(myFixture); List<XmlTag> results = TestReferenceUtil.resolveReference(element, XmlTag.class); assertEquals(1, results.size()); assertEquals("<from uri=\"direct:def\"/>", results.get(0).getText()); }
Example #29
Source File: MuleTopElementLiveTemplateContextType.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
public boolean isInContext(@NotNull final PsiFile file, final int offset) { if (!MuleConfigUtils.isMuleFile(file)) { return false; } PsiElement element = file.findElementAt(offset); XmlTag parent = PsiTreeUtil.getParentOfType(element, XmlTag.class); return (element != null && parent != null && MuleConfigUtils.isMuleTag(parent)); }
Example #30
Source File: RTClassTagDescriptor.java From react-templates-plugin with MIT License | 5 votes |
@Override public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) { XmlTag parent = contextTag.getParentTag(); if (parent == null) return null; final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true); return descriptor == null ? null : descriptor.getElementDescriptor(childTag); }