test_class.file: dubbo-common/src/test/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGeneratorTest.java
test_class.identifier: AdaptiveClassCodeGeneratorTest
test_case.body: @Test
      public void testGenerate() throws IOException {
          AdaptiveClassCodeGenerator generator = new AdaptiveClassCodeGenerator(HasAdaptiveExt.class, "adaptive");
          String value = generator.generate();
          URL url = getClass().getResource("/org/apache/dubbo/common/extension/adaptive/HasAdaptiveExt$Adaptive");
          try (InputStream inputStream = url.openStream()) {
              String content = IOUtils.read(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
              // in Windows platform content get from resource contains \r delimiter
              content = content.replaceAll("\r","");
              assertTrue(content.contains(value));
          }
      }
test_case.class_method_signature: AdaptiveClassCodeGeneratorTest.testGenerate()
test_case.full_signature: @Test public void testGenerate()
test_case.identifier: testGenerate
test_case.invocations: generate getResource getClass openStream read replaceAll assertTrue contains
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGenerate()
focal_class.declarator: logger = LoggerFactory.getLogger(AdaptiveClassCodeGenerator.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(AdaptiveClassCodeGenerator.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: CLASSNAME_INVOCATION = "org.apache.dubbo.rpc.Invocation"
focal_class.modifier: private static final
focal_class.original_string: private static final String CLASSNAME_INVOCATION = "org.apache.dubbo.rpc.Invocation";
focal_class.type: String
focal_class.var_name: CLASSNAME_INVOCATION
focal_class.declarator: CODE_PACKAGE = "package %s;\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_PACKAGE = "package %s;\n";
focal_class.type: String
focal_class.var_name: CODE_PACKAGE
focal_class.declarator: CODE_IMPORTS = "import %s;\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_IMPORTS = "import %s;\n";
focal_class.type: String
focal_class.var_name: CODE_IMPORTS
focal_class.declarator: CODE_CLASS_DECLARATION = "public class %s$Adaptive implements %s {\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_CLASS_DECLARATION = "public class %s$Adaptive implements %s {\n";
focal_class.type: String
focal_class.var_name: CODE_CLASS_DECLARATION
focal_class.declarator: CODE_METHOD_DECLARATION = "public %s %s(%s) %s {\n%s}\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_METHOD_DECLARATION = "public %s %s(%s) %s {\n%s}\n";
focal_class.type: String
focal_class.var_name: CODE_METHOD_DECLARATION
focal_class.declarator: CODE_METHOD_ARGUMENT = "%s arg%d"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_METHOD_ARGUMENT = "%s arg%d";
focal_class.type: String
focal_class.var_name: CODE_METHOD_ARGUMENT
focal_class.declarator: CODE_METHOD_THROWS = "throws %s"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_METHOD_THROWS = "throws %s";
focal_class.type: String
focal_class.var_name: CODE_METHOD_THROWS
focal_class.declarator: CODE_UNSUPPORTED = "throw new UnsupportedOperationException(\"The method %s of interface %s is not adaptive method!\");\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_UNSUPPORTED = "throw new UnsupportedOperationException(\"The method %s of interface %s is not adaptive method!\");\n";
focal_class.type: String
focal_class.var_name: CODE_UNSUPPORTED
focal_class.declarator: CODE_URL_NULL_CHECK = "if (arg%d == null) throw new IllegalArgumentException(\"url == null\");\n%s url = arg%d;\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_URL_NULL_CHECK = "if (arg%d == null) throw new IllegalArgumentException(\"url == null\");\n%s url = arg%d;\n";
focal_class.type: String
focal_class.var_name: CODE_URL_NULL_CHECK
focal_class.declarator: CODE_EXT_NAME_ASSIGNMENT = "String extName = %s;\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_EXT_NAME_ASSIGNMENT = "String extName = %s;\n";
focal_class.type: String
focal_class.var_name: CODE_EXT_NAME_ASSIGNMENT
focal_class.declarator: CODE_EXT_NAME_NULL_CHECK = "if(extName == null) "
                      + "throw new IllegalStateException(\"Failed to get extension (%s) name from url (\" + url.toString() + \") use keys(%s)\");\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_EXT_NAME_NULL_CHECK = "if(extName == null) "
                      + "throw new IllegalStateException(\"Failed to get extension (%s) name from url (\" + url.toString() + \") use keys(%s)\");\n";
focal_class.type: String
focal_class.var_name: CODE_EXT_NAME_NULL_CHECK
focal_class.declarator: CODE_INVOCATION_ARGUMENT_NULL_CHECK = "if (arg%d == null) throw new IllegalArgumentException(\"invocation == null\"); "
                      + "String methodName = arg%d.getMethodName();\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_INVOCATION_ARGUMENT_NULL_CHECK = "if (arg%d == null) throw new IllegalArgumentException(\"invocation == null\"); "
                      + "String methodName = arg%d.getMethodName();\n";
focal_class.type: String
focal_class.var_name: CODE_INVOCATION_ARGUMENT_NULL_CHECK
focal_class.declarator: CODE_EXTENSION_ASSIGNMENT = "%s extension = (%<s)%s.getExtensionLoader(%s.class).getExtension(extName);\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_EXTENSION_ASSIGNMENT = "%s extension = (%<s)%s.getExtensionLoader(%s.class).getExtension(extName);\n";
focal_class.type: String
focal_class.var_name: CODE_EXTENSION_ASSIGNMENT
focal_class.declarator: CODE_EXTENSION_METHOD_INVOKE_ARGUMENT = "arg%d"
focal_class.modifier: private static final
focal_class.original_string: private static final String CODE_EXTENSION_METHOD_INVOKE_ARGUMENT = "arg%d";
focal_class.type: String
focal_class.var_name: CODE_EXTENSION_METHOD_INVOKE_ARGUMENT
focal_class.declarator: type
focal_class.modifier: private final
focal_class.original_string: private final Class<?> type;
focal_class.type: Class<?>
focal_class.var_name: type
focal_class.declarator: defaultExtName
focal_class.modifier: private
focal_class.original_string: private String defaultExtName;
focal_class.type: String
focal_class.var_name: defaultExtName
focal_class.file: dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java
focal_class.identifier: AdaptiveClassCodeGenerator
focal_class.class_method_signature: AdaptiveClassCodeGenerator.AdaptiveClassCodeGenerator(Class<?> type, String defaultExtName)
focal_class.full_signature: public  AdaptiveClassCodeGenerator(Class<?> type, String defaultExtName)
focal_class.identifier: AdaptiveClassCodeGenerator
focal_class.modifiers: public
focal_class.parameters: (Class<?> type, String defaultExtName)
focal_class.signature:  AdaptiveClassCodeGenerator(Class<?> type, String defaultExtName)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.hasAdaptiveMethod()
focal_class.full_signature: private boolean hasAdaptiveMethod()
focal_class.identifier: hasAdaptiveMethod
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean hasAdaptiveMethod()
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generate()
focal_class.full_signature: public String generate()
focal_class.identifier: generate
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String generate()
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generatePackageInfo()
focal_class.full_signature: private String generatePackageInfo()
focal_class.identifier: generatePackageInfo
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String generatePackageInfo()
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateImports()
focal_class.full_signature: private String generateImports()
focal_class.identifier: generateImports
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String generateImports()
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateClassDeclaration()
focal_class.full_signature: private String generateClassDeclaration()
focal_class.identifier: generateClassDeclaration
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String generateClassDeclaration()
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateUnsupported(Method method)
focal_class.full_signature: private String generateUnsupported(Method method)
focal_class.identifier: generateUnsupported
focal_class.modifiers: private
focal_class.parameters: (Method method)
focal_class.return: String
focal_class.signature: String generateUnsupported(Method method)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.getUrlTypeIndex(Method method)
focal_class.full_signature: private int getUrlTypeIndex(Method method)
focal_class.identifier: getUrlTypeIndex
focal_class.modifiers: private
focal_class.parameters: (Method method)
focal_class.return: int
focal_class.signature: int getUrlTypeIndex(Method method)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateMethod(Method method)
focal_class.full_signature: private String generateMethod(Method method)
focal_class.identifier: generateMethod
focal_class.modifiers: private
focal_class.parameters: (Method method)
focal_class.return: String
focal_class.signature: String generateMethod(Method method)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateMethodArguments(Method method)
focal_class.full_signature: private String generateMethodArguments(Method method)
focal_class.identifier: generateMethodArguments
focal_class.modifiers: private
focal_class.parameters: (Method method)
focal_class.return: String
focal_class.signature: String generateMethodArguments(Method method)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateMethodThrows(Method method)
focal_class.full_signature: private String generateMethodThrows(Method method)
focal_class.identifier: generateMethodThrows
focal_class.modifiers: private
focal_class.parameters: (Method method)
focal_class.return: String
focal_class.signature: String generateMethodThrows(Method method)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateUrlNullCheck(int index)
focal_class.full_signature: private String generateUrlNullCheck(int index)
focal_class.identifier: generateUrlNullCheck
focal_class.modifiers: private
focal_class.parameters: (int index)
focal_class.return: String
focal_class.signature: String generateUrlNullCheck(int index)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateMethodContent(Method method)
focal_class.full_signature: private String generateMethodContent(Method method)
focal_class.identifier: generateMethodContent
focal_class.modifiers: private
focal_class.parameters: (Method method)
focal_class.return: String
focal_class.signature: String generateMethodContent(Method method)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateExtNameNullCheck(String[] value)
focal_class.full_signature: private String generateExtNameNullCheck(String[] value)
focal_class.identifier: generateExtNameNullCheck
focal_class.modifiers: private
focal_class.parameters: (String[] value)
focal_class.return: String
focal_class.signature: String generateExtNameNullCheck(String[] value)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateExtNameAssignment(String[] value, boolean hasInvocation)
focal_class.full_signature: private String generateExtNameAssignment(String[] value, boolean hasInvocation)
focal_class.identifier: generateExtNameAssignment
focal_class.modifiers: private
focal_class.parameters: (String[] value, boolean hasInvocation)
focal_class.return: String
focal_class.signature: String generateExtNameAssignment(String[] value, boolean hasInvocation)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateExtensionAssignment()
focal_class.full_signature: private String generateExtensionAssignment()
focal_class.identifier: generateExtensionAssignment
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String generateExtensionAssignment()
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateReturnAndInvocation(Method method)
focal_class.full_signature: private String generateReturnAndInvocation(Method method)
focal_class.identifier: generateReturnAndInvocation
focal_class.modifiers: private
focal_class.parameters: (Method method)
focal_class.return: String
focal_class.signature: String generateReturnAndInvocation(Method method)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.hasInvocationArgument(Method method)
focal_class.full_signature: private boolean hasInvocationArgument(Method method)
focal_class.identifier: hasInvocationArgument
focal_class.modifiers: private
focal_class.parameters: (Method method)
focal_class.return: boolean
focal_class.signature: boolean hasInvocationArgument(Method method)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateInvocationArgumentNullCheck(Method method)
focal_class.full_signature: private String generateInvocationArgumentNullCheck(Method method)
focal_class.identifier: generateInvocationArgumentNullCheck
focal_class.modifiers: private
focal_class.parameters: (Method method)
focal_class.return: String
focal_class.signature: String generateInvocationArgumentNullCheck(Method method)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.getMethodAdaptiveValue(Adaptive adaptiveAnnotation)
focal_class.full_signature: private String[] getMethodAdaptiveValue(Adaptive adaptiveAnnotation)
focal_class.identifier: getMethodAdaptiveValue
focal_class.modifiers: private
focal_class.parameters: (Adaptive adaptiveAnnotation)
focal_class.return: String[]
focal_class.signature: String[] getMethodAdaptiveValue(Adaptive adaptiveAnnotation)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateUrlAssignmentIndirectly(Method method)
focal_class.full_signature: private String generateUrlAssignmentIndirectly(Method method)
focal_class.identifier: generateUrlAssignmentIndirectly
focal_class.modifiers: private
focal_class.parameters: (Method method)
focal_class.return: String
focal_class.signature: String generateUrlAssignmentIndirectly(Method method)
focal_class.class_method_signature: AdaptiveClassCodeGenerator.generateGetUrlNullCheck(int index, Class<?> type, String method)
focal_class.full_signature: private String generateGetUrlNullCheck(int index, Class<?> type, String method)
focal_class.identifier: generateGetUrlNullCheck
focal_class.modifiers: private
focal_class.parameters: (int index, Class<?> type, String method)
focal_class.return: String
focal_class.signature: String generateGetUrlNullCheck(int index, Class<?> type, String method)
focal_method.body: public String generate() {
          // no need to generate adaptive class since there's no adaptive method found.
          if (!hasAdaptiveMethod()) {
              throw new IllegalStateException("No adaptive method exist on extension " + type.getName() + ", refuse to create the adaptive class!");
          }
  
          StringBuilder code = new StringBuilder();
          code.append(generatePackageInfo());
          code.append(generateImports());
          code.append(generateClassDeclaration());
  
          Method[] methods = type.getMethods();
          for (Method method : methods) {
              code.append(generateMethod(method));
          }
          code.append("}");
  
          if (logger.isDebugEnabled()) {
              logger.debug(code.toString());
          }
          return code.toString();
      }
focal_method.class_method_signature: AdaptiveClassCodeGenerator.generate()
focal_method.full_signature: public String generate()
focal_method.identifier: generate
focal_method.invocations: hasAdaptiveMethod getName append generatePackageInfo append generateImports append generateClassDeclaration getMethods append generateMethod append isDebugEnabled debug toString toString
focal_method.modifiers: public
focal_method.parameters: ()
focal_method.return: String
focal_method.signature: String generate()