本文整理汇总了Java中com.github.javaparser.ast.CompilationUnit.getPackage方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit.getPackage方法的具体用法?Java CompilationUnit.getPackage怎么用?Java CompilationUnit.getPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.getPackage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override public void visit(final CompilationUnit n, final Object arg) {
printJavaComment(n.getComment(), arg);
if (n.getPackage() != null) {
n.getPackage().accept(this, arg);
}
if (!isNullOrEmpty(n.getImports())) {
for (final ImportDeclaration i : n.getImports()) {
i.accept(this, arg);
}
printer.printLn();
}
if (!isNullOrEmpty(n.getTypes())) {
for (final Iterator<TypeDeclaration> i = n.getTypes().iterator(); i.hasNext();) {
i.next().accept(this, arg);
printer.printLn();
if (i.hasNext()) {
printer.printLn();
}
}
}
printOrphanCommentsEnding(n);
}
示例2: visit
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override public void visit(final CompilationUnit n, final A arg) {
visitComment(n.getComment(), arg);
if (n.getPackage() != null) {
n.getPackage().accept(this, arg);
}
if (n.getImports() != null) {
for (final ImportDeclaration i : n.getImports()) {
i.accept(this, arg);
}
}
if (n.getTypes() != null) {
for (final TypeDeclaration typeDeclaration : n.getTypes()) {
typeDeclaration.accept(this, arg);
}
}
}
示例3: visit
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override public void visit(final CompilationUnit n, final A arg) {
visitComment(n.getComment(), arg);
if (n.getPackage() != null) {
n.getPackage().accept(this, arg);
}
if (n.getImports() != null) {
for (final ImportDeclaration i : n.getImports()) {
i.accept(this, arg);
}
}
if (n.getTypes() != null) {
for (final TypeDeclaration typeDeclaration : n.getTypes()) {
typeDeclaration.accept(this, arg);
}
}
}
示例4: visit
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override public Node visit(final CompilationUnit n, final A arg) {
if (n.getPackage() != null) {
n.setPackage((PackageDeclaration) n.getPackage().accept(this, arg));
}
final List<ImportDeclaration> imports = n.getImports();
if (imports != null) {
for (int i = 0; i < imports.size(); i++) {
imports.set(i, (ImportDeclaration) imports.get(i).accept(this, arg));
}
removeNulls(imports);
}
final List<TypeDeclaration> types = n.getTypes();
if (types != null) {
for (int i = 0; i < types.size(); i++) {
types.set(i, (TypeDeclaration) types.get(i).accept(this, arg));
}
removeNulls(types);
}
return n;
}
示例5: insertCommentsInCu
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
/**
* Comments are attributed to the thing the comment and are removed from
* allComments.
*/
private static void insertCommentsInCu(CompilationUnit cu, CommentsCollection commentsCollection){
if (commentsCollection.size()==0) return;
// I should sort all the direct children and the comments, if a comment is the first thing then it
// a comment to the CompilationUnit
// FIXME if there is no package it could be also a comment to the following class...
// so I could use some heuristics in these cases to distinguish the two cases
List<Comment> comments = commentsCollection.getAll();
PositionUtils.sortByBeginPosition(comments);
List<Node> children = cu.getChildrenNodes();
PositionUtils.sortByBeginPosition(children);
if (cu.getPackage()!=null && (children.isEmpty() || PositionUtils.areInOrder(comments.get(0), children.get(0)))){
cu.setComment(comments.get(0));
comments.remove(0);
}
insertCommentsInNode(cu,comments);
}
示例6: visit
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override
public void visit(CompilationUnit node, Object arg) {
if (node == null || node.getPackage() == null || node.getPackage().getName() == null) {
return;
}
Log.d(TAG, "visit CompilationUnit, packageName: %s", node.getPackage().getName());
sourceInfo.setPackageName(node.getPackage().getName().toString());
if (node.getImports() != null && node.getImports().size() > 0) {
for (ImportDeclaration importDeclaration : node.getImports()) {
Log.d(TAG, "visit CompilationUnit, import: %s", importDeclaration.getName());
sourceInfo.addImports(importDeclaration.isAsterisk() ? importDeclaration.getName().toString() + ".*" :
importDeclaration.getName().toString());
}
}
super.visit(node, arg);
}
示例7: insertComments
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
/**
* Comments are attributed to the thing they comment and are removed from
* the comments.
*/
private void insertComments(CompilationUnit cu, TreeSet<Comment> comments) {
if (comments.isEmpty())
return;
/* I should sort all the direct children and the comments, if a comment
is the first thing then it
a comment to the CompilationUnit */
// FIXME if there is no package it could be also a comment to the following class...
// so I could use some heuristics in these cases to distinguish the two
// cases
List<Node> children = cu.getChildrenNodes();
PositionUtils.sortByBeginPosition(children);
Comment firstComment = comments.iterator().next();
if (cu.getPackage() != null
&& (children.isEmpty() || PositionUtils.areInOrder(
firstComment, children.get(0)))) {
cu.setComment(firstComment);
comments.remove(firstComment);
}
}
示例8: visit
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override public void visit(final CompilationUnit n, final Object arg) {
printJavaComment(n.getComment(), arg);
if (n.getPackage() != null) {
n.getPackage().accept(this, arg);
}
if (n.getImports() != null) {
for (final ImportDeclaration i : n.getImports()) {
i.accept(this, arg);
}
printer.printLn();
}
if (n.getTypes() != null) {
for (final Iterator<TypeDeclaration> i = n.getTypes().iterator(); i.hasNext();) {
i.next().accept(this, arg);
printer.printLn();
if (i.hasNext()) {
printer.printLn();
}
}
}
printOrphanCommentsEnding(n);
}
示例9: insertCommentsInCu
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
/**
* Comments are attributed to the thing the comment and are removed from
* allComments.
*/
private static void insertCommentsInCu(CompilationUnit cu, CommentsCollection commentsCollection){
if (commentsCollection.size()==0) return;
// I should sort all the direct children and the comments, if a comment is the first thing then it
// a comment to the CompilationUnit
// FIXME if there is no package it could be also a comment to the following class...
// so I could use some heuristics in these cases to distinguish the two cases
List<Comment> comments = commentsCollection.getAll();
PositionUtils.sortByBeginPosition(comments);
List<Node> children = cu.getChildrenNodes();
PositionUtils.sortByBeginPosition(children);
if (cu.getPackage()!=null && (children.size()==0 || PositionUtils.areInOrder(comments.get(0), children.get(0)))){
cu.setComment(comments.get(0));
comments.remove(0);
}
insertCommentsInNode(cu,comments);
}
示例10: setFromFile
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
/********************************
* 작성일 : 2016. 7. 4. 작성자 : KYJ
*
*
* @param voFile
* @throws IOException
* @throws FileNotFoundException
********************************/
public void setFromFile(File voFile) {
if (voFile == null || !voFile.exists())
return;
if (voFile.isFile()) {
CompilationUnit cu;
try (FileInputStream in = new FileInputStream(voFile)) {
// parse the file
cu = JavaParser.parse(in);
PackageDeclaration packageDeclaration = cu.getPackage();
txtPackageName.setText(packageDeclaration.getName().toString());
txtClassName.setText(voFile.getName().substring(0, voFile.getName().indexOf('.')));
txtLocation.setText(voFile.getAbsolutePath());
MethodVisitor methodVisitor = new MethodVisitor();
methodVisitor.visit(cu, null);
List<TableModelDVO> valideFieldMeta = methodVisitor.getValideFieldMeta(t -> {
TableModelDVO tableModelDVO = new TableModelDVO();
tableModelDVO.setName(t.getName());
tableModelDVO.setType(t.getFieldType().getSimpleName());
return tableModelDVO;
});
this.tbVoEditor.getItems().addAll(valideFieldMeta);
} catch (IOException | ParseException e) {
LOGGER.error(ValueUtil.toString(e));
}
} else {
txtLocation.setText(voFile.getAbsolutePath());
}
}
示例11: main
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
public static void main(String[] args) throws ParseException, IOException {
String fileName = "C:\\Users\\KYJ\\JAVA_FX\\gagoyleWorkspace\\VisualFxVoEditor\\src\\main\\java\\com\\kyj\\fx\\voeditor\\visual\\main\\model\\vo\\ClassPathEntry.java";
FileInputStream in = new FileInputStream(fileName);
CompilationUnit cu;
try {
// parse the file
cu = JavaParser.parse(in);
} finally {
in.close();
}
PackageDeclaration packageDeclaration = cu.getPackage();
// System.out.println(packageDeclaration.getName().toString());
// System.out.println();
// System.out.println(String.format("package name : %s",
// packageDeclaration.getName().getName()));
ClassMeta classMeta = new ClassMeta("");
classMeta.setPackageName(packageDeclaration.getName().toString());
ArrayList<FieldMeta> fields = new ArrayList<FieldMeta>();
VoEditor voEditor = new VoEditor(classMeta, fields);
List<Node> childrenNodes = cu.getChildrenNodes();
for (Node n : childrenNodes) {
}
new MethodVisitor().visit(cu, null);
}
示例12: visit
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override
public void visit(final CompilationUnit n, final Object arg) {
printer.printLn("CompilationUnit");
printJavaComment(n.getComment(), arg);
if (n.getPackage() != null) {
n.getPackage().accept(this, arg);
}
if (n.getImports() != null) {
for (final ImportDeclaration i : n.getImports()) {
i.accept(this, arg);
}
printer.printLn();
}
if (n.getTypes() != null) {
for (final Iterator<TypeDeclaration> i = n.getTypes().iterator(); i.hasNext(); ) {
i.next().accept(this, arg);
printer.printLn();
if (i.hasNext()) {
printer.printLn();
}
}
}
printOrphanCommentsEnding(n);
}
示例13: visit
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override
public JCTree visit(final CompilationUnit n, final Object arg) {
// ARG0: List<JCAnnotation> packageAnnotations
List<JCAnnotation> arg0 = List.<JCAnnotation>nil();
// ARG1: JCExpression pid
// Package declaration
JCExpression arg1 = null;
if (n.getPackage() != null) {
arg1 = (JCExpression) n.getPackage().accept(this, arg);
if (n.getPackage().getAnnotations() != null) {
for (final AnnotationExpr packageAnnotation : n.getPackage().getAnnotations()) {
arg0 = arg0.append((JCAnnotation) packageAnnotation.accept(this, arg));
}
}
}
// ARG2 = List<JCTree> defs
// Imports and classes are passed in the same structure
List<JCTree> arg2 = List.<JCTree>nil();
if (n.getImports() != null) {
for (final ImportDeclaration i : n.getImports()) {
arg2 = arg2.append(i.accept(this, arg));
}
}
if (n.getTypes() != null) {
for (final TypeDeclaration typeDeclaration : n.getTypes()) {
arg2 = arg2.append(typeDeclaration.accept(this, arg));
}
}
return new AJCCompilationUnit(make.TopLevel(arg0, arg1, arg2), ((n.getComment() != null) ? n.getComment().getContent() : null));
}
示例14: parse
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
public void parse() throws ParseException {
// FileInputStream in = new FileInputStream(fileName);
CompilationUnit cu = JavaParser.parse(is);
PackageDeclaration package1 = cu.getPackage();
LOGGER.debug(package1.getName().toString());
LOGGER.debug(String.format("package name : %s", package1.getName().getName()));
// prints the resulting compilation unit to default system output
LOGGER.debug(cu.toString());
new MethodVisitor().visit(cu, null);
}
示例15: getPackageName
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
/********************************
* 작성일 : 2016. 7. 14. 작성자 : KYJ
*
*
* @param cu
* @return
* @throws FileNotFoundException
* @throws IOException
* @throws ParseException
********************************/
public static String getPackageName(CompilationUnit cu) throws FileNotFoundException, IOException, ParseException {
PackageDeclaration packageDeclaration = cu.getPackage();
return packageDeclaration.getPackageName();
}