summaryrefslogtreecommitdiff
path: root/json/src/com/intellij/json/liveTemplates/JsonInPropertyKeysContextType.java
diff options
context:
space:
mode:
authorAndrej Shadura <andrew.shadura@collabora.co.uk>2019-08-28 14:13:29 +0200
committerAndrej Shadura <andrew.shadura@collabora.co.uk>2019-08-29 17:48:13 +0200
commite19ef5983707e6a5c8d127f1ac8f02754cef82fd (patch)
tree9e3852cb9abc81ed6aa444465928d45fd7763dea /json/src/com/intellij/json/liveTemplates/JsonInPropertyKeysContextType.java
New upstream version 0~183.5153.4+dfsg
Diffstat (limited to 'json/src/com/intellij/json/liveTemplates/JsonInPropertyKeysContextType.java')
-rw-r--r--json/src/com/intellij/json/liveTemplates/JsonInPropertyKeysContextType.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/json/src/com/intellij/json/liveTemplates/JsonInPropertyKeysContextType.java b/json/src/com/intellij/json/liveTemplates/JsonInPropertyKeysContextType.java
new file mode 100644
index 00000000..145e1b28
--- /dev/null
+++ b/json/src/com/intellij/json/liveTemplates/JsonInPropertyKeysContextType.java
@@ -0,0 +1,33 @@
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+package com.intellij.json.liveTemplates;
+
+import com.intellij.codeInsight.template.TemplateContextType;
+import com.intellij.json.JsonElementTypes;
+import com.intellij.json.psi.JsonFile;
+import com.intellij.json.psi.JsonPsiUtil;
+import com.intellij.json.psi.JsonValue;
+import com.intellij.patterns.PatternCondition;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.util.ProcessingContext;
+import org.jetbrains.annotations.NotNull;
+
+import static com.intellij.patterns.PlatformPatterns.psiElement;
+
+public class JsonInPropertyKeysContextType extends TemplateContextType {
+ protected JsonInPropertyKeysContextType() {
+ super("JSON_PROPERTY_KEYS", "JSON Property Keys", JsonContextType.class);
+ }
+
+ @Override
+ public boolean isInContext(@NotNull PsiFile file, int offset) {
+ return file instanceof JsonFile && psiElement().inside(psiElement(JsonValue.class)
+ .with(new PatternCondition<PsiElement>("insidePropertyKey") {
+ @Override
+ public boolean accepts(@NotNull PsiElement element,
+ ProcessingContext context) {
+ return JsonPsiUtil.isPropertyKey(element);
+ }
+ })).beforeLeaf(psiElement(JsonElementTypes.COLON)).accepts(file.findElementAt(offset));
+ }
+} \ No newline at end of file