public IClass lookupClass(String className, IClassHierarchy cha) { assert this.cha == cha; return types.get(TypeName.string2TypeName(className)); }
public JavaClass(String typeName, Collection<TypeName> superTypeNames, CAstSourcePositionMap.Position position, Collection<CAstQualifier> qualifiers, JavaSourceLoaderImpl loader, IClass enclosingClass, Collection<Annotation> annotations) { super(position, TypeName.string2TypeName(typeName), loader, (short) mapToInt(qualifiers), new HashMap<Atom, IField>(), new HashMap<Selector, IMethod>()); this.superTypeNames = superTypeNames; this.enclosingClass = enclosingClass; this.annotations = annotations; }
/** * Method classLoaderName2Ref. * * @return ClassLoaderReference */ private TypeReference className2Ref(String clName) { return TypeReference.findOrCreate(governingLoader, TypeName.string2TypeName(clName)); } }
public JavaClass(String typeName, Collection<TypeName> superTypeNames, CAstSourcePositionMap.Position position, Collection<CAstQualifier> qualifiers, JavaSourceLoaderImpl loader, IClass enclosingClass, Collection<Annotation> annotations) { super(position, TypeName.string2TypeName(typeName), loader, (short) mapToInt(qualifiers), new HashMap<Atom, IField>(), new HashMap<Selector, IMethod>()); this.superTypeNames = superTypeNames; this.enclosingClass = enclosingClass; this.annotations = annotations; }
/** * Find or create the canonical {@link TypeReference} instance for the given pair. * * @param cl the classloader (defining/initiating depending on usage) * @param typeName something like "Ljava/util/Arrays" */ public static synchronized TypeReference findOrCreate(ClassLoaderReference cl, String typeName) { return findOrCreate(cl, TypeName.string2TypeName(typeName)); }
/** * Find or create the canonical {@link TypeReference} instance for the given pair. * * @param cl the classloader (defining/initiating depending on usage) * @param typeName something like "Ljava/util/Arrays" */ public static synchronized TypeReference findOrCreate(ClassLoaderReference cl, String typeName) { return findOrCreate(cl, TypeName.string2TypeName(typeName)); }
/** * @param T a type reference * @return a synthetic class name to represent the synthetic form of this type * @throws IllegalArgumentException if T is null */ public static TypeName getName(TypeReference T) { if (T == null) { throw new IllegalArgumentException("T is null"); } String s = "L$" + T.getName().toString().substring(1); return TypeName.string2TypeName(s); }
/** * @param T a type reference * @return a synthetic class name to represent the synthetic form of this type * @throws IllegalArgumentException if T is null */ public static TypeName getName(TypeReference T) { if (T == null) { throw new IllegalArgumentException("T is null"); } String s = "L$" + T.getName().toString().substring(1); return TypeName.string2TypeName(s); }
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; }
/** * 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 MethodReference getMethodRef(IMethodBinding met) { if (!fMethodMap.containsKey(met.getKey())) { // create one TypeName ownerType = TypeName.string2TypeName(typeToTypeID(met.getDeclaringClass())); TypeReference ownerTypeRef = TypeReference.findOrCreate(fClassLoaderRef, ownerType); MethodReference ref = MethodReference.findOrCreate(ownerTypeRef, selectorForMethod(met)); fMethodMap.put(met.getKey(), ref); return ref; } return fMethodMap.get(met.getKey()); }
@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))); }
@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); } }
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 test1() throws InvalidClassFileException { TypeReference t = TypeReference.findOrCreate(ClassLoaderReference.Application, TypeName .string2TypeName("Linner/TestStaticInner")); IClass klass = cha.lookupClass(t); assert klass != null; ShrikeClass s = (ShrikeClass)klass; Assert.assertFalse(s.isInnerClass()); }
@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)); }