/** * @param s a String like Ljava/lang/Object * @return the corresponding TypeName * @throws IllegalArgumentException if s is null */ public static TypeName string2TypeName(String s) throws IllegalArgumentException { if (s == null) { throw new IllegalArgumentException("s is null"); } byte[] val = s.getBytes(); return findOrCreate(new ImmutableByteArray(val)); }
public static ImmutableByteArray concat(byte b, ImmutableByteArray b1) { if (b1 == null) { throw new IllegalArgumentException("b1 is null"); } byte[] arr = new byte[b1.length() + 1]; arr[0] = b; System.arraycopy(b1.b, 0, arr, 1, b1.b.length); return new ImmutableByteArray(arr); }
/** * @param s a String like Ljava/lang/Object * @return the corresponding TypeName * @throws IllegalArgumentException if s is null */ public static TypeName string2TypeName(String s) throws IllegalArgumentException { if (s == null) { throw new IllegalArgumentException("s is null"); } byte[] val = s.getBytes(); return findOrCreate(new ImmutableByteArray(val)); }
public static ImmutableByteArray concat(byte b, ImmutableByteArray b1) { if (b1 == null) { throw new IllegalArgumentException("b1 is null"); } byte[] arr = new byte[b1.length() + 1]; arr[0] = b; System.arraycopy(b1.b, 0, arr, 1, b1.b.length); return new ImmutableByteArray(arr); }
public static ImmutableByteArray make(String s) { return new ImmutableByteArray(UTF8Convert.toUTF8(s)); }
public static ImmutableByteArray make(String s) { return new ImmutableByteArray(UTF8Convert.toUTF8(s)); }
/** * Parse an array descriptor to obtain number of dimensions in corresponding array type. b: descriptor - something like * "[Ljava/lang/String;" or "[[I" * * @return dimensionality - something like "Ljava/lang/String;" or "I" * @throws IllegalArgumentException if b is null */ public static ImmutableByteArray parseForInnermostArrayElementDescriptor(ImmutableByteArray b, int start, int length) { if (b == null) { throw new IllegalArgumentException("b is null"); } try { int i = start; for (; i < start + length; ++i) { if (! isTypeCodeChar(b, i)) { break; } } return new ImmutableByteArray(b.b, i, length - (i - start)); } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException("invalid element desciptor: " + b, e); } }
/** * Parse an array descriptor to obtain number of dimensions in corresponding array type. b: descriptor - something like * "[Ljava/lang/String;" or "[[I" * * @return dimensionality - something like "Ljava/lang/String;" or "I" * @throws IllegalArgumentException if b is null */ public static ImmutableByteArray parseForInnermostArrayElementDescriptor(ImmutableByteArray b, int start, int length) { if (b == null) { throw new IllegalArgumentException("b is null"); } try { int i = start; for (; i < start + length; ++i) { if (! isTypeCodeChar(b, i)) { break; } } return new ImmutableByteArray(b.b, i, length - (i - start)); } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException("invalid element desciptor: " + b, e); } }
/** * @param s string representation of this descriptor * @return the canonical representative for this descriptor value */ public static Descriptor findOrCreateUTF8(Language l, String s) throws IllegalArgumentException { byte[] b = UTF8Convert.toUTF8(s); return findOrCreate(l, new ImmutableByteArray(b)); }
/** * @param s string representation of this descriptor * @return the canonical representative for this descriptor value */ public static Descriptor findOrCreateUTF8(Language l, String s) throws IllegalArgumentException { byte[] b = UTF8Convert.toUTF8(s); return findOrCreate(l, new ImmutableByteArray(b)); }
/** * Parse an array descriptor to obtain number of dimensions in corresponding array type. b: descriptor - something like * "[Ljava/lang/String;" or "[[I" * * @return dimensionality - something like "Ljava/lang/String;" or "I" * @throws IllegalArgumentException if a is null */ public static ImmutableByteArray parseForInnermostArrayElementDescriptor(Atom a) { if (a == null) { throw new IllegalArgumentException("a is null"); } ImmutableByteArray b = new ImmutableByteArray(a.getValArray()); return parseForInnermostArrayElementDescriptor(b, 0, b.length()); }
/** * Parse an array descriptor to obtain number of dimensions in corresponding array type. b: descriptor - something like * "[Ljava/lang/String;" or "[[I" * * @return dimensionality - something like "Ljava/lang/String;" or "I" * @throws IllegalArgumentException if a is null */ public static ImmutableByteArray parseForInnermostArrayElementDescriptor(Atom a) { if (a == null) { throw new IllegalArgumentException("a is null"); } ImmutableByteArray b = new ImmutableByteArray(a.getValArray()); return parseForInnermostArrayElementDescriptor(b, 0, b.length()); }
@Test public void testIR1() { // 'remove' is a nice short method doMethod(cha.getScope().findMethod(AnalysisScope.APPLICATION, "Ljava/util/HashMap", Atom.findOrCreateUnicodeAtom("remove"), new ImmutableByteArray(UTF8Convert.toUTF8("(Ljava/lang/Object;)Ljava/lang/Object;")))); }
@Test public void testIR3() { // 'resolveProxyClass' is a nice long method (at least in Sun libs) doMethod(cha.getScope().findMethod(AnalysisScope.APPLICATION, "Ljava/io/ObjectInputStream", Atom .findOrCreateUnicodeAtom("resolveProxyClass"), new ImmutableByteArray(UTF8Convert .toUTF8("([Ljava/lang/String;)Ljava/lang/Class;")))); }
@Test public void testIR2() { // 'equals' is a nice medium-sized method doMethod(cha.getScope().findMethod(AnalysisScope.APPLICATION, "Ljava/lang/String", Atom.findOrCreateUnicodeAtom("equals"), new ImmutableByteArray(UTF8Convert.toUTF8("(Ljava/lang/Object;)Z")))); }
@Test public void testIR4() { // test some corner cases with try-finally doMethod(cha.getScope().findMethod(AnalysisScope.APPLICATION, "LcornerCases/TryFinally", Atom.findOrCreateUnicodeAtom("test1"), new ImmutableByteArray(UTF8Convert.toUTF8("(Ljava/io/InputStream;Ljava/io/InputStream;)V")))); } }
@Test public void test3() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("inferInt"), new ImmutableByteArray(UTF8Convert.toUTF8("()V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, true); TypeAbstraction type = ti.getType(7); Assert.assertNotNull("null type abstraction", type); Assert.assertTrue("inferred wrong type", type.toString().equals("int")); }
@Test public void test4() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("useCast"), new ImmutableByteArray(UTF8Convert.toUTF8("(Ljava/lang/Object;)V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, false); TypeAbstraction type = ti.getType(4); Assert.assertNotNull("null type abstraction", type); Assert.assertTrue("inferred wrong type " + type, type instanceof ConeType && ((ConeType)type).getTypeReference().getName().toString().equals("Ljava/lang/String")); }
@Test public void test1() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("foo"), new ImmutableByteArray(UTF8Convert.toUTF8("()V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, false); for (int i = 1; i <= ir.getSymbolTable().getMaxValueNumber(); i++) { System.err.println(i + " " + ti.getType(i)); } }
@Test public void test2() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("bar"), new ImmutableByteArray(UTF8Convert.toUTF8("(I)V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, true); Assert.assertNotNull("null type abstraction for parameter", ti.getType(2)); }