2013-03-29 4 views
1

일부 클래스는 내부 클래스가있는 프로젝트를 구문 분석하고 싶습니다 .Eclips JDT를 사용하여 내부 클래스 이름을 다른 정보로 추출 할 수 있습니까?일식을 사용하여 내부 클래스를 추출하십시오.

+0

어떻게 이것이 javascript와 관련이 있습니까 ?? –

+0

실수로 소리. – rosedoli

+0

도움이된다면 답을 수락하시오 –

답변

4

Compilation 단위의 Java 클래스를 탐색하여 TypeDeclaration AST 노드를 방문 할 수 있습니다. 아래 코드는 최상위 클래스가 아닌 내부 클래스인지 확인하는 데 사용할 수 있습니다. 익명의 내부 클래스를 얻기 위해

public boolean visit(TypeDeclaration typeDeclarationStatement) { 

    if (!typeDeclarationStatement.isPackageMemberTypeDeclaration()) { 
      System.out.println(typeDeclarationStatement.getName()); 
      // Get more details from the type declaration. 
    } 

    return true; 
} 

는 아래 너무 코드를 사용 : 클래스 탐색에

public boolean visit(AnonymousClassDeclaration anonyomousClassDeclaration) { 

    System.out.println(anonyomousClassDeclaration.toString()); 

    return true; 
} 

세부 JDT를 사용하여 링크를 아래에서 찾을 수 있습니다

+0

아래 코드를 사용했지만 모든 내부 클래스를 표시하지 않습니다 – rosedoli

+0

코드에 내부 클래스가 표시되지 않거나 일부 특정 내부 클래스에 문제가 있습니까 (익명/메서드 내부 클래스)? –

+0

ASTParser 파서 = ASTParser.newParser (AST.JLS3); parser.setKind (ASTParser.K_COMPILATION_UNIT); parser.setSource (fileName.toString(). toCharArray()); parser.setResolveBindings (true); parser.setCompilerOptions (options); final CompilationUnit cu = (CompilationUnit) parser.createAST (null); cu.accept (새 ASTVisitor() { \t \t \t 공공 부울 방문 (TypeDeclaration typeDeclarationStatement) { 경우 (typeDeclarationStatement.isPackageMemberTypeDeclaration()) { 에서 System.out.println (typeDeclarationStatement.getName())! 사실 } 반환;. 그런 당신을 위해 작동하는 경우 } – rosedoli

1

IType 인스턴스 (유형)가있는 경우

type.getTypes(); 

이 유형으로 선언 된 직접 멤버 유형의 배열을 제공합니다.

+0

어떤 메신저 ITYPE 예를 – rosedoli

+0

를 사용하지 않는 확인하지만 만약 그렇게 ICompilationUnit의 인스턴스가 당신을? 모든 최상위 유형 선언을 얻을 수 있습니다. ICompilationUnit.getTypes()를 사용하여이 컴파일 단위의 이온 –

관련 문제