Java 8 semantic analysis for the javalang project. Therefore, the Java 8 AST is enriched with data calculated during the semantic analysis. Mainly, the calculated data is:
-
Symbols data types: In other words, what are the Java runtime classes, fields and methods that a given type or expression is referencing. For example, if the AST contains a
MethodCallExprnode, the methodgetSymbolData()of this node returns thejava.lang.Methodthat this node is referencing. -
Definitions and usages: For those nodes that are subclass of
SymbolDefinition(e.g declarations), the nodes contain which external references(getBodyReferences()) they have and which nodes reference them inside the same compilation unit (getUsages()).
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
If you are interested in creating a new walkmod plugin for Java code that requires this kind of information, you must add the following steps:
-
Add the following dependency in your project.
<dependency>
<groupId>org.walkmod</groupId>
<artifactId>javalang-compiler</artifactId>
<version>{last-version}</version>
</dependency>
-
Annotate your code transformations (visitors) with the
@RequiresSemanticAnalysisannotation. Walkmod (specifically the walkmod-javalang-plugin), will automatically run theorg.walkmod.javalang.compiler.symbols.SymbolVisitorAdapterto enrich the nodes. -
Add a walkmod plugin in your
walkmod.xmlfile that resolves your classpath and compiles your code (e.g walkmod-maven-plugin)