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


Java CompilationUnit.getPackage方法代码示例

本文整理汇总了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);
   }
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:27,代码来源:DumpVisitor.java

示例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);
		}
	}
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:17,代码来源:VoidVisitorAdapter.java

示例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);
        }
    }
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:17,代码来源:JsonVisitorAdapter.java

示例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;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:21,代码来源:ModifierVisitorAdapter.java

示例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);
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:25,代码来源:JavaParser.java

示例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);
}
 
开发者ID:ragnraok,项目名称:JParserUtil,代码行数:17,代码来源:SourceTreeVisitor.java

示例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);
    }
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:28,代码来源:CommentsInserter.java

示例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);
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:27,代码来源:DumpVisitor.java

示例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);
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:25,代码来源:JavaParser.java

示例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());
	}

}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:45,代码来源:VoEditorController.java

示例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);

}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:33,代码来源:VOEditorParser2.java

示例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);
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:29,代码来源:ASTDumpVisitor.java

示例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));
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:36,代码来源:JavaParser2JCTree.java

示例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);

	}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:19,代码来源:VOEditorParser.java

示例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();
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:15,代码来源:GargoyleJavaParser.java


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