
com.intellij.patterns.DomPatterns Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dom-openapi Show documentation
Show all versions of dom-openapi Show documentation
A packaging of the IntelliJ Community Edition dom-openapi library.
This is release number 1 of trunk branch 142.
The newest version!
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.patterns;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ProcessingContext;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.DomManager;
import com.intellij.util.xml.DomTarget;
import com.intellij.pom.PomTargetPsiElement;
import org.jetbrains.annotations.NotNull;
/**
* @author peter
*/
public class DomPatterns {
public static DomElementPattern.Capture domElement(Class aClass) {
return new DomElementPattern.Capture(aClass);
}
public static DomElementPattern.Capture domElement() {
return domElement(DomElement.class);
}
public static GenericDomValuePattern> genericDomValue() {
return new GenericDomValuePattern();
}
public static GenericDomValuePattern genericDomValue(ElementPattern> valuePattern) {
return ((GenericDomValuePattern)genericDomValue()).withValue(valuePattern);
}
public static GenericDomValuePattern genericDomValue(Class aClass) {
return new GenericDomValuePattern(aClass);
}
/**
* @deprecated use {@link #tagWithDom(String, ElementPattern)} and {@link #attributeWithDom(String, ElementPattern)}
*/
public static XmlElementPattern.Capture withDom(final ElementPattern extends DomElement> pattern) {
return new XmlElementPattern.Capture().with(new PatternCondition("tagWithDom") {
@Override
public boolean accepts(@NotNull final XmlElement xmlElement, final ProcessingContext context) {
final DomManager manager = DomManager.getDomManager(xmlElement.getProject());
if (xmlElement instanceof XmlAttribute) {
return pattern.accepts(manager.getDomElement((XmlAttribute)xmlElement), context);
}
return xmlElement instanceof XmlTag && pattern.accepts(manager.getDomElement((XmlTag)xmlElement), context);
}
});
}
public static DomFilePattern.Capture inDomFile(Class rootElementClass) {
return new DomFilePattern.Capture(rootElementClass);
}
public static XmlTagPattern.Capture tagWithDom(String tagName, Class extends DomElement> aClass) {
return tagWithDom(tagName, domElement(aClass));
}
public static XmlTagPattern.Capture tagWithDom(String tagName, ElementPattern extends DomElement> domPattern) {
return XmlPatterns.xmlTag().withLocalName(tagName).and(withDom(domPattern));
}
public static XmlNamedElementPattern.XmlAttributePattern attributeWithDom(String tagName, ElementPattern extends DomElement> domPattern) {
return XmlPatterns.xmlAttribute().withLocalName(tagName).and(withDom(domPattern));
}
public static PsiElementPattern.Capture domTargetElement(final ElementPattern extends DomElement> pattern) {
return PlatformPatterns.pomElement(withDomTarget(pattern));
}
public static ElementPattern withDomTarget(final ElementPattern extends DomElement> pattern) {
return new ObjectPattern.Capture(DomTarget.class).with(new PatternCondition("withDomTarget") {
@Override
public boolean accepts(@NotNull final DomTarget target, final ProcessingContext context) {
return pattern.accepts(target.getDomElement(), context);
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy