-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepared adding support for C# and Rider
- Loading branch information
Showing
11 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
resources/postfixTemplates/CustomCsharpStringPostfixTemplate/after.java.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 2 additions & 0 deletions
2
resources/postfixTemplates/CustomCsharpStringPostfixTemplate/before.java.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
21 changes: 21 additions & 0 deletions
21
resources/postfixTemplates/CustomCsharpStringPostfixTemplate/description.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/de/endrullis/idea/postfixtemplates/languages/csharp/CsharpAnnotator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <stefan@endrullis.de> | ||
*/ | ||
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())); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/de/endrullis/idea/postfixtemplates/languages/csharp/CsharpLang.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <stefan@endrullis.de> | ||
*/ | ||
public class CsharpLang extends CptLang { | ||
|
||
public CsharpLang() { | ||
super("C#", CsharpAnnotator.class); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/de/endrullis/idea/postfixtemplates/languages/csharp/CsharpPostfixTemplateProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
.../endrullis/idea/postfixtemplates/languages/csharp/CsharpStringPostfixTemplateCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <stefan@endrullis.de> | ||
*/ | ||
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); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...e/endrullis/idea/postfixtemplates/languages/csharp/CustomCsharpStringPostfixTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters