From 5a324adb6f05345b5b4a322b9338cc8fdf7dfd9a Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Tue, 28 Oct 2014 14:54:38 +0300 Subject: [PATCH] EA-62151 Add diagnostic messages to log --- .../JsonStandardComplianceInspection.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/json/src/com/intellij/json/codeinsight/JsonStandardComplianceInspection.java b/json/src/com/intellij/json/codeinsight/JsonStandardComplianceInspection.java index 0124c48fa7fe..8c17715d696c 100644 --- a/json/src/com/intellij/json/codeinsight/JsonStandardComplianceInspection.java +++ b/json/src/com/intellij/json/codeinsight/JsonStandardComplianceInspection.java @@ -6,6 +6,7 @@ import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel; import com.intellij.json.JsonBundle; import com.intellij.json.JsonElementTypes; import com.intellij.json.psi.*; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiComment; @@ -22,15 +23,17 @@ import javax.swing.*; /** * Compliance checks include * * * @author Mikhail Golubev */ public class JsonStandardComplianceInspection extends LocalInspectionTool { + private static final Logger LOG = Logger.getInstance(JsonStandardComplianceInspection.class); + public boolean myWarnAboutComments = true; @NotNull @@ -58,8 +61,10 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool { @Override public void visitStringLiteral(@NotNull JsonStringLiteral stringLiteral) { if (stringLiteral.getText().startsWith("'")) { - holder.registerProblem(stringLiteral, JsonBundle.message("msg.compliance.problem.single.quoted.strings"), new AddDoubleQuotesFix()); + holder + .registerProblem(stringLiteral, JsonBundle.message("msg.compliance.problem.single.quoted.strings"), new AddDoubleQuotesFix()); } + // May be illegal property key as well super.visitStringLiteral(stringLiteral); } @@ -76,6 +81,8 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool { @Override public void visitReferenceExpression(@NotNull JsonReferenceExpression reference) { holder.registerProblem(reference, JsonBundle.message("msg.compliance.problem.identifier"), new AddDoubleQuotesFix()); + // May be illegal property key as well + super.visitReferenceExpression(reference); } @Override @@ -133,9 +140,13 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool { @Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); - assert element instanceof JsonLiteral || element instanceof JsonReferenceExpression; - final String content = StringUtil.stripQuotesAroundValue(element.getText()); - element.replace(new JsonElementGenerator(project).createStringLiteral(content)); + if (element instanceof JsonLiteral || element instanceof JsonReferenceExpression) { + final String content = StringUtil.stripQuotesAroundValue(element.getText()); + element.replace(new JsonElementGenerator(project).createStringLiteral(content)); + } + else if (element != null) { + LOG.error("Quick fix was applied to unexpected element", element.getText(), element.getParent().getText()); + } } } }