Search in sources :

Example 16 with SootClass

use of soot.SootClass in project robovm by robovm.

the class ObjCBlockPlugin method getBlockTargetMethod.

protected static SootMethod getBlockTargetMethod(SootMethod method, int paramIndex) {
    soot.Type type = method.getParameterType(paramIndex);
    if (!(type instanceof RefType)) {
        throw new CompilerException("@Block annotated parameter " + (paramIndex + 1) + " of method " + method + " must be of interface type");
    }
    SootClass blockType = ((RefType) type).getSootClass();
    if (!blockType.isInterface()) {
        throw new CompilerException("@Block annotated parameter " + (paramIndex + 1) + " of method " + method + " must be of interface type");
    }
    List<SootMethod> allMethods = collectAbstractMethods(blockType);
    if (allMethods.isEmpty()) {
        throw new CompilerException("No abstract method found in interface " + blockType + " used in @Block annotated parameter " + (paramIndex + 1) + " of method " + method);
    }
    if (allMethods.size() > 1) {
        throw new CompilerException("More than 1 abstract method found in interface " + blockType + " used in @Block annotated parameter " + (paramIndex + 1) + " of method " + method);
    }
    return allMethods.get(0);
}
Also used : RefType(soot.RefType) CompilerException(org.robovm.compiler.CompilerException) SootMethod(soot.SootMethod) SootClass(soot.SootClass)

Example 17 with SootClass

use of soot.SootClass in project robovm by robovm.

the class SootClassType method getEnclosingMethod.

private SootMethodType getEnclosingMethod(boolean constructor) {
    EnclosingMethodTag emTag = (EnclosingMethodTag) sootClass.getTag("EnclosingMethodTag");
    if (emTag != null) {
        String clsName = emTag.getEnclosingClass();
        String name = emTag.getEnclosingMethod();
        String desc = emTag.getEnclosingMethodSig();
        if (clsName != null && name != null && desc != null) {
            if ((constructor && name.equals("<init>")) || (!constructor && !name.equals("<init>") && !name.equals("<clinit>"))) {
                SootClass cls = SootResolver.v().makeClassRef(clsName);
                if (!cls.isPhantom()) {
                    for (SootMethod m : cls.getMethods()) {
                        String mDesc = org.robovm.compiler.Types.getDescriptor(m);
                        if (m.getName().equals(name) && desc.equals(mDesc)) {
                            return new SootMethodType(m);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : EnclosingMethodTag(soot.tagkit.EnclosingMethodTag) SootMethod(soot.SootMethod) SootClass(soot.SootClass)

Example 18 with SootClass

use of soot.SootClass in project robovm by robovm.

the class AnnotationsTest method testCopyParameterAnnotationsNoParams.

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

Example 19 with SootClass

use of soot.SootClass in project robovm by robovm.

the class AnnotationsTest method testCopyParameterAnnotationsOnlyInvisibleNoShift.

@Test
public void testCopyParameterAnnotationsOnlyInvisibleNoShift() {
    SootClass sc = toSootClass(getClass());
    SootMethod src = sc.getMethodByName("src9");
    SootMethod dest = sc.getMethodByName("dest9");
    copyParameterAnnotations(src, dest, 0, 2, 0, Visibility.RuntimeVisible);
    assertEquals("void dest9(int, @E int)", toString(dest));
}
Also used : SootMethod(soot.SootMethod) SootClass(soot.SootClass) Test(org.junit.Test)

Example 20 with SootClass

use of soot.SootClass in project robovm by robovm.

the class AnnotationsTest method testCopyParameterAnnotationsSingleAllNoShift.

@Test
public void testCopyParameterAnnotationsSingleAllNoShift() {
    SootClass sc = toSootClass(getClass());
    SootMethod src = sc.getMethodByName("src3");
    SootMethod dest = sc.getMethodByName("dest3");
    copyParameterAnnotations(src, dest, 0, 2, 0, Visibility.Any);
    assertEquals("void dest3(@A int, @B int)", toString(dest));
}
Also used : SootMethod(soot.SootMethod) 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