JavaParser 列出两个版本的差异化代码
时间: 2023-09-30 10:07:27 浏览: 56
好的,以下是 JavaParser 3.0.0 和 3.1.0 版本之间的一些差异化代码:
1. `com.github.javaparser.ast.expr.EnclosedExpr` 类的 `getInner` 方法在 3.0.0 版本中返回一个 `Expression` 对象,而在 3.1.0 版本中返回一个 `Optional<Expression>` 对象,需要使用 `ifPresent` 方法来获取内部表达式。
JavaParser 3.0.0 版本代码:
```java
public Expression getInner() {
return inner;
}
```
JavaParser 3.1.0 版本代码:
```java
public Optional<Expression> getInner() {
return Optional.ofNullable(inner);
}
```
2. `com.github.javaparser.ast.CompilationUnit` 类的 `setImports` 方法在 3.0.0 版本中接受一个 `List<ImportDeclaration>` 参数,而在 3.1.0 版本中改为接受一个 `NodeList<ImportDeclaration>` 参数。
JavaParser 3.0.0 版本代码:
```java
public void setImports(List<ImportDeclaration> imports) {
this.imports = imports;
setAsParentNodeOf(this.imports);
}
```
JavaParser 3.1.0 版本代码:
```java
public void setImports(NodeList<ImportDeclaration> imports) {
this.imports = imports;
setAsParentNodeOf(this.imports);
}
```
3. `com.github.javaparser.ast.visitor.VoidVisitorAdapter` 类的 `visit` 方法在 3.0.0 版本中接受一个 `Node` 参数,而在 3.1.0 版本中改为接受一个泛型类型为 `T extends Node` 的参数。
JavaParser 3.0.0 版本代码:
```java
public void visit(Node node) {
if (node != null) {
node.accept(this, null);
}
}
```
JavaParser 3.1.0 版本代码:
```java
public <T extends Node> void visit(T node, A arg) {
if (node != null) {
node.accept(this, arg);
}
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)