Inline inner: check when possible to inline this ref only (IDEA-39274)

This commit is contained in:
anna
2010-01-29 17:07:23 +03:00
parent 22353e8a58
commit de02933e05
14 changed files with 220 additions and 18 deletions
@@ -6,6 +6,7 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.psi.PsiCall;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiClassType;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.usageView.UsageInfo;
@@ -377,4 +378,56 @@ public class InlineToAnonymousClassTest extends LightCodeInsightTestCase {
assertEquals(0, conflicts.size());
processor.run();
}
public void testCanBeInvokedOnReference() throws Exception {
doTestCanBeInvokedOnReference(true);
}
public void testCanBeInvokedOnReference1() throws Exception {
doTestCanBeInvokedOnReference(true);
}
public void testCanBeInvokedOnReferenceSubstitution() throws Exception {
doTestCanBeInvokedOnReference(true);
}
public void testCanBeInvokedOnReferenceSubstitution1() throws Exception {
doTestCanBeInvokedOnReference(true);
}
public void testCanBeInvokedOnReferenceVarargs() throws Exception {
doTestCanBeInvokedOnReference(true);
}
public void testCantBeInvokedOnReference() throws Exception {
doTestCanBeInvokedOnReference(false);
}
public void testCantBeInvokedOnReference1() throws Exception {
doTestCanBeInvokedOnReference(false);
}
public void testCantBeInvokedOnReferenceReturnStatement() throws Exception {
doTestCanBeInvokedOnReference(false);
}
public void testCanBeInvokedOnReferenceSyncStatement() throws Exception {
doTestCanBeInvokedOnReference(true);
}
public void testCantBeInvokedOnReferenceThrowStatement() throws Exception {
doTestCanBeInvokedOnReference(false);
}
private void doTestCanBeInvokedOnReference(boolean canBeInvokedOnReference) throws Exception {
configureByFile("/refactoring/inlineToAnonymousClass/" + getTestName(false) + ".java");
PsiElement element = TargetElementUtilBase
.findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
PsiCall callToInline = InlineToAnonymousClassHandler.findCallToInline(myEditor);
PsiClass classToInline = (PsiClass) element;
assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline));
final PsiClassType superType = InlineToAnonymousClassProcessor.getSuperType(classToInline);
assertTrue(superType != null);
assertEquals(canBeInvokedOnReference, InlineToAnonymousClassHandler.canBeInvokedOnReference(callToInline, superType));
}
}