This is an automated email from the ASF dual-hosted git repository.

sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new aa96709ba2d Remove useless MethodAdvisor (#23398)
aa96709ba2d is described below

commit aa96709ba2dbadb9123c5e0936ae3179d1a2d639
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jan 7 23:54:46 2023 +0800

    Remove useless MethodAdvisor (#23398)
---
 .../agent/core/builder/advisor/MethodAdvisor.java  | 35 ----------------------
 .../core/builder/advisor/MethodAdvisorBuilder.java | 23 +++++++-------
 2 files changed, 12 insertions(+), 46 deletions(-)

diff --git 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/builder/advisor/MethodAdvisor.java
 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/builder/advisor/MethodAdvisor.java
deleted file mode 100644
index f146b1abf87..00000000000
--- 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/builder/advisor/MethodAdvisor.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.builder.advisor;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import net.bytebuddy.description.method.MethodDescription;
-import org.apache.shardingsphere.agent.core.plugin.executor.AdviceExecutor;
-
-/**
- * Method advisor.
- */
-@RequiredArgsConstructor
-@Getter
-public final class MethodAdvisor {
-    
-    private final MethodDescription pointcut;
-    
-    private final AdviceExecutor adviceExecutor;
-}
diff --git 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/builder/advisor/MethodAdvisorBuilder.java
 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/builder/advisor/MethodAdvisorBuilder.java
index db48bdbf680..c30e835d118 100644
--- 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/builder/advisor/MethodAdvisorBuilder.java
+++ 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/builder/advisor/MethodAdvisorBuilder.java
@@ -27,10 +27,11 @@ import 
org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
 import org.apache.shardingsphere.agent.api.advice.type.StaticMethodAdvice;
 import org.apache.shardingsphere.agent.core.log.LoggerFactory;
 import org.apache.shardingsphere.agent.core.log.LoggerFactory.Logger;
+import 
org.apache.shardingsphere.agent.core.plugin.advisor.AdvisorConfiguration;
+import org.apache.shardingsphere.agent.core.plugin.executor.AdviceExecutor;
 import 
org.apache.shardingsphere.agent.core.plugin.executor.type.ConstructorAdviceExecutor;
 import 
org.apache.shardingsphere.agent.core.plugin.executor.type.InstanceMethodAdviceExecutor;
 import 
org.apache.shardingsphere.agent.core.plugin.executor.type.StaticMethodAdviceExecutor;
-import 
org.apache.shardingsphere.agent.core.plugin.advisor.AdvisorConfiguration;
 
 import java.util.Collection;
 import java.util.Optional;
@@ -58,9 +59,13 @@ public final class MethodAdvisorBuilder {
      */
     public Builder<?> build(final Builder<?> builder) {
         Builder<?> result = builder;
-        for (MethodAdvisor each : getMatchedMethodAdvisors()) {
+        for (InDefinedShape each : typePointcut.getDeclaredMethods()) {
+            Optional<AdviceExecutor> adviceExecutor = 
findMatchedAdviceExecutor(each);
+            if (!adviceExecutor.isPresent()) {
+                continue;
+            }
             try {
-                result = each.getAdviceExecutor().decorateBuilder(result, 
each.getPointcut());
+                result = adviceExecutor.get().decorateBuilder(result, each);
                 // CHECKSTYLE:OFF
             } catch (final Throwable ex) {
                 // CHECKSTYLE:ON
@@ -70,21 +75,17 @@ public final class MethodAdvisorBuilder {
         return result;
     }
     
-    private Collection<MethodAdvisor> getMatchedMethodAdvisors() {
-        return 
typePointcut.getDeclaredMethods().stream().map(this::findMatchedMethodAdvisor).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
-    }
-    
-    private Optional<MethodAdvisor> findMatchedMethodAdvisor(final 
InDefinedShape methodDescription) {
+    private Optional<AdviceExecutor> findMatchedAdviceExecutor(final 
InDefinedShape methodDescription) {
         Collection<AgentAdvice> advices = advisorConfig.getAdvisors().stream()
                 .filter(each -> 
each.getPointcut().matches(methodDescription)).map(each -> 
adviceFactory.getAdvice(each.getAdviceClassName())).collect(Collectors.toList());
         if (isConstructor(methodDescription)) {
-            return Optional.of(new MethodAdvisor(methodDescription, new 
ConstructorAdviceExecutor(advices.stream().map(each -> (ConstructorAdvice) 
each).collect(Collectors.toList()))));
+            return Optional.of(new 
ConstructorAdviceExecutor(advices.stream().map(each -> (ConstructorAdvice) 
each).collect(Collectors.toList())));
         }
         if (isStaticMethod(methodDescription)) {
-            return Optional.of(new MethodAdvisor(methodDescription, new 
StaticMethodAdviceExecutor(advices.stream().map(each -> (StaticMethodAdvice) 
each).collect(Collectors.toList()))));
+            return Optional.of(new 
StaticMethodAdviceExecutor(advices.stream().map(each -> (StaticMethodAdvice) 
each).collect(Collectors.toList())));
         }
         if (isMethod(methodDescription)) {
-            return Optional.of(new MethodAdvisor(methodDescription, new 
InstanceMethodAdviceExecutor(advices.stream().map(each -> 
(InstanceMethodAdvice) each).collect(Collectors.toList()))));
+            return Optional.of(new 
InstanceMethodAdviceExecutor(advices.stream().map(each -> 
(InstanceMethodAdvice) each).collect(Collectors.toList())));
         }
         return Optional.empty();
     }

Reply via email to