From 4fb1124d2dd6ead2c24ec00417438051cb3a40fe Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 19 Jan 2015 14:58:18 +0100 Subject: [PATCH] IDEA-133004 (no comment injections for binary files) --- .../plugins/intelliLang/inject/InjectorUtils.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java index 1b4e43ec4df1..035507d22122 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -229,15 +229,17 @@ public class InjectorUtils { public static BaseInjection findCommentInjection(@NotNull PsiElement context, @NotNull String supportId, @Nullable Ref causeRef) { PsiElement target = CompletionUtil.getOriginalOrSelf(context); PsiFile file = target.getContainingFile(); + if (file == null || file.getFileType().isBinary()) return null; TreeMap map = getInjectionMap(file); - Map.Entry entry = map == null ? null : map.lowerEntry(target.getTextRange()); + if (map == null) return null; + Map.Entry entry = map.lowerEntry(target.getTextRange()); if (entry == null) return null; PsiComment psiComment = PsiTreeUtil.findElementOfClassAtOffset(file, entry.getKey().getStartOffset(), PsiComment.class, false); if (psiComment == null) return null; TextRange r0 = psiComment.getTextRange(); - // calulate topmost siblings & heights + // calculate topmost siblings & heights PsiElement commonParent = PsiTreeUtil.findCommonParent(psiComment, target); int h1 = 0, h2 = 0; PsiElement e1 = psiComment, e2 = target; @@ -269,8 +271,7 @@ public class InjectorUtils { } @Nullable - private static TreeMap getInjectionMap(@Nullable final PsiFile file) { - if (file == null) return null; // e.g. null for synthetic groovy variables + private static TreeMap getInjectionMap(@NotNull final PsiFile file) { return CachedValuesManager.getCachedValue(file, new CachedValueProvider>() { @Nullable @Override