-1

Using JavaCC 6.0_1, with JDK_VERSION set to (the default of) 1.5, I'm unable to use the getErrorOffset method of ParseException - despite the Java docs stating that it exists.

Is there something I've missed?

Minimum example:

PARSER_BEGIN(B)
class B {
    public static void main(String[] args) {
        ParseException p = new ParseException("Test", 2);
        System.out.println(p.getErrorOffset());
    }
}
PARSER_END(B)

TOKEN: {<TRIVIAL: "foo">}

Results:

$ javacc B.jj
[...]
Parser generated successfully.
$ javac ./*.java
./B.java:5: error: no suitable constructor found for ParseException(String,int)
                ParseException p = new ParseException("Test", 2);
                                   ^
    constructor ParseException.ParseException(Token,int[][],String[]) is not applicable
      (actual and formal argument lists differ in length)
    constructor ParseException.ParseException() is not applicable
      (actual and formal argument lists differ in length)
    constructor ParseException.ParseException(String) is not applicable
      (actual and formal argument lists differ in length)
./B.java:6: error: cannot find symbol
                System.out.println(p.getErrorOffset());
                                    ^
  symbol:   method getErrorOffset()
  location: variable p of type ParseException
2 errors

(The second error similarly shows that the "error offset" part of ParseException is mysteriously absent...)

  • This isn't really a question. It's just a statement that you can't do something that can't be done. You are unable to call a method. If you want to know why you can't use the method, it is because there is no such method. If you have an actual problem that you'd like help to solve: E.g. "How can I find the source coordinates associated with a ParseException?" then I'd suggest you close this question and ask the question you actually need an answer to if you can't answer it yourself. – Theodore Norvell Apr 13 '17 at 01:05

1 Answers1

0

It would seem that the class I linked, java.text.ParseException, is not the class that JavaCC uses!

Some reflection:

    System.out.println("getCanonicalName():\n"+ParseException.class.getCanonicalName()+"\n");
    System.out.println("getPackage():\n"+ParseException.class.getPackage()+"\n");
    System.out.println("getDeclaredMethods():");
    for (java.lang.reflect.Method m : ParseException.class.getDeclaredMethods()) {
        System.out.println(m);
    }
    System.out.println("\ngetDeclaredFields():");
    for (java.lang.reflect.Field m : ParseException.class.getFields()) {
        System.out.println(m);
    }

Output:

getCanonicalName():
ParseException

getPackage():
null

getDeclaredMethods():
private static java.lang.String ParseException.initialise(Token,int[][],java.lang.String[])
static java.lang.String ParseException.add_escapes(java.lang.String)

getDeclaredFields():
public Token ParseException.currentToken
public int[][] ParseException.expectedTokenSequences
public java.lang.String[] ParseException.tokenImage

Altogther, more parser-related functionality, but missing that seemingly extremely useful method I was after - despite the toString() containing that information!