-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support for combining defaults and constraints in type generics
- Loading branch information
Showing
10 changed files
with
140 additions
and
79 deletions.
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
42 changes: 42 additions & 0 deletions
42
.../com/intellij/plugins/haxe/ide/annotator/semantics/HaxeDefaultTypeParameterAnnotator.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,42 @@ | ||
package com.intellij.plugins.haxe.ide.annotator.semantics; | ||
|
||
import com.intellij.lang.annotation.AnnotationHolder; | ||
import com.intellij.lang.annotation.Annotator; | ||
import com.intellij.lang.annotation.HighlightSeverity; | ||
import com.intellij.plugins.haxe.lang.lexer.HaxeTokenTypes; | ||
import com.intellij.plugins.haxe.lang.psi.HaxeGenericDefaultType; | ||
import com.intellij.plugins.haxe.lang.psi.HaxeGenericListPart; | ||
import com.intellij.plugins.haxe.lang.psi.HaxeMethodDeclaration; | ||
import com.intellij.plugins.haxe.model.fixer.HaxeFixer; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class HaxeDefaultTypeParameterAnnotator implements Annotator { | ||
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) { | ||
if (element instanceof HaxeGenericListPart genericListPart) { | ||
check(genericListPart, holder); | ||
} | ||
} | ||
|
||
public static void check(HaxeGenericListPart psi, AnnotationHolder holder) { | ||
|
||
HaxeGenericDefaultType type = psi.getGenericDefaultType(); | ||
PsiElement parent1 = psi.getParent(); | ||
PsiElement parent2 = parent1.getParent(); | ||
|
||
if (type != null && parent2 instanceof HaxeMethodDeclaration) { | ||
PsiElement equalsToken = PsiTreeUtil.findSiblingBackward(type, HaxeTokenTypes.OASSIGN, null); | ||
//TODO extract text to bundle | ||
holder.newAnnotation(HighlightSeverity.ERROR, "Default type parameters are only supported on types") | ||
.range(type) | ||
.withFix(new HaxeFixer("Remove default type") { | ||
@Override | ||
public void run() { | ||
psi.deleteChildRange(equalsToken, type); | ||
} | ||
}) | ||
.create(); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
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