Search in sources :

Example 6 with Printer

use of org.jetbrains.kotlin.utils.Printer in project kotlin by JetBrains.

the class RecursiveDescriptorProcessorTest method testRecursive.

public void testRecursive() throws Exception {
    File ktFile = new File("compiler/testData/recursiveProcessor/declarations.kt");
    File txtFile = new File("compiler/testData/recursiveProcessor/declarations.txt");
    String text = FileUtil.loadFile(ktFile, true);
    KtFile jetFile = KotlinTestUtils.createFile("declarations.kt", text, getEnvironment().getProject());
    AnalysisResult result = KotlinTestUtils.analyzeFile(jetFile, getEnvironment());
    PackageViewDescriptor testPackage = result.getModuleDescriptor().getPackage(FqName.topLevel(Name.identifier("test")));
    List<String> descriptors = recursivelyCollectDescriptors(testPackage);
    StringBuilder builder = new StringBuilder();
    Printer p = new Printer(builder);
    for (String descriptor : descriptors) {
        p.println(descriptor);
    }
    String actualText = builder.toString();
    if (!txtFile.exists()) {
        FileUtil.writeToFile(txtFile, actualText);
        fail("Test data file did not exist and was created from the results of the test: " + txtFile);
    }
    assertSameLinesWithFile(txtFile.getAbsolutePath(), actualText);
}
Also used : KtFile(org.jetbrains.kotlin.psi.KtFile) Printer(org.jetbrains.kotlin.utils.Printer) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File) AnalysisResult(org.jetbrains.kotlin.analyzer.AnalysisResult)

Aggregations

Printer (org.jetbrains.kotlin.utils.Printer)6 File (java.io.File)4 NotNull (org.jetbrains.annotations.NotNull)3 KtFile (org.jetbrains.kotlin.psi.KtFile)2 IElementType (com.intellij.psi.tree.IElementType)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Nullable (org.jetbrains.annotations.Nullable)1 AnalysisResult (org.jetbrains.kotlin.analyzer.AnalysisResult)1 KtKeywordToken (org.jetbrains.kotlin.lexer.KtKeywordToken)1 KotlinTestUtils (org.jetbrains.kotlin.test.KotlinTestUtils)1 TargetBackend (org.jetbrains.kotlin.test.TargetBackend)1 TestMetadata (org.jetbrains.kotlin.test.TestMetadata)1 RunWith (org.junit.runner.RunWith)1