mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
missed comments on Simplify (IDEA-114798)
This commit is contained in:
+7
@@ -32,6 +32,8 @@ import com.siyeh.ig.psiutils.EquivalenceChecker;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class TrivialIfInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@@ -131,6 +133,11 @@ public class TrivialIfInspection extends BaseInspection {
|
||||
}
|
||||
final String conditionText = condition.getText();
|
||||
@NonNls final String newStatement = "return " + conditionText + ';';
|
||||
final Collection<PsiComment> comments = PsiTreeUtil.findChildrenOfType(statement, PsiComment.class);
|
||||
final PsiElement parent = statement.getParent();
|
||||
for (PsiComment comment : comments) {
|
||||
parent.addBefore(comment.copy(), statement);
|
||||
}
|
||||
replaceStatement(statement, newStatement);
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class Test {
|
||||
public static boolean test(String key, String keyValue){
|
||||
// some comment goes here
|
||||
return key != null && key.equals(keyValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
public static boolean test(String key, String keyValue){
|
||||
<caret>if(key != null && key.equals(keyValue)) {
|
||||
// some comment goes here
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
*/
|
||||
package com.siyeh.ig.fixes.controlflow;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.IGQuickFixesTestCase;
|
||||
import com.siyeh.ig.controlflow.TrivialIfInspection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TrivialIfInspectionTest extends IGQuickFixesTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new TrivialIfInspection());
|
||||
myRelativePath = "controlflow/trivialIf";
|
||||
}
|
||||
|
||||
public void testComments() {
|
||||
final String testName = getTestName(false);
|
||||
myFixture.configureByFile(getRelativePath() + "/" + testName + ".java");
|
||||
final String message = InspectionGadgetsBundle.message("constant.conditional.expression.simplify.quickfix");
|
||||
final List<IntentionAction> actions =
|
||||
myFixture.filterAvailableIntentions(message);
|
||||
assertFalse("No actions available", actions.isEmpty());
|
||||
for (IntentionAction action : actions) {
|
||||
if (action.getText().equals(message)) {
|
||||
myFixture.launchAction(action);
|
||||
myFixture.checkResultByFile(getRelativePath() + "/" + testName + ".after.java");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user