本文整理汇总了Java中com.intellij.psi.xml.XmlTag.getAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java XmlTag.getAttributes方法的具体用法?Java XmlTag.getAttributes怎么用?Java XmlTag.getAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.xml.XmlTag
的用法示例。
在下文中一共展示了XmlTag.getAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getElementTooltip
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
@Nullable
public String getElementTooltip(@NotNull final PsiElement e) {
final XmlTag tag = (XmlTag)e;
final StringBuilder result = new StringBuilder("<");
result.append(tag.getName());
final XmlAttribute[] attributes = tag.getAttributes();
for (final XmlAttribute each : attributes) {
result.append(" ").append(each.getText());
}
if (tag.isEmpty()) {
result.append("/>");
}
else {
result.append(">...</").append(tag.getName()).append(">");
}
return result.toString();
}
示例2: apply
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
final XmlTag tag = PsiTreeUtil.getParentOfType(startElement, XmlTag.class);
if (tag == null) {
return;
}
for (XmlAttribute attribute : tag.getAttributes()) {
if (attribute.getName().startsWith(SdkConstants.XMLNS)) {
String uri = attribute.getValue();
if (uri != null && !uri.isEmpty() && uri.startsWith(URI_PREFIX) && !uri.equals(ANDROID_URI)) {
attribute.setValue(AUTO_URI);
}
}
}
}
示例3: registerExistingAttributes
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@NotNull
private static Set<XmlName> registerExistingAttributes(AndroidFacet facet,
XmlTag tag,
MyCallback callback,
AndroidDomElement element) {
final Set<XmlName> result = new HashSet<XmlName>();
XmlAttribute[] attrs = tag.getAttributes();
for (XmlAttribute attr : attrs) {
String localName = attr.getLocalName();
if (!localName.endsWith(CompletionUtil.DUMMY_IDENTIFIER_TRIMMED)) {
if (!"xmlns".equals(attr.getNamespacePrefix())) {
AttributeDefinition attrDef = AndroidDomUtil.getAttributeDefinition(facet, attr);
if (attrDef != null) {
String namespace = attr.getNamespace();
result.add(new XmlName(attr.getLocalName(), attr.getNamespace()));
registerAttribute(attrDef, null, namespace.length() > 0 ? namespace : null, callback, null, element);
}
}
}
}
return result;
}
示例4: isMyFile
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) {
if (!super.isMyFile(file, module)) {
return false;
}
final XmlTag rootTag = file.getRootTag();
if (rootTag == null || rootTag.getNamespace().length() > 0) {
return false;
}
for (XmlAttribute attribute : rootTag.getAttributes()) {
if (attribute.getName().equals("xmlns")) {
return false;
}
}
return true;
}
示例5: addNamespaceAttributes
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void addNamespaceAttributes(XmlTag tag, Map<String, String> namespaces, Project project) {
final XmlAttribute[] parentAttributes = tag.getAttributes();
final XmlAttribute firstParentAttribute = parentAttributes.length > 0 ? parentAttributes[0] : null;
final XmlElementFactory factory = XmlElementFactory.getInstance(project);
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
final String prefix = entry.getKey();
final String namespace = entry.getValue();
if (!namespace.equals(tag.getNamespaceByPrefix(prefix))) {
final XmlAttribute xmlnsAttr = factory.createXmlAttribute("xmlns:" + prefix, namespace);
if (firstParentAttribute != null) {
tag.addBefore(xmlnsAttr, firstParentAttribute);
}
else {
tag.add(xmlnsAttr);
}
}
}
}
示例6: visitXmlElement
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
void visitXmlElement(XmlElement element, ElementStub parent, int index) {
DomInvocationHandler handler = myManager.getDomHandler(element);
if (handler == null || handler.getAnnotation(Stubbed.class) == null && !handler.getChildDescription().isStubbed()) return;
AbstractDomChildrenDescription description = handler.getChildDescription();
String nsKey = description instanceof DomChildrenDescription ? ((DomChildrenDescription)description).getXmlName().getNamespaceKey() : "";
if (element instanceof XmlTag) {
XmlTag tag = (XmlTag)element;
String elementClass = null;
if (handler.getAnnotation(StubbedOccurrence.class) != null) {
final Type type = description.getType();
elementClass = ((Class)type).getName();
}
ElementStub stub = new ElementStub(parent,
StringRef.fromString(tag.getName()),
StringRef.fromNullableString(nsKey),
index,
description instanceof CustomDomChildrenDescription,
elementClass == null ? null : StringRef.fromNullableString(elementClass),
tag.getSubTags().length == 0 ? tag.getValue().getTrimmedText() : "");
for (XmlAttribute attribute : tag.getAttributes()) {
visitXmlElement(attribute, stub, 0);
}
Map<String, Integer> indices = new HashMap<String, Integer>();
for (final XmlTag subTag : tag.getSubTags()) {
String name = subTag.getName();
Integer i = indices.get(name);
i = i == null ? 0 : i + 1;
visitXmlElement(subTag, stub, i);
indices.put(name, i);
}
} else if (element instanceof XmlAttribute) {
new AttributeStub(parent, StringRef.fromString(((XmlAttribute)element).getLocalName()),
StringRef.fromNullableString(nsKey),
((XmlAttribute)element).getValue());
}
}
示例7: annotate
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
public void annotate(@NotNull XmlTag tag, @NotNull ProblemsHolder holder) {
for (XmlAttribute xmlAttribute : tag.getAttributes()) {
String attrName = xmlAttribute.getName();
if (!ArrayUtil.contains(attrName, myAttrNames)) {
PsiElement attributeNameElement = getAttributeNameElement(xmlAttribute);
if (attributeNameElement != null) {
holder.registerProblem(attributeNameElement, myText, myType, new RemoveAttributeIntentionAction(attrName));
}
}
}
}
示例8: addAttributeReferenceCompletionVariants
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public static void addAttributeReferenceCompletionVariants(XmlAttributeReference reference, CompletionResultSet result,
@Nullable InsertHandler<LookupElement> replacementInsertHandler) {
final XmlTag declarationTag = reference.getElement().getParent();
LOG.assertTrue(declarationTag.isValid());
final XmlElementDescriptor parentDescriptor = declarationTag.getDescriptor();
if (parentDescriptor != null) {
final XmlAttribute[] attributes = declarationTag.getAttributes();
XmlAttributeDescriptor[] descriptors = parentDescriptor.getAttributesDescriptors(declarationTag);
descriptors = HtmlUtil.appendHtmlSpecificAttributeCompletions(declarationTag, descriptors, reference.getElement());
addVariants(result, attributes, descriptors, reference.getElement(), replacementInsertHandler);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:XmlAttributeReferenceCompletionProvider.java
示例9: parseAttributeName
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Nullable
private String parseAttributeName() {
String name = "";
ZenCodingToken token = getToken();
while (token != null) {
if ((token instanceof IdentifierToken)) {
name += ((IdentifierToken)token).getText();
}
else if (token instanceof OperationToken &&
(((OperationToken)token).getSign() == '+' || ((OperationToken)token).getSign() == '-')) {
name += ((OperationToken)token).getSign();
}
else {
break;
}
advance();
token = getToken();
}
if (name.isEmpty()) {
return null;
}
final XmlTag tag = XmlElementFactory.getInstance(myCallback.getProject()).createTagFromText("<tag " + name + "=''/>", StdLanguages.HTML);
XmlAttribute[] attributes = tag.getAttributes();
if (attributes.length == 1) {
return attributes[0].getName();
}
else {
return null;
}
}
示例10: 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;
}
示例11: getExtractableAttributes
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@NotNull
static List<XmlAttribute> getExtractableAttributes(@NotNull XmlTag viewTag) {
final List<XmlAttribute> extractableAttributes = new ArrayList<XmlAttribute>();
for (XmlAttribute attribute : viewTag.getAttributes()) {
if (canBeExtracted(attribute)) {
extractableAttributes.add(attribute);
}
}
return extractableAttributes;
}
示例12: convertNamespacePrefix
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void convertNamespacePrefix(XmlTag xmlTag, String namespacePrefix) {
for (XmlAttribute attribute : xmlTag.getAttributes()) {
if (ANDROID_NS_NAME.equals(attribute.getNamespacePrefix())) {
attribute.setName(namespacePrefix + ":" + attribute.getLocalName());
}
}
for (XmlTag subTag : xmlTag.getSubTags()) {
convertNamespacePrefix(subTag, namespacePrefix);
}
}
示例13: createAttributesForTag
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
/** Creates a list of attribute snapshots corresponding to the attributes of the given tag */
@NotNull
public static List<AttributeSnapshot> createAttributesForTag(@NotNull XmlTag tag) {
// Attributes
XmlAttribute[] psiAttributes = tag.getAttributes();
List<AttributeSnapshot> attributes = Lists.newArrayListWithExpectedSize(psiAttributes.length);
for (XmlAttribute psiAttribute : psiAttributes) {
AttributeSnapshot attribute = createAttributeSnapshot(psiAttribute);
if (attribute != null) {
attributes.add(attribute);
}
}
return attributes;
}
示例14: attributesEqual
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static boolean attributesEqual(XmlTag genTag, XmlTag expTag) {
final XmlAttribute[] gattributes = genTag.getAttributes();
final XmlAttribute[] eattributes = expTag.getAttributes();
if (gattributes.length != eattributes.length) return false;
for (int i = 0; i < eattributes.length; i++) {
XmlAttribute eattribute = eattributes[i];
XmlAttribute gattribute = gattributes[i];
// logical comparison of the attributes (namespace:localname and display value)
if (!Comparing.strEqual(gattribute.getLocalName(), eattribute.getLocalName())) return false;
if (!Comparing.strEqual(gattribute.getNamespace(), eattribute.getNamespace())) return false;
if (!Comparing.strEqual(gattribute.getDisplayValue(), eattribute.getDisplayValue())) return false;
}
return true;
}
示例15: diagnoseNegativeIndex2
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static <T extends DomElement> void diagnoseNegativeIndex2(T t,
DomElement parent,
AbstractDomChildrenDescription description,
List<? extends DomElement> values) {
final XmlTag parentTag = parent.getXmlTag();
StringBuilder diag = new StringBuilder("Index<0: description=" + description + "\nparent=" + parent + "\nt=" + t + "\nvalues=" + values + "\n");
for (int i = 0, size = values.size(); i < size; i++) {
DomElement value = values.get(i);
if (value.toString().equals(t.toString())) {
final XmlElement tElement = t.getXmlElement();
final XmlElement valElement = value.getXmlElement();
diag.append(" hasSame, i=" + i +
"; same=" + (value == t) +
", equal=" + value.equals(t) +
", equal2=" + t.equals(value) +
", t.physical=" + (tElement == null ? "null" : String.valueOf(tElement.isPhysical())) +
", value.physical=" + (valElement == null ? "null" : String.valueOf(valElement.isPhysical())) +
", sameElements=" + (tElement == value.getXmlElement()) +
"\n");
if (tElement != null && valElement != null) {
diag.append(" sameFile=" + (tElement.getContainingFile() == valElement.getContainingFile()) +
", sameParent=" + (tElement.getParent() == valElement.getParent()) +
"\n");
}
}
}
if (parentTag != null) {
diag.append("Parent tag: ").append(parentTag.getName()).append("\n");
if (t instanceof GenericAttributeValue) {
for (XmlAttribute attribute : parentTag.getAttributes()) {
diag.append(", attr: ").append(attribute.getName());
}
diag.append("\n");
} else {
for (XmlTag tag : parentTag.getSubTags()) {
diag.append("\n subtag: ").append(tag.getName());
}
diag.append("\n");
}
}
diag.append("Child name: ").append(t.getXmlElementName()).append(";").append(t.getXmlElementNamespaceKey());
LOG.error(diag);
}