@@ -507,6 +507,7 @@ public void testLocalVar27() {
507
507
" x = 3.14\n " +
508
508
" break\n " +
509
509
" default:\n " +
510
+ " break" +
510
511
" }\n " +
511
512
" x\n " +
512
513
"}" ;
@@ -647,124 +648,168 @@ public void testLocalMethod5() {
647
648
648
649
@ Test
649
650
public void testMatcher1 () {
650
- String contents = "def x = \" \" =~ /pattern/\n x " ;
651
+ String contents = "def x = ('' =~ /pattern/) " ;
651
652
assertType (contents , "x" , "java.util.regex.Matcher" );
652
653
}
653
654
654
655
@ Test
655
656
public void testMatcher2 () {
656
- String contents = "(\" \" =~ /pattern/).hasGroup()" ;
657
+ String contents = "('' =~ /pattern/).hasGroup()" ;
657
658
assertType (contents , "hasGroup" , "java.lang.Boolean" );
658
659
}
659
660
660
661
@ Test
661
662
public void testPattern1 () {
662
- String contents = "def x = ~/pattern/\n x " ;
663
+ String contents = "def x = ~/pattern/" ;
663
664
assertType (contents , "x" , "java.util.regex.Pattern" );
664
665
}
665
666
666
667
@ Test
667
668
public void testPattern2 () {
668
- String contents = "def x = \" \" ==~ /pattern/\n x " ;
669
+ String contents = "def x = \" \" ==~ /pattern/" ;
669
670
assertType (contents , "x" , "java.lang.Boolean" );
670
671
}
671
672
672
673
@ Test
673
674
public void testSpread1 () {
674
- String contents = "def z = [1,2 ]*.value " ;
675
- assertType (contents , "value " , "java.lang.Integer " );
675
+ String contents = "def x = ['1','2' ]*.bytes " ;
676
+ assertType (contents , "x " , "java.util.List<byte[]> " );
676
677
}
677
678
678
679
@ Test
679
680
public void testSpread2 () {
680
- String contents = "[1,2,3]*.intValue()" ;
681
- assertType (contents , "intValue " , "java.lang.Integer" );
681
+ String contents = "def x = [1,2,3]*.intValue()" ;
682
+ assertType (contents , "x " , "java.util.List<java. lang.Integer> " );
682
683
}
683
684
684
685
@ Test
685
686
public void testSpread3 () {
686
- String contents = "[1,2,3]*.intValue()[0].value " ;
687
- assertType (contents , "value " , "java.lang.Integer" );
687
+ String contents = "def x = [1,2,3]*.intValue()[0].intValue() " ;
688
+ assertType (contents , "x " , "java.lang.Integer" );
688
689
}
689
690
690
691
@ Test
691
692
public void testSpread4 () {
692
- String contents = "[x :1,y :2,z :3]*.getKey()" ;
693
- assertType (contents , "getKey " , "java.lang.String" );
693
+ String contents = "def x = [a :1,b :2,c :3]*.getKey()" ;
694
+ assertType (contents , "x " , "java.util.List<java. lang.String> " );
694
695
}
695
696
696
697
@ Test
697
698
public void testSpread5 () {
698
- String contents = "[x :1,y :2,z :3]*.getValue()" ;
699
- assertType (contents , "getValue " , "java.lang.Integer" );
699
+ String contents = "def x = [a :1,b :2,c :3]*.getValue()" ;
700
+ assertType (contents , "x " , "java.util.List<java. lang.Integer> " );
700
701
}
701
702
702
703
@ Test
703
704
public void testSpread6 () {
704
- String contents = "[x :1,y :2,z :3]*.key" ;
705
- assertType (contents , "key " , "java.lang.String" );
705
+ String contents = "def x = [a :1,b :2,c :3]*.key" ;
706
+ assertType (contents , "x " , "java.util.List<java. lang.String> " );
706
707
}
707
708
708
709
@ Test
709
710
public void testSpread7 () {
710
- String contents = "[x :1,y :2,z :3]*.value" ;
711
- assertType (contents , "value " , "java.lang.Integer" );
711
+ String contents = "def x = [a :1,b :2,c :3]*.value" ;
712
+ assertType (contents , "x " , "java.util.List<java. lang.Integer> " );
712
713
}
713
714
714
715
@ Test
715
716
public void testSpread8 () {
716
- String contents = "[x :1,y :2,z :3]*.key[0].toLowerCase()" ;
717
- assertType (contents , "toLowerCase " , "java.lang.String" );
717
+ String contents = "def x = [a :1,b :2,c :3]*.key[0].toLowerCase()" ;
718
+ assertType (contents , "x " , "java.lang.String" );
718
719
}
719
720
720
721
@ Test
721
722
public void testSpread9 () {
722
- String contents = "[x :1,y :2,z :3]*.value[0].intValue()" ;
723
- assertType (contents , "intValue " , "java.lang.Integer" );
723
+ String contents = "def x = [a :1,b :2,c :3]*.value[0].intValue()" ;
724
+ assertType (contents , "x " , "java.lang.Integer" );
724
725
}
725
726
726
727
@ Test
727
728
public void testSpread10 () {
728
- String contents = "[1,2,3 ]*.value [0].value " ;
729
- assertType (contents , "value " , "java.lang.Integer" );
729
+ String contents = "def x = ['1','2','3' ]*.bytes [0].length " ;
730
+ assertType (contents , "x " , "java.lang.Integer" );
730
731
}
731
732
732
733
@ Test
733
734
public void testSpread11 () {
734
- String contents = "Set<String> strings = ['1','2','3'] as Set\n " +
735
- "strings*.bytes\n " ;
736
- assertType (contents , "bytes" , "byte[]" );
735
+ String contents = "Set<String> strings = ['1','2','3']; def x = strings*.bytes" ;
736
+ assertType (contents , "x" , "java.util.List<byte[]>" );
737
737
}
738
738
739
739
@ Test
740
740
public void testSpread12 () {
741
- String contents = "Set<String> strings = ['1','2','3'] as Set\n " +
742
- "strings*.length()\n " ;
743
- assertType (contents , "length" , "java.lang.Integer" );
741
+ String contents = "Set<String> strings = ['1','2','3']; def x = strings*.length()" ;
742
+ assertType (contents , "x" , "java.util.List<java.lang.Integer>" );
744
743
}
745
744
746
745
@ Test
747
746
public void testSpread13 () {
748
- String contents = "@groovy.transform.TypeChecked\n " +
749
- "class Foo {\n " +
750
- " static def meth() {\n " +
751
- " Set<java.beans.BeanInfo> beans = []\n " +
752
- " beans*.additionalBeanInfo\n " +
753
- " }\n " +
747
+ String contents =
748
+ "@groovy.transform.TypeChecked\n " +
749
+ "void test(Set<java.beans.BeanInfo> beans) {\n " +
750
+ " beans*.additionalBeanInfo\n " +
754
751
"}\n " ;
755
752
assertType (contents , "beans" , "java.util.Set<java.beans.BeanInfo>" );
756
753
assertType (contents , "additionalBeanInfo" , "java.beans.BeanInfo[]" );
757
754
}
758
755
759
- @ Test // https://github.com/groovy/groovy-eclipse/issues/763
756
+ @ Test // GROOVY-9021
760
757
public void testSpread14 () {
758
+ createJavaUnit ("Pojo" ,
759
+ "interface Pojo {\n " +
760
+ " java.util.Collection<? extends java.lang.String> getStrings();\n " +
761
+ "}\n " );
762
+
763
+ String contents =
764
+ "@groovy.transform.TypeChecked\n " +
765
+ "void test(Pojo pojo) {\n " +
766
+ " def result = pojo.strings*.bytes\n " + // exercises StaticTypeCheckingVisitor#getTypeForSpreadExpression
767
+ "}\n " ;
768
+ assertType (contents , "strings" , "java.util.Collection<? extends java.lang.String>" );
769
+ assertType (contents , "result" , "java.util.List<byte[]>" );
770
+ }
771
+
772
+ @ Test // GROOVY-9021
773
+ public void testSpread15 () {
774
+ createJavaUnit ("Pojo" ,
775
+ "interface Pojo {\n " +
776
+ " java.util.List<? extends java.lang.String> getStrings();\n " +
777
+ "}\n " );
778
+
779
+ String contents =
780
+ "@groovy.transform.TypeChecked\n " +
781
+ "void test(Pojo pojo) {\n " +
782
+ " def result = pojo.strings*.bytes\n " + // exercises StaticTypeCheckingVisitor#getTypeForListExpression
783
+ "}\n " ;
784
+ assertType (contents , "strings" , "java.util.List<? extends java.lang.String>" );
785
+ assertType (contents , "result" , "java.util.List<byte[]>" );
786
+ }
787
+
788
+ @ Test
789
+ public void testSpread16 () {
790
+ createJavaUnit ("Pojo" ,
791
+ "interface Pojo {\n " +
792
+ " java.util.Map<String, ? extends java.lang.String> getStrings();\n " +
793
+ "}\n " );
794
+
795
+ String contents =
796
+ "@groovy.transform.TypeChecked\n " +
797
+ "void test(Pojo pojo) {\n " +
798
+ " def result = pojo.strings*.value\n " + // exercises StaticTypeCheckingVisitor#getTypeForMapExpression
799
+ "}\n " ;
800
+ assertType (contents , "strings" , "java.util.Map<java.lang.String,? extends java.lang.String>" );
801
+ assertType (contents , "result" , "java.util.List<? extends java.lang.String>" );
802
+ }
803
+
804
+ @ Test // https://github.com/groovy/groovy-eclipse/issues/763
805
+ public void testSpread17 () {
761
806
String contents = "def strings = [[['1','2','3']]]\n " +
762
807
"def result = strings*.length()\n " ;
763
808
assertType (contents , "result" , "java.util.List<java.util.List>" );
764
809
}
765
810
766
811
@ Test // CommandRegistry.iterator() lacks generics
767
- public void testSpread15 () {
812
+ public void testSpread18 () {
768
813
String contents =
769
814
"import org.codehaus.groovy.tools.shell.CommandRegistry\n " +
770
815
"def registry = new CommandRegistry()\n " +
@@ -773,7 +818,7 @@ public void testSpread15() {
773
818
}
774
819
775
820
@ Test
776
- public void testSpread16 () {
821
+ public void testSpread19 () {
777
822
String contents =
778
823
"import java.util.regex.Matcher\n " +
779
824
"Matcher matcher = ('abc' =~ /./)\n " +
@@ -782,7 +827,7 @@ public void testSpread16() {
782
827
}
783
828
784
829
@ Test
785
- public void testSpread17 () {
830
+ public void testSpread20 () {
786
831
String contents =
787
832
"Reader reader = null\n " +
788
833
"def result = reader*.with {it}\n " ;
@@ -794,6 +839,22 @@ public void testMapLiteral() {
794
839
assertType ("[:]" , "java.util.Map<java.lang.Object,java.lang.Object>" );
795
840
}
796
841
842
+ @ Test // GROOVY-9021
843
+ public void testMapProperty () {
844
+ createJavaUnit ("Pojo" ,
845
+ "interface Pojo {\n " +
846
+ " java.util.Map<String, ? extends java.lang.Number> getMap();\n " +
847
+ "}\n " );
848
+
849
+ String contents =
850
+ "@groovy.transform.TypeChecked\n " +
851
+ "void test(Pojo pojo) {\n " +
852
+ " def result = pojo.map.name\n " + // exercises StaticTypeCheckingVisitor#getTypeForMapExpression
853
+ "}\n " ;
854
+ assertType (contents , "map" , "java.util.Map<java.lang.String,? extends java.lang.Number>" );
855
+ assertType (contents , "result" , "java.lang.Number" );
856
+ }
857
+
797
858
@ Test
798
859
public void testBoolean1 () {
799
860
assertType ("!x" , "java.lang.Boolean" );
0 commit comments