Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor generateExtNameAssignment to better structure #14918

Open
wants to merge 3 commits into
base: 3.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -269,44 +269,38 @@ private String generateExtNameNullCheck(String[] value) {
* generate extName assignment code
*/
private String generateExtNameAssignment(String[] value, boolean hasInvocation) {
// TODO: refactor it
String getNameCode = null;

for (int i = value.length - 1; i >= 0; --i) {
if (i == value.length - 1) {
if (null != defaultExtName) {
if (!CommonConstants.PROTOCOL_KEY.equals(value[i])) {
if (hasInvocation) {
getNameCode = String.format(
"url.getMethodParameter(methodName, \"%s\", \"%s\")", value[i], defaultExtName);
} else {
getNameCode = String.format("url.getParameter(\"%s\", \"%s\")", value[i], defaultExtName);
}
} else {
boolean isLastElement = (i == value.length - 1);
boolean isProtocolKey = CommonConstants.PROTOCOL_KEY.equals(value[i]);

if (isLastElement) {
if (defaultExtName != null) {
if (isProtocolKey) {
getNameCode = String.format(
"( url.getProtocol() == null ? \"%s\" : url.getProtocol() )", defaultExtName);
}
} else {
if (!CommonConstants.PROTOCOL_KEY.equals(value[i])) {
if (hasInvocation) {
getNameCode = String.format(
"url.getMethodParameter(methodName, \"%s\", \"%s\")", value[i], defaultExtName);
} else {
getNameCode = String.format("url.getParameter(\"%s\")", value[i]);
}
} else {
getNameCode = "url.getProtocol()";
getNameCode = hasInvocation
? String.format(
"url.getMethodParameter(methodName, \"%s\", \"%s\")", value[i], defaultExtName)
: String.format("url.getParameter(\"%s\", \"%s\")", value[i], defaultExtName);
}
} else {
getNameCode = isProtocolKey
? "url.getProtocol()"
: (hasInvocation
? String.format("url.getMethodParameter(methodName, \"%s\")", value[i])
: String.format("url.getParameter(\"%s\")", value[i]));
}
} else {
if (!CommonConstants.PROTOCOL_KEY.equals(value[i])) {
if (hasInvocation) {
getNameCode = String.format(
"url.getMethodParameter(methodName, \"%s\", \"%s\")", value[i], defaultExtName);
} else {
getNameCode = String.format("url.getParameter(\"%s\", %s)", value[i], getNameCode);
}
} else {
if (isProtocolKey) {
getNameCode = String.format("url.getProtocol() == null ? (%s) : url.getProtocol()", getNameCode);
} else {
getNameCode = hasInvocation
? String.format(
"url.getMethodParameter(methodName, \"%s\", \"%s\")", value[i], defaultExtName)
: String.format("url.getParameter(\"%s\", %s)", value[i], getNameCode);
}
}
}
Expand Down
Loading