use of org.jetbrains.org.objectweb.asm.ClassVisitor 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.ClassVisitor 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.ClassVisitor in project intellij-community by JetBrains.
the class ClassProcessingBuilder method getClassFileVersion.
public static int getClassFileVersion(ClassReader reader) {
final Ref<Integer> result = new Ref<>(0);
reader.accept(new ClassVisitor(Opcodes.API_VERSION) {
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
result.set(version);
}
}, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
return result.get();
}
use of org.jetbrains.org.objectweb.asm.ClassVisitor in project intellij-community by JetBrains.
the class CompilingEvaluator method changeSuperToMagicAccessor.
private static byte[] changeSuperToMagicAccessor(byte[] bytes) {
ClassWriter classWriter = new ClassWriter(0);
ClassVisitor classVisitor = new ClassVisitor(Opcodes.API_VERSION, 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.ClassVisitor in project intellij-community by JetBrains.
the class ClassFileViewProvider method detectInnerClass.
private static boolean detectInnerClass(VirtualFile file, @Nullable byte[] content) {
String name = file.getNameWithoutExtension();
int p = name.lastIndexOf('$', name.length() - 2);
if (p <= 0)
return false;
Boolean isInner = IS_INNER_CLASS.get(file);
if (isInner != null)
return isInner;
if (content == null) {
try {
content = file.contentsToByteArray(false);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
ClassReader reader = new ClassReader(content);
final Ref<Boolean> ref = Ref.create(Boolean.FALSE);
final String className = reader.getClassName();
reader.accept(new ClassVisitor(Opcodes.API_VERSION) {
@Override
public void visitOuterClass(String owner, String name, String desc) {
ref.set(Boolean.TRUE);
}
@Override
public void visitInnerClass(String name, String outer, String inner, int access) {
if (className.equals(name)) {
ref.set(Boolean.TRUE);
}
}
}, EMPTY_ATTRIBUTES, ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
isInner = ref.get();
IS_INNER_CLASS.set(file, isInner);
return isInner;
}
Aggregations