@Override public String toString() { return "new " + methodOwner.getName() + "." + methodMeta; }
@Override public boolean match(IClass type, ClassHolder holder) { String typeStr = type.getName(); if(typeStr.startsWith("java.") || typeStr.startsWith("javax.") ) { return false; } return true; }
@Override public String toString() { StringBuilder sb = new StringBuilder(elementType.getName()); for(int i=0; i<dim; i++){ sb.append("[]"); } return sb.toString(); }
/** * Check the specify type is primitive wrap type. * * @param type */ public static boolean isPrimitiveWrapAClass(IClass type) { if (type.getName().equals(Byte.class.getName()) || type.getName().equals(Short.class.getName()) || type.getName().equals(Character.class.getName()) || type.getName().equals(Integer.class.getName()) || type.getName().equals(Long.class.getName()) || type.getName().equals(Float.class.getName()) || type.getName().equals(Double.class.getName()) || type.getName().equals(Boolean.class.getName())) { return true; } return false; }
public static String getMethodString(String name, IClass[] arguments) { if (arguments == null) { arguments = new IClass[0]; } StringBuilder str = new StringBuilder(name).append("("); for(IClass arg : arguments) { str.append(arg.getName()).append(", "); } if (arguments.length > 0) { str.delete(str.length() - 2, str.length()); } str.append(")"); return str.toString(); }
/** * Check the specify whether or not as an arithmetical operation factor. */ public static boolean isArithmetical(IClass type) { if (type.isPrimitive() && !type.getName().equals(boolean.class.getName())) { return true; } else if (isPrimitiveWrapAClass(type) && !type.getName().equals(Boolean.class.getName())) { return true; } return false; }
if (aclass.getName().equals(int.class.getName())) { return new Value(holder, 0); } else if (aclass.getName().equals(short.class.getName())) { return new Value(holder, (short) 0); } else if (aclass.getName().equals(byte.class.getName())) { return new Value(holder, (byte) 0); } else if (aclass.getName().equals(boolean.class.getName())) { return new Value(holder, false); } else if (aclass.getName().equals(long.class.getName())) { return new Value(holder, (long) 0); } else if (aclass.getName().equals(double.class.getName())) { return new Value(holder, 0d); } else if (aclass.getName().equals(char.class.getName())) { return new Value(holder, (char) 0); } else if (aclass.getName().equals(float.class.getName())) { return new Value(holder, 0f);
@Override public void push(MethodExecuteContext context) { Instructions instructions = context.getInstructions(); if (value == null) { instructions.push(this.getType()); return; } if (this.cls.getName().equals(int.class.getName())) { instructions.push((Integer) value); } else if (this.cls.getName().equals(short.class.getName())) { instructions.push((Short) value); } else if (this.cls.getName().equals(byte.class.getName())) { instructions.push((Byte) value); } else if (this.cls.getName().equals(boolean.class.getName())) { instructions.push((Boolean) value); } else if (this.cls.getName().equals(long.class.getName())) { instructions.push((Long) value); } else if (this.cls.getName().equals(double.class.getName())) { instructions.push((Double) value); } else if (this.cls.getName().equals(char.class.getName())) { instructions.push((Character) value); } else if (this.cls.getName().equals(float.class.getName())) { instructions.push((Float) value); } else if (this.cls.getName().equals(String.class.getName())) { instructions.push(value.toString()); } else if (this.cls.getName().equals(Class.class.getName())) { instructions.pushClass(((IClass) value).getType()); } }
@Override public Class<?> resolve() { byte[] code = toBytes(); IClass currentClass = getCurrentClass(); if(!StringUtils.isBlank(classOutPutPath)){ CommonUtils.toLocal(code, classOutPutPath, currentClass.getName()); } if(LOG.isPrintEnabled()){ LOG.print("End create class : " + currentClass.getName().replace('.', '/')); } return loadClass(currentClass.getName(), code); }
/** * <strong>4.10 Subtyping</strong> * <p>The subtype and supertype relations are binary relations on types.</p> * <p>check is subtyping</p> * @param subType * @param superType * @return */ public static boolean isSubtyping(IClass subType, IClass superType) { if (superType.getName().equals(Object.class.getName()) || subType.equals(superType)) { return true; } IClass[] directSuperTypes = TypeUtils.directSuperType(subType); if (directSuperTypes == null) { return false; } for (IClass directSuperType : directSuperTypes) { if (directSuperType.isChildOrEqual(superType)) { return true; } } return false; }
/** * * @param me * @param method * @return */ public static boolean methodEqualWithoutOwner(AMethodMeta me, AMethodMeta method) { if (me.getName().equals(method.getName())) { IClass[] mePara = me.getParameterTypes(); IClass[] methodPara = method.getParameterTypes(); if (mePara.length == methodPara.length) { for (int i = 0, len = mePara.length; i < len; i++) { if (!mePara[i].getName().equals(methodPara[i].getName())) { return false; } } return true; } } return false; }
/** * * @param block * @param argumentClasses * @param arguments */ protected ConstructorInvoker(KernelProgramBlock block, IClass argumentClasses, KernelParam[] arguments) { super(block, argumentClasses, ASConstants.INIT, arguments); if (argumentClasses.isPrimitive()) { throw new IllegalArgumentException("Cannot new a primitive class"); }else if(argumentClasses.isAbstract()){ throw new IllegalArgumentException(argumentClasses.getName() + "is an abstract class cannot new an abstract class"); } //default to don't save return result reference of this method. setSaveReference(false); }
public List<AMethodMeta> getAllMethod(final IClass owner, final String methodName) throws IOException { InputStream classStream = classLoader.getResourceAsStream( owner.getName().replace('.', '/') + ".class"); ClassReader cr = new ClassReader(classStream); final ClassHolder holder = owner.getClassHolder();
/** * Get all interface from a class and put the found classes to a list. * * @param itfList * @param clazz */ public static void getAllInterfaces(List<IClass> itfList, IClass clazz) { if (clazz == null || Object.class.getName().endsWith(clazz.getName())) { return; } // get interface from super class getAllInterfaces(itfList, clazz.getSuperclass()); IClass[] interfaces = clazz.getInterfaces(); if (ArrayUtils.isNotEmpty(interfaces)) { for (IClass itf : interfaces) { if (!itfList.contains(itf)) { itfList.add(itf); } // get interface from current interface getAllInterfaces(itfList, itf); } } } }
public ClassBuildResolver(int version, int access, String name, IClass superCls, IClass[] interfaces, ASMSupportClassLoader classLoader) { super(classLoader); CommonUtils.validateJavaClassName(name); if (superCls == null) { superCls = classLoader.getType(Object.class); } else if (superCls.isInterface()) { throw new ClassException("the super class \"" + superCls.getName() + "\" is an interface"); } sc = new SemiClass(classLoader, version, access, name, superCls, interfaces); }
@Override protected void verifyArgument() { if(leftFactor.getResultType().isPrimitive() && isNullValue(rightFactor)) { throw new ASMSupportException("The operator '" + getOperatorSymbol().getSymbol() + "' cannot be applied to " + leftFactor.getResultType().getName() + ", null"); } else if (rightFactor.getResultType().isPrimitive() && isNullValue(leftFactor)) { throw new ASMSupportException("The operator '" + getOperatorSymbol().getSymbol() + "' cannot be applied to null, " + rightFactor.getResultType().getName()); } super.verifyArgument(); }
@Override public void doExecute(MethodExecuteContext context) { LOG.print("new a instance of class :" + this.methodOwner.getName()); LOG.print("put class reference to stack"); context.getInstructions().newInstance(methodOwner.getType()); if (isSaveReference()) { context.getInstructions().dup(); } argumentsToStack(context); LOG.print("call the constrcutor"); context.getInstructions().invokeConstructor(methodOwner.getType(), methodMeta.getParameterAsmTypes()); }
@Override public void push(MethodExecuteContext context) { if (!IClassUtils.visible(context.getMethod().getDeclaringClass(), meta.getDirectOwnerType(), meta.getDeclaringClass(), meta.getModifiers())) { throw new IllegalArgumentException("Cannot access field " + meta.getDeclaringClass() + "#" + meta.getName() + " from " + context.getMethod().getDeclaringClass()); } if (LOG.isPrintEnabled()) { LOG.print("get field " + meta.getName() + " from class " + meta.getDirectOwnerType().getName() + " and push to stack!"); } context.getInstructions().getStatic(owner.getType(), meta.getName(), meta.getType().getType()); }
cw.visit(sc.getVersion(), sc.getModifiers(), sc.getName().replace('.', '/'), null, Type.getInternalName(sc.getSuperclass().getName()), interfaceStrings); context.setClassVisitor(cw); context.setOwner(sc);