CtMethodJavaWriter { public String createJavaSignature(CtMethod overridenMethod) throws NotFoundException { return extractModifier(overridenMethod) + " " + extractReturnType(overridenMethod) + " " + overridenMethod.getName() + "(" + extractParametersAndTypes(overridenMethod) + ")" + extractThrowClause(overridenMethod); }  String createJavaSignature(CtMethod overridenMethod); String invokeSuper(CtMethod method);  }
@Test public void testExtractSignature_simple() throws CannotCompileException, NotFoundException { CtClass targetClass = ClassPool.getDefault().makeClass( "Target" + TestCounter.testCounter++); CtMethod fooMethod = CtNewMethod.make("public void foo() { }", targetClass); targetClass.addMethod(fooMethod); String extractSignature = signatureExtractor.createJavaSignature(fooMethod); assertEquals("public void foo()", extractSignature); }
@Test public void testExtractSignature_with_return_type() throws CannotCompileException, NotFoundException { CtClass targetClass = ClassPool.getDefault().makeClass( "Target" + TestCounter.testCounter++); CtMethod fooMethod = CtNewMethod.make("public int foo() { return 0; }", targetClass); targetClass.addMethod(fooMethod); String extractSignature = signatureExtractor.createJavaSignature(fooMethod); assertEquals("public int foo()", extractSignature); }
@Test public void testExtractSignature_with_params() throws CannotCompileException, NotFoundException { CtClass targetClass = ClassPool.getDefault().makeClass( "Target" + TestCounter.testCounter++); CtMethod fooMethod = CtNewMethod.make("public void foo(int a, String b) {}", targetClass); targetClass.addMethod(fooMethod); String extractSignature = signatureExtractor.createJavaSignature(fooMethod); assertEquals("public void foo(int p0, java.lang.String p1)", extractSignature); }
@Test public void testExtractSignature_with_throws() throws CannotCompileException, NotFoundException { CtClass targetClass = ClassPool.getDefault().makeClass( "Target" + TestCounter.testCounter++); CtMethod fooMethod = CtNewMethod.make("public void foo() throws Exception, Throwable {}", targetClass); targetClass.addMethod(fooMethod); String extractSignature = signatureExtractor.createJavaSignature(fooMethod); assertEquals("public void foo() throws java.lang.Exception, java.lang.Throwable", extractSignature); }