2017-12-16 9 views
1

국기 및 기타 정보로 declared methods을 검색하고 싶습니다.AccessFlags로 찾기 방법

예를 들어, 방법 public final void ae(StringTokenizer);을 검색하고 싶습니다.

다음
private CtMethod findMethod(CtClass clazz, int access, String returns, String[] parameters) throws NotFoundException { 

    /* 
     returns = null = void, other String for returned class name 
     parameters = easy names of parameters 
    */ 
    CtMethod found = null; 

    for(CtMethod method : clazz.getDeclaredMethods()) { 
     // Check here all flags and informations - If found, set the `found` variable and return 
    } 

    return found; 
} 

은 샘플의 호출입니다 : 여기

어떻게 그것을 검색 할 샘플 방법입니다

내가 샘플 AccessFlag.FINAL | AccessFlag.PUBLIC를 들어, 명시 적으로 플래그를 확인할 수있는 방법
CtMethod inputMethod = this.findMethod(theClass, AccessFlag.FINAL, null, new String[] { "StringTokenizer" }); 

?

답변

1

CtMethod::getModifiers​을 호출하여 수정자를 얻을 수 있습니다. 그런 다음 수정 자 설정 여부를 확인할 수 있습니다.

if (ctMethod.getModifiers() & (AccessFlag.FINAL | AccessFlag.PUBLIC) != 0) { 
    found = ctMethod; 
    break; 
}