org.eclipse.jdt.core.dom.CompilationUnit.getModule()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(120)

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

CompilationUnit.getModule介绍

[英]Returns the node for the module declaration of this compilation unit, or null if this compilation unit is not a module info.
[中]返回此编译单元的模块声明的节点,如果此编译单元不是模块信息,则返回null

代码示例

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

public boolean visit(CompilationUnit node) {
  if (node.getAST().apiLevel() >= JLS9) {
    if (node.getModule() != null) {
      node.getModule().accept(this);
    }
  }
  if (node.getPackage() != null) {
    node.getPackage().accept(this);
  }
  for (Iterator it = node.imports().iterator(); it.hasNext(); ) {
    ImportDeclaration d = (ImportDeclaration) it.next();
    d.accept(this);
  }
  for (Iterator it = node.types().iterator(); it.hasNext(); ) {
    AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
    d.accept(this);
  }
  return false;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core.manipulation

@Override
public boolean visit(CompilationUnit node) {
  if (node.getAST().apiLevel() >= JLS9) {
    if (node.getModule() != null) {
      node.getModule().accept(this);
    }
  }
  if (node.getPackage() != null) {
    node.getPackage().accept(this);
  }
  for (Iterator<ImportDeclaration> it= node.imports().iterator(); it.hasNext();) {
    ImportDeclaration d= it.next();
    d.accept(this);
  }
  for (Iterator<AbstractTypeDeclaration> it= node.types().iterator(); it.hasNext();) {
    AbstractTypeDeclaration d= it.next();
    d.accept(this);
  }
  return false;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

@Override
public boolean visit(CompilationUnit node) {
  if (node.getAST().apiLevel() >= JLS9) {
    if (node.getModule() != null) {
      node.getModule().accept(this);
    }
  }
  if (node.getPackage() != null) {
    node.getPackage().accept(this);
  }
  for (Iterator it = node.imports().iterator(); it.hasNext(); ) {
    ImportDeclaration d = (ImportDeclaration) it.next();
    d.accept(this);
  }
  for (Iterator it = node.types().iterator(); it.hasNext(); ) {
    AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
    d.accept(this);
  }
  return false;
}

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
  if (property == MODULE_PROPERTY) {
    if (get) {
      return getModule();
    } else {
      setModule((ModuleDeclaration) child);
      return null;
    }
  }
  if (property == PACKAGE_PROPERTY) {
    if (get) {
      return getPackage();
    } else {
      setPackage((PackageDeclaration) child);
      return null;
    }
  }
  // allow default implementation to flag the error
  return super.internalGetSetChildProperty(property, get, child);
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

@Override
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
  if (property == MODULE_PROPERTY) {
    if (get) {
      return getModule();
    } else {
      setModule((ModuleDeclaration) child);
      return null;
    }
  }
  if (property == PACKAGE_PROPERTY) {
    if (get) {
      return getPackage();
    } else {
      setPackage((PackageDeclaration) child);
      return null;
    }
  }
  // allow default implementation to flag the error
  return super.internalGetSetChildProperty(property, get, child);
}

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

int treeSize() {
  int size = memSize();
  if (this.module != null) {
    size += getModule().treeSize();
  }
  if (this.optionalPackageDeclaration != null) {
    size += getPackage().treeSize();
  }
  size += this.imports.listSize();
  size += this.types.listSize();
  // include disconnected comments
  if (this.optionalCommentList != null) {
    for (int i = 0; i < this.optionalCommentList.size(); i++) {
      Comment comment = (Comment) this.optionalCommentList.get(i);
      if (comment != null && comment.getParent() == null) {
        size += comment.treeSize();
      }
    }
  }
  return size;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

@Override
int treeSize() {
  int size = memSize();
  if (this.module != null) {
    size += getModule().treeSize();
  }
  if (this.optionalPackageDeclaration != null) {
    size += getPackage().treeSize();
  }
  size += this.imports.listSize();
  size += this.types.listSize();
  // include disconnected comments
  if (this.optionalCommentList != null) {
    for (int i = 0; i < this.optionalCommentList.size(); i++) {
      Comment comment = (Comment) this.optionalCommentList.get(i);
      if (comment != null && comment.getParent() == null) {
        size += comment.treeSize();
      }
    }
  }
  return size;
}

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

void accept0(ASTVisitor visitor) {
  boolean visitChildren = visitor.visit(this);
  if (visitChildren) {
    // visit children in normal left to right reading order
    if (this.ast.apiLevel >= AST.JLS9_INTERNAL) {
      acceptChild(visitor, getModule());
    }
    acceptChild(visitor, getPackage());
    acceptChildren(visitor, this.imports);
    acceptChildren(visitor, this.types);
  }
  visitor.endVisit(this);
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

@Override
void accept0(ASTVisitor visitor) {
  boolean visitChildren = visitor.visit(this);
  if (visitChildren) {
    // visit children in normal left to right reading order
    if (this.ast.apiLevel >= AST.JLS9_INTERNAL) {
      acceptChild(visitor, getModule());
    }
    acceptChild(visitor, getPackage());
    acceptChildren(visitor, this.imports);
    acceptChildren(visitor, this.types);
  }
  visitor.endVisit(this);
}

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

/**
 * Returns whether the given node and the other object match.
 * <p>
 * The default implementation provided by this class tests whether the
 * other object is a node of the same type with structurally isomorphic
 * child subtrees. Subclasses may override this method as needed.
 * </p>
 *
 * @param node the node
 * @param other the other object, or <code>null</code>
 * @return <code>true</code> if the subtree matches, or
 *   <code>false</code> if they do not match or the other object has a
 *   different node type or is <code>null</code>
 */
public boolean match(CompilationUnit node, Object other) {
  if (!(other instanceof CompilationUnit)) {
    return false;
  }
  CompilationUnit o = (CompilationUnit) other;
  return (
    (node.getAST().apiLevel >= AST.JLS9_INTERNAL ? safeSubtreeMatch(node.getModule(), o.getModule()) : true)
      && safeSubtreeMatch(node.getPackage(), o.getPackage())
      && safeSubtreeListMatch(node.imports(), o.imports())
      && safeSubtreeListMatch(node.types(), o.types()));
}

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

ASTNode clone0(AST target) {
  CompilationUnit result = new CompilationUnit(target);
  // n.b do not copy line number table or messages
  result.setSourceRange(getStartPosition(), getLength());
  if (this.ast.apiLevel >= AST.JLS9_INTERNAL) {
    result.setModule((ModuleDeclaration) ASTNode.copySubtree(target, getModule()));
  }
  result.setPackage(
    (PackageDeclaration) ASTNode.copySubtree(target, getPackage()));
  result.imports().addAll(ASTNode.copySubtrees(target, imports()));
  result.types().addAll(ASTNode.copySubtrees(target, types()));
  return result;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

/**
 * Returns whether the given node and the other object match.
 * <p>
 * The default implementation provided by this class tests whether the
 * other object is a node of the same type with structurally isomorphic
 * child subtrees. Subclasses may override this method as needed.
 * </p>
 *
 * @param node the node
 * @param other the other object, or <code>null</code>
 * @return <code>true</code> if the subtree matches, or
 *   <code>false</code> if they do not match or the other object has a
 *   different node type or is <code>null</code>
 */
public boolean match(CompilationUnit node, Object other) {
  if (!(other instanceof CompilationUnit)) {
    return false;
  }
  CompilationUnit o = (CompilationUnit) other;
  return (
    (node.getAST().apiLevel >= AST.JLS9_INTERNAL ? safeSubtreeMatch(node.getModule(), o.getModule()) : true)
      && safeSubtreeMatch(node.getPackage(), o.getPackage())
      && safeSubtreeListMatch(node.imports(), o.imports())
      && safeSubtreeListMatch(node.types(), o.types()));
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

@Override
ASTNode clone0(AST target) {
  CompilationUnit result = new CompilationUnit(target);
  // n.b do not copy line number table or messages
  result.setSourceRange(getStartPosition(), getLength());
  if (this.ast.apiLevel >= AST.JLS9_INTERNAL) {
    result.setModule((ModuleDeclaration) ASTNode.copySubtree(target, getModule()));
  }
  result.setPackage(
    (PackageDeclaration) ASTNode.copySubtree(target, getPackage()));
  result.imports().addAll(ASTNode.copySubtrees(target, imports()));
  result.types().addAll(ASTNode.copySubtrees(target, types()));
  return result;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

parser.setUnitName(JavaModelUtil.MODULE_INFO_JAVA);
unit= (CompilationUnit) parser.createAST(null);
if (unit.getModule() != null) {
  return Collections.singletonList(new ParsedCu(text, ASTParser.K_COMPILATION_UNIT, null, null, true));

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

public boolean visit(CompilationUnit node) {
  if (!hasChildrenChanges(node)) {
    return doVisitUnchangedChildren(node);
  }
  if (node.getAST().apiLevel() >= JLS9_INTERNAL && node.getModule() != null) {
    rewriteNode(node, CompilationUnit.MODULE_PROPERTY, 0, ASTRewriteFormatter.NONE);
    return false;
  }
  int startPos= rewriteNode(node, CompilationUnit.PACKAGE_PROPERTY, 0, ASTRewriteFormatter.NONE);
  if (getChangeKind(node, CompilationUnit.PACKAGE_PROPERTY) == RewriteEvent.INSERTED) {
    doTextInsert(0, getLineDelimiter(), getEditGroup(node, CompilationUnit.PACKAGE_PROPERTY));
  }
  startPos= rewriteParagraphList(node, CompilationUnit.IMPORTS_PROPERTY, startPos, 0, 0, 2);
  rewriteParagraphList(node, CompilationUnit.TYPES_PROPERTY, startPos, 0, -1, 2);
  return false;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

@Override
public boolean visit(CompilationUnit node) {
  if (!hasChildrenChanges(node)) {
    return doVisitUnchangedChildren(node);
  }
  if (node.getAST().apiLevel() >= JLS9_INTERNAL && node.getModule() != null) {
    rewriteNode(node, CompilationUnit.MODULE_PROPERTY, 0, ASTRewriteFormatter.NONE);
    return false;
  }
  int startPos= rewriteNode(node, CompilationUnit.PACKAGE_PROPERTY, 0, ASTRewriteFormatter.NONE);
  if (getChangeKind(node, CompilationUnit.PACKAGE_PROPERTY) == RewriteEvent.INSERTED) {
    doTextInsert(0, getLineDelimiter(), getEditGroup(node, CompilationUnit.PACKAGE_PROPERTY));
  }
  startPos= rewriteParagraphList(node, CompilationUnit.IMPORTS_PROPERTY, startPos, 0, 0, 2);
  rewriteParagraphList(node, CompilationUnit.TYPES_PROPERTY, startPos, 0, -1, 2);
  return false;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

ModuleDeclaration moduleDecl= astRoot.getModule();
if (moduleDecl == null) {
  return null;

相关文章

微信公众号

最新文章

更多