@Override public boolean canHandle(MethodReference method) { if (!characteristics.isStructure(method.getClassName())) { return false; } switch (method.getName()) { case "cast": case "toAddress": return method.parameterCount() == 0; case "sizeOf": return method.parameterCount() == 1 && method.parameterType(0).equals(ValueType.parse(Class.class)); case "add": return method.parameterCount() == 3 && method.parameterType(0).equals(ValueType.parse(Class.class)) && method.parameterType(1).equals(ValueType.parse(Structure.class)) && method.parameterType(2).equals(ValueType.INTEGER); default: return false; } }
private static boolean sameParams(MethodDescriptor a, MethodDescriptor b) { if (a.parameterCount() != b.parameterCount()) { return false; } for (int i = 0; i < a.parameterCount(); ++i) { if (!a.parameterType(i).equals(b.parameterType(i))) { return false; } } return true; } }
public boolean isSuperType(ValueType superType, ValueType subType, boolean defaultValue) { if (superType.equals(subType)) { return true; } if (superType instanceof ValueType.Primitive || subType instanceof ValueType.Primitive) { return false; } if (superType.isObject("java.lang.Object")) { return true; } if (superType instanceof ValueType.Object && subType instanceof ValueType.Object) { return isSuperType(((ValueType.Object) superType).getClassName(), ((ValueType.Object) subType).getClassName(), defaultValue); } else if (superType instanceof ValueType.Array & subType instanceof ValueType.Array) { return isSuperType(((ValueType.Array) superType).getItemType(), ((ValueType.Array) subType).getItemType(), defaultValue); } else { return false; } }
private boolean isProperGetter(MethodReader method) { if (method.parameterCount() > 0 || !typeHelper.isSupportedType(method.getResultType())) { return false; } if (extractSuggestedPropertyName(method) != null) { return true; } if (method.getResultType().equals(ValueType.BOOLEAN)) { if (isProperPrefix(method.getName(), "is")) { return true; } } return isProperPrefix(method.getName(), "get"); }
private ValueEmitter tryConvertArgument(ValueEmitter arg, ValueType from, ValueType to) { if (from.equals(to)) { return arg; } if (from instanceof ValueType.Primitive && to instanceof ValueType.Primitive) { return arg.cast(to); } else if (from instanceof ValueType.Primitive && to instanceof ValueType.Object) { String primitiveClass = ((ValueType.Object) to).getClassName(); PrimitiveType toType = getWrappedPrimitive(primitiveClass); if (toType == null) { return arg; } arg = tryConvertArgument(arg, from, ValueType.primitive(toType)); return arg.getProgramEmitter().invoke(primitiveClass, "valueOf", to, arg); } else if (from instanceof ValueType.Object && to instanceof ValueType.Primitive) { String primitiveClass = ((ValueType.Object) from).getClassName(); PrimitiveType fromType = getWrappedPrimitive(primitiveClass); if (fromType == null) { return arg; } arg = arg.invokeVirtual(primitiveName(fromType) + "Value", ValueType.primitive(fromType)); return tryConvertArgument(arg, ValueType.primitive(fromType), to); } else { return arg.cast(to); } }
public ValueEmitter cast(ValueType type) { if (type.equals(this.type)) { return this; } else if (pe.hierarchy.isSuperType(type, this.type, false)) {
default Optional<Boolean> isSuperType(ValueType superType, ValueType subType) { if (superType.equals(subType)) { return Optional.of(true); } if (superType instanceof ValueType.Primitive || subType instanceof ValueType.Primitive) { return Optional.of(false); } if (superType.isObject("java.lang.Object")) { return Optional.of(true); } if (superType instanceof ValueType.Object && subType instanceof ValueType.Object) { return isSuperType(((ValueType.Object) superType).getClassName(), ((ValueType.Object) subType).getClassName()); } else if (superType instanceof ValueType.Array & subType instanceof ValueType.Array) { return isSuperType(((ValueType.Array) superType).getItemType(), ((ValueType.Array) subType).getItemType()); } else { return Optional.of(false); } } }
private boolean isProperGetter(MethodReader method) { if (method.parameterCount() > 0 || !typeHelper.isSupportedType(method.getResultType())) { return false; } if (extractSuggestedPropertyName(method) != null) { return true; } if (method.getResultType().equals(ValueType.BOOLEAN)) { if (isProperPrefix(method.getName(), "is")) { return true; } } return isProperPrefix(method.getName(), "get"); }
public ValueEmitter cast(ValueType type) { if (type.equals(this.type)) { return this; } else if (pe.classSource.isSuperType(type, this.type).orElse(false)) {