本文整理汇总了Java中com.intellij.psi.xml.XmlTag.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java XmlTag.setAttribute方法的具体用法?Java XmlTag.setAttribute怎么用?Java XmlTag.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.xml.XmlTag
的用法示例。
在下文中一共展示了XmlTag.setAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
final XmlTag parentTag = tag.getParentTag();
if (parentTag == null) {
return;
}
String attrName;
if (AndroidLintUtil.ATTR_VALUE_VERTICAL
.equals(parentTag.getAttributeValue(AndroidLintUtil.ATTR_ORIENTATION, SdkConstants.NS_RESOURCES))) {
attrName = AndroidLintUtil.ATTR_LAYOUT_HEIGHT;
}
else {
attrName = AndroidLintUtil.ATTR_LAYOUT_WIDTH;
}
tag.setAttribute(attrName, SdkConstants.NS_RESOURCES, "0dp");
}
示例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;
}
final XmlTag parentTag = tag.getParentTag();
if (parentTag == null) {
return;
}
final boolean isHorizontal = SdkConstants.HORIZONTAL_SCROLL_VIEW.equals(parentTag.getName());
final String attributeName = isHorizontal
? AndroidLintUtil.ATTR_LAYOUT_WIDTH
: AndroidLintUtil.ATTR_LAYOUT_HEIGHT;
tag.setAttribute(attributeName, SdkConstants.NS_RESOURCES, AndroidLintUtil.ATTR_VALUE_WRAP_CONTENT);
}
示例3: 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);
}
示例4: assignLayout
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void assignLayout(
@NotNull final Project project,
@NotNull final XmlFile file,
@NotNull final String activityName,
@NotNull final String layout) {
WriteCommandAction<Void> action = new WriteCommandAction<Void>(project, "Assign Preview Layout", file) {
@Override
protected void run(@NotNull Result<Void> result) throws Throwable {
SuppressLintIntentionAction.ensureNamespaceImported(getProject(), file, TOOLS_URI);
Collection<XmlTag> xmlTags = PsiTreeUtil.findChildrenOfType(file, XmlTag.class);
for (XmlTag tag : xmlTags) {
if (tag.getName().equals(VIEW_FRAGMENT) ) {
String name = tag.getAttributeValue(ATTR_CLASS);
if (name == null || name.isEmpty()) {
name = tag.getAttributeValue(ATTR_NAME, ANDROID_URI);
}
if (activityName.equals(name)) {
tag.setAttribute(ATTR_LAYOUT, TOOLS_URI, layout);
}
}
}
}
};
action.execute();
}
示例5: applyFix
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
try {
final XmlTag tag = (XmlTag)descriptor.getPsiElement();
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.getPsiElement().getContainingFile())) return;
final XmlAttribute attribute = tag.setAttribute(myAttrName, myNamespace, "");
new OpenFileDescriptor(project, tag.getContainingFile().getVirtualFile(),
attribute.getValueElement().getTextRange().getStartOffset() + 1).navigate(true);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
示例6: setName
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
static void setName(final XmlTag dcl, final String name) throws IncorrectOperationException {
if (dcl.isWritable()) {
final VirtualFile virtualFile = dcl.getContainingFile().getVirtualFile();
if (virtualFile!=null &&
ProjectRootManager.getInstance(dcl.getProject()).getFileIndex().getModuleForFile(virtualFile)!=null
) {
dcl.setAttribute("name",name.substring(name.indexOf(':')+1));
}
}
}
示例7: configureManifest
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void configureManifest(@NotNull AndroidFacet facet, @NotNull IAndroidTarget target) {
final Manifest manifest = facet.getManifest();
if (manifest == null) {
return;
}
final XmlTag manifestTag = manifest.getXmlTag();
if (manifestTag == null) {
return;
}
final PsiFile manifestFile = manifestTag.getContainingFile();
if (manifestFile == null) {
return;
}
final VirtualFile vManifestFile = manifestFile.getVirtualFile();
if (vManifestFile == null ||
!ReadonlyStatusHandler.ensureFilesWritable(manifestFile.getProject(), vManifestFile)) {
return;
}
XmlTag usesSdkTag = manifestTag.createChildTag("uses-sdk", "", null, false);
if (usesSdkTag != null) {
usesSdkTag = manifestTag.addSubTag(usesSdkTag, true);
usesSdkTag.setAttribute("minSdkVersion", SdkConstants.NS_RESOURCES, target.getVersion().getApiString());
}
CodeStyleManager.getInstance(manifestFile.getProject()).reformat(manifestFile);
}
示例8: 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, false);
if (tag == null) {
return;
}
String value = myValue;
if (value == null && context instanceof AndroidQuickfixContexts.DesignerContext) {
value = askForAttributeValue(tag);
if (value == null) {
return;
}
}
final XmlAttribute attribute = tag.setAttribute(myAttributeName, SdkConstants.NS_RESOURCES, "");
if (attribute != null) {
if (value != null) {
attribute.setValue(value);
}
if (context instanceof AndroidQuickfixContexts.EditorContext) {
final Editor editor = ((AndroidQuickfixContexts.EditorContext)context).getEditor();
final XmlAttributeValue valueElement = attribute.getValueElement();
final TextRange valueTextRange = attribute.getValueTextRange();
if (valueElement != null && valueTextRange != null) {
final int valueElementStart = valueElement.getTextRange().getStartOffset();
editor.getCaretModel().moveToOffset(valueElementStart + valueTextRange.getStartOffset());
if (valueTextRange.getStartOffset() < valueTextRange.getEndOffset()) {
editor.getSelectionModel().setSelection(valueElementStart + valueTextRange.getStartOffset(),
valueElementStart + valueTextRange.getEndOffset());
}
}
}
}
}
示例9: assignId
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
/**
* Assign a suitable new and unique id to the given component. The set of
* existing id's is provided in the given list.
*/
@NotNull
public String assignId(RadViewComponent component, Collection<String> idList) {
String idValue = StringUtil.decapitalize(component.getMetaModel().getTag());
XmlTag tag = component.getTag();
Module module = AndroidPsiUtils.getModuleSafely(tag);
if (module != null) {
idValue = ResourceHelper.prependResourcePrefix(module, idValue);
}
String nextIdValue = idValue;
int index = 0;
// Ensure that we don't create something like "switch" as an id, which won't compile when used
// in the R class
NamesValidator validator = LanguageNamesValidation.INSTANCE.forLanguage(JavaLanguage.INSTANCE);
Project project = tag.getProject();
while (idList.contains(nextIdValue) || validator != null && validator.isKeyword(nextIdValue, project)) {
++index;
if (index == 1 && (validator == null || !validator.isKeyword(nextIdValue, project))) {
nextIdValue = idValue;
} else {
nextIdValue = idValue + Integer.toString(index);
}
}
String newId = NEW_ID_PREFIX + idValue + (index == 0 ? "" : Integer.toString(index));
tag.setAttribute(ATTR_ID, ANDROID_URI, newId);
return newId;
}
示例10: performWriteAction
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
protected void performWriteAction() {
XmlTag tag = myLayout.getTag();
if (myAlign) {
// TODO: Also set index?
XmlAttribute attribute = tag.getAttribute(ATTR_BASELINE_ALIGNED, ANDROID_URI);
if (attribute != null) {
attribute.delete();
}
} else {
tag.setAttribute(ATTR_BASELINE_ALIGNED, ANDROID_URI, VALUE_FALSE);
}
}
示例11: performWriteAction
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
protected void performWriteAction() {
boolean isFill = isFill();
for (RadViewComponent component : myComponents) {
XmlTag tag = component.getTag();
if (isFill) {
tag.setAttribute(myAttribute, ANDROID_URI, VALUE_WRAP_CONTENT);
} else {
// TODO: Worry about using FILL_PARENT on older platforms?
tag.setAttribute(myAttribute, ANDROID_URI, VALUE_MATCH_PARENT);
}
}
}
示例12: execute
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private void execute(String cell, String span, boolean cellFix) {
XmlTag tag = myComponent.getTag();
if (cellFix) {
tag.setAttribute(cell, SdkConstants.NS_RESOURCES, Integer.toString(myCells[myIndex]));
}
int spanValue = mySpans[myIndex];
if (spanValue == 1) {
RadComponentOperations.deleteAttribute(tag, span);
}
else {
tag.setAttribute(span, SdkConstants.NS_RESOURCES, Integer.toString(spanValue));
}
}
示例13: setValue
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private void setValue(XmlTag tag, String name, int pxValue) {
int value = AndroidDesignerUtils.pxToDp(myContext.getArea(), pxValue);
if (value == 0) {
RadComponentOperations.deleteAttribute(tag, name);
}
else {
tag.setAttribute(name, SdkConstants.NS_RESOURCES, String.format(Locale.US, VALUE_N_DP, value));
}
}
示例14: run
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
protected void run(@NotNull Result<Void> result) throws Throwable {
final List<XmlTag> missing = findViewsMissingSizes();
for (XmlTag tag : missing) {
if (!definesWidth(tag, myResourceResolver)) {
tag.setAttribute(ATTR_LAYOUT_WIDTH, ANDROID_URI, getDefaultWidth(tag));
}
if (!definesHeight(tag, myResourceResolver)) {
tag.setAttribute(ATTR_LAYOUT_HEIGHT, ANDROID_URI, getDefaultHeight(tag));
}
}
}
示例15: updateAttributeForElement
import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private void updateAttributeForElement(@NotNull XmlAttribute attribute, int minSdk) {
final String attributeLocalName = attribute.getLocalName();
LOG.info("Updating attribute name: " + attributeLocalName + " value: " + attribute.getValue());
if (attributeLocalName.equals(ATTR_GRAVITY) || attributeLocalName.equals(ATTR_LAYOUT_GRAVITY)) {
// Special case for android:gravity and android:layout_gravity
final String value = StringUtil.notNullize(attribute.getValue());
final String newValue = value.replace(GRAVITY_VALUE_LEFT, GRAVITY_VALUE_START).replace(GRAVITY_VALUE_RIGHT, GRAVITY_VALUE_END);
attribute.setValue(newValue);
LOG.info("Changing gravity from: " + value + " to: " + newValue);
}
else {
// General case for RTL attributes
final String mirroredAttributeLocalName = ourMapMirroredAttributeName.get(attributeLocalName);
if (mirroredAttributeLocalName == null) {
LOG.warn("Cannot mirror attribute: " + attribute.toString());
return;
}
final String mirroredAttributeName = attribute.getNamespacePrefix() + ":" + mirroredAttributeLocalName;
XmlAttribute attributeForUpdatingValue;
if (myProperties.replaceLeftRightPropertiesOption) {
attribute.setName(mirroredAttributeName);
LOG.info("Replacing attribute name from: " + attributeLocalName + " to: " + mirroredAttributeLocalName);
attributeForUpdatingValue = attribute;
}
else {
XmlTag parent = attribute.getParent();
attributeForUpdatingValue = parent.setAttribute(mirroredAttributeName, StringUtil.notNullize(attribute.getValue()));
LOG.info("Adding attribute name: " + mirroredAttributeName + " value: " + attribute.getValue());
}
// Special case for updating attribute value
updateAttributeValueIfNeeded(attributeForUpdatingValue, minSdk);
}
}