Java Code Examples for com.intellij.psi.xml.XmlTag#getParentTag()

The following examples show how to use com.intellij.psi.xml.XmlTag#getParentTag() . 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: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
public static boolean isInTopLevelTag(XmlTag tag) {
    boolean inTopLevel = false;
    XmlTag current = tag;

    while (!inTopLevel && current != null) {
        inTopLevel = MuleConfigUtils.isTopLevelTag(current);
        if (!inTopLevel)
            current = current.getParentTag();
    }

    return inTopLevel;
}
 
Example 2
Source File: MuleConfigUtils.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
public static String getMulePath(XmlTag tag) {
    final LinkedList<XmlTag> elements = new LinkedList<>();
    while (!isMuleTag(tag)) {
        elements.push(tag);
        tag = tag.getParentTag();
    }
    String path = "";
    for (int i = 0; i < elements.size(); i++) {
        final XmlTag element = elements.get(i);
        switch (i) {
            case 0: {
                final XmlAttribute name = element.getAttribute(MuleConfigConstants.NAME_ATTRIBUTE);
                if (name != null) {
                    path = "/" + MulePathUtils.escape(name.getValue()) + getGlobalElementCategory(element);
                }
                break;
            }
            default: {
                final XmlTag parentTag = element.getParentTag();
                int index = 0;
                for (XmlTag xmlTag : parentTag.getSubTags()) {
                    if (xmlTag == element) {
                        break;
                    }
                    final MuleElementType muleElementType = getMuleElementTypeFromXmlElement(xmlTag);
                    if (muleElementType == MuleElementType.MESSAGE_PROCESSOR) {
                        index = index + 1;
                    }
                }
                path = path + "/" + index;
            }
        }
    }
    System.out.println("path = " + path);
    return path;
}
 
Example 3
Source File: XmlCamelIdeaUtils.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
private boolean isCamelRouteStartTag(XmlTag tag) {
    String name = tag.getLocalName();
    XmlTag parentTag = tag.getParentTag();
    if (parentTag != null) {
        //TODO: unsure about this, <rest> cannot be a child of <routes> according to blueprint xsd, see issue #475
        return "routes".equals(parentTag.getLocalName()) && "rest".equals(name)
            || "route".equals(parentTag.getLocalName()) && "from".equals(name);
    }
    return false;
}
 
Example 4
Source File: BeanUtils.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public PsiClass getPropertyBeanClass(XmlTag propertyTag) {
    XmlTag beanTag = propertyTag.getParentTag();
    if (beanTag != null && isBeanDeclaration(beanTag)) {
        IdeaUtils ideaUtils = IdeaUtils.getService();
        JavaClassUtils javaClassUtils = JavaClassUtils.getService();
        return ideaUtils.findAttributeValue(beanTag, "class")
                .map(javaClassUtils::findClassReference)
                .map(javaClassUtils::resolveClassReference)
                .orElse(null);
    }
    return null;
}
 
Example 5
Source File: CamelAddEndpointIntention.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
    if (ServiceManager.getService(project, CamelService.class).isCamelPresent()) {
        // special for xml
        XmlTag xml = PsiTreeUtil.getParentOfType(element, XmlTag.class);
        if (xml != null) {
            // special check for poll enrich where we add the endpoint on a child node (camel expression)
            XmlTag parent = xml.getParentTag();
            if (parent != null && parent.getLocalName().equals("pollEnrich")) {
                return true;
            }
        }

        String text = null;

        // special for java token
        if (element instanceof PsiJavaToken) {
            // if its a string literal
            PsiJavaToken token = (PsiJavaToken) element;
            if (token.getTokenType() == JavaTokenType.STRING_LITERAL) {
                text = getIdeaUtils().getInnerText(token.getText());
            }
        } else {
            // should be a literal element and therefore dont fallback to generic
            text = getIdeaUtils().extractTextFromElement(element, false, false, true);
        }

        return text != null && text.trim().isEmpty();
    }

    return false;
}
 
Example 6
Source File: RTClassTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    XmlTag parent = contextTag.getParentTag();
    if (parent == null) return null;
    final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true);
    return descriptor == null ? null : descriptor.getElementDescriptor(childTag);
}
 
Example 7
Source File: RTImportTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    XmlTag parent = contextTag.getParentTag();
    if (parent == null) return null;
    final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true);
    return descriptor == null ? null : descriptor.getElementDescriptor(childTag);
}
 
Example 8
Source File: RTRequireTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    XmlTag parent = contextTag.getParentTag();
    if (parent == null) return null;
    final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true);
    return descriptor == null ? null : descriptor.getElementDescriptor(childTag);
}
 
Example 9
Source File: ISMLTagDescriptor.java    From intellij-demandware with MIT License 5 votes vote down vote up
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    XmlTag parent = contextTag.getParentTag();
    if (parent == null) return null;
    final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true);
    return descriptor == null ? null : descriptor.getElementDescriptor(childTag);
}
 
Example 10
Source File: RTClassTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    XmlTag parent = contextTag.getParentTag();
    if (parent == null) return null;
    final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true);
    return descriptor == null ? null : descriptor.getElementDescriptor(childTag);
}
 
Example 11
Source File: RTImportTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    XmlTag parent = contextTag.getParentTag();
    if (parent == null) return null;
    final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true);
    return descriptor == null ? null : descriptor.getElementDescriptor(childTag);
}
 
Example 12
Source File: RTRequireTagDescriptor.java    From react-templates-plugin with MIT License 5 votes vote down vote up
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    XmlTag parent = contextTag.getParentTag();
    if (parent == null) return null;
    final XmlNSDescriptor descriptor = parent.getNSDescriptor(childTag.getNamespace(), true);
    return descriptor == null ? null : descriptor.getElementDescriptor(childTag);
}
 
Example 13
Source File: IdeaUtils.java    From camel-idea-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Is the given element from a XML tag with any of the given tag names
 *
 * @param xml  the xml tag
 * @param parentTag a special parent tag name to match first
 * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
 */
public boolean hasParentXmlTag(@NotNull XmlTag xml, @NotNull String parentTag) {
    XmlTag parent = xml.getParentTag();
    return parent != null && parent.getLocalName().equals(parentTag);
}