ExpressionStatements를 가져 와서 하위 노드와 하위 노드를 반환하여 AST 노드의 모든 하위 노드를 가져 오려고하는데 알고리즘이 작동하지 않습니다. 첫 번째 ExpStat과 나는 이유를 찾을 수 없습니다.ASTNode의 모든 하위 노드 (하위 및 하위 노드)를 찾는 방법
public static void getChildren(ASTNode node) {
if (node != null) {
List<ASTNode> children = new ArrayList<ASTNode>();
List list = node.structuralPropertiesForType();
for (int i = 0; i < list.size(); i++) {
Object child = node.getStructuralProperty((StructuralPropertyDescriptor) list.get(i));
if (child instanceof ASTNode) {
children.add((ASTNode) child);
}
if (children.get(0) != null) {
String c = children.toString();
results.append("Children Node: " + c + "\n");
getChildren(children.get(0));
}
}
} else {
return;
}
}
:
은 우선은 내가 아이들private void analyseClass(ICompilationUnit classe) throws JavaModelException {
// ICompilationUnit unit == class
// now create the AST for the ICompilationUnits
CompilationUnit parse = parse(classe);
// Calls the method for visit node in AST e return your information
ExpressionStatementVisitor visitor = new ExpressionStatementVisitor();
parse.accept(visitor);
// Write in the screen: ExpressionStatement and your type next
for (ExpressionStatement method : visitor.getExpression()) {
//String t = null;
// 32 -> METHOD_INVOCATION type
if (method.getExpression().getNodeType() == 32) {
getChildren(method);
results.append("\n\n");
}
// 48 -> SUPER_METHOD_INVOCATION type
else if (method.getExpression().getNodeType() == 48) {
// results.append("\n SuperMethodInvocation: " + t);
//getChildren(method);
//results.append("\n\n");
} else {
//getChildren(method);
//results.append("\n\n");
}
}
}
을 반복적으로 아이들이 찾을 수있는 기능을 찾을 수있는 함수를 호출, 내 클래스의 모든 ExpressionStatements를 찾는 방문자 기능을 생성 수업에서 다음과 같이 가정 해 봅시다.
a.getTheDataA().getTheDataB().getTheDataC().getTheData();
b.getTheDataA().getTheDataB().getTheDataC().getTheData();
c.getTheE(a,b).getTheF(getTheDataB).getTheH();
getChildren 함수는 ds 만 a.getTheDataA(). getTheDataB(). getTheDataC(). getTheData(); 이 같은 그의 아이들과 아이의 아이를 반환
나는 내가 무엇을보고에서 재귀
동일한 결과가 표시되지만 도움을 주셔서 감사합니다. ((: –