use of org.elixir_lang.local_quick_fix.ConvertMatchToTypeOperation in project intellij-elixir by KronicDeth.
the class MatchOperatorInsteadOfTypeOperator 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 Match) {
Infix infix = (Infix) grandChild;
Operator operator = infix.operator();
int elementStartOffset = operator.getTextOffset();
ASTNode astNode = operatorTokenNode(operator);
int nodeStartOffset = astNode.getStartOffset();
int nodeTextLength = astNode.getTextLength();
int relativeStart = nodeStartOffset - elementStartOffset;
TextRange relativeTextRange = new TextRange(relativeStart, relativeStart + nodeTextLength);
LocalQuickFix localQuickFix = new ConvertMatchToTypeOperation(astNode);
problemsHolder.registerProblem(operator, "Type specifications separate the name from the definition using `::`, not `=`", ProblemHighlightType.ERROR, relativeTextRange, localQuickFix);
}
}
}
}
});
return problemsHolder.getResultsArray();
}
Aggregations