javaparser icon indicating copy to clipboard operation
javaparser copied to clipboard

Is there a way to obtain method calls just inside the project?

Open GholamaliIrani opened this issue 3 years ago • 1 comments

I want to get all method calls inside methods of the classes of local project, not method calls external the local project packages.

I try this:

 // finding all method calls
      List<MethodCallExpr> allMethodCalls = declaration.findAll(MethodCallExpr.class);
      for (MethodCallExpr methodcall : allMethodCalls)
      {
    	  MethodInvocation mcall=new MethodInvocation();	
    	  
    	  System.out.println("CALLLLL : " + methodcall.getName());
    	  System.out.println("     LL : " + methodcall.getScope());        	
    	  
    	  
    	  try {
        		  System.out.println("  CCCCC : " + methodcall.calculateResolvedType().describe());
        		  System.out.println("  CCCCC : " + methodcall.getParentNode().get().toString());
    	  }
    	  catch (Exception e) {
			  // TODO: handle exception
	  }
    	  
    	  
    	  try {
            	  System.out.println("  QQQQQ : " + methodcall.resolve().getSignature());        		
    	    	  System.out.println("  QQQQQ : " + methodcall.resolve().getQualifiedSignature());
        		  System.out.println("  QQQQQ : " + methodcall.resolve().getQualifiedName());
        		  System.out.println("  QQQQQ : " + methodcall.resolve().getPackageName());
            	  //System.out.println("  QQQQQ : " + methodcall.resolve().toString());
    	  }
    	  catch (Exception e) {
		  // TODO: handle exception
	  }
      }
    

but I could not distinguish among them.

GholamaliIrani avatar Jul 25 '22 11:07 GholamaliIrani

Hi @GholamaliIrani have you tried to resolve the scope of the method call and then filter on the qualified name? Can you provide us a simple unit test that illustrates your problem?

jlerbsc avatar Jul 25 '22 15:07 jlerbsc

I am closing this issue but you can reopen it if the answer does not suit you.

jlerbsc avatar Aug 18 '22 06:08 jlerbsc