/** * Makes an initializer creating a new array. * * @param type the type of the array. * @param size the size of the array. * @throws NotFoundException if the type of the array components * is not found. */ public static Initializer byNewArray(CtClass type, int size) throws NotFoundException { return new ArrayInitializer(type.getComponentType(), size); }
if (c.isArray()) { ret.append('['); ret.append(getDesc(c.getComponentType())); } else if (c.isPrimitive()) { String t = c.getName();
if (c.isArray()) { ret.append('['); ret.append(getDesc(c.getComponentType())); } else if (c.isPrimitive()) { String t = c.getName();
/** * Makes an initializer creating a new array. * * @param type the type of the array. * @param size the size of the array. * @throws NotFoundException if the type of the array components * is not found. */ public static Initializer byNewArray(CtClass type, int size) throws NotFoundException { return new ArrayInitializer(type.getComponentType(), size); }
/** * Returns the array component if this type is an array. If the type * is not an array null is returned. * * @return the array component if an array, otherwise null */ public Type getComponent() { if (this.clazz == null || !this.clazz.isArray()) return null; CtClass component; try { component = this.clazz.getComponentType(); } catch (NotFoundException e) { throw new RuntimeException(e); } Type type = (Type)prims.get(component); return (type != null) ? type : new Type(component); }
private static boolean isObjectArray(CtClass cc) throws NotFoundException { return cc.isArray() && cc.getComponentType().getSuperclass() == null; }
private static void toDescriptor(StringBuffer desc, CtClass type) { if (type.isArray()) { desc.append('['); try { toDescriptor(desc, type.getComponentType()); } catch (NotFoundException e) { desc.append('L'); String name = type.getName(); desc.append(toJvmName(name.substring(0, name.length() - 2))); desc.append(';'); } } else if (type.isPrimitive()) { CtPrimitiveType pt = (CtPrimitiveType)type; desc.append(pt.getDescriptor()); } else { // class type desc.append('L'); desc.append(type.getName().replace('.', '/')); desc.append(';'); } }
/** * Returns the array component if this type is an array. If the type * is not an array null is returned. * * @return the array component if an array, otherwise null */ public Type getComponent() { if (this.clazz == null || !this.clazz.isArray()) return null; CtClass component; try { component = this.clazz.getComponentType(); } catch (NotFoundException e) { throw new RuntimeException(e); } Type type = (Type)prims.get(component); return (type != null) ? type : new Type(component); }
private static boolean isObjectArray(CtClass cc) throws NotFoundException { return cc.isArray() && cc.getComponentType().getSuperclass() == null; }
public boolean subtypeOf(CtClass clazz) throws NotFoundException { if (super.subtypeOf(clazz)) return true; String cname = clazz.getName(); if (cname.equals(javaLangObject)) return true; CtClass[] intfs = getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].subtypeOf(clazz)) return true; return clazz.isArray() && getComponentType().subtypeOf(clazz.getComponentType()); }
/** * Finds the most specific common super class of the given classes * by considering array types. */ public static CtClass commonSuperClassEx(CtClass one, CtClass two) throws NotFoundException { if (one == two) return one; else if (one.isArray() && two.isArray()) { CtClass ele1 = one.getComponentType(); CtClass ele2 = two.getComponentType(); CtClass element = commonSuperClassEx(ele1, ele2); if (element == ele1) return one; else if (element == ele2) return two; else return one.getClassPool().get(element == null ? "java.lang.Object" : element.getName() + "[]"); } else if (one.isPrimitive() || two.isPrimitive()) return null; // TOP else if (one.isArray() || two.isArray()) // but !(one.isArray() && two.isArray()) return one.getClassPool().get("java.lang.Object"); else return commonSuperClass(one, two); }
private void setType(CtClass type, int dim) throws CompileError { if (type.isPrimitive()) { CtPrimitiveType pt = (CtPrimitiveType)type; exprType = MemberResolver.descToType(pt.getDescriptor()); arrayDim = dim; className = null; } else if (type.isArray()) try { setType(type.getComponentType(), dim + 1); } catch (NotFoundException e) { throw new CompileError("undefined type: " + type.getName()); } else { exprType = CLASS; arrayDim = dim; className = MemberResolver.javaToJvmName(type.getName()); } }
private void setType(CtClass type, int dim) throws CompileError { if (type.isPrimitive()) { CtPrimitiveType pt = (CtPrimitiveType)type; exprType = MemberResolver.descToType(pt.getDescriptor()); arrayDim = dim; className = null; } else if (type.isArray()) try { setType(type.getComponentType(), dim + 1); } catch (NotFoundException e) { throw new CompileError("undefined type: " + type.getName()); } else { exprType = CLASS; arrayDim = dim; className = MemberResolver.javaToJvmName(type.getName()); } } }
@Override public boolean subtypeOf(CtClass clazz) throws NotFoundException { if (super.subtypeOf(clazz)) return true; String cname = clazz.getName(); if (cname.equals(javaLangObject)) return true; CtClass[] intfs = getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].subtypeOf(clazz)) return true; return clazz.isArray() && getComponentType().subtypeOf(clazz.getComponentType()); }
CtClass arrayType = type.getComponentType(); int len = Array.getLength(value); MemberValue[] members = new MemberValue[len];
CtClass arrayType = type.getComponentType(); int len = Array.getLength(value); MemberValue[] members = new MemberValue[len];
private void setType(CtClass type, int dim) throws CompileError { if (type.isPrimitive()) { CtPrimitiveType pt = (CtPrimitiveType)type; exprType = MemberResolver.descToType(pt.getDescriptor()); arrayDim = dim; className = null; } else if (type.isArray()) try { setType(type.getComponentType(), dim + 1); } catch (NotFoundException e) { throw new CompileError("undefined type: " + type.getName()); } else { exprType = CLASS; arrayDim = dim; className = MemberResolver.javaToJvmName(type.getName()); } } }
private void setType(CtClass type, int dim) throws CompileError { if (type.isPrimitive()) { CtPrimitiveType pt = (CtPrimitiveType)type; exprType = MemberResolver.descToType(pt.getDescriptor()); arrayDim = dim; className = null; } else if (type.isArray()) try { setType(type.getComponentType(), dim + 1); } catch (NotFoundException e) { throw new CompileError("undefined type: " + type.getName()); } else { exprType = CLASS; arrayDim = dim; className = MemberResolver.javaToJvmName(type.getName()); } }
return new StringMemberValue(cp); else if (type.isArray()) { CtClass arrayType = type.getComponentType(); MemberValue member = createMemberValue(cp, arrayType); return new ArrayMemberValue(member, cp);
private synchronized CtClass javassistLoadClass( CtClass cc ) throws NotFoundException, CannotCompileException, BadBytecode { if( cc.isFrozen() ) return cc; // serialize parent javassistLoadClass(cc.getSuperclass()); // Serialize enums first, since we need the raw_enum function for this class for( CtField ctf : cc.getDeclaredFields() ) { CtClass base = ctf.getType(); while( base.isArray() ) base = base.getComponentType(); if( base.subclassOf(_enum) && base != cc ) javassistLoadClass(base); } CtClass ccr = addSerializationMethods(cc); ccr.freeze(); return ccr; }