use of org.jetbrains.org.objectweb.asm.ClassReader in project kotlin by JetBrains.
the class CompileKotlinAgainstCustomBinariesTest method testInlineFunWithoutDebugInfo.
/*test source mapping generation when source info is absent*/
public void testInlineFunWithoutDebugInfo() throws Exception {
compileKotlin("sourceInline.kt", tmpdir);
File inlineFunClass = new File(tmpdir.getAbsolutePath(), "test/A.class");
ClassWriter cw = new ClassWriter(Opcodes.ASM5);
new ClassReader(FilesKt.readBytes(inlineFunClass)).accept(new ClassVisitor(Opcodes.ASM5, cw) {
@Override
public void visitSource(String source, String debug) {
//skip debug info
}
}, 0);
assert inlineFunClass.delete();
assert !inlineFunClass.exists();
FilesKt.writeBytes(inlineFunClass, cw.toByteArray());
compileKotlin("source.kt", tmpdir, tmpdir);
final Ref<String> debugInfo = new Ref<String>();
File resultFile = new File(tmpdir.getAbsolutePath(), "test/B.class");
new ClassReader(FilesKt.readBytes(resultFile)).accept(new ClassVisitor(Opcodes.ASM5) {
@Override
public void visitSource(String source, String debug) {
//skip debug info
debugInfo.set(debug);
}
}, 0);
String expected = "SMAP\n" + "source.kt\n" + "Kotlin\n" + "*S Kotlin\n" + "*F\n" + "+ 1 source.kt\n" + "test/B\n" + "*L\n" + "1#1,13:1\n" + "*E\n";
if (InlineCodegenUtil.GENERATE_SMAP) {
assertEquals(expected, debugInfo.get());
} else {
assertEquals(null, debugInfo.get());
}
}
use of org.jetbrains.org.objectweb.asm.ClassReader in project kotlin by JetBrains.
the class CompilingEvaluatorUtils method changeSuperToMagicAccessor.
public static byte[] changeSuperToMagicAccessor(byte[] bytes) {
ClassWriter classWriter = new ClassWriter(0);
ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM5, classWriter) {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
if ("java/lang/Object".equals(superName)) {
superName = "sun/reflect/MagicAccessorImpl";
}
super.visit(version, access, name, signature, superName, interfaces);
}
};
new ClassReader(bytes).accept(classVisitor, 0);
return classWriter.toByteArray();
}
use of org.jetbrains.org.objectweb.asm.ClassReader 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.org.objectweb.asm.ClassReader 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.org.objectweb.asm.ClassReader in project kotlin by JetBrains.
the class OuterClassGenTest method doTest.
private void doTest(@NotNull String classFqName, @NotNull String javaClassName, @NotNull String testDataFile) throws Exception {
File javaOut = CodegenTestUtil.compileJava(Collections.singletonList(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + testDataFile + ".java"), Collections.<String>emptyList(), Collections.<String>emptyList());
String javaClassPath = javaClassName.replace('.', File.separatorChar) + ".class";
ClassReader javaReader = new ClassReader(FilesKt.readBytes(new File(javaOut, javaClassPath)));
ClassReader kotlinReader = getKotlinClassReader(classFqName.replace('.', '/').replace("$", "\\$"), testDataFile);
checkInfo(kotlinReader, javaReader);
}
Aggregations