use of com.github.javaparser.ast.ImportDeclaration in project javaparser by javaparser.
the class NameTest method importName.
@Test
public void importName() {
ImportDeclaration importDeclaration = parseImport("import java.@Abc util.List;");
assertThat(importDeclaration.getName().getQualifier().get().getAnnotations()).containsExactly(new MarkerAnnotationExpr("Abc"));
assertEquals("import java.@Abc util.List;" + EOL, importDeclaration.toString());
assertEquals("import java.@Abc util.List;", ConcreteSyntaxModel.genericPrettyPrint(importDeclaration));
}
use of com.github.javaparser.ast.ImportDeclaration in project drools by kiegroup.
the class DrlxVisitor method visit.
public void visit(CompilationUnit u, Void arg) {
PackageDeclaration packageDeclaration = u.getPackageDeclaration().orElseThrow(() -> new ParseException("Expected package declaration.", -1));
String pkgName = packageDeclaration.getNameAsString();
builder.name(pkgName);
for (ImportDeclaration i : u.getImports()) {
this.visit(i, null);
}
ModuleDeclaration moduleDeclaration = u.getModule().orElseThrow(() -> new ParseException("Expected unit declaration.", -1));
builder.newUnit().target(String.format("%s.%s", pkgName, moduleDeclaration.getNameAsString()));
for (TypeDeclaration<?> typeDeclaration : u.getTypes()) {
RuleDeclaration rd = (RuleDeclaration) typeDeclaration;
this.visit(rd, null);
}
}
use of com.github.javaparser.ast.ImportDeclaration in project drools by kiegroup.
the class JavaParserCompiler method toPojoSource.
public static String toPojoSource(String pkgName, Collection<String> imports, Collection<String> staticImports, TypeDeclaration pojo) {
CompilationUnit cu = new CompilationUnit();
cu.setPackageDeclaration(pkgName);
for (String i : imports) {
cu.getImports().add(new ImportDeclaration(new Name(i), false, false));
}
for (String i : staticImports) {
cu.getImports().add(new ImportDeclaration(new Name(i), true, false));
}
cu.addType(pojo);
return getPrettyPrinter().print(cu);
}
use of com.github.javaparser.ast.ImportDeclaration in project checker-framework by typetools.
the class JointJavacJavaParserVisitor method visitImport.
@Override
public Void visitImport(ImportTree javacTree, Node javaParserNode) {
ImportDeclaration node = castNode(ImportDeclaration.class, javaParserNode, javacTree);
processImport(javacTree, node);
// stores "a" and records that the name ends in an asterisk.
if (node.isAsterisk()) {
assert javacTree.getQualifiedIdentifier().getKind() == Tree.Kind.MEMBER_SELECT;
MemberSelectTree identifier = (MemberSelectTree) javacTree.getQualifiedIdentifier();
identifier.getExpression().accept(this, node.getName());
} else {
javacTree.getQualifiedIdentifier().accept(this, node.getName());
}
return null;
}
use of com.github.javaparser.ast.ImportDeclaration in project checker-framework by typetools.
the class ToIndexFileConverter method extractScene.
/**
* Entry point of recursive-descent IndexUnit to AScene transformer. It operates by visiting the
* stub and scene in parallel, descending into them in the same way. It augments the existing
* scene (it does not create a new scene).
*
* @param iu {@link StubUnit} representing stubfile
*/
private static void extractScene(StubUnit iu, AScene scene) {
for (CompilationUnit cu : iu.getCompilationUnits()) {
NodeList<TypeDeclaration<?>> typeDecls = cu.getTypes();
if (typeDecls != null && cu.getPackageDeclaration().isPresent()) {
List<ImportDeclaration> impDecls = cu.getImports();
PackageDeclaration pkgDecl = cu.getPackageDeclaration().get();
for (TypeDeclaration<?> typeDecl : typeDecls) {
ToIndexFileConverter converter = new ToIndexFileConverter(pkgDecl, impDecls, scene);
String pkgName = converter.pkgName;
String name = typeDecl.getNameAsString();
if (pkgName != null) {
name = pkgName + "." + name;
}
typeDecl.accept(converter, scene.classes.getVivify(name));
}
}
}
}
Aggregations