use of com.jetbrains.php.lang.psi.elements.PhpPsiElement in project phpinspectionsea by kalessil.
the class SuspiciousOperatorFormattingStrategy method apply.
public static void apply(@NotNull AssignmentExpression expression, @NotNull ProblemsHolder holder) {
final PhpPsiElement value = expression.getValue();
if (value instanceof UnaryExpression) {
/* previous should be "...=[!+-] ..." */
final PsiElement previous = value.getPrevSibling();
if (null == previous || PhpTokenTypes.opASGN != previous.getNode().getElementType()) {
return;
}
final PsiElement valueOperator = ((UnaryExpression) value).getOperation();
if (null == valueOperator || !(valueOperator.getNextSibling() instanceof PsiWhiteSpace)) {
return;
}
/* analyze statement */
final IElementType valueOperation = valueOperator.getNode().getElementType();
if (mapping.containsKey(valueOperation)) {
holder.registerProblem(expression, MessagesPresentationUtil.prefixWithEa(messagePattern.replace("%o%", mapping.get(valueOperation))));
}
}
}
use of com.jetbrains.php.lang.psi.elements.PhpPsiElement in project phpinspectionsea by kalessil.
the class DuplicateArrayKeysInspector method buildVisitor.
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PhpElementVisitor() {
@Override
public void visitPhpArrayCreationExpression(@NotNull ArrayCreationExpression expression) {
final Map<String, PsiElement> processed = new HashMap<>();
for (final ArrayHashElement pair : expression.getHashElements()) {
final PhpPsiElement key = pair.getKey();
if (key instanceof StringLiteralExpression && key.getFirstPsiChild() == null) {
final PsiElement value = pair.getValue();
if (value != null) {
final String literal = ((StringLiteralExpression) key).getContents();
if (processed.containsKey(literal)) {
final boolean isPairDuplicated = !(value instanceof ArrayCreationExpression) && OpenapiEquivalenceUtil.areEqual(value, processed.get(literal));
if (isPairDuplicated) {
holder.registerProblem(pair, MessagesPresentationUtil.prefixWithEa(messageDuplicatePair), ProblemHighlightType.LIKE_UNUSED_SYMBOL);
} else {
holder.registerProblem(key, MessagesPresentationUtil.prefixWithEa(messageDuplicateKey));
}
}
processed.put(literal, value);
}
}
}
processed.clear();
}
};
}
use of com.jetbrains.php.lang.psi.elements.PhpPsiElement in project idea-php-typo3-plugin by cedricziel.
the class ClassConstantMatcherInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
return new PhpElementVisitor() {
@Override
public void visitPhpElement(PhpPsiElement element) {
if (!PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE).accepts(element)) {
return;
}
Set<String> constants = getDeprecatedClassConstants(element);
ClassConstantReference classConstantReference = (ClassConstantReference) element;
if (constants.contains(classConstantReference.getText())) {
problemsHolder.registerProblem(element, "Deprecated class constant");
}
}
};
}
use of com.jetbrains.php.lang.psi.elements.PhpPsiElement in project idea-php-typo3-plugin by cedricziel.
the class ClassNameMatcherInspection method getDeprecatedClasses.
private Set<String> getDeprecatedClasses(PhpPsiElement element) {
Set<PsiElement> elements = new HashSet<>();
PsiFile[] classNameMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ClassNameMatcher.php", GlobalSearchScope.allScope(element.getProject()));
for (PsiFile file : classNameMatcherFiles) {
Collections.addAll(elements, PsiTreeUtil.collectElements(file, el -> PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withAncestor(4, PlatformPatterns.psiElement(PhpElementTypes.RETURN))).accepts(el)));
}
return elements.stream().map(stringLiteral -> "\\" + ((StringLiteralExpression) stringLiteral).getContents()).collect(Collectors.toSet());
}
use of com.jetbrains.php.lang.psi.elements.PhpPsiElement in project idea-php-typo3-plugin by cedricziel.
the class FunctionCallMatcherInspection method getRemovedGlobalFuntions.
private Set<String> getRemovedGlobalFuntions(PhpPsiElement element) {
Set<PsiElement> elements = new HashSet<>();
PsiFile[] constantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "FunctionCallMatcher.php", GlobalSearchScope.allScope(element.getProject()));
for (PsiFile file : constantMatcherFiles) {
Collections.addAll(elements, PsiTreeUtil.collectElements(file, el -> PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withAncestor(4, PlatformPatterns.psiElement(PhpElementTypes.RETURN))).accepts(el)));
}
return elements.stream().map(stringLiteral -> "\\" + ((StringLiteralExpression) stringLiteral).getContents()).collect(Collectors.toSet());
}
Aggregations