use of com.intellij.psi.impl.source.tree.LeafElement in project phpinspectionsea by kalessil.
the class MisorderedModifiersInspector method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder problemsHolder, final boolean isOnTheFly) {
return new BasePhpElementVisitor() {
@Override
public void visitPhpMethod(@NotNull Method method) {
if (method.isStatic() || method.isAbstract() || method.isFinal()) {
final PhpModifierList modifiersNode = PsiTreeUtil.findChildOfType(method, PhpModifierList.class);
final List<LeafPsiElement> modifiers = PsiTreeUtil.findChildrenOfType(modifiersNode, LeafPsiElement.class).stream().filter(element -> !(element instanceof PsiWhiteSpace)).collect(Collectors.toList());
if (modifiersNode != null && modifiers.size() >= 2) {
final String original = this.getOriginalOrder(modifiers);
final String expected = this.getExpectedOrder(original, standardOrder);
if (!original.equals(expected)) {
problemsHolder.registerProblem(modifiersNode, MessagesPresentationUtil.prefixWithEa(message), new TheLocalFix(expected));
}
}
}
}
@NotNull
private String getOriginalOrder(@NotNull Collection<LeafPsiElement> original) {
return original.stream().map(LeafElement::getText).collect(Collectors.joining(" ")).toLowerCase();
}
@NotNull
private String getExpectedOrder(@NotNull String original, @NotNull Collection<String> expected) {
return expected.stream().filter(original::contains).collect(Collectors.joining(" "));
}
};
}
Aggregations