From 5321f3402e8b7fb08d7cd9427dfa9b072dc0be3d Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Sat, 3 Sep 2016 12:56:56 +0300 Subject: [PATCH] IDEA-160408 Quote not recognized as an end to String --- .../plugins/intelliLang/ReferenceInjectionTest.java | 10 ++++++++++ .../references/InjectedReferencesInspection.java | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/IntelliLang/IntelliLang-tests/test/org/intellij/plugins/intelliLang/ReferenceInjectionTest.java b/plugins/IntelliLang/IntelliLang-tests/test/org/intellij/plugins/intelliLang/ReferenceInjectionTest.java index 0946f4c6cb84..415fabb0b194 100644 --- a/plugins/IntelliLang/IntelliLang-tests/test/org/intellij/plugins/intelliLang/ReferenceInjectionTest.java +++ b/plugins/IntelliLang/IntelliLang-tests/test/org/intellij/plugins/intelliLang/ReferenceInjectionTest.java @@ -108,6 +108,16 @@ public class ReferenceInjectionTest extends LightCodeInsightFixtureTestCase { myFixture.testHighlighting(); } + public void testEmptyLiteral() throws Exception { + myFixture.configureByText("Foo.java", "class Foo {\n" + + " void bar() {\n" + + " @org.intellij.lang.annotations.Language(\"encoding-reference\")\n" + + " String cset = true ? \"\" : \"utf-8\";//\n" + + " }\n" + + "}"); + myFixture.testHighlighting(); + } + private PsiReference[] getInjectedReferences() { PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); element = PsiTreeUtil.getParentOfType(element, PsiLanguageInjectionHost.class); diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/references/InjectedReferencesInspection.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/references/InjectedReferencesInspection.java index 1f8f68249bb5..b2cfab0540d3 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/references/InjectedReferencesInspection.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/references/InjectedReferencesInspection.java @@ -16,7 +16,9 @@ package org.intellij.plugins.intelliLang.references; import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiReference; @@ -39,7 +41,14 @@ public class InjectedReferencesInspection extends LocalInspectionTool { if (injected != null) { for (PsiReference reference : injected) { if (reference.resolve() == null) { - holder.registerProblem(reference); + TextRange range = reference.getRangeInElement(); + if (range.isEmpty() && range.getStartOffset() == 1 && "\"\"".equals(element.getText())) { + String message = ProblemsHolder.unresolvedReferenceMessage(reference); + holder.registerProblem(element, message, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, TextRange.create(0, 2)); + } + else { + holder.registerProblem(reference); + } } } }