IDEA-62374 Suggest ternary operation to avoid NPE implemented

This commit is contained in:
Danila Ponomarenko
2012-05-28 14:55:25 +04:00
parent ced3ee94b3
commit c152ac976f
12 changed files with 271 additions and 48 deletions
@@ -0,0 +1,10 @@
// "Replace with 'list != null ?:'" "true"
import org.jetbrains.annotations.NotNull;
class A{
void test(@NotNull List l) {
final List list = null;
test(list != null ? list : <selection>null</selection>);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'integer != null ?:'" "true"
import java.lang.Integer;
class A{
void test(){
Integer integer = null;
int i = integer != null ? integer.intValue() : <selection>0</selection>;
}
}
@@ -0,0 +1,8 @@
// "Replace with 'list != null ?:'" "true"
class A{
void test(){
List list = null;
Object o = list != null ? list.get(0) : <selection>null</selection>;
}
}
@@ -0,0 +1,7 @@
// "Replace with 'list != null ?:'" "false"
class A{
void test(){
List list = null;
li<caret>st.get(0);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'list != null ?:'" "true"
import org.jetbrains.annotations.NotNull;
class A{
void test(@NotNull List l) {
final List list = null;
test(li<caret>st);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'integer != null ?:'" "true"
import java.lang.Integer;
class A{
void test(){
Integer integer = null;
int i = in<caret>teger.intValue();
}
}
@@ -0,0 +1,8 @@
// "Replace with 'list != null ?:'" "true"
class A{
void test(){
List list = null;
Object o = li<caret>st.get(0);
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* User: anna
* Date: 21-Mar-2008
*/
package com.intellij.codeInsight.daemon.quickFix;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
import com.intellij.codeInspection.nullable.NullableStuffInspection;
public class ReplaceWithTernaryOperatorTest extends LightQuickFixTestCase {
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{new DataFlowInspection(), new NullableStuffInspection()};
}
public void test() throws Exception {
doAllTests();
}
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/replaceWithTernaryOperator";
}
}