Skip to content

Refactor rename methods to use accessor style (from getter style) #105

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

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
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 @@ -26,32 +26,32 @@ class ClientMethodWriter {
ClientMethodWriter(MethodReader method, Append writer, ProcessingContext ctx) {
this.method = method;
this.writer = writer;
this.webMethod = method.getWebMethod();
this.webMethod = method.webMethod();
this.ctx = ctx;
this.returnType = Util.parseType(method.getReturnType());
this.returnType = Util.parseType(method.returnType());
}

void addImportTypes(ControllerReader reader) {
reader.addImportTypes(returnType.importTypes());
for (MethodParam param : method.getParams()) {
for (MethodParam param : method.params()) {
param.addImports(reader);
}
}

private void methodStart(Append writer) {
for (MethodParam param : method.getParams()) {
for (MethodParam param : method.params()) {
checkBodyHandler(param);
}
writer.append(" // %s %s", webMethod, method.getWebMethodPath()).eol();
writer.append(" // %s %s", webMethod, method.webMethodPath()).eol();
writer.append(" @Override").eol();
writer.append(" public %s%s %s(", methodGenericParams, returnType.shortType(), method.simpleName());
int count = 0;
for (MethodParam param : method.getParams()) {
for (MethodParam param : method.params()) {
if (count++ > 0) {
writer.append(", ");
}
writer.append(param.getUType().shortType()).append(" ");
writer.append(param.getName());
writer.append(param.utype().shortType()).append(" ");
writer.append(param.name());
}
writer.append(") {").eol();
}
Expand All @@ -60,10 +60,10 @@ private void methodStart(Append writer) {
* Assign a method parameter as *the* BodyHandler.
*/
private void checkBodyHandler(MethodParam param) {
if (param.getRawType().startsWith(BODY_HANDLER)) {
if (param.rawType().startsWith(BODY_HANDLER)) {
param.setResponseHandler();
bodyHandlerParam = param;
methodGenericParams = param.getUType().genericParams();
methodGenericParams = param.utype().genericParams();
}
}

Expand All @@ -75,8 +75,8 @@ void write() {
}
writer.append("clientContext.request()").eol();

PathSegments pathSegments = method.getPathSegments();
Set<PathSegments.Segment> segments = pathSegments.getSegments();
PathSegments pathSegments = method.pathSegments();
Set<PathSegments.Segment> segments = pathSegments.segments();

writeHeaders();
writePaths(segments);
Expand All @@ -88,7 +88,7 @@ void write() {
}

private void writeEnd() {
WebMethod webMethod = method.getWebMethod();
WebMethod webMethod = method.webMethod();
writer.append(" .%s()", webMethod.name()).eol();
if (returnType == UType.VOID) {
writer.append(" .asVoid();").eol();
Expand Down Expand Up @@ -144,57 +144,57 @@ private void writeResponse(String type0, String type1) {

private void writeWithHandler() {
if (bodyHandlerParam != null) {
writer.append(".handler(%s);", bodyHandlerParam.getName()).eol();
writer.append(".handler(%s);", bodyHandlerParam.name()).eol();
} else {
writer.append(".handler(responseHandler);").eol(); // Better to barf here?
}
}

private void writeQueryParams(PathSegments pathSegments) {
for (MethodParam param : method.getParams()) {
ParamType paramType = param.getParamType();
for (MethodParam param : method.params()) {
ParamType paramType = param.paramType();
if (paramType == ParamType.QUERYPARAM) {
if (pathSegments.segment(param.getParamName()) == null) {
if (pathSegments.segment(param.paramName()) == null) {
if (isMap(param)) {
writer.append(" .queryParam(%s)", param.getName()).eol();
writer.append(" .queryParam(%s)", param.name()).eol();
} else {
writer.append(" .queryParam(\"%s\", %s)", param.getParamName(), param.getName()).eol();
writer.append(" .queryParam(\"%s\", %s)", param.paramName(), param.name()).eol();
}
}
}
}
}

private void writeHeaders() {
for (MethodParam param : method.getParams()) {
ParamType paramType = param.getParamType();
for (MethodParam param : method.params()) {
ParamType paramType = param.paramType();
if (paramType == ParamType.HEADER) {
if (isMap(param)) {
writer.append(" .header(%s)", param.getName()).eol();
writer.append(" .header(%s)", param.name()).eol();
} else {
writer.append(" .header(\"%s\", %s)", param.getParamName(), param.getName()).eol();
writer.append(" .header(\"%s\", %s)", param.paramName(), param.name()).eol();
}
}
}
}

private void writeBeanParams(PathSegments segments) {
for (MethodParam param : method.getParams()) {
final String varName = param.getName();
ParamType paramType = param.getParamType();
for (MethodParam param : method.params()) {
final String varName = param.name();
ParamType paramType = param.paramType();
PathSegments.Segment segment = segments.segment(varName);
if (segment == null && paramType == ParamType.BEANPARAM) {
TypeElement formBeanType = ctx.getTypeElement(param.getRawType());
BeanParamReader form = new BeanParamReader(ctx, formBeanType, param.getName(), param.getShortType(), ParamType.QUERYPARAM);
TypeElement formBeanType = ctx.typeElement(param.rawType());
BeanParamReader form = new BeanParamReader(ctx, formBeanType, param.name(), param.shortType(), ParamType.QUERYPARAM);
form.writeFormParams(writer);
}
}
}

private void writeFormParams(PathSegments segments) {
for (MethodParam param : method.getParams()) {
final String varName = param.getName();
ParamType paramType = param.getParamType();
for (MethodParam param : method.params()) {
final String varName = param.name();
ParamType paramType = param.paramType();
PathSegments.Segment segment = segments.segment(varName);
if (segment == null) {
// not a path or matrix parameter
Expand All @@ -206,22 +206,22 @@ private void writeFormParams(PathSegments segments) {
private void writeFormParam(MethodParam param, ParamType paramType) {
if (paramType == ParamType.FORMPARAM) {
if (isMap(param)) {
writer.append(" .formParam(%s)", param.getName()).eol();
writer.append(" .formParam(%s)", param.name()).eol();
} else {
writer.append(" .formParam(\"%s\", %s)", param.getParamName(), param.getName()).eol();
writer.append(" .formParam(\"%s\", %s)", param.paramName(), param.name()).eol();
}
} else if (paramType == ParamType.FORM) {
TypeElement formBeanType = ctx.getTypeElement(param.getRawType());
BeanParamReader form = new BeanParamReader(ctx, formBeanType, param.getName(), param.getShortType(), ParamType.FORMPARAM);
TypeElement formBeanType = ctx.typeElement(param.rawType());
BeanParamReader form = new BeanParamReader(ctx, formBeanType, param.name(), param.shortType(), ParamType.FORMPARAM);
form.writeFormParams(writer);
}
}

private void writeBody() {
for (MethodParam param : method.getParams()) {
ParamType paramType = param.getParamType();
for (MethodParam param : method.params()) {
ParamType paramType = param.paramType();
if (paramType == ParamType.BODY) {
writer.append(" .body(%s)", param.getName()).eol();
writer.append(" .body(%s)", param.name()).eol();
}
}
}
Expand All @@ -244,7 +244,7 @@ private void writePaths(Set<PathSegments.Segment> segments) {
}

private boolean isMap(MethodParam param) {
return isMap(param.getUType().mainType());
return isMap(param.utype().mainType());
}

private boolean isMap(String type0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void writeForImported(Element importedElement) {
private void writeImported(String fullName) {
// trim .class suffix
String apiClassName = fullName.substring(0, fullName.length() - 6);
TypeElement typeElement = ctx.getTypeElement(apiClassName);
TypeElement typeElement = ctx.typeElement(apiClassName);
if (typeElement != null) {
writeClient(typeElement);
}
Expand All @@ -101,7 +101,7 @@ private void writeClient(Element controller) {
generatedClients.add(writeClientAdapter(ctx, reader));
} catch (Throwable e) {
e.printStackTrace();
ctx.logError(reader.getBeanType(), "Failed to write client class " + e);
ctx.logError(reader.beanType(), "Failed to write client class " + e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected String initPackageName(String originName) {
}

private void readMethods() {
for (MethodReader method : reader.getMethods()) {
for (MethodReader method : reader.methods()) {
if (method.isWebMethod()) {
ClientMethodWriter methodWriter = new ClientMethodWriter(method, writer, ctx);
methodWriter.addImportTypes(reader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected BaseControllerWriter(ControllerReader reader, ProcessingContext ctx, S
this.reader = reader;
this.ctx = ctx;
this.router = "$Route".equals(suffix);
TypeElement origin = reader.getBeanType();
TypeElement origin = reader.beanType();
this.originName = origin.getQualifiedName().toString();
this.shortName = origin.getSimpleName().toString();
this.packageName = initPackageName(originName);
Expand All @@ -50,7 +50,7 @@ protected void initWriter() throws IOException {
}

protected Writer createFileWriter() throws IOException {
JavaFileObject jfo = ctx.createWriter(fullName, reader.getBeanType());
JavaFileObject jfo = ctx.createWriter(fullName, reader.beanType());
return jfo.openWriter();
}

Expand All @@ -64,11 +64,11 @@ protected void writeImports() {
if (router) {
writer.append(Constants.IMPORT_PATH_TYPE_CONVERT).eol();
}
for (String type : reader.getStaticImportTypes()) {
for (String type : reader.staticImportTypes()) {
writer.append("import static %s;", type).eol();
}
writer.eol();
for (String type : reader.getImportTypes()) {
for (String type : reader.importTypes()) {
writer.append("import %s;", type).eol();
}
writer.eol();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void writeControllerAdapter(Element controller) {
writeControllerAdapter(ctx, reader);
} catch (Throwable e) {
e.printStackTrace();
ctx.logError(reader.getBeanType(), "Failed to write $Route class " + e);
ctx.logError(reader.beanType(), "Failed to write $Route class " + e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void read() {

private void readField(Element enclosedElement) {
FieldReader field = new FieldReader(ctx, enclosedElement, defaultParamType);
fieldMap.put(field.getVarName(), field);
fieldMap.put(field.varName(), field);
}

private void readMethod(ExecutableElement enclosedElement) {
Expand Down Expand Up @@ -104,13 +104,13 @@ private Set<String> writeConstructorParams(Append writer) {

public void writeFormParams(Append writer) {
for (FieldReader field : fieldMap.values()) {
ExecutableElement getter = findGetter(field.getVarName());
ParamType paramType = field.element.getParamType();
ExecutableElement getter = findGetter(field.varName());
ParamType paramType = field.element.paramType();
String type = propertyParamType(paramType);
if (type != null) {
String accessor = (getter != null) ? getter.toString() : field.isPublic() ? field.getVarName() : null;
String accessor = (getter != null) ? getter.toString() : field.isPublic() ? field.varName() : null;
if (accessor != null) {
writer.append(" .%s(\"%s\", %s.%s)", type, field.getParamName(), beanVarName, accessor).eol();
writer.append(" .%s(\"%s\", %s.%s)", type, field.paramName(), beanVarName, accessor).eol();
}
}
}
Expand Down Expand Up @@ -152,15 +152,15 @@ static class FieldReader {
}

boolean isPublic() {
return element.getElement().getModifiers().contains(Modifier.PUBLIC);
return element.element().getModifiers().contains(Modifier.PUBLIC);
}

String getParamName() {
return element.getParamName();
String paramName() {
return element.paramName();
}

String getVarName() {
return element.getVarName();
String varName() {
return element.varName();
}

@Override
Expand All @@ -187,7 +187,7 @@ void writeSet(Append writer, String beanVarName) {

} else {
// populate via field put
writer.append("%s %s.%s = ", ctx.platform().indent(), beanVarName, getVarName());
writer.append("%s %s.%s = ", ctx.platform().indent(), beanVarName, varName());
element.setValue(writer);
writer.append(";").eol();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ private boolean initHasValid() {
return findAnnotation(Valid.class) != null;
}

String getProduces() {
String produces() {
return produces;
}

public TypeElement getBeanType() {
public TypeElement beanType() {
return beanType;
}

Expand Down Expand Up @@ -237,15 +237,15 @@ private void readMethod(ExecutableElement method, DeclaredType declaredType) {
}
}

public List<String> getRoles() {
public List<String> roles() {
return roles;
}

public List<MethodReader> getMethods() {
public List<MethodReader> methods() {
return methods;
}

public String getPath() {
public String path() {
Path path = findAnnotation(Path.class);
if (path == null) {
return null;
Expand All @@ -269,11 +269,11 @@ public void addStaticImportType(String rawType) {
staticImportTypes.add(rawType);
}

public Set<String> getStaticImportTypes() {
public Set<String> staticImportTypes() {
return staticImportTypes;
}

public Set<String> getImportTypes() {
public Set<String> importTypes() {
return importTypes;
}

Expand Down
Loading