private static TypeReference fromString(ClassLoaderReference clRef, String typeName) { // TODO: should we not use some lookup that try to (recursively) find a TypeReference in clRefs parents, // and only create a new TypeReference in clRef if this fails? I can't find a such a utility method, though..?!?! return TypeReference.findOrCreate(clRef, 'L' +typeName.replaceAll(";", "")); }
/** * Return the innermost element type reference for an array */ public final TypeReference getInnermostElementType() { return findOrCreate(classloader, name.getInnermostElementType()); }
/** * Method classLoaderName2Ref. * * @return ClassLoaderReference */ private TypeReference className2Ref(String clName) { return TypeReference.findOrCreate(governingLoader, TypeName.string2TypeName(clName)); } }
public static MethodReference getMethodReference(String funName) { boolean ctor = funName.startsWith("ctor:"); MethodReference MR; if (ctor) { TypeReference TR = TypeReference.findOrCreate(JavaScriptTypes.jsLoader, TypeName.string2TypeName('L' + funName.substring(5))); MR = JavaScriptMethods.makeCtorReference(TR); } else { TypeReference TR = TypeReference.findOrCreate(JavaScriptTypes.jsLoader, TypeName.string2TypeName('L' + funName)); MR = AstMethodReference.fnReference(TR); } return MR; }
public static MethodReference getMethodReference(String funName) { boolean ctor = funName.startsWith("ctor:"); MethodReference MR; if (ctor) { TypeReference TR = TypeReference.findOrCreate(JavaScriptTypes.jsLoader, TypeName.string2TypeName('L' + funName.substring(5))); MR = JavaScriptMethods.makeCtorReference(TR); } else { TypeReference TR = TypeReference.findOrCreate(JavaScriptTypes.jsLoader, TypeName.string2TypeName('L' + funName)); MR = AstMethodReference.fnReference(TR); } return MR; }
public static TypeReference findOrCreateArrayOf(TypeReference t) { if (t == null) { throw new IllegalArgumentException("t is null"); } TypeName name = t.getName(); if (t.isPrimitiveType()) { return findOrCreate(ClassLoaderReference.Primordial, name.getArrayTypeForElementType()); } else { return findOrCreate(t.getClassLoader(), name.getArrayTypeForElementType()); } }
public static TypeReference findOrCreatePointerTo(TypeReference t) { if (t == null) { throw new IllegalArgumentException("t is null"); } TypeName name = t.getName(); if (t.isPrimitiveType()) { return findOrCreate(ClassLoaderReference.Primordial, name.getPointerTypeForElementType()); } else { return findOrCreate(t.getClassLoader(), name.getPointerTypeForElementType()); } }
/** * creates a reference to a global named globalName. the declaring type and * type of the global are both the root type. */ protected FieldReference makeGlobalRef(String globalName) { TypeReference rootTypeRef = TypeReference.findOrCreate(loader.getReference(), AstTypeReference.rootTypeName); return FieldReference.findOrCreate(rootTypeRef, Atom.findOrCreateUnicodeAtom("global " + globalName), rootTypeRef); }
/** * creates a reference to a global named globalName. the declaring type and * type of the global are both the root type. */ protected FieldReference makeGlobalRef(String globalName) { TypeReference rootTypeRef = TypeReference.findOrCreate(loader.getReference(), AstTypeReference.rootTypeName); return FieldReference.findOrCreate(rootTypeRef, Atom.findOrCreateUnicodeAtom("global " + globalName), rootTypeRef); }
protected TypeReference[] computeExceptionTypes(CAstEntity methodEntity) { CAstType.Function fType = (Function) methodEntity.getType(); Collection<CAstType> exceptionTypes = fType.getExceptionTypes(); TypeReference[] result = new TypeReference[exceptionTypes.size()]; int i = 0; for (CAstType type : exceptionTypes) { result[i] = TypeReference.findOrCreate(JavaSourceLoaderImpl.this.getReference(), type.getName()); ++i; } return result; }
/** * Utility function. Useful when parsing input. */ public MethodReference findMethod(Atom loader, String klass, Atom name, ImmutableByteArray desc) { if (desc == null) { throw new IllegalArgumentException("null desc"); } ClassLoaderReference clr = getLoader(loader); Descriptor ddesc = Descriptor.findOrCreate(languages.get(clr.getLanguage()), desc); TypeReference type = TypeReference.findOrCreate(clr, TypeName.string2TypeName(klass)); return MethodReference.findOrCreate(type, name, ddesc); }
public static LambdaSummaryClass findOrCreate(CGNode caller, SSAInvokeDynamicInstruction inst) { if (! summaries.containsKey(inst.getBootstrap())) { String bootstrapCls = caller.getMethod().getDeclaringClass().getName().toString().replace("/", "$").substring(1); int bootstrapIndex = inst.getBootstrap().getIndexInClassFile(); TypeReference ref = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Lwala/lambda" + '$' + bootstrapCls + '$' + bootstrapIndex); LambdaSummaryClass cls = new LambdaSummaryClass(ref, caller.getClassHierarchy(), inst); caller.getClassHierarchy().addClass(cls); summaries.put(inst.getBootstrap(), cls); } return summaries.get(inst.getBootstrap()); }
/** * Test for bug 1714480, reported OOM on {@link ClassHierarchy} getPossibleTargets() */ @Test public void testCell() { TypeReference t = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lcell/Cell"); MethodReference m = MethodReference.findOrCreate(t, "<init>", "(Ljava/lang/Object;)V"); Collection<IMethod> c = cha.getPossibleTargets(m); for (IMethod method : c) { System.err.println(method); } Assert.assertEquals(1, c.size()); }
@Override protected void doNewObject(WalkContext context, CAstNode newNode, int result, Object type, int[] arguments) { assert arguments == null; TypeReference typeRef = TypeReference.findOrCreate(JavaScriptTypes.jsLoader, TypeName.string2TypeName("L" + type)); context.cfg().addInstruction(insts.NewInstruction(context.cfg().getCurrentInstruction(), result, NewSiteReference.make(context.cfg().getCurrentInstruction(), typeRef))); }
protected JavaField(CAstEntity fieldEntity, IClassLoader loader, IClass declaringClass, Collection<Annotation> annotations) { super(FieldReference.findOrCreate(declaringClass.getReference(), Atom.findOrCreateUnicodeAtom(fieldEntity.getName()), TypeReference.findOrCreate(loader.getReference(), TypeName.string2TypeName(fieldEntity.getType().getName()))), fieldEntity.getQualifiers(), declaringClass, declaringClass.getClassHierarchy(), annotations); } }
@Test public void testConstructorLookup() { IClass testKlass = cha.lookupClass(TypeReference.findOrCreate(ClassLoaderReference.Application, "LmethodLookup/MethodLookupStuff$B")); IMethod m = testKlass.getMethod(Selector.make("<init>(I)V")); Assert.assertNull(m); } }
@Test public void testExclusions() throws IOException { AnalysisScope scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, (new FileProvider()).getFile("GUIExclusions.txt"), ExclusionsTest.class.getClassLoader()); TypeReference buttonRef = TypeReference.findOrCreate(ClassLoaderReference.Application, StringStuff.deployment2CanonicalTypeString("java.awt.Button")); Assert.assertTrue(scope.getExclusions().contains(buttonRef.getName().toString().substring(1))); } }
@Test public void test2() throws InvalidClassFileException { TypeReference t = TypeReference.findOrCreate(ClassLoaderReference.Application, TypeName .string2TypeName("Linner/TestStaticInner$A")); IClass klass = cha.lookupClass(t); assert klass != null; ShrikeClass s = (ShrikeClass)klass; Assert.assertTrue(s.isInnerClass()); Assert.assertTrue(s.isStaticInnerClass()); }
@Test public void test3() throws InvalidClassFileException { TypeReference t = TypeReference.findOrCreate(ClassLoaderReference.Application, TypeName .string2TypeName("Linner/TestInner$A")); IClass klass = cha.lookupClass(t); assert klass != null; ShrikeClass s = (ShrikeClass)klass; Assert.assertTrue(s.isInnerClass()); Assert.assertFalse(s.isStaticInnerClass()); }
@Override protected void leaveTypeLiteralExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext wc = c; assert n.getChild(0).getKind() == CAstNode.CONSTANT; String typeNameStr = (String) n.getChild(0).getValue(); TypeName typeName = TypeName.string2TypeName(typeNameStr); TypeReference typeRef = TypeReference.findOrCreate(loader.getReference(), typeName); int result = wc.currentScope().allocateTempValue(); c.setValue(n, result); wc.cfg().addInstruction(insts.LoadMetadataInstruction(wc.cfg().currentInstruction, result, loader.getLanguage().getConstantType(typeRef), typeRef)); }