mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
Java surrounders: if and not surrounder should be able to handle java.lang
.Boolean expressions
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.intellij.codeInsight.generation.surroundWith;
|
||||
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiPrimitiveType;
|
||||
import com.intellij.psi.PsiType;
|
||||
|
||||
abstract public class JavaBooleanExpressionSurrounder extends JavaExpressionSurrounder {
|
||||
@Override
|
||||
public boolean isApplicable(PsiExpression expr) {
|
||||
PsiType type = expr.getType();
|
||||
return type != null && (PsiType.BOOLEAN.equals(type) || PsiType.BOOLEAN.equals(PsiPrimitiveType.getUnboxedType(type)));
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -1,6 +1,6 @@
|
||||
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -23,15 +23,14 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.psi.util.FileTypeUtils;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
public class JavaWithIfExpressionSurrounder extends JavaExpressionSurrounder{
|
||||
public class JavaWithIfExpressionSurrounder extends JavaBooleanExpressionSurrounder {
|
||||
@Override
|
||||
public boolean isApplicable(PsiExpression expr) {
|
||||
PsiType type = expr.getType();
|
||||
if (PsiType.BOOLEAN != type) return false;
|
||||
if (!super.isApplicable(expr)) return false;
|
||||
if (!expr.isPhysical()) return false;
|
||||
PsiElement parent = expr.getParent();
|
||||
if (!(parent instanceof PsiExpressionStatement)) return false;
|
||||
|
||||
+2
-7
@@ -1,6 +1,6 @@
|
||||
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -25,12 +25,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
class JavaWithNotSurrounder extends JavaExpressionSurrounder{
|
||||
@Override
|
||||
public boolean isApplicable(PsiExpression expr) {
|
||||
return PsiType.BOOLEAN.equals(expr.getType());
|
||||
}
|
||||
|
||||
class JavaWithNotSurrounder extends JavaBooleanExpressionSurrounder {
|
||||
@Override
|
||||
public TextRange surroundExpression(Project project, Editor editor, PsiExpression expr) throws IncorrectOperationException {
|
||||
PsiManager manager = expr.getManager();
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Test {
|
||||
boolean foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void bar() {
|
||||
<selection>foo()</selection>
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import java.lang.Boolean;
|
||||
|
||||
class Test {
|
||||
Boolean foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void bar() {
|
||||
<selection>foo()</selection>
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import java.lang.Boolean;
|
||||
|
||||
class Test {
|
||||
Boolean foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void bar() {
|
||||
if (foo()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
boolean foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void bar() {
|
||||
if (foo()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import java.lang.Boolean;
|
||||
|
||||
class Test {
|
||||
Boolean foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void bar() {
|
||||
<selection>foo()</selection>
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import java.lang.Boolean;
|
||||
|
||||
class Test {
|
||||
Boolean foo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void bar() {
|
||||
!(foo())
|
||||
}
|
||||
}
|
||||
+15
@@ -130,6 +130,21 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase {
|
||||
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
|
||||
doTest(getTestName(false), new JavaWithNullCheckSurrounder());
|
||||
}
|
||||
|
||||
public void testSurroundExpressionWithIf() {
|
||||
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
|
||||
doTest(getTestName(false), new JavaWithIfExpressionSurrounder());
|
||||
}
|
||||
|
||||
public void testSurroundExpressionWithIfForBoxedBooleans() {
|
||||
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
|
||||
doTest(getTestName(false), new JavaWithIfExpressionSurrounder());
|
||||
}
|
||||
|
||||
public void testSurroundExpressionWithNotForBoxedBooleans() {
|
||||
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
|
||||
doTest(getTestName(false), new JavaWithNotSurrounder());
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String fileName, final Surrounder surrounder) {
|
||||
configureByFile(BASE_PATH + fileName + ".java");
|
||||
|
||||
Reference in New Issue
Block a user