com.intellij.psi.xml.XmlTag#getAttributeValue ( )源码实例Demo

下面列出了com.intellij.psi.xml.XmlTag#getAttributeValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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;
}
 
源代码2 项目: idea-php-symfony2-plugin   文件: RouteHelper.java
/**
 * <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;
}
 
/**
 * <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)));
    }
}
 
源代码4 项目: idea-php-typo3-plugin   文件: TranslationIndex.java
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);
        }
    }
}
 
源代码5 项目: idea-php-typo3-plugin   文件: TranslationIndex.java
@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);
                }});
            }
        }
    }
}
 
@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);
}
 
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;
    }
 
源代码8 项目: mule-intellij-plugins   文件: FlowGoToSymbol.java
@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));
        }
    }
}
 
源代码9 项目: mule-intellij-plugins   文件: MuleConfigUtils.java
@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:";
}
 
源代码10 项目: idea-php-symfony2-plugin   文件: XmlServiceTag.java
@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);
}
 
源代码11 项目: mule-intellij-plugins   文件: MuleConfigUtils.java
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);
        }
    }
}
 
源代码12 项目: camel-idea-plugin   文件: XmlIdeaUtils.java
@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;

}
 
源代码13 项目: svgtoandroid   文件: SVGAttrParser.java
private static String getPathValue(XmlTag tag) {
    String rawValue = tag.getAttributeValue("d");
    if (rawValue != null) {
        return VectorDrawableFixinator.getContentWithFixedFloatingPoints(rawValue);
    }
    return rawValue;
}
 
@Nullable
@Override
public String findIdForElement(@NotNull PsiElement psiElement) {
    XmlTag parentOfType = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class);
    if(parentOfType == null) {
        return null;
    }

    return parentOfType.getAttributeValue("id");
}
 
源代码15 项目: svgtoandroid   文件: SVGParser.java
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;
}
 
源代码16 项目: intellij-haxe   文件: HaxelibUtil.java
/**
 * 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);
}
 
@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);
}
 
@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;
    }
 
public GlobalConfigNode(SimpleNode aParent, XmlTag tag) {
    super(aParent, tag.getAttributeValue("name"));
    myTag = tag;
    myClosedIcon = MuleIcons.ConnectorIcon;
    updatePresentation();
}
 
源代码20 项目: idea-php-symfony2-plugin   文件: EntityHelper.java
@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;
}