-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for #863: respect declared type of variable for STC (incl. if/else)
GROOVY-9064
- Loading branch information
1 parent
e29dba0
commit 7eaf200
Showing
4 changed files
with
164 additions
and
16 deletions.
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
....tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/Groovy25InferencingTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* Copyright 2009-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.eclipse.jdt.core.groovy.tests.search; | ||
|
||
import static org.eclipse.jdt.groovy.core.tests.GroovyBundle.isAtLeastGroovy; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public final class Groovy25InferencingTests extends InferencingTestSuite { | ||
|
||
@Before | ||
public void setUp() { | ||
assumeTrue(isAtLeastGroovy(25)); | ||
} | ||
|
||
@Test | ||
public void testCompileStaticVariableAssignment1() { | ||
String contents = | ||
"@groovy.transform.CompileStatic\n" + | ||
"void meth() {\n" + | ||
" List list = Collections.emptyList()\n" + | ||
"}"; | ||
|
||
String target = "list"; | ||
int offset = contents.indexOf(target); | ||
assertType(contents, offset, offset + target.length(), "java.util.List"); | ||
} | ||
|
||
@Test | ||
public void testCompileStaticVariableAssignment2() { | ||
String contents = | ||
"@groovy.transform.CompileStatic\n" + | ||
"void meth() {\n" + | ||
" List list = new ArrayList()\n" + | ||
"}"; | ||
|
||
String target = "list"; | ||
int offset = contents.indexOf(target); | ||
assertType(contents, offset, offset + target.length(), "java.util.List"); | ||
} | ||
|
||
@Test | ||
public void testCompileStaticVariableAssignment3() { | ||
String contents = | ||
"@groovy.transform.CompileStatic\n" + | ||
"void meth() {\n" + | ||
" List list = [1, 2]\n" + | ||
"}"; | ||
|
||
String target = "list"; | ||
int offset = contents.indexOf(target); | ||
assertType(contents, offset, offset + target.length(), "java.util.List"); | ||
} | ||
|
||
@Test | ||
public void testCompileStaticVariableAssignment4() { | ||
String contents = | ||
"@groovy.transform.CompileStatic\n" + | ||
"void meth(boolean flag) {\n" + | ||
" List list = [1, 2]\n" + | ||
" if (flag) {\n" + | ||
" list = [3, 'four']\n" + | ||
" }\n" + | ||
"}"; | ||
|
||
String target = "list"; | ||
int offset = contents.indexOf(target); | ||
assertType(contents, offset, offset + target.length(), "java.util.List"); | ||
} | ||
|
||
@Test | ||
public void testCompileStaticVariableAssignment5() { | ||
String contents = | ||
"@groovy.transform.CompileStatic\n" + | ||
"void meth() {\n" + | ||
" Map map = Collections.emptyMap()\n" + | ||
"}"; | ||
|
||
String target = "map"; | ||
int offset = contents.indexOf(target); | ||
assertType(contents, offset, offset + target.length(), "java.util.Map"); | ||
} | ||
|
||
@Test | ||
public void testCompileStaticVariableAssignment6() { | ||
String contents = | ||
"@groovy.transform.CompileStatic\n" + | ||
"void meth() {\n" + | ||
" Map map = new HashMap()\n" + | ||
"}"; | ||
|
||
String target = "map"; | ||
int offset = contents.indexOf(target); | ||
assertType(contents, offset, offset + target.length(), "java.util.Map"); | ||
} | ||
|
||
@Test | ||
public void testCompileStaticVariableAssignment7() { | ||
String contents = | ||
"@groovy.transform.CompileStatic\n" + | ||
"void meth() {\n" + | ||
" Map map = [:]\n" + | ||
"}"; | ||
|
||
String target = "map"; | ||
int offset = contents.indexOf(target); | ||
assertType(contents, offset, offset + target.length(), "java.util.Map"); | ||
} | ||
|
||
@Test | ||
public void testCompileStaticVariableAssignment8() { | ||
String contents = | ||
"@groovy.transform.CompileStatic\n" + | ||
"void meth(boolean flag) {\n" + | ||
" Map map = [:]\n" + | ||
" if (flag) {\n" + | ||
" map = [a: 1, b: '2']\n" + | ||
" }\n" + | ||
"}"; | ||
|
||
String target = "map"; | ||
int offset = contents.indexOf(target); | ||
assertType(contents, offset, offset + target.length(), "java.util.Map"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters