2

JDT를 사용하는 메소드 호출을 점검하고 해당 인수를 점검합니다. MethodInvocation 노드를 방문하고이 작업을 수행하는 AST Visitor 클래스를 사용하고 있습니다. Visitor 클래스에서 아래 메서드를 사용합니다.VariableDeclarationStatement 안에있는 MethodInvocation에 액세스하는 방법

public boolean visit(MethodInvocation node) { 

     if (node.getName().toString().equals("createQuery")) { 

      String argument= node.arguments().get(0).toString(); 

      // process the argument here 

     } 

     return true; 
    } 

그러나 변수 선언의 일부인 호출은 visted되지 않습니다.

예 : 'createQuery'메소드의 호출을 찾고있는 경우, 아래 호출이 방문됩니다.

session.createQuery("some query here"); 

부 이것이 방문하지 않았습니다.

Query query = session.createQuery("another query here"); 

어떻게 그러한 진술을 방문하고 적절한 방법으로 인수를 가져올 수 있습니까?

도와주세요.

답변

0

발견 ... AST의 VariableDeclarationStatement 노드를 방문하여 true를 반환해야합니다.

public boolean visit(VariableDeclarationStatement node) { 

    return true; 
} 

이렇게하면 AST에서 VariableDeclarationStatement의 하위 항목을 방문 할 수 있습니다. 메서드 호출의 특정 유형은 VariableDeclarationStatement 노드의 하위 노드로 제공되므로 방문도 수행됩니다.