Accepted answer

one solution will be not using the offset logic at all. you can generalise the solution by using a node parent check.

here is a sample code:

public boolean visit(stringliteral stringliteral) {

        // check if parent is a method inovacation.
        if (stringliteral.getparent().getnodetype() == astnode.method_invocation) {

              // get the parent method inovacation.
              methodinvocation minode = (methodinvocation) stringliteral.getparent();

              //to do: null and empty check on argument list.

              // check if is the special method and this is the 1st argument
              if (minode.getname().tostring().equals("specialmethod")
                        && minode.arguments().get(0).tostring().equals(stringliteral.tostring())) {

                    system.out.println("found it : " + stringliteral.tostring());

        return true;

Related Query

More Query from same tag