use of com.jetbrains.php.lang.psi.elements.ForeachStatement in project phpinspectionsea by kalessil.
the class UnsupportedEmptyListAssignmentsInspector method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new BasePhpElementVisitor() {
@Override
public void visitPhpForeach(@NotNull ForeachStatement expression) {
if (PhpLanguageLevel.get(holder.getProject()).atLeast(PhpLanguageLevel.PHP700) && expression.getVariables().isEmpty()) {
final PsiElement first = expression.getFirstChild();
if (first != null) {
boolean reachedAsKeyword = false;
boolean isTarget = false;
PsiElement current = first.getNextSibling();
while (current != null) {
if (!reachedAsKeyword) {
reachedAsKeyword = OpenapiTypesUtil.is(current, PhpTokenTypes.kwAS);
} else {
isTarget = OpenapiTypesUtil.is(current, PhpTokenTypes.kwLIST) || OpenapiTypesUtil.is(current, PhpTokenTypes.chLBRACKET);
if (isTarget) {
break;
}
}
current = current.getNextSibling();
}
if (isTarget) {
holder.registerProblem(current, MessagesPresentationUtil.prefixWithEa(message), ProblemHighlightType.GENERIC_ERROR);
}
}
}
}
};
}
use of com.jetbrains.php.lang.psi.elements.ForeachStatement in project phpinspectionsea by kalessil.
the class ShortListSyntaxCanBeUsedInspector method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new BasePhpElementVisitor() {
public void visitPhpMultiassignmentExpression(MultiassignmentExpression multiassignmentExpression) {
/* ensure php version is at least PHP 7.1 */
final PhpLanguageLevel phpVersion = PhpProjectConfigurationFacade.getInstance(holder.getProject()).getLanguageLevel();
if (phpVersion.compareTo(PhpLanguageLevel.PHP710) < 0) {
return;
}
/* verify if it's dedicated statement and it's the list(...) construction */
final PsiElement parent = multiassignmentExpression.getParent();
if (!OpenapiTypesUtil.isStatementImpl(parent)) {
return;
}
final PsiElement listKeyword = multiassignmentExpression.getFirstChild();
if (null != listKeyword && PhpTokenTypes.kwLIST == listKeyword.getNode().getElementType()) {
holder.registerProblem(listKeyword, messageAssign, ProblemHighlightType.WEAK_WARNING, new TheLocalFix());
}
}
public void visitPhpForeach(ForeachStatement foreach) {
/* ensure php version is at least PHP 7.1 */
final PhpLanguageLevel phpVersion = PhpProjectConfigurationFacade.getInstance(holder.getProject()).getLanguageLevel();
if (phpVersion.compareTo(PhpLanguageLevel.PHP710) < 0) {
return;
}
final List<Variable> variables = foreach.getVariables();
if (variables.size() > 0) {
PsiElement childNode = foreach.getFirstChild();
while (null != childNode) {
if (childNode.getClass() == LeafPsiElement.class && PhpTokenTypes.kwLIST == childNode.getNode().getElementType()) {
holder.registerProblem(childNode, messageForeach, ProblemHighlightType.WEAK_WARNING, new TheLocalFix());
break;
}
childNode = childNode.getNextSibling();
if (childNode instanceof GroupStatement) {
break;
}
}
}
}
};
}
Aggregations