2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.lang.java.parser.partial;
18 import com.intellij.lang.java.parser.JavaParser;
19 import com.intellij.lang.java.parser.JavaParsingTestCase;
21 public class ExpressionParserTest extends JavaParsingTestCase {
22 public ExpressionParserTest() {
23 super("parser-partial/expressions");
26 public void testAssignment0() { doParserTest("a = 0"); }
27 public void testAssignment1() { doParserTest("a ="); }
29 public void testBinary0() { doParserTest("a + b"); }
30 public void testBinary1() { doParserTest("a < b"); }
31 public void testBinary2() { doParserTest("a > = b"); }
32 public void testBinary3() { doParserTest("a >/**/= b"); }
34 public void testCond0() { doParserTest("cond ? true : false"); }
35 public void testCond1() { doParserTest("cond ?"); }
36 public void testCond2() { doParserTest("cond ? true"); }
37 public void testCond3() { doParserTest("cond ? true :"); }
39 public void testCondOr0() { doParserTest("a || b || c"); }
40 public void testCondOr1() { doParserTest("a ||"); }
42 public void testOr0() { doParserTest("a | b | c"); }
43 public void testOr1() { doParserTest("a |"); }
45 public void testInstanceOf0() { doParserTest("a instanceof String"); }
46 public void testInstanceOf1() { doParserTest("a instanceof"); }
48 public void testNot0() { doParserTest("!!a"); }
49 public void testNot1() { doParserTest("!"); }
51 public void testCast() { doParserTest("(Type)var"); }
53 public void testParenth0() { doParserTest("(c)"); }
54 public void testParenth1() { doParserTest("(this).f--"); }
55 public void testParenth2() { doParserTest("("); }
56 public void testParenth3() { doParserTest("(a < b)"); }
58 public void testNewInExprList() { doParserTest("call(new)"); }
60 public void testNew0() { doParserTest("new A()"); }
61 public void testNew1() { doParserTest("new A[1][]"); }
62 public void testNew2() { doParserTest("new A[]"); }
63 public void testNew3() { doParserTest("new A[][1]"); }
64 public void testNew4() { doParserTest("new A[][]{null}"); }
65 public void testNew5() { doParserTest("new A[1]{null}"); }
66 public void testNew6() { doParserTest("new"); }
67 public void testNew7() { doParserTest("new A"); }
68 public void testNew8() { doParserTest("new A["); }
69 public void testNew9() { doParserTest("new int"); }
70 public void testNew10() { doParserTest("new int()"); }
71 public void testNew11() { doParserTest("new String[0"); }
72 public void testNew12() { doParserTest("new int[1][2]"); }
73 public void testNew13() { doParserTest("new int[1][][2]"); }
74 public void testNew14() { doParserTest("Q.new A()"); }
75 public void testNew15() { doParserTest("new C<?>.B()"); }
76 public void testNew16() { doParserTest("new C<>()"); }
77 public void testNew17() { doParserTest("new Map<String, >()"); }
78 public void testNew18() { doParserTest("new int @A [2] @B"); }
80 public void testExprList0() { doParserTest("f(1,2)"); }
81 public void testExprList1() { doParserTest("f("); }
82 public void testExprList2() { doParserTest("f(1"); }
83 public void testExprList3() { doParserTest("f(1,"); }
84 public void testExprList4() { doParserTest("f(1,)"); }
85 public void testExprList5() { doParserTest("f(1,,2)"); }
86 public void testExprList6() { doParserTest("f(,2)"); }
88 public void testArrayInitializer0() { doParserTest("{ }"); }
89 public void testArrayInitializer1() { doParserTest("{ 1 }"); }
90 public void testArrayInitializer2() { doParserTest("{ 1, }"); }
91 public void testArrayInitializer3() { doParserTest("{ 1,2 }"); }
92 public void testArrayInitializer4() { doParserTest("{ 1 2 }"); }
93 public void testArrayInitializer5() { doParserTest("{ { }"); }
94 public void testArrayInitializer6() { doParserTest("{ , }"); }
95 public void testArrayInitializer7() { doParserTest("{ , , 7 }"); }
96 public void testArrayInitializer8() { doParserTest("{ 8, , , }"); }
97 public void testArrayInitializer9() { doParserTest("{ , 9 }"); }
99 public void testPinesInReferenceExpression0() { doParserTest("Collections.<String>sort(null)"); }
100 public void testPinesInReferenceExpression1() { doParserTest("this.<String>sort(null)"); }
101 public void testPinesInReferenceExpression2() { doParserTest("<String>super(null)"); }
103 public void testGE0() { doParserTest("x >>>= 8 >> 2"); }
104 public void testGE1() { doParserTest("x >= 2"); }
106 public void testIncompleteCast() { doParserTest("f((ArrayList<String>) )"); }
107 public void testShiftRight() { doParserTest("x >>= 2"); }
109 public void testIllegalWildcard() { doParserTest("this.<?>foo()"); }
110 public void testIllegalBound() { doParserTest("C.<T extends S>foo()"); }
112 public void testQualifiedSuperMethodCall0() { doParserTest("new D().super(0)"); }
113 public void testQualifiedSuperMethodCall1() { doParserTest("d.super(0)"); }
114 public void testQualifiedSuperMethodCall2() { doParserTest("(new O()).<T>super()"); }
115 public void testQualifiedSuperMethodCall3() { doParserTest("C.A.super()"); }
116 public void testSuperMethodCallTypeParameterList() { doParserTest("super()"); }
117 public void testPrimitiveClassObjectAccess() { doParserTest("int.class"); }
118 public void testPrimitiveFieldAccess() { doParserTest("int.x"); }
119 public void testChainedClassObjectAccess() { doParserTest("A.class.B.class"); }
120 public void testChainedThisObjectAccess() { doParserTest("A.this.B.this"); }
121 public void testAnnotatedRefExpr0() { doParserTest("@A C1.@B() C2"); }
122 public void testAnnotatedRefExpr1() { doParserTest("@A C1.@B() ()"); }
124 public void testMethodRef0() { doParserTest("a.b.C::m"); }
125 public void testMethodRef1() { doParserTest("a.b.C<T>::new"); }
126 public void testMethodRef2() { doParserTest("C::<T>m"); }
127 public void testMethodRef3() { doParserTest("a[i]::m"); }
128 public void testMethodRef4() { doParserTest("int[]::clone"); }
129 public void testMethodRef5() { doParserTest("(f ? list.map(String::length) : Collections.emptyList())::iterator"); }
131 public void testLambdaExpression0() { doParserTest("p -> 42"); }
132 public void testLambdaExpression1() { doParserTest("p -> "); }
133 public void testLambdaExpression2() { doParserTest("p -> {"); }
134 public void testLambdaExpression3() { doParserTest("(p) -> { }"); }
135 public void testLambdaExpression4() { doParserTest("(p, v) -> null"); }
136 public void testLambdaExpression5() { doParserTest("(p, v -> null"); }
137 public void testLambdaExpression6() { doParserTest("(p, v, -> null"); }
138 public void testLambdaExpression7() { doParserTest("(p -> null)"); }
139 public void testLambdaExpression8() { doParserTest("(I)(p) -> null"); }
140 public void testLambdaExpression9() { doParserTest("(I)p -> null"); }
141 public void testLambdaExpression10() { doParserTest("(I)(p -> null)"); }
142 public void testLambdaExpression11() { doParserTest("() -> { }"); }
143 public void testLambdaExpression12() { doParserTest("(I1 & I2) () -> null"); }
144 public void testLambdaExpression13() { doParserTest("(I1 & I2) () -> {}"); }
145 public void testLambdaExpression14() { doParserTest("(String t) -> t"); }
146 public void testLambdaExpression15() { doParserTest("(int a, int b) -> a + b"); }
147 public void testLambdaExpression16() { doParserTest("(final int x) -> x"); }
148 public void testLambdaExpression17() { doParserTest("(String s -> s"); }
149 public void testLambdaExpression18() { doParserTest("(java.lang.String s, -> s"); }
150 public void testLambdaExpression19() { doParserTest("(@A T t) -> (null)"); }
151 public void testLambdaExpression20() { doParserTest("(@A T) -> (null)"); }
152 public void testLambdaExpression21() { doParserTest("(T @A() [] x) -> { }"); }
153 public void testLambdaExpression22() { doParserTest("(T x @A() []) -> { }"); }
154 public void testAmbiguousLambdaExpression() { doParserTest("f( (x) < y , z > (w) -> v )"); }
156 private void doParserTest(String text) {
157 doParserTest(text, builder -> JavaParser.INSTANCE.getExpressionParser().parse(builder));