@@ -37,11 +37,8 @@ public class GoReferenceImporterTest extends GoCodeInsightFixtureTestCase {
3737 private boolean defaultJavaMemberOnTheFly ;
3838 private boolean defaultGoOnTheFly ;
3939
40- private static void updateSettings (boolean goOnTheFlyEnabled , boolean javaOnTheFlyEnabled ) {
41- CodeInsightSettings codeInsightSettings = CodeInsightSettings .getInstance ();
42- codeInsightSettings .ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = javaOnTheFlyEnabled ;
43- codeInsightSettings .ADD_MEMBER_IMPORTS_ON_THE_FLY = javaOnTheFlyEnabled ;
44- GoCodeInsightSettings .getInstance ().setAddUnambiguousImportsOnTheFly (goOnTheFlyEnabled );
40+ private static void updateSettings (boolean onTheFlyEnabled ) {
41+ GoCodeInsightSettings .getInstance ().setAddUnambiguousImportsOnTheFly (onTheFlyEnabled );
4542 }
4643
4744 @ Override
@@ -53,36 +50,41 @@ protected void setUp() throws Exception {
5350 defaultJavaOnTheFly = codeInsightSettings .ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY ;
5451 defaultJavaMemberOnTheFly = codeInsightSettings .ADD_MEMBER_IMPORTS_ON_THE_FLY ;
5552 defaultGoOnTheFly = GoCodeInsightSettings .getInstance ().isAddUnambiguousImportsOnTheFly ();
53+
54+ codeInsightSettings .ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true ;
55+ codeInsightSettings .ADD_MEMBER_IMPORTS_ON_THE_FLY = true ;
5656 }
5757
5858 @ Override
5959 protected void tearDown () throws Exception {
6060 try {
61- updateSettings (defaultGoOnTheFly , defaultJavaOnTheFly );
62- CodeInsightSettings .getInstance ().ADD_MEMBER_IMPORTS_ON_THE_FLY = defaultJavaMemberOnTheFly ;
61+ updateSettings (defaultGoOnTheFly );
62+ CodeInsightSettings codeInsightSettings = CodeInsightSettings .getInstance ();
63+ codeInsightSettings .ADD_MEMBER_IMPORTS_ON_THE_FLY = defaultJavaMemberOnTheFly ;
64+ codeInsightSettings .ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = defaultJavaOnTheFly ;
6365 }
6466 finally {
6567 //noinspection ThrowFromFinallyBlock
6668 super .tearDown ();
6769 }
6870 }
6971
70- private void doTestAddOnTheFly (boolean goOnTheFlyEnabled , boolean javaOnTheFlyEnabled ) {
72+ private void doTestAddOnTheFly (boolean goOnTheFlyEnabled ) {
7173 DaemonCodeAnalyzerSettings .getInstance ().setImportHintEnabled (true );
72- updateSettings (goOnTheFlyEnabled , javaOnTheFlyEnabled );
74+ updateSettings (goOnTheFlyEnabled );
7375
7476 String initial = "package a; func a() {\n fmt.Println() <caret> \n }" ;
7577 myFixture .configureByText ("a.go" , initial );
7678 myFixture .doHighlighting ();
7779 myFixture .doHighlighting ();
7880 String after = "package a;\n \n import \" fmt\" \n \n func a() {\n fmt.Println() \n }" ;
79- String result = goOnTheFlyEnabled && javaOnTheFlyEnabled ? after : initial ;
81+ String result = goOnTheFlyEnabled ? after : initial ;
8082 myFixture .checkResult (result );
8183 }
8284
8385 public void testUndo () {
8486 DaemonCodeAnalyzerSettings .getInstance ().setImportHintEnabled (true );
85- updateSettings (true , true );
87+ updateSettings (true );
8688 myFixture .configureByText ("a.go" , "package main\n \n func main() { <caret> }" );
8789 myFixture .type ("fmt." );
8890 myFixture .doHighlighting ();
@@ -94,73 +96,64 @@ public void testUndo() {
9496 }
9597
9698 public void testOnTheFlyEnabled () {
97- doTestAddOnTheFly (true , true );
99+ doTestAddOnTheFly (true );
98100 }
99101
100102 public void testOnTheFlyDisabled () {
101- doTestAddOnTheFly (false , true );
102- }
103-
104- public void testOnTheFlyEnabledJavaOnTheFlyDisabled () {
105- doTestAddOnTheFly (true , false );
103+ doTestAddOnTheFly (false );
106104 }
107105
108- public void testOnTheFlyDisabledJavaOnTheFlyDisabled () {
109- doTestAddOnTheFly (false , false );
110- }
111-
112- private void doTestImportOwnPath (String file , String text , String testFileText , String testText , String path , boolean shouldImport ) {
113- updateSettings (false , false );
114-
115- myFixture .addFileToProject (FileUtil .join (path , file ), text );
116- PsiFile testFile = myFixture .addFileToProject (FileUtil .join (path , testFileText ), testText );
106+ private void doTestImportOwnPath (String text , String testText , boolean shouldImport ) {
107+ updateSettings (false );
108+ myFixture .addFileToProject (FileUtil .join ("pack" , "a.go" ), text );
109+ PsiFile testFile = myFixture .addFileToProject (FileUtil .join ("pack" , "a_test.go" ), testText );
117110 myFixture .configureFromExistingVirtualFile (testFile .getVirtualFile ());
118- List <IntentionAction > actions = myFixture .filterAvailableIntentions ("Import " + path + "?" );
111+ List <IntentionAction > actions = myFixture .filterAvailableIntentions ("Import " + "pack" + "?" );
119112 assertTrue (shouldImport != actions .isEmpty ());
120113 }
121114
122115 public void testOwnAddPathFromTest () {
123- doTestImportOwnPath ("a.go" , " package myPack; func Func() {}" ,
124- "a_test.go" , " package myPack_test; func TestFunc() { my<caret>Pack.Func() }" ,
125- "pack" , true );
116+ doTestImportOwnPath ("package myPack; func Func() {}" ,
117+ "package myPack_test; func TestFunc() { my<caret>Pack.Func() }" ,
118+ true );
126119 }
127120
128121 public void testDoNotImportOwnPathFromDifferentPackage () {
129- doTestImportOwnPath ("a.go" , " package pack1; func Func() {}" ,
130- "a_test.go" , " package pack2_test; func TestFunc() { pack<caret>1.Func() }" ,
131- "pack" , false );
122+ doTestImportOwnPath ("package pack1; func Func() {}" ,
123+ "package pack2_test; func TestFunc() { pack<caret>1.Func() }" ,
124+ false );
132125 }
133126
134127 public void testCompleteDifferentPackageFromTest () {
135128 myFixture .configureByText ("a.go" , "package foo; func a() { fmt.Print<caret> }" );
136129 assertNotEmpty (myFixture .getLookupElementStrings ());
137130 }
138-
131+
139132 public void testImportVendoringPackage () {
140133 myFixture .addFileToProject ("vendor/a/b/c.go" , "package b" );
141134 myFixture .configureByText ("a.go" , "package a; func a() { b<caret>.Println() }" );
142135 myFixture .launchAction (myFixture .findSingleIntention ("Import a/b?" ));
143136 myFixture .checkResult ("package a;\n \n import \" a/b\" \n \n func a() { b<caret>.Println() }" );
144- }
145-
137+ }
138+
146139 public void testImportVendoringPackageWithDisabledVendoring () {
147140 disableVendoring ();
148141 myFixture .addFileToProject ("vendor/a/b/c.go" , "package b" );
149142 myFixture .configureByText ("a.go" , "package a; func a() { b<caret>.Println() }" );
150143 myFixture .launchAction (myFixture .findSingleIntention ("Import vendor/a/b?" ));
151144 myFixture .checkResult ("package a;\n \n import \" vendor/a/b\" \n \n func a() { b<caret>.Println() }" );
152145 }
153-
146+
154147 public void testImportBuiltinPackage () {
155148 myFixture .configureByText ("a.go" , "package a; func a() { built<caret>in.Println() }" );
156149 assertEmpty (myFixture .filterAvailableIntentions ("Import builtin?" ));
157- }
158-
150+ }
151+
159152 public void testImportSdkTestData () {
160153 myFixture .configureByText ("a.go" , "package a; func _() { println(p<caret>kg.ExportedConstant) } " );
161154 assertEmpty (myFixture .filterAvailableIntentions ("Import doc/testdata?" ));
162155 }
163-
156+
164157 public void testImportVendoredBuiltinPackage () {
165158 myFixture .addFileToProject ("vendor/builtin/builtin.go" , "package builtin" );
166159 myFixture .configureByText ("a.go" , "package a; func a() { built<caret>in.Println() }" );
0 commit comments