当前位置: 首页>>代码示例>>Java>>正文


Java XmlTag.add方法代码示例

本文整理汇总了Java中com.intellij.psi.xml.XmlTag.add方法的典型用法代码示例。如果您正苦于以下问题:Java XmlTag.add方法的具体用法?Java XmlTag.add怎么用?Java XmlTag.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.xml.XmlTag的用法示例。


在下文中一共展示了XmlTag.add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertSchemaLocationLookup

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public static void insertSchemaLocationLookup(XmlFile xmlFile, String namespace, String locationLookup) {
    final XmlTag rootTag = xmlFile.getRootTag();
    if (rootTag == null)
        return;
    final XmlAttribute attribute = rootTag.getAttribute("xsi:schemaLocation", HTTP_WWW_W3_ORG_2001_XMLSCHEMA);
    if (attribute != null) {
        final String value = attribute.getValue();
        attribute.setValue(value + "\n\t\t\t" + namespace + " " + locationLookup);
    } else {
        final XmlElementFactory elementFactory = XmlElementFactory.getInstance(xmlFile.getProject());
        final XmlAttribute schemaLocation = elementFactory.createXmlAttribute("xsi:schemaLocation", XmlUtil.XML_SCHEMA_INSTANCE_URI);
        schemaLocation.setValue(namespace + " " + locationLookup);
        rootTag.add(schemaLocation);
    }

}
 
开发者ID:machaval,项目名称:mule-intellij-plugins,代码行数:17,代码来源:MuleSchemaUtils.java

示例2: addEmptyTag

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private XmlTag addEmptyTag(final EvaluatedXmlName tagName, int index) throws IncorrectOperationException {
  final XmlTag tag = ensureTagExists();
  final List<XmlTag> subTags = DomImplUtil.findSubTags(tag, tagName, getFile());
  if (subTags.size() < index) {
    index = subTags.size();
  }
  final boolean changing = myManager.setChanging(true);
  try {
    XmlTag newTag = createChildTag(tagName);
    if (index == 0) {
      if (subTags.isEmpty()) {
        return (XmlTag)tag.add(newTag);
      }

      return (XmlTag)tag.addBefore(newTag, subTags.get(0));
    }

    return (XmlTag)tag.addAfter(newTag, subTags.get(index - 1));
  }
  finally {
    myManager.setChanging(changing);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:DomInvocationHandler.java

示例3: testCustomChildrenEvents

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
public void testCustomChildrenEvents() throws Throwable {
  final Sepulka element = createElement("<a><foo/><bar/></a>", Sepulka.class);
  final List<MyElement> list = element.getCustomChildren();
  final XmlTag tag = element.getXmlTag();
  WriteCommandAction.runWriteCommandAction(null, new Runnable(){
    @Override
    public void run() {
      tag.getSubTags()[0].delete();
      tag.getSubTags()[0].delete();
    }
  });

  tag.add(createTag("<goo/>"));
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  putExpected(new DomEvent(element, false));
  assertResultsAndClear();

  assertEquals(1, element.getCustomChildren().size());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:TreeIncrementalUpdateTest.java

示例4: 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);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:LayoutUsageData.java

示例5: invoke

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().preparePsiElementsForWrite(element)) return;
  final XmlTag tag = (XmlTag)element.getParent();
  final String value;
  if (tag.getSubTags().length == 0) {
    value = tag.getValue().getText().trim();
  }
  else {
    value = StringUtil.join(tag.getSubTags(), new Function<XmlTag, String>() {
      @Override
      public String fun(XmlTag childTag) {
        final XmlAttribute valueAttr = childTag.getAttribute(FxmlConstants.FX_VALUE);
        if (valueAttr != null) {
          return valueAttr.getValue();
        }
        return "";
      }
    }, ", ");
  }
  final XmlAttribute attribute = XmlElementFactory.getInstance(project).createXmlAttribute(tag.getName(), value);
  final XmlTag parentTag = tag.getParentTag();
  parentTag.add(attribute);
  tag.delete();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:JavaFxCollapseSubTagToAttributeIntention.java

示例6: doFix

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private void doFix(XmlTag parentTag) {
  if (!FileModificationService.getInstance().prepareFileForWrite(parentTag.getContainingFile())) return;

  try {
    parentTag.add(parentTag.createChildTag(tagName, tagNamespace, null, false));
  }
  catch (IncorrectOperationException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:DomHighlightingHelperImpl.java

示例7: doIt

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void doIt(final PsiFile file, final Editor editor, final String uri, final XmlTag tag, final String s) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
  final XmlElementFactory elementFactory = XmlElementFactory.getInstance(file.getProject());

  if (tag.getAttributeValue(XMLNS_XSI_ATTR_NAME) == null) {
    tag.add(elementFactory.createXmlAttribute(XMLNS_XSI_ATTR_NAME, XmlUtil.XML_SCHEMA_INSTANCE_URI));
  }

  final XmlAttribute locationAttribute = tag.getAttribute(XSI_SCHEMA_LOCATION_ATTR_NAME);
  final String toInsert = uri + " " + s;
  int offset = s.length();

  if (locationAttribute == null) {
    tag.add(elementFactory.createXmlAttribute(XSI_SCHEMA_LOCATION_ATTR_NAME, toInsert));
  } else {
    final String newValue = locationAttribute.getValue() + "\n" + toInsert;
    locationAttribute.setValue(newValue);
  }

  PsiDocumentManager.getInstance(file.getProject()).doPostponedOperationsAndUnblockDocument(editor.getDocument());
  CodeStyleManager.getInstance(file.getProject()).reformat(tag);

  @SuppressWarnings("ConstantConditions")
  final TextRange range = tag.getAttribute(XSI_SCHEMA_LOCATION_ATTR_NAME).getValueElement().getTextRange();
  final TextRange textRange = new TextRange(range.getEndOffset() - offset - 1, range.getEndOffset() - 1);
  editor.getCaretModel().moveToOffset(textRange.getStartOffset());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:AddXsiSchemaLocationForExtResourceAction.java

示例8: addMissingAttributes

import com.intellij.psi.xml.XmlTag; //导入方法依赖的package包/类
private static void addMissingAttributes(@NotNull XmlTag tag, @NotNull Map<String, String> attributes) {
  for (Map.Entry<String, String> attribute : attributes.entrySet()) {
    if (!XmlEmmetParser.DEFAULT_ATTRIBUTE_NAME.equals(attribute.getKey()) && tag.getAttribute(attribute.getKey()) == null) {
      XmlTag htmlTag = XmlElementFactory.getInstance(tag.getProject()).createHTMLTagFromText("<dummy " + attribute.getKey() + "=\"\"/>");
      final XmlAttribute newAttribute = ArrayUtil.getFirstElement(htmlTag.getAttributes());
      if (newAttribute != null) {
        tag.add(newAttribute);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:TemplateToken.java


注:本文中的com.intellij.psi.xml.XmlTag.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。