use of de.fraunhofer.aisec.cpg.TranslationResult in project cpg by Fraunhofer-AISEC.
the class VisitorTest method setup.
@BeforeAll
public static void setup() throws TranslationException, InterruptedException, ExecutionException, TimeoutException {
File file = new File("src/test/resources/compiling/RecordDeclaration.java");
TranslationConfiguration config = TranslationConfiguration.builder().sourceLocations(file).defaultPasses().defaultLanguages().build();
TranslationResult result = TranslationManager.builder().config(config).build().analyze().get(20, TimeUnit.SECONDS);
TranslationUnitDeclaration tu = result.getTranslationUnits().get(0);
namespace = (NamespaceDeclaration) tu.getDeclarations().get(0);
}
use of de.fraunhofer.aisec.cpg.TranslationResult in project cpg by Fraunhofer-AISEC.
the class DemoTests method testPartial.
@Test
void testPartial() throws Exception {
Path topLevel = Paths.get("src/test/resources/partial");
File[] files = Files.walk(topLevel, Integer.MAX_VALUE).map(Path::toFile).filter(File::isFile).filter(f -> f.getName().endsWith(".java")).toArray(File[]::new);
TranslationConfiguration config = TranslationConfiguration.builder().sourceLocations(files).topLevel(topLevel.toFile()).defaultPasses().defaultLanguages().debugParser(true).failOnError(true).build();
TranslationManager analyzer = TranslationManager.builder().config(config).build();
TranslationResult result = analyzer.analyze().get();
for (Node node : result.getTranslationUnits()) {
assertNotNull(node);
}
}
use of de.fraunhofer.aisec.cpg.TranslationResult in project cpg by Fraunhofer-AISEC.
the class VariableUsageResolver method accept.
@Override
public void accept(TranslationResult result) {
walker = new ScopedWalker(lang);
for (TranslationUnitDeclaration tu : result.getTranslationUnits()) {
currTu = tu;
walker.clearCallbacks();
walker.registerHandler((currClass, parent, currNode) -> walker.collectDeclarations(currNode));
walker.registerHandler(this::findRecordsAndEnums);
walker.iterate(currTu);
}
Map<Type, List<Type>> currSuperTypes = recordMap.values().stream().collect(Collectors.toMap(r -> TypeParser.createFrom(r.getName(), true), RecordDeclaration::getSuperTypes));
superTypesMap.putAll(currSuperTypes);
for (TranslationUnitDeclaration tu : result.getTranslationUnits()) {
walker.clearCallbacks();
walker.registerHandler(this::resolveFieldUsages);
walker.iterate(tu);
}
for (TranslationUnitDeclaration tu : result.getTranslationUnits()) {
walker.clearCallbacks();
walker.registerHandler(this::resolveLocalVarUsage);
walker.iterate(tu);
}
}
Aggregations