title: How can I store values inside JDT/ASTVisitor()?
body: <p>I have a code that detects the start position and length of invocation of a method in the source as follows.</p>
  
  <p>I need to store those data outside the ASTVisitor(), but using final int, I got an error.</p>
  
  <p>How can I store values inside ASTVisitor()? </p>
  
  <pre><code>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;
          }
      });
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/JHxNB.png" alt="enter image description here"></p>