Java Code Examples for com.intellij.psi.xml.XmlTag#getAttributeValue()
The following examples show how to use
com.intellij.psi.xml.XmlTag#getAttributeValue() .
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: ServiceActionUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public static PhpClass getPhpClassFromXmlTag(@NotNull XmlTag xmlTag, @NotNull ContainerCollectionResolver.LazyServiceCollector collector) { String className = xmlTag.getAttributeValue("class"); if(className == null) { String id = xmlTag.getAttributeValue("id"); if(id == null || !YamlHelper.isClassServiceId(id)) { return null; } className = id; } // @TODO: cache defs PhpClass resolvedClassDefinition = ServiceUtil.getResolvedClassDefinition(xmlTag.getProject(), className, collector); if(resolvedClassDefinition == null) { return null; } return resolvedClassDefinition; }
Example 3
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 4
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
public void visitElement(PsiElement element) { super.visitElement(element); if (element != null && element instanceof XmlTag) { XmlTag tag = (XmlTag) element; if (MuleConfigConstants.FLOW_REF_TAG_NAME.equals(tag.getName())) { String fn = tag.getAttributeValue(MuleConfigConstants.NAME_ATTRIBUTE); if (flowName.equals(fn)) flowRefs.add(tag); } } }
Example 5
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 6
Source File: SVGParser.java From svgtoandroid with MIT License | 5 votes |
private String getValueFromRootTag(String key) { if (svg.getDocument() != null) { XmlTag rootTag = svg.getDocument().getRootTag(); if (rootTag != null) { XmlAttribute attribute = rootTag.getAttribute(key); if (attribute != null) { return rootTag.getAttributeValue(key); } } } return null; }
Example 7
Source File: XmlGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable @Override public String findIdForElement(@NotNull PsiElement psiElement) { XmlTag parentOfType = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class); if(parentOfType == null) { return null; } return parentOfType.getAttributeValue("id"); }
Example 8
Source File: SVGAttrParser.java From svgtoandroid with MIT License | 5 votes |
private static String getPathValue(XmlTag tag) { String rawValue = tag.getAttributeValue("d"); if (rawValue != null) { return VectorDrawableFixinator.getContentWithFixedFloatingPoints(rawValue); } return rawValue; }
Example 9
Source File: XmlIdeaUtils.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
@Override public boolean isElementFromSetterProperty(@NotNull PsiElement element, @NotNull String setter) { // its maybe an XML property XmlTag xml = PsiTreeUtil.getParentOfType(element, XmlTag.class); if (xml != null) { boolean bean = isFromXmlTag(xml, "bean", "property"); if (bean) { String key = xml.getAttributeValue("name"); return setter.equals(key); } } return false; }
Example 10
Source File: TranslationIndex.java From idea-php-typo3-plugin with MIT License | 5 votes |
void extractTranslationStub(@NotNull XmlTag tag) { String id = tag.getAttributeValue("id"); String languageKeyToUse = String.valueOf(languageKey); XmlTag fileTag = (XmlTag) PsiTreeUtil.findFirstParent(tag, t -> PlatformPatterns.psiElement(XmlTag.class).withName("file").accepts(t)); String sourceValue = ""; String targetValue = ""; if (fileTag != null) { if (fileTag.getAttributeValue("source-language") != null) { sourceValue = fileTag.getAttributeValue("source-language"); } if (fileTag.getAttributeValue("target-language") != null) { targetValue = fileTag.getAttributeValue("target-language"); } } if (!sourceValue.isEmpty() && !targetValue.isEmpty()) { languageKeyToUse = targetValue; } String[] compileIds; try { compileIds = compileIds(file, extensionKeyFromFile, id); } catch (FileNotFoundException e) { return; } for (String calculatedId : compileIds) { if (result.containsKey(calculatedId)) { result.get(calculatedId).add(createStubTranslationFromIndex(file, extensionKeyFromFile, languageKeyToUse, tag, id)); } else { ArrayList<StubTranslation> v = new ArrayList<>(); v.add(createStubTranslationFromIndex(file, extensionKeyFromFile, languageKeyToUse, tag, id)); result.put(calculatedId, v); } } }
Example 11
Source File: XmlServiceTag.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable public static ServiceTagInterface create(@NotNull String serviceId, @NotNull XmlTag xmlTag) { String name = xmlTag.getAttributeValue("name"); if(StringUtils.isBlank(name)) { return null; } return new XmlServiceTag(name, serviceId, xmlTag); }
Example 12
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
@NotNull private static String getPrefix(XmlTag weavePart) { final String localName = weavePart.getLocalName(); if (localName.equals("set-payload")) { return "payload:"; } else if (localName.equals("set-variable")) { return "flowVar:" + weavePart.getAttributeValue("variableName"); } else if (localName.equals("set-property")) { return "property:" + weavePart.getAttributeValue("propertyName"); } else if (localName.equals("set-session-variable")) { return "sessionVar:" + weavePart.getAttributeValue("variableName"); } return "payload:"; }
Example 13
Source File: FlowGoToSymbol.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
@Override protected void addItems(@NotNull Module module, String name, List<NavigationItem> list) { final XmlTag flow = MuleConfigUtils.findFlow(module, name); if (flow != null) { final String flowName = flow.getAttributeValue(MuleConfigConstants.NAME_ATTRIBUTE); if (flowName != null) { list.add(createNavigationItem(flow, flowName, MuleIcons.MuleFlow)); } } }
Example 14
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 15
Source File: InTemplateDeclarationVariableProvider.java From idea-php-typo3-plugin with MIT License | 5 votes |
@Override public void visitXmlTag(XmlTag tag) { if (tag.getName().equals("f:variable")) { String variableName = tag.getAttributeValue("name"); if (variableName != null && !variableName.isEmpty()) { variables.put(variableName, new FluidVariable(variableName)); } } super.visitXmlTag(tag); }
Example 16
Source File: TranslationIndex.java From idea-php-typo3-plugin with MIT License | 5 votes |
@Override void extractTranslationStub(@NotNull XmlTag tag) { String id = tag.getAttributeValue("index"); String[] compiledIds; try { compiledIds = compileIds(file, extensionKeyFromFile, id); } catch (FileNotFoundException e) { return; } for (String calculatedId : compiledIds) { XmlTag languageKeyTag = (XmlTag) PsiTreeUtil.findFirstParent(tag, t -> PlatformPatterns.psiElement(XmlElementType.XML_TAG).withName("languageKey").accepts(t)); if (languageKeyTag != null && languageKeyTag.getAttributeValue("index") != null) { if (result.containsKey(calculatedId)) { result.get(calculatedId).add(createStubTranslationFromIndex(file, extensionKeyFromFile, languageKeyTag.getAttributeValue("index"), tag, id)); } else { result.put(calculatedId, new ArrayList<StubTranslation>() {{ add(createStubTranslationFromIndex(file, extensionKeyFromFile, languageKeyTag.getAttributeValue("index"), tag, id)); }}); } } else { if (result.containsKey(calculatedId)) { result.get(calculatedId).add(createStubTranslationFromIndex(file, extensionKeyFromFile, String.valueOf(this.languageKey), tag, id)); } else { result.put(calculatedId, new ArrayList<StubTranslation>() {{ createStubTranslationFromIndex(file, extensionKeyFromFile, String.valueOf(languageKey), tag, id); }}); } } } }
Example 17
Source File: GlobalConfigsTreeStructure.java From mule-intellij-plugins with Apache License 2.0 | 4 votes |
public GlobalConfigNode(SimpleNode aParent, XmlTag tag) { super(aParent, tag.getAttributeValue("name")); myTag = tag; myClosedIcon = MuleIcons.ConnectorIcon; updatePresentation(); }
Example 18
Source File: EntityHelper.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@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; }
Example 19
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; }
Example 20
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); }