public TypeDesc getRootComponentType() { TypeDesc type = mComponent; while (type.isArray()) { type = type.getComponentType(); } return type; }
private String getClassName(TypeDesc classDesc) throws IllegalArgumentException { if (classDesc.isPrimitive()) { throw new IllegalArgumentException("Primitive type not allowed"); } if (classDesc.isArray()) { throw new IllegalArgumentException("Array type not allowed"); } return classDesc.getRootName(); }
public ConstantClassInfo(ConstantPool cp, TypeDesc type) { super(TAG_CLASS); String desc; if (type.isArray()) { desc = type.getDescriptor(); } else { desc = type.getRootName().replace('.', '/'); } mType = type; mNameConstant = cp.addConstantUTF(desc); }
/** * Returns this in Java method signature syntax. * * @param name method name * @param varargs request that the last argument, if it is an array, to * be formatted in varargs syntax. */ public String toMethodSignature(String name, boolean varargs) { StringBuffer buf = new StringBuffer(); buf.append(mRetType.getFullName()); buf.append(' '); buf.append(name); buf.append('('); TypeDesc[] params = mParams; for (int i=0; i<params.length; i++) { if (i > 0) { buf.append(", "); } TypeDesc param = params[i]; if (varargs && param.isArray() && i == (params.length - 1)) { buf.append(param.getComponentType().getFullName()); buf.append("..."); } else { buf.append(param.getFullName()); } } return buf.append(')').toString(); }
public void newObject(TypeDesc type, int dimensions) { if (dimensions == 0 && !type.isArray()) { newObject(type); } else { println(mBulder + "newObject(" + getTypeDescName(type) + ", " + dimensions + ')'); } }
public void newObject(TypeDesc type) { if (type.isArray()) { newObject(type, 1); } else { mInstructions.new NewObjectInstruction(mCp.addConstantClass(type)); } }
public TypeDesc getRootComponentType() { TypeDesc type = mComponent; while (type.isArray()) { type = type.getComponentType(); } return type; }
private String getClassName(TypeDesc classDesc) throws IllegalArgumentException { if (classDesc.isPrimitive()) { throw new IllegalArgumentException("Primitive type not allowed"); } if (classDesc.isArray()) { throw new IllegalArgumentException("Array type not allowed"); } return classDesc.getRootName(); }
public ConstantClassInfo(ConstantPool cp, TypeDesc type) { super(TAG_CLASS); String desc; if (type.isArray()) { desc = type.getDescriptor(); } else { desc = type.getRootName().replace('.', '/'); } mType = type; mNameConstant = cp.addConstantUTF(desc); }
/** * Returns this in Java method signature syntax. * * @param name method name * @param varargs request that the last argument, if it is an array, to * be formatted in varargs syntax. */ public String toMethodSignature(String name, boolean varargs) { StringBuffer buf = new StringBuffer(); buf.append(mRetType.getFullName()); buf.append(' '); buf.append(name); buf.append('('); TypeDesc[] params = mParams; for (int i=0; i<params.length; i++) { if (i > 0) { buf.append(", "); } TypeDesc param = params[i]; if (varargs && param.isArray() && i == (params.length - 1)) { buf.append(param.getComponentType().getFullName()); buf.append("..."); } else { buf.append(param.getFullName()); } } return buf.append(')').toString(); }
public void newObject(TypeDesc type) { if (type.isArray()) { newObject(type, 1); } else { mInstructions.new NewObjectInstruction(mCp.addConstantClass(type)); } }
static boolean isKnownType(ClassLoader loader, TypeDesc type) { if (type == null) { // Assume void return type. return true; } if (type.isArray()) { type = type.getRootComponentType(); } if (type.isPrimitive()) { return true; } String name = type.getRootName(); try { if (loader == null) { Class.forName(name); } else { loader.loadClass(name); } } catch (ClassNotFoundException e) { return false; } return true; }
public void newObject(TypeDesc type, int dimensions) { if (dimensions == 0 && !type.isArray()) { newObject(type); } else { println(mBulder + "newObject(" + getTypeDescName(type) + ", " + dimensions + ')'); } }
private static void addValueHashCodeCallTo(CodeBuilder b, TypeDesc valueType) { if (valueType.isArray()) { if (!valueType.getComponentType().isPrimitive()) { b.invokeStatic("java.util.Arrays", "deepHashCode", TypeDesc.INT, new TypeDesc[] {TypeDesc.forClass(Object[].class)}); } else { b.invokeStatic("java.util.Arrays", "hashCode", TypeDesc.INT, new TypeDesc[] {valueType}); } } else { b.invokeVirtual(TypeDesc.OBJECT, "hashCode", TypeDesc.INT, null); } }
private static void addValueHashCodeCallTo(CodeBuilder b, TypeDesc valueType) { if (valueType.isArray()) { if (!valueType.getComponentType().isPrimitive()) { b.invokeStatic("java.util.Arrays", "deepHashCode", TypeDesc.INT, new TypeDesc[] {TypeDesc.forClass(Object[].class)}); } else { b.invokeStatic("java.util.Arrays", "hashCode", TypeDesc.INT, new TypeDesc[] {valueType}); } } else { b.invokeVirtual(TypeDesc.OBJECT, "hashCode", TypeDesc.INT, null); } }
} else if (type.isArray()) { TypeDesc root = type.getRootComponentType(); if (root.isPrimitive()) {
@Override public Object visit(PropertyFilter<S> filter, Object param) { ChainedProperty<S> chained = filter.getChainedProperty(); switch (filter.getOperator()) { case EQ: case NE: // Use equals() method instead of comparator. break; default: TypeDesc typeDesc = TypeDesc.forClass(chained.getType()).toObjectType(); if (!Comparable.class.isAssignableFrom(typeDesc.toClass()) && (!typeDesc.isArray() || Comparators.arrayComparator(typeDesc.toClass(), true) == null)) { throw new UnsupportedOperationException ("Property \"" + chained + "\" does not implement Comparable"); } break; } // Follow the chain, verifying that each property has an accessible // read method. checkForReadMethod(chained, chained.getPrimeProperty()); for (int i=0; i<chained.getChainCount(); i++) { checkForReadMethod(chained, chained.getChainedProperty(i)); } return null; }
@Override public Object visit(PropertyFilter<S> filter, Object param) { ChainedProperty<S> chained = filter.getChainedProperty(); switch (filter.getOperator()) { case EQ: case NE: // Use equals() method instead of comparator. break; default: TypeDesc typeDesc = TypeDesc.forClass(chained.getType()).toObjectType(); if (!Comparable.class.isAssignableFrom(typeDesc.toClass()) && (!typeDesc.isArray() || Comparators.arrayComparator(typeDesc.toClass(), true) == null)) { throw new UnsupportedOperationException ("Property \"" + chained + "\" does not implement Comparable"); } break; } // Follow the chain, verifying that each property has an accessible // read method. checkForReadMethod(chained, chained.getPrimeProperty()); for (int i=0; i<chained.getChainCount(); i++) { checkForReadMethod(chained, chained.getChainedProperty(i)); } return null; }
private void addPropertyAppendCall(CodeBuilder b, StorableProperty property) { b.loadConstant(property.getName()); invokeAppend(b, TypeDesc.STRING); b.loadConstant('='); invokeAppend(b, TypeDesc.CHAR); loadThisProperty(b, property); TypeDesc type = TypeDesc.forClass(property.getType()); if (type.isPrimitive()) { if (type == TypeDesc.BYTE || type == TypeDesc.SHORT) { type = TypeDesc.INT; } } else { if (type != TypeDesc.STRING) { if (type.isArray()) { if (!type.getComponentType().isPrimitive()) { b.invokeStatic("java.util.Arrays", "deepToString", TypeDesc.STRING, new TypeDesc[] {TypeDesc.OBJECT.toArrayType()}); } else { b.invokeStatic("java.util.Arrays", TO_STRING_METHOD_NAME, TypeDesc.STRING, new TypeDesc[] {type}); } } type = TypeDesc.OBJECT; } } invokeAppend(b, type); }
private void addPropertyAppendCall(CodeBuilder b, StorableProperty property) { b.loadConstant(property.getName()); invokeAppend(b, TypeDesc.STRING); b.loadConstant('='); invokeAppend(b, TypeDesc.CHAR); loadThisProperty(b, property); TypeDesc type = TypeDesc.forClass(property.getType()); if (type.isPrimitive()) { if (type == TypeDesc.BYTE || type == TypeDesc.SHORT) { type = TypeDesc.INT; } } else { if (type != TypeDesc.STRING) { if (type.isArray()) { if (!type.getComponentType().isPrimitive()) { b.invokeStatic("java.util.Arrays", "deepToString", TypeDesc.STRING, new TypeDesc[] {TypeDesc.OBJECT.toArrayType()}); } else { b.invokeStatic("java.util.Arrays", TO_STRING_METHOD_NAME, TypeDesc.STRING, new TypeDesc[] {type}); } } type = TypeDesc.OBJECT; } } invokeAppend(b, type); }