-
Notifications
You must be signed in to change notification settings - Fork 316
/
JvmModelGenerator.java
1709 lines (1606 loc) · 74.7 KB
/
JvmModelGenerator.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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2012, 2021, 2022 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.xbase.compiler;
import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Inject;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtend2.lib.StringConcatenationClient;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue;
import org.eclipse.xtext.common.types.JvmAnnotationReference;
import org.eclipse.xtext.common.types.JvmAnnotationType;
import org.eclipse.xtext.common.types.JvmAnnotationValue;
import org.eclipse.xtext.common.types.JvmBooleanAnnotationValue;
import org.eclipse.xtext.common.types.JvmByteAnnotationValue;
import org.eclipse.xtext.common.types.JvmCharAnnotationValue;
import org.eclipse.xtext.common.types.JvmConstructor;
import org.eclipse.xtext.common.types.JvmCustomAnnotationValue;
import org.eclipse.xtext.common.types.JvmDeclaredType;
import org.eclipse.xtext.common.types.JvmDoubleAnnotationValue;
import org.eclipse.xtext.common.types.JvmEnumAnnotationValue;
import org.eclipse.xtext.common.types.JvmEnumerationLiteral;
import org.eclipse.xtext.common.types.JvmEnumerationType;
import org.eclipse.xtext.common.types.JvmExecutable;
import org.eclipse.xtext.common.types.JvmFeature;
import org.eclipse.xtext.common.types.JvmField;
import org.eclipse.xtext.common.types.JvmFloatAnnotationValue;
import org.eclipse.xtext.common.types.JvmFormalParameter;
import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference;
import org.eclipse.xtext.common.types.JvmGenericType;
import org.eclipse.xtext.common.types.JvmIdentifiableElement;
import org.eclipse.xtext.common.types.JvmIntAnnotationValue;
import org.eclipse.xtext.common.types.JvmLongAnnotationValue;
import org.eclipse.xtext.common.types.JvmMember;
import org.eclipse.xtext.common.types.JvmOperation;
import org.eclipse.xtext.common.types.JvmShortAnnotationValue;
import org.eclipse.xtext.common.types.JvmStringAnnotationValue;
import org.eclipse.xtext.common.types.JvmType;
import org.eclipse.xtext.common.types.JvmTypeAnnotationValue;
import org.eclipse.xtext.common.types.JvmTypeParameter;
import org.eclipse.xtext.common.types.JvmTypeParameterDeclarator;
import org.eclipse.xtext.common.types.JvmTypeReference;
import org.eclipse.xtext.common.types.JvmUpperBound;
import org.eclipse.xtext.common.types.JvmVisibility;
import org.eclipse.xtext.common.types.TypesPackage;
import org.eclipse.xtext.common.types.util.TypeReferences;
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
import org.eclipse.xtext.documentation.IEObjectDocumentationProviderExtension;
import org.eclipse.xtext.documentation.IFileHeaderProvider;
import org.eclipse.xtext.documentation.IJavaDocTypeReferenceProvider;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.xtext.generator.trace.AbsoluteURI;
import org.eclipse.xtext.generator.trace.ITraceURIConverter;
import org.eclipse.xtext.generator.trace.LocationData;
import org.eclipse.xtext.generator.trace.SourceRelativeURI;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.ILocationInFileProvider;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.IScopeProvider;
import org.eclipse.xtext.util.ITextRegionWithLineInformation;
import org.eclipse.xtext.util.JavaVersion;
import org.eclipse.xtext.util.ReplaceRegion;
import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.validation.Issue;
import org.eclipse.xtext.workspace.IProjectConfig;
import org.eclipse.xtext.xbase.XExpression;
import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable;
import org.eclipse.xtext.xbase.compiler.output.ImportingStringConcatenation;
import org.eclipse.xtext.xbase.compiler.output.SharedAppendableState;
import org.eclipse.xtext.xbase.compiler.output.TreeAppendable;
import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations;
import org.eclipse.xtext.xbase.jvmmodel.IJvmModelInferrer;
import org.eclipse.xtext.xbase.jvmmodel.ILogicalContainerProvider;
import org.eclipse.xtext.xbase.jvmmodel.JvmTypeExtensions;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IntegerRange;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure2;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner;
import org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner;
import org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices;
/**
* A generator implementation that processes the
* derived {@link IJvmModelInferrer JVM model}
* and produces the respective java code.
*/
@SuppressWarnings("all")
public class JvmModelGenerator implements IGenerator {
@Inject
@Extension
protected ILogicalContainerProvider _iLogicalContainerProvider;
@Inject
@Extension
protected TypeReferences _typeReferences;
@Inject
@Extension
protected TreeAppendableUtil _treeAppendableUtil;
@Inject
@Extension
protected JvmTypeExtensions _jvmTypeExtensions;
@Inject
@Extension
protected LoopExtensions _loopExtensions;
@Inject
@Extension
protected ErrorSafeExtensions _errorSafeExtensions;
@Inject
private CommonTypeComputationServices commonServices;
@Inject
private XbaseCompiler compiler;
@Inject
private ILocationInFileProvider locationProvider;
@Inject
private IEObjectDocumentationProvider documentationProvider;
@Inject
private IFileHeaderProvider fileHeaderProvider;
@Inject
private IJvmModelAssociations jvmModelAssociations;
@Inject
private JavaKeywords keywords;
@Inject
private IGeneratorConfigProvider generatorConfigProvider;
@Inject
private ITraceURIConverter converter;
@Inject
private IJavaDocTypeReferenceProvider javaDocTypeReferenceProvider;
@Inject
private IScopeProvider scopeProvider;
@Inject
private IQualifiedNameConverter qualifiedNameConverter;
@Override
public void doGenerate(final Resource input, final IFileSystemAccess fsa) {
EList<EObject> _contents = input.getContents();
for (final EObject obj : _contents) {
this.internalDoGenerate(obj, fsa);
}
}
protected void _internalDoGenerate(final EObject obj, final IFileSystemAccess fsa) {
}
protected void _internalDoGenerate(final JvmDeclaredType type, final IFileSystemAccess fsa) {
boolean _isDisabled = DisableCodeGenerationAdapter.isDisabled(type);
if (_isDisabled) {
return;
}
String _qualifiedName = type.getQualifiedName();
boolean _tripleNotEquals = (_qualifiedName != null);
if (_tripleNotEquals) {
String _replace = type.getQualifiedName().replace(".", "/");
String _plus = (_replace + ".java");
fsa.generateFile(_plus, this.generateType(type, this.generatorConfigProvider.get(type)));
}
}
protected ImportManager createImportManager(final JvmDeclaredType type) {
return new ImportManager(true, type);
}
public CharSequence generateType(final JvmDeclaredType type, final GeneratorConfig config) {
final ImportManager importManager = this.createImportManager(type);
final TreeAppendable bodyAppendable = this.createAppendable(type, importManager, config);
bodyAppendable.openScope();
this.assignThisAndSuper(bodyAppendable, type, config);
this.generateBody(type, bodyAppendable, config);
bodyAppendable.closeScope();
final TreeAppendable importAppendable = this.createAppendable(type, importManager, config);
this.generateFileHeader(type, importAppendable, config);
String _packageName = type.getPackageName();
boolean _tripleNotEquals = (_packageName != null);
if (_tripleNotEquals) {
importAppendable.append("package ").append(type.getPackageName()).append(";");
importAppendable.newLine().newLine();
}
List<String> _imports = importManager.getImports();
for (final String i : _imports) {
importAppendable.append("import ").append(i).append(";").newLine();
}
boolean _isEmpty = importManager.getImports().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
importAppendable.newLine();
}
importAppendable.append(bodyAppendable);
return importAppendable;
}
protected ITreeAppendable _generateBody(final JvmGenericType it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
this.generateJavaDoc(it, appendable, config);
final ITreeAppendable childAppendable = appendable.trace(it);
this.generateAnnotations(it.getAnnotations(), childAppendable, true, config);
this.generateModifier(it, childAppendable, config);
boolean _isInterface = it.isInterface();
if (_isInterface) {
childAppendable.append("interface ");
} else {
childAppendable.append("class ");
}
this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
this.generateTypeParameterDeclaration(it, childAppendable, config);
boolean _isEmpty = it.getTypeParameters().isEmpty();
if (_isEmpty) {
childAppendable.append(" ");
}
this.generateExtendsClause(it, childAppendable, config);
this.generateMembersInBody(it, childAppendable, config);
ITreeAppendable _xifexpression = null;
if (((!it.isAnonymous()) && (!(it.eContainer() instanceof JvmType)))) {
_xifexpression = appendable.newLine();
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
public ITreeAppendable generateMembersInBody(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
appendable.append("{").increaseIndentation();
final Procedure1<LoopParams> _function = (LoopParams it_1) -> {
it_1.setSeparator(this.memberSeparator());
};
final Procedure1<JvmMember> _function_1 = (JvmMember it_1) -> {
final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
memberAppendable.openScope();
this.generateMember(it_1, memberAppendable, config);
memberAppendable.closeScope();
};
this._loopExtensions.<JvmMember>forEach(appendable, this.getMembersToBeCompiled(it), _function, _function_1);
_xblockexpression = appendable.decreaseIndentation().newLine().append("}");
}
return _xblockexpression;
}
/**
* @since 2.27
*/
protected Function1<? super ITreeAppendable, ? extends ITreeAppendable> memberSeparator() {
final Function1<ITreeAppendable, ITreeAppendable> _function = (ITreeAppendable it) -> {
return it.blankLine();
};
return _function;
}
/**
* @deprecated Additional annotations should be created in the JVM model.
*/
@Deprecated
public ITreeAppendable generateAnnotationsWithSyntheticSuppressWarnings(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
final Function1<JvmAnnotationReference, Boolean> _function = (JvmAnnotationReference it_1) -> {
JvmAnnotationType _annotation = it_1.getAnnotation();
String _identifier = null;
if (_annotation!=null) {
_identifier=_annotation.getIdentifier();
}
String _name = SuppressWarnings.class.getName();
return Boolean.valueOf((!Objects.equal(_identifier, _name)));
};
final Function1<JvmAnnotationReference, Boolean> noSuppressWarningsFilter = _function;
this.generateAnnotations(IterableExtensions.<JvmAnnotationReference>filter(it.getAnnotations(), noSuppressWarningsFilter), appendable, true, config);
ITreeAppendable _xifexpression = null;
EObject _eContainer = it.eContainer();
boolean _tripleEquals = (_eContainer == null);
if (_tripleEquals) {
_xifexpression = appendable.append("@SuppressWarnings(\"all\")").newLine();
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
protected ITreeAppendable _generateBody(final JvmEnumerationType it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
this.generateJavaDoc(it, appendable, config);
final ITreeAppendable childAppendable = appendable.trace(it);
this.generateAnnotations(it.getAnnotations(), childAppendable, true, config);
this.generateModifier(it, childAppendable, config);
childAppendable.append("enum ");
this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
childAppendable.append(" ");
this.generateExtendsClause(it, childAppendable, config);
childAppendable.append("{").increaseIndentation();
final Procedure1<LoopParams> _function = (LoopParams it_1) -> {
final Function1<ITreeAppendable, ITreeAppendable> _function_1 = (ITreeAppendable it_2) -> {
return it_2.append(",").blankLine();
};
it_1.setSeparator(_function_1);
it_1.setSuffix(";");
};
final Procedure1<JvmEnumerationLiteral> _function_1 = (JvmEnumerationLiteral it_1) -> {
this.generateEnumLiteral(it_1, childAppendable.trace(it_1), config);
};
this._loopExtensions.<JvmEnumerationLiteral>forEach(childAppendable, it.getLiterals(), _function, _function_1);
final Function1<JvmMember, Boolean> _function_2 = (JvmMember it_1) -> {
return Boolean.valueOf((!(it_1 instanceof JvmEnumerationLiteral)));
};
final Procedure1<LoopParams> _function_3 = (LoopParams it_1) -> {
it_1.setSeparator(this.memberSeparator());
};
final Procedure1<JvmMember> _function_4 = (JvmMember it_1) -> {
this.generateMember(it_1, childAppendable.trace(it_1), config);
};
this._loopExtensions.<JvmMember>forEach(childAppendable, IterableExtensions.<JvmMember>filter(this.getMembersToBeCompiled(it), _function_2), _function_3, _function_4);
childAppendable.decreaseIndentation().newLine().append("}");
ITreeAppendable _xifexpression = null;
EObject _eContainer = it.eContainer();
boolean _not = (!(_eContainer instanceof JvmType));
if (_not) {
_xifexpression = appendable.newLine();
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
public void generateEnumLiteral(final JvmEnumerationLiteral it, final ITreeAppendable appendable, final GeneratorConfig config) {
appendable.newLine();
this.generateJavaDoc(it, appendable, config);
this.generateAnnotations(it.getAnnotations(), appendable, true, config);
appendable.append(this.makeJavaIdentifier(it.getSimpleName()));
}
protected ITreeAppendable _generateBody(final JvmAnnotationType it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
this.generateJavaDoc(it, appendable, config);
final ITreeAppendable childAppendable = appendable.trace(it);
this.generateAnnotations(it.getAnnotations(), childAppendable, true, config);
this.generateModifier(it, childAppendable, config);
childAppendable.append("@interface ");
this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
childAppendable.append(" {");
Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(this.getMembersToBeCompiled(it), JvmDeclaredType.class);
for (final JvmDeclaredType innerType : _filter) {
{
final ITreeAppendable innerTypeAppendable = childAppendable.trace(innerType);
innerTypeAppendable.increaseIndentation();
this.generateMember(innerType, innerTypeAppendable, config);
innerTypeAppendable.decreaseIndentation();
}
}
Iterable<JvmOperation> _filter_1 = Iterables.<JvmOperation>filter(this.getMembersToBeCompiled(it), JvmOperation.class);
for (final JvmOperation operation : _filter_1) {
this.generateAnnotationMethod(operation, childAppendable, config);
}
childAppendable.newLine().append("}");
ITreeAppendable _xifexpression = null;
EObject _eContainer = it.eContainer();
boolean _not = (!(_eContainer instanceof JvmType));
if (_not) {
_xifexpression = appendable.newLine();
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
public void generateAnnotationMethod(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) {
appendable.increaseIndentation().newLine();
appendable.openScope();
this.generateJavaDoc(it, appendable, config);
final ITreeAppendable tracedAppendable = appendable.trace(it);
this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config);
this.generateModifier(it, tracedAppendable, config);
this._errorSafeExtensions.serializeSafely(it.getReturnType(), "Object", tracedAppendable);
tracedAppendable.append(" ");
this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
tracedAppendable.append("()");
this.generateDefaultExpression(it, tracedAppendable, config);
tracedAppendable.append(";");
appendable.decreaseIndentation();
appendable.closeScope();
}
public void generateDefaultExpression(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) {
Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(it);
boolean _tripleNotEquals = (_compilationStrategy != null);
if (_tripleNotEquals) {
appendable.append(" default ");
appendable.increaseIndentation();
this._jvmTypeExtensions.getCompilationStrategy(it).apply(appendable);
appendable.decreaseIndentation();
} else {
StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(it);
boolean _tripleNotEquals_1 = (_compilationTemplate != null);
if (_tripleNotEquals_1) {
appendable.append(" default ").increaseIndentation();
this.appendCompilationTemplate(appendable, it);
appendable.decreaseIndentation();
} else {
boolean _isGenerateExpressions = config.isGenerateExpressions();
if (_isGenerateExpressions) {
final XExpression body = this._iLogicalContainerProvider.getAssociatedExpression(it);
if ((body != null)) {
boolean _hasErrors = this._errorSafeExtensions.hasErrors(body);
if (_hasErrors) {
appendable.append("/* skipped default expression with errors */");
} else {
appendable.append(" default ");
this.compiler.compileAsJavaExpression(body, appendable, it.getReturnType());
}
} else {
JvmAnnotationValue _defaultValue = it.getDefaultValue();
boolean _tripleNotEquals_2 = (_defaultValue != null);
if (_tripleNotEquals_2) {
boolean _hasErrors_1 = this._errorSafeExtensions.hasErrors(it.getDefaultValue());
if (_hasErrors_1) {
appendable.append("/* skipped default expression with errors */");
} else {
appendable.append(" default ");
this.toJavaLiteral(it.getDefaultValue(), appendable, config);
}
}
}
}
}
}
}
/**
* @since 2.16
*/
protected void appendCompilationTemplate(final ITreeAppendable appendable, final JvmIdentifiableElement it) {
boolean _matched = false;
if (appendable instanceof TreeAppendable) {
_matched=true;
SharedAppendableState _state = ((TreeAppendable)appendable).getState();
StandardTypeReferenceOwner _standardTypeReferenceOwner = new StandardTypeReferenceOwner(this.commonServices, it);
final ImportingStringConcatenation target = this.createImportingStringConcatenation(_state, _standardTypeReferenceOwner);
target.append(this._jvmTypeExtensions.getCompilationTemplate(it));
((TreeAppendable)appendable).append(target);
}
if (!_matched) {
String _name = appendable.getClass().getName();
String _plus = ("unexpected appendable: " + _name);
throw new IllegalStateException(_plus);
}
}
protected ImportingStringConcatenation createImportingStringConcatenation(final SharedAppendableState state, final ITypeReferenceOwner owner) {
return new ImportingStringConcatenation(state, owner);
}
protected ITreeAppendable _generateModifier(final JvmGenericType it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
this.generateVisibilityModifier(it, appendable);
boolean _isInterface = it.isInterface();
boolean _not = (!_isInterface);
if (_not) {
if ((it.isStatic() && (!this.isDeclaredWithinInterface(it)))) {
appendable.append("static ");
}
boolean _isAbstract = it.isAbstract();
if (_isAbstract) {
appendable.append("abstract ");
}
}
boolean _isFinal = it.isFinal();
if (_isFinal) {
appendable.append("final ");
}
ITreeAppendable _xifexpression = null;
boolean _isStrictFloatingPoint = it.isStrictFloatingPoint();
if (_isStrictFloatingPoint) {
_xifexpression = appendable.append("strictfp ");
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
private boolean isDeclaredWithinInterface(final JvmMember it) {
return ((it.getDeclaringType() instanceof JvmGenericType) && ((JvmGenericType) it.getDeclaringType()).isInterface());
}
protected ITreeAppendable _generateModifier(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
return this.generateVisibilityModifier(it, appendable);
}
protected ITreeAppendable _generateModifier(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
this.generateVisibilityModifier(it, appendable);
boolean _isStatic = it.isStatic();
if (_isStatic) {
appendable.append("static ");
}
boolean _isFinal = it.isFinal();
if (_isFinal) {
appendable.append("final ");
}
boolean _isTransient = it.isTransient();
if (_isTransient) {
appendable.append("transient ");
}
ITreeAppendable _xifexpression = null;
boolean _isVolatile = it.isVolatile();
if (_isVolatile) {
_xifexpression = appendable.append("volatile ");
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
protected ITreeAppendable _generateModifier(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
this.generateVisibilityModifier(it, appendable);
if ((it.isAbstract() && (!this.isDeclaredWithinInterface(it)))) {
appendable.append("abstract ");
}
boolean _isStatic = it.isStatic();
if (_isStatic) {
appendable.append("static ");
}
if (((((!it.isAbstract()) && (!it.isStatic())) && config.getJavaSourceVersion().isAtLeast(JavaVersion.JAVA8)) && this.isDeclaredWithinInterface(it))) {
appendable.append("default ");
}
boolean _isFinal = it.isFinal();
if (_isFinal) {
appendable.append("final ");
}
boolean _isSynchronized = it.isSynchronized();
if (_isSynchronized) {
appendable.append("synchronized ");
}
boolean _isStrictFloatingPoint = it.isStrictFloatingPoint();
if (_isStrictFloatingPoint) {
appendable.append("strictfp ");
}
ITreeAppendable _xifexpression = null;
boolean _isNative = it.isNative();
if (_isNative) {
_xifexpression = appendable.append("native ");
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
public ITreeAppendable generateVisibilityModifier(final JvmMember it, final ITreeAppendable result) {
return result.append(this.javaName(it.getVisibility()));
}
protected ITreeAppendable _generateModifier(final JvmConstructor it, final ITreeAppendable appendable, final GeneratorConfig config) {
return this.generateVisibilityModifier(it, appendable);
}
/**
* Returns the visibility modifier and a space as suffix if not empty
*/
public String javaName(final JvmVisibility visibility) {
if ((visibility != null)) {
String _switchResult = null;
if (visibility != null) {
switch (visibility) {
case PRIVATE:
_switchResult = "private ";
break;
case PUBLIC:
_switchResult = "public ";
break;
case PROTECTED:
_switchResult = "protected ";
break;
case DEFAULT:
_switchResult = "";
break;
default:
break;
}
}
return _switchResult;
} else {
return "";
}
}
public void generateExtendsClause(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
String _switchResult = null;
boolean _matched = false;
if (it instanceof JvmAnnotationType) {
_matched=true;
_switchResult = "java.lang.Annotation";
}
if (!_matched) {
if (it instanceof JvmEnumerationType) {
_matched=true;
String _identifier = ((JvmEnumerationType)it).getIdentifier();
String _plus = ("java.lang.Enum<" + _identifier);
_switchResult = (_plus + ">");
}
}
if (!_matched) {
_switchResult = "java.lang.Object";
}
final String implicitSuperType = _switchResult;
if (((it instanceof JvmAnnotationType) || ((it instanceof JvmGenericType) && ((JvmGenericType) it).isInterface()))) {
final Function1<JvmTypeReference, Boolean> _function = (JvmTypeReference typeRef) -> {
String _identifier = typeRef.getIdentifier();
return Boolean.valueOf((!Objects.equal(_identifier, implicitSuperType)));
};
final Iterable<JvmTypeReference> withoutObject = IterableExtensions.<JvmTypeReference>filter(it.getSuperTypes(), _function);
final Procedure1<LoopParams> _function_1 = (LoopParams it_1) -> {
it_1.setPrefix("extends ");
it_1.setSeparator(", ");
it_1.setSuffix(" ");
};
final Procedure2<JvmTypeReference, ITreeAppendable> _function_2 = (JvmTypeReference it_1, ITreeAppendable app) -> {
this._errorSafeExtensions.serializeSafely(it_1, app);
};
this._errorSafeExtensions.<JvmTypeReference>forEachSafely(appendable, withoutObject, _function_1, _function_2);
} else {
final Function1<JvmTypeReference, Boolean> _function_3 = (JvmTypeReference typeRef) -> {
String _identifier = typeRef.getIdentifier();
return Boolean.valueOf((!Objects.equal(_identifier, implicitSuperType)));
};
final Iterable<JvmTypeReference> withoutObject_1 = IterableExtensions.<JvmTypeReference>filter(it.getSuperTypes(), _function_3);
final Function1<JvmTypeReference, Boolean> _function_4 = (JvmTypeReference typeRef) -> {
return Boolean.valueOf(((typeRef.getType() instanceof JvmGenericType) && (!((JvmGenericType) typeRef.getType()).isInterface())));
};
final JvmTypeReference superClazz = IterableExtensions.<JvmTypeReference>head(IterableExtensions.<JvmTypeReference>filter(withoutObject_1, _function_4));
final Function1<JvmTypeReference, Boolean> _function_5 = (JvmTypeReference typeRef) -> {
return Boolean.valueOf((!Objects.equal(typeRef, superClazz)));
};
final Iterable<JvmTypeReference> superInterfaces = IterableExtensions.<JvmTypeReference>filter(withoutObject_1, _function_5);
if ((superClazz != null)) {
final boolean hasErrors = this._errorSafeExtensions.hasErrors(superClazz);
if (hasErrors) {
appendable.append("/* ");
}
try {
appendable.append("extends ");
this._errorSafeExtensions.serializeSafely(superClazz, appendable);
appendable.append(" ");
} catch (final Throwable _t) {
if (_t instanceof Exception) {
} else {
throw Exceptions.sneakyThrow(_t);
}
}
if (hasErrors) {
appendable.append(" */");
}
}
final Procedure1<LoopParams> _function_6 = (LoopParams it_1) -> {
it_1.setPrefix("implements ");
it_1.setSeparator(", ");
it_1.setSuffix(" ");
};
final Procedure2<JvmTypeReference, ITreeAppendable> _function_7 = (JvmTypeReference it_1, ITreeAppendable app) -> {
this._errorSafeExtensions.serializeSafely(it_1, app);
};
this._errorSafeExtensions.<JvmTypeReference>forEachSafely(appendable, superInterfaces, _function_6, _function_7);
}
}
protected ITreeAppendable _generateMember(final JvmMember it, final ITreeAppendable appendable, final GeneratorConfig config) {
Class<? extends JvmMember> _class = null;
if (it!=null) {
_class=it.getClass();
}
String _name = null;
if (_class!=null) {
_name=_class.getName();
}
String _plus = ("generateMember not implemented for elements of type " + _name);
throw new UnsupportedOperationException(_plus);
}
protected ITreeAppendable _generateMember(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
appendable.newLine();
appendable.openScope();
this.assignThisAndSuper(appendable, it, config);
ITreeAppendable _xtrycatchfinallyexpression = null;
try {
_xtrycatchfinallyexpression = this.generateBody(it, appendable, config);
} finally {
appendable.closeScope();
}
_xblockexpression = _xtrycatchfinallyexpression;
}
return _xblockexpression;
}
protected ITreeAppendable _generateMember(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
appendable.newLine();
this.generateJavaDoc(it, appendable, config);
final ITreeAppendable tracedAppendable = appendable.trace(it);
this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config);
this.generateModifier(it, tracedAppendable, config);
this._errorSafeExtensions.serializeSafely(it.getType(), "Object", tracedAppendable);
tracedAppendable.append(" ");
final String name = tracedAppendable.declareVariable(it, this.makeJavaIdentifier(it.getSimpleName()));
this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(name);
this.generateInitialization(it, tracedAppendable, config);
_xblockexpression = tracedAppendable.append(";");
}
return _xblockexpression;
}
protected ITreeAppendable _generateMember(final JvmOperation it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
appendable.newLine();
appendable.openScope();
this.generateJavaDoc(it, appendable, config);
final ITreeAppendable tracedAppendable = appendable.trace(it);
this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config);
this.generateModifier(it, tracedAppendable, config);
this.generateTypeParameterDeclaration(it, tracedAppendable, config);
JvmTypeReference _returnType = it.getReturnType();
boolean _tripleEquals = (_returnType == null);
if (_tripleEquals) {
tracedAppendable.append("void");
} else {
this._errorSafeExtensions.serializeSafely(it.getReturnType(), "Object", tracedAppendable);
}
tracedAppendable.append(" ");
this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
tracedAppendable.append("(");
this.generateParameters(it, tracedAppendable, config);
tracedAppendable.append(")");
this.generateThrowsClause(it, tracedAppendable, config);
if ((it.isAbstract() || (!this.hasBody(it)))) {
tracedAppendable.append(";");
} else {
tracedAppendable.append(" ");
this.generateExecutableBody(it, tracedAppendable, config);
}
appendable.closeScope();
_xblockexpression = appendable;
}
return _xblockexpression;
}
protected ITreeAppendable _generateMember(final JvmConstructor it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xblockexpression = null;
{
appendable.newLine();
appendable.openScope();
this.generateJavaDoc(it, appendable, config);
final ITreeAppendable tracedAppendable = appendable.trace(it);
this.generateAnnotations(it.getAnnotations(), tracedAppendable, true, config);
this.generateModifier(it, tracedAppendable, config);
this.generateTypeParameterDeclaration(it, tracedAppendable, config);
this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
tracedAppendable.append("(");
this.generateParameters(it, tracedAppendable, config);
tracedAppendable.append(")");
this.generateThrowsClause(it, tracedAppendable, config);
tracedAppendable.append(" ");
this.generateExecutableBody(it, tracedAppendable, config);
appendable.closeScope();
_xblockexpression = appendable;
}
return _xblockexpression;
}
public void generateInitialization(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) {
Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(it);
boolean _tripleNotEquals = (_compilationStrategy != null);
if (_tripleNotEquals) {
final Iterable<Issue> errors = this.getDirectErrorsOrLogicallyContainedErrors(it);
boolean _isEmpty = IterableExtensions.isEmpty(errors);
if (_isEmpty) {
appendable.append(" = ");
appendable.increaseIndentation();
this._jvmTypeExtensions.getCompilationStrategy(it).apply(appendable);
appendable.decreaseIndentation();
} else {
appendable.append(" /* Skipped initializer because of errors */");
}
} else {
StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(it);
boolean _tripleNotEquals_1 = (_compilationTemplate != null);
if (_tripleNotEquals_1) {
final Iterable<Issue> errors_1 = this.getDirectErrorsOrLogicallyContainedErrors(it);
boolean _isEmpty_1 = IterableExtensions.isEmpty(errors_1);
if (_isEmpty_1) {
appendable.append(" = ").increaseIndentation();
this.appendCompilationTemplate(appendable, it);
appendable.decreaseIndentation();
} else {
appendable.append(" /* Skipped initializer because of errors */");
}
} else {
final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(it);
if (((expression != null) && config.isGenerateExpressions())) {
boolean _hasErrors = this._errorSafeExtensions.hasErrors(expression);
if (_hasErrors) {
appendable.append(" /* Skipped initializer because of errors */");
} else {
appendable.append(" = ");
this.compiler.compileAsJavaExpression(expression, appendable, it.getType());
}
}
}
}
}
public void generateTypeParameterDeclaration(final JvmTypeParameterDeclarator it, final ITreeAppendable appendable, final GeneratorConfig config) {
final Procedure1<LoopParams> _function = (LoopParams it_1) -> {
it_1.setPrefix("<");
it_1.setSeparator(", ");
it_1.setSuffix("> ");
};
final Procedure1<JvmTypeParameter> _function_1 = (JvmTypeParameter it_1) -> {
this.generateTypeParameterDeclaration(it_1, appendable, config);
};
this._loopExtensions.<JvmTypeParameter>forEach(appendable, it.getTypeParameters(), _function, _function_1);
}
public void generateTypeParameterDeclaration(final JvmTypeParameter it, final ITreeAppendable appendable, final GeneratorConfig config) {
final ITreeAppendable tracedAppendable = appendable.trace(it);
this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(it.getName());
this.generateTypeParameterConstraints(it, tracedAppendable, config);
}
public void generateTypeParameterConstraints(final JvmTypeParameter it, final ITreeAppendable appendable, final GeneratorConfig config) {
final Iterable<JvmUpperBound> upperBounds = Iterables.<JvmUpperBound>filter(it.getConstraints(), JvmUpperBound.class);
final Procedure1<LoopParams> _function = (LoopParams it_1) -> {
it_1.setPrefix(" extends ");
it_1.setSeparator(" & ");
};
final Procedure2<JvmUpperBound, ITreeAppendable> _function_1 = (JvmUpperBound it_1, ITreeAppendable app) -> {
this._errorSafeExtensions.serializeSafely(it_1.getTypeReference(), app);
};
this._errorSafeExtensions.<JvmUpperBound>forEachSafely(appendable, upperBounds, _function, _function_1);
}
public void generateThrowsClause(final JvmExecutable it, final ITreeAppendable appendable, final GeneratorConfig config) {
final LinkedHashMap<JvmType, JvmTypeReference> toBeGenerated = CollectionLiterals.<JvmType, JvmTypeReference>newLinkedHashMap();
final Consumer<JvmTypeReference> _function = (JvmTypeReference it_1) -> {
boolean _containsKey = toBeGenerated.containsKey(it_1.getType());
boolean _not = (!_containsKey);
if (_not) {
toBeGenerated.put(it_1.getType(), it_1);
}
};
it.getExceptions().forEach(_function);
final Procedure1<LoopParams> _function_1 = (LoopParams it_1) -> {
it_1.setPrefix(" throws ");
it_1.setSeparator(", ");
};
final Procedure2<JvmTypeReference, ITreeAppendable> _function_2 = (JvmTypeReference it_1, ITreeAppendable app) -> {
app.trace(it_1).append(it_1.getType());
};
this._errorSafeExtensions.<JvmTypeReference>forEachSafely(appendable, toBeGenerated.values(), _function_1, _function_2);
}
public void generateParameters(final JvmExecutable it, final ITreeAppendable appendable, final GeneratorConfig config) {
boolean _isEmpty = it.getParameters().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
int _size = it.getParameters().size();
int _minus = (_size - 1);
IntegerRange _upTo = new IntegerRange(0, _minus);
for (final Integer i : _upTo) {
{
int _size_1 = it.getParameters().size();
final boolean last = (((i).intValue() + 1) == _size_1);
final JvmFormalParameter p = it.getParameters().get((i).intValue());
this.generateParameter(p, appendable, (last && it.isVarArgs()), config);
if ((!last)) {
appendable.append(", ");
}
}
}
}
}
public void generateParameter(final JvmFormalParameter it, final ITreeAppendable appendable, final boolean vararg, final GeneratorConfig config) {
final ITreeAppendable tracedAppendable = appendable.trace(it);
this.generateAnnotations(it.getAnnotations(), tracedAppendable, false, config);
tracedAppendable.append("final ");
if (vararg) {
JvmTypeReference _parameterType = it.getParameterType();
boolean _not = (!(_parameterType instanceof JvmGenericArrayTypeReference));
if (_not) {
tracedAppendable.append("/* Internal Error: Parameter was vararg but not an array type. */");
} else {
JvmTypeReference _parameterType_1 = it.getParameterType();
this._errorSafeExtensions.serializeSafely(((JvmGenericArrayTypeReference) _parameterType_1).getComponentType(), "Object", tracedAppendable);
}
tracedAppendable.append("...");
} else {
this._errorSafeExtensions.serializeSafely(it.getParameterType(), "Object", tracedAppendable);
}
tracedAppendable.append(" ");
final String name = tracedAppendable.declareVariable(it, this.makeJavaIdentifier(it.getSimpleName()));
this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(name);
}
public boolean hasBody(final JvmExecutable it) {
return (((this._jvmTypeExtensions.getCompilationTemplate(it) != null) || (this._jvmTypeExtensions.getCompilationStrategy(it) != null)) || (this._iLogicalContainerProvider.getAssociatedExpression(it) != null));
}
/**
* Returns the errors that are produced for elements that are directly contained
* in this feature (e.g. unresolved type proxies) or that are associated with
* the expression that may be logically contained in the given feature.
*/
private Iterable<Issue> getDirectErrorsOrLogicallyContainedErrors(final JvmFeature feature) {
Iterable<Issue> errors = this._errorSafeExtensions.getErrors(feature);
boolean _isEmpty = IterableExtensions.isEmpty(errors);
if (_isEmpty) {
final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(feature);
if ((expression != null)) {
errors = this._errorSafeExtensions.getErrors(expression);
}
}
return errors;
}
public void generateExecutableBody(final JvmExecutable op, final ITreeAppendable appendable, final GeneratorConfig config) {
Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(op);
boolean _tripleNotEquals = (_compilationStrategy != null);
if (_tripleNotEquals) {
Iterable<Issue> errors = this.getDirectErrorsOrLogicallyContainedErrors(op);
boolean _isEmpty = IterableExtensions.isEmpty(errors);
if (_isEmpty) {
appendable.increaseIndentation().append("{").newLine();
this._jvmTypeExtensions.getCompilationStrategy(op).apply(appendable);
appendable.decreaseIndentation().newLine().append("}");
} else {
this.generateBodyWithIssues(op, appendable, errors);
}
} else {
StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(op);
boolean _tripleNotEquals_1 = (_compilationTemplate != null);
if (_tripleNotEquals_1) {
final Iterable<Issue> errors_1 = this.getDirectErrorsOrLogicallyContainedErrors(op);
boolean _isEmpty_1 = IterableExtensions.isEmpty(errors_1);
if (_isEmpty_1) {
appendable.increaseIndentation().append("{").newLine();
this.appendCompilationTemplate(appendable, op);
appendable.decreaseIndentation().newLine().append("}");
} else {
this.generateBodyWithIssues(op, appendable, errors_1);