public static void addImport(Context context, ClassDefinitionNode node, String packageName) { NodeFactory nodeFactory = new NodeFactory(context); PackageIdentifiersNode packageIdentifiers = null; StringTokenizer stringTokenizer = new StringTokenizer(packageName, "."); while (stringTokenizer.hasMoreTokens()) { String token = stringTokenizer.nextToken(); IdentifierNode identifier = nodeFactory.identifier(token); packageIdentifiers = nodeFactory.packageIdentifiers(packageIdentifiers, identifier, true); } PackageNameNode packageNameNode = nodeFactory.packageName(packageIdentifiers); ImportDirectiveNode importDirective = nodeFactory.importDirective(null, packageNameNode, null, context); importDirective.pkgdef = node.pkgdef; if (node.statements == null) { node.statements = new StatementListNode(null); } node.statements.items.add(0, importDirective); }