org.jboss.shrinkwrap.descriptor.spi.node.Node.setComment()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(2.5k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中org.jboss.shrinkwrap.descriptor.spi.node.Node.setComment()方法的一些代码示例,展示了Node.setComment()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.setComment()方法的具体详情如下:
包路径:org.jboss.shrinkwrap.descriptor.spi.node.Node
类名称:Node
方法名:setComment

Node.setComment介绍

[英]Marks this Node as a comment
[中]将此节点标记为注释

代码示例

代码示例来源:origin: org.projectodd.shrinkwrap.descriptors/shrinkwrap-descriptors-spi

  1. private void readRecursive(final Node target, final org.w3c.dom.Node source) {
  2. readAttributes(target, source);
  3. final NodeList sourceChildren = source.getChildNodes();
  4. if (sourceChildren != null) {
  5. for (int i = 0; i < sourceChildren.getLength(); i++) {
  6. final org.w3c.dom.Node child = sourceChildren.item(i);
  7. if (child.getNodeType() != org.w3c.dom.Node.TEXT_NODE) {
  8. // Create our representation of the Node
  9. final Node newTarget = target.createChild(child.getNodeName());
  10. if (onlyTextChildren(child)) {
  11. // See if we're dealing with a comment and mark specifically
  12. if (child.getNodeType() == org.w3c.dom.Node.COMMENT_NODE) {
  13. newTarget.setComment(true);
  14. }
  15. // Set text
  16. newTarget.text(child.getTextContent());
  17. readAttributes(newTarget, child);
  18. } else {
  19. readRecursive(newTarget, child);
  20. }
  21. } else {
  22. target.text(child.getTextContent());
  23. }
  24. }
  25. }
  26. }

代码示例来源:origin: org.jboss.shrinkwrap.descriptors/shrinkwrap-descriptors-spi

  1. private void readRecursive(final Node target, final org.w3c.dom.Node source) {
  2. readAttributes(target, source);
  3. final NodeList sourceChildren = source.getChildNodes();
  4. if (sourceChildren != null) {
  5. for (int i = 0; i < sourceChildren.getLength(); i++) {
  6. final org.w3c.dom.Node child = sourceChildren.item(i);
  7. if (child.getNodeType() != org.w3c.dom.Node.TEXT_NODE) {
  8. // Create our representation of the Node
  9. final Node newTarget = target.createChild(child.getNodeName());
  10. if (onlyTextChildren(child)) {
  11. // See if we're dealing with a comment and mark specifically
  12. if (child.getNodeType() == org.w3c.dom.Node.COMMENT_NODE) {
  13. newTarget.setComment(true);
  14. }
  15. // Set text
  16. newTarget.text(child.getTextContent());
  17. readAttributes(newTarget, child);
  18. } else {
  19. readRecursive(newTarget, child);
  20. }
  21. } else {
  22. target.text(child.getTextContent());
  23. }
  24. }
  25. }
  26. }

代码示例来源:origin: stackoverflow.com

  1. import japa.parser.JavaParser;
  2. import japa.parser.ParseException;
  3. import japa.parser.ast.CompilationUnit;
  4. import japa.parser.ast.Node;
  5. import java.io.File;
  6. import java.io.IOException;
  7. public class RemoveAllComments {
  8. static void removeComments(Node node) {
  9. for (Node child : node.getChildrenNodes()) {
  10. child.setComment(null);
  11. removeComments(child);
  12. }
  13. }
  14. public static void main(String[] args) throws ParseException, IOException {
  15. File sourceFile = new File("Test.java");
  16. CompilationUnit cu = JavaParser.parse(sourceFile);
  17. removeComments(cu);
  18. System.out.println(cu.toString());
  19. }
  20. }

相关文章