4
4
import com .azure .autorest .customization .PackageCustomization ;
5
5
import com .github .javaparser .StaticJavaParser ;
6
6
import com .github .javaparser .ast .Modifier ;
7
- import com .github .javaparser .ast .NodeList ;
8
- import com .github .javaparser .ast .body .BodyDeclaration ;
9
7
import com .github .javaparser .ast .body .ClassOrInterfaceDeclaration ;
10
- import com .github .javaparser .ast .body .ConstructorDeclaration ;
11
- import com .github .javaparser .ast .stmt .BlockStmt ;
12
- import com .github .javaparser .ast .stmt .Statement ;
13
8
import com .github .javaparser .javadoc .Javadoc ;
14
- import com .github .javaparser .javadoc .JavadocBlockTag ;
15
9
import com .github .javaparser .javadoc .description .JavadocDescription ;
16
10
import com .github .javaparser .javadoc .description .JavadocSnippet ;
17
11
import org .slf4j .Logger ;
@@ -28,7 +22,6 @@ public class DocumentIntelligenceCustomizations extends Customization {
28
22
@ Override
29
23
public void customize (LibraryCustomization customization , Logger logger ) {
30
24
customizeAnalyzeOperation (customization , logger );
31
- customizeAnalyzeBatchOperation (customization , logger );
32
25
customizePollingStrategy (customization , logger );
33
26
customizePollingUtils (customization , logger );
34
27
customizeModifierForOverloadMethods (customization , logger );
@@ -37,6 +30,18 @@ public void customize(LibraryCustomization customization, Logger logger) {
37
30
customizeAnalyzeBatchDocumentOptions (customization , logger );
38
31
customizeClassifyDocumentOptions (customization , logger );
39
32
customizeSamplesForOverload (customization , logger );
33
+ addStaticAccessorForOperationId (customization , logger );
34
+ }
35
+
36
+ private void addStaticAccessorForOperationId (LibraryCustomization customization , Logger logger ) {
37
+ logger .info ("Customizing to add static operationnId accessor setter methods" );
38
+ ClassCustomization classCustomization = customization .getPackage (MODELS_PACKAGE ).getClass ("AnalyzeOperation" );
39
+ classCustomization .addStaticBlock ("AnalyzeOperationHelper.setAccessor(new AnalyzeOperationHelper.AnalyzeOperationAccessor() {\n " +
40
+ " @Override\n " +
41
+ " public void setOperationId(AnalyzeOperation analyzeOperation, String operationId) {\n " +
42
+ " analyzeOperation.setOperationId(operationId);\n " +
43
+ " }\n " +
44
+ " });" );
40
45
}
41
46
42
47
private void customizeSamplesForOverload (LibraryCustomization customization , Logger logger ) {
@@ -140,7 +145,6 @@ private void customizeAnalyzeDocumentOptions(LibraryCustomization customization,
140
145
141
146
classCustomization .getMethod ("setUrlSource" ).setModifier (0 );
142
147
classCustomization .getMethod ("setBytesSource" ).setModifier (0 );
143
- //addConstructors(classCustomization);
144
148
}
145
149
146
150
private void customizeAnalyzeBatchDocumentOptions (LibraryCustomization customization , Logger logger ) {
@@ -151,7 +155,6 @@ private void customizeAnalyzeBatchDocumentOptions(LibraryCustomization customiza
151
155
152
156
classCustomization .getMethod ("setAzureBlobSource" ).setModifier (0 );
153
157
classCustomization .getMethod ("setAzureBlobFileListSource" ).setModifier (0 );
154
- //addConstructors(classCustomization);
155
158
}
156
159
157
160
private void customizeClassifyDocumentOptions (LibraryCustomization customization , Logger logger ) {
@@ -162,7 +165,6 @@ private void customizeClassifyDocumentOptions(LibraryCustomization customization
162
165
163
166
classCustomization .getMethod ("setUrlSource" ).setModifier (0 );
164
167
classCustomization .getMethod ("setBytesSource" ).setModifier (0 );
165
- //addConstructors(classCustomization);
166
168
}
167
169
168
170
private void customizeModifierForOverloadMethods (LibraryCustomization customization , Logger logger ) {
@@ -225,21 +227,8 @@ private void customizeAnalyzeOperation(LibraryCustomization customization, Logge
225
227
}));
226
228
}
227
229
228
- private void customizeAnalyzeBatchOperation (LibraryCustomization customization , Logger logger ) {
229
- logger .info ("Customizing the AnalyzeBatchOperation class" );
230
- PackageCustomization packageCustomization = customization .getPackage ("com.azure.ai.documentintelligence.models" );
231
- packageCustomization .getClass ("AnalyzeBatchOperation" )
232
- .removeAnnotation ("Immutable" )
233
- .customizeAst (ast ->
234
- ast .getClassByName ("AnalyzeBatchOperation" ).ifPresent (clazz -> {
235
- addOperationIdField (clazz );
236
- addOperationIdGetter (clazz );
237
- addOperationIdSetter (clazz );
238
- }));
239
- }
240
-
241
230
private void addOperationIdSetter (ClassOrInterfaceDeclaration clazz ) {
242
- clazz .addMethod ("setOperationId" , Modifier .Keyword .PUBLIC )
231
+ clazz .addMethod ("setOperationId" , Modifier .Keyword .PRIVATE )
243
232
.setType ("void" )
244
233
.addParameter ("String" , "operationId" )
245
234
.setJavadocComment (new Javadoc (new JavadocDescription (List .of (new JavadocSnippet ("Sets the operationId property: Operation ID." ))))
@@ -252,7 +241,7 @@ private void addOperationIdSetter(ClassOrInterfaceDeclaration clazz) {
252
241
}
253
242
254
243
private void addOperationIdGetter (ClassOrInterfaceDeclaration clazz ) {
255
- clazz .addMethod ("getOperationId " , Modifier .Keyword .PUBLIC )
244
+ clazz .addMethod ("getResultId " , Modifier .Keyword .PUBLIC )
256
245
.setType ("String" )
257
246
.setJavadocComment (new Javadoc (new JavadocDescription (List .of (new JavadocSnippet ("Gets the operationId property: Operation ID." ))))
258
247
.addBlockTag ("return" , "the operationId value." )
@@ -303,7 +292,6 @@ private void customizePollingStrategy(LibraryCustomization customization, Logger
303
292
packageCustomization .getClass ("SyncOperationLocationPollingStrategy" ).customizeAst (ast ->
304
293
ast .getClassByName ("SyncOperationLocationPollingStrategy" ).ifPresent (clazz -> {
305
294
ast .addImport ("com.azure.ai.documentintelligence.models.AnalyzeOperation" );
306
- ast .addImport ("com.azure.ai.documentintelligence.models.AnalyzeBatchOperation" );
307
295
ast .addImport ("static com.azure.ai.documentintelligence.implementation.PollingUtils.parseOperationId" );
308
296
addSyncPollOverrideMethod (clazz );
309
297
}));
@@ -312,7 +300,6 @@ private void customizePollingStrategy(LibraryCustomization customization, Logger
312
300
packageCustomization .getClass ("OperationLocationPollingStrategy" ).customizeAst (ast ->
313
301
ast .getClassByName ("OperationLocationPollingStrategy" ).ifPresent (clazz -> {
314
302
ast .addImport ("com.azure.ai.documentintelligence.models.AnalyzeOperation" );
315
- ast .addImport ("com.azure.ai.documentintelligence.models.AnalyzeBatchOperation" );
316
303
ast .addImport ("static com.azure.ai.documentintelligence.implementation.PollingUtils.parseOperationId" );
317
304
addAsyncPollOverrideMethod (clazz );
318
305
}));
@@ -336,11 +323,7 @@ private void addAsyncPollOverrideMethod(ClassOrInterfaceDeclaration clazz) {
336
323
" }" ,
337
324
" if (pollResponse.getValue() instanceof AnalyzeOperation) {" ,
338
325
" AnalyzeOperation operation = (AnalyzeOperation) pollResponse.getValue();" ,
339
- " operation.setOperationId(operationId);" ,
340
- " }" ,
341
- " if (pollResponse.getValue() instanceof AnalyzeBatchOperation) {" ,
342
- " AnalyzeBatchOperation operation = (AnalyzeBatchOperation) pollResponse.getValue();" ,
343
- " operation.setOperationId(operationId);" ,
326
+ " AnalyzeOperationHelper.setOperationId(operation, operationId);" ,
344
327
" }" ,
345
328
" return pollResponse;" ,
346
329
" });" ,
@@ -363,15 +346,9 @@ private void addSyncPollOverrideMethod(ClassOrInterfaceDeclaration clazz) {
363
346
"}" ,
364
347
"if (pollResponse.getValue() instanceof AnalyzeOperation) {" ,
365
348
" AnalyzeOperation operation = (AnalyzeOperation) pollResponse.getValue();" ,
366
- " operation.setOperationId(operationId);" ,
367
- "}" ,
368
- "if (pollResponse.getValue() instanceof AnalyzeBatchOperation) {" ,
369
- " AnalyzeBatchOperation operation = (AnalyzeBatchOperation) pollResponse.getValue();" ,
370
- " operation.setOperationId(operationId);" ,
349
+ " AnalyzeOperationHelper.setOperationId(operation, operationId);" ,
371
350
"}" ,
372
351
"return pollResponse;" ,
373
352
"}" )));
374
353
}
375
-
376
-
377
354
}
0 commit comments