Java Code Examples for org.mybatis.generator.api.dom.java.Parameter#getAnnotations()

The following examples show how to use org.mybatis.generator.api.dom.java.Parameter#getAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenameExampleClassAndMethodsPlugin.java    From mybatis-generator-plugins with Apache License 2.0 6 votes vote down vote up
boolean renameMethod(Method method) {
	String oldMethodName = method.getName();
	Matcher matcher = classMethodPattern.matcher(oldMethodName);
	String newMethodName = matcher.replaceAll(classMethodReplaceString);
	method.setName(newMethodName);

	for (int i = 0; i < method.getParameters().size(); i++) {
		Parameter parameter = method.getParameters().get(i);
		String oldParamName = parameter.getName();
		matcher = parameterPattern.matcher(oldParamName);
		if (matcher.lookingAt()) {
			String newName = matcher.replaceAll(parameterReplaceString);
			Parameter newParam = new Parameter(parameter.getType(), newName, parameter.isVarargs());
			for (String annotation : parameter.getAnnotations()) {
				newParam.addAnnotation(annotation);
			}
			method.getParameters().set(i, newParam);
		}
	}

	return true;
}
 
Example 2
Source File: CreateSubPackagePlugin.java    From mybatis-generator-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Rename the method types.
 *
 * @param method
 *            the method
 * @return true
 */
boolean renameMethod(Method method) {
	method.setReturnType(modelProperties.renameType(method.getReturnType()));

	for (int i = 0; i < method.getParameters().size(); i++) {
		Parameter parameter = method.getParameters().get(i);
		FullyQualifiedJavaType parameterType = parameter.getType();
		FullyQualifiedJavaType newParameterType = modelProperties.renameType(parameterType);
		if (parameterType != newParameterType) {
			Parameter newParam = new Parameter(newParameterType, parameter.getName(), parameter.isVarargs());
			for (String annotation : parameter.getAnnotations()) {
				newParam.addAnnotation(annotation);
			}
			method.getParameters().set(i, newParam);
			log.debug("set new parameter: [{}][{}]", parameter, newParam);
		}
	}

	modelProperties.renameAnnotations(method.getAnnotations());
	mapperProperties.renameAnnotations(method.getAnnotations());

	return true;
}
 
Example 3
Source File: JavaElementTools.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * clone
 * @param parameter
 * @return
 */
public static Parameter clone(Parameter parameter) {
    Parameter dest = new Parameter(parameter.getType(), parameter.getName(), parameter.isVarargs());
    for (String annotation : parameter.getAnnotations()) {
        dest.addAnnotation(annotation);
    }
    return dest;
}