PY-12564 Django: Template directories auto-configuration is missing on opening existi...
authorIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Thu, 27 Nov 2014 12:03:17 +0000 (15:03 +0300)
committerIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Thu, 27 Nov 2014 12:03:17 +0000 (15:03 +0300)
PY-12876 Jinja2 Unresolved template reference

python/openapi/src/com/jetbrains/python/templateLanguages/PythonTemplateLanguage.java [new file with mode: 0644]
python/openapi/src/com/jetbrains/python/templateLanguages/TemplatesService.java

diff --git a/python/openapi/src/com/jetbrains/python/templateLanguages/PythonTemplateLanguage.java b/python/openapi/src/com/jetbrains/python/templateLanguages/PythonTemplateLanguage.java
new file mode 100644 (file)
index 0000000..28a7e08
--- /dev/null
@@ -0,0 +1,41 @@
+package com.jetbrains.python.templateLanguages;
+
+import com.intellij.lang.Language;
+import com.intellij.openapi.module.Module;
+import com.intellij.psi.templateLanguages.TemplateLanguage;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Python template language
+ * @author Ilya.Kazakevich
+ */
+public abstract class PythonTemplateLanguage extends Language implements TemplateLanguage {
+
+
+  protected PythonTemplateLanguage(@Nullable final Language baseLanguage,
+                                @NotNull @NonNls final String ID,
+                                @NotNull @NonNls final String... mimeTypes) {
+    super(baseLanguage, ID, mimeTypes);
+  }
+
+  protected PythonTemplateLanguage(@NotNull @NonNls final String id) {
+    super(id);
+  }
+
+  /**
+   * @return template language readable name
+   */
+  @NotNull
+  public abstract String getTemplateLanguageName();
+
+  /**
+   * Checks if text contains some chars that make us think this text uses appropriate template language and we should set
+   * this language as our project language
+   *
+   * @param text text with chars to check
+   * @return text contains some chars that make us think this text uses appropriate template language and we should set this language as our project language
+   */
+  public abstract boolean isFileLeadsToLanguageSelection(@NotNull String text);
+}
index 03d82e338144182a887677cc759ad4c73111e63e..e7873d1bb7e36f9ea50bb09ad03befb0712edb54 100644 (file)
@@ -23,7 +23,9 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.containers.ContainerUtil;
 import com.jetbrains.python.packaging.PyPackageManager;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -31,12 +33,42 @@ import java.util.List;
  */
 public abstract class TemplatesService {
   public static final String NONE = "None";
+  /**
+   * @deprecated Use {@link #getKnownTemplateLanguages()}
+   * or {@link com.jetbrains.python.templateLanguages.PythonTemplateLanguage#getTemplateLanguageName()}
+   */
+  @Deprecated
   public static final String DJANGO = "Django";
+  /**
+   * @deprecated Use {@link #getKnownTemplateLanguages()}
+   * or {@link com.jetbrains.python.templateLanguages.PythonTemplateLanguage#getTemplateLanguageName()}
+   */
+  @Deprecated
   public static final String MAKO = "Mako";
+  /**
+   * @deprecated Use {@link #getKnownTemplateLanguages()}
+   * or {@link com.jetbrains.python.templateLanguages.PythonTemplateLanguage#getTemplateLanguageName()}
+   */
+  @Deprecated
   public static final String JINJA2 = "Jinja2";
+  /**
+   * @deprecated Use {@link #getKnownTemplateLanguages()}
+   * or {@link com.jetbrains.python.templateLanguages.PythonTemplateLanguage#getTemplateLanguageName()}
+   */
+  @Deprecated
   public static final String WEB2PY = "Web2Py";
+  /**
+   * @deprecated Use {@link #getKnownTemplateLanguages()}
+   * or {@link com.jetbrains.python.templateLanguages.PythonTemplateLanguage#getTemplateLanguageName()}
+   */
+  @Deprecated
   public static final String CHAMELEON = "Chameleon";
 
+  /**
+   * @deprecated Use {@link #getKnownTemplateLanguages()}
+   * or {@link com.jetbrains.python.templateLanguages.PythonTemplateLanguage#getTemplateLanguageName()}
+   */
+  @Deprecated
   private static List<String> ALL_TEMPLATE_LANGUAGES = ContainerUtil.immutableList(NONE,
                                                                                    DJANGO,
                                                                                    MAKO,
@@ -47,16 +79,24 @@ public abstract class TemplatesService {
   public static List<String> ALL_TEMPLATE_BINDINGS = ContainerUtil.immutableList("django-mako", "django-jinja", "django-chameleon",
                                                                                   "flask-mako", "pyramid_jinja2");
 
+  @Nullable
   public abstract Language getSelectedTemplateLanguage();
 
   public static TemplatesService getInstance(Module module) {
     return ModuleServiceManager.getService(module, TemplatesService.class);
   }
 
+  /**
+   * @deprecated Use {@link #getKnownTemplateLanguages()}
+   * or {@link com.jetbrains.python.templateLanguages.PythonTemplateLanguage#getTemplateLanguageName()}
+   */
+  @Deprecated
   public static List<String> getAllTemplateLanguages() {
     return ALL_TEMPLATE_LANGUAGES;
   }
 
+  public abstract List<PythonTemplateLanguage> getKnownTemplateLanguages();
+
   public abstract void setTemplateLanguage(String templateLanguage);
 
   @NotNull