Search in sources :

Example 1 with Printer

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

the class CodegenTestsOnAndroidGenerator method generateAndSave.

private void generateAndSave() throws Throwable {
    System.out.println("Generating test files...");
    StringBuilder out = new StringBuilder();
    Printer p = new Printer(out);
    p.print(FileUtil.loadFile(new File("license/LICENSE.txt")));
    p.println("package " + testClassPackage + ";");
    p.println();
    p.println("import ", baseTestClassPackage, ".", baseTestClassName, ";");
    p.println();
    p.println("/* This class is generated by " + generatorName + ". DO NOT MODIFY MANUALLY */");
    p.println("public class ", testClassName, " extends ", baseTestClassName, " {");
    p.pushIndent();
    generateTestMethodsForDirectories(p, new File("compiler/testData/codegen/box"), new File("compiler/testData/codegen/boxInline"));
    p.popIndent();
    p.println("}");
    String testSourceFilePath = pathManager.getSrcFolderInAndroidTmpFolder() + "/" + testClassPackage.replace(".", "/") + "/" + testClassName + ".java";
    FileUtil.writeToFile(new File(testSourceFilePath), out.toString());
}
Also used : Printer(org.jetbrains.kotlin.utils.Printer) KtFile(org.jetbrains.kotlin.psi.KtFile) File(java.io.File)

Example 2 with Printer

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

the class ScopeUtils method printStructure.

// TestOnly
@NotNull
public static String printStructure(@Nullable MemberScope scope) {
    StringBuilder out = new StringBuilder();
    Printer p = new Printer(out);
    if (scope == null) {
        p.println("null");
    } else {
        scope.printScopeStructure(p);
    }
    return out.toString();
}
Also used : Printer(org.jetbrains.kotlin.utils.Printer) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Printer

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

the class TestGenerator method generateAndSave.

public void generateAndSave() throws IOException {
    StringBuilder out = new StringBuilder();
    Printer p = new Printer(out);
    p.println(FileUtil.loadFile(new File("license/LICENSE.txt")));
    p.println("package ", suiteClassPackage, ";");
    p.println();
    p.println("import com.intellij.testFramework.TestDataPath;");
    p.println("import ", RUNNER.getCanonicalName(), ";");
    p.println("import " + KotlinTestUtils.class.getCanonicalName() + ";");
    p.println("import " + TargetBackend.class.getCanonicalName() + ";");
    if (!suiteClassPackage.equals(baseTestClassPackage)) {
        p.println("import " + baseTestClassPackage + "." + baseTestClassName + ";");
    }
    p.println("import " + TestMetadata.class.getCanonicalName() + ";");
    p.println("import " + RunWith.class.getCanonicalName() + ";");
    p.println();
    p.println("import java.io.File;");
    p.println("import java.util.regex.Pattern;");
    p.println();
    p.println("/** This class is generated by {@link ", KotlinTestUtils.TEST_GENERATOR_NAME, "}. DO NOT MODIFY MANUALLY */");
    generateSuppressAllWarnings(p);
    TestClassModel model;
    if (testClassModels.size() == 1) {
        model = new DelegatingTestClassModel(single(testClassModels)) {

            @NotNull
            @Override
            public String getName() {
                return suiteClassName;
            }
        };
    } else {
        model = new TestClassModel() {

            @NotNull
            @Override
            public Collection<TestClassModel> getInnerTestClasses() {
                return testClassModels;
            }

            @NotNull
            @Override
            public Collection<MethodModel> getMethods() {
                return Collections.emptyList();
            }

            @Override
            public boolean isEmpty() {
                return false;
            }

            @NotNull
            @Override
            public String getName() {
                return suiteClassName;
            }

            @Override
            public String getDataString() {
                return null;
            }

            @Nullable
            @Override
            public String getDataPathRoot() {
                return null;
            }
        };
    }
    generateTestClass(p, model, false);
    File testSourceFile = new File(testSourceFilePath);
    GeneratorsFileUtil.writeFileIfContentChanged(testSourceFile, out.toString(), false);
}
Also used : TargetBackend(org.jetbrains.kotlin.test.TargetBackend) Printer(org.jetbrains.kotlin.utils.Printer) RunWith(org.junit.runner.RunWith) TestMetadata(org.jetbrains.kotlin.test.TestMetadata) NotNull(org.jetbrains.annotations.NotNull) KotlinTestUtils(org.jetbrains.kotlin.test.KotlinTestUtils) Collection(java.util.Collection) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with Printer

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

the class GenerateKeywordStrings method generate.

@NotNull
public static String generate() throws IOException {
    StringBuilder sb = new StringBuilder();
    Printer p = new Printer(sb);
    p.println(FileUtil.loadFile(new File("license/LICENSE.txt")));
    p.println("package org.jetbrains.kotlin.renderer;");
    p.println();
    p.println("import java.util.Arrays;");
    p.println("import java.util.Set;");
    p.println("import java.util.HashSet;");
    p.println();
    p.println("/** This class is generated by {@link \"org.jetbrains.kotlin.generators.frontend.GenerateKeywordStrings\"}. DO NOT MODIFY MANUALLY */");
    p.println("public class KeywordStringsGenerated {");
    p.pushIndent();
    p.println("private KeywordStringsGenerated() {}");
    p.println();
    p.println("public static final Set<String> KEYWORDS = new HashSet<String>(Arrays.asList(");
    p.pushIndent();
    List<String> strings = new ArrayList<String>();
    for (IElementType type : KtTokens.KEYWORDS.getTypes()) {
        assert type instanceof KtKeywordToken : "Not a keyword in KtTokens.KEYWORDS: " + type;
        KtKeywordToken keyword = (KtKeywordToken) type;
        assert !keyword.isSoft() : "Soft keyword in KtTokens.KEYWORDS: " + keyword.getValue();
        if (keyword != KtTokens.AS_SAFE && keyword != KtTokens.NOT_IN && keyword != KtTokens.NOT_IS) {
            strings.add(keyword.getValue());
        }
    }
    for (Iterator<String> iterator = strings.iterator(); iterator.hasNext(); ) {
        String string = iterator.next();
        p.println("\"" + string + "\"" + (iterator.hasNext() ? "," : ""));
    }
    p.popIndent();
    p.println("));");
    p.popIndent();
    p.println("}");
    return sb.toString();
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ArrayList(java.util.ArrayList) Printer(org.jetbrains.kotlin.utils.Printer) File(java.io.File) KtKeywordToken(org.jetbrains.kotlin.lexer.KtKeywordToken) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Printer

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

the class RecursiveDescriptorComparator method serializeRecursively.

public String serializeRecursively(@NotNull DeclarationDescriptor declarationDescriptor) {
    StringBuilder result = new StringBuilder();
    appendDeclarationRecursively(declarationDescriptor, DescriptorUtils.getContainingModule(declarationDescriptor), new Printer(result, 1), true);
    return result.toString();
}
Also used : Printer(org.jetbrains.kotlin.utils.Printer)

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