IDEA-121779 set correct context when creating extracted method body.

If there is no correct context set original used classes are over covered by the classes imported by default. So the extracted class gets broken.
This commit is contained in:
Max Medvedev
2014-03-18 14:33:45 +04:00
parent e8b960c466
commit 4e20c7fbcf
3 changed files with 31 additions and 4 deletions
@@ -329,9 +329,7 @@ public class ExtractUtil {
buffer.append("\n}");
String methodText = buffer.toString();
GrMethod method = factory.createMethodFromText(methodText);
LOG.assertTrue(method != null);
return method;
return factory.createMethodFromText(methodText, helper.getContext());
}
public static void appendName(@NotNull final StringBuilder buffer, @NotNull final String name) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -250,4 +250,9 @@ private String '-'() {
}
''')
}
void testClassVsDefaultGDKClass() {
myFixture.addClass('package javax.sound.midi; public class Sequence { }')
doTest()
}
}
@@ -0,0 +1,24 @@
import javax.sound.midi.*
class Player {
public static void playMidiFromClasspath(String resourceName) {
<begin>Sequence sequence = MidiSystem.getSequence(Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName))<end>
println sequence
}
}
-----
import javax.sound.midi.*
class Player {
public static void playMidiFromClasspath(String resourceName) {
Sequence sequence = testMethod(resourceName)
println sequence
}
private static Sequence testMethod(String resourceName) {
Sequence sequence = MidiSystem.getSequence(Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName))
return sequence
}
}