Search in sources :

Example 11 with ImportDeclaration

use of com.github.javaparser.ast.ImportDeclaration in project javaparser by javaparser.

the class SourceFileInfoExtractor method solve.

private void solve(Node node) {
    if (node instanceof ClassOrInterfaceDeclaration) {
        solveTypeDecl((ClassOrInterfaceDeclaration) node);
    } else if (node instanceof Expression) {
        if ((requireParentNode(node) instanceof ImportDeclaration) || (requireParentNode(node) instanceof Expression) || (requireParentNode(node) instanceof MethodDeclaration) || (requireParentNode(node) instanceof PackageDeclaration)) {
        // skip
        } else if ((requireParentNode(node) instanceof Statement) || (requireParentNode(node) instanceof VariableDeclarator)) {
            try {
                ResolvedType ref = JavaParserFacade.get(typeSolver).getType(node);
                out.println("  Line " + node.getRange().get().begin.line + ") " + node + " ==> " + ref.describe());
                ok++;
            } catch (UnsupportedOperationException upe) {
                unsupported++;
                err.println(upe.getMessage());
                throw upe;
            } catch (RuntimeException re) {
                ko++;
                err.println(re.getMessage());
                throw re;
            }
        }
    }
}
Also used : ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Expression(com.github.javaparser.ast.expr.Expression) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Statement(com.github.javaparser.ast.stmt.Statement) ImportDeclaration(com.github.javaparser.ast.ImportDeclaration) PackageDeclaration(com.github.javaparser.ast.PackageDeclaration) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator)

Example 12 with ImportDeclaration

use of com.github.javaparser.ast.ImportDeclaration in project javaparser by javaparser.

the class ImportDeclarationTest method singleTypeImportDeclaration.

@Test
public void singleTypeImportDeclaration() {
    ImportDeclaration i = JavaParser.parseImport("import a.b.c.X;");
    assertEquals("a.b.c.X", i.getNameAsString());
}
Also used : ImportDeclaration(com.github.javaparser.ast.ImportDeclaration) Test(org.junit.Test)

Example 13 with ImportDeclaration

use of com.github.javaparser.ast.ImportDeclaration in project javaparser by javaparser.

the class ImportDeclarationTest method staticImportOnDemandDeclaration.

@Test
public void staticImportOnDemandDeclaration() {
    ImportDeclaration i = JavaParser.parseImport("import static a.b.c.X.*;");
    assertEquals("a.b.c.X", i.getNameAsString());
}
Also used : ImportDeclaration(com.github.javaparser.ast.ImportDeclaration) Test(org.junit.Test)

Example 14 with ImportDeclaration

use of com.github.javaparser.ast.ImportDeclaration in project javaparser by javaparser.

the class ImportDeclarationTest method typeImportOnDemandDeclaration.

@Test
public void typeImportOnDemandDeclaration() {
    ImportDeclaration i = JavaParser.parseImport("import a.b.c.D.*;");
    assertEquals("a.b.c.D", i.getName().toString());
    assertEquals("D", i.getName().getIdentifier());
}
Also used : ImportDeclaration(com.github.javaparser.ast.ImportDeclaration) Test(org.junit.Test)

Example 15 with ImportDeclaration

use of com.github.javaparser.ast.ImportDeclaration in project javaparser by javaparser.

the class ImportDeclarationTest method singleStaticImportDeclaration.

@Test
public void singleStaticImportDeclaration() {
    ImportDeclaration i = JavaParser.parseImport("import static a.b.c.X.def;");
    assertEquals("a.b.c.X", i.getName().getQualifier().get().asString());
    assertEquals("def", i.getName().getIdentifier());
}
Also used : ImportDeclaration(com.github.javaparser.ast.ImportDeclaration) Test(org.junit.Test)

Aggregations

ImportDeclaration (com.github.javaparser.ast.ImportDeclaration)16 TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)5 Test (org.junit.Test)5 CompilationUnit (com.github.javaparser.ast.CompilationUnit)4 PackageDeclaration (com.github.javaparser.ast.PackageDeclaration)3 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)3 AnnotationDeclaration (com.github.javaparser.ast.body.AnnotationDeclaration)2 EmptyTypeDeclaration (com.github.javaparser.ast.body.EmptyTypeDeclaration)2 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)2 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)2 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)2 ResolvedReferenceTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration)2 ResolvedTypeDeclaration (com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration)2 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)2 JavaParserAnnotationDeclaration (com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration)2 JavaParserEnumDeclaration (com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration)2 SymbolSolver (com.github.javaparser.symbolsolver.resolution.SymbolSolver)2 ASTParser (com.github.javaparser.ASTParser)1 Node (com.github.javaparser.ast.Node)1 NodeList (com.github.javaparser.ast.NodeList)1