Skip to content

Commit

Permalink
fix: support deprecated annotation in get set method
Browse files Browse the repository at this point in the history
  • Loading branch information
飞澋 authored and PanPanZou committed Jun 25, 2024
1 parent efcc2d8 commit c3d91e5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class Visitor {
dependencyObject.artifactId = dependency[1];
dependencyObject.version = this.packageManager[`${dependency[0]}:${dependency[1]}`];
newJson.project.dependencies[0].dependency.forEach((dependency) => {
if (dependency.groupId[0] === dependencyObject.groupId
if (dependency.groupId[0] === dependencyObject.groupId
&& dependency.artifactId[0] === dependencyObject.artifactId) {
dependency.version[0] = dependencyObject.version;
needAdd = false;
Expand Down Expand Up @@ -937,7 +937,11 @@ class Visitor {
node = ast.nodes[i];
const value = node.fieldValue;

const deprecated = getAttr(node, 'deprecated');
let fieldName = _name(node.fieldName);
if (deprecated === 'true') {
this.emit(`@Deprecated\n`, level);
}
this.emit(`public ${_subModelName(modelName, this.conflictModelNameMap, this.allModleNameMap, this.enableMinimizeModelName)} set`, level);
this.emit(`${_upperFirst(fieldName)}(`);
this.visitFieldType(value, node, modelName);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/comment/models/Test1.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public String getTest() {
return this.test;
}

@Deprecated
public Test1 setTest2(String test2) {
this.test2 = test2;
return this;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/comment/models/Test4.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static Test4 build(java.util.Map<String, ?> map) throws Exception {
return TeaModel.build(map, self);
}

@Deprecated
public Test4 setTest(String test) {
this.test = test;
return this;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/model/MinimizeModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public java.util.Map<String, String> getMapfield() {
return this.mapfield;
}

@Deprecated
public MyModel setName(String name) {
this.name = name;
return this;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/model/MyModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public java.util.Map<String, String> getMapfield() {
return this.mapfield;
}

@Deprecated
public MyModel setName(String name) {
this.name = name;
return this;
Expand Down

0 comments on commit c3d91e5

Please sign in to comment.