Skip to content

Commit d470679

Browse files
tswstarplanetbeiwei30
authored andcommitted
Move the iteration of methods of a service config to the if block of the class have method declared not by Object; remove some useless parameter type (#3282)
1 parent ca84f6c commit d470679

File tree

1 file changed

+38
-40
lines changed
  • dubbo-common/src/main/java/org/apache/dubbo/common/bytecode

1 file changed

+38
-40
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Wrapper.java

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ private static Wrapper makeWrapper(Class<?> c) {
137137
c2.append(name).append(" w; try{ w = ((").append(name).append(")$1); }catch(Throwable e){ throw new IllegalArgumentException(e); }");
138138
c3.append(name).append(" w; try{ w = ((").append(name).append(")$1); }catch(Throwable e){ throw new IllegalArgumentException(e); }");
139139

140-
Map<String, Class<?>> pts = new HashMap<String, Class<?>>(); // <property name, property types>
141-
Map<String, Method> ms = new LinkedHashMap<String, Method>(); // <method desc, Method instance>
142-
List<String> mns = new ArrayList<String>(); // method names.
143-
List<String> dmns = new ArrayList<String>(); // declaring method names.
140+
Map<String, Class<?>> pts = new HashMap<>(); // <property name, property types>
141+
Map<String, Method> ms = new LinkedHashMap<>(); // <method desc, Method instance>
142+
List<String> mns = new ArrayList<>(); // method names.
143+
List<String> dmns = new ArrayList<>(); // declaring method names.
144144

145145
// get all public field.
146146
for (Field f : c.getFields()) {
@@ -160,51 +160,49 @@ private static Wrapper makeWrapper(Class<?> c) {
160160
boolean hasMethod = hasMethods(methods);
161161
if (hasMethod) {
162162
c3.append(" try{");
163-
}
164-
for (Method m : methods) {
165-
if (m.getDeclaringClass() == Object.class) //ignore Object's method.
166-
{
167-
continue;
168-
}
163+
for (Method m : methods) {
164+
//ignore Object's method.
165+
if (m.getDeclaringClass() == Object.class) {
166+
continue;
167+
}
169168

170-
String mn = m.getName();
171-
c3.append(" if( \"").append(mn).append("\".equals( $2 ) ");
172-
int len = m.getParameterTypes().length;
173-
c3.append(" && ").append(" $3.length == ").append(len);
169+
String mn = m.getName();
170+
c3.append(" if( \"").append(mn).append("\".equals( $2 ) ");
171+
int len = m.getParameterTypes().length;
172+
c3.append(" && ").append(" $3.length == ").append(len);
174173

175-
boolean override = false;
176-
for (Method m2 : methods) {
177-
if (m != m2 && m.getName().equals(m2.getName())) {
178-
override = true;
179-
break;
174+
boolean override = false;
175+
for (Method m2 : methods) {
176+
if (m != m2 && m.getName().equals(m2.getName())) {
177+
override = true;
178+
break;
179+
}
180180
}
181-
}
182-
if (override) {
183-
if (len > 0) {
184-
for (int l = 0; l < len; l++) {
185-
c3.append(" && ").append(" $3[").append(l).append("].getName().equals(\"")
186-
.append(m.getParameterTypes()[l].getName()).append("\")");
181+
if (override) {
182+
if (len > 0) {
183+
for (int l = 0; l < len; l++) {
184+
c3.append(" && ").append(" $3[").append(l).append("].getName().equals(\"")
185+
.append(m.getParameterTypes()[l].getName()).append("\")");
186+
}
187187
}
188188
}
189-
}
190189

191-
c3.append(" ) { ");
190+
c3.append(" ) { ");
192191

193-
if (m.getReturnType() == Void.TYPE) {
194-
c3.append(" w.").append(mn).append('(').append(args(m.getParameterTypes(), "$4")).append(");").append(" return null;");
195-
} else {
196-
c3.append(" return ($w)w.").append(mn).append('(').append(args(m.getParameterTypes(), "$4")).append(");");
197-
}
192+
if (m.getReturnType() == Void.TYPE) {
193+
c3.append(" w.").append(mn).append('(').append(args(m.getParameterTypes(), "$4")).append(");").append(" return null;");
194+
} else {
195+
c3.append(" return ($w)w.").append(mn).append('(').append(args(m.getParameterTypes(), "$4")).append(");");
196+
}
198197

199-
c3.append(" }");
198+
c3.append(" }");
200199

201-
mns.add(mn);
202-
if (m.getDeclaringClass() == c) {
203-
dmns.add(mn);
200+
mns.add(mn);
201+
if (m.getDeclaringClass() == c) {
202+
dmns.add(mn);
203+
}
204+
ms.put(ReflectUtils.getDesc(m), m);
204205
}
205-
ms.put(ReflectUtils.getDesc(m), m);
206-
}
207-
if (hasMethod) {
208206
c3.append(" } catch(Throwable e) { ");
209207
c3.append(" throw new java.lang.reflect.InvocationTargetException(e); ");
210208
c3.append(" }");
@@ -216,7 +214,7 @@ private static Wrapper makeWrapper(Class<?> c) {
216214
Matcher matcher;
217215
for (Map.Entry<String, Method> entry : ms.entrySet()) {
218216
String md = entry.getKey();
219-
Method method = (Method) entry.getValue();
217+
Method method = entry.getValue();
220218
if ((matcher = ReflectUtils.GETTER_METHOD_DESC_PATTERN.matcher(md)).matches()) {
221219
String pn = propertyName(matcher.group(1));
222220
c2.append(" if( $2.equals(\"").append(pn).append("\") ){ return ($w)w.").append(method.getName()).append("(); }");

0 commit comments

Comments
 (0)