! alias for not makes bulenkov happy

This commit is contained in:
Sergey Ignatov
2013-12-19 14:14:03 +04:00
parent c13888669d
commit ceee385d20
7 changed files with 18 additions and 8 deletions
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.LinkedHashSet;
import java.util.Set;
@Aliases("inst")
@Aliases(".inst")
public class InstanceofExpressionPostfixTemplate extends PostfixTemplate {
public InstanceofExpressionPostfixTemplate() {
super("instanceof", "Surrounds expression with instanceof", "expr instanceof SomeType ? ((SomeType) expr). : null");
@@ -1,12 +1,14 @@
package com.intellij.codeInsight.template.postfix.templates;
import com.intellij.codeInsight.CodeInsightServicesUtil;
import com.intellij.codeInsight.template.postfix.util.Aliases;
import com.intellij.codeInsight.template.postfix.util.PostfixTemplatesUtils;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.PsiExpression;
import org.jetbrains.annotations.NotNull;
@Aliases("!")
public class NotExpressionPostfixTemplate extends ExpressionPostfixTemplateWithChooser {
public NotExpressionPostfixTemplate() {
super("not", "Negates boolean expression", "!expr");
@@ -3,7 +3,7 @@ package com.intellij.codeInsight.template.postfix.templates;
import com.intellij.codeInsight.template.postfix.util.Aliases;
import org.jetbrains.annotations.NotNull;
@Aliases("nn")
@Aliases(".nn")
public class NotNullCheckPostfixTemplate extends NullCheckPostfixTemplate {
public NotNullCheckPostfixTemplate() {
super("notnull", "Checks expression to be not-null", "if (expr != null)");
@@ -42,7 +42,7 @@ public class PostfixLiveTemplate extends CustomLiveTemplateBase {
Aliases aliases = template.getClass().getAnnotation(Aliases.class);
if (aliases != null) {
for (String key : aliases.value()) {
register("." + key, template);
register(key, template);
}
}
}
@@ -60,10 +60,7 @@ public class PostfixLiveTemplate extends CustomLiveTemplateBase {
public String computeTemplateKey(@NotNull CustomTemplateCallback callback) {
Editor editor = callback.getEditor();
String key = computeTemplateKeyWithoutContextChecking(editor);
if (key == null) {
return null;
}
if (key == null) return null;
return isApplicableTemplate(getTemplateByKey(key), key, callback.getContext().getContainingFile(), editor) ? key : null;
}
@@ -75,7 +72,7 @@ public class PostfixLiveTemplate extends CustomLiveTemplateBase {
while (startOffset > 0) {
char currentChar = documentContent.charAt(startOffset - 1);
if (!Character.isJavaIdentifierPart(currentChar)) {
if (currentChar != '.') {
if (currentChar != '.' && currentChar != '!') {
return null;
}
startOffset--;
@@ -0,0 +1,5 @@
public class Foo {
void m(boolean b) {
m(b!<caret>);
}
}
@@ -0,0 +1,5 @@
public class Foo {
void m(boolean b) {
m(!b<caret>);
}
}
@@ -13,5 +13,6 @@ public class NotExpressionPostfixTemplateTest extends PostfixTemplateTestCase {
public void testSimple() { doTest(); }
public void testComplexCondition() { doTest(); }
public void testBoxedBoolean() { doTest(); }
public void testExclamation() { doTest(); }
// public void testNegation() { doTest(); } // todo: test for chooser
}