0
我有一個代碼,檢測源的方法調用的開始位置和長度如下。如何在JDT/ASTVisitor()中存儲值?
我需要將這些數據存儲在ASTVisitor()之外,但是使用final int,我得到了一個錯誤。
如何將值存儲在ASTVisitor()中?
public void setPositionFinder(String methodName) throws JavaModelException
{
//findMethod(methodName);
IType type = this.javaProject.findType(this.className);
ICompilationUnit unit = type.getCompilationUnit();
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(unit);
parser.setResolveBindings(true);
CompilationUnit cunit = (CompilationUnit) parser.createAST(null);
//ASTNode root = parser.createAST(null);
final String name = this.newMethodName;
final int startPosition = -1;
final int length = -1;
cunit.accept(new ASTVisitor() {
public boolean visit(MethodInvocation methodInvocation)
{
String methodName = methodInvocation.getName().toString();
System.out.println(methodName);
if (methodName.equals(name))
{
// ERROR!
startPosition = methodInvocation.getStartPosition();
length = methodInvocation.getLength();
System.out.printf("startPosition %d - Length %d", startPosition, length);
}
return false;
}
});
}