AST를 구하는 방법을 공유해 주신 Jeff에게 감사드립니다. 내 코드를 살펴본 결과, AST를 가져 오는 다른 방법이 있지만 공용 API도 사용합니다. 그 방법도 게시하고 싶습니다.
// Assume there is a variable, 'file', of type IFile
ICProject cProject = CoreModel.getDefault().create(file.getProject());
ITranslationUnit unit = CoreModelUtil.findTranslationUnit(file);
if (unit == null) {
unit = CoreModel.getDefault().createTranslationUnitFrom(cProject, file.getLocation());
}
IASTTranslationUnit ast = null;
IIndex index = null;
try {
index = CCorePlugin.getIndexManager().getIndex(cProject);
} catch (CoreException e) {
...
}
try {
index.acquireReadLock();
ast = unit.getAST(index, ITranslationUnit.AST_PARSE_INACTIVE_CODE);
if (ast == null) {
throw new IllegalArgumentException(file.getLocation().toPortableString() + ": not a valid C/C++ code file");
}
} catch (InterruptedException e) {
...
} catch (CoreException e) {
...
} finally {
index.releaseReadLock();
}
광산은 좀 더 복잡합니다. 나는 기본적으로 물건들이 일관되게 100 % 일하기 시작할 때까지 물건들을 바꾸어 놓았다. 실제 리팩터링에 대해 말한 내용을 추가 할 필요가 없습니다.
편집 : 명확히하기 위해 : 이것은 제가 지금까지 번역 단위를 얻는 데있어 가장 안전한 방법입니다.
그래서 마지막으로 무엇을 했습니까? –