mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
java strings are not statement live template context
This commit is contained in:
@@ -95,7 +95,7 @@ public abstract class JavaCodeContextType extends TemplateContextType {
|
||||
}
|
||||
|
||||
private static boolean isStatementContext(PsiElement element) {
|
||||
if (isAfterExpression(element)) {
|
||||
if (isAfterExpression(element) || JavaStringContextType.isStringLiteral(element)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,12 @@ public class JavaStringContextType extends TemplateContextType {
|
||||
@Override
|
||||
public boolean isInContext(@NotNull final PsiFile file, final int offset) {
|
||||
if (PsiUtilBase.getLanguageAtOffset(file, offset).isKindOf(StdLanguages.JAVA)) {
|
||||
PsiElement element = file.findElementAt(offset);
|
||||
return element instanceof PsiJavaToken && ((PsiJavaToken) element).getTokenType() == JavaTokenType.STRING_LITERAL;
|
||||
return isStringLiteral(file.findElementAt(offset));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean isStringLiteral(PsiElement element) {
|
||||
return element instanceof PsiJavaToken && ((PsiJavaToken) element).getTokenType() == JavaTokenType.STRING_LITERAL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,6 +323,7 @@ class Foo {
|
||||
assertTrue(isApplicable("class Foo {{ <caret>inst\n a=b; }}", template));
|
||||
assertFalse(isApplicable("class Foo {{ return (<caret>inst) }}", template));
|
||||
assertFalse(isApplicable("class Foo {{ return a <caret>inst) }}", template));
|
||||
assertFalse(isApplicable("class Foo {{ \"<caret>\" }}", template));
|
||||
assertTrue(isApplicable("class Foo {{ <caret>a.b(); ) }}", template));
|
||||
assertTrue(isApplicable("class Foo {{ <caret>a(); ) }}", template));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user