use of de.fraunhofer.aisec.cpg.graph.declarations.NamespaceDeclaration in project cpg by Fraunhofer-AISEC.
the class CXXLanguageFrontendTest method testNamespaces.
@Test
void testNamespaces() throws Exception {
File file = new File("src/test/resources/namespaces.cpp");
TranslationUnitDeclaration tu = TestUtils.analyzeAndGetFirstTU(List.of(file), file.getParentFile().toPath(), true);
assertNotNull(tu);
NamespaceDeclaration firstNamespace = tu.getDeclarationsByName("FirstNamespace", NamespaceDeclaration.class).iterator().next();
assertNotNull(firstNamespace);
RecordDeclaration someClass = firstNamespace.getDeclarationsByName("FirstNamespace::SomeClass", RecordDeclaration.class).iterator().next();
assertNotNull(someClass);
RecordDeclaration anotherClass = tu.getDeclarationsByName("AnotherClass", RecordDeclaration.class).iterator().next();
assertNotNull(anotherClass);
}
use of de.fraunhofer.aisec.cpg.graph.declarations.NamespaceDeclaration in project cpg by Fraunhofer-AISEC.
the class SubgraphWalkerTest method testASTChildrenGetter.
@Test
void testASTChildrenGetter() throws Exception {
File file = new File("src/test/resources/compiling/RecordDeclaration.java");
TranslationUnitDeclaration tu = TestUtils.analyzeAndGetFirstTU(List.of(file), file.getParentFile().toPath(), false);
NamespaceDeclaration namespace = tu.getDeclarationAs(0, NamespaceDeclaration.class);
RecordDeclaration recordDeclaration = namespace.getDeclarationAs(0, RecordDeclaration.class);
var ast = SubgraphWalker.getAstChildren(recordDeclaration);
assertFalse(ast.isEmpty());
// should contain 4 AST nodes, 1 field (+1 this field), 1 method, 1 constructor
assertEquals(4, ast.size());
}
Aggregations