-
-
Notifications
You must be signed in to change notification settings - Fork 342
/
CoreFactory.java
650 lines (545 loc) · 15.8 KB
/
CoreFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/*
* SPDX-License-Identifier: (MIT OR CECILL-C)
*
* Copyright (C) 2006-2023 INRIA and contributors
*
* Spoon is available either under the terms of the MIT License (see LICENSE-MIT.txt) or the Cecill-C License (see LICENSE-CECILL-C.txt). You as the user are entitled to choose the terms under which to adopt Spoon.
*/
package spoon.reflect.factory;
import java.lang.annotation.Annotation;
import spoon.reflect.code.CtAnnotationFieldAccess;
import spoon.reflect.code.CtArrayRead;
import spoon.reflect.code.CtArrayWrite;
import spoon.reflect.code.CtAssert;
import spoon.reflect.code.CtAssignment;
import spoon.reflect.code.CtBinaryOperator;
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtBreak;
import spoon.reflect.code.CtCase;
import spoon.reflect.code.CtCasePattern;
import spoon.reflect.code.CtCatch;
import spoon.reflect.code.CtCatchVariable;
import spoon.reflect.code.CtCodeSnippetExpression;
import spoon.reflect.code.CtCodeSnippetStatement;
import spoon.reflect.code.CtComment;
import spoon.reflect.code.CtConditional;
import spoon.reflect.code.CtConstructorCall;
import spoon.reflect.code.CtContinue;
import spoon.reflect.code.CtDo;
import spoon.reflect.code.CtExecutableReferenceExpression;
import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtFieldRead;
import spoon.reflect.code.CtFieldWrite;
import spoon.reflect.code.CtFor;
import spoon.reflect.code.CtForEach;
import spoon.reflect.code.CtIf;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.code.CtJavaDoc;
import spoon.reflect.code.CtJavaDocTag;
import spoon.reflect.code.CtLambda;
import spoon.reflect.code.CtLiteral;
import spoon.reflect.code.CtLocalVariable;
import spoon.reflect.code.CtNewArray;
import spoon.reflect.code.CtNewClass;
import spoon.reflect.code.CtOperatorAssignment;
import spoon.reflect.code.CtReturn;
import spoon.reflect.code.CtStatementList;
import spoon.reflect.code.CtSuperAccess;
import spoon.reflect.code.CtSwitch;
import spoon.reflect.code.CtSwitchExpression;
import spoon.reflect.code.CtSynchronized;
import spoon.reflect.code.CtTextBlock;
import spoon.reflect.code.CtThisAccess;
import spoon.reflect.code.CtThrow;
import spoon.reflect.code.CtTry;
import spoon.reflect.code.CtTryWithResource;
import spoon.reflect.code.CtTypeAccess;
import spoon.reflect.code.CtTypePattern;
import spoon.reflect.code.CtUnaryOperator;
import spoon.reflect.code.CtVariableRead;
import spoon.reflect.code.CtVariableWrite;
import spoon.reflect.code.CtWhile;
import spoon.reflect.code.CtYieldStatement;
import spoon.reflect.cu.CompilationUnit;
import spoon.reflect.cu.SourcePosition;
import spoon.reflect.cu.position.BodyHolderSourcePosition;
import spoon.reflect.cu.position.CompoundSourcePosition;
import spoon.reflect.cu.position.DeclarationSourcePosition;
import spoon.reflect.declaration.CtAnnotation;
import spoon.reflect.declaration.CtAnnotationMethod;
import spoon.reflect.declaration.CtAnnotationType;
import spoon.reflect.declaration.CtAnonymousExecutable;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtConstructor;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtEnum;
import spoon.reflect.declaration.CtEnumValue;
import spoon.reflect.declaration.CtField;
import spoon.reflect.declaration.CtInterface;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtModule;
import spoon.reflect.declaration.CtPackageExport;
import spoon.reflect.declaration.CtProvidedService;
import spoon.reflect.declaration.CtRecord;
import spoon.reflect.declaration.CtRecordComponent;
import spoon.reflect.declaration.CtPackage;
import spoon.reflect.declaration.CtPackageDeclaration;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.declaration.CtTypeParameter;
import spoon.reflect.declaration.CtUsedService;
import spoon.reflect.reference.CtArrayTypeReference;
import spoon.reflect.reference.CtCatchVariableReference;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtFieldReference;
import spoon.reflect.declaration.CtImport;
import spoon.reflect.reference.CtIntersectionTypeReference;
import spoon.reflect.reference.CtLocalVariableReference;
import spoon.reflect.reference.CtModuleReference;
import spoon.reflect.declaration.CtModuleRequirement;
import spoon.reflect.reference.CtPackageReference;
import spoon.reflect.reference.CtParameterReference;
import spoon.reflect.reference.CtTypeMemberWildcardImportReference;
import spoon.reflect.reference.CtTypeParameterReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.reference.CtUnboundVariableReference;
import spoon.reflect.reference.CtWildcardReference;
/**
* This interface defines the core creation methods for the meta-model (to be
* implemented so that Spoon can manipulate other meta-model implementations).
* <p>
* <b>Important</b>: a required post-condition for all the created elements is
* that the factory (see {@link spoon.processing.FactoryAccessor#getFactory()})
* is correctly initialized with the main factory returned by
* {@link #getMainFactory()}, which cannot be null.
*/
public interface CoreFactory {
/**
* Recursively clones a given element of the metamodel and all its child
* elements.
*
* @param <T> the element's type
* @param element the element
* @return a clone of <code>element</code>
* @see spoon.reflect.declaration.CtElement#clone()
*/
<T extends CtElement> T clone(T element);
/**
* Creates an annotation.
*/
<A extends Annotation> CtAnnotation<A> createAnnotation();
/**
* Creates an annotation type.
*/
<T extends Annotation> CtAnnotationType<T> createAnnotationType();
/**
* Creates an anonymous executable.
*/
CtAnonymousExecutable createAnonymousExecutable();
/**
* Creates an array read access expression.
*/
<T> CtArrayRead<T> createArrayRead();
/**
* Creates an array write access expression.
*/
<T> CtArrayWrite<T> createArrayWrite();
/**
* Creates an array type reference.
*/
<T> CtArrayTypeReference<T> createArrayTypeReference();
/**
* Creates an <code>assert</code> statement.
*/
<T> CtAssert<T> createAssert();
/**
* Creates an assignment expression.
*/
<T, A extends T> CtAssignment<T, A> createAssignment();
/**
* Creates a binary operator.
*/
<T> CtBinaryOperator<T> createBinaryOperator();
/**
* Creates a block.
*/
<R> CtBlock<R> createBlock();
/**
* Creates a <code>break</code> statement.
*/
CtBreak createBreak();
/**
* Creates a <code>case</code> clause.
*/
<S> CtCase<S> createCase();
/**
* Creates a <code>catch</code> clause.
*/
CtCatch createCatch();
/**
* Creates a class.
*/
<T> CtClass<T> createClass();
/**
* Creates a type parameter declaration.
*/
CtTypeParameter createTypeParameter();
/**
* Creates a conditional expression (<code>boolExpr?ifTrue:ifFalse</code>).
*/
<T> CtConditional<T> createConditional();
/**
* Creates a constructor.
*/
<T> CtConstructor<T> createConstructor();
/**
* Creates an invisible array constructor.
*/
<T> CtConstructor<T> createInvisibleArrayConstructor();
/**
* Creates a <code>continue</code> statement.
*/
CtContinue createContinue();
/**
* Creates a <code>do</code> loop.
*/
CtDo createDo();
/**
* Creates an enum.
*/
<T extends Enum<?>> CtEnum<T> createEnum();
/**
* Creates an executable reference.
*/
<T> CtExecutableReference<T> createExecutableReference();
/**
* Creates a field.
*/
<T> CtField<T> createField();
/**
* Creates an enum value.
*/
<T> CtEnumValue<T> createEnumValue();
/**
* Creates a field read access.
*/
<T> CtFieldRead<T> createFieldRead();
/**
* Creates a field write access.
*/
<T> CtFieldWrite<T> createFieldWrite();
/**
* Creates an access expression to this.
*/
<T> CtThisAccess<T> createThisAccess();
/**
* Creates an access expression to super.
*/
<T> CtSuperAccess<T> createSuperAccess();
/**
* Creates a field reference.
*/
<T> CtFieldReference<T> createFieldReference();
/**
* Creates a <code>for</code> loop.
*/
CtFor createFor();
/**
* Creates a <code>foreach</code> loop.
*/
CtForEach createForEach();
/**
* Creates an <code>if</code> statement.
*/
CtIf createIf();
/**
* Creates an interface.
*/
<T> CtInterface<T> createInterface();
/**
* Creates an invocation expression.
*/
<T> CtInvocation<T> createInvocation();
/**
* Creates a literal expression.
*/
<T> CtLiteral<T> createLiteral();
/**
* Creates a local variable declaration statement.
*/
<T> CtLocalVariable<T> createLocalVariable();
/**
* Creates a local variable reference.
*/
<T> CtLocalVariableReference<T> createLocalVariableReference();
/**
* Creates a catch variable declaration statement.
*/
<T> CtCatchVariable<T> createCatchVariable();
/**
* Creates a catch variable reference.
*/
<T> CtCatchVariableReference<T> createCatchVariableReference();
/**
* Creates a method.
*/
<T> CtMethod<T> createMethod();
/**
* Creates an annotation method.
*/
<T> CtAnnotationMethod<T> createAnnotationMethod();
/**
* Creates a new array expression.
*/
<T> CtNewArray<T> createNewArray();
/**
* Creates a constructor call expression.
*
* Example to build "new Foo()":
* <pre>
* CtConstructorCall call = spoon.getFactory().Core().createConstructorCall();
* call.setType(spoon.getFactory().Core().createTypeReference().setSimpleName("Foo"));
* </pre>
*/
<T> CtConstructorCall<T> createConstructorCall();
/**
* Creates a new anonymous class expression.
*/
<T> CtNewClass<T> createNewClass();
/**
* Creates a new anonymous method expression.
*/
<T> CtLambda<T> createLambda();
/**
* Creates a new executable reference expression.
*/
<T, E extends CtExpression<?>> CtExecutableReferenceExpression<T, E> createExecutableReferenceExpression();
/**
* Creates a new operator assignment (like +=).
*/
<T, A extends T> CtOperatorAssignment<T, A> createOperatorAssignment();
/**
* Creates a package.
*/
CtPackage createPackage();
/**
* Creates a package reference.
*/
CtPackageReference createPackageReference();
/**
* Creates a parameter.
*/
<T> CtParameter<T> createParameter();
/**
* Creates a parameter reference.
*/
<T> CtParameterReference<T> createParameterReference();
/**
* Creates a <code>return</code> statement.
*/
<R> CtReturn<R> createReturn();
/**
* Creates a source position.
*/
SourcePosition createSourcePosition(
CompilationUnit compilationUnit,
int startSource, int end, int[] lineSeparatorPositions);
/** Creates a source position that points to the given compilation unit */
SourcePosition createPartialSourcePosition(CompilationUnit compilationUnit);
/**
* Creates a compound source position.
*/
CompoundSourcePosition createCompoundSourcePosition(
CompilationUnit compilationUnit,
int startSource, int end,
int declarationStart, int declarationEnd,
int[] lineSeparatorPositions);
/**
* Creates a declaration source position.
*/
DeclarationSourcePosition createDeclarationSourcePosition(
CompilationUnit compilationUnit,
int startSource, int end,
int modifierStart, int modifierEnd,
int declarationStart, int declarationEnd,
int[] lineSeparatorPositions);
/**
* Creates a body holder source position.
*/
BodyHolderSourcePosition createBodyHolderSourcePosition(
CompilationUnit compilationUnit,
int nameSource, int nameEnd,
int modifierStart, int modifierEnd,
int declarationStart, int declarationEnd,
int bodyStart, int bodyEnd, int[] lineSeparatorPositions);
/**
* Creates a statement list.
*/
<R> CtStatementList createStatementList();
/**
* Creates a <code>switch</code> statement.
*/
<S> CtSwitch<S> createSwitch();
/**
* Creates a <code>switch</code> expression.
*/
<T, S> CtSwitchExpression<T, S> createSwitchExpression();
/**
* Creates a <code>synchronized</code> statement.
*/
CtSynchronized createSynchronized();
/**
* Creates a <code>throw</code> statement.
*/
CtThrow createThrow();
/**
* Creates a <code>try</code> block.
*/
CtTry createTry();
/**
* Creates a <code>try</code> with resource block.
*/
CtTryWithResource createTryWithResource();
/**
* Creates a type parameter reference.
*/
CtTypeParameterReference createTypeParameterReference();
/**
* Creates a wildcard reference.
*/
CtWildcardReference createWildcardReference();
/**
* Creates an intersection type reference.
*/
<T> CtIntersectionTypeReference<T> createIntersectionTypeReference();
/**
* Creates a type reference.
*/
<T> CtTypeReference<T> createTypeReference();
/**
* Creates a type access expression.
*/
<T> CtTypeAccess<T> createTypeAccess();
/**
* Creates a unary operator expression.
*/
<T> CtUnaryOperator<T> createUnaryOperator();
/**
* Creates a variable read expression.
*/
<T> CtVariableRead<T> createVariableRead();
/**
* Creates a variable write expression.
*/
<T> CtVariableWrite<T> createVariableWrite();
/**
* Creates a <code>while</code> loop.
*/
CtWhile createWhile();
/**
* Creates a code snippet expression.
*/
<T> CtCodeSnippetExpression<T> createCodeSnippetExpression();
/**
* Creates a code snippet statement.
*/
CtCodeSnippetStatement createCodeSnippetStatement();
/**
* Creates a comment.
*/
CtComment createComment();
/**
* Creates a javadoc comment.
*/
CtJavaDoc createJavaDoc();
/**
* Creates a javadoc tag.
*/
CtJavaDocTag createJavaDocTag();
/**
* Creates an import.
*/
CtImport createImport();
/**
* Creates an unresolved import.
* CtUnresolvedImport stores the original content of the imort as a String in order to be able
* to restituate it when pretty printing.
*/
CtImport createUnresolvedImport();
/**
* Creates a package declaration.
*/
CtPackageDeclaration createPackageDeclaration();
/**
* Gets the main factory of that core factory (cannot be <code>null</code>).
*/
Factory getMainFactory();
/**
* Sets the main factory of that core factory.
*/
void setMainFactory(Factory mainFactory);
/**
* Creates a compilation unit.
*/
CompilationUnit createCompilationUnit();
/**
* Create an access to annotation value
*
* @return
*/
<T> CtAnnotationFieldAccess<T> createAnnotationFieldAccess();
/**
* Creates an unbound variable used in noclasspath.
*/
<T> CtUnboundVariableReference<T> createUnboundVariableReference();
/**
* Creates an instance of the concrete metamodel class given as parameter.
*
* This is in particular useful when one uses reflection.
*/
CtElement create(Class<? extends CtElement> klass);
/**
* Create a wildcard reference to a type member, used in a static import
*/
CtTypeMemberWildcardImportReference createTypeMemberWildcardImportReference();
/** Creates a Java 9 module */
CtModule createModule();
/** Creates a reference to a Java 9 module */
CtModuleReference createModuleReference();
/** Creates a "requires" directive for a Java 9 module file */
CtModuleRequirement createModuleRequirement();
/** Creates a "export" directive for a Java 9 module file */
CtPackageExport createPackageExport();
/** Creates a "provides" directive for a Java 9 module file */
CtProvidedService createProvidedService();
/** Creates a "uses" directive for a Java 9 module file */
CtUsedService createUsedService();
/**
* Creates a <code>yield</code> statement
* @return yieldStatement
*/
CtYieldStatement createYieldStatement();
/**
* Creates a TextBlock String Literal
*/
CtTextBlock createTextBlock();
/**
* Creates a Type Pattern
* @return a new Type Pattern instance.
*/
CtTypePattern createTypePattern();
/**
* Creates a record.
* @return the created record.
*/
CtRecord createRecord();
/**
* Creates a record component.
* @return the created record component.
*/
CtRecordComponent createRecordComponent();
/**
* Creates a case pattern.
* @return the created case pattern.
*/
CtCasePattern createCasePattern();
}