summaryrefslogtreecommitdiff
path: root/json/src/com/intellij/json/liveTemplates
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
New upstream version 0~183.5153.4+dfsg
Diffstat (limited to 'json/src/com/intellij/json/liveTemplates')
-rw-r--r--json/src/com/intellij/json/liveTemplates/JsonContextType.java22
-rw-r--r--json/src/com/intellij/json/liveTemplates/JsonInLiteralsContextType.java21
-rw-r--r--json/src/com/intellij/json/liveTemplates/JsonInPropertyKeysContextType.java33
3 files changed, 76 insertions, 0 deletions
diff --git a/json/src/com/intellij/json/liveTemplates/JsonContextType.java b/json/src/com/intellij/json/liveTemplates/JsonContextType.java
new file mode 100644
index 00000000..cc5ef222
--- /dev/null
+++ b/json/src/com/intellij/json/liveTemplates/JsonContextType.java
@@ -0,0 +1,22 @@
+package com.intellij.json.liveTemplates;
+
+import com.intellij.codeInsight.template.FileTypeBasedContextType;
+import com.intellij.json.JsonBundle;
+import com.intellij.json.JsonFileType;
+import com.intellij.json.psi.JsonFile;
+import com.intellij.psi.PsiFile;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Konstantin.Ulitin
+ */
+public class JsonContextType extends FileTypeBasedContextType {
+ protected JsonContextType() {
+ super("JSON", JsonBundle.message("json.template.context.type"), JsonFileType.INSTANCE);
+ }
+
+ @Override
+ public boolean isInContext(@NotNull PsiFile file, int offset) {
+ return file instanceof JsonFile;
+ }
+}
diff --git a/json/src/com/intellij/json/liveTemplates/JsonInLiteralsContextType.java b/json/src/com/intellij/json/liveTemplates/JsonInLiteralsContextType.java
new file mode 100644
index 00000000..0e21d5fa
--- /dev/null
+++ b/json/src/com/intellij/json/liveTemplates/JsonInLiteralsContextType.java
@@ -0,0 +1,21 @@
+// 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.psi.JsonFile;
+import com.intellij.json.psi.JsonStringLiteral;
+import com.intellij.psi.PsiFile;
+import org.jetbrains.annotations.NotNull;
+
+import static com.intellij.patterns.PlatformPatterns.psiElement;
+
+public class JsonInLiteralsContextType extends TemplateContextType {
+ protected JsonInLiteralsContextType() {
+ super("JSON_STRING_VALUES", "JSON String Values", JsonContextType.class);
+ }
+
+ @Override
+ public boolean isInContext(@NotNull PsiFile file, int offset) {
+ return file instanceof JsonFile && psiElement().inside(JsonStringLiteral.class).accepts(file.findElementAt(offset));
+ }
+}
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