Java Code Examples for com.intellij.psi.xml.XmlAttribute#getValue()
The following examples show how to use
com.intellij.psi.xml.XmlAttribute#getValue() .
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: FormUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public static Set<String> getTags(XmlTag serviceTag) { Set<String> tags = new HashSet<>(); for(XmlTag serviceSubTag: serviceTag.getSubTags()) { if("tag".equals(serviceSubTag.getName())) { XmlAttribute attribute = serviceSubTag.getAttribute("name"); if(attribute != null) { String tagName = attribute.getValue(); if(tagName != null && StringUtils.isNotBlank(tagName)) { tags.add(tagName); } } } } return tags; }
Example 2
Source File: Sqls2XmlNavigationHandler.java From NutzCodeInsight with Apache License 2.0 | 6 votes |
private PsiClass findJavaPsiClass(PsiElement psiElement) { XmlTag parentOfType = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class); if (parentOfType.getName().equals("Sqls")) { XmlAttribute aClass = parentOfType.getAttribute("class"); if (Objects.nonNull(aClass)) { String value = aClass.getValue(); String[] split = value.split("\\."); Collection<PsiClass> roleBizImpl = JavaShortClassNameIndex.getInstance().get(split[split.length - 1], psiElement.getProject(), GlobalSearchScope.projectScope(psiElement.getProject())); for (PsiClass psiClass : roleBizImpl) { if (psiClass.getQualifiedName().equals(value)) { return psiClass; } } } } return null; }
Example 3
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 4
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 5
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 6
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 7
Source File: ControllerMethodInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable @Override public String getRouteName() { XmlTag defaultTag = PsiTreeUtil.getParentOfType(this.psiElement, XmlTag.class); if(defaultTag != null) { XmlTag routeTag = PsiTreeUtil.getParentOfType(defaultTag, XmlTag.class); if(routeTag != null) { XmlAttribute id = routeTag.getAttribute("id"); if(id != null) { return id.getValue(); } } } return null; }
Example 8
Source File: Sqls2XmlNavigationHandler.java From NutzCodeInsight with Apache License 2.0 | 5 votes |
@Override public List<PsiElement> findReferences(PsiElement psiElement) { XmlTag xmlTag = (XmlTag) psiElement; XmlAttribute xmlAttribute = xmlTag.getAttribute("id"); if (xmlTag.getName().equals("sql") && Objects.nonNull(xmlAttribute)) { String id = xmlAttribute.getValue(); PsiClass javaPsiClass = findJavaPsiClass(psiElement); if (Objects.nonNull(javaPsiClass)) { return SqlsXmlUtil.findJavaPsiElement(javaPsiClass, id); } } return Arrays.asList(); }
Example 9
Source File: MuleSchemaUtils.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
@Nullable public static PsiReference getSchemaReference(XmlAttribute base) { if (base != null && base.getValueElement() != null) { final String text = base.getValue(); if (text != null && text.indexOf(":") > 0) { final String prefix = text.substring(0, text.indexOf(":")); return SchemaReferencesProvider.createTypeOrElementOrAttributeReference(base.getValueElement(), prefix); } else { return SchemaReferencesProvider.createTypeOrElementOrAttributeReference(base.getValueElement()); } } return null; }
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: BeanReferenceProvider.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
@Override protected PsiReference[] getAttributeReferences(@NotNull XmlAttribute attribute, @NotNull XmlAttributeValue value, ProcessingContext context) { String beanId = attribute.getValue(); if (beanId != null && beanId.length() > 0) { if ("ref".equals(attribute.getLocalName())) { return new PsiReference[] {new BeanReference(value, beanId)}; } else if ("id".equals(attribute.getLocalName())) { return new PsiReference[] {new BeanSelfReference(value, beanId)}; } } return PsiReference.EMPTY_ARRAY; }
Example 12
Source File: LatteXmlFileDataFactory.java From intellij-latte with MIT License | 5 votes |
private static String getTextValue(XmlTag tag, String attrName) { XmlAttribute attribute = tag.getAttribute(attrName); if (attribute == null || attribute.getValue() == null) { return ""; } return attribute.getValue(); }
Example 13
Source File: HtmlNSNamespaceProvider.java From idea-php-typo3-plugin with MIT License | 5 votes |
@Override public void visitXmlAttribute(XmlAttribute attribute) { if (attribute.getName().startsWith("xmlns:") && attribute.getValue() != null) { if (attribute.getValue().startsWith(fluidNamespaceURIPrefix)) { namespaces.add(new FluidNamespace(attribute.getLocalName(), attribute.getValue().substring(fluidNamespaceURIPrefix.length()))); } } super.visitXmlAttribute(attribute); }
Example 14
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 15
Source File: XmlServiceTagIntention.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Override public void invoke(@NotNull final Project project, final Editor editor, @NotNull PsiElement psiElement) throws IncorrectOperationException { final XmlTag xmlTag = XmlServiceArgumentIntention.getServiceTagValid(psiElement); if(xmlTag == null) { return; } final PhpClass phpClassFromXmlTag = ServiceActionUtil.getPhpClassFromXmlTag(xmlTag, new ContainerCollectionResolver.LazyServiceCollector(project)); if(phpClassFromXmlTag == null) { return; } Set<String> phpServiceTags = ServiceUtil.getPhpClassServiceTags(phpClassFromXmlTag); if(phpServiceTags.size() == 0) { HintManager.getInstance().showErrorHint(editor, "Ops, no possible Tag found"); return; } for (XmlTag tag : xmlTag.getSubTags()) { if(!"tag".equals(tag.getName())) { continue; } XmlAttribute name = tag.getAttribute("name"); if(name == null) { continue; } String value = name.getValue(); if(phpServiceTags.contains(value)) { phpServiceTags.remove(value); } } ServiceUtil.insertTagWithPopupDecision(editor, phpServiceTags, tag -> { ServiceTag serviceTag = new ServiceTag(phpClassFromXmlTag, tag); ServiceUtil.decorateServiceTag(serviceTag); xmlTag.addSubTag(XmlElementFactory.getInstance(project).createTagFromText(serviceTag.toXmlString()), false); }); }
Example 16
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; }
Example 17
Source File: XmlDuplicateServiceKeyInspection.java From idea-php-symfony2-plugin with MIT License | 4 votes |
protected void visitRoot(PsiFile psiFile, @NotNull ProblemsHolder holder, String root, String child, String tagName) { XmlDocument xmlDocument = PsiTreeUtil.getChildOfType(psiFile, XmlDocument.class); if(xmlDocument == null) { return; } Map<String, XmlAttribute> psiElementMap = new HashMap<>(); Set<XmlAttribute> yamlKeyValues = new HashSet<>(); for(XmlTag xmlTag: PsiTreeUtil.getChildrenOfTypeAsList(psiFile.getFirstChild(), XmlTag.class)) { if(xmlTag.getName().equals("container")) { for(XmlTag servicesTag: xmlTag.getSubTags()) { if(servicesTag.getName().equals(root)) { for(XmlTag parameterTag: servicesTag.getSubTags()) { if(parameterTag.getName().equals(child)) { XmlAttribute keyAttr = parameterTag.getAttribute(tagName); if(keyAttr != null) { String parameterName = keyAttr.getValue(); if(parameterName != null && StringUtils.isNotBlank(parameterName)) { if(psiElementMap.containsKey(parameterName)) { yamlKeyValues.add(psiElementMap.get(parameterName)); yamlKeyValues.add(keyAttr); } else { psiElementMap.put(parameterName, keyAttr); } } } } } } } } } if(yamlKeyValues.size() > 0) { for(PsiElement psiElement: yamlKeyValues) { XmlAttributeValue valueElement = ((XmlAttribute) psiElement).getValueElement(); if(valueElement != null) { holder.registerProblem(valueElement, "Duplicate Key", ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } } } }
Example 18
Source File: StringTableKey.java From arma-intellij-plugin with MIT License | 4 votes |
/** * @return the key's id attribute */ @NotNull public String getID() { XmlAttribute attr = key.getID().getXmlAttribute(); return attr == null || attr.getValue() == null ? "<No ID>" : attr.getValue(); }
Example 19
Source File: StringTableKey.java From arma-intellij-plugin with MIT License | 4 votes |
/** * @return the key's id attribute */ @NotNull public String getID() { XmlAttribute attr = key.getID().getXmlAttribute(); return attr == null || attr.getValue() == null ? "<No ID>" : attr.getValue(); }
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); }