use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class AbstractLineNumberTest method extractActualLineNumbersFromBytecode.
@NotNull
private static List<String> extractActualLineNumbersFromBytecode(@NotNull ClassFileFactory factory, boolean testFunInvoke) {
List<String> actualLineNumbers = Lists.newArrayList();
for (OutputFile outputFile : ClassFileUtilsKt.getClassFiles(factory)) {
ClassReader cr = new ClassReader(outputFile.asByteArray());
try {
List<String> lineNumbers = testFunInvoke ? readTestFunLineNumbers(cr) : readAllLineNumbers(cr);
actualLineNumbers.addAll(lineNumbers);
} catch (Throwable e) {
System.out.println(factory.createText());
throw ExceptionUtilsKt.rethrow(e);
}
}
return actualLineNumbers;
}
use of org.jetbrains.kotlin.backend.common.output.OutputFile in project kotlin by JetBrains.
the class DxChecker method check.
public static void check(ClassFileFactory outputFiles) {
Main.Arguments arguments = new Main.Arguments();
String[] array = new String[1];
array[0] = "testArgs";
arguments.parse(array);
for (OutputFile file : ClassFileUtilsKt.getClassFiles(outputFiles)) {
try {
byte[] bytes = file.asByteArray();
checkFileWithDx(bytes, file.getRelativePath(), arguments);
} catch (Throwable e) {
Assert.fail(generateExceptionMessage(e));
}
}
}
use of org.jetbrains.kotlin.backend.common.output.OutputFile 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.OutputFile 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.OutputFile 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);
}
Aggregations