1

I am trying to import com.sun.tools.javac.code.Symbol to my below bold code line in Open JDK -11. But i am unable to import the above package. Need Support !`

Code line

private String getJsonValue(Element element) {
    JSONObject builder = new JSONObject();
    **ClassSymbol classSymbol = (ClassSymbol) element.getEnclosingElement();**
    PackageElement packageElement = null;
    if (classSymbol.getEnclosingElement() instanceof   PackageElement) {
        packageElement = (PackageElement) classSymbol.getEnclosingElement();
    }
    
}

Error code

Show screen capture

  • 2
    The example you are adapting is not written for Java 11 (where things have moved around). Also this is an internal class not for public consumption. – Thorbjørn Ravn Andersen Mar 26 '21 at 09:52
  • Thanks. Yeah I already got that @ThorbjørnRavnAndersen. I am asking here what should be the workaround for above 'ClassSymbol classSymbol = (ClassSymbol) element.getEnclosingElement();' code line if this 'com.sun.tools.javac.code.Symbol' import is not possible in open JDK-11 ? – Sahan Sudaraka Mar 26 '21 at 10:02
  • 1
    Your question did not indicate that you got that. I would suggest you just assign it to an object for now, skip the rest, and inspect the type of classSymbol in a debugger. – Thorbjørn Ravn Andersen Mar 26 '21 at 11:33
  • My fault @ThorbjørnRavnAndersen ! Since 'element.getEnclosingElement()' returns javax.lang.model.element.Element type Element , I was casting it to com.sun.tools.javac.code.Symbol type object alright, I was unable to put a debug when i use OPEN JDK 11 because this error is a compilation error.(Please look at the original error i was attached a screen capture). My question here what type of alternatives ca use for 'com.sun.tools.javac.code.Symbol.ClassSymbol, com.sun.tools.javac.code.Symbol.MethodSymbol, com.sun.tools.javac.code.Symbol.VarSymbol' these type of imports ? – Sahan Sudaraka Mar 27 '21 at 02:57
  • Change your code so it is just stored in an object (comment out the rest for now) and it will run. Then inspect. – Thorbjørn Ravn Andersen Mar 27 '21 at 07:12

0 Answers0