* @param typeParameterList
*/
MethodDefinitionBuilder makeParamDefaultValueMethod(boolean noBody, Declaration container,
Tree.ParameterList params, Tree.Parameter currentParam, TypeParameterList typeParameterList) {
at(currentParam);
Parameter parameter = currentParam.getParameterModel();
if (!Strategy.hasDefaultParameterValueMethod(parameter)) {
throw new BugException();
}
MethodDefinitionBuilder methodBuilder = MethodDefinitionBuilder.systemMethod(this, Naming.getDefaultedParamMethodName(container, parameter));
methodBuilder.ignoreModelAnnotations();
if (container != null && Decl.isAnnotationConstructor(container)) {
AnnotationInvocation ac = (AnnotationInvocation)((Method)container).getAnnotationConstructor();
for (AnnotationConstructorParameter acp : ac.getConstructorParameters()) {
if (acp.getParameter().equals(parameter)
&& acp.getDefaultArgument() != null) {
methodBuilder.userAnnotations(acp.getDefaultArgument().makeDpmAnnotations(expressionGen()));
}
}
}
int modifiers = 0;
if (noBody) {
modifiers |= PUBLIC | ABSTRACT;
} else if (container == null
|| !(container instanceof Class
&& Strategy.defaultParameterMethodStatic(container))) {
// initializers can override parameter defaults
modifiers |= FINAL;
}
if (container != null && container.isShared()) {
modifiers |= PUBLIC;
} else if (container == null || (!container.isToplevel()
&& !noBody)){
modifiers |= PRIVATE;
}
if (Strategy.defaultParameterMethodStatic(container)) {
// static default parameter methods should be consistently public so that if non-shared class Top and
// shared class Bottom which extends Top both have the same default param name, we don't get an error
// if the Bottom class tries to "hide" a static public method with a private one
modifiers |= STATIC | PUBLIC;
}
methodBuilder.modifiers(modifiers);
if (container instanceof Functional) {
copyTypeParameters((Functional)container, methodBuilder);
}
// make sure reified type parameters are accepted
if(typeParameterList != null)
methodBuilder.reifiedTypeParameters(typeParameterListModel(typeParameterList));
// Add any of the preceding parameters as parameters to the method
for (Tree.Parameter p : params.getParameters()) {
if (p.equals(currentParam)) {
break;
}
at(p);
methodBuilder.parameter(p.getParameterModel(), null, 0, container instanceof Class);
}
// The method's return type is the same as the parameter's type
methodBuilder.resultType(parameter.getModel(), parameter.getType(), 0);
// The implementation of the method
if (noBody) {
methodBuilder.noBody();
} else {