move OverrideImplementTest to community

This commit is contained in:
Dmitry Jemerov
2011-11-04 13:11:01 +01:00
parent bc99e8934e
commit 23dba4e6bd
22 changed files with 308 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
class A {
A() { }
A(String s) { }
}
class B extends A {
B() { super(); }
<caret>
}

View File

@@ -0,0 +1,12 @@
@interface ff{
String f() default "";
}
class d implements ff {
public String f() {
<caret><selection>return null; //To change body of implemented methods use File | Settings | File Templates.</selection>
}
public Class<? extends Annotation> annotationType() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@@ -0,0 +1,12 @@
class Gen {
protected Gen clone() {
return null;
}
}
class X2 extends Gen {
@Override
protected Gen clone() {
<caret><selection>return super.clone(); //To change body of overridden methods use File | Settings | File Templates.</selection>
}
}

View File

@@ -0,0 +1,5 @@
class S implements Runnable {
public void run() {
<caret><selection>//To change body of implemented methods use File | Settings | File Templates.</selection>
}
}

View File

@@ -0,0 +1,16 @@
public interface A {
void foo(String pppppppppppp1, String pppppppppppp2,String pppppppppppp3,String pppppppppppp4,String pppppppppppp5,String pppppppppppp6,String pppppppppppp7,String pppppppppppp8);
}
abstract class B implements A{
public void foo(final String pppppppppppp1,
final String pppppppppppp2,
final String pppppppppppp3,
final String pppppppppppp4,
final String pppppppppppp5,
final String pppppppppppp6,
final String pppppppppppp7,
final String pppppppppppp8) {
<caret><selection>//To change body of implemented methods use File | Settings | File Templates.</selection>
}
}

View File

@@ -0,0 +1,15 @@
public interface A {
void foo(String p1, String p2,String p3,String p4,String p5,String p6,String p7);
}
abstract class B implements A{
public void foo(String p1,
String p2,
String p3,
String p4,
String p5,
String p6,
String p7) {
<caret><selection>//To change body of implemented methods use File | Settings | File Templates.</selection>
}
}

View File

@@ -0,0 +1,12 @@
abstract class Base {
void foo(){}
}
class Sub extends Base {
int it;
@Override
void foo() {
<caret><selection>super.foo(); //To change body of overridden methods use File | Settings | File Templates.</selection>
}
}

View File

@@ -0,0 +1,10 @@
abstract class IX {
void foo(){}
}
class XXC extends IX {
@Override
void foo() {
<caret><selection>super.foo(); //To change body of overridden methods use File | Settings | File Templates.</selection>
}
}

View File

@@ -0,0 +1,10 @@
abstract class IX<T> {
abstract <S extends T> void foo(){}
}
class XXC<S> extends IX<Throwable> {
@Override
<S extends Throwable> void foo() {
<caret><selection>//To change body of implemented methods use File | Settings | File Templates.</selection>
}
}

View File

@@ -0,0 +1,11 @@
class f{
@org.testng.annotations.BeforeMethod
String foo() {return "";}
}
class ff extends f {
@Override
String foo() {
<selection>return super.foo(); //To change body of overridden methods use File | Settings | File Templates.</selection>
}
}

View File

@@ -0,0 +1,9 @@
interface Function<S, R> {
R fun(S s);
}
class Bar extends Function<String, ?>{
public Object fun(String s) {
<selection>return null; //To change body of implemented methods use File | Settings | File Templates.</selection>
}
}

View File

@@ -0,0 +1,9 @@
@interface ff{
String f() default "";
}
class d implements ff {
<caret>
public Class<? extends Annotation> annotationType() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@@ -0,0 +1,9 @@
class Gen {
protected Gen clone() {
return null;
}
}
class X2 extends Gen {
<caret>
}

View File

@@ -0,0 +1 @@
class S <caret>implements Runnable

View File

@@ -0,0 +1,7 @@
public interface A {
void foo(String pppppppppppp1, String pppppppppppp2,String pppppppppppp3,String pppppppppppp4,String pppppppppppp5,String pppppppppppp6,String pppppppppppp7,String pppppppppppp8);
}
abstract class B implements A{
<caret>
}

View File

@@ -0,0 +1,7 @@
public interface A {
void foo(String p1, String p2,String p3,String p4,String p5,String p6,String p7);
}
abstract class B implements A{
<caret>
}

View File

@@ -0,0 +1,7 @@
abstract class Base {
void foo(){}
}
class Sub extends Base {
int it;<caret>
}

View File

@@ -0,0 +1,7 @@
abstract class IX {
void foo(){}
}
class XXC extends IX {
<caret>
}

View File

@@ -0,0 +1,7 @@
abstract class IX<T> {
abstract <S extends T> void foo(){}
}
class XXC<S> extends IX<Throwable> {
<caret>
}

View File

@@ -0,0 +1,8 @@
class f{
@org.testng.annotations.BeforeMethod
String foo() {return "";}
}
class ff extends f {
<caret>
}

View File

@@ -0,0 +1,7 @@
interface Function<S, R> {
R fun(S s);
}
class Bar extends Function<String, ?>{
<caret>
}

View File

@@ -0,0 +1,118 @@
package com.intellij.codeInsight;
import com.intellij.codeInsight.generation.OverrideImplementUtil;
import com.intellij.codeInsight.generation.PsiMethodMember;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.util.MethodSignature;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import java.util.Collection;
import java.util.Collections;
/**
* @author ven
*/
public class OverrideImplementTest extends LightCodeInsightTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
setLanguageLevel(LanguageLevel.JDK_1_5);
}
public void testSimple() throws Exception { doTest(true); }
public void testAnnotation() throws Exception { doTest(true); }
public void testIncomplete() throws Exception { doTest(false); }
public void testSubstitutionInTypeParametersList() throws Exception { doTest(false); }
public void testTestMissed() throws Exception { doTest(false); }
public void testWildcard() throws Exception { doTest(false); }
public void testLongFinalParameterList() throws Exception {
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
try {
CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);
codeStyleSettings.RIGHT_MARGIN = 80;
javaSettings.KEEP_LINE_BREAKS = true;
codeStyleSettings.GENERATE_FINAL_PARAMETERS = true;
javaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(codeStyleSettings);
doTest(false);
}
finally {
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
}
}
public void testLongParameterList() throws Exception {
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
try {
CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);
codeStyleSettings.RIGHT_MARGIN = 80;
javaSettings.KEEP_LINE_BREAKS = false;
codeStyleSettings.GENERATE_FINAL_PARAMETERS = false;
javaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(codeStyleSettings);
doTest(false);
}
finally {
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
}
}
public void testClone() throws Exception {
doTest(false);
}
public void testOnTheLineWithExistingExpression() throws Exception {
doTest(false);
}
public void testImplementedConstructorsExcluded() throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/overrideImplement/" + name + ".java");
int offset = getEditor().getCaretModel().getOffset();
PsiElement context = getFile().findElementAt(offset);
PsiClass psiClass = PsiTreeUtil.getParentOfType(context, PsiClass.class);
assert psiClass != null;
final Collection<MethodSignature> signatures = OverrideImplementUtil.getMethodSignaturesToOverride(psiClass);
final Collection<String> strings = ContainerUtil.map(signatures, new Function<MethodSignature, String>() {
public String fun(MethodSignature signature) { return signature.toString(); }
});
assertTrue(strings.toString(), strings.contains("HierarchicalMethodSignatureImpl: A([PsiType:String])"));
assertFalse(strings.toString(), strings.contains("HierarchicalMethodSignatureImpl: A([])"));
}
private void doTest(boolean copyJavadoc) throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/overrideImplement/before" + name + ".java");
int offset = getEditor().getCaretModel().getOffset();
PsiElement context = getFile().findElementAt(offset);
PsiClass psiClass = PsiTreeUtil.getParentOfType(context, PsiClass.class);
assert psiClass != null;
PsiClassType[] implement = psiClass.getImplementsListTypes();
final PsiClass superClass = implement.length == 0 ? psiClass.getSuperClass() : implement[0].resolve();
assert superClass != null;
PsiMethod method = superClass.getMethods()[0];
final PsiMethodMember member2Override = new PsiMethodMember(method,
TypeConversionUtil.getSuperClassSubstitutor(superClass, psiClass,
PsiSubstitutor.EMPTY));
OverrideImplementUtil.overrideOrImplementMethodsInRightPlace(getEditor(), psiClass, Collections.singletonList(member2Override),
copyJavadoc, true);
checkResultByFile("/codeInsight/overrideImplement/after" + name + ".java");
}
}