List of usage examples for org.objectweb.asm.commons Method equals
@Override public boolean equals(final Object other)
From source file:io.datakernel.codegen.AsmBuilder.java
License:Apache License
/** * Creates a new method for a dynamic class. The method must be part of the provided interfaces or abstract class. * * @param methodName name of method//from ww w .j ava2 s .c o m * @param expression function which will be processed * @return changed AsmFunctionFactory */ public AsmBuilder<T> method(String methodName, Expression expression) { if (methodName.contains("(")) { Method method = Method.getMethod(methodName); return method(method, expression); } Method foundMethod = null; List<List<java.lang.reflect.Method>> listOfMethods = new ArrayList<>(); listOfMethods.add(asList(Object.class.getMethods())); for (Class<?> type : scope.getParentClasses()) { listOfMethods.add(asList(type.getMethods())); listOfMethods.add(asList(type.getDeclaredMethods())); } for (List<java.lang.reflect.Method> list : listOfMethods) { for (java.lang.reflect.Method m : list) { if (m.getName().equals(methodName)) { Method method = getMethod(m); if (foundMethod != null && !method.equals(foundMethod)) throw new IllegalArgumentException("Method " + method + " collides with " + foundMethod); foundMethod = method; } } } Preconditions.check(foundMethod != null, "Could not find method '" + methodName + "'"); return method(foundMethod, expression); }
From source file:net.wpm.codegen.ClassBuilder.java
License:Apache License
/** * Creates a new method for a dynamic class. The method must be part of the provided interfaces or abstract class. * * @param methodName name of method/*from w ww . j av a 2 s . com*/ * @param expression function which will be processed * @return changed AsmFunctionFactory */ public ClassBuilder<T> method(String methodName, Expression expression) { if (methodName.contains("(")) { Method method = Method.getMethod(methodName); return method(method, expression); } Method foundMethod = null; List<List<java.lang.reflect.Method>> listOfMethods = new ArrayList<List<java.lang.reflect.Method>>(); listOfMethods.add(asList(Object.class.getMethods())); for (Class<?> type : scope.getParentClasses()) { listOfMethods.add(asList(type.getMethods())); listOfMethods.add(asList(type.getDeclaredMethods())); } for (List<java.lang.reflect.Method> list : listOfMethods) { for (java.lang.reflect.Method m : list) { if (m.getName().equals(methodName)) { Method method = getMethod(m); if (foundMethod != null && !method.equals(foundMethod)) throw new IllegalArgumentException("Method " + method + " collides with " + foundMethod); foundMethod = method; } } } Preconditions.check(foundMethod != null, "Could not find method '" + methodName + "'"); return method(foundMethod, expression); }
From source file:org.kjots.json.object.JsonObjectGeneratorBase.java
License:Apache License
/** * Generate the class.//from ww w . j a va 2 s .c om * * @param classVisitor The class visitor. * @param jsonObjectClass The class of the JSON object. * @param jsonObjectType The type of the JSON object. * @param superJsonObjectImplType The type of the super JSON object implementation. */ private void generateClass(ClassVisitor classVisitor, Class<? extends JsonObject> jsonObjectClass, Type jsonObjectType, Type superJsonObjectImplType) { Type jsonObjectImplType = Type .getObjectType(jsonObjectType.getInternalName() + "$" + this.jsonObjectImplClass.getSimpleName()); classVisitor.visit(V1_6, ACC_PUBLIC + ACC_SUPER, jsonObjectImplType, null, superJsonObjectImplType, jsonObjectType); this.generateConstructor(classVisitor, jsonObjectImplType, superJsonObjectImplType); for (java.lang.reflect.Method method : jsonObjectClass.getDeclaredMethods()) { if (method.getAnnotation(JsonFunction.class) != null) { this.generateFunctionMethod(classVisitor, jsonObjectImplType, jsonObjectClass, Method.getMethod(method), method.getAnnotation(JsonFunction.class), method.isVarArgs()); } else if (method.getAnnotation(JsonException.class) != null) { this.generateExceptionMethod(classVisitor, jsonObjectImplType, jsonObjectClass, Method.getMethod(method), method.getAnnotation(JsonException.class), method.isVarArgs()); } else if (method.getAnnotation(JsonProperty.class) != null) { this.generatePropertyMethod(classVisitor, jsonObjectImplType, method, Method.getMethod(method), method.getAnnotation(JsonProperty.class)); } else { throw new IllegalArgumentException( method.getName() + "() is not annotated with suitable annotation"); } } Set<Method> implementedMethods = new HashSet<Method>(classVisitor.getImplementedMethods()); for (GenericMethod declaredMethod : this.getExtraInterfaceMethods(jsonObjectClass)) { Method implementedMethod = null; if (declaredMethod.getGenericReturnType() || !declaredMethod.getGenericTypeIndices().isEmpty()) { implementedMethod = declaredMethod.getCompatibleMethod(implementedMethods); } else if (!declaredMethod.getGenericReturnType() && !implementedMethods.contains(declaredMethod)) { int returnTypeSort = declaredMethod.getReturnType().getSort(); if (returnTypeSort == Type.ARRAY) { returnTypeSort = declaredMethod.getReturnType().getElementType().getSort(); } if (returnTypeSort == Type.OBJECT) { GenericMethod newDeclaredMethod = new GenericMethod(declaredMethod.getName(), declaredMethod.getDescriptor(), true, declaredMethod.getGenericTypeIndices()); implementedMethod = newDeclaredMethod.getCompatibleMethod(implementedMethods); } } if (implementedMethod != null && !implementedMethod.equals(declaredMethod)) { this.generateBridgeMethod(classVisitor, jsonObjectImplType, declaredMethod, implementedMethod); } } classVisitor.visitEnd(); }