aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/core/TransformationsUtil.java
blob: 8aea09a47eb01e647c4a4be9790f68e554b5efb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package lombok.core;

public class TransformationsUtil {
	private TransformationsUtil() {}
	
	public static String toGetterName(CharSequence fieldName, boolean isBoolean) {
		final String prefix = isBoolean ? "is" : "get";
		
		if ( fieldName.length() == 0 ) return prefix;
		
		return buildName(prefix, fieldName.toString());
	}
	
	private static String buildName(String prefix, String suffix) {
		if ( suffix.length() == 0 ) return prefix;
		
		char first = suffix.charAt(0);
		if ( Character.isLowerCase(first) )
			suffix = String.format("%s%s", Character.toTitleCase(first), suffix.subSequence(1, suffix.length()));
		return String.format("%s%s", prefix, suffix);
	}
	
	public static String toSetterName(CharSequence fieldName) {
		return buildName("set", fieldName.toString());
	}
}