Skip to content

Commit 0989592

Browse files
authored
Replace Java Poet with JavaParser in annotation processing (Azure#43998)
Replace Java Poet with JavaParser in annotation processing
1 parent 7714c80 commit 0989592

File tree

21 files changed

+1354
-850
lines changed

21 files changed

+1354
-850
lines changed

eng/versioning/external_dependencies.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ com.microsoft.azure:azure-functions-maven-plugin;1.30.0
3939
com.microsoft.azure.functions:azure-functions-java-library;2.2.0
4040
com.mysql:mysql-connector-j;9.0.0
4141
com.squareup.okhttp3:okhttp;4.12.0
42-
com.squareup:javapoet;1.13.0
4342
commons-codec:commons-codec;1.15
4443
commons-net:commons-net;3.9.0
4544
io.cloudevents:cloudevents-api;2.2.0

sdk/clientcore/annotation-processor-test/pom.xml

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,65 @@
7878
<groupId>org.apache.maven.plugins</groupId>
7979
<artifactId>maven-compiler-plugin</artifactId>
8080
<version>3.13.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-compiler-plugin;external_dependency} -->
81-
<configuration>
82-
<proc>only</proc>
83-
<!-- Supported source version 'RELEASE_8' from annotation processor 'io.clientcore.annotation.processor.AnnotationProcessor' less than -source '17' -->
84-
<failOnWarning>false</failOnWarning>
85-
<generatedSourcesDirectory>${project.build.directory}/generated-sources/</generatedSourcesDirectory>
86-
<annotationProcessorPaths>
87-
<annotationProcessorPath>
88-
<groupId>io.clientcore</groupId>
89-
<artifactId>annotation-processor</artifactId>
90-
<version>1.0.0-beta.1</version> <!-- {x-version-update;io.clientcore:annotation-processor;current} -->
91-
</annotationProcessorPath>
92-
</annotationProcessorPaths>
93-
<annotationProcessors>
94-
<annotationProcessor>io.clientcore.annotation.processor.AnnotationProcessor</annotationProcessor>
95-
</annotationProcessors>
96-
<compileSourceRoots>
97-
<compileSourceRoot>${project.build.directory}/generated-sources/</compileSourceRoot>
98-
</compileSourceRoots>
99-
</configuration>
81+
<executions>
82+
<execution>
83+
<id>run-annotation-processing</id>
84+
<phase>generate-sources</phase>
85+
<goals>
86+
<goal>compile</goal>
87+
</goals>
88+
89+
<configuration>
90+
<source>1.8</source>
91+
<target>1.8</target>
92+
<release>8</release>
93+
<proc>only</proc>
94+
<generatedSourcesDirectory>${project.build.directory}/generated-sources/</generatedSourcesDirectory>
95+
<annotationProcessorPaths>
96+
<annotationProcessorPath>
97+
<groupId>io.clientcore</groupId>
98+
<artifactId>annotation-processor</artifactId>
99+
<version>1.0.0-beta.1</version> <!-- {x-version-update;io.clientcore:annotation-processor;current} -->
100+
</annotationProcessorPath>
101+
</annotationProcessorPaths>
102+
<annotationProcessors>
103+
<annotationProcessor>io.clientcore.annotation.processor.AnnotationProcessor</annotationProcessor>
104+
</annotationProcessors>
105+
106+
<compilerArgs>
107+
<arg>-Xlint:-options</arg>
108+
</compilerArgs>
109+
</configuration>
110+
</execution>
111+
</executions>
112+
113+
<dependencies>
114+
<dependency>
115+
<groupId>io.clientcore</groupId>
116+
<artifactId>annotation-processor</artifactId>
117+
<version>1.0.0-beta.1</version> <!-- {x-version-update;io.clientcore:annotation-processor;current} -->
118+
</dependency>
119+
</dependencies>
120+
</plugin>
121+
122+
<plugin>
123+
<groupId>org.codehaus.mojo</groupId>
124+
<artifactId>build-helper-maven-plugin</artifactId>
125+
<version>3.6.0</version> <!-- {x-version-update;org.codehaus.mojo:build-helper-maven-plugin;external_dependency} -->
126+
<executions>
127+
<execution>
128+
<id>add-generated-sources</id>
129+
<phase>generate-sources</phase>
130+
<goals>
131+
<goal>add-source</goal>
132+
</goals>
133+
<configuration>
134+
<sources>
135+
<source>${basedir}/target/generated-sources</source>
136+
</sources>
137+
</configuration>
138+
</execution>
139+
</executions>
100140
</plugin>
101141
</plugins>
102142
</build>
Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package io.clientcore.annotation.processor.test.implementation;
5+
6+
import io.clientcore.core.serialization.json.JsonReader;
7+
import io.clientcore.core.serialization.json.JsonSerializable;
8+
import io.clientcore.core.serialization.json.JsonToken;
9+
import io.clientcore.core.serialization.json.JsonWriter;
10+
11+
import java.io.IOException;
12+
import java.time.OffsetDateTime;
13+
import java.time.format.DateTimeFormatter;
14+
import java.util.Map;
15+
16+
/**
17+
* The Foo model.
18+
*/
19+
public final class Foo implements JsonSerializable<Foo> {
20+
/*
21+
* The key of the key-value.
22+
*/
23+
private String key;
24+
25+
/*
26+
* The label the key-value belongs to.
27+
*/
28+
private String label;
29+
30+
/*
31+
* The content type of the value stored within the key-value.
32+
*/
33+
private String contentType;
34+
35+
/*
36+
* The value of the key-value.
37+
*/
38+
private String value;
39+
40+
/*
41+
* A date representing the last time the key-value was modified.
42+
*/
43+
private OffsetDateTime lastModified;
44+
45+
/*
46+
* The tags of the key-value
47+
*/
48+
private Map<String, String> tags;
49+
50+
/*
51+
* Indicates whether the key-value is locked.
52+
*/
53+
private Boolean locked;
54+
55+
/*
56+
* A value representing the current state of the resource.
57+
*/
58+
private String etag;
59+
60+
/**
61+
* Creates an instance of Foo class.
62+
*/
63+
public Foo() {
64+
}
65+
66+
/**
67+
* Get the key property: The key of the key-value.
68+
*
69+
* @return the key value.
70+
*/
71+
public String getKey() {
72+
return this.key;
73+
}
74+
75+
/**
76+
* Set the key property: The key of the key-value.
77+
*
78+
* @param key the key value to set.
79+
* @return the Foo object itself.
80+
*/
81+
public Foo setKey(String key) {
82+
this.key = key;
83+
return this;
84+
}
85+
86+
/**
87+
* Get the label property: The label the key-value belongs to.
88+
*
89+
* @return the label value.
90+
*/
91+
public String getLabel() {
92+
return this.label;
93+
}
94+
95+
/**
96+
* Set the label property: The label the key-value belongs to.
97+
*
98+
* @param label the label value to set.
99+
* @return the Foo object itself.
100+
*/
101+
public Foo setLabel(String label) {
102+
this.label = label;
103+
return this;
104+
}
105+
106+
/**
107+
* Get the contentType property: The content type of the value stored within the key-value.
108+
*
109+
* @return the contentType value.
110+
*/
111+
public String getContentType() {
112+
return this.contentType;
113+
}
114+
115+
/**
116+
* Set the contentType property: The content type of the value stored within the key-value.
117+
*
118+
* @param contentType the contentType value to set.
119+
* @return the Foo object itself.
120+
*/
121+
public Foo setContentType(String contentType) {
122+
this.contentType = contentType;
123+
return this;
124+
}
125+
126+
/**
127+
* Get the value property: The value of the key-value.
128+
*
129+
* @return the value value.
130+
*/
131+
public String getValue() {
132+
return this.value;
133+
}
134+
135+
/**
136+
* Set the value property: The value of the key-value.
137+
*
138+
* @param value the value value to set.
139+
* @return the Foo object itself.
140+
*/
141+
public Foo setValue(String value) {
142+
this.value = value;
143+
return this;
144+
}
145+
146+
/**
147+
* Get the lastModified property: A date representing the last time the key-value was modified.
148+
*
149+
* @return the lastModified value.
150+
*/
151+
public OffsetDateTime getLastModified() {
152+
return this.lastModified;
153+
}
154+
155+
/**
156+
* Set the lastModified property: A date representing the last time the key-value was modified.
157+
*
158+
* @param lastModified the lastModified value to set.
159+
* @return the Foo object itself.
160+
*/
161+
public Foo setLastModified(OffsetDateTime lastModified) {
162+
this.lastModified = lastModified;
163+
return this;
164+
}
165+
166+
/**
167+
* Get the tags property: The tags of the key-value.
168+
*
169+
* @return the tags value.
170+
*/
171+
public Map<String, String> getTags() {
172+
return this.tags;
173+
}
174+
175+
/**
176+
* Set the tags property: The tags of the key-value.
177+
*
178+
* @param tags the tags value to set.
179+
* @return the Foo object itself.
180+
*/
181+
public Foo setTags(Map<String, String> tags) {
182+
this.tags = tags;
183+
return this;
184+
}
185+
186+
/**
187+
* Get the locked property: Indicates whether the key-value is locked.
188+
*
189+
* @return the locked value.
190+
*/
191+
public Boolean isLocked() {
192+
return this.locked;
193+
}
194+
195+
/**
196+
* Set the locked property: Indicates whether the key-value is locked.
197+
*
198+
* @param locked the locked value to set.
199+
* @return the Foo object itself.
200+
*/
201+
public Foo setLocked(Boolean locked) {
202+
this.locked = locked;
203+
return this;
204+
}
205+
206+
/**
207+
* Get the etag property: A value representing the current state of the resource.
208+
*
209+
* @return the etag value.
210+
*/
211+
public String getEtag() {
212+
return this.etag;
213+
}
214+
215+
/**
216+
* Set the etag property: A value representing the current state of the resource.
217+
*
218+
* @param etag the etag value to set.
219+
* @return the Foo object itself.
220+
*/
221+
public Foo setEtag(String etag) {
222+
this.etag = etag;
223+
return this;
224+
}
225+
226+
/**
227+
* {@inheritDoc}
228+
*/
229+
@Override
230+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
231+
jsonWriter.writeStartObject();
232+
jsonWriter.writeStringField("key", this.key);
233+
jsonWriter.writeStringField("label", this.label);
234+
jsonWriter.writeStringField("content_type", this.contentType);
235+
jsonWriter.writeStringField("value", this.value);
236+
jsonWriter.writeStringField("last_modified",
237+
this.lastModified == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.lastModified));
238+
jsonWriter.writeMapField("tags", this.tags, (writer, element) -> writer.writeString(element));
239+
jsonWriter.writeBooleanField("locked", this.locked);
240+
jsonWriter.writeStringField("etag", this.etag);
241+
return jsonWriter.writeEndObject();
242+
}
243+
244+
/**
245+
* Reads an instance of Foo from the JsonReader.
246+
*
247+
* @param jsonReader The JsonReader being read.
248+
* @return An instance of Foo if the JsonReader was pointing to an instance of it, or null if it was pointing
249+
* to JSON null.
250+
* @throws IOException If an error occurs while reading the Foo.
251+
*/
252+
public static Foo fromJson(JsonReader jsonReader) throws IOException {
253+
return jsonReader.readObject(reader -> {
254+
Foo deserializedKeyValue = new Foo();
255+
while (reader.nextToken() != JsonToken.END_OBJECT) {
256+
String fieldName = reader.getFieldName();
257+
reader.nextToken();
258+
259+
if ("key".equals(fieldName)) {
260+
deserializedKeyValue.key = reader.getString();
261+
} else if ("label".equals(fieldName)) {
262+
deserializedKeyValue.label = reader.getString();
263+
} else if ("content_type".equals(fieldName)) {
264+
deserializedKeyValue.contentType = reader.getString();
265+
} else if ("value".equals(fieldName)) {
266+
deserializedKeyValue.value = reader.getString();
267+
} else if ("last_modified".equals(fieldName)) {
268+
deserializedKeyValue.lastModified = OffsetDateTime.parse(reader.getString());
269+
} else if ("tags".equals(fieldName)) {
270+
Map<String, String> tags = reader.readMap(reader1 -> reader1.getString());
271+
deserializedKeyValue.tags = tags;
272+
} else if ("locked".equals(fieldName)) {
273+
deserializedKeyValue.locked = reader.getNullable(JsonReader::getBoolean);
274+
} else if ("etag".equals(fieldName)) {
275+
deserializedKeyValue.etag = reader.getString();
276+
} else {
277+
reader.skipChildren();
278+
}
279+
}
280+
281+
return deserializedKeyValue;
282+
});
283+
}
284+
}

0 commit comments

Comments
 (0)