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());
}
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();
}
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);
}
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();
}
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();
}
Aggregations