public int compare(Object arg0, Object arg1) { CachedConstructor c0 = (CachedConstructor) arg0; CachedConstructor c1 = (CachedConstructor) arg1; String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes()); String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes()); return descriptor0.compareTo(descriptor1); } };
private MetaConstructor(CachedConstructor cc, boolean bean) { super(cc.getNativeParameterTypes()); this.setParametersTypes(cc.getParameterTypes()); this.cc = cc; this.beanConstructor = bean; } @Override
private void appendMethods(StringBuilder buffer) { for (int i = 0; i < methods.size; i++) { buffer.append("\n "); Object methodOrConstructor = methods.get(i); if (methodOrConstructor instanceof MetaMethod) { MetaMethod method = (MetaMethod) methodOrConstructor; buffer.append(Modifier.toString(method.getModifiers())); buffer.append(" ").append(method.getReturnType().getName()); buffer.append(" ").append(method.getDeclaringClass().getName()); buffer.append("#"); buffer.append(method.getName()); appendClassNames(buffer,method.getNativeParameterTypes()); } else { CachedConstructor method = (CachedConstructor) methodOrConstructor; buffer.append(Modifier.toString(method.cachedConstructor.getModifiers())); buffer.append(" ").append(method.cachedConstructor.getDeclaringClass().getName()); buffer.append("#<init>"); appendClassNames(buffer,method.getNativeParameterTypes()); } } } }
/** * Constructor selection algorithm for Groovy 2.1.9+. * This selection algorithm was introduced as a workaround for GROOVY-6080. Instead of generating an index between * 0 and N where N is the number of super constructors at the time the class is compiled, this algorithm uses * a hash of the constructor descriptor instead. * * This has the advantage of letting the super class add new constructors while being binary compatible. But there * are still problems with this approach: * <ul> * <li>There's a risk of hash collision, even if it's very low (two constructors of the same class must have the same hash)</li> * <li>If the super class adds a new constructor which takes as an argument a superclass of an existing constructor parameter and * that this new constructor is selected at runtime, it would not find it.</li> * </ul> * * Hopefully in the last case, the error message is much nicer now since it explains that it's a binary incompatible change. * * @param arguments the actual constructor call arguments * @return a hash used to identify the constructor to be called * @since 2.1.9 */ private int selectConstructorAndTransformArguments1(Object[] arguments) { CachedConstructor constructor = createCachedConstructor(arguments); final String methodDescriptor = BytecodeHelper.getMethodDescriptor(Void.TYPE, constructor.getNativeParameterTypes()); // keeping 3 bits for additional information such as vargs return BytecodeHelper.hashCode(methodDescriptor); }
public int compare(Object arg0, Object arg1) { CachedConstructor c0 = (CachedConstructor) arg0; CachedConstructor c1 = (CachedConstructor) arg1; String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes()); String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes()); return descriptor0.compareTo(descriptor1); } };
public int compare(Object arg0, Object arg1) { CachedConstructor c0 = (CachedConstructor) arg0; CachedConstructor c1 = (CachedConstructor) arg1; String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes()); String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes()); return descriptor0.compareTo(descriptor1); } };
public int compare(Object arg0, Object arg1) { CachedConstructor c0 = (CachedConstructor) arg0; CachedConstructor c1 = (CachedConstructor) arg1; String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes()); String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes()); return descriptor0.compareTo(descriptor1); } };
public int compare(Object arg0, Object arg1) { CachedConstructor c0 = (CachedConstructor) arg0; CachedConstructor c1 = (CachedConstructor) arg1; String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes()); String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes()); return descriptor0.compareTo(descriptor1); } };
private void appendMethods(StringBuffer buffer) { for (int i = 0; i < methods.size; i++) { buffer.append("\n "); Object methodOrConstructor = methods.get(i); if (methodOrConstructor instanceof MetaMethod) { MetaMethod method = (MetaMethod) methodOrConstructor; buffer.append(Modifier.toString(method.getModifiers())); buffer.append(" ").append(method.getReturnType().getName()); buffer.append(" ").append(method.getDeclaringClass().getName()); buffer.append("#"); buffer.append(method.getName()); appendClassNames(buffer,method.getNativeParameterTypes()); } else { CachedConstructor method = (CachedConstructor) methodOrConstructor; buffer.append(Modifier.toString(method.cachedConstructor.getModifiers())); buffer.append(" ").append(method.cachedConstructor.getDeclaringClass().getName()); buffer.append("#<init>"); appendClassNames(buffer,method.getNativeParameterTypes()); } } } }
private void appendMethods(StringBuffer buffer) { for (int i = 0; i < methods.size; i++) { buffer.append("\n "); Object methodOrConstructor = methods.get(i); if (methodOrConstructor instanceof MetaMethod) { MetaMethod method = (MetaMethod) methodOrConstructor; buffer.append(Modifier.toString(method.getModifiers())); buffer.append(" ").append(method.getReturnType().getName()); buffer.append(" ").append(method.getDeclaringClass().getName()); buffer.append("#"); buffer.append(method.getName()); appendClassNames(buffer,method.getNativeParameterTypes()); } else { CachedConstructor method = (CachedConstructor) methodOrConstructor; buffer.append(Modifier.toString(method.cachedConstructor.getModifiers())); buffer.append(" ").append(method.cachedConstructor.getDeclaringClass().getName()); buffer.append("#<init>"); appendClassNames(buffer,method.getNativeParameterTypes()); } } } }
private void appendMethods(StringBuffer buffer) { for (int i = 0; i < methods.size; i++) { buffer.append("\n "); Object methodOrConstructor = methods.get(i); if (methodOrConstructor instanceof MetaMethod) { MetaMethod method = (MetaMethod) methodOrConstructor; buffer.append(Modifier.toString(method.getModifiers())); buffer.append(" ").append(method.getReturnType().getName()); buffer.append(" ").append(method.getDeclaringClass().getName()); buffer.append("#"); buffer.append(method.getName()); appendClassNames(buffer,method.getNativeParameterTypes()); } else { CachedConstructor method = (CachedConstructor) methodOrConstructor; buffer.append(Modifier.toString(method.cachedConstructor.getModifiers())); buffer.append(" ").append(method.cachedConstructor.getDeclaringClass().getName()); buffer.append("#<init>"); appendClassNames(buffer,method.getNativeParameterTypes()); } } } }
private void appendMethods(StringBuffer buffer) { for (int i = 0; i < methods.size; i++) { buffer.append("\n "); Object methodOrConstructor = methods.get(i); if (methodOrConstructor instanceof MetaMethod) { MetaMethod method = (MetaMethod) methodOrConstructor; buffer.append(Modifier.toString(method.getModifiers())); buffer.append(" ").append(method.getReturnType().getName()); buffer.append(" ").append(method.getDeclaringClass().getName()); buffer.append("#"); buffer.append(method.getName()); appendClassNames(buffer,method.getNativeParameterTypes()); } else { CachedConstructor method = (CachedConstructor) methodOrConstructor; buffer.append(Modifier.toString(method.cachedConstructor.getModifiers())); buffer.append(" ").append(method.cachedConstructor.getDeclaringClass().getName()); buffer.append("#<init>"); appendClassNames(buffer,method.getNativeParameterTypes()); } } } }