Skip to content

Commit

Permalink
prepared adding support for C# and Rider
Browse files Browse the repository at this point in the history
  • Loading branch information
xylo committed Oct 21, 2018
1 parent 9111b92 commit 67737fc
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 1 deletion.
5 changes: 5 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
<depends optional="true">com.jetbrains.php</depends>
<depends optional="true">org.rust.lang</depends>
<depends optional="true">org.intellij.groovy</depends>
<depends optional="true">com.intellij.modules.rider</depends>

<application-components>
<component>
Expand Down Expand Up @@ -357,6 +358,10 @@
implementationClass="de.endrullis.idea.postfixtemplates.languages.rust.RustPostfixTemplateProvider"/>
<codeInsight.template.postfixTemplateProvider language="Groovy"
implementationClass="de.endrullis.idea.postfixtemplates.languages.groovy.GroovyPostfixTemplateProvider"/>
<!--
<codeInsight.template.postfixTemplateProvider language="C#"
implementationClass="de.endrullis.idea.postfixtemplates.languages.csharp.CsharpPostfixTemplateProvider"/>
-->

<applicationConfigurable id="Settings.CustomPostfixTemplates"
bundle="de.endrullis.idea.postfixtemplates.bundle.PostfixTemplatesBundle"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// this is a custom template defined by the user
// see "Custom Postfix Templates" for template definition
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// this is a custom template defined by the user
// see "Custom Postfix Templates" for template definition
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
~ Copyright 2000-2017 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.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<html>
<body>

Custom postfix template.
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.psi.PsiElement;
import de.endrullis.idea.postfixtemplates.language.CptLang;
import de.endrullis.idea.postfixtemplates.language.CptUtil;
import de.endrullis.idea.postfixtemplates.languages.csharp.CsharpLang;
import de.endrullis.idea.postfixtemplates.languages.dart.DartLang;
import de.endrullis.idea.postfixtemplates.languages.groovy.GroovyLang;
import de.endrullis.idea.postfixtemplates.languages.java.JavaLang;
Expand Down Expand Up @@ -34,6 +35,7 @@
public class SupportedLanguages {

public static final List<CptLang> supportedLanguages = _List(
//new CsharpLang(),
new DartLang(),
new GroovyLang(),
new KotlinLang(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.endrullis.idea.postfixtemplates.languages.csharp;

import com.intellij.codeInsight.completion.CompletionParameters;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import de.endrullis.idea.postfixtemplates.language.CptLangAnnotator;
import de.endrullis.idea.postfixtemplates.templates.SpecialType;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

/**
* Code annotator for C# CPTs.
*
* @author Stefan Endrullis &lt;stefan@endrullis.de&gt;
*/
public class CsharpAnnotator implements CptLangAnnotator {

private final Map<String, Boolean> className2exists = new HashMap<String, Boolean>() {{
put(SpecialType.ANY.name(), true);
}};

@Override
public boolean isMatchingType(@NotNull final LeafPsiElement element, @NotNull final String className) {
return className2exists.containsKey(className);
}

@Override
public void completeMatchingType(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet resultSet) {
resultSet.addElement(LookupElementBuilder.create(SpecialType.ANY.name()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.endrullis.idea.postfixtemplates.languages.csharp;

import de.endrullis.idea.postfixtemplates.language.CptLang;

/**
* Language definition for C#.
*
* @author Stefan Endrullis &lt;stefan@endrullis.de&gt;
*/
public class CsharpLang extends CptLang {

public CsharpLang() {
super("C#", CsharpAnnotator.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.endrullis.idea.postfixtemplates.languages.csharp;

import com.intellij.codeInsight.template.postfix.templates.PostfixTemplateProvider;
import de.endrullis.idea.postfixtemplates.language.psi.CptMapping;
import de.endrullis.idea.postfixtemplates.templates.CustomPostfixTemplateProvider;
import org.jetbrains.annotations.NotNull;

public class CsharpPostfixTemplateProvider extends CustomPostfixTemplateProvider {

@NotNull
@Override
protected String getLanguage() {
return "csharp";
}

@Override
public String getPluginClassName() {
return "com.jetbrains.rider.ideaInterop.fileTypes.csharp.psi.CSharpDummyNode";
}

@NotNull
@Override
protected CustomCsharpStringPostfixTemplate createTemplate(CptMapping mapping, String matchingClass, String conditionClass, String templateName, String description, String template, PostfixTemplateProvider provider) {
return CsharpStringPostfixTemplateCreator.createTemplate(mapping, matchingClass, conditionClass, templateName, description, template, provider);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.endrullis.idea.postfixtemplates.languages.csharp;

import com.intellij.codeInsight.template.postfix.templates.PostfixTemplateProvider;
import de.endrullis.idea.postfixtemplates.language.psi.CptMapping;
import org.jetbrains.annotations.NotNull;

/**
* @author Stefan Endrullis &lt;stefan@endrullis.de&gt;
*/
class CsharpStringPostfixTemplateCreator {

@NotNull
static CustomCsharpStringPostfixTemplate createTemplate(CptMapping mapping, String matchingClass, String conditionClass, String templateName, String description, String template, PostfixTemplateProvider provider) {
return new CustomCsharpStringPostfixTemplate(matchingClass, conditionClass, templateName, description, template, provider, mapping);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.endrullis.idea.postfixtemplates.languages.csharp;

import com.intellij.codeInsight.template.postfix.templates.PostfixTemplateProvider;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.PsiElement;
import de.endrullis.idea.postfixtemplates.templates.SimpleStringBasedPostfixTemplate;
import de.endrullis.idea.postfixtemplates.templates.SpecialType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

/**
* Custom postfix template for C#.
*/
@SuppressWarnings("WeakerAccess")
public class CustomCsharpStringPostfixTemplate extends SimpleStringBasedPostfixTemplate {

/** Contains predefined type-to-psiCondition mappings as well as cached mappings for individual types. */
private static final Map<String, Condition<PsiElement>> type2psiCondition = new HashMap<String, Condition<PsiElement>>() {{
put(SpecialType.ANY.name(), e -> true);
}};

public CustomCsharpStringPostfixTemplate(String matchingClass, String conditionClass, String name, String example, String template, PostfixTemplateProvider provider, PsiElement psiElement) {
super(name, example, template, provider, psiElement, selectorAllExpressionsWithCurrentOffset(getCondition(matchingClass, conditionClass)));
}

@NotNull
public static Condition<PsiElement> getCondition(final @NotNull String matchingClass, final @Nullable String conditionClass) {
Condition<PsiElement> psiElementCondition = type2psiCondition.get(matchingClass);

// PyElementTypes.INTEGER_LITERAL_EXPRESSION
//TypeEvalContext.codeAnalysis(e.getProject(), e.getContainingFile()).getType((PyTypedElement) e)

if (psiElementCondition == null) {
//psiElementCondition = PythonPostfixTemplatesUtils.isCustomClass(matchingClass);
}

return psiElementCondition;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import de.endrullis.idea.postfixtemplates.language.CptLang;

/**
* Language definition for Java.
* Language definition for Python.
*
* @author Stefan Endrullis &lt;stefan@endrullis.de&gt;
*/
Expand Down

0 comments on commit 67737fc

Please sign in to comment.