本文整理汇总了Java中com.intellij.psi.xml.XmlTag.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java XmlTag.getAttribute方法的具体用法?Java XmlTag.getAttribute怎么用?Java XmlTag.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.xml.XmlTag
的用法示例。
在下文中一共展示了XmlTag.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getXmlnsDeclaration
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
private static XmlAttribute getXmlnsDeclaration(PsiElement element) {
final PsiElement parent = element.getParent();
if (parent instanceof XmlTag) {
XmlTag tag = (XmlTag)parent;
if (tag.getNamespacePrefix().isEmpty()) {
while (tag != null) {
final XmlAttribute attr = tag.getAttribute("xmlns");
if (attr != null) return attr;
tag = tag.getParentTag();
}
}
} else if (parent instanceof XmlAttribute && ((XmlAttribute)parent).getName().equals("xmlns")) {
return (XmlAttribute)parent;
}
return null;
}
示例2: getReferencedTag
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
public static XmlTag getReferencedTag(XmlTag tag) {
final String tagName = tag.getName();
if (FxmlConstants.FX_REFERENCE.equals(tagName) || FxmlConstants.FX_COPY.equals(tagName)) {
final XmlAttribute attribute = tag.getAttribute(FxmlConstants.FX_ELEMENT_SOURCE);
if (attribute != null) {
final XmlAttributeValue valueElement = attribute.getValueElement();
if (valueElement != null) {
final PsiReference reference = valueElement.getReference();
if (reference != null) {
final PsiElement resolve = reference.resolve();
if (resolve instanceof XmlAttributeValue) {
return PsiTreeUtil.getParentOfType(resolve, XmlTag.class);
}
}
}
}
}
return null;
}
示例3: testAny3
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public void testAny3() throws Exception {
XmlNSDescriptor NSDescriptor = createDescriptor(
"<xsd:schema targetNamespace=\"http://foo\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" >" +
" <xsd:element name=\"root\">" +
" <xsd:complexType>" +
" <xsd:anyAttribute namespace=\"##other\" processContents=\"skip\"/>" +
" </xsd:complexType>" +
" </xsd:element>" +
"</xsd:schema>"
);
XmlFile xmlFile = (XmlFile)createFile("file.xml",
"<root xmlns=\"http://foo\" y:a=\"1\">" +
"</root>"
);
final XmlTag rootTag = xmlFile.getDocument().getRootTag();
XmlElementDescriptor rootDescriptor = NSDescriptor.getElementDescriptor(rootTag);
assertNotNull(rootDescriptor);
XmlAttribute attribute = rootTag.getAttribute("y:a", XmlUtil.EMPTY_URI);
assertNotNull(attribute);
XmlAttributeDescriptor aDescriptor = rootDescriptor.getAttributeDescriptor("y:a", rootTag);
assertNotNull(aDescriptor);
}
示例4: createAttributeStrategy
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public static StubParentStrategy createAttributeStrategy(@Nullable AttributeStub stub, @NotNull final DomStub parent) {
if (stub == null) {
return new Empty(parent);
}
else {
return new StubParentStrategy(stub) {
@Override
public XmlElement getXmlElement() {
DomInvocationHandler parentHandler = getParentHandler();
if (parentHandler == null) {
LOG.error("no parent handler for " + this);
return null;
}
XmlTag tag = parentHandler.getXmlTag();
if (tag == null) {
LOG.error("can't find tag for " + parentHandler + "\n" +
"parent stub: " + myStub.getParentStub() + "\n" +
"parent's children: " + myStub.getParentStub().getChildrenStubs());
return null;
}
return tag.getAttribute(myStub.getName());
}
};
}
}
示例5: addSuppressAttribute
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void addSuppressAttribute(final Project project,
final XmlFile file,
final XmlTag element,
final String id) throws IncorrectOperationException {
XmlAttribute attribute = element.getAttribute(ATTR_IGNORE, TOOLS_URI);
String value;
if (attribute == null) {
value = id;
} else {
List<String> ids = new ArrayList<String>();
for (String existing : Splitter.on(',').trimResults().split(attribute.getValue())) {
if (!existing.equals(id)) {
ids.add(existing);
}
}
ids.add(id);
Collections.sort(ids);
value = Joiner.on(',').join(ids);
}
ensureNamespaceImported(project, file, TOOLS_URI);
element.setAttribute(ATTR_IGNORE, TOOLS_URI, value);
}
示例6: isAvailable
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
if (element instanceof XmlToken && ((XmlToken)element).getTokenType() == XmlTokenType.XML_NAME && element.getParent() instanceof XmlTag) {
final XmlTag tag = (XmlTag)element.getParent();
for (XmlTag xmlTag : tag.getSubTags()) {
if (xmlTag.getAttribute(FxmlConstants.FX_VALUE) == null) return false;
}
final XmlTag parentTag = tag.getParentTag();
if (parentTag != null &&
tag.getDescriptor() instanceof JavaFxPropertyElementDescriptor &&
parentTag.getDescriptor() instanceof JavaFxClassBackedElementDescriptor) {
setText("Collapse tag '" + tag.getName() + "' to attribute");
return true;
}
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:JavaFxCollapseSubTagToAttributeIntention.java
示例7: findProperties
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static String[] findProperties(@NotNull XmlTag tag) {
final XmlAttribute typeAttribute = tag.getAttribute(ITEM_TYPE);
if (typeAttribute != null) {
final XmlAttributeValue valueElement = typeAttribute.getValueElement();
final PsiReference[] references = valueElement != null ? valueElement.getReferences() : PsiReference.EMPTY_ARRAY;
List<String> result = new ArrayList<String>();
for (PsiReference reference : references) {
final PsiElement target = reference != null ? reference.resolve() : null;
if (target instanceof PsiFile) {
result.addAll(extractProperties((PsiFile)target, StringUtil.stripQuotesAroundValue(reference.getCanonicalText())));
}
}
return ArrayUtil.toStringArray(result);
}
return ArrayUtil.EMPTY_STRING_ARRAY;
}
示例8: getAttributeDescriptor
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
@Override
public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, XmlTag context) {
if (!HtmlUtil.isHtml5Context(context)) {
return null;
}
if (ITEM_SCOPE.equalsIgnoreCase(attributeName)) {
return new AnyXmlAttributeDescriptor(attributeName);
}
if (context.getAttribute(ITEM_SCOPE) != null &&
(ITEM_TYPE.equalsIgnoreCase(attributeName) || ITEM_ID.equalsIgnoreCase(attributeName) || ITEM_REF.equalsIgnoreCase(attributeName))) {
return new XmlAttributeDescriptorWithEmptyDefaultValue(attributeName);
}
if (ITEM_PROP.equalsIgnoreCase(attributeName) && hasScopeTag(context)) {
return new MicrodataPropertyAttributeDescriptor(context);
}
return null;
}
示例9: resolve
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
@Override
public PsiElement resolve() {
final String flowName = getFlowName();
final XmlTag flow = MuleConfigUtils.findFlow(myElement, flowName);
if (flow != null) {
final XmlAttribute name = flow.getAttribute(MuleConfigConstants.NAME_ATTRIBUTE);
return name != null ? name.getValueElement() : null;
}
return null;
}
示例10: buildVisitor
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder,
boolean isOnTheFly,
@NotNull LocalInspectionToolSession session) {
return new XmlElementVisitor() {
@Override
public void visitXmlTag(XmlTag tag) {
DomElement element = DomUtil.getDomElement(tag);
if (element instanceof Extension) {
ExtensionPoint extensionPoint = ((Extension)element).getExtensionPoint();
if (extensionPoint != null && InheritanceUtil.isInheritor(extensionPoint.getBeanClass().getValue(), "com.intellij.codeInspection.InspectionEP")) {
boolean key = tag.getAttribute("key") != null;
boolean groupKey = tag.getAttribute("groupKey") != null;
if (key) {
if (tag.getAttribute("bundle") == null) {
checkDefaultBundle(element, holder);
}
}
else if (tag.getAttribute("displayName") == null) {
registerProblem(element, holder, "displayName or key should be specified", "displayName", "key");
}
if (groupKey) {
if (tag.getAttribute("bundle") == null && tag.getAttribute("groupBundle") == null) {
checkDefaultBundle(element, holder);
}
}
else if (tag.getAttribute("groupName") == null) {
registerProblem(element, holder, "groupName or groupKey should be specified", "groupName", "groupKey");
}
}
}
}
};
}
示例11: getMulePath
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
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;
}
示例12: getAttribute
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
private XmlAttribute getAttribute(@NotNull XmlTag tag, @NotNull String attributeName) {
if (myCaseSensitive) {
return tag.getAttribute(attributeName);
}
for (XmlAttribute xmlAttribute : tag.getAttributes()) {
if (attributeName.equalsIgnoreCase(xmlAttribute.getName())) {
return xmlAttribute;
}
}
return null;
}
示例13: getAttributeChild
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@NotNull
final AttributeChildInvocationHandler getAttributeChild(final AttributeChildDescriptionImpl description) {
final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(description.getXmlName());
if (myStub != null && description.isStubbed()) {
AttributeStub stub = myStub.getAttributeStub(description.getXmlName());
StubParentStrategy strategy = StubParentStrategy.createAttributeStrategy(stub, myStub);
return new AttributeChildInvocationHandler(evaluatedXmlName, description, myManager, strategy, stub);
}
final XmlTag tag = getXmlTag();
if (tag != null) {
// TODO: this seems ugly
String ns = evaluatedXmlName.getNamespace(tag, getFile());
final XmlAttribute attribute = tag.getAttribute(description.getXmlName().getLocalName(), ns.equals(tag.getNamespace())? null:ns);
if (attribute != null) {
PsiUtilCore.ensureValid(attribute);
AttributeChildInvocationHandler semElement =
myManager.getSemService().getSemElement(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute);
if (semElement == null) {
final AttributeChildInvocationHandler take2 = myManager.getSemService().getSemElement(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute);
throw new AssertionError("No DOM at XML. Parent=" + tag + "; attribute=" + attribute + "; second attempt=" + take2);
}
return semElement;
}
}
return new AttributeChildInvocationHandler(evaluatedXmlName, description, myManager, new VirtualDomParentStrategy(this), null);
}
示例14: matches
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public boolean matches(XmlTag element) {
if (super.matches(element) && element.getAttribute("match", null) != null) {
final XsltTemplate t = XsltElementFactory.getInstance().wrapElement(element, XsltTemplate.class);
final QName mode = t.getMode();
if (mode != null) {
if (QNameUtil.equal(myMode, mode)) {
return true;
}
} else {
return myMode == null;
}
}
return false;
}
示例15: getClassReferencesElement
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
protected PsiElement getClassReferencesElement() {
final XmlTag tag = (XmlTag)myElement.getParent().getParent();
final XmlAttribute name = tag.getAttribute("name",null);
if (name != null) { return name.getValueElement(); }
return null;
}