-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add intercept for method and param names
- Loading branch information
Showing
6 changed files
with
162 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package z.hol.spgen; | ||
|
||
/** | ||
* const name's transformation | ||
* Created by holmes on 16-8-1. | ||
*/ | ||
public final class ConstNameIntercept implements TextIntercept { | ||
|
||
public static final ConstNameIntercept INSTANCE = new ConstNameIntercept(); | ||
|
||
private ConstNameIntercept() { | ||
} | ||
|
||
public String intercept(String src) { | ||
String result; | ||
final String name = src; | ||
int length = name.length(); | ||
StringBuilder sb = new StringBuilder(length + 8); | ||
for (int i = 0; i < length; i++) { | ||
char c = name.charAt(i); | ||
if (c >= 'A' && c <= 'Z') { | ||
c = Character.toLowerCase(c); | ||
sb.append("_"); | ||
} | ||
sb.append(c); | ||
} | ||
result = sb.toString(); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package z.hol.spgen; | ||
|
||
/** | ||
* parameter name's transformation | ||
* Created by holmes on 16-8-1. | ||
*/ | ||
public final class ParamNameIntercept implements TextIntercept { | ||
|
||
public static final ParamNameIntercept INSTANCE = new ParamNameIntercept(); | ||
|
||
private ParamNameIntercept() { | ||
} | ||
|
||
public String intercept(String src) { | ||
String result; | ||
// 去掉_以及-, 并将下个字母的小字转大小 | ||
final String name = src; | ||
int length = name.length(); | ||
StringBuilder sb = new StringBuilder(length); | ||
boolean nextCap = false; | ||
for (int i = 0; i < length; i++) { | ||
char c = name.charAt(i); | ||
if (c == '_' || c == '-') { | ||
nextCap = true; | ||
continue; | ||
} | ||
if (sb.length() > 0 && nextCap && c >= 'a' && c <= 'z') { | ||
c = Character.toUpperCase(c); | ||
nextCap = false; | ||
} | ||
sb.append(c); | ||
} | ||
result = sb.toString(); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package z.hol.spgen; | ||
|
||
/** | ||
* To handle the transformation between text; | ||
* Created by holmes on 16-8-1. | ||
*/ | ||
public interface TextIntercept { | ||
|
||
/** | ||
* transforming the text | ||
* @param src origin text | ||
* @return | ||
*/ | ||
String intercept(String src); | ||
|
||
} |