private void processInterface(Class interfaceClass) { Class[] interfaces = interfaceClass.getInterfaces(); for (int i = 0; i < interfaces.length; i++) addInterfaceToQueue(interfaces[i]); Method[] methods = interfaceClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { MethodSignature sig = new MethodSignature(methods[i]); _interfaceMethods.add(sig); } }
public void addMethod(MethodSignature ms) { CtClass ctReturnType = convertClass(ms.getReturnType()); CtClass[] ctParameters = convertClasses(ms.getParameterTypes()); CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes()); CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass()); try { method.setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT); method.setExceptionTypes(ctExceptions); getCtClass().addMethod(method); } catch (Exception ex) { throw new ApplicationRuntimeException(ServiceMessages.unableToAddMethod( ms, getCtClass(), ex), ex); } _methods.add(ms); }
private boolean mismatch(Class[] a1, Class[] a2) { int a1Count = count(a1); int a2Count = count(a2); if (a1Count != a2Count) return true; // Hm. What if order is important (for exceptions)? We're really saying here that they // were derived from the name Method. for (int i = 0; i < a1Count; i++) { if (a1[i] != a2[i]) return true; } return false; }
/** * Returns true if this signature has the same return type, name and parameters types as the * method signature passed in, and this signatures exceptions "trump" (are the same as, or * super-implementations of, all exceptions thrown by the other method signature). * * @since 1.1 */ public boolean isOverridingSignatureOf(MethodSignature ms) { if (_returnType != ms._returnType) return false; if (!_name.equals(ms._name)) return false; if (mismatch(_parameterTypes, ms._parameterTypes)) return false; return exceptionsEncompass(ms._exceptionTypes); }
/** @since 1.1 */ private void processMethod(Method m, Map map) { _toString |= ClassFabUtils.isToString(m); MethodSignature sig = new MethodSignature(m); String uid = sig.getUniqueId(); MethodSignature existing = (MethodSignature) map.get(uid); if (existing == null || sig.isOverridingSignatureOf(existing)) map.put(uid, sig); }
/** * Finds a public or protected method in the base class. */ private Method findMethod(MethodSignature sig) { // Finding a public method is easy: try { return _baseClass.getMethod(sig.getName(), sig.getParameterTypes()); } catch (NoSuchMethodException ex) { // Good; no super-implementation to invoke. } Class c = _baseClass; while(c != Object.class) { try { return c.getDeclaredMethod(sig.getName(), sig .getParameterTypes()); } catch (NoSuchMethodException ex) { // Ok, continue loop up to next base class. } c = c.getSuperclass(); } return null; }
public boolean matchMethod(MethodSignature sig) { return sig.getName().equals(_name); }
protected void addServiceMethodImplementation(ClassFab classFab, MethodSignature sig) Class returnType = sig.getReturnType(); String methodName = sig.getName(); Class[] exceptions = sig.getExceptionTypes();
public boolean matchMethod(MethodSignature method) { return method.getParameterTypes().length == _parameterCount; }
Class returnType = m.getReturnType();
public boolean matchMethod(MethodSignature sig) { return sig.getName().indexOf(_nameSubstring) >= 0; }
/** * Finds a public or protected method in the base class. */ private Method findMethod(MethodSignature sig) { // Finding a public method is easy: try { return _baseClass.getMethod(sig.getName(), sig.getParameterTypes()); } catch (NoSuchMethodException ex) { // Good; no super-implementation to invoke. } Class c = _baseClass; while(c != Object.class) { try { return c.getDeclaredMethod(sig.getName(), sig .getParameterTypes()); } catch (NoSuchMethodException ex) { // Ok, continue loop up to next base class. } c = c.getSuperclass(); } return null; }
public boolean matchMethod(MethodSignature sig) { Class actualType = sig.getParameterTypes()[_parameterIndex]; String actualTypeName = ClassFabUtils.getJavaClassName(actualType); return actualTypeName.equals(_parameterType); }
public void addMethod(MethodSignature ms) { CtClass ctReturnType = convertClass(ms.getReturnType()); CtClass[] ctParameters = convertClasses(ms.getParameterTypes()); CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes()); CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass()); try { method.setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT); method.setExceptionTypes(ctExceptions); getCtClass().addMethod(method); } catch (Exception ex) { throw new ApplicationRuntimeException(EnhanceMessages.unableToAddMethod( ms, getCtClass(), ex), ex); } _methods.add(ms); }
/** * Adds a <code>toString()</code> method to a class that returns a fixed, pre-computed value. * * @param classFab * ClassFab used to construct the new class. * @param toStringResult * fixed result to be returned by the method. */ public static void addToStringMethod(ClassFab classFab, String toStringResult) { StringBuffer buffer = new StringBuffer("return "); buffer.append(QUOTE); buffer.append(toStringResult); buffer.append(QUOTE); buffer.append(";"); classFab.addMethod(Modifier.PUBLIC, new MethodSignature(String.class, "toString", null, null), buffer.toString()); }
public boolean matchMethod(MethodSignature sig) { return sig.getName().startsWith(_namePrefix); }
rootExpr = ""; createLocalReferences(context, generateClassFab(compiled), compiled.getGetterMethod().getParameterTypes());
public int hashCode() { if (_hashCode == -1) { _hashCode = _returnType.hashCode(); _hashCode = 31 * _hashCode + _name.hashCode(); int count = count(_parameterTypes); for (int i = 0; i < count; i++) _hashCode = 31 * _hashCode + _parameterTypes[i].hashCode(); count = count(_exceptionTypes); for (int i = 0; i < count; i++) _hashCode = 31 * _hashCode + _exceptionTypes[i].hashCode(); } return _hashCode; }
public void addMethod(MethodSignature ms) { CtClass ctReturnType = convertClass(ms.getReturnType()); CtClass[] ctParameters = convertClasses(ms.getParameterTypes()); CtClass[] ctExceptions = convertClasses(ms.getExceptionTypes()); CtMethod method = new CtMethod(ctReturnType, ms.getName(), ctParameters, getCtClass()); try { method.setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT); method.setExceptionTypes(ctExceptions); getCtClass().addMethod(method); } catch (Exception ex) { throw new ApplicationRuntimeException(EnhanceMessages.unableToAddMethod( ms, getCtClass(), ex), ex); } _methods.add(ms); }
public void processClass(Class beanClass) { Class[] interfaces = beanClass.getInterfaces(); for (int i = 0; i < interfaces.length; i++) addInterfaceToQueue(interfaces[i]); Method[] methods = beanClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i]; int modifiers = m.getModifiers(); if (Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) continue; MethodSignature sig = new MethodSignature(m); _allMethods.add(sig); } }