use of org.jetbrains.kotlin.backend.common.output.OutputFileCollection in project kotlin by JetBrains.
the class AbstractCheckLocalVariablesTableTest method doTest.
protected void doTest(@NotNull String ktFileName) throws Exception {
ktFile = new File(ktFileName);
String text = FileUtil.loadFile(ktFile, true);
KtFile psiFile = KotlinTestUtils.createFile(ktFile.getName(), text, environment.getProject());
OutputFileCollection outputFiles = GenerationUtils.compileFile(psiFile, environment);
String classAndMethod = parseClassAndMethodSignature();
String[] split = classAndMethod.split("\\.");
assert split.length == 2 : "Exactly one dot is expected: " + classAndMethod;
final String classFileRegex = StringUtil.escapeToRegexp(split[0] + ".class").replace("\\*", ".+");
String methodName = split[1];
OutputFile outputFile = ContainerUtil.find(outputFiles.asList(), new Condition<OutputFile>() {
@Override
public boolean value(OutputFile outputFile) {
return outputFile.getRelativePath().matches(classFileRegex);
}
});
String pathsString = StringUtil.join(outputFiles.asList(), new Function<OutputFile, String>() {
@Override
public String fun(OutputFile file) {
return file.getRelativePath();
}
}, ", ");
assertNotNull("Couldn't find class file for pattern " + classFileRegex + " in: " + pathsString, outputFile);
ClassReader cr = new ClassReader(outputFile.asByteArray());
List<LocalVariable> actualLocalVariables = readLocalVariable(cr, methodName);
KotlinTestUtils.assertEqualsToFile(ktFile, text.substring(0, text.indexOf("// VARIABLE : ")) + getActualVariablesAsString(actualLocalVariables));
}
use of org.jetbrains.kotlin.backend.common.output.OutputFileCollection in project kotlin by JetBrains.
the class KotlinBytecodeToolWindow method getBytecodeForFile.
// public for tests
@NotNull
public static String getBytecodeForFile(@NotNull KtFile ktFile, @NotNull CompilerConfiguration configuration) {
GenerationState state;
try {
state = compileSingleFile(ktFile, configuration);
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
return printStackTraceToString(e);
}
StringBuilder answer = new StringBuilder();
Collection<Diagnostic> diagnostics = state.getCollectedExtraJvmDiagnostics().all();
if (!diagnostics.isEmpty()) {
answer.append("// Backend Errors: \n");
answer.append("// ================\n");
for (Diagnostic diagnostic : diagnostics) {
answer.append("// Error at ").append(diagnostic.getPsiFile().getName()).append(StringsKt.join(diagnostic.getTextRanges(), ",")).append(": ").append(DefaultErrorMessages.render(diagnostic)).append("\n");
}
answer.append("// ================\n\n");
}
OutputFileCollection outputFiles = state.getFactory();
for (OutputFile outputFile : outputFiles.asList()) {
answer.append("// ================");
answer.append(outputFile.getRelativePath());
answer.append(" =================\n");
answer.append(outputFile.asText()).append("\n\n");
}
return answer.toString();
}
use of org.jetbrains.kotlin.backend.common.output.OutputFileCollection in project kotlin by JetBrains.
the class GenerateNotNullAssertionsTest method assertNoIntrinsicsMethodIsCalled.
private void assertNoIntrinsicsMethodIsCalled(String className, boolean noClassFileIsAnError) {
OutputFileCollection classes = generateClassesInFile();
OutputFile file = classes.get(className + ".class");
if (noClassFileIsAnError) {
assertNotNull("File for " + className + " is absent", file);
} else if (file == null) {
return;
}
ClassReader reader = new ClassReader(file.asByteArray());
reader.accept(new ClassVisitor(Opcodes.ASM5) {
@Override
public MethodVisitor visitMethod(int access, @NotNull final String callerName, @NotNull final String callerDesc, String signature, String[] exceptions) {
return new MethodVisitor(Opcodes.ASM5) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
assertFalse("Intrinsics method is called: " + name + desc + " Caller: " + callerName + callerDesc, "kotlin/jvm/internal/Intrinsics".equals(owner));
}
};
}
}, 0);
}
use of org.jetbrains.kotlin.backend.common.output.OutputFileCollection in project kotlin by JetBrains.
the class OuterClassGenTest method getKotlinClassReader.
@NotNull
private ClassReader getKotlinClassReader(@Language("RegExp") @NotNull String internalNameRegexp, @NotNull String testDataFile) {
loadFile(getPrefix() + "/" + testDataFile + ".kt");
OutputFileCollection outputFiles = generateClassesInFile();
for (OutputFile file : outputFiles.asList()) {
if (file.getRelativePath().matches(internalNameRegexp + "\\.class")) {
return new ClassReader(file.asByteArray());
}
}
throw new AssertionError("Couldn't find class by regexp: " + internalNameRegexp + " in:\n" + StringsKt.join(outputFiles.asList(), "\n"));
}
use of org.jetbrains.kotlin.backend.common.output.OutputFileCollection in project kotlin by JetBrains.
the class GenerateNotNullAssertionsTest method testNoAssertionsForKotlinFromBinary.
public void testNoAssertionsForKotlinFromBinary() throws Exception {
setUpEnvironment(false, true);
loadSource("noAssertionsForKotlin.kt");
OutputFileCollection outputFiles = generateClassesInFile();
File compiledDirectory = new File(FileUtil.getTempDirectory(), "kotlin-classes");
OutputUtilsKt.writeAllTo(outputFiles, compiledDirectory);
setUpEnvironment(false, true, compiledDirectory);
loadSource("noAssertionsForKotlinMain.kt");
assertNoIntrinsicsMethodIsCalledInMyClasses(false);
}
Aggregations