moving tests

This commit is contained in:
Dmitry Jemerov
2009-09-10 19:49:38 +04:00
parent e389680982
commit b43c03ca2f
305 changed files with 32 additions and 4 deletions
@@ -0,0 +1,43 @@
package com.intellij.refactoring.convertToInstanceMethod;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.JavaTestUtil;
/**
* @author dsl
*/
public class ConvertToInstanceMethodTest extends LightCodeInsightTestCase {
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void testSimple() throws Exception { doTest(0); }
public void testInterface() throws Exception { doTest(1); }
public void testInterfacePrivate() throws Exception { doTest(1); }
public void testInterface2() throws Exception { doTest(0); }
public void testInterface3() throws Exception { doTest(0); }
public void testTypeParameter() throws Exception { doTest(0); }
public void testInterfaceTypeParameter() throws Exception { doTest(0); }
private void doTest(final int targetParameter) throws Exception {
final String filePath = "/refactoring/convertToInstanceMethod/" + getTestName(false) + ".java";
configureByFile(filePath);
final PsiElement targetElement = TargetElementUtilBase.findTargetElement(getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
PsiMethod method = (PsiMethod) targetElement;
new ConvertToInstanceMethodProcessor(getProject(),
method, method.getParameterList().getParameters()[targetParameter], null).run();
checkResultByFile(filePath + ".after");
}
}
@@ -0,0 +1,160 @@
package com.intellij.refactoring.inline;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLocalVariable;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceExpression;
import com.intellij.refactoring.RefactoringBundle;
import com.intellij.testFramework.LightCodeInsightTestCase;
/**
* @author ven
*/
public class InlineLocalTest extends LightCodeInsightTestCase {
private LanguageLevel myPreviousLanguageLevel;
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
protected void setUp() throws Exception {
super.setUp();
myPreviousLanguageLevel = LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).getLanguageLevel();
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
}
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk15("java 1.5");
}
protected void tearDown() throws Exception {
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(myPreviousLanguageLevel);
super.tearDown();
}
public void testInference () throws Exception {
doTest(false);
}
public void testQualifier () throws Exception {
doTest(false);
}
public void testIDEADEV950 () throws Exception {
doTest(false);
}
public void testNoRedundantCasts () throws Exception {
doTest(false);
}
public void testIDEADEV9404 () throws Exception {
doTest(false);
}
public void testIDEADEV12244 () throws Exception {
doTest(false);
}
public void testIDEADEV10376 () throws Exception {
doTest(true);
}
public void testIDEADEV13151 () throws Exception {
doTest(true);
}
public void testAugmentedAssignment() throws Exception {
String exception = null;
try {
doTest(false);
}
catch(RuntimeException ex) {
exception = ex.getMessage();
}
String error = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("variable.is.accessed.for.writing", "text"));
assertEquals(error, exception);
}
public void testUsedInInnerClass() throws Exception { // IDEADEV-28786
doTest(true);
}
public void testUsedInInnerClass2() throws Exception { // IDEADEV-28786
doTest(true);
}
public void testUsedInInnerClass3() throws Exception { // IDEADEV-28786
doTest(true);
}
public void testUsedInInnerClass4() throws Exception { // IDEADEV-28786
doTest(true);
}
public void testAnotherDefinitionUsed() throws Exception {
doTest(true, "Cannot perform refactoring.\nAnother variable 'bar' definition is used together with inlined one.");
}
public void testAnotherDefinitionUsed1() throws Exception {
doTest(false, "Cannot perform refactoring.\nAnother variable 'bar' definition is used together with inlined one.");
}
public void testTypeArgumentsStatic() throws Exception {
doTest(true);
}
public void testTypeArguments() throws Exception {
doTest(true);
}
private void doTest(final boolean inlineDef, String conflictMessage) throws Exception {
try {
doTest(inlineDef);
fail("Conflict was not detected");
}
catch (RuntimeException e) {
assertEquals(e.getMessage(), conflictMessage);
}
}
private void doTest(final boolean inlineDef) throws Exception {
String name = getTestName(false);
String fileName = "/refactoring/inlineLocal/" + name + ".java";
configureByFile(fileName);
if (!inlineDef) {
performInline(getProject(), myEditor);
}
else {
performDefInline(getProject(), myEditor);
}
checkResultByFile(fileName + ".after");
}
public static void performInline(Project project, Editor editor) {
PsiElement element = TargetElementUtilBase
.findTargetElement(editor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
assertTrue(element instanceof PsiLocalVariable);
InlineLocalHandler.invoke(project, editor, (PsiLocalVariable)element, null);
}
public static void performDefInline(Project project, Editor editor) {
PsiReference reference = TargetElementUtilBase.findReference(editor);
assertTrue(reference instanceof PsiReferenceExpression);
final PsiElement local = reference.resolve();
assertTrue(local instanceof PsiLocalVariable);
InlineLocalHandler.invoke(project, editor, (PsiLocalVariable)local, (PsiReferenceExpression)reference);
}
}
@@ -0,0 +1,164 @@
package com.intellij.refactoring.inline;
import com.intellij.codeInsight.CodeInsightTestCase;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceExpression;
import com.intellij.refactoring.MockInlineMethodOptions;
import com.intellij.JavaTestUtil;
import org.jetbrains.annotations.NonNls;
public class InlineMethodTest extends CodeInsightTestCase {
private LanguageLevel myPreviousLanguageLevel;
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
protected void setUp() throws Exception {
super.setUp();
myPreviousLanguageLevel = LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).getLanguageLevel();
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
}
protected void tearDown() throws Exception {
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(myPreviousLanguageLevel);
super.tearDown();
}
public void testInlineParms() throws Exception {
doTest();
}
public void testInlineWithQualifier() throws Exception {
doTest();
}
public void testInlineWithQualifierFromSuper() throws Exception { doTest(); }
public void testTry() throws Exception {
doTest();
}
public void testTrySynchronized() throws Exception {
doTest();
}
public void testSideEffect() throws Exception { doTest(); }
public void testInlineWithTry() throws Exception { doTest(); }
public void testVoidWithReturn() throws Exception { doTest(); }
public void testVoidWithReturn1() throws Exception { doTest(); }
public void testScr10884() throws Exception {
doTest();
}
public void testFinalParameters() throws Exception { doTest(); }
public void testFinalParameters1() throws Exception { doTest(); }
public void testScr13831() throws Exception { doTest(); }
public void testNameClash() throws Exception { doTest(); }
public void testArrayAccess() throws Exception { doTest(); }
public void testConflictingField() throws Exception { doTest(); }
public void testCallInFor() throws Exception { doTest(); }
public void testSCR20655() throws Exception { doTest(); }
public void testFieldInitializer() throws Exception { doTest(); }
public void testStaticFieldInitializer() throws Exception { doTest(); }
public void testSCR22644() throws Exception { doTest(); }
public void testCallUnderIf() throws Exception { doTest(); }
//This gives extra 'result' local variable, currently I don't see a way to cope with it, todo: think about addional inline possibilities
//public void testLocalVariableResult() throws Exception { doTest(); }
public void testSCR31093() throws Exception { doTest(); }
public void testSCR37742() throws Exception { doTest(); }
public void testChainingConstructor() throws Exception { doTest(); }
public void testChainingConstructor1() throws Exception { doTest(); }
public void testNestedCall() throws Exception { doTest(); }
public void testIDEADEV3672() throws Exception { doTest(); }
public void testIDEADEV5806() throws Exception { doTest(); }
public void testIDEADEV6807() throws Exception { doTest(); }
public void testIDEADEV12616() throws Exception { doTest(); }
public void testVarargs() throws Exception { doTest(); }
public void testVarargs1() throws Exception { doTest(); }
public void testEnumConstructor() throws Exception { doTest(); }
public void testEnumConstantConstructorParameter() throws Exception { // IDEADEV-26133
doTest();
}
public void testEnumConstantConstructorParameterComplex() throws Exception { // IDEADEV-26133
doTest();
}
public void testEnumConstantConstructorParameterComplex2() throws Exception { // IDEADEV-26133
doTest();
}
public void testConstantInChainingConstructor() throws Exception { // IDEADEV-28136
doTest();
}
public void testReplaceParameterWithArgumentForConstructor() throws Exception { // IDEADEV-23652
doTest();
}
public void testTailCallReturn() throws Exception { // IDEADEV-27983
doTest();
}
public void testTailCallSimple() throws Exception { // IDEADEV-27983
doTest();
}
public void testTailComment() throws Exception { //IDEADEV-33638
doTest();
}
private void doTest() throws Exception {
String name = getTestName(false);
@NonNls String fileName = "/refactoring/inlineMethod/" + name + ".java";
configureByFile(fileName);
performAction();
checkResultByFile(fileName + ".after");
}
private void performAction() {
PsiElement element = TargetElementUtilBase
.findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
final PsiReference ref = myFile.findReferenceAt(myEditor.getCaretModel().getOffset());
PsiReferenceExpression refExpr = ref instanceof PsiReferenceExpression ? (PsiReferenceExpression)ref : null;
assertTrue(element instanceof PsiMethod);
PsiMethod method = (PsiMethod)element;
final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineMethodHandler.allUsagesAreTailCalls(method);
assertFalse("Bad returns found", condition);
InlineOptions options = new MockInlineMethodOptions();
final InlineMethodProcessor processor = new InlineMethodProcessor(myProject, method, refExpr, myEditor, options.isInlineThisOnly());
processor.run();
}
}
@@ -0,0 +1,111 @@
package com.intellij.refactoring.inline;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.JavaTestUtil;
import org.jetbrains.annotations.NonNls;
/**
* @author yole
*/
public class InlineParameterTest extends LightCodeInsightTestCase {
private LanguageLevel myPreviousLanguageLevel;
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
protected void setUp() throws Exception {
super.setUp();
myPreviousLanguageLevel = LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).getLanguageLevel();
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
}
protected void tearDown() throws Exception {
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(myPreviousLanguageLevel);
super.tearDown();
}
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk15("java 1.5");
}
public void testSameValue() throws Exception {
doTest(true);
}
public void testNullValue() throws Exception {
doTest(true);
}
public void testConstructorCall() throws Exception {
doTest(true);
}
public void testStaticFinalField() throws Exception {
doTest(true);
}
public void testRefIdentical() throws Exception {
doTest(true);
}
public void testRefIdenticalNoLocal() throws Exception {
doTest(false);
}
public void testRefLocalConstantInitializer() throws Exception {
doTest(false);
}
public void testRefLocalWithLocal() throws Exception {
doTest(false);
}
public void testRefMethod() throws Exception {
doTest(true);
}
public void testRefMethodOnLocal() throws Exception {
doTest(false);
}
public void testRefFinalLocal() throws Exception {
doTest(true);
}
public void testRefStaticField() throws Exception {
doTest(true);
}
public void testRefFinalLocalInitializedWithMethod() throws Exception {
doTest(false);
}
public void testRefSelfField() throws Exception {
doTest(false);
}
private void doTest(final boolean createLocal) throws Exception {
getProject().putUserData(InlineParameterExpressionProcessor.CREATE_LOCAL_FOR_TESTS,createLocal);
String name = getTestName(false);
@NonNls String fileName = "/refactoring/inlineParameter/" + name + ".java";
configureByFile(fileName);
performAction();
checkResultByFile(null, fileName + ".after", true);
}
private void performAction() {
final PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase
.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
new InlineParameterHandler().inlineElement(getProject(), myEditor, element);
}
}
@@ -0,0 +1,57 @@
package com.intellij.refactoring.inline;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightTestCase;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.search.ProjectScope;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.usageView.UsageInfo;
import java.io.File;
import java.util.ArrayList;
/**
* @author yole
*/
public class InlineToAnonymousClassMultifileTest extends CodeInsightTestCase {
public void testProtectedMember() throws Exception { // IDEADEV-18738
doTest("p1.SubjectWithSuper");
}
public void testImportForConstructor() throws Exception { // IDEADEV-18714
doTest("p1.ChildCtor");
}
public void testStaticImports() throws Exception { // IDEADEV-18745
doTest("p1.Inlined");
}
private String getRoot() {
return JavaTestUtil.getJavaTestDataPath() + "/refactoring/inlineToAnonymousClass/multifile/" + getTestName(true);
}
private void doTest(String className) throws Exception {
String rootBefore = getRoot() + "/before";
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk("java 1.4"));
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
PsiClass classToInline = myJavaFacade.findClass(className, ProjectScope.getAllScope(myProject));
assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage(classToInline));
InlineToAnonymousClassProcessor processor = new InlineToAnonymousClassProcessor(myProject,
classToInline,
null, false, false, false);
UsageInfo[] usages = processor.findUsages();
ArrayList<String> conflicts = processor.getConflicts(usages);
assertEquals(0, conflicts.size());
processor.run();
String rootAfter = getRoot() + "/after";
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir, IdeaTestUtil.CVS_FILE_FILTER);
}
}
@@ -0,0 +1,396 @@
package com.intellij.refactoring.inline;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiCall;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.usageView.UsageInfo;
import com.intellij.JavaTestUtil;
import org.jetbrains.annotations.NonNls;
import java.util.ArrayList;
/**
* @author yole
*/
public class InlineToAnonymousClassTest extends LightCodeInsightTestCase {
private LanguageLevel myPreviousLanguageLevel;
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
protected void setUp() throws Exception {
super.setUp();
myPreviousLanguageLevel = LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).getLanguageLevel();
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
}
protected void tearDown() throws Exception {
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(myPreviousLanguageLevel);
super.tearDown();
}
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk15("java 1.5");
}
public void testSimple() throws Exception {
doTest(false, false);
}
public void testChangeToSuperType() throws Exception {
doTest(false, false);
}
public void testImplementsInterface() throws Exception {
doTest(false, false);
}
public void testClassInitializer() throws Exception {
doTest(false, false);
}
public void testConstructor() throws Exception {
doTest(false, false);
}
public void testConstructorWithArguments() throws Exception {
doTest(false, false);
}
public void testConstructorWithArgumentsInExpression() throws Exception {
doTest(false, false);
}
public void testMultipleConstructors() throws Exception {
doTest(false, false);
}
public void testMethodUsage() throws Exception {
doTest(false, false);
}
public void testConstructorArgumentToField() throws Exception {
doTest(false, false);
}
public void testField() throws Exception {
doTest(false, false);
}
public void testStaticConstantField() throws Exception {
doTest(false, false);
}
public void testWritableInitializedField() throws Exception {
doTest(false, false);
}
public void testNullInitializedField() throws Exception {
doTest(false, false);
}
public void testInnerClass() throws Exception {
doTest(false, false);
}
public void testConstructorToInstanceInitializer() throws Exception {
doTest(false, false);
}
public void testNewExpressionContext() throws Exception {
doTest(false, false);
}
public void testWritableFieldInitializedWithParameter() throws Exception {
doTest(false, false);
}
public void testFieldInitializedWithVar() throws Exception {
doTest(false, false);
}
public void testFieldVsLocalConflict() throws Exception {
doTest(false, false);
}
public void testFieldVsParameterConflict() throws Exception {
doTest(false, false);
}
public void testGenerics() throws Exception {
doTest(false, false);
}
public void testGenericsSubstitute() throws Exception {
doTest(false, false);
}
public void testGenericsFieldDeclaration() throws Exception {
doTest(false, false);
}
public void testGenericsRawType() throws Exception {
doTest(false, false);
}
public void testGenericsInTypeParameter() throws Exception {
doTest(false, false);
}
public void testQualifyInner() throws Exception {
doTest(false, false);
}
public void testQualifiedNew() throws Exception {
doTest(false, false);
}
public void testChainedConstructors() throws Exception {
doTest(false, false);
}
public void testInlineThisOnly() throws Exception {
doTest(true, false);
}
public void testArrayType() throws Exception {
doTest(false, false);
}
public void testArrayTypeWithGenerics() throws Exception {
doTest(false, false);
}
public void testArrayInitializer() throws Exception {
doTest(false, false);
}
public void testVarargs() throws Exception {
doTest(false, false);
}
public void testSelfReference() throws Exception {
doTest(false, false);
}
public void _testOuterClassFieldAccess() throws Exception {
doTest(false, false);
}
public void testPrivateFieldUsedFromInnerClass() throws Exception {
doTest(false, false);
}
public void testOverwriteInitializer() throws Exception {
doTest(false, false);
}
public void testMultipleInnerClasses() throws Exception {
doTest(false, false);
}
public void testConstructorArgumentInExpression() throws Exception {
doTest(false, false);
}
public void testMethodCallInNewExpression() throws Exception {
doTest(false, false);
}
public void testMethodCallInNewExpressionWithParens() throws Exception {
doTest(false, false);
}
public void testRedundantImplementsInterface() throws Exception {
doTest(false, false);
}
public void testStringInMethodCallFromConstructor() throws Exception {
doTest(false, false);
}
public void testMultipleGeneratedVars() throws Exception {
doTest(false, false);
}
public void testFieldAsConstructorParameter() throws Exception {
doTest(false, false);
}
public void testQualifyParentStaticReferences() throws Exception {
doTest(false, false);
}
public void testLocalClass() throws Exception {
doTest(false, true);
}
public void testNoInlineAbstract() throws Exception {
doTestNoInline("Abstract classes cannot be inlined");
}
public void testNoInlineInterface() throws Exception {
doTestNoInline("Interfaces cannot be inlined");
}
public void testNoInlineEnum() throws Exception {
doTestNoInline("Enums cannot be inlined");
}
public void testNoInlineAnnotationType() throws Exception {
doTestNoInline("Annotation types cannot be inlined");
}
public void testNoInlineMultipleInterfaces() throws Exception {
doTestNoInline("Classes which implement multiple interfaces cannot be inlined");
}
public void testNoInlineSuperclassInterface() throws Exception {
doTestNoInline("Classes which have a superclass and implement an interface cannot be inlined");
}
public void testNoInlineMethodUsage() throws Exception {
doTestNoInline("Class cannot be inlined because it has usages of methods not inherited from its superclass or interface");
}
public void testNoInlineFieldUsage() throws Exception {
doTestNoInline("Class cannot be inlined because it has usages of fields not inherited from its superclass");
}
public void testNoInlineNewWithInner() throws Exception {
doTestNoInline("Class cannot be inlined because it has usages of its inner classes");
}
public void testNoInlineStaticField() throws Exception {
doTestNoInline("Class cannot be inlined because it has static fields with non-constant initializers");
}
public void testNoInlineStaticNonFinalField() throws Exception {
doTestNoInline("Class cannot be inlined because it has static non-final fields");
}
public void testNoInlineStaticMethod() throws Exception {
doTestNoInline("Class cannot be inlined because it has static methods");
}
public void testNoInlineStaticInitializer() throws Exception {
doTestNoInline("Class cannot be inlined because it has static initializers");
}
public void testNoInlineClassLiteral() throws Exception {
doTestPreprocessUsages("Class cannot be inlined because it has usages of its class literal");
}
public void testNoInlineCatchClause() throws Exception {
doTestPreprocessUsages("Class cannot be inlined because it is used in a 'catch' clause");
}
public void testNoInlineThrowsClause() throws Exception {
doTestPreprocessUsages("Class cannot be inlined because it is used in a 'throws' clause");
}
public void testNoInlineThisQualifier() throws Exception {
doTestPreprocessUsages("Class cannot be inlined because it is used as a 'this' qualifier");
}
public void testNoInlineUnresolvedConstructor() throws Exception {
doTestPreprocessUsages("Class cannot be inlined because a call to its constructor is unresolved");
}
public void testNoInlineUnresolvedConstructor2() throws Exception {
doTestPreprocessUsages("Class cannot be inlined because a call to its constructor is unresolved");
}
public void testNoInlineStaticInnerClass() throws Exception {
doTestNoInline("Class cannot be inlined because it has static inner classes");
}
public void testNoInlineReturnInConstructor() throws Exception {
doTestNoInline("Class cannot be inlined because its constructor contains 'return' statements");
}
public void testNoInlineUnresolvedSuperclass() throws Exception {
doTestNoInline("Class cannot be inlined because its superclass cannot be resolved");
}
public void testNoInlineUnresolvedInterface() throws Exception {
doTestNoInline("Class cannot be inlined because an interface implemented by it cannot be resolved");
}
public void testNoInlineLibraryClass() throws Exception {
doTestNoInline("Library classes cannot be inlined");
}
public void testNoInlineNoUsages() throws Exception {
doTestPreprocessUsages("Class is never used");
}
public void testConflictInaccessibleOuterField() throws Exception {
InlineToAnonymousClassProcessor processor = prepareProcessor();
UsageInfo[] usages = processor.findUsages();
ArrayList<String> conflicts = processor.getConflicts(usages);
assertEquals(1, conflicts.size());
assertEquals("Field <b><code>C2.a</code></b> that is used in inlined method is not accessible from call site(s) in method <b><code>C2User.test()</code></b>",
conflicts.get(0));
}
private void doTestNoInline(final String expectedMessage) throws Exception {
String name = getTestName(false);
@NonNls String fileName = "/refactoring/inlineToAnonymousClass/" + name + ".java";
configureByFile(fileName);
PsiElement element = TargetElementUtilBase
.findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
assertInstanceOf(element, PsiClass.class);
String message = InlineToAnonymousClassHandler.getCannotInlineMessage((PsiClass) element);
assertEquals(expectedMessage, message);
}
private void doTest(final boolean inlineThisOnly, final boolean searchInNonJavaFiles) throws Exception {
String name = getTestName(false);
@NonNls String fileName = "/refactoring/inlineToAnonymousClass/" + name + ".java";
configureByFile(fileName);
performAction(inlineThisOnly, searchInNonJavaFiles);
checkResultByFile(null, fileName + ".after", true);
}
private void doTestPreprocessUsages(final String expectedMessage) throws Exception {
final InlineToAnonymousClassProcessor processor = prepareProcessor();
String message = processor.getPreprocessUsagesMessage(processor.findUsages());
assertEquals(expectedMessage, message);
}
private InlineToAnonymousClassProcessor prepareProcessor() throws Exception {
String name = getTestName(false);
@NonNls String fileName = "/refactoring/inlineToAnonymousClass/" + name + ".java";
configureByFile(fileName);
PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase
.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
assertInstanceOf(element, PsiClass.class);
assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage((PsiClass) element));
return new InlineToAnonymousClassProcessor(getProject(), (PsiClass) element, null, false, false, false);
}
private void performAction(final boolean inlineThisOnly, final boolean searchInNonJavaFiles) {
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 InlineToAnonymousClassProcessor processor = new InlineToAnonymousClassProcessor(getProject(), classToInline, callToInline, inlineThisOnly,
false, searchInNonJavaFiles);
UsageInfo[] usages = processor.findUsages();
ArrayList<String> conflicts = processor.getConflicts(usages);
assertEquals(0, conflicts.size());
processor.run();
}
}