use of org.elixir_lang.local_quick_fix.ConvertKeywordPairToTypeOperation in project intellij-elixir by KronicDeth.
the class KeywordPairColonInsteadOfTypeOperator method checkFile.
/*
* Instance Methods
*/
@NotNull
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
final ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly);
file.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(@NotNull final PsiElement element) {
// See org.elixir_lang.annotator.ModuleAttribute.annotate for path of checks
if (element instanceof AtUnqualifiedNoParenthesesCall) {
visitAtUnqualifiedNoParenthesesCall((AtUnqualifiedNoParenthesesCall) element);
}
super.visitElement(element);
}
private void visitAtUnqualifiedNoParenthesesCall(@NotNull final AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall) {
ElixirAtIdentifier atIdentifier = atUnqualifiedNoParenthesesCall.getAtIdentifier();
String identifier = identifierName(atIdentifier);
if (isTypeName(identifier)) {
PsiElement child = atUnqualifiedNoParenthesesCall.getNoParenthesesOneArgument();
PsiElement[] grandChildren = child.getChildren();
if (grandChildren.length == 1) {
PsiElement grandChild = grandChildren[0];
if (grandChild instanceof QuotableKeywordList) {
QuotableKeywordList quotableKeywordList = (QuotableKeywordList) grandChild;
List<QuotableKeywordPair> quotableKeywordPairList = quotableKeywordList.quotableKeywordPairList();
if (quotableKeywordPairList.size() == 1) {
QuotableKeywordPair quotableKeywordPair = quotableKeywordPairList.get(0);
Quotable keywordKey = quotableKeywordPair.getKeywordKey();
PsiElement keywordPairColon = keywordKey.getNextSibling();
LocalQuickFix localQuickFix = new ConvertKeywordPairToTypeOperation(/* Can't be KEYWORD_PAIR_COLON because caret is never on the single
character in editor mode, only to left or right */
keywordPairColon);
problemsHolder.registerProblem(keywordPairColon, "Type specifications separate the name from the definition using `::`, not `:`", ProblemHighlightType.ERROR, localQuickFix);
}
}
}
}
}
});
return problemsHolder.getResultsArray();
}
Aggregations