Skip to content

Commit 5b425f5

Browse files
committed
Fixed bug that system will get parameter name in the method as method's parameter.
1 parent 2715f11 commit 5b425f5

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

EasyRest/src/main/java/tech/dbgsoftware/easyrest/model/request/RestObject.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,21 @@ private void analysisMethod(){
8383
MethodInfo methodInfo = cm.getMethodInfo();
8484
CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
8585
LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
86-
int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;
86+
boolean afterThis = false;
87+
List<String> paraName = new ArrayList<>(method.getParameters().length);
88+
for (int i = 0; i < attr.tableLength(); i++) {
89+
String name = attr.variableName(i);
90+
if (!afterThis && name.equalsIgnoreCase("this")){
91+
afterThis = true;
92+
continue;
93+
}
94+
if (afterThis && paraName.size() < method.getParameters().length) {
95+
paraName.add(name);
96+
}
97+
}
8798
for (int i = 0; i < method.getParameters().length; i++) {
88-
String parameterName = attr.variableName(i + pos);
8999
Type type = method.getParameters()[i].getParameterizedType();
90-
parameterTypeMap.put(parameterName, type);
100+
parameterTypeMap.put(paraName.get(i), type);
91101
}
92102
} catch (Exception e){
93103
e.printStackTrace();

Example/Example-Quick-Start/src/main/java/com/example/rest/TestRestService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
import tech.dbgsoftware.easyrest.annotations.method.BindURL;
44
import tech.dbgsoftware.easyrest.annotations.method.Get;
5+
import tech.dbgsoftware.easyrest.annotations.method.Post;
6+
import tech.dbgsoftware.easyrest.annotations.parameter.AllDefined;
57

68
@BindURL("/test")
79
public interface TestRestService {
810

911
@Get
1012
String ping();
1113

14+
@Post
15+
@AllDefined
16+
String test(String a, String b);
17+
1218
}

Example/Example-Quick-Start/src/main/java/com/example/services/TestServiceImpl.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,27 @@ public String ping() {
1111
return ("Pong");
1212
}
1313

14+
@Override
15+
public String test(String a, String b) {
16+
String c;
17+
String d;
18+
String e;
19+
String f;
20+
String g;
21+
if (a.equalsIgnoreCase(b)){
22+
c = a;
23+
d = a;
24+
e = a;
25+
f = a;
26+
g = a;
27+
} else {
28+
c = a;
29+
d = b;
30+
e = "e";
31+
f = "f";
32+
g = "g";
33+
}
34+
return c + "-" + d + "-" + e + "-" + f + "-" + g;
35+
}
36+
1437
}

0 commit comments

Comments
 (0)