# Automatic Refactoring Approach for Asynchronous Mechanisms with CompletableFuture
## 4 Empirical Research
### Executor Inheritance Structure Analysis
#### 5.3.1 Executor Delegation Analysis  
Executor delegation analysis aims to identify executor types within an executor inheritance hierarchy that delegate the concrete (partial) logic of their submit or execute methods, responsible for submitting asynchronous tasks, to another executor object. Whether such a type satisfies the refactoring conditions depends not only on the definition of its own submit or execute method but also on the execution logic of methods with the same name in the executor type it delegates to. In this section, we first define an interprocedural field access analysis within the class. Then, we formally define the delegated executor type and present a preliminary method for determining whether a delegated executor type can be refactored. **Definition 4**. : _Field Access Analysis: This analysis determines whether a local reference type variable local within the body of a method \(m\) of a class \(t\) ultimately points to a field \(f\) of the given class \(t\), if it points then class \(t\) belongs to the delegate class. The formal definition is as follows._  
where  
\[\text{getDefStmt}(Local):\text{Retrieves the definition statement Stmt for a local reference type variable Local within the current method body via the use-def chain.  
\[\text{isFieldAccess}(\text{Stmt},\text{ f}):\text{Determines whether a definition statement Stmt within the method body defines a local reference type variable as field f.  
\[\text{isMethodInvec}(\text{Stmt}):\text{Checks if a definition statement Stmt in the method body has a local reference type variable that serves as the return value of an intra-class method invocation.  
\[\text{getMethod}(\text{Stmt}):\text{Obtain the methods that contain class internal method calls within the current statement Stmt.  
\[\text{getReturnLocal}(\text{Method}):\text{Obtains the local reference type variable local returned in the return statement of the current method Method.  
Following this, we provide the characteristic definition of delegate executor types.  
**Definition 5**.: _Delegate Executor Type: A Delegate Executor Type (DT) is defined as a class that simultaneously satisfies the following characteristics._  
1. DT is a concrete implementation class of the ExecutorService interface, formally represented as: \[DT\in\text{allSubTypes}(ExecutorService)\land\forall\text{m}\in\text{getMethods}( DT)\text{, ``Abstract''}\
otin\text{modiMethod}(m)\] (5) where allSubTypes(T): Retrieves the set of all direct and indirect subclasses of type T. getMethods(T): Obtains the collection of all methods defined in type T. modiMethod(Method): Acquires the set of modifiers for the method Method. 2. DT has an instance field \(f\), whose declared type is ExecutorService or its subclass, formally represented as: \[\exists f^{\prime}\in\text{getFields}(\text{DT}):\text{fieldType}\big{(}f^{ \prime}\big{)}\in\text{allSubTypes}(\text{ExecutorService})\land\text{``Static''}\
otin\text{ modiField}\big{(}f^{\prime}\big{)}\] (6) where getFields(T): Retrieves all fields defined in type T. fieldType(F): Obtains the declared type of field F. modiField(F): Acquires the set of modifiers for field F.
3. The bodies of DT's execute and submit methods both contain method invocations with the same sub-signature as the methods themselves, and the receiver object of these calls is field \(f^{\prime}\), formally represented as: \[\forall m\in\{\text{execute},\text{submit}\},m\in\text{getMethods}( DT)\ \Rightarrow\ \exists stmt\in\text{getBody}(m),\] (7) \[\exists m^{\prime}\in\text{getMethod}(stmt):(\text{sig}(m^{\prime})= \text{sig}(m))\land(\text{fieldAccessAnalysis}(\text{receiver}(stmt),f^{ \prime})=\text{true})\] where getBody(Method): Retrieves the body of a given method Method, a collection of statements Stmt. sig(Method): Obtains the sub-signature of a given method Method, including the return type, method name, and the list of parameter types. receiver(Stmt): Identifies the receiver object of the method invocation expression contained in a given statement Stmt, which is a reference type local variable.