Skip to content

Commit c4bee31

Browse files
committed
Initial commit
0 parents  commit c4bee31

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
2+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3+
4+
# User-specific stuff:
5+
build
6+
.gradle
7+
.idea
8+
*.iml
9+
10+
# IntelliJ
11+
out/

build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
buildscript {
2+
repositories {
3+
maven {
4+
url "https://plugins.gradle.org/m2/"
5+
}
6+
maven {
7+
url 'http://dl.bintray.com/jetbrains/intellij-plugin-service'
8+
}
9+
mavenCentral()
10+
}
11+
dependencies {
12+
classpath "gradle.plugin.org.jetbrains:gradle-intellij-plugin:0.1.10"
13+
}
14+
}
15+
16+
apply plugin: 'org.jetbrains.intellij'
17+
18+
version = "IU-173.3942.27"
19+
intellij {
20+
version 'IU-173.3942.27'
21+
pluginName 'vue-gwt-plugin'
22+
downloadSources false
23+
updateSinceUntilBuild false
24+
}
25+
26+
group 'com.axellience'
27+
version '0.0.1'
28+
29+
repositories {
30+
mavenCentral()
31+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.axellience.vuegwtplugin;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import com.intellij.lang.injection.MultiHostInjector;
9+
import com.intellij.lang.injection.MultiHostRegistrar;
10+
import com.intellij.lang.java.JavaLanguage;
11+
import com.intellij.openapi.editor.impl.TextRangeInterval;
12+
import com.intellij.psi.PsiElement;
13+
import com.intellij.psi.PsiFile;
14+
import com.intellij.psi.PsiLanguageInjectionHost;
15+
import com.intellij.psi.impl.source.PsiJavaFileImpl;
16+
import com.intellij.psi.xml.XmlAttribute;
17+
import com.intellij.psi.xml.XmlAttributeValue;
18+
19+
public class VueCustomInjector implements MultiHostInjector
20+
{
21+
@Override
22+
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar,
23+
@NotNull PsiElement host)
24+
{
25+
if (!(host.getParent() instanceof XmlAttribute))
26+
return;
27+
28+
XmlAttribute attribute = (XmlAttribute) host.getParent();
29+
String attr = attribute.getName();
30+
if (attr.startsWith(":") || attr.startsWith("@") || attr.startsWith("v-"))
31+
{
32+
registrar.startInjecting(JavaLanguage.INSTANCE);
33+
34+
PsiFile templateFile = host.getContainingFile();
35+
String componentName = templateFile
36+
.getName()
37+
.substring(0, templateFile.getName().length() - ".html".length());
38+
39+
String javaClassFileName = componentName + ".java";
40+
41+
if (templateFile.getContainingDirectory() == null)
42+
return;
43+
44+
PsiJavaFileImpl componentFile = null;
45+
for (PsiFile psiFile : templateFile.getContainingDirectory().getFiles())
46+
{
47+
if (psiFile.getName().equals(javaClassFileName))
48+
{
49+
componentFile = (PsiJavaFileImpl) psiFile;
50+
break;
51+
}
52+
}
53+
54+
if (componentFile == null)
55+
return;
56+
57+
String templateExpressionMethod;
58+
if (attr.startsWith("@"))
59+
templateExpressionMethod = "public void templateExpression() {\n\t\t";
60+
else
61+
templateExpressionMethod = "public Object templateExpression() {\n\t\treturn ";
62+
63+
String expressionStart = "package "
64+
+ componentFile.getPackageName()
65+
+ ";\n"
66+
+ "class "
67+
+ componentName
68+
+ "TemplateImpl extends "
69+
+ componentName
70+
+ "JsType {\n"
71+
+ templateExpressionMethod;
72+
73+
String expressionEnd = ";\n\t}\n}";
74+
75+
registrar.addPlace(expressionStart,
76+
expressionEnd,
77+
(PsiLanguageInjectionHost) host,
78+
new TextRangeInterval(1, host.getTextLength() - 1));
79+
registrar.doneInjecting();
80+
}
81+
}
82+
83+
@NotNull
84+
@Override
85+
public List<? extends Class<? extends PsiElement>> elementsToInjectIn()
86+
{
87+
return Collections.singletonList(XmlAttributeValue.class);
88+
}
89+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<idea-plugin>
2+
<id>com.axellience.vuegwt</id>
3+
<name>VueGWT</name>
4+
<version>0.0.1</version>
5+
<vendor email="support@axellience.com" url="http://www.genmymodel.com">Axellience</vendor>
6+
7+
<description><![CDATA[
8+
Add syntax highlighting and code completion in Vue GWT templates.
9+
]]></description>
10+
11+
<change-notes><![CDATA[
12+
]]>
13+
</change-notes>
14+
15+
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
16+
<idea-version since-build="173.0"/>
17+
18+
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
19+
on how to target different products -->
20+
<!-- uncomment to enable plugin in all products
21+
<depends>com.intellij.modules.lang</depends>
22+
-->
23+
24+
<extensions defaultExtensionNs="com.intellij">
25+
<multiHostInjector implementation="com.axellience.vuegwtplugin.VueCustomInjector"/>
26+
</extensions>
27+
28+
<actions>
29+
</actions>
30+
31+
</idea-plugin>

0 commit comments

Comments
 (0)