欢迎来到天天文库
浏览记录
ID:38289107
大小:18.26 KB
页数:9页
时间:2019-06-07
《JDT生成代码实例》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、packageast.test.demo;importorg.eclipse.jdt.core.dom.AST;importorg.eclipse.jdt.core.dom.Assignment;importorg.eclipse.jdt.core.dom.Block;importorg.eclipse.jdt.core.dom.ClassInstanceCreation;importorg.eclipse.jdt.core.dom.CompilationUnit;importorg.eclipse.jdt.core.do
2、m.ExpressionStatement;importorg.eclipse.jdt.core.dom.IfStatement;importorg.eclipse.jdt.core.dom.ImportDeclaration;importorg.eclipse.jdt.core.dom.InfixExpression;importorg.eclipse.jdt.core.dom.MethodDeclaration;importorg.eclipse.jdt.core.dom.MethodInvocation;import
3、org.eclipse.jdt.core.dom.Modifier;importorg.eclipse.jdt.core.dom.NumberLiteral;importorg.eclipse.jdt.core.dom.PackageDeclaration;importorg.eclipse.jdt.core.dom.PrimitiveType;importorg.eclipse.jdt.core.dom.ReturnStatement;importorg.eclipse.jdt.core.dom.SingleVariab
4、leDeclaration;importorg.eclipse.jdt.core.dom.StringLiteral;importorg.eclipse.jdt.core.dom.SuperConstructorInvocation;importorg.eclipse.jdt.core.dom.ThrowStatement;importorg.eclipse.jdt.core.dom.TypeDeclaration;importorg.eclipse.jdt.core.dom.TypeLiteral;importorg.e
5、clipse.jdt.core.dom.VariableDeclarationFragment;importorg.eclipse.jdt.core.dom.VariableDeclarationStatement;importorg.eclipse.jdt.core.dom.Assignment.Operator;importorg.eclipse.jdt.core.dom.Modifier.ModifierKeyword;publicclassDemo{publicstaticvoidmain(String[]args
6、){ASTast=AST.newAST(AST.JLS3);CompilationUnitcompilationUnit=ast.newCompilationUnit();//创建类TypeDeclarationprogramClass=ast.newTypeDeclaration();programClass.setName(ast.newSimpleName("Program"));//设定类或接口的修饰类型programClass.modifiers().add(ast.newModifier(ModifierKey
7、word.PUBLIC_KEYWORD));//将创建好的类添加到文件compilationUnit.types().add(programClass);//创建包PackageDeclarationpackageDeclaration=ast.newPackageDeclaration();//设定包名packageDeclaration.setName(ast.newName("com.aptech.lzh"));//将创建好的添加到文件compilationUnit.setPackage(packageDeclara
8、tion);//要导入的包String[]imports={"java.util.Date","java.util.Random"};for(Stringimp:imports){//创建一个新包声名ImportDeclarationimportDeclaration=ast.newImportDecl
此文档下载收益归作者所有