moving tests from codeInsight-tests to community

This commit is contained in:
Dmitry Jemerov
2015-02-11 15:07:16 +01:00
parent 9dee6e8ff3
commit c25243f74d
78 changed files with 1449 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
class List {
/**
* javadoc must be present, see SCR 39108
*/
void foo() {}
}
class Test {
List l;
public void foo() {
l.foo();
}
}

View File

@@ -0,0 +1,14 @@
class A {
void methodA() {};
final void methodB() {};
}
class B {
private A a;
public void methodA() {
a.methodA();
}
}

View File

@@ -0,0 +1,31 @@
public class K {
@A("unused")
void kkkk(){}
}
@interface A {
String[] value();
}
class KImpl extends K {}
abstract class InspectionToolWrapper<T extends K> {
T myTool;
protected InspectionToolWrapper(T tool) {
myTool = tool;
}
public T getTool() {
return myTool;
}
}
class CommonInspectionToolWrapper extends InspectionToolWrapper<KImpl>{
protected CommonInspectionToolWrapper(KImpl tool) {
super(tool);
}
@A("unused")
public void kkkk() {
myTool.kkkk();
}
}

View File

@@ -0,0 +1,17 @@
class List {
/**
* comment
*/
void foo() {}
}
class Test {
List l;
/**
* comment
*/
public void foo() {
l.foo();
}
}

View File

@@ -0,0 +1,6 @@
class Test {
String s;
static class S {
<caret>
}
}

View File

@@ -0,0 +1,17 @@
class A {
void foo() {}
}
class Test {
Runnable r = new Runnable() {
public void foo() {
a.foo();
}
public void run() {
}
};
private A a;
}

View File

@@ -0,0 +1,13 @@
class A<T> {
public T get(T key) {
return null;
}
}
class B<K> extends A<K> {
private A<String> a;
public String get(String key) {
return a.get(key);
}
}

View File

@@ -0,0 +1,14 @@
class A<T> {
public T get(T key) {
return null;
}
}
class B<K> extends A<K> {
private A<K> a;
@Override
public K get(K key) {
return a.get(key);
}
}

View File

@@ -0,0 +1,15 @@
class A {
void methodA() {};
final void methodB() {};
}
class B extends A {
private A a;
@Override
public void methodA() {
a.methodA();
}
}

View File

@@ -0,0 +1,14 @@
class List {
@SuppressWarnings
@Deprecated
void foo() {}
}
class Test {
List l;
@Deprecated
static void foo() {
l.foo();
}
}

View File

@@ -0,0 +1,17 @@
interface B0 {
void foo();
}
class A3 implements B0{
@Override
public void foo() {}
}
class B3 implements A3 {
B3 myDelegate;
@Override
public void foo() {
myDelegate.foo();
}
}

View File

@@ -0,0 +1,11 @@
class List {
static void foo() {}
}
class Test {
List l;
public static void foo() {
List.foo();
}
}

View File

@@ -0,0 +1,14 @@
public class Boo {
@SuppressWarnings("UnusedDeclaration")
public void foo() {
}
}
class BooI {
Boo boo;
public void foo() {
boo.foo();
}
}

View File

@@ -0,0 +1,27 @@
public class K {
void kkkk(){}
}
class KImpl extends K {}
abstract class InspectionToolWrapper<T extends K> {
T myTool;
protected InspectionToolWrapper(T tool) {
myTool = tool;
}
public T getTool() {
return myTool;
}
}
class CommonInspectionToolWrapper extends InspectionToolWrapper<KImpl>{
protected CommonInspectionToolWrapper(KImpl tool) {
super(tool);
}
public void kkkk() {
myTool.kkkk();
}
}

View File

@@ -0,0 +1,11 @@
interface MyInterface {
int myMethod();
}
class MyTemplatedClass<T extends MyInterface> {
protected T myInterfaceField;
public int myMethod() {
return myInterfaceField.myMethod();
}
}

View File

@@ -0,0 +1,11 @@
class List {
/**
* javadoc must be present, see SCR 39108
*/
void foo() {}
}
class Test {
List l;
<caret>
}

View File

@@ -0,0 +1,13 @@
class A {
void methodA() {};
final void methodB() {};
}
class B {
private A a;
<caret>
}

View File

@@ -0,0 +1,28 @@
public class K {
@A("unused")
void kkkk(){}
}
@interface A {
String[] value();
}
class KImpl extends K {}
abstract class InspectionToolWrapper<T extends K> {
T myTool;
protected InspectionToolWrapper(T tool) {
myTool = tool;
}
public T getTool() {
return myTool;
}
}
class CommonInspectionToolWrapper extends InspectionToolWrapper<KImpl>{
protected CommonInspectionToolWrapper(KImpl tool) {
super(tool);
}
<caret>
}

View File

@@ -0,0 +1,12 @@
class List {
/**
* comment
*/
void foo() {}
}
class Test {
List l;
<caret>
}

View File

@@ -0,0 +1,6 @@
class Test {
String s;
static class S {
<caret>
}
}

View File

@@ -0,0 +1,14 @@
class A {
void foo() {}
}
class Test {
Runnable r = new Runnable() {
<caret>
public void run() {
}
};
private A a;
}

View File

@@ -0,0 +1,12 @@
class A<T> {
public T get(T key) {
return null;
}
}
class B<K> extends A<K> {
private A<String> a;
<caret>
}

View File

@@ -0,0 +1,12 @@
class A<T> {
public T get(T key) {
return null;
}
}
class B<K> extends A<K> {
private A<K> a;
<caret>
}

View File

@@ -0,0 +1,13 @@
class A {
void methodA() {};
final void methodB() {};
}
class B extends A {
private A a;
<caret>
}

View File

@@ -0,0 +1,15 @@
class List {
@SuppressWarnings
@Deprecated
void foo() {}
}
class Test {
List l;
@Deprecated
static void foo() {
l.foo();
}
<caret>
}

View File

@@ -0,0 +1,14 @@
interface B0 {
void foo();
}
class A3 implements B0{
@Override
public void foo() {}
}
class B3 implements A3 {
B3 myDelegate;
<caret>
}

View File

@@ -0,0 +1,8 @@
class List {
static void foo() {}
}
class Test {
List l;
<caret>
}

View File

@@ -0,0 +1,11 @@
public class Boo {
@SuppressWarnings("UnusedDeclaration")
public void foo() {
}
}
class BooI {
Boo boo;
<caret>
}

View File

@@ -0,0 +1,25 @@
public class K {
void kkkk(){}
}
class KImpl extends K {}
abstract class InspectionToolWrapper<T extends K> {
T myTool;
protected InspectionToolWrapper(T tool) {
myTool = tool;
}
public T getTool() {
return myTool;
}
}
class CommonInspectionToolWrapper extends InspectionToolWrapper<KImpl>{
protected CommonInspectionToolWrapper(KImpl tool) {
super(tool);
}
<caret>
}

View File

@@ -0,0 +1,9 @@
interface MyInterface {
int myMethod();
}
class MyTemplatedClass<T extends MyInterface> {
protected T myInterfaceField;
<caret>
}

View File

@@ -0,0 +1,9 @@
class Test {
<caret>
private class Inner {
}
}

View File

@@ -0,0 +1,11 @@
class Test {
public void foo() {<caret>
}
private class Inner {
}
}

View File

@@ -0,0 +1,4 @@
public class Test
{
//ddd<caret>
}

View File

@@ -0,0 +1,7 @@
public class Test
{
//ddd
public void foo() {
}
}

View File

@@ -0,0 +1,3 @@
public <caret>class Test
{
}

View File

@@ -0,0 +1,5 @@
public class Test
{
public void foo() {<caret>
}
}

View File

@@ -0,0 +1,7 @@
public class Test {
public void foo1(){
}
<caret>
public void foo2(){
}
}

View File

@@ -0,0 +1,10 @@
public class Test {
public void foo1(){
}
public void foo() {<caret>
}
public void foo2(){
}
}

View File

@@ -0,0 +1,4 @@
public class Test {
// comment
<caret>
}

View File

@@ -0,0 +1,6 @@
public class Test {
// comment
public void foo() {<caret>
}
}

View File

@@ -0,0 +1,3 @@
public class Test<caret>
{
}

View File

@@ -0,0 +1,5 @@
public class Test
{
public void foo() {<caret>
}
}

View File

@@ -0,0 +1,4 @@
public class Test
{
private int x, <caret>y, z;
}

View File

@@ -0,0 +1,4 @@
public class Test
{
private int x,<caret> y, z;
}

View File

@@ -0,0 +1,10 @@
public class Test
{
private int x;
public void foo() {<caret>
}
private int y;
private int z;
}

View File

@@ -0,0 +1,4 @@
public class Test
{
private int x<caret>, y, z;
}

View File

@@ -0,0 +1,10 @@
public class Test
{
private int x;
public void foo() {<caret>
}
private int y;
private int z;
}

View File

@@ -0,0 +1,10 @@
public class Test
{
private int x;
public void foo() {<caret>
}
private int y;
private int z;
}

View File

@@ -0,0 +1,10 @@
class s implements Runnable {
public void run() {
}
}
class Over extends s {
public void run() {
<caret>super.run();
}
}

View File

@@ -0,0 +1,6 @@
class s implements Runnable {
public void run() {
<caret>
}
}

View File

@@ -0,0 +1,9 @@
class s implements Runnable {
public void run() {
}
}
class Over extends s {
public void run() {<caret>
}
}

View File

@@ -0,0 +1,3 @@
class X {
String usedToOpenInProjectView2 = "/java/lang<caret>";
}

View File

@@ -0,0 +1,9 @@
import java.lang.String;
class X {
X(int i){}
X(String s){}
{
new <caret>X();
}
}

View File

@@ -0,0 +1,5 @@
class X {
{
String[] arg = new Stri<caret>ng[1];
}
}

View File

@@ -0,0 +1,11 @@
class SomeClass {
public static final Object OBJECT_OVERRIDDEN = new Object() {
public String toString() {
return "";
}
};
public String get() {
return OBJECT_OVERRIDDEN.to<caret>String();
}
}

View File

@@ -0,0 +1,11 @@
class SomeClass {
public static final Object OBJECT_OVERRIDDEN = new Object() {
public String <caret>toString() {
return "";
}
};
public String get() {
return OBJECT_OVERRIDDEN.toString();
}
}

View File

@@ -0,0 +1,8 @@
class Test{
{
while(true){
foo();
<caret>break;
}
}
}

View File

@@ -0,0 +1,8 @@
class Test{
void foo() {
Label:
for ( ; ; ) {
<caret>break;
}
}
}

View File

@@ -0,0 +1,8 @@
class Test{
void foo() {
Label:
for ( ; ; ) {
break;
}<caret>
}
}

View File

@@ -0,0 +1,9 @@
class Test{
{
Label:
while(true){
foo();
break <caret>Label;
}
}
}

View File

@@ -0,0 +1,9 @@
class Test{
{
<caret>Label:
while(true){
foo();
break Label;
}
}
}

View File

@@ -0,0 +1,8 @@
class Test{
{
while(true){
foo();
break;
}<caret>
}
}

View File

@@ -0,0 +1,8 @@
class Test{
{
while(true){
foo();
<caret>continue;
}
}
}

View File

@@ -0,0 +1,9 @@
class Test{
{
Label:
while(true){
foo();
continue <caret>Label;
}
}
}

View File

@@ -0,0 +1,9 @@
class Test{
{
<caret>Label:
while(true){
foo();
continue Label;
}
}
}

View File

@@ -0,0 +1,8 @@
class Test{
{
<caret>while(true){
foo();
continue;
}
}
}

View File

@@ -0,0 +1,11 @@
import java.util.List;
import java.util.ArrayList;
public class Test {
{
List list;
list.add("abcd");
<caret>list
}
}

View File

@@ -0,0 +1,9 @@
class MyList<T> {}
public class Test {
{
MyList<String> list;
<caret>list
}
}

View File

@@ -0,0 +1,11 @@
import java.util.List;
import java.util.ArrayList;
public class Test {
public void foo(Object o){
if (o instanceof String){
<selection>o</selection>
}
}
}

View File

@@ -0,0 +1,11 @@
import java.util.List;
import java.util.ArrayList;
public class Test {
{
List list;
list.add("abcd");
<selection>list.get(0)</selection>
}
}

View File

@@ -0,0 +1,96 @@
package com.intellij.codeInsight;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.generation.GenerateDelegateHandler;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NotNull;
/**
* @author ven
*/
public class DelegateMethodsTest extends LightCodeInsightTestCase {
private static final String BASE_PATH = "/codeInsight/delegateMethods/";
@NotNull
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void testMethodWithJavadoc () throws Exception {
doTest("1");
}
public void testStaticMemberWithNonStaticField() throws Exception {
doTest(getTestName(false));
}
public void testTypeParam() throws Exception {
doTest(getTestName(false));
}
public void testExistingMethodWithAnnotation() throws Exception {
doTest(getTestName(false));
}
public void testDelegateToContainingClassField() throws Exception {
doTest(getTestName(false));
}
public void testDelegateFromStaticClassField() throws Exception {
doTest(getTestName(false));
}
public void testCopyJavadoc() throws Exception {
String testName = getTestName(false);
configureByFile(BASE_PATH + "before" + testName + ".java");
final GenerateDelegateHandler handler = new GenerateDelegateHandler();
try {
handler.setToCopyJavaDoc(true);
handler.invoke(getProject(), getEditor(), getFile());
}
finally {
handler.setToCopyJavaDoc(false);
}
checkResultByFile(BASE_PATH + "after" + testName + ".java");
}
public void testSuperSubstitution() throws Exception {
doTest(getTestName(false));
}
public void testCopyAnnotationWithParams() throws Exception {
doTest(getTestName(false));
}
public void testMultipleOverrideAnnotations() throws Exception {
doTest(getTestName(false));
}
public void testStripSuppressWarningsAnnotation() throws Exception {
doTest(getTestName(false));
}
public void testDoNotOverrideFinal() throws Exception {
doTest(getTestName(false));
}
public void testAllowDelegateToFinal() throws Exception {
doTest(getTestName(false));
}
public void testDelegateWithSubstitutionOverrides() throws Exception {
doTest(getTestName(false));
}
public void testDelegateWithSubstitutionNoOverrides() throws Exception {
doTest(getTestName(false));
}
private void doTest(String testName) throws Exception {
configureByFile(BASE_PATH + "before" + testName+ ".java");
new GenerateDelegateHandler().invoke(getProject(), getEditor(), getFile());
checkResultByFile(BASE_PATH + "after" + testName + ".java");
}
}

View File

@@ -0,0 +1,155 @@
package com.intellij.codeInsight;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NonNls;
import java.util.List;
import java.util.Collection;
/**
* @author mike
*/
public class ExceptionCheckingTest extends LightCodeInsightTestCase {
public void testNoExceptions() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() { System.out.println(); }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertTrue(exceptions.isEmpty());
}
public void testCheckedUnhandledException() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() { throwsIOException(); }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertEquals(1, exceptions.size());
assertEquals("java.io.IOException", exceptions.get(0).getCanonicalText());
}
public void testCheckedDeclaredException() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() throws java.io.IOException { throwsIOException(); }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertTrue(exceptions.isEmpty());
}
public void testCheckedDeclaredAncestorException() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() throws Exception { throwsIOException(); }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertTrue(exceptions.isEmpty());
}
public void testCheckedDeclaredAnotherException() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() throws IllegalAccessException { throwsIOException(); }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertEquals(1, exceptions.size());
assertEquals("java.io.IOException", exceptions.get(0).getCanonicalText());
}
public void testCheckedCatchedException() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() { try { throwsIOException(); } catch (java.io.IOException e) {} }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertTrue(exceptions.isEmpty());
}
public void testCheckedLikeCatchedException() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() { try { } catch (java.io.IOException e) {throwsIOException();} }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertEquals(1, exceptions.size());
assertEquals("java.io.IOException", exceptions.get(0).getCanonicalText());
}
public void testCheckedCatchedAncestorException() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() { try { throwsIOException(); } catch (Exception e) {} }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertTrue(exceptions.isEmpty());
}
public void testCheckedCatchedAnotherException() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() { try { throwsIOException(); } catch (IllegalAccessException e) {} }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertEquals(1, exceptions.size());
assertEquals("java.io.IOException", exceptions.get(0).getCanonicalText());
}
public void testRuntimeException() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() { throwsRuntimeException(); }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertTrue(exceptions.isEmpty());
}
public void testError() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() { throwsError(); }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertTrue(exceptions.isEmpty());
}
public void testArray() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() { int[] arr; arr.clone(); }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(methodCall, null);
assertTrue(exceptions.isEmpty());
}
public void testConstructor1() throws Exception {
final PsiNewExpression newExpression = createNewExpression("void foo() { new ClassIOException(); }");
List<PsiClassType> exceptions = ExceptionUtil.getUnhandledExceptions(newExpression, null);
assertEquals(1, exceptions.size());
assertEquals("java.io.IOException", exceptions.get(0).getCanonicalText());
}
public void testCollectExceptionsInTryCatch() throws Exception {
PsiMethodCallExpression methodCall = createCall("void foo() { try { throwsIOException(); } catch (java.io.Exception e) {} }");
PsiTryStatement statement = PsiTreeUtil.getParentOfType(methodCall, PsiTryStatement.class);
final Collection<PsiClassType> exceptions = ExceptionUtil.collectUnhandledExceptions(statement.getTryBlock(), statement.getTryBlock());
assertEquals(1, exceptions.size());
assertEquals("java.io.IOException", exceptions.iterator().next().getCanonicalText());
}
private static PsiMethodCallExpression createCall(@NonNls final String body) throws Exception {
final PsiFile file = createFile("test.java", "class Test { " + body +
"void throwsIOException() throws java.io.IOException {}" +
"void throwsRuntimeException() throws RuntimeException {}" +
"void throwsError() throws Error {}" +
"}");
PsiMethodCallExpression methodCall = findMethodCall(file);
assertNotNull(methodCall);
return methodCall;
}
private static PsiNewExpression createNewExpression(@NonNls final String body) throws Exception {
final PsiFile file = createFile("test.java", "class Test { " + body +
"class ClassIOException { ClassIOException() throws java.io.IOException {} }" +
"class ClassError { ClassError() throws Error {} }" +
"class ClassRuntime { ClassRuntime() throws RuntimeException {} }" +
"}");
PsiNewExpression newExpression = findNewExpression(file);
assertNotNull(newExpression);
return newExpression;
}
private static PsiNewExpression findNewExpression(PsiElement element) {
if (element instanceof PsiNewExpression) {
return (PsiNewExpression)element;
}
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
final PsiNewExpression expression = findNewExpression(child);
if (expression != null) return expression;
}
return null;
}
private static PsiMethodCallExpression findMethodCall(PsiElement element) {
if (element instanceof PsiMethodCallExpression) {
return (PsiMethodCallExpression)element;
}
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
final PsiMethodCallExpression call = findMethodCall(child);
if (call != null) return call;
}
return null;
}
}

View File

@@ -0,0 +1,180 @@
/*
* Created by IntelliJ IDEA.
* User: mike
* Date: Aug 19, 2002
* Time: 5:40:30 PM
* To change template for new class use
* Code Style | Class Templates options (Tools | IDE Options).
*/
package com.intellij.codeInsight;
import com.intellij.psi.CommonClassNames;
import com.intellij.psi.PsiType;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NotNull;
public class ExpectedTypeInfoTest extends LightCodeInsightTestCase {
public void testIntersectStrictStrict1() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo info2 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(1, result.length);
assertEquals(ExpectedTypeInfo.TYPE_STRICTLY, result[0].getKind());
assertTrue(result[0].getType().equalsToText("java.lang.Exception"));
}
public void testIntersectStrictStrict2() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo info2 = createInfo(CommonClassNames.JAVA_LANG_OBJECT, ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(result.length, 0);
}
public void testIntersectSubtypeStrict1() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo info2 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(1, result.length);
assertEquals(ExpectedTypeInfo.TYPE_STRICTLY, result[0].getKind());
assertTrue(result[0].getType().equalsToText("java.io.IOException"));
}
public void testIntersectSubtypeStrict2() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo info2 = createInfo(CommonClassNames.JAVA_LANG_OBJECT, ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(result.length, 0);
}
public void testIntersectSupertypeStrict1() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo info2 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(1, result.length);
assertEquals(ExpectedTypeInfo.TYPE_STRICTLY, result[0].getKind());
assertTrue(result[0].getType().equalsToText("java.lang.Exception"));
}
public void testIntersectSupertypeStrict2() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo info2 = createInfo("java.io.EOFException", ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(result.length, 0);
}
public void testIntersectStrictSubtype1() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo info2 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(1, result.length);
assertEquals(ExpectedTypeInfo.TYPE_STRICTLY, result[0].getKind());
assertTrue(result[0].getType().equalsToText("java.io.IOException"));
}
public void testIntersectStrictSubtype2() throws Exception {
ExpectedTypeInfo info1 = createInfo(CommonClassNames.JAVA_LANG_OBJECT, ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo info2 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(result.length, 0);
}
public void testIntersectStrictSupertype1() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo info2 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(1, result.length);
assertEquals(ExpectedTypeInfo.TYPE_STRICTLY, result[0].getKind());
assertTrue(result[0].getType().equalsToText("java.lang.Exception"));
}
public void testIntersectStrictSupertype2() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.io.EOFException", ExpectedTypeInfo.TYPE_STRICTLY);
ExpectedTypeInfo info2 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(result.length, 0);
}
public void testIntersectSubtypeSubtype1() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo info2 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(1, result.length);
assertEquals(ExpectedTypeInfo.TYPE_OR_SUBTYPE, result[0].getKind());
assertTrue(result[0].getType().equalsToText("java.io.IOException"));
}
public void testIntersectSubtypeSubtype2() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo info2 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(1, result.length);
assertEquals(ExpectedTypeInfo.TYPE_OR_SUBTYPE, result[0].getKind());
assertTrue(result[0].getType().equalsToText("java.io.IOException"));
}
public void testIntersectSubtypeSubtype3() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo info2 = createInfo("javax.swing.JButton", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(result.length, 0);
}
public void testIntersectSuperSuper1() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.io.EOFException", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo info2 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(1, result.length);
assertEquals(ExpectedTypeInfo.TYPE_OR_SUPERTYPE, result[0].getKind());
assertTrue(result[0].getType().equalsToText("java.io.IOException"));
}
public void testIntersectSuperSuper2() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo info2 = createInfo("java.io.EOFException", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(1, result.length);
assertEquals(ExpectedTypeInfo.TYPE_OR_SUPERTYPE, result[0].getKind());
assertTrue(result[0].getType().equalsToText("java.io.IOException"));
}
public void testIntersectSuperSuper3() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.io.IOException", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo info2 = createInfo("javax.swing.JButton", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertEquals(result.length, 0);
}
public void testIntersectSubSuper1() throws Exception {
ExpectedTypeInfo info1 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_OR_SUBTYPE);
ExpectedTypeInfo info2 = createInfo("java.io.EOFException", ExpectedTypeInfo.TYPE_OR_SUPERTYPE);
ExpectedTypeInfo[] result = info1.intersect(info2);
assertNotNull(result);
assertEquals(1, result.length);
assertEquals(ExpectedTypeInfo.TYPE_OR_SUPERTYPE, result[0].getKind());
assertTrue(result[0].getType().equalsToText("java.io.EOFException"));
}
@NotNull
private static ExpectedTypeInfo createInfo(String className, @ExpectedTypeInfo.Type int kind) throws Exception{
PsiType type = getJavaFacade().getElementFactory().createTypeByFQClassName(className, GlobalSearchScope.allScope(getProject()));
return ExpectedTypesProvider.createInfo(type, kind, type, TailType.NONE);
}
}

View File

@@ -0,0 +1,56 @@
package com.intellij.codeInsight;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.generation.GenerateMembersUtil;
import com.intellij.codeInsight.generation.GenerationInfo;
import com.intellij.codeInsight.generation.PsiGenerationInfo;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiType;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class GenerateMembersUtilTest extends LightCodeInsightTestCase {
@NonNls private static final String BASE_PATH = "/codeInsight/generateMembersUtil/";
@NotNull
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void testBeforeInner() throws Exception {
doTest();
}
public void testNoExtraEmptyLine() throws Exception {
doTest();
}
public void testNoRemoveComment() throws Exception { doTest(); }
public void testSCR5798() throws Exception { doTest(); }
public void testSCR6491() throws Exception { doTest(); }
public void testSCR6491_1() throws Exception { doTest(); }
public void testSCR6491_2() throws Exception { doTest(); }
public void testCaretAtDeclaration() throws Exception { doTest(); }
public void testCaretAfterComment() throws Exception { doTest(); }
private void doTest() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
PsiMethod method = factory.createMethod("foo", PsiType.VOID);
int offset = getEditor().getCaretModel().getOffset();
List<GenerationInfo> list = Collections.<GenerationInfo>singletonList(new PsiGenerationInfo<PsiMethod>(method));
List<GenerationInfo> members = GenerateMembersUtil.insertMembersAtOffset(getFile(), offset, list);
members.get(0).positionCaret(myEditor, true);
checkResultByFile(null, BASE_PATH + getTestName(false) + "_after.java", true);
}
}

View File

@@ -0,0 +1,51 @@
package com.intellij.codeInsight;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.generation.actions.GenerateSuperMethodCallAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NotNull;
import java.io.File;
public class GenerateSuperMethodCallTest extends LightCodeInsightTestCase {
@NotNull
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void testImplement() throws Exception { doTest(); }
public void testOverride() throws Exception { doTest(); }
private void doTest() throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/generateSuperMethodCall/before" +
name +
".java");
String after = "/codeInsight/generateSuperMethodCall/after" + name + ".java";
boolean mustBeAvailable = new File(getTestDataPath() + after).exists();
boolean isValid = new GenerateSuperMethodCallAction() {
@Override
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull final PsiFile file) {
return super.isValidForFile(project, editor, file);
}
}.isValidForFile(getProject(), getEditor(), getFile());
assertEquals(mustBeAvailable, isValid);
if (mustBeAvailable) {
CodeInsightActionHandler handler = new GenerateSuperMethodCallAction() {
@NotNull
@Override
protected CodeInsightActionHandler getHandler() {
return super.getHandler();
}
}.getHandler();
handler.invoke(getProject(), getEditor(), getFile());
checkResultByFile(after);
}
}
}

View File

@@ -0,0 +1,47 @@
package com.intellij.codeInsight.guess;
import com.intellij.JavaTestUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiReferenceExpression;
import com.intellij.psi.PsiType;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NotNull;
public class GuessContainerElementTypeTest extends LightCodeInsightTestCase {
private static final String BASE_PATH = "/codeInsight/guess/containerElement";
@NotNull
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void test1() throws Exception{
configureByFile(BASE_PATH + "/Test1.java");
PsiType[] result = guessContainerElementTypes();
assertNotNull(result);
assertEquals(result.length, 1);
assertTrue(result[0].equalsToText("java.lang.String"));
}
public void test2() throws Exception{
configureByFile(BASE_PATH + "/Test2.java");
PsiType[] result = guessContainerElementTypes();
assertNotNull(result);
assertEquals(result.length, 1);
assertTrue(result[0].equalsToText("java.lang.String"));
}
private PsiType[] guessContainerElementTypes() {
int offset = getEditor().getCaretModel().getOffset();
PsiElement element = getFile().findElementAt(offset);
assertNotNull(element);
PsiElement parent = element.getParent();
assertTrue(parent instanceof PsiReferenceExpression);
PsiExpression expr = (PsiExpression)parent;
return GuessManager.getInstance(getProject()).guessContainerElementType(expr, null);
}
}

View File

@@ -0,0 +1,41 @@
package com.intellij.codeInsight.guess;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.psi.CommonClassNames;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiType;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.annotations.NotNull;
public class GuessExprTypeTest extends LightCodeInsightTestCase {
private static final String BASE_PATH = "/codeInsight/guess/exprType";
@NotNull
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void test1() throws Exception{
configureByFile(BASE_PATH + "/Test1.java");
PsiType[] result = guessExprTypes();
assertEquals(CommonClassNames.JAVA_LANG_STRING, assertOneElement(result).getCanonicalText());
}
public void test2() throws Exception{
configureByFile(BASE_PATH + "/Test2.java");
PsiType[] result = guessExprTypes();
assertNotNull(result);
assertEquals(CommonClassNames.JAVA_LANG_STRING, assertOneElement(result).getCanonicalText());
}
private static PsiType[] guessExprTypes() {
int offset1 = getEditor().getSelectionModel().getSelectionStart();
int offset2 = getEditor().getSelectionModel().getSelectionEnd();
PsiExpression expr = CodeInsightUtil.findExpressionInRange(getFile(), offset1, offset2);
assertNotNull(expr);
return GuessManager.getInstance(getProject()).guessTypeToCast(expr);
}
}

View File

@@ -0,0 +1,79 @@
package com.intellij.codeInsight.navigation;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.psi.*;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collection;
public class GotoDeclarationTest extends LightCodeInsightTestCase {
@NotNull
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void testContinue() throws Exception { doTest(); }
public void testContinueLabel() throws Exception { doTest(); }
public void testBreak() throws Exception { doTest(); }
public void testBreak1() throws Exception { doTest(); }
public void testBreakLabel() throws Exception { doTest(); }
public void testAnonymous() throws Exception { doTest(); }
private static void performAction() {
PsiElement element = GotoDeclarationAction.findTargetElement(getProject(), getEditor(), getEditor().getCaretModel().getOffset());
assertEquals(getFile(), element.getContainingFile());
getEditor().getCaretModel().moveToOffset(element.getTextOffset());
getEditor().getScrollingModel().scrollToCaret(ScrollType.CENTER);
getEditor().getSelectionModel().removeSelection();
}
private void doTest() throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/gotoDeclaration/continueAndBreak/" + name + ".java");
performAction();
checkResultByFile("/codeInsight/gotoDeclaration/continueAndBreak/" + name + "_after.java");
}
public void testGotoDirectory() throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/gotoDeclaration/" + name + ".java");
PsiDirectory element = (PsiDirectory)GotoDeclarationAction.findTargetElement(getProject(), getEditor(), getEditor().getCaretModel().getOffset());
assertEquals("java.lang", JavaDirectoryService.getInstance().getPackage(element).getQualifiedName());
}
public void testMultipleConstructors() throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/gotoDeclaration/" + name + ".java");
final int offset = getEditor().getCaretModel().getOffset();
final PsiElement[] elements =
GotoDeclarationAction.findAllTargetElements(getProject(), getEditor(), offset);
assertEquals(Arrays.asList(elements).toString(), 0, elements.length);
final TargetElementUtilBase elementUtilBase = TargetElementUtilBase.getInstance();
final PsiReference reference = getFile().findReferenceAt(offset);
assertNotNull(reference);
final Collection<PsiElement> candidates = elementUtilBase.getTargetCandidates(reference);
assertEquals(candidates.toString(), 2, candidates.size());
}
public void testMultipleConstructorsButArrayCreation() throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/gotoDeclaration/" + name + ".java");
final int offset = getEditor().getCaretModel().getOffset();
final PsiReference reference = getFile().findReferenceAt(offset);
assertNotNull(reference);
final Collection<PsiElement> candidates = TargetElementUtilBase.getInstance().getTargetCandidates(reference);
assertEquals(candidates.toString(), 1, candidates.size());
final PsiElement item = ContainerUtil.getFirstItem(candidates);
assertNotNull(item);
assertTrue(item instanceof PsiClass && CommonClassNames.JAVA_LANG_STRING.equals(((PsiClass)item).getQualifiedName()));
}
}