下面列出了com.intellij.psi.xml.XmlTag#getSubTags ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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;
}
}
/**
* 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();
}
/**
* 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();
}
public SVGParser(XmlFile svg, String dpi) {
styles = new HashMap<String, String>();
this.svg = svg;
this.dpi = dpi;
parseDimensions();
XmlDocument document = svg.getDocument();
if (document != null) {
XmlTag rootTag = document.getRootTag();
if (rootTag != null) {
XmlTag[] subTags = rootTag.getSubTags();
for (XmlTag tag : subTags) {
getChildAttrs(tag);
}
}
}
}
public Map<String, XmlTag> getAcceptedDefNodes() {
XmlTag rootTag = svg.getRootTag();
Map<String, XmlTag> tags = new HashMap<String, XmlTag>();
XmlTag[] subTags = rootTag.getSubTags();
for (XmlTag tag : subTags) {
if ("defs".equalsIgnoreCase(tag.getName())) {
XmlTag[] defSubTags = tag.getSubTags();
if (defSubTags != null) {
for (XmlTag defNode : defSubTags) {
if (AttrMapper.isShapeName(defNode.getName())) {
tags.put(defNode.getAttributeValue("id"), defNode);
} else {
Logger.info("Tag <" + tag.getName() + "> was not supported by android");
}
}
}
}
}
Logger.debug("use tags of " + rootTag.getName() + " :" + tags.toString());
return tags;
}
public XmlTag trim(XmlTag rootTag, List<XmlAttribute> attr) {
Logger.debug("Current tag: " + rootTag.getName());
CommonUtil.dumpAttrs("current attr", Arrays.asList(rootTag.getAttributes()));
CommonUtil.dumpAttrs("parent attr", attr);
if (attr == null) {
attr = new ArrayList<XmlAttribute>();
attr.addAll(Arrays.asList(rootTag.getAttributes()));
}
XmlTag[] subTags = rootTag.getSubTags();
List<XmlAttribute> attrs = new ArrayList<XmlAttribute>();
if (subTags.length == 1 && subTags[0].getName().equals("g")) {
Logger.debug("Tag" + rootTag + " has only a subTag and the tag is 'g'");
Collections.addAll(attrs, subTags[0].getAttributes());
attrs.addAll(attr);
rootTag = trim(subTags[0], attrs);
} else if (subTags.length > 0 && AttrMapper.isShapeName(subTags[0].getName())) {
Logger.debug(rootTag.getSubTags()[0].getName());
Logger.debug("Tag" + rootTag + " is correct tag.");
for (XmlAttribute attribute : attr) {
Logger.debug(attribute.getName() + ":" + attribute.getValue());
}
return AttrMergeUtil.mergeAttrs((XmlTag) rootTag.copy(), reduceAttrs(attr));
}
return rootTag;
}
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;
}
/**
* <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;
}
@NotNull
public static Collection<XmlTag> getXmlContainerServiceDefinition(PsiFile psiFile) {
Collection<XmlTag> xmlTags = new ArrayList<>();
for(XmlTag xmlTag: PsiTreeUtil.getChildrenOfTypeAsList(psiFile.getFirstChild(), XmlTag.class)) {
if(xmlTag.getName().equals("container")) {
for(XmlTag servicesTag: xmlTag.getSubTags()) {
if(servicesTag.getName().equals("services")) {
for(XmlTag parameterTag: servicesTag.getSubTags()) {
if(parameterTag.getName().equals("service")) {
xmlTags.add(parameterTag);
}
}
}
}
}
}
return xmlTags;
}
@NotNull
public static List<String> getXmlMissingArgumentTypes(@NotNull XmlTag xmlTag, boolean collectOptionalParameter, @NotNull ContainerCollectionResolver.LazyServiceCollector collector) {
PhpClass resolvedClassDefinition = getPhpClassFromXmlTag(xmlTag, collector);
if (resolvedClassDefinition == null) {
return Collections.emptyList();
}
Method constructor = resolvedClassDefinition.getConstructor();
if(constructor == null) {
return Collections.emptyList();
}
int serviceArguments = 0;
for (XmlTag tag : xmlTag.getSubTags()) {
if("argument".equals(tag.getName())) {
serviceArguments++;
}
}
Parameter[] parameters = collectOptionalParameter ? constructor.getParameters() : PhpElementsUtil.getFunctionRequiredParameter(constructor);
if(parameters.length <= serviceArguments) {
return Collections.emptyList();
}
final List<String> args = new ArrayList<>();
for (int i = serviceArguments; i < parameters.length; i++) {
Parameter parameter = parameters[i];
String s = parameter.getDeclaredType().toString();
args.add(s);
}
return args;
}
public List<XmlTag> getGroups() {
List<XmlTag> groups = new ArrayList<XmlTag>();
if (svg.getDocument() != null) {
XmlTag rootTag = svg.getDocument().getRootTag();
if (rootTag != null) {
for (XmlTag tag : rootTag.getSubTags()) {
if (tag.getName().equals("g")) {
groups.add(trim(tag, null));
}
}
}
}
return groups;
}
public List<XmlTag> getGroupChildes(String groupName) {
List<XmlTag> childes = new ArrayList<XmlTag>();
if (svg.getDocument() != null) {
XmlTag rootTag = svg.getDocument().getRootTag();
if (rootTag != null) {
for (XmlTag tag : rootTag.getSubTags()) {
if (tag.getName().equals(groupName)) {
Collections.addAll(childes, tag.getSubTags());
}
}
}
}
return childes;
}
public List<XmlTag> getSubGroups(XmlTag parent) {
List<XmlTag> list = new ArrayList<XmlTag>();
for (XmlTag tag : parent.getSubTags()) {
if (tag.getName().equals("g")) {
list.add(tag);
}
}
return list;
}
public XmlTag getStyles() {
List<XmlTag> childes = getSVGChildes();
for (XmlTag tag : childes) {
if ("defs".equals(tag.getName()) && tag.getSubTags() != null) {
for (XmlTag subTag : tag.getSubTags()) {
if ("style".equals(subTag.getName())) {
return subTag;
}
}
}
}
return null;
}
public List<XmlTag> getShapeTags(XmlTag parentTag) {
List<XmlTag> tags = new ArrayList<XmlTag>();
XmlTag[] subTags = parentTag.getSubTags();
for (XmlTag tag : subTags) {
if (AttrMapper.isShapeName(tag.getName())) {
tags.add(tag);
}
}
Logger.debug("shapeTag of " + parentTag.getName() + " :" + tags.toString());
return tags;
}
@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);
});
}
@Nullable
public DoctrineMetadataModel getMetadata(@NotNull DoctrineMappingDriverArguments args) {
PsiFile psiFile = args.getPsiFile();
if(!(psiFile instanceof XmlFile)) {
return null;
}
XmlTag rootTag = ((XmlFile) psiFile).getRootTag();
if(rootTag == null || !rootTag.getName().matches(DoctrineMetadataPattern.DOCTRINE_MAPPING)) {
return null;
}
Collection<DoctrineModelField> fields = new ArrayList<>();
DoctrineMetadataModel model = new DoctrineMetadataModel(fields);
for (XmlTag xmlTag : rootTag.getSubTags()) {
String name = xmlTag.getAttributeValue("name");
if(name == null) {
continue;
}
if("entity".equals(xmlTag.getName()) && args.isEqualClass(name)) {
// Doctrine ORM
// @TODO: refactor allow multiple
fields.addAll(EntityHelper.getEntityFields((XmlFile) psiFile));
// get table for dbal
String table = xmlTag.getAttributeValue("table");
if(StringUtils.isNotBlank(table)) {
model.setTable(table);
}
} else if("document".equals(xmlTag.getName()) && args.isEqualClass(name)) {
// Doctrine ODM
getOdmFields(xmlTag, fields);
}
}
if(model.isEmpty()) {
return null;
}
return model;
}
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);
}
}
}
}
public static Collection<StubIndexedRoute> getXmlRouteDefinitions(XmlFile psiFile) {
XmlDocumentImpl document = PsiTreeUtil.getChildOfType(psiFile, XmlDocumentImpl.class);
if(document == null) {
return Collections.emptyList();
}
Collection<StubIndexedRoute> indexedRoutes = new ArrayList<>();
/*
* <routes>
* <route id="foo" path="/blog/{slug}" methods="GET">
* <default key="_controller">Foo</default>
* </route>
*
* <route id="foo" path="/blog/{slug}" methods="GET" controller="AppBundle:Blog:list"/>
* </routes>
*/
for(XmlTag xmlTag: PsiTreeUtil.getChildrenOfTypeAsList(psiFile.getFirstChild(), XmlTag.class)) {
if(xmlTag.getName().equals("routes")) {
for(XmlTag servicesTag: xmlTag.getSubTags()) {
if(servicesTag.getName().equals("route")) {
XmlAttribute xmlAttribute = servicesTag.getAttribute("id");
if(xmlAttribute != null) {
String attrValue = xmlAttribute.getValue();
if(attrValue != null && StringUtils.isNotBlank(attrValue)) {
StubIndexedRoute route = new StubIndexedRoute(attrValue);
String pathAttribute = servicesTag.getAttributeValue("path");
if(pathAttribute == null) {
pathAttribute = servicesTag.getAttributeValue("pattern");
}
if(pathAttribute != null && StringUtils.isNotBlank(pathAttribute) ) {
route.setPath(pathAttribute);
}
String methods = servicesTag.getAttributeValue("methods");
if(methods != null && StringUtils.isNotBlank(methods)) {
String[] split = methods.replaceAll(" +", "").toLowerCase().split("\\|");
if(split.length > 0) {
route.addMethod(split);
}
}
// <route><default key="_controller"/></route>
// <route controller="AppBundle:Blog:list"/>
String controller = getXmlController(servicesTag);
if(controller != null) {
route.setController(normalizeRouteController(controller));
}
indexedRoutes.add(route);
}
}
}
}
}
}
return indexedRoutes;
}