/
AbstractModelLoader.java
4391 lines (4020 loc) · 209 KB
/
AbstractModelLoader.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 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the authors tag. All rights reserved.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License version 2.
*
* This particular file is subject to the "Classpath" exception as provided in the
* LICENSE file that accompanied this code.
*
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License,
* along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package com.redhat.ceylon.compiler.loader;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.lang.model.type.TypeKind;
import com.redhat.ceylon.cmr.api.ArtifactResult;
import com.redhat.ceylon.cmr.api.JDKUtils;
import com.redhat.ceylon.common.Versions;
import com.redhat.ceylon.compiler.java.codegen.AbstractTransformer;
import com.redhat.ceylon.compiler.java.codegen.AnnotationArgument;
import com.redhat.ceylon.compiler.java.codegen.AnnotationConstructorParameter;
import com.redhat.ceylon.compiler.java.codegen.AnnotationFieldName;
import com.redhat.ceylon.compiler.java.codegen.AnnotationInvocation;
import com.redhat.ceylon.compiler.java.codegen.AnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.BooleanLiteralAnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.CharacterLiteralAnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.CollectionLiteralAnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.Decl;
import com.redhat.ceylon.compiler.java.codegen.DeclarationLiteralAnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.FloatLiteralAnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.IntegerLiteralAnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.InvocationAnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.LiteralAnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.Naming;
import com.redhat.ceylon.compiler.java.codegen.ObjectLiteralAnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.ParameterAnnotationTerm;
import com.redhat.ceylon.compiler.java.codegen.StringLiteralAnnotationTerm;
import com.redhat.ceylon.compiler.java.util.Timer;
import com.redhat.ceylon.compiler.java.util.Util;
import com.redhat.ceylon.compiler.loader.mirror.AccessibleMirror;
import com.redhat.ceylon.compiler.loader.mirror.AnnotatedMirror;
import com.redhat.ceylon.compiler.loader.mirror.AnnotationMirror;
import com.redhat.ceylon.compiler.loader.mirror.ClassMirror;
import com.redhat.ceylon.compiler.loader.mirror.FieldMirror;
import com.redhat.ceylon.compiler.loader.mirror.MethodMirror;
import com.redhat.ceylon.compiler.loader.mirror.PackageMirror;
import com.redhat.ceylon.compiler.loader.mirror.TypeMirror;
import com.redhat.ceylon.compiler.loader.mirror.TypeParameterMirror;
import com.redhat.ceylon.compiler.loader.mirror.VariableMirror;
import com.redhat.ceylon.compiler.loader.model.FieldValue;
import com.redhat.ceylon.compiler.loader.model.JavaBeanValue;
import com.redhat.ceylon.compiler.loader.model.JavaMethod;
import com.redhat.ceylon.compiler.loader.model.LazyClass;
import com.redhat.ceylon.compiler.loader.model.LazyClassAlias;
import com.redhat.ceylon.compiler.loader.model.LazyContainer;
import com.redhat.ceylon.compiler.loader.model.LazyElement;
import com.redhat.ceylon.compiler.loader.model.LazyInterface;
import com.redhat.ceylon.compiler.loader.model.LazyInterfaceAlias;
import com.redhat.ceylon.compiler.loader.model.LazyMethod;
import com.redhat.ceylon.compiler.loader.model.LazyModule;
import com.redhat.ceylon.compiler.loader.model.LazyPackage;
import com.redhat.ceylon.compiler.loader.model.LazyTypeAlias;
import com.redhat.ceylon.compiler.loader.model.LazyValue;
import com.redhat.ceylon.compiler.loader.model.LocalDeclarationContainer;
import com.redhat.ceylon.compiler.loader.model.SetterWithLocalDeclarations;
import com.redhat.ceylon.compiler.typechecker.analyzer.DeclarationVisitor;
import com.redhat.ceylon.compiler.typechecker.analyzer.ModuleManager;
import com.redhat.ceylon.compiler.typechecker.model.Annotation;
import com.redhat.ceylon.compiler.typechecker.model.Class;
import com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface;
import com.redhat.ceylon.compiler.typechecker.model.Declaration;
import com.redhat.ceylon.compiler.typechecker.model.Element;
import com.redhat.ceylon.compiler.typechecker.model.Functional;
import com.redhat.ceylon.compiler.typechecker.model.Interface;
import com.redhat.ceylon.compiler.typechecker.model.IntersectionType;
import com.redhat.ceylon.compiler.typechecker.model.Method;
import com.redhat.ceylon.compiler.typechecker.model.MethodOrValue;
import com.redhat.ceylon.compiler.typechecker.model.Module;
import com.redhat.ceylon.compiler.typechecker.model.ModuleImport;
import com.redhat.ceylon.compiler.typechecker.model.Modules;
import com.redhat.ceylon.compiler.typechecker.model.Package;
import com.redhat.ceylon.compiler.typechecker.model.Parameter;
import com.redhat.ceylon.compiler.typechecker.model.ParameterList;
import com.redhat.ceylon.compiler.typechecker.model.ProducedType;
import com.redhat.ceylon.compiler.typechecker.model.Scope;
import com.redhat.ceylon.compiler.typechecker.model.Setter;
import com.redhat.ceylon.compiler.typechecker.model.TypeAlias;
import com.redhat.ceylon.compiler.typechecker.model.TypeDeclaration;
import com.redhat.ceylon.compiler.typechecker.model.TypeParameter;
import com.redhat.ceylon.compiler.typechecker.model.TypedDeclaration;
import com.redhat.ceylon.compiler.typechecker.model.UnionType;
import com.redhat.ceylon.compiler.typechecker.model.Unit;
import com.redhat.ceylon.compiler.typechecker.model.UnknownType;
import com.redhat.ceylon.compiler.typechecker.model.Value;
/**
* Abstract class of a model loader that can load a model from a compiled Java representation,
* while being agnostic of the reflection API used to load the compiled Java representation.
*
* @author Stéphane Épardaud <stef@epardaud.fr>
*/
public abstract class AbstractModelLoader implements ModelCompleter, ModelLoader {
public static final String JAVA_BASE_MODULE_NAME = "java.base";
public static final String CEYLON_LANGUAGE = "ceylon.language";
public static final String CEYLON_LANGUAGE_MODEL = "ceylon.language.meta.model";
public static final String CEYLON_LANGUAGE_MODEL_DECLARATION = "ceylon.language.meta.declaration";
private static final String TIMER_MODEL_LOADER_CATEGORY = "model loader";
public static final String JDK_MODULE_VERSION = "7";
public static final String CEYLON_CEYLON_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Ceylon";
private static final String CEYLON_MODULE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Module";
private static final String CEYLON_PACKAGE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Package";
public static final String CEYLON_IGNORE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Ignore";
private static final String CEYLON_CLASS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Class";
public static final String CEYLON_NAME_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Name";
private static final String CEYLON_SEQUENCED_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Sequenced";
private static final String CEYLON_FUNCTIONAL_PARAMETER_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.FunctionalParameter";
private static final String CEYLON_DEFAULTED_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Defaulted";
private static final String CEYLON_SATISFIED_TYPES_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.SatisfiedTypes";
private static final String CEYLON_CASE_TYPES_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.CaseTypes";
private static final String CEYLON_TYPE_PARAMETERS = "com.redhat.ceylon.compiler.java.metadata.TypeParameters";
private static final String CEYLON_TYPE_INFO_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.TypeInfo";
public static final String CEYLON_ATTRIBUTE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Attribute";
public static final String CEYLON_SETTER_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Setter";
public static final String CEYLON_OBJECT_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Object";
public static final String CEYLON_METHOD_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Method";
public static final String CEYLON_CONTAINER_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Container";
public static final String CEYLON_LOCAL_CONTAINER_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.LocalContainer";
public static final String CEYLON_LOCAL_DECLARATION_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.LocalDeclaration";
public static final String CEYLON_LOCAL_DECLARATIONS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.LocalDeclarations";
private static final String CEYLON_MEMBERS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Members";
private static final String CEYLON_ANNOTATIONS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Annotations";
public static final String CEYLON_VALUETYPE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.ValueType";
public static final String CEYLON_ALIAS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Alias";
public static final String CEYLON_TYPE_ALIAS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.TypeAlias";
private static final String CEYLON_ANNOTATION_INSTANTIATION_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.AnnotationInstantiation";
private static final String CEYLON_ANNOTATION_INSTANTIATION_ARGUMENTS_MEMBER = "arguments";
private static final String CEYLON_ANNOTATION_INSTANTIATION_ANNOTATION_MEMBER = "primary";
private static final String CEYLON_ANNOTATION_INSTANTIATION_TREE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.AnnotationInstantiationTree";
private static final String CEYLON_STRING_VALUE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.StringValue";
private static final String CEYLON_STRING_EXPRS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.StringExprs";
private static final String CEYLON_BOOLEAN_VALUE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.BooleanValue";
private static final String CEYLON_BOOLEAN_EXPRS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.BooleanExprs";
private static final String CEYLON_INTEGER_VALUE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.IntegerValue";
private static final String CEYLON_INTEGER_EXPRS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.IntegerExprs";
private static final String CEYLON_CHARACTER_VALUE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.CharacterValue";
private static final String CEYLON_CHARACTER_EXPRS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.CharacterExprs";
private static final String CEYLON_FLOAT_VALUE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.FloatValue";
private static final String CEYLON_FLOAT_EXPRS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.FloatExprs";
private static final String CEYLON_OBJECT_VALUE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.ObjectValue";
private static final String CEYLON_OBJECT_EXPRS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.ObjectExprs";
private static final String CEYLON_DECLARATION_VALUE_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.DeclarationValue";
private static final String CEYLON_DECLARATION_EXPRS_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.DeclarationExprs";
private static final String CEYLON_TRANSIENT_ANNOTATION = "com.redhat.ceylon.compiler.java.metadata.Transient";
private static final String JAVA_DEPRECATED_ANNOTATION = "java.lang.Deprecated";
private static final String CEYLON_LANGUAGE_ABSTRACT_ANNOTATION = "ceylon.language.AbstractAnnotation$annotation$";
private static final String CEYLON_LANGUAGE_ACTUAL_ANNOTATION = "ceylon.language.ActualAnnotation$annotation$";
private static final String CEYLON_LANGUAGE_ANNOTATION_ANNOTATION = "ceylon.language.AnnotationAnnotation$annotation$";
private static final String CEYLON_LANGUAGE_DEFAULT_ANNOTATION = "ceylon.language.DefaultAnnotation$annotation$";
private static final String CEYLON_LANGUAGE_FORMAL_ANNOTATION = "ceylon.language.FormalAnnotation$annotation$";
private static final String CEYLON_LANGUAGE_LATE_ANNOTATION = "ceylon.language.LateAnnotation$annotation$";
// important that these are with ::
private static final String CEYLON_LANGUAGE_CALLABLE_TYPE_NAME = "ceylon.language::Callable";
private static final String CEYLON_LANGUAGE_TUPLE_TYPE_NAME = "ceylon.language::Tuple";
private static final String CEYLON_LANGUAGE_SEQUENTIAL_TYPE_NAME = "ceylon.language::Sequential";
private static final String CEYLON_LANGUAGE_SEQUENCE_TYPE_NAME = "ceylon.language::Sequence";
private static final String CEYLON_LANGUAGE_EMPTY_TYPE_NAME = "ceylon.language::Empty";
private static final TypeMirror OBJECT_TYPE = simpleCeylonObjectType("java.lang.Object");
private static final TypeMirror CEYLON_OBJECT_TYPE = simpleCeylonObjectType("ceylon.language.Object");
private static final TypeMirror CEYLON_BASIC_TYPE = simpleCeylonObjectType("ceylon.language.Basic");
private static final TypeMirror CEYLON_REIFIED_TYPE_TYPE = simpleCeylonObjectType("com.redhat.ceylon.compiler.java.runtime.model.ReifiedType");
private static final TypeMirror CEYLON_TYPE_DESCRIPTOR_TYPE = simpleCeylonObjectType("com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor");
private static final TypeMirror THROWABLE_TYPE = simpleCeylonObjectType("java.lang.Throwable");
private static final TypeMirror ERROR_TYPE = simpleCeylonObjectType("java.lang.Error");
private static final TypeMirror EXCEPTION_TYPE = simpleCeylonObjectType("java.lang.Exception");
private static final TypeMirror CEYLON_THROWABLE_TYPE = simpleCeylonObjectType("java.lang.Throwable");
private static final TypeMirror CEYLON_ERROR_TYPE = simpleCeylonObjectType("ceylon.language.Error");
private static final TypeMirror CEYLON_EXCEPTION_TYPE = simpleCeylonObjectType("ceylon.language.Exception");
private static final TypeMirror STRING_TYPE = simpleJDKObjectType("java.lang.String");
private static final TypeMirror CEYLON_STRING_TYPE = simpleCeylonObjectType("ceylon.language.String");
private static final TypeMirror PRIM_BOOLEAN_TYPE = simpleJDKObjectType("boolean");
private static final TypeMirror CEYLON_BOOLEAN_TYPE = simpleCeylonObjectType("ceylon.language.Boolean");
private static final TypeMirror PRIM_BYTE_TYPE = simpleJDKObjectType("byte");
private static final TypeMirror PRIM_SHORT_TYPE = simpleJDKObjectType("short");
private static final TypeMirror PRIM_INT_TYPE = simpleJDKObjectType("int");
private static final TypeMirror PRIM_LONG_TYPE = simpleJDKObjectType("long");
private static final TypeMirror CEYLON_INTEGER_TYPE = simpleCeylonObjectType("ceylon.language.Integer");
private static final TypeMirror PRIM_FLOAT_TYPE = simpleJDKObjectType("float");
private static final TypeMirror PRIM_DOUBLE_TYPE = simpleJDKObjectType("double");
private static final TypeMirror CEYLON_FLOAT_TYPE = simpleCeylonObjectType("ceylon.language.Float");
private static final TypeMirror PRIM_CHAR_TYPE = simpleJDKObjectType("char");
private static final TypeMirror CEYLON_CHARACTER_TYPE = simpleCeylonObjectType("ceylon.language.Character");
// this one has no "_" postfix because that's how we look it up
protected static final String JAVA_LANG_BYTE_ARRAY = "java.lang.ByteArray";
protected static final String JAVA_LANG_SHORT_ARRAY = "java.lang.ShortArray";
protected static final String JAVA_LANG_INT_ARRAY = "java.lang.IntArray";
protected static final String JAVA_LANG_LONG_ARRAY = "java.lang.LongArray";
protected static final String JAVA_LANG_FLOAT_ARRAY = "java.lang.FloatArray";
protected static final String JAVA_LANG_DOUBLE_ARRAY = "java.lang.DoubleArray";
protected static final String JAVA_LANG_CHAR_ARRAY = "java.lang.CharArray";
protected static final String JAVA_LANG_BOOLEAN_ARRAY = "java.lang.BooleanArray";
protected static final String JAVA_LANG_OBJECT_ARRAY = "java.lang.ObjectArray";
// this one has the "_" postfix because that's what we translate it to
private static final String CEYLON_BYTE_ARRAY = "com.redhat.ceylon.compiler.java.language.ByteArray";
private static final String CEYLON_SHORT_ARRAY = "com.redhat.ceylon.compiler.java.language.ShortArray";
private static final String CEYLON_INT_ARRAY = "com.redhat.ceylon.compiler.java.language.IntArray";
private static final String CEYLON_LONG_ARRAY = "com.redhat.ceylon.compiler.java.language.LongArray";
private static final String CEYLON_FLOAT_ARRAY = "com.redhat.ceylon.compiler.java.language.FloatArray";
private static final String CEYLON_DOUBLE_ARRAY = "com.redhat.ceylon.compiler.java.language.DoubleArray";
private static final String CEYLON_CHAR_ARRAY = "com.redhat.ceylon.compiler.java.language.CharArray";
private static final String CEYLON_BOOLEAN_ARRAY = "com.redhat.ceylon.compiler.java.language.BooleanArray";
private static final String CEYLON_OBJECT_ARRAY = "com.redhat.ceylon.compiler.java.language.ObjectArray";
private static final TypeMirror JAVA_BYTE_ARRAY_TYPE = simpleJDKObjectType("java.lang.ByteArray");
private static final TypeMirror JAVA_SHORT_ARRAY_TYPE = simpleJDKObjectType("java.lang.ShortArray");
private static final TypeMirror JAVA_INT_ARRAY_TYPE = simpleJDKObjectType("java.lang.IntArray");
private static final TypeMirror JAVA_LONG_ARRAY_TYPE = simpleJDKObjectType("java.lang.LongArray");
private static final TypeMirror JAVA_FLOAT_ARRAY_TYPE = simpleJDKObjectType("java.lang.FloatArray");
private static final TypeMirror JAVA_DOUBLE_ARRAY_TYPE = simpleJDKObjectType("java.lang.DoubleArray");
private static final TypeMirror JAVA_CHAR_ARRAY_TYPE = simpleJDKObjectType("java.lang.CharArray");
private static final TypeMirror JAVA_BOOLEAN_ARRAY_TYPE = simpleJDKObjectType("java.lang.BooleanArray");
private static TypeMirror simpleJDKObjectType(String name) {
return new SimpleReflType(name, SimpleReflType.Module.JDK, TypeKind.DECLARED);
}
private static TypeMirror simpleCeylonObjectType(String name) {
return new SimpleReflType(name, SimpleReflType.Module.CEYLON, TypeKind.DECLARED);
}
protected Map<String, Declaration> valueDeclarationsByName = new HashMap<String, Declaration>();
protected Map<String, Declaration> typeDeclarationsByName = new HashMap<String, Declaration>();
protected Map<Package, Unit> unitsByPackage = new HashMap<Package, Unit>();
protected TypeParser typeParser;
/**
* The type factory
* (<strong>should not be used while completing a declaration</strong>)
*/
protected Unit typeFactory;
protected final Set<String> loadedPackages = new HashSet<String>();
protected final Map<String,LazyPackage> packagesByName = new HashMap<String,LazyPackage>();
protected boolean packageDescriptorsNeedLoading = false;
protected boolean isBootstrap;
protected ModuleManager moduleManager;
protected Modules modules;
protected Map<String, ClassMirror> classMirrorCache = new HashMap<String, ClassMirror>();
protected boolean binaryCompatibilityErrorRaised = false;
protected Timer timer;
private Map<String,LazyPackage> modulelessPackages = new HashMap<String,LazyPackage>();
private ParameterNameParser parameterNameParser = new ParameterNameParser(this);
/**
* Loads a given package, if required. This is mostly useful for the javac reflection impl.
*
* @param the module to load the package from
* @param packageName the package name to load
* @param loadDeclarations true to load all the declarations in this package.
* @return
*/
public abstract boolean loadPackage(Module module, String packageName, boolean loadDeclarations);
public final Object getLock(){
return this;
}
/**
* To be redefined by subclasses if they don't need local declarations.
*/
protected boolean needsLocalDeclarations(){
return true;
}
public boolean searchAgain(Module module, String name) {
return false;
}
public boolean searchAgain(LazyPackage lazyPackage, String name) {
return false;
}
/**
* Looks up a ClassMirror by name. Uses cached results, and caches the result of calling lookupNewClassMirror
* on cache misses.
*
* @param module the module in which we should find the class
* @param name the name of the Class to load
* @return a ClassMirror for the specified class, or null if not found.
*/
public final ClassMirror lookupClassMirror(Module module, String name) {
synchronized(getLock()){
timer.startIgnore(TIMER_MODEL_LOADER_CATEGORY);
try{
// Java array classes are not where we expect them
if (JAVA_LANG_OBJECT_ARRAY.equals(name)
|| JAVA_LANG_BOOLEAN_ARRAY.equals(name)
|| JAVA_LANG_BYTE_ARRAY.equals(name)
|| JAVA_LANG_SHORT_ARRAY.equals(name)
|| JAVA_LANG_INT_ARRAY.equals(name)
|| JAVA_LANG_LONG_ARRAY.equals(name)
|| JAVA_LANG_FLOAT_ARRAY.equals(name)
|| JAVA_LANG_DOUBLE_ARRAY.equals(name)
|| JAVA_LANG_CHAR_ARRAY.equals(name)) {
// turn them into their real class location (get rid of the "java.lang" prefix)
name = "com.redhat.ceylon.compiler.java.language" + name.substring(9);
module = getLanguageModule();
}
String cacheKey = cacheKeyByModule(module, name);
// we use containsKey to be able to cache null results
if(classMirrorCache.containsKey(cacheKey)) {
ClassMirror cachedMirror = classMirrorCache.get(cacheKey);
if (cachedMirror != null || ! searchAgain(module, name)) {
return cachedMirror;
}
}
ClassMirror mirror = lookupNewClassMirror(module, name);
// we even cache null results
classMirrorCache.put(cacheKey, mirror);
return mirror;
}finally{
timer.stopIgnore(TIMER_MODEL_LOADER_CATEGORY);
}
}
}
protected String cacheKeyByModule(Module module, String name) {
return getCacheKeyByModule(module, name);
}
public static String getCacheKeyByModule(Module module, String name){
String moduleSignature = module.getSignature();
StringBuilder buf = new StringBuilder(moduleSignature.length()+1+name.length());
// '/' is allowed in module version but not in module or class name, so we're good
return buf.append(moduleSignature).append('/').append(name).toString();
}
protected boolean lastPartHasLowerInitial(String name) {
int index = name.lastIndexOf('.');
if (index != -1){
name = name.substring(index+1);
}
// remove any possibly quoting char
name = Naming.stripLeadingDollar(name);
if(!name.isEmpty()){
char c = name.charAt(0);
return Util.isLowerCase(c);
}
return false;
}
/**
* Looks up a ClassMirror by name. Called by lookupClassMirror on cache misses.
*
* @param module the module in which we should find the given class
* @param name the name of the Class to load
* @return a ClassMirror for the specified class, or null if not found.
*/
protected abstract ClassMirror lookupNewClassMirror(Module module, String name);
/**
* Adds the given module to the set of modules from which we can load classes.
*
* @param module the module
* @param artifact the module's artifact, if any. Can be null.
*/
public abstract void addModuleToClassPath(Module module, ArtifactResult artifact);
/**
* Returns true if the given module has been added to this model loader's classpath.
* Defaults to true.
*/
public boolean isModuleInClassPath(Module module){
return true;
}
/**
* Returns true if the given method is overriding an inherited method (from super class or interfaces).
*/
protected abstract boolean isOverridingMethod(MethodMirror methodMirror);
/**
* Returns true if the given method is overloading an inherited method (from super class or interfaces).
*/
protected abstract boolean isOverloadingMethod(MethodMirror methodMirror);
/**
* Logs a warning.
*/
protected abstract void logWarning(String message);
/**
* Logs a debug message.
*/
protected abstract void logVerbose(String message);
/**
* Logs an error
*/
protected abstract void logError(String message);
public void loadStandardModules(){
// set up the type factory
Module languageModule = findOrCreateModule(CEYLON_LANGUAGE, null);
addModuleToClassPath(languageModule, null);
Package languagePackage = findOrCreatePackage(languageModule, CEYLON_LANGUAGE);
typeFactory.setPackage(languagePackage);
// make sure the jdk modules are loaded
for(String jdkModule : JDKUtils.getJDKModuleNames())
findOrCreateModule(jdkModule, JDK_MODULE_VERSION);
for(String jdkOracleModule : JDKUtils.getOracleJDKModuleNames())
findOrCreateModule(jdkOracleModule, JDK_MODULE_VERSION);
Module jdkModule = findOrCreateModule(JAVA_BASE_MODULE_NAME, JDK_MODULE_VERSION);
/*
* We start by loading java.lang and ceylon.language because we will need them no matter what.
*/
loadPackage(jdkModule, "java.lang", false);
loadPackage(languageModule, "com.redhat.ceylon.compiler.java.metadata", false);
loadPackage(languageModule, "com.redhat.ceylon.compiler.java.language", false);
/*
* We do not load the ceylon.language module from class files if we're bootstrapping it
*/
if(!isBootstrap){
// loadPackage(languageModule, CEYLON_LANGUAGE, true);
// loadPackage(languageModule, CEYLON_LANGUAGE_MODEL, true);
// loadPackage(languageModule, CEYLON_LANGUAGE_MODEL_DECLARATION, true);
}
}
/**
* This is meant to be called if your subclass doesn't call loadStandardModules for whatever reason
*/
public void setupWithNoStandardModules() {
Module languageModule = modules.getLanguageModule();
if(languageModule == null)
throw new RuntimeException("Assertion failed: language module is null");
Package languagePackage = languageModule.getPackage(CEYLON_LANGUAGE);
if(languagePackage == null)
throw new RuntimeException("Assertion failed: language package is null");
typeFactory.setPackage(languagePackage);
}
enum ClassType {
ATTRIBUTE, METHOD, OBJECT, CLASS, INTERFACE;
}
private ClassMirror loadClass(Module module, String pkgName, String className) {
ClassMirror moduleClass = null;
try{
loadPackage(module, pkgName, false);
moduleClass = lookupClassMirror(module, className);
}catch(Exception x){
logVerbose("[Failed to complete class "+className+"]");
}
return moduleClass;
}
private Declaration convertNonPrimitiveTypeToDeclaration(Module moduleScope, TypeMirror type, Scope scope, DeclarationType declarationType) {
switch(type.getKind()){
case VOID:
return typeFactory.getAnythingDeclaration();
case ARRAY:
return ((Class)convertToDeclaration(getLanguageModule(), JAVA_LANG_OBJECT_ARRAY, DeclarationType.TYPE));
case DECLARED:
return convertDeclaredTypeToDeclaration(moduleScope, type, declarationType);
case TYPEVAR:
return safeLookupTypeParameter(scope, type.getQualifiedName());
case WILDCARD:
return typeFactory.getNothingDeclaration();
// those can't happen
case BOOLEAN:
case BYTE:
case CHAR:
case SHORT:
case INT:
case LONG:
case FLOAT:
case DOUBLE:
// all the autoboxing should already have been done
throw new RuntimeException("Expected non-primitive type: "+type);
case ERROR:
return null;
default:
throw new RuntimeException("Failed to handle type "+type);
}
}
private Declaration convertDeclaredTypeToDeclaration(Module moduleScope, TypeMirror type, DeclarationType declarationType) {
// SimpleReflType does not do declared class so we make an exception for it
String typeName = type.getQualifiedName();
if(type instanceof SimpleReflType){
Module module = null;
switch(((SimpleReflType) type).getModule()){
case CEYLON: module = getLanguageModule(); break;
case JDK : module = getJDKBaseModule(); break;
}
return convertToDeclaration(module, typeName, declarationType);
}
ClassMirror classMirror = type.getDeclaredClass();
Module module = findModuleForClassMirror(classMirror);
if(isImported(moduleScope, module)){
return convertToDeclaration(module, typeName, declarationType);
}else{
logVerbose("Declaration is not from an imported module: "+typeName);
return null;
}
}
protected Declaration convertToDeclaration(ClassMirror classMirror, DeclarationType declarationType) {
// avoid ignored classes
if(classMirror.getAnnotation(CEYLON_IGNORE_ANNOTATION) != null)
return null;
// avoid local interfaces that were pulled to the toplevel if required
if(classMirror.getAnnotation(CEYLON_LOCAL_CONTAINER_ANNOTATION) != null
&& !needsLocalDeclarations())
return null;
// avoid Ceylon annotations
if(classMirror.getAnnotation(CEYLON_CEYLON_ANNOTATION) != null
&& classMirror.isAnnotationType())
return null;
// avoid module and package descriptors too
if(classMirror.getAnnotation(CEYLON_MODULE_ANNOTATION) != null
|| classMirror.getAnnotation(CEYLON_PACKAGE_ANNOTATION) != null)
return null;
List<Declaration> decls = new ArrayList<Declaration>();
Module module = findModuleForClassMirror(classMirror);
boolean[] alreadyExists = new boolean[1];
Declaration decl = getOrCreateDeclaration(module, classMirror, declarationType,
decls, alreadyExists);
if (alreadyExists[0]) {
return decl;
}
// find its package
String pkgName = getPackageNameForQualifiedClassName(classMirror);
LazyPackage pkg = findOrCreatePackage(module, pkgName);
// find/make its Unit
Unit unit = getCompiledUnit(pkg, classMirror);
// set all the containers
for(Declaration d : decls){
// add it to its Unit
d.setUnit(unit);
unit.addDeclaration(d);
setContainer(classMirror, d, pkg);
}
return decl;
}
protected String getPackageNameForQualifiedClassName(ClassMirror classMirror) {
String qualifiedName = classMirror.getQualifiedName();
// Java array classes we pretend come from java.lang
if(qualifiedName.equals(CEYLON_OBJECT_ARRAY)
|| qualifiedName.equals(CEYLON_BOOLEAN_ARRAY)
|| qualifiedName.equals(CEYLON_BYTE_ARRAY)
|| qualifiedName.equals(CEYLON_SHORT_ARRAY)
|| qualifiedName.equals(CEYLON_INT_ARRAY)
|| qualifiedName.equals(CEYLON_LONG_ARRAY)
|| qualifiedName.equals(CEYLON_FLOAT_ARRAY)
|| qualifiedName.equals(CEYLON_DOUBLE_ARRAY)
|| qualifiedName.equals(CEYLON_CHAR_ARRAY))
return "java.lang";
else
return unquotePackageName(classMirror.getPackage());
}
private String unquotePackageName(PackageMirror pkg) {
return pkg.getQualifiedName().replace("$", "");
}
private void setContainer(ClassMirror classMirror, Declaration d, LazyPackage pkg) {
// add it to its package if it's not an inner class
if(!classMirror.isInnerClass() && !classMirror.isLocalClass()){
d.setContainer(pkg);
pkg.addCompiledMember(d);
if(d instanceof LazyInterface && ((LazyInterface) d).isCeylon()){
setInterfaceCompanionClass(d, null, pkg);
}
DeclarationVisitor.setVisibleScope(d);
}else if(classMirror.isLocalClass()){
// set its container to the package for now, but don't add it to the package as a member because it's not
Scope localContainer = getLocalContainer(pkg, classMirror, d);
if(localContainer != null){
d.setContainer(localContainer);
// do not add it as member, it has already been registered by getLocalContainer
}else{
d.setContainer(pkg);
}
((LazyElement)d).setLocal(true);
}else if(d instanceof ClassOrInterface || d instanceof TypeAlias){
// do overloads later, since their container is their abstract superclass's container and
// we have to set that one first
if(d instanceof Class == false || !((Class)d).isOverloaded()){
ClassOrInterface container = getContainer(pkg.getModule(), classMirror);
d.setContainer(container);
if(d instanceof LazyInterface && ((LazyInterface) d).isCeylon()){
setInterfaceCompanionClass(d, container, pkg);
}
// let's not trigger lazy-loading
((LazyContainer)container).addMember(d);
DeclarationVisitor.setVisibleScope(d);
// now we can do overloads
if(d instanceof Class && ((Class)d).getOverloads() != null){
for(Declaration overload : ((Class)d).getOverloads()){
overload.setContainer(container);
// let's not trigger lazy-loading
((LazyContainer)container).addMember(overload);
DeclarationVisitor.setVisibleScope(overload);
}
}
}
}
}
private void setInterfaceCompanionClass(Declaration d, ClassOrInterface container, LazyPackage pkg) {
// find its companion class in its real container
ClassMirror containerMirror = null;
if(container instanceof LazyClass){
containerMirror = ((LazyClass) container).classMirror;
}else if(container instanceof LazyInterface){
// container must be a LazyInterface, as TypeAlias doesn't contain anything
containerMirror = ((LazyInterface)container).companionClass;
if(containerMirror == null){
throw new ModelResolutionException("Interface companion class for "+container.getQualifiedNameString()+" not set up");
}
}
String companionName;
if(containerMirror != null)
companionName = containerMirror.getFlatName() + "$" + Naming.suffixName(Naming.Suffix.$impl, d.getName());
else{
// toplevel
String p = pkg.getNameAsString();
companionName = "";
if(!p.isEmpty())
companionName = p + ".";
companionName += Naming.suffixName(Naming.Suffix.$impl, d.getName());
}
ClassMirror companionClass = lookupClassMirror(pkg.getModule(), companionName);
if(companionClass == null){
throw new ModelResolutionException("Could not find interface companion class "+companionName+" for "+d.getQualifiedNameString());
}
((LazyInterface)d).companionClass = companionClass;
}
private Scope getLocalContainer(Package pkg, ClassMirror classMirror, Declaration declaration) {
AnnotationMirror localContainerAnnotation = classMirror.getAnnotation(CEYLON_LOCAL_CONTAINER_ANNOTATION);
LocalDeclarationContainer methodDecl = null;
// we get a @LocalContainer annotation for local interfaces
if(localContainerAnnotation != null){
methodDecl = (LocalDeclarationContainer) findLocalContainerFromAnnotationAndSetCompanionClass(pkg, (Interface) declaration, localContainerAnnotation);
}else{
// all the other cases stay where they belong
MethodMirror method = classMirror.getEnclosingMethod();
if(method == null)
return null;
// see where that method belongs
ClassMirror enclosingClass = method.getEnclosingClass();
// if we are in a setter class, the attribute is declared in the getter class, so look for its declaration there
TypeMirror getterClass = (TypeMirror) getAnnotationValue(enclosingClass, CEYLON_SETTER_ANNOTATION, "getterClass");
boolean isSetter = false;
// we use void.class as default value
if(getterClass != null && !getterClass.isPrimitive()){
enclosingClass = getterClass.getDeclaredClass();
isSetter = true;
}
String javaClassName = enclosingClass.getQualifiedName();
// make sure we don't go looking in companion classes
if(javaClassName.endsWith(Naming.Suffix.$impl.name()))
javaClassName = javaClassName.substring(0, javaClassName.length() - 5);
// find the enclosing declaration
Declaration enclosingClassDeclaration = convertToDeclaration(pkg.getModule(), javaClassName, DeclarationType.TYPE);
if(enclosingClassDeclaration instanceof ClassOrInterface){
ClassOrInterface containerDecl = (ClassOrInterface) enclosingClassDeclaration;
// now find the method's declaration
// FIXME: find the proper overload if any
if(method.isConstructor()){
methodDecl = (LocalDeclarationContainer) containerDecl;
}else{
String name = method.getName();
// this is only for error messages
String type;
// lots of special cases
if(isStringAttribute(method)){
name = "string";
type = "attribute";
}else if(isHashAttribute(method)){
name = "hash";
type = "attribute";
}else if(isGetter(method)) {
// simple attribute
name = getJavaAttributeName(name);
type = "attribute";
}else if(isSetter(method)) {
// simple attribute
name = getJavaAttributeName(name);
type = "attribute setter";
isSetter = true;
}else{
type = "method";
}
// strip any escaping or private suffix
name = Util.strip(name, true, method.isPublic() || method.isProtected() || method.isDefaultAccess());
methodDecl = (LocalDeclarationContainer) containerDecl.getDirectMember(name, null, false);
if(methodDecl == null)
throw new ModelResolutionException("Failed to load outer "+type+" " + name
+ " for local type " + classMirror.getQualifiedName().toString());
// if it's a setter we wanted, let's get it
if(isSetter){
LocalDeclarationContainer setter = (LocalDeclarationContainer) ((Value)methodDecl).getSetter();
if(setter == null)
throw new ModelResolutionException("Failed to load outer "+type+" " + name
+ " for local type " + classMirror.getQualifiedName().toString());
methodDecl = setter;
}
}
}else if(enclosingClassDeclaration instanceof LazyMethod){
// local and toplevel methods
methodDecl = (LazyMethod)enclosingClassDeclaration;
}else if(enclosingClassDeclaration instanceof LazyValue){
// local and toplevel attributes
if(enclosingClassDeclaration.isToplevel() && method.getName().equals(Naming.Unfix.set_.name()))
isSetter = true;
if(isSetter){
LocalDeclarationContainer setter = (LocalDeclarationContainer) ((LazyValue)enclosingClassDeclaration).getSetter();
if(setter == null)
throw new ModelResolutionException("Failed to toplevel attribute setter " + enclosingClassDeclaration.getName()
+ " for local type " + classMirror.getQualifiedName().toString());
methodDecl = setter;
}else
methodDecl = (LazyValue)enclosingClassDeclaration;
}else{
throw new ModelResolutionException("Unknown container type " + enclosingClassDeclaration
+ " for local type " + classMirror.getQualifiedName().toString());
}
}
// we have the method, now find the proper local qualifier if any
String qualifier = getAnnotationStringValue(classMirror, CEYLON_LOCAL_DECLARATION_ANNOTATION, "qualifier");
if(qualifier == null)
return null;
declaration.setQualifier(qualifier);
methodDecl.addLocalDeclaration(declaration);
return methodDecl;
}
private Scope findLocalContainerFromAnnotationAndSetCompanionClass(Package pkg, Interface declaration, AnnotationMirror localContainerAnnotation) {
@SuppressWarnings("unchecked")
List<String> path = (List<String>) localContainerAnnotation.getValue("path");
// we start at the package
Scope scope = pkg;
for(String name : path){
scope = (Scope) getDirectMember(scope, name);
}
String companionClassName = (String) localContainerAnnotation.getValue("companionClassName");
ClassMirror container;
Scope javaClassScope;
if(scope instanceof TypedDeclaration && ((TypedDeclaration) scope).isMember())
javaClassScope = scope.getContainer();
else
javaClassScope = scope;
if(javaClassScope instanceof LazyInterface){
container = ((LazyInterface)javaClassScope).companionClass;
}else if(javaClassScope instanceof LazyClass){
container = ((LazyClass) javaClassScope).classMirror;
}else if(javaClassScope instanceof LazyValue){
container = ((LazyValue) javaClassScope).classMirror;
}else if(javaClassScope instanceof LazyMethod){
container = ((LazyMethod) javaClassScope).classMirror;
}else if(javaClassScope instanceof SetterWithLocalDeclarations){
container = ((SetterWithLocalDeclarations) javaClassScope).classMirror;
}else{
throw new ModelResolutionException("Unknown scope class: "+javaClassScope);
}
String qualifiedCompanionClassName = container.getQualifiedName() + "$" + companionClassName;
ClassMirror companionClassMirror = lookupClassMirror(pkg.getModule(), qualifiedCompanionClassName);
if(companionClassMirror == null)
throw new ModelResolutionException("Could not find companion class mirror: "+qualifiedCompanionClassName);
((LazyInterface)declaration).companionClass = companionClassMirror;
return scope;
}
/**
* Looks for a direct member of type ClassOrInterface. We're not using Class.getDirectMember()
* because it skips object types and we want them.
*/
public static Declaration getDirectMember(Scope container, String name) {
if(name.isEmpty())
return null;
boolean wantsSetter = false;
if(name.startsWith(Naming.Suffix.$setter$.name())){
wantsSetter = true;
name = name.substring(8);
}
if(Character.isDigit(name.charAt(0))){
// this is a local type we have a different accessor for it
return ((LocalDeclarationContainer)container).getLocalDeclaration(name);
}
// don't even try using getDirectMember except on Package,
// because it will fail miserably during completion, since we
// will for instance have only anonymous types first, before we load their anonymous values, and
// when we go looking for them we won't be able to find them until we add their anonymous values,
// which is too late
if(container instanceof Package){
// don't use Package.getMembers() as it loads the whole package
Declaration result = container.getDirectMember(name, null, false);
return selectTypeOrSetter(result, wantsSetter);
}else{
// must be a Declaration
for(Declaration member : container.getMembers()){
if(!member.getName().equals(name))
continue;
Declaration result = selectTypeOrSetter(member, wantsSetter);
if(result != null)
return result;
}
}
// not found
return null;
}
private static Declaration selectTypeOrSetter(Declaration member, boolean wantsSetter) {
// if we found a type or a method/value we're good to go
if (member instanceof ClassOrInterface
|| member instanceof Method) {
return member;
}
// if it's a Value return its object type by preference, the member otherwise
if (member instanceof Value){
TypeDeclaration typeDeclaration = ((Value) member).getTypeDeclaration();
if(typeDeclaration != null && typeDeclaration.isAnonymous())
return typeDeclaration;
// did we want the setter?
if(wantsSetter)
return ((Value)member).getSetter();
// must be a non-object value
return member;
}
return null;
}
private ClassOrInterface getContainer(Module module, ClassMirror classMirror) {
AnnotationMirror containerAnnotation = classMirror.getAnnotation(CEYLON_CONTAINER_ANNOTATION);
if(containerAnnotation != null){
TypeMirror javaClassMirror = (TypeMirror)containerAnnotation.getValue("klass");
String javaClassName = javaClassMirror.getQualifiedName();
ClassOrInterface containerDecl = (ClassOrInterface) convertToDeclaration(module, javaClassName, DeclarationType.TYPE);
if(containerDecl == null)
throw new ModelResolutionException("Failed to load outer type " + javaClassName
+ " for inner type " + classMirror.getQualifiedName().toString());
return containerDecl;
}else{
return (ClassOrInterface) convertToDeclaration(classMirror.getEnclosingClass(), DeclarationType.TYPE);
}
}
protected Declaration getOrCreateDeclaration(Module module, ClassMirror classMirror,
DeclarationType declarationType, List<Declaration> decls, boolean[] alreadyExists) {
alreadyExists[0] = false;
Declaration decl = null;
ClassType type;
if(classMirror.isCeylonToplevelAttribute()){
type = ClassType.ATTRIBUTE;
}else if(classMirror.isCeylonToplevelMethod()){
type = ClassType.METHOD;
}else if(classMirror.isCeylonToplevelObject()){
type = ClassType.OBJECT;
}else if(classMirror.isInterface()){
type = ClassType.INTERFACE;
}else{
type = ClassType.CLASS;
}
String key = classMirror.getCacheKey(module);
// see if we already have it
Map<String, Declaration> declarationCache = null;
switch(type){
case OBJECT:
if(declarationType == DeclarationType.TYPE){
declarationCache = typeDeclarationsByName;
break;
}
// else fall-through to value
case ATTRIBUTE:
case METHOD:
declarationCache = valueDeclarationsByName;
break;
case CLASS:
case INTERFACE:
declarationCache = typeDeclarationsByName;
}
if(declarationCache.containsKey(key)){
alreadyExists[0] = true;
return declarationCache.get(key);
}
checkBinaryCompatibility(classMirror);
boolean isCeylon = classMirror.getAnnotation(CEYLON_CEYLON_ANNOTATION) != null;
// make it
switch(type){
case ATTRIBUTE:
decl = makeToplevelAttribute(classMirror);
setDeclarationVisibility(decl, classMirror, classMirror, true);
break;
case METHOD:
decl = makeToplevelMethod(classMirror);
setDeclarationVisibility(decl, classMirror, classMirror, true);
break;
case OBJECT:
// we first make a class
Declaration objectClassDecl = makeLazyClass(classMirror, null, null, true);
typeDeclarationsByName.put(key, objectClassDecl);
decls.add(objectClassDecl);
// then we make a value for it
Declaration objectDecl = makeToplevelAttribute(classMirror);
valueDeclarationsByName.put(key, objectDecl);
decls.add(objectDecl);
// which one did we want?
decl = declarationType == DeclarationType.TYPE ? objectClassDecl : objectDecl;
setDeclarationVisibility(objectClassDecl, classMirror, classMirror, true);
setDeclarationVisibility(objectDecl, classMirror, classMirror, true);
break;
case CLASS:
if(classMirror.getAnnotation(CEYLON_ALIAS_ANNOTATION) != null){
decl = makeClassAlias(classMirror);
setDeclarationVisibility(decl, classMirror, classMirror, true);
}else if(classMirror.getAnnotation(CEYLON_TYPE_ALIAS_ANNOTATION) != null){
decl = makeTypeAlias(classMirror);
setDeclarationVisibility(decl, classMirror, classMirror, true);
}else{
List<MethodMirror> constructors = getClassConstructors(classMirror);
if (!constructors.isEmpty()) {
if (constructors.size() > 1) {
decl = makeOverloadedConstructor(constructors, classMirror, decls, isCeylon);
} else {
// single constructor
MethodMirror constructor = constructors.get(0);
// if the class and constructor have different visibility, we pretend there's an overload of one
// if it's a ceylon class we don't care that they don't match sometimes, like for inner classes
// where the constructor is protected because we want to use an accessor, in this case the class
// visibility is to be used
if(isCeylon || getJavaVisibility(classMirror) == getJavaVisibility(constructor)){
decl = makeLazyClass(classMirror, null, constructor, false);
setDeclarationVisibility(decl, classMirror, classMirror, isCeylon);
}else{