do not need parenthesis for associative operations (IDEADEV-41569); move to java-tests

This commit is contained in:
anna
2009-11-25 14:39:43 +03:00
parent ac7d7872ee
commit c317da06f1
116 changed files with 1340 additions and 2 deletions
@@ -48,7 +48,7 @@ public class ReplaceExpressionUtil implements Constants {
else if (i == BINARY_EXPRESSION) {
if (priority < parentPriority) return true;
final IElementType opType = ((PsiBinaryExpression)SourceTreeToPsiMap.treeElementToPsi(oldParent)).getOperationSign().getTokenType();
return ((CompositeElement)oldParent).getChildRole(oldExpr) == ChildRole.LOPERAND ? false : opType != PLUS && opType != ASTERISK;
return ((CompositeElement)oldParent).getChildRole(oldExpr) == ChildRole.LOPERAND ? false : opType != PLUS && opType != ASTERISK && opType != ANDAND;
}
else if (i == INSTANCE_OF_EXPRESSION) {
return priority < parentPriority;
@@ -158,4 +158,4 @@ public class ReplaceExpressionUtil implements Constants {
return -1;
}
}
}
}
@@ -0,0 +1,6 @@
class A {
public void test(boolean a, boolean b) {
final boolean ab = a && b;
if (true && ab);
}
}
@@ -0,0 +1,5 @@
class A {
public void test(boolean a, boolean b) {
if (true && <selection>a && b</selection>);
}
}
@@ -0,0 +1,10 @@
class Test {
public void method() {
final int temp = 1 + 2;
Runnable r = new Runnable() {
public void run() {
int i = temp;
}
};
}
}
@@ -0,0 +1,10 @@
class Test {
public void method() {
1 + 2 <caret>
Runnable r = new Runnable() {
public void run() {
int i = 1 + 2;
}
};
}
}
@@ -0,0 +1,9 @@
class A {
static {
Runnable runnable = new Runnable() {
public void run() {
}
};
System.out.println(runnable);
}
}
@@ -0,0 +1,8 @@
class A {
static {
System.out.println(<selection>new Runnable() {
public void run() {
}
}</selection>);
}
}
@@ -0,0 +1,13 @@
public class TestClass {
void x() {
new Exception() {
int doSomething() { return 1; }
void a() {
int j = doSomething();
}
void b() {
doSomething();
}
};
}
}
@@ -0,0 +1,13 @@
public class TestClass {
void x() {
new Exception() {
int doSomething() { return 1; }
void a() {
<selection>doSomething()</selection>;
}
void b() {
doSomething();
}
};
}
}
@@ -0,0 +1,8 @@
class A {
private int name;
public void method() {
System.out.println(name);
String name = "xyz";
System.out.println(this.name);
}
}
@@ -0,0 +1,8 @@
class A {
private int name;
public void method() {
System.out.println(name);
<selection>"xyz"</selection>
System.out.println(name);
}
}
@@ -0,0 +1,8 @@
class A {
private int name;
public void method() {
System.out.println(name);
int name = this.name;
System.out.println(this.name);
}
}
@@ -0,0 +1,8 @@
class A {
private int name;
public void method() {
System.out.println(name);
<selection>name</selection>
System.out.println(name);
}
}
@@ -0,0 +1,9 @@
public class Test4 {
String text = "Hello world!";
private class Q {
void foo() {
final String text = Test4.this.text;
System.out.println("text = " + text);
}
}
}
@@ -0,0 +1,8 @@
public class Test4 {
String text = "Hello world!";
private class Q {
void foo() {
System.out.println("text = " + <selection>text</selection>);
}
}
}
@@ -0,0 +1,12 @@
class Foo2<T> {
Foo2<? extends Runnable> getList() {
return null;
}
{
Foo2<T> f = new Foo2<T>();
Foo2<? extends Runnable> temp = f.getList();
Object a = temp;
Object b = temp;
}
}
@@ -0,0 +1,11 @@
class Foo2<T> {
Foo2<? extends Runnable> getList() {
return null;
}
{
Foo2<T> f = new Foo2<T>();
Object a = <selection>f.getList()</selection>;
Object b = f.getList();
}
}
@@ -0,0 +1,9 @@
class Tester {
void method() {
final int[] ints = {1};
f(ints);
}
private void f(int[] ints) {
}
}
@@ -0,0 +1,8 @@
class Tester {
void method() {
f(<selection>new int[]{1}</selection>);
}
private void f(int[] ints) {
}
}
@@ -0,0 +1,9 @@
class Bar {
void bar(Object[] components) {
for (int i = 0; i < components.length; ++i) {
final Object component = components[i];
if (component != null)
addChildren(component);
}
}
}
@@ -0,0 +1,7 @@
class Bar {
void bar(Object[] components) {
for (int i = 0; i < components.length; ++i)
if (<selection>components[i]</selection> != null)
addChildren(components[i]);
}
}
@@ -0,0 +1,12 @@
public class C {
{
Object o = getO();
String s;
if (o == null)
s = "";
else {
String s1 = o.toString();
s = s1;
}
}
}
@@ -0,0 +1,9 @@
public class C {
{
Object o = getO();
String s;
if (o == null)
s = "";
else s = <selection>o.toString()</selection>;
}
}
@@ -0,0 +1,8 @@
class Test {
public void method() {
for(int i = 0; i < 100; i++) {
int temp = i * 2;
sum += temp;
}
}
}
@@ -0,0 +1,6 @@
class Test {
public void method() {
for(int i = 0; i < 100; i++)
sum += <selection>i * 2</selection>;
}
}
@@ -0,0 +1,10 @@
public class C {
{
Object o = getO();
String s = "";
if (o != null) {
String s1 = o.toString();
s += s1;
}
}
}
@@ -0,0 +1,8 @@
public class C {
{
Object o = getO();
String s = "";
if (o != null)
s += <selection>o.toString()</selection>;
}
}
@@ -0,0 +1,9 @@
class Test {
public void method() {
int i = 0;
while(i < 100) {
int temp = i++ * 2;
sum += temp;
}
}
}
@@ -0,0 +1,7 @@
class Test {
public void method() {
int i = 0;
while(i < 100)
sum += <selection>i++ * 2</selection>;
}
}
@@ -0,0 +1,11 @@
class A {
Object getObject() {
return null;
}
void method() {
final Object temp = getObject();
Object o = temp;
return temp.hashCode();
}
}
@@ -0,0 +1,10 @@
class A {
Object getObject() {
return null;
}
void method() {
Object o = <selection>getObject()</selection>;
return getObject().hashCode();
}
}
@@ -0,0 +1,12 @@
class A {
int getContentElementType() {
return 0;
}
void method() {
final int i = getContentElementType();
switch (i) {
default: throw new IllegalArgumentException("Wrong content type: " + i);
}
}
}
@@ -0,0 +1,11 @@
class A {
int getContentElementType() {
return 0;
}
void method() {
switch (<selection>getContentElementType()</selection>) {
default: throw new IllegalArgumentException("Wrong content type: " + getContentElementType());
}
}
}
@@ -0,0 +1,7 @@
class A {
public void test() {
int a = 0; int b = 0; int c = 0;
final int sum = b + c;
int d = a + sum;
}
}
@@ -0,0 +1,6 @@
class A {
public void test() {
int a = 0; int b = 0; int c = 0;
int d = a + <selection>b + c</selection>;
}
}
@@ -0,0 +1,6 @@
class A {
public void test() {
int a = 0; int b = 0; int c = 0;
int d = a - <selection>b + c</selection>;
}
}
@@ -0,0 +1,6 @@
class A {
public void test() {
int a = 0; int b = 0; int c = 0;
int d = a - <selection>b + c</selection>;
}
}
@@ -0,0 +1,6 @@
class A {
void method() {
int temp = 1 + 2;
int k = temp;
}
}
@@ -0,0 +1,5 @@
class A {
void method() {
int k = <selection>(1 + 2)</selection>;
}
}
@@ -0,0 +1,14 @@
import java.util.*;
public class Introduce {
private static List _list = new ArrayList();
public static void main(String[] args) {
final boolean empty = _list.isEmpty();
final boolean invisible = (!empty);
final boolean visible = empty;
if("".equals(_list.get(0)) || empty) {
}
}
}
@@ -0,0 +1,13 @@
import java.util.*;
public class Introduce {
private static List _list = new ArrayList();
public static void main(String[] args) {
final boolean invisible = (!<selection>_list.isEmpty()</selection>);
final boolean visible = (_list.isEmpty());
if("".equals(_list.get(0)) || _list.isEmpty()) {
}
}
}
@@ -0,0 +1,8 @@
class Test {
int method(String p1, int p2) {
final String s = p1 + p2;
int i = s;
for(int l = i; l <= s; l++)
sum += s;
}
}
@@ -0,0 +1,7 @@
class Test {
int method(String p1, int p2) {
int i = <selection>p1 + p2</selection>;
for(int l = i; l <= p1 + p2; l++)
sum += p1 + p2;
}
}
@@ -0,0 +1,6 @@
class Test {
public String bla() {
final String b = String.format("foo.bar.%s", "");
return b
}
}
@@ -0,0 +1,5 @@
class Test {
public String bla() {
return String.<caret>format("foo.bar.%s", "")
}
}
@@ -0,0 +1,6 @@
class Test {
{
String[] newVar = {"a", "b"};
String[] s = newVar;
}
}
@@ -0,0 +1,5 @@
class Test {
{
String[] s = <selection>{ "a", "b" }</selection>;
}
}
@@ -0,0 +1,9 @@
public class Thing {
private String it;
private void dumb() {
String it = this.it;
it.length();
}
}
@@ -0,0 +1,8 @@
public class Thing {
private String it;
private void dumb() {
<selection>it</selection>.length();
}
}
@@ -0,0 +1,8 @@
public class Thing {
private String it;
private void dumb() {
String it = this.it;
}
}
@@ -0,0 +1,8 @@
public class Thing {
private String it;
private void dumb() {
<selection>it</selection>
}
}
@@ -0,0 +1,8 @@
class Test {
Object object;
void foo() {
final Object object = this.object;
Object o = object; // object is selected
Object p = object;
}
}
@@ -0,0 +1,7 @@
class Test {
Object object;
void foo() {
Object o = <selection>object</selection>; // object is selected
Object p = object;
}
}
@@ -0,0 +1,15 @@
class C {
String f () {
return null;
}
C getParent() {return null;}
void test () {
C c = new C();
String wrong = c.f();
while (wrong != null) {
c = c.getParent();
}
}
}
@@ -0,0 +1,14 @@
class C {
String f () {
return null;
}
C getParent() {return null;}
void test () {
C c = new C();
while (<selection>c.f()</selection> != null) {
c = c.getParent();
}
}
}
@@ -0,0 +1,13 @@
class Set<T> {}
class Map <K,V> {
class Entry<K,V> {
}
Set<Entry<K,V>> entries () { return null; }
}
class C {
void foo (Map<?, String> s) {
Set<? extends Map<?, String>.Entry<?, String>> temp = s.entries();
}
}
@@ -0,0 +1,13 @@
class Set<T> {}
class Map <K,V> {
class Entry<K,V> {
}
Set<Entry<K,V>> entries () { return null; }
}
class C {
void foo (Map<?, String> s) {
<selection>s.entries()</selection>;
}
}
@@ -0,0 +1,9 @@
class C {
{
String s = "Text";
if (()) {
final int i = s.length();
System.out.println("Whatever" + i);
}
}
}
@@ -0,0 +1,7 @@
class C {
{
String s = "Text";
if (())
System.out.println("Whatever" + <selection>s.length()</selection>);
}
}
@@ -0,0 +1,5 @@
public class Test {
public void method() {
int i = 1 + 2;
}
}
@@ -0,0 +1,5 @@
public class Test {
public void method() {
1 + 2 <caret>
}
}
@@ -0,0 +1,6 @@
class Test {
void foo() {
int mi5 = 0;
int i = mi5;
}
}
@@ -0,0 +1,5 @@
class Test {
void foo() {
int i = <selection>0;</selection>
}
}
@@ -0,0 +1,9 @@
class XYZ {
static int name;
void method() {
System.out.println(name);
int name = 27;
System.out.println(XYZ.name);
}
}
@@ -0,0 +1,9 @@
class XYZ {
static int name;
void method() {
System.out.println(name);
<selection>27</selection>
System.out.println(name);
}
}
@@ -0,0 +1,7 @@
import static java.lang.Integer.*;
class A {
public void test() {
final int i = MAX_VALUE;
}
}
@@ -0,0 +1,7 @@
import static java.lang.Integer.*;
class A {
public void test() {
<selection>MAX_VALUE</selection>;
}
}
@@ -0,0 +1,6 @@
class A {
public void test() {
String str = "ss";
String s = "s" + str + "s";
}
}
@@ -0,0 +1,5 @@
class A {
public void test() {
String s = "s<selection>ss</selection>s";
}
}
@@ -0,0 +1,6 @@
class A {
public void test() {
String str = "ss";
String s = str;
}
}
@@ -0,0 +1,5 @@
class A {
public void test() {
String s = "<selection>ss</selection>";
}
}
@@ -0,0 +1,7 @@
class A {
public void test() {
int i = 0;
String str = i + "sss";
String s = str + "s";
}
}
@@ -0,0 +1,6 @@
class A {
public void test() {
int i = 0;
String s = <selection>i + "sss</selection>s";
}
}
@@ -0,0 +1,6 @@
class A {
public void test() {
boolean str = true;
String s = "ss" + str;
}
}
@@ -0,0 +1,5 @@
class A {
public void test() {
String s = "ss<selection>true</selection>";
}
}
@@ -0,0 +1,12 @@
public class Test9 {
protected int count;
}
class Test10 extends Test9 {
private class Test10i {
void test() {
final int count = Test10.this.count;
System.out.println(count);
}
}
}
@@ -0,0 +1,11 @@
public class Test9 {
protected int count;
}
class Test10 extends Test9 {
private class Test10i {
void test() {
System.out.println(<selection>count</selection>);
}
}
}
@@ -0,0 +1,13 @@
import java.lang.annotation.*;
@Target({ElementType.TYPE_USE/*, ElementType.TYPE*/})
@interface TA {
}
class C {
void foo () {
@TA C y = null;
@TA C y1 = y;
}
}
@@ -0,0 +1,13 @@
import java.lang.annotation.*;
@Target({ElementType.TYPE_USE/*, ElementType.TYPE*/})
@interface TA {
}
class C {
void foo () {
@TA C y = null;
<selection>y</selection>;
}
}
@@ -0,0 +1,22 @@
class A {
private class Inner {
public void innerMethod() {
new Runnable() {
public void run() {
if (true) {
if (true) {
int i = 0;
int temp = i * i;
if (i == 0) {
System.out.println("" + temp);
} else {
System.out.println("" + temp);
i = temp;
}
}
}
}
}.run();
}
}
}
@@ -0,0 +1,21 @@
class A {
private class Inner {
public void innerMethod() {
new Runnable() {
public void run() {
if (true) {
if (true) {
int i = 0;
if (i == 0) {
System.out.println("" + <selection>i * i</selection>);
} else {
System.out.println("" + i * i);
i = i * i;
}
}
}
}
}.run();
}
}
}
@@ -0,0 +1,6 @@
package test;
public class A {
public static class B {
}
}
@@ -0,0 +1,9 @@
package test;
public class Client {
public static List<A.B> getList() { return null; }
public static void method() {
final List<A.B> l = getList();
}
}
@@ -0,0 +1,4 @@
package test;
public class List<E> {
}
@@ -0,0 +1,6 @@
package test;
public class A {
public static class B {
}
}
@@ -0,0 +1,9 @@
package test;
public class Client {
public static List<A.B> getList() { return null; }
public static void method() {
<selection>getList()</selection>
}
}
@@ -0,0 +1,4 @@
package test;
public class List<E> {
}
@@ -0,0 +1,6 @@
package test;
public class A {
public static class B {
}
}
@@ -0,0 +1,7 @@
package test;
public class Client {
public static void method() {
final List<A.B> l = X.getList();
}
}
@@ -0,0 +1,4 @@
package test;
public class List<E> {
}
@@ -0,0 +1,5 @@
package test;
public class X {
public static List<A.B> getList() { return null; }
}
@@ -0,0 +1,6 @@
package test;
public class A {
public static class B {
}
}
@@ -0,0 +1,7 @@
package test;
public class Client {
public static void method() {
<selection>X.getList()</selection>
}
}
@@ -0,0 +1,4 @@
package test;
public class List<E> {
}
@@ -0,0 +1,5 @@
package test;
public class X {
public static List<A.B> getList() { return null; }
}
@@ -0,0 +1,7 @@
import util.Pair;
class Client {
void method() {
Pair<String, Pair<Integer,Boolean>> p = PairProvider.getPair();
}
}
@@ -0,0 +1,7 @@
import util.Pair;
class PairProvider {
public static Pair<String, Pair<Integer, Boolean>> getPair() {
return null;
}
}
@@ -0,0 +1,13 @@
package util;
class Pair<L,R> {
public Pair(L l, R r) {
}
public L getL() {
return null;
}
public R getR() {
return null;
}
}
@@ -0,0 +1,5 @@
class Client {
void method() {
<selection>PairProvider.getPair()</selection>
}
}
@@ -0,0 +1,7 @@
import util.Pair;
class PairProvider {
public static Pair<String, Pair<Integer, Boolean>> getPair() {
return null;
}
}

Some files were not shown because too many files have changed in this diff Show More