@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) { return new PhpElementVisitor() { @Override public void visitPhpClass(PhpClass clazz) { PhpIndex index = PhpIndex.getInstance(problemsHolder.getProject()); if (DatabaseUtils.HasConnections(problemsHolder.getProject()) && ClassUtils.isClassInheritsOrEqual(clazz, ClassUtils.getClass(index, "\\yii\\db\\ActiveRecord"))) { String table = DatabaseUtils.getTableByActiveRecordClass(clazz); if (table == null) { problemsHolder.registerProblem(clazz.getFirstChild(), "Can not detect database table for class " + clazz.getFQN(), ProblemHighlightType.WEAK_WARNING); } else if (! DatabaseUtils.isTableExists(table, problemsHolder.getProject())) { problemsHolder.registerProblem(clazz.getFirstChild(), "Table '" + table + "' not found in database connections", ProblemHighlightType.WEAK_WARNING); } } super.visitPhpClass(clazz); } }; }
@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"); } } }; }
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { if (JNomadInspection.jnomad == null) { setupJNomad(); } List<EnvFileFullReport> fileFullReports; VirtualFile virtualFile = holder.getFile().getVirtualFile(); if (virtualFile.getPath().endsWith("java") && virtualFile instanceof VirtualFileImpl) { CharSequence contents = holder.getFile().getViewProvider().getContents(); fileFullReports = getFileFullReports(contents); return new JNomadQueryVisitor(holder, holder.getFile().getVirtualFile(), fileFullReports.toArray(new EnvFileFullReport[0])); } return new JNomadQueryVisitor(holder, holder.getFile().getVirtualFile(), null); }
@NotNull @Override public PsiElementVisitor buildVisitor( @NotNull final ProblemsHolder problemsHolder, final boolean isOnTheFly ) { return new PhpElementVisitor() { @Override public void visitPhpMethod(final Method method) { final PhpReturnType returnType = method.getReturnType(); final ClassReference methodReturnTypeClassReference = (returnType != null) ? returnType.getClassReference() : null; if (FluentUtil.isUsingDirectly(methodReturnTypeClassReference)) { problemsHolder.registerProblem(methodReturnTypeClassReference, messageDirectInstantiation, ProblemHighlightType.WEAK_WARNING); } } @Override public void visitPhpFunction(final Function function) { final PhpReturnType functionReturnType = function.getReturnType(); if ((functionReturnType != null) && FluentUtil.isUsingDirectly(functionReturnType.getClassReference())) { problemsHolder.registerProblem(functionReturnType, messageDirectInstantiation, ProblemHighlightType.WEAK_WARNING); } } @Override public void visitPhpParameter(final Parameter parameter) { if (FluentUtil.isUsingDirectly(parameter)) { problemsHolder.registerProblem(parameter, messageDirectInstantiation, ProblemHighlightType.WEAK_WARNING); } } @Override public void visitPhpDocType(final PhpDocType type) { if (FluentUtil.isUsingDirectly(type)) { problemsHolder.registerProblem(type, messageDirectInstantiation, ProblemHighlightType.WEAK_WARNING); } } }; }
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) { return new PhpElementVisitor() { @Override public void visitPhpElement(PhpPsiElement element) { if (element instanceof PhpDocTag) { PhpDocTag tag = (PhpDocTag) element; if ("@inject".equals(tag.getName())) { problemsHolder.registerProblem(element, "Extbase property injection", new CreateInjectorQuickFix(element)); } } } }; }
public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof FlexibleSearchVisitor) accept((FlexibleSearchVisitor)visitor); else super.accept(visitor); }
public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof MasVisitor) accept((MasVisitor)visitor); else super.accept(visitor); }
public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof AppleScriptVisitor) accept((AppleScriptVisitor)visitor); else super.accept(visitor); }
public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof CptVisitor) accept((CptVisitor)visitor); else super.accept(visitor); }
public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof GCMVisitor) accept((GCMVisitor)visitor); else super.accept(visitor); }
public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof DotEnvVisitor) accept((DotEnvVisitor)visitor); else super.accept(visitor); }
public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof TestVisitor) accept((TestVisitor)visitor); else super.accept(visitor); }
public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof ModuleVisitor) accept((ModuleVisitor)visitor); else super.accept(visitor); }
@Override @NotNull public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new PhpElementVisitor() { @Override public void visitPhpMethodReference(MethodReference reference) { /* ensure that it's a target call; category is not empty and has no injections; we have messages */ TranslationCallsProcessUtil.ProcessingResult extracted = TranslationCallsProcessUtil.process(reference, true); if (null == extracted) { return; } /* handle `category` and `category/subcategory` cases */ String categoryForFileName = extracted.getCategory().getContents(); if (-1 != categoryForFileName.indexOf('/')) { categoryForFileName = categoryForFileName.substring(1 + categoryForFileName.lastIndexOf('/'), categoryForFileName.length()); } final String expectedFileName = categoryForFileName + ".php"; /* iterate found translations and validate correctness */ final Map<StringLiteralExpression, PsiElement> messages = extracted.getMessages(); for (StringLiteralExpression literal : messages.keySet()) { /* only quotes, no content presented */ if (literal.getTextLength() <= 2) { continue; } final String message = literal.getContents(); final PsiElement reportingTarget = messages.get(literal); /* warn injections are presented and skip further processing */ if (REPORT_INJECTIONS && null != literal.getFirstPsiChild()) { holder.registerProblem(reportingTarget, messageInjection, ProblemHighlightType.WEAK_WARNING); continue; } /* warn if non-ascii characters has been used */ if (REPORT_NONASCII_CHARACTERS && nonAsciiCharsRegex.matcher(message).matches()) { holder.registerProblem(reportingTarget, messageNonAscii, ProblemHighlightType.WEAK_WARNING); } /* warn if the message is have no translations in the group */ final Set<String> searchEntry = new HashSet<>(Collections.singletonList(PhpStringUtil.unescapeText(message, literal.isSingleQuote()))); GlobalSearchScope theScope = GlobalSearchScope.allScope(reference.getProject()); theScope = GlobalSearchScope.getScopeRestrictedByFileTypes(theScope, PhpFileType.INSTANCE); final Set<VirtualFile> providers = new HashSet<>(); FileBasedIndex.getInstance() .getFilesWithKey(TranslationKeysIndexer.identity, searchEntry, virtualFile -> { if (virtualFile.getName().equals(expectedFileName)) { providers.add(virtualFile); } return true; }, theScope); /* report found cases */ if (REPORT_UNKNOWN_TRANSLATIONS && 0 == providers.size()) { holder.registerProblem(reportingTarget, messageNoTranslations, ProblemHighlightType.WEAK_WARNING); } providers.clear(); } extracted.dispose(); } }; }