Search in sources :

Example 21 with SootClass

use of soot.SootClass in project robovm by robovm.

the class AnnotationsTest method testCopyParameterAnnotationsNoAnnotations.

@Test
public void testCopyParameterAnnotationsNoAnnotations() {
    SootClass sc = toSootClass(getClass());
    SootMethod src = sc.getMethodByName("src2");
    SootMethod dest = sc.getMethodByName("dest2");
    copyParameterAnnotations(src, dest, 0, 2, 0, Visibility.Any);
    assertEquals("void dest2(int, int)", toString(dest));
}
Also used : SootMethod(soot.SootMethod) SootClass(soot.SootClass) Test(org.junit.Test)

Example 22 with SootClass

use of soot.SootClass in project robovm by robovm.

the class AnnotationsTest method testCopyParameterAnnotationsMultipleAllNoShift.

@Test
public void testCopyParameterAnnotationsMultipleAllNoShift() {
    SootClass sc = toSootClass(getClass());
    SootMethod src = sc.getMethodByName("src6");
    SootMethod dest = sc.getMethodByName("dest6");
    copyParameterAnnotations(src, dest, 0, 2, 0, Visibility.Any);
    assertEquals("void dest6(@A @B @C int, @B @C @D int)", toString(dest));
}
Also used : SootMethod(soot.SootMethod) SootClass(soot.SootClass) Test(org.junit.Test)

Example 23 with SootClass

use of soot.SootClass in project robovm by robovm.

the class AnnotationImplPlugin method beforeClass.

@Override
public void beforeClass(Config config, Clazz clazz, ModuleBuilder moduleBuilder) {
    init();
    SootClass sootClass = clazz.getSootClass();
    if ((sootClass.getModifiers() & MOD_ANNOTATION) > 0) {
        try {
            String implInternalName = clazz.getInternalName() + IMPL_CLASS_NAME_SUFFIX;
            ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
            cw.visit(V1_7, ACC_SUPER + ACC_FINAL + ACC_SYNTHETIC + ACC_PUBLIC, implInternalName, null, BASE_CLASS, new String[] { clazz.getInternalName() });
            generateConstructor(clazz, cw);
            generateAnnotationTypeMethod(clazz, cw);
            generateMembersToStringMethod(clazz, cw);
            generateFastEqualsMethod(clazz, cw);
            generateSlowEqualsMethod(clazz, cw);
            generateHashCodeMethod(clazz, cw);
            generateMemberFieldsAndAccessorMethods(clazz, cw);
            generateSetDefaultsMethod(clazz, cw);
            generateSingletonFactoryMethod(clazz, cw);
            generateFactoryMethod(clazz, cw);
            cw.visitEnd();
            File f = clazz.getPath().getGeneratedClassFile(implInternalName);
            FileUtils.writeByteArrayToFile(f, cw.toByteArray());
            // The impl class is created after the interface is compiled.
            // This prevents the triggering of a recompile of the interface.
            f.setLastModified(clazz.lastModified());
            // Add the impl class as a dependency for the annotation interface.
            // Important! This must be done AFTER the class file has been written.
            clazz.getClazzInfo().addClassDependency(implInternalName, false);
            // Make sure the factory methods are always linked in when the
            // annotation class is referenced.
            clazz.getClazzInfo().addInvokeMethodDependency(implInternalName, "$createSingleton", "()Ljava/lang/Object;", false);
            clazz.getClazzInfo().addInvokeMethodDependency(implInternalName, "$create", "()Ljava/lang/Object;", false);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : IOException(java.io.IOException) SootClass(soot.SootClass) File(java.io.File) ClassWriter(org.objectweb.asm.ClassWriter)

Example 24 with SootClass

use of soot.SootClass in project robovm by robovm.

the class VTableTest method testEmpty.

@Test
public void testEmpty() {
    SootClass scJLO = getSootClass("java.lang.Object");
    SootClass scEmpty = getSootClass("org.robovm.compiler.a.Empty");
    VTable.Cache cache = new VTable.Cache();
    VTable vtableJLO = cache.get(scJLO);
    VTable vtableEmpty = cache.get(scEmpty);
    assertArrayEquals(vtableJLO.getEntries(), vtableEmpty.getEntries());
}
Also used : SootClass(soot.SootClass) Test(org.junit.Test)

Example 25 with SootClass

use of soot.SootClass in project robovm by robovm.

the class VTableTest method testC.

@Test
public void testC() {
    SootClass scA = getSootClass("org.robovm.compiler.a.A");
    SootClass scC = getSootClass("org.robovm.compiler.a.C");
    VTable.Cache cache = new VTable.Cache();
    VTable vtableA = cache.get(scA);
    VTable vtableC = cache.get(scC);
    assertEquals(14, vtableC.size());
    Entry fooEntry = vtableC.findEntry("org.robovm.compiler.a", "foo", "()V");
    assertEquals(scC.getName(), fooEntry.getDeclaringClass());
    Entry superFooEntry = vtableA.findEntry("org.robovm.compiler.a", "foo", "()V");
    assertEquals(superFooEntry.getIndex(), fooEntry.getIndex());
    assertNotSame(superFooEntry, fooEntry);
    Entry barEntry = vtableC.findEntry("org.robovm.compiler.a", "bar", "()V");
    assertEquals(scA.getName(), barEntry.getDeclaringClass());
    Entry superBarEntry = vtableA.findEntry("org.robovm.compiler.a", "bar", "()V");
    assertSame(superBarEntry, barEntry);
}
Also used : Entry(org.robovm.compiler.VTable.Entry) SootClass(soot.SootClass) Test(org.junit.Test)

Aggregations

SootClass (soot.SootClass)48 SootMethod (soot.SootMethod)30 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)9 PrimType (soot.PrimType)9 RefType (soot.RefType)8 SootField (soot.SootField)7 HashSet (java.util.HashSet)6 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)4 Global (org.robovm.compiler.llvm.Global)4 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)4 Type (org.robovm.compiler.llvm.Type)4 File (java.io.File)3 CompilerException (org.robovm.compiler.CompilerException)3 Entry (org.robovm.compiler.VTable.Entry)3 ArrayType (org.robovm.compiler.llvm.ArrayType)3 NullConstant (org.robovm.compiler.llvm.NullConstant)3 PointerType (org.robovm.compiler.llvm.PointerType)3 StructureConstant (org.robovm.compiler.llvm.StructureConstant)3 StructureConstantBuilder (org.robovm.compiler.llvm.StructureConstantBuilder)3