久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='UP6ef'></bdo><ul id='UP6ef'></ul>
  • <legend id='UP6ef'><style id='UP6ef'><dir id='UP6ef'><q id='UP6ef'></q></dir></style></legend>

    1. <i id='UP6ef'><tr id='UP6ef'><dt id='UP6ef'><q id='UP6ef'><span id='UP6ef'><b id='UP6ef'><form id='UP6ef'><ins id='UP6ef'></ins><ul id='UP6ef'></ul><sub id='UP6ef'></sub></form><legend id='UP6ef'></legend><bdo id='UP6ef'><pre id='UP6ef'><center id='UP6ef'></center></pre></bdo></b><th id='UP6ef'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='UP6ef'><tfoot id='UP6ef'></tfoot><dl id='UP6ef'><fieldset id='UP6ef'></fieldset></dl></div>

      <small id='UP6ef'></small><noframes id='UP6ef'>

    2. <tfoot id='UP6ef'></tfoot>
      1. 從 Java 注釋處理器訪問源代碼

        Accessing source code from Java Annotation Processor(從 Java 注釋處理器訪問源代碼)

          <small id='qc2Xe'></small><noframes id='qc2Xe'>

            <tbody id='qc2Xe'></tbody>
          • <bdo id='qc2Xe'></bdo><ul id='qc2Xe'></ul>
                  <legend id='qc2Xe'><style id='qc2Xe'><dir id='qc2Xe'><q id='qc2Xe'></q></dir></style></legend>
                  <tfoot id='qc2Xe'></tfoot>

                • <i id='qc2Xe'><tr id='qc2Xe'><dt id='qc2Xe'><q id='qc2Xe'><span id='qc2Xe'><b id='qc2Xe'><form id='qc2Xe'><ins id='qc2Xe'></ins><ul id='qc2Xe'></ul><sub id='qc2Xe'></sub></form><legend id='qc2Xe'></legend><bdo id='qc2Xe'><pre id='qc2Xe'><center id='qc2Xe'></center></pre></bdo></b><th id='qc2Xe'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qc2Xe'><tfoot id='qc2Xe'></tfoot><dl id='qc2Xe'><fieldset id='qc2Xe'></fieldset></dl></div>

                  本文介紹了從 Java 注釋處理器訪問源代碼的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試從 Java 注釋處理器中訪問某個類型的實際原始源代碼.這有可能嗎?謝謝!

                  I am trying to access the actual original source code of a type from within a Java Annotation Processor. Is this possible somehow? Thanks!

                  推薦答案

                  我遇到了一個問題,我必須訪問一些源代碼(非字符串/非原始常量的初始化代碼)并通過訪問解決了它通過 編譯器樹 API.

                  I had a problem where I had to access some source code (the initializer code for a non-String/non-primitive constant) and got it solved by accessing the source code via the Compiler Tree API.

                  這是一般配方:

                  1.創建自定義 TreePathScanner:

                  private static class CodeAnalyzerTreeScanner extends TreePathScanner<Object, Trees> {
                  
                  private String fieldName;
                  
                  private String fieldInitializer;
                  
                  public void setFieldName(String fieldName) {
                      this.fieldName = fieldName;
                  }
                  
                  public String getFieldInitializer() {
                      return this.fieldInitializer;
                  }
                  
                  @Override
                  public Object visitVariable(VariableTree variableTree, Trees trees) {
                      if (variableTree.getName().toString().equals(this.fieldName)) {
                          this.fieldInitializer = variableTree.getInitializer().toString();
                      }
                  
                      return super.visitVariable(variableTree, trees);
                  }
                  

                  <強>2.在您的 AbstractProcessor 中,通過覆蓋 init 方法保存對當前編譯樹的引用:

                  @Override
                  public void init(ProcessingEnvironment pe) {
                      super.init(pe);
                      this.trees = Trees.instance(pe);
                  }
                  

                  3.獲取 VariableElement 的初始化源代碼(在您的情況下為枚舉):

                  // assuming theClass is a javax.lang.model.element.Element reference
                  // assuming theField is a javax.lang.model.element.VariableElement reference
                  String fieldName = theField.getSimpleName().toString();
                  CodeAnalyzerTreeScanner codeScanner = new CodeAnalyzerTreeScanner();
                  TreePath tp = this.trees.getPath(theClass);
                  
                  codeScanner.setFieldName(fieldName);
                  codeScanner.scan(tp, this.trees);
                  String fieldInitializer = codeScanner.getFieldInitializer();
                  

                  就是這樣!最后 fieldInitializer 變量將包含用于初始化我的常量的確切代碼行.通過一些調整,您應該能夠使用相同的配方來訪問源樹中其他元素類型的源代碼(即方法、包聲明等)

                  And that's it! In the end the fieldInitiliazer variable is going to contain the exact line(s) of code used to initialize my constant. With some tweaking you should be able to use the same recipe to access the source code of other element types in the source tree (i.e. methods, package declarations, etc)

                  有關更多閱讀和示例,請閱讀此 文章:來源使用 Java 6 API 進行代碼分析.

                  For more reading and examples read this article: Source Code Analysis Using Java 6 APIs.

                  這篇關于從 Java 注釋處理器訪問源代碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯誤)
                  Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語句 - 是“或/“和可能的?)
                  Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                  What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數的三元表達式的類型是什么?)
                  Read a text file and store every single character occurrence(讀取文本文件并存儲出現的每個字符)
                  Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉換 char 原語?)

                  1. <i id='L99fo'><tr id='L99fo'><dt id='L99fo'><q id='L99fo'><span id='L99fo'><b id='L99fo'><form id='L99fo'><ins id='L99fo'></ins><ul id='L99fo'></ul><sub id='L99fo'></sub></form><legend id='L99fo'></legend><bdo id='L99fo'><pre id='L99fo'><center id='L99fo'></center></pre></bdo></b><th id='L99fo'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='L99fo'><tfoot id='L99fo'></tfoot><dl id='L99fo'><fieldset id='L99fo'></fieldset></dl></div>
                        <bdo id='L99fo'></bdo><ul id='L99fo'></ul>

                        1. <legend id='L99fo'><style id='L99fo'><dir id='L99fo'><q id='L99fo'></q></dir></style></legend>
                            <tfoot id='L99fo'></tfoot>

                              <tbody id='L99fo'></tbody>

                            <small id='L99fo'></small><noframes id='L99fo'>

                          • 主站蜘蛛池模板: 丁香五月网久久综合 | 亚洲一区二区精品 | 羞羞羞视频 | 在线观看黄视频 | 精品国产一区二区久久 | 成人在线小视频 | www.788.com色淫免费 | 精品一二三区在线观看 | 久久久激情| 国产片侵犯亲女视频播放 | 欧美日韩国产在线观看 | 欧美一区二区三区在线 | av男人的天堂在线 | 中文精品久久 | 久久aⅴ乱码一区二区三区 亚洲国产成人精品久久久国产成人一区 | 午夜久久久久 | 天天天操操操 | 成人在线激情 | av资源在线看 | 国产99久久久国产精品 | 黄色三级在线播放 | 99热这里只有精品8 激情毛片 | 国产精品美女久久久 | 日韩色图视频 | 天天操综合网 | 国产一区二区美女 | 99精品观看 | 成人高清在线视频 | 日本在线视 | 一区二区免费视频 | 成人在线免费观看 | 日韩一区二区三区视频 | www.中文字幕 | www.99re| 黑人巨大精品欧美一区二区一视频 | 国产精品久久久久久久久久久久久 | 午夜精品久久久久久不卡欧美一级 | 欧美三级视频在线观看 | 国产成人综合在线 | 91精品无人区卡一卡二卡三 | 成人不卡视频 |