I am trying to catch constructor in a class and the constructor name is caught as "init" in aspectj. I want to print the constructor name and not as "init".
I tried to capture constructor call inside the class "LeastSquaresSolver_ESTest" and it printed the constructor name as "init" instead of the actual name of the constructor. The code is given below.
Code:
pointcut publicMethodExecuted1() :
execution(org.la4j.linear.LeastSquaresSolver_ESTest.new(..));
before(): publicMethodExecuted1() {
String value2=thisJoinPoint.getSignature().getName();
System.out.println(value2);
}
The expected value is the constructor name and the actual value is init. Kindly help in this regard.
<init>
is just a symbolic name used to denote a constructor. Actually constructors have no names like methods. When you declare them in Java you use the class name instead. If this is what you want you can get it like this:
String fullyQualifiedClassName = thisJoinPoint.getSignature().getDeclaringTypeName();
// org.la4j.linear.LeastSquaresSolver_ESTest
String shortClassName = thisJoinPoint.getSignature().getDeclaringType().getSimpleName();
// LeastSquaresSolver_ESTest
Or just don't make a simple thing complicated and print the joinpoint or at least the signature directly, then you see exactly what is going on:
System.out.println(thisJoinPoint);
// execution(org.la4j.linear.LeastSquaresSolver_ESTest(String, int))
System.out.println(thisJoinPoint.getSignature());
// org.la4j.linear.LeastSquaresSolver_ESTest(String, int)
I always print the full joinpoint because it contains exactly the information I need whenever I want to debug something or just better understand what my aspect does.