Skip to content

Commit 3b3bb67

Browse files
committed
Fix formatting of PR 679
1 parent 7f21e30 commit 3b3bb67

2 files changed

Lines changed: 106 additions & 106 deletions

File tree

handlebars/src/main/java/com/github/jknack/handlebars/context/JavaBeanValueResolver.java

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
*/
1818
package com.github.jknack.handlebars.context;
1919

20+
import com.github.jknack.handlebars.ValueResolver;
21+
2022
import java.lang.reflect.Method;
2123
import java.util.Collection;
2224

23-
import com.github.jknack.handlebars.ValueResolver;
24-
2525
/**
2626
* A JavaBean method value resolver.
2727
*
@@ -30,90 +30,90 @@
3030
*/
3131
public class JavaBeanValueResolver extends MethodValueResolver {
3232

33-
/**
34-
* The 'is' prefix.
35-
*/
36-
private static final String IS_PREFIX = "is";
33+
/**
34+
* The 'is' prefix.
35+
*/
36+
private static final String IS_PREFIX = "is";
3737

38-
/**
39-
* The 'get' prefix.
40-
*/
41-
private static final String GET_PREFIX = "get";
38+
/**
39+
* The 'get' prefix.
40+
*/
41+
private static final String GET_PREFIX = "get";
4242

43-
/**
44-
* The default value resolver.
45-
*/
46-
public static final ValueResolver INSTANCE = new JavaBeanValueResolver();
43+
/**
44+
* The default value resolver.
45+
*/
46+
public static final ValueResolver INSTANCE = new JavaBeanValueResolver();
4747

48-
@Override
49-
public boolean matches(final Method method, final String name) {
50-
if (method.getName().equals("size") && name.equals("length")) {
51-
boolean isCollection = isCollectionMethod(method);
52-
if (isCollection) {
53-
return true;
54-
}
55-
}
48+
@Override
49+
public boolean matches(final Method method, final String name) {
50+
if (name.equals("length") && method.getName().equals("size")) {
51+
boolean isCollection = isCollectionMethod(method);
52+
if (isCollection) {
53+
return true;
54+
}
55+
}
5656

57-
boolean isStatic = isStatic(method);
58-
boolean isPublic = isPublic(method);
59-
boolean isGet = method.getName().equals(javaBeanMethod(GET_PREFIX, name));
60-
boolean isBoolGet = method.getName().equals(javaBeanMethod(IS_PREFIX, name));
61-
int parameterCount = method.getParameterTypes().length;
57+
boolean isStatic = isStatic(method);
58+
boolean isPublic = isPublic(method);
59+
boolean isGet = method.getName().equals(javaBeanMethod(GET_PREFIX, name));
60+
boolean isBoolGet = method.getName().equals(javaBeanMethod(IS_PREFIX, name));
61+
int parameterCount = method.getParameterTypes().length;
6262

63-
return !isStatic && isPublic && parameterCount == 0 && (isGet || isBoolGet);
64-
}
63+
return !isStatic && isPublic && parameterCount == 0 && (isGet || isBoolGet);
64+
}
6565

66-
/**
67-
* Convert the property's name to a JavaBean read method name.
68-
*
69-
* @param prefix The prefix: 'get' or 'is'.
70-
* @param name The unqualified property name.
71-
* @return The javaBean method name.
72-
*/
73-
private static String javaBeanMethod(final String prefix,
74-
final String name) {
75-
StringBuilder buffer = new StringBuilder(prefix);
76-
buffer.append(name);
77-
buffer.setCharAt(prefix.length(), Character.toUpperCase(name.charAt(0)));
78-
return buffer.toString();
79-
}
66+
/**
67+
* Convert the property's name to a JavaBean read method name.
68+
*
69+
* @param prefix The prefix: 'get' or 'is'.
70+
* @param name The unqualified property name.
71+
* @return The javaBean method name.
72+
*/
73+
private static String javaBeanMethod(final String prefix,
74+
final String name) {
75+
StringBuilder buffer = new StringBuilder(prefix);
76+
buffer.append(name);
77+
buffer.setCharAt(prefix.length(), Character.toUpperCase(name.charAt(0)));
78+
return buffer.toString();
79+
}
8080

81-
@Override
82-
protected String memberName(final Method member) {
83-
if (member.getName().equals("size")) {
84-
boolean isCollection = isCollectionMethod(member);
81+
@Override
82+
protected String memberName(final Method member) {
83+
if (member.getName().equals("size")) {
84+
boolean isCollection = isCollectionMethod(member);
8585

86-
if (isCollection) {
87-
return "length";
88-
}
89-
}
86+
if (isCollection) {
87+
return "length";
88+
}
89+
}
9090

91-
String name = member.getName();
92-
if (name.startsWith(GET_PREFIX)) {
93-
name = name.substring(GET_PREFIX.length());
94-
} else if (name.startsWith(IS_PREFIX)) {
95-
name = name.substring(IS_PREFIX.length());
96-
} else {
97-
return name;
98-
}
99-
if (name.length() > 0) {
100-
return Character.toLowerCase(name.charAt(0)) + name.substring(1);
101-
}
102-
return member.getName();
91+
String name = member.getName();
92+
if (name.startsWith(GET_PREFIX)) {
93+
name = name.substring(GET_PREFIX.length());
94+
} else if (name.startsWith(IS_PREFIX)) {
95+
name = name.substring(IS_PREFIX.length());
96+
} else {
97+
return name;
98+
}
99+
if (name.length() > 0) {
100+
return Character.toLowerCase(name.charAt(0)) + name.substring(1);
103101
}
102+
return member.getName();
103+
}
104104

105-
/**
106-
* Check is method class implements Collection interface.
107-
*
108-
* @param method from class
109-
* @return true/false
110-
*/
111-
private boolean isCollectionMethod(final Method method) {
112-
for (Class clazz : method.getDeclaringClass().getInterfaces()) {
113-
if (Collection.class.equals(clazz)) {
114-
return true;
115-
}
116-
}
117-
return false;
105+
/**
106+
* Check is method class implements Collection interface.
107+
*
108+
* @param method from class
109+
* @return true/false
110+
*/
111+
private boolean isCollectionMethod(final Method method) {
112+
for (Class clazz : method.getDeclaringClass().getInterfaces()) {
113+
if (Collection.class.equals(clazz)) {
114+
return true;
115+
}
118116
}
117+
return false;
118+
}
119119
}

handlebars/src/test/java/com/github/jknack/handlebars/CollectionsLengthTest.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,41 @@
88

99
public class CollectionsLengthTest extends AbstractTest {
1010

11-
static class SizeAndLength {
12-
int size;
13-
int length;
11+
static class SizeAndLength {
12+
int size;
13+
int length;
1414

15-
public int getSize() {
16-
return size;
17-
}
18-
19-
public void setSize(int size) {
20-
this.size = size;
21-
}
22-
23-
public int getLength() {
24-
return length;
25-
}
26-
27-
public void setLength(int length) {
28-
this.length = length;
29-
}
15+
public int getSize() {
16+
return size;
3017
}
3118

32-
@Test
33-
public void collectionLengthTest() throws IOException {
34-
List<String> list = new ArrayList<>();
35-
list.add("a");
36-
shouldCompileTo("{{this.length}}", list, "1");
19+
public void setSize(int size) {
20+
this.size = size;
3721
}
3822

39-
@Test
40-
public void otherClassSizeAndLength() throws IOException {
41-
SizeAndLength sizeAndLength = new SizeAndLength();
42-
sizeAndLength.length = 5;
43-
sizeAndLength.size = 4;
44-
shouldCompileTo("{{this.length}}", sizeAndLength, "5");
45-
shouldCompileTo("{{this.size}}", sizeAndLength, "4");
23+
public int getLength() {
24+
return length;
25+
}
4626

27+
public void setLength(int length) {
28+
this.length = length;
4729
}
30+
}
31+
32+
@Test
33+
public void collectionLengthTest() throws IOException {
34+
List<String> list = new ArrayList<>();
35+
list.add("a");
36+
shouldCompileTo("{{this.length}}", list, "1");
37+
}
38+
39+
@Test
40+
public void otherClassSizeAndLength() throws IOException {
41+
SizeAndLength sizeAndLength = new SizeAndLength();
42+
sizeAndLength.length = 5;
43+
sizeAndLength.size = 4;
44+
shouldCompileTo("{{this.length}}", sizeAndLength, "5");
45+
shouldCompileTo("{{this.size}}", sizeAndLength, "4");
46+
47+
}
4848
}

0 commit comments

Comments
 (0)