本文整理了Java中com.intellij.psi.xml.XmlTag.getAttributeValue()
方法的一些代码示例,展示了XmlTag.getAttributeValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlTag.getAttributeValue()
方法的具体详情如下:
包路径:com.intellij.psi.xml.XmlTag
类名称:XmlTag
方法名:getAttributeValue
暂无
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Nullable
@Override
public String getAttribute(@NotNull String attr) {
return this.xmlTag.getAttributeValue(attr);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Nullable
@Override
public String getString(@NotNull String key) {
String value = this.xmlTag.getAttributeValue(key);
if(StringUtils.isBlank(value)) {
return null;
}
return value;
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Nullable
@Override
public String findIdForElement(@NotNull PsiElement psiElement) {
XmlTag parentOfType = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class);
if(parentOfType == null) {
return null;
}
return parentOfType.getAttributeValue("id");
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@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);
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Nullable
@Override
public String findClassForElement(@NotNull PsiElement psiElement) {
XmlTag parentOfType = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class);
if (parentOfType != null) {
String aClass = parentOfType.getAttributeValue("class");
if (StringUtils.isNotBlank(aClass)) {
return aClass;
}
}
return null;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* Extract service class for class or id attribute on shortcut
*
* <service id="foo" class="Foobar"/> => Foobar
* <service class="Foobar"/> => Foobar
*/
@Nullable
public static String getClassFromServiceDefinition(@NotNull XmlTag xmlTag) {
String classAttribute = xmlTag.getAttributeValue("class");
if(StringUtils.isNotBlank(classAttribute)) {
return classAttribute;
}
String id = xmlTag.getAttributeValue("id");
if(id == null || StringUtils.isBlank(id) || !YamlHelper.isClassServiceId(id)) {
return null;
}
return id;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
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;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Override
public boolean value(PsiElement psiElement) {
return psiElement instanceof XmlTag && this.key.equals(((XmlTag) psiElement).getAttributeValue(this.attr));
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@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;
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@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;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
private void getOdmFields(@NotNull XmlTag xmlTag, @NotNull Collection<DoctrineModelField> fields) {
for (XmlTag tag : xmlTag.getSubTags()) {
String tagName = tag.getName();
if("field".equals(tagName)) {
String name = tag.getAttributeValue("name");
if(StringUtils.isNotBlank(name)) {
DoctrineModelField type = new DoctrineModelField(name, tag.getAttributeValue("type"));
type.setColumn(tag.getAttributeValue("fieldName"));
fields.add(type);
}
} else if(RELATIONS.contains(tagName)) {
String field = tag.getAttributeValue("field");
if(StringUtils.isNotBlank(field)) {
DoctrineModelField type = new DoctrineModelField(field);
type.setRelationType(tagName);
type.setRelation(tag.getAttributeValue("target-document"));
fields.add(type);
}
}
}
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* Extract default values for services tag scope
*
* <defaults autowire="true" public="false" />
*/
private static ServiceFileDefaults createDefaults(@NotNull XmlTag servicesTag) {
XmlTag xmlDefaults = servicesTag.findFirstSubTag("defaults");
if(xmlDefaults == null) {
return ServiceFileDefaults.EMPTY;
}
return new ServiceFileDefaults(
getBooleanValueOf(xmlDefaults.getAttributeValue("public")),
getBooleanValueOf(xmlDefaults.getAttributeValue("autowire"))
);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* Find argument of given service function / method scope
*
* <service>
* <argument key="$foobar"/>
* <argument index="0"/>
* <argument/>
* </service>
*/
public static int getArgumentIndex(@NotNull XmlTag argumentTag, @NotNull Function function) {
String indexAttr = argumentTag.getAttributeValue("index");
if(indexAttr != null) {
try {
return Integer.valueOf(indexAttr);
} catch (NumberFormatException e) {
return -1;
}
}
String keyAttr = argumentTag.getAttributeValue("key");
if(keyAttr != null) {
int parameter = PhpElementsUtil.getFunctionArgumentByName(function, StringUtils.stripStart(keyAttr, "$"));
if(parameter >= 0) {
return parameter;
}
}
return getArgumentIndexByCount(argumentTag);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* <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;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Nullable
public static PhpClass getPhpClassForServiceFactory(@NotNull XmlAttributeValue xmlAttributeValue) {
String method = xmlAttributeValue.getValue();
if(StringUtils.isBlank(method)) {
return null;
}
XmlTag callXmlTag = PsiTreeUtil.getParentOfType(xmlAttributeValue, XmlTag.class);
if(callXmlTag == null) {
return null;
}
String service = callXmlTag.getAttributeValue("service");
if(StringUtils.isBlank(service)) {
return null;
}
return ServiceUtil.getResolvedClassDefinition(xmlAttributeValue.getProject(), service);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* Get class factory method attribute
*
* <factory class="FooBar" method="cre<caret>ate"/>
*/
@Nullable
public static PhpClass getPhpClassForClassFactory(@NotNull XmlAttributeValue xmlAttributeValue) {
String method = xmlAttributeValue.getValue();
if(StringUtils.isBlank(method)) {
return null;
}
XmlTag parentOfType = PsiTreeUtil.getParentOfType(xmlAttributeValue, XmlTag.class);
if(parentOfType == null) {
return null;
}
String aClass = parentOfType.getAttributeValue("class");
if(aClass == null || StringUtils.isBlank(aClass)) {
return null;
}
return PhpElementsUtil.getClass(xmlAttributeValue.getProject(), aClass);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* <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)));
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Nullable
public static PsiElement getLocalServiceName(PsiFile psiFile, String serviceName) {
if(!(psiFile.getFirstChild() instanceof XmlDocument)) {
return null;
}
XmlTag xmlTags[] = PsiTreeUtil.getChildrenOfType(psiFile.getFirstChild(), XmlTag.class);
if(xmlTags == null) {
return null;
}
for(XmlTag xmlTag: xmlTags) {
if(xmlTag.getName().equals("container")) {
for(XmlTag servicesTag: xmlTag.getSubTags()) {
if(servicesTag.getName().equals("services")) {
for(XmlTag serviceTag: servicesTag.getSubTags()) {
String serviceNameId = serviceTag.getAttributeValue("id");
if(serviceNameId != null && serviceNameId.equalsIgnoreCase(serviceName)) {
return serviceTag;
}
}
}
}
}
}
return null;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
public static void visitFile(@NotNull XmlFile psiFile, @NotNull Consumer<ServiceConsumer> consumer) {
if(!(psiFile.getFirstChild() instanceof XmlDocument)) {
return;
}
XmlTag xmlTags[] = PsiTreeUtil.getChildrenOfType(psiFile.getFirstChild(), XmlTag.class);
if(xmlTags == null) {
return;
}
for(XmlTag xmlTag: xmlTags) {
if(xmlTag.getName().equals("container")) {
for(XmlTag servicesTag: xmlTag.getSubTags()) {
if("services".equals(servicesTag.getName())) {
// default values:
// <defaults autowire="true" public="false" />
ServiceFileDefaults defaults = createDefaults(servicesTag);
for(XmlTag serviceTag: servicesTag.findSubTags("service")) {
String serviceId = serviceTag.getAttributeValue("id");
if(StringUtils.isBlank(serviceId)) {
continue;
}
consumer.consume(new ServiceConsumer(serviceTag, serviceId, new XmlTagAttributeValue(serviceTag), defaults));
}
}
}
}
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
public void testGetTargetForXlfAsXmlFileInVersion12AndResname() {
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\" resname=\"index.hello_world\">\n" +
" <source>foo</source>\n" +
" </trans-unit>\n" +
" </body>\n" +
" </file>\n" +
"</xliff>\n"
);
Collection<PsiElement> files = TranslationUtil.getTargetForXlfAsXmlFile((XmlFile) fileFromText, "index.hello_world");
assertNotNull(ContainerUtil.find(files, psiElement ->
psiElement instanceof XmlTag && "index.hello_world".equals(((XmlTag) psiElement).getAttributeValue("resname")))
);
}
内容来源于网络,如有侵权,请联系作者删除!