/** * Checks if entries are relative. * * @param file current working file yo check * @param manager {@link InspectionManager} to ask for {@link ProblemDescriptor}'s from * @param isOnTheFly true if called during on the fly editor highlighting. Called from Inspect Code action * otherwise * @return <code>null</code> if no problems found or not applicable at file level */ @Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof IgnoreFile)) { return null; } final ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, isOnTheFly); file.acceptChildren(new IgnoreVisitor() { @Override public void visitEntry(@NotNull IgnoreEntry entry) { String path = entry.getText().replaceAll("\\\\(.)", "$1"); if (path.contains("./")) { problemsHolder.registerProblem(entry, IgnoreBundle.message("codeInspection.relativeEntry.message"), new IgnoreRelativeEntryFix(entry)); } super.visitEntry(entry); } }); return problemsHolder.getResultsArray(); }
final MultiMap<String, IgnoreEntry> entries = MultiMap.create(); file.acceptChildren(new IgnoreVisitor() { @Override public void visitEntry(@NotNull IgnoreEntry entry) {
@NotNull protected List<IgnoreEntry> getFixtureChildrenEntries() { final List<IgnoreEntry> children = ContainerUtil.newArrayList(); myFixture.getFile().acceptChildren(new IgnoreVisitor() { @Override public void visitEntry(@NotNull IgnoreEntry entry) { children.add(entry); } }); return children; }
/** * Maps indexed files content to the {@link IgnoreEntryOccurrence}. * * @param inputData indexed file data * @return {@link IgnoreEntryOccurrence} data mapped with {@link IgnoreFileTypeKey} */ @NotNull @Override public Map<IgnoreFileTypeKey, IgnoreEntryOccurrence> map(@NotNull final FileContent inputData) { if (!(inputData.getPsiFile() instanceof IgnoreFile)) { return Collections.emptyMap(); } final ArrayList<Pair<String, Boolean>> items = ContainerUtil.newArrayList(); inputData.getPsiFile().acceptChildren(new IgnoreVisitor() { @Override public void visitEntry(@NotNull IgnoreEntry entry) { final String regex = Glob.getRegex(entry.getValue(), entry.getSyntax(), false); items.add(Pair.create(regex, entry.isNegated())); } }); return Collections.singletonMap( new IgnoreFileTypeKey((IgnoreFileType) inputData.getFileType()), new IgnoreEntryOccurrence(inputData.getFile().getUrl(), items) ); }
final Document document = manager.getDocument(file); if (document != null) { file.acceptChildren(new IgnoreVisitor() { @Override public void visitEntry(@NotNull IgnoreEntry entry) {
private void visitYaml(final ProblemsHolder holder, PsiFile psiFile) { psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(PsiElement element) { if(YamlElementPatternHelper.getSingleLineScalarKey("_controller", "controller").accepts(element)) { String text = PsiElementUtils.trimQuote(element.getText()); if(StringUtils.isNotBlank(text)) { InspectionUtil.inspectController(element, text, holder, new YamlLazyRouteName(element)); } } super.visitElement(element); } }); }
private void visitXml(final ProblemsHolder holder, PsiFile psiFile) { psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(PsiElement element) { if(XmlHelper.getRouteControllerPattern().accepts(element)) { String text = PsiElementUtils.trimQuote(element.getText()); if(StringUtils.isNotBlank(text)) { InspectionUtil.inspectController(element, text, holder, new XmlLazyRouteName(element)); } } super.visitElement(element); } }); }
private void visitYamlFile(PsiFile psiFile, final ProblemsHolder holder, @NotNull final ContainerCollectionResolver.LazyServiceCollector lazyServiceCollector) { psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(PsiElement element) { annotateCallMethod(element, holder, lazyServiceCollector); super.visitElement(element); } }); }
private void xmlVisitor(final @NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) { psiFile.acceptChildren(new PsiRecursiveElementVisitor() { @Override public void visitElement(PsiElement psiElement) { if(psiElement instanceof XmlAttributeValue && (XmlHelper.getArgumentServiceIdPattern().accepts(psiElement) || XmlHelper.getServiceIdAttributePattern().accepts(psiElement))) { String serviceName = ((XmlAttributeValue) psiElement).getValue(); if(StringUtils.isNotBlank(serviceName) && !serviceName.equals(serviceName.toLowerCase()) && !YamlHelper.isClassServiceId(serviceName)) { holder.registerProblem(psiElement, SYMFONY_LOWERCASE_LETTERS_FOR_SERVICE, ProblemHighlightType.WEAK_WARNING); } } super.visitElement(psiElement); } }); }
private void yamlVisitor(@NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) { psiFile.acceptChildren(new PsiRecursiveElementVisitor() { @Override public void visitElement(PsiElement psiElement) { if(psiElement instanceof YAMLScalar) { String textValue = ((YAMLScalar) psiElement).getTextValue(); if(textValue.length() > 0 && textValue.startsWith("!php/const:")) { String constantName = textValue.substring(11); if(StringUtils.isNotBlank(constantName) && ServiceContainerUtil.getTargetsForConstant(psiElement.getProject(), constantName).size() == 0) { holder.registerProblem(psiElement, MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } } } super.visitElement(psiElement); } }); }
private void phpVisitor(final @NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) { psiFile.acceptChildren(new PsiRecursiveElementVisitor() { @Override public void visitElement(PsiElement element) { PsiElement parent = element.getParent(); if(!(parent instanceof StringLiteralExpression)) { super.visitElement(element); return; } MethodReference methodReference = PsiElementUtils.getMethodReferenceWithFirstStringParameter(element); if (methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, ServiceContainerUtil.SERVICE_GET_SIGNATURES)) { String serviceName = ((StringLiteralExpression) parent).getContents(); if(StringUtils.isNotBlank(serviceName) && !serviceName.equals(serviceName.toLowerCase())) { holder.registerProblem(element, SYMFONY_LOWERCASE_LETTERS_FOR_SERVICE, ProblemHighlightType.WEAK_WARNING); } } super.visitElement(element); } }); }
private void visitXmlFile(@NotNull PsiFile psiFile, @NotNull final ProblemsHolder holder, @NotNull final ContainerCollectionResolver.LazyServiceCollector lazyServiceCollector) { psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(PsiElement element) { if(XmlHelper.getTagAttributePattern("tag", "method").inside(XmlHelper.getInsideTagPattern("services")).inFile(XmlHelper.getXmlFilePattern()).accepts(element) || XmlHelper.getTagAttributePattern("call", "method").inside(XmlHelper.getInsideTagPattern("services")).inFile(XmlHelper.getXmlFilePattern()).accepts(element) ) { // attach to text child only PsiElement[] psiElements = element.getChildren(); if(psiElements.length < 2) { return; } String serviceClassValue = XmlHelper.getServiceDefinitionClass(element); if(serviceClassValue != null && StringUtils.isNotBlank(serviceClassValue)) { registerMethodProblem(psiElements[1], holder, serviceClassValue, lazyServiceCollector); } } super.visitElement(element); } }); }
private void xmlVisitor(@NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) { psiFile.acceptChildren(new PsiRecursiveElementVisitor() { @Override public void visitElement(PsiElement psiElement) { if(!XmlHelper.getArgumentValueWithTypePattern("constant").accepts(psiElement)) { super.visitElement(psiElement); return; } PsiElement xmlText = psiElement.getParent(); if(!(xmlText instanceof XmlText)) { super.visitElement(psiElement); return; } String value = ((XmlText) xmlText).getValue(); if(StringUtils.isBlank(value)) { super.visitElement(psiElement); return; } if(ServiceContainerUtil.getTargetsForConstant(xmlText.getProject(), value).size() == 0) { holder.registerProblem(xmlText, MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } super.visitElement(psiElement); } }); } }
private void yamlVisitor(final @NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) { psiFile.acceptChildren(new PsiRecursiveElementVisitor() { @Override public void visitElement(PsiElement psiElement) {
@Override public void visitFile(PsiFile psiFile) { if(psiFile instanceof YAMLFile) { psiFile.acceptChildren(new YmlClassElementWalkingVisitor(holder, new ContainerCollectionResolver.LazyServiceCollector(holder.getProject()))); } else if(psiFile instanceof XmlFile) { psiFile.acceptChildren(new XmlClassElementWalkingVisitor(holder, new ContainerCollectionResolver.LazyServiceCollector(holder.getProject()))); } } };
@Override public void visitFile(PsiFile psiFile) { ProblemRegistrar problemRegistrar = null; if(psiFile instanceof YAMLFile) { psiFile.acceptChildren(new YmlClassElementWalkingVisitor(holder, problemRegistrar = new ProblemRegistrar())); } else if(psiFile instanceof XmlFile) { psiFile.acceptChildren(new XmlClassElementWalkingVisitor(holder, problemRegistrar = new ProblemRegistrar())); } else if(psiFile instanceof PhpFile) { psiFile.acceptChildren(new PhpClassWalkingVisitor(holder, problemRegistrar = new ProblemRegistrar())); } if(problemRegistrar != null) { problemRegistrar.reset(); } super.visitFile(psiFile); } }
@Override public void collectPsiVariables(@NotNull final TwigFileVariableCollectorParameter parameter, @NotNull final Map<String, PsiVariable> variables) { PsiFile psiFile = parameter.getElement().getContainingFile(); if(!(psiFile instanceof TwigFile) || PsiTreeUtil.getChildOfType(psiFile, TwigExtendsTag.class) != null) { return; } Collection<VirtualFile> files = getImplements((TwigFile) psiFile); if(files.size() == 0) { return; } for(VirtualFile virtualFile: files) { PsiFile twigFile = PsiManager.getInstance(parameter.getProject()).findFile(virtualFile); if(!(twigFile instanceof TwigFile)) { continue; } twigFile.acceptChildren(new MyPsiRecursiveElementWalkingVisitor(psiFile, variables, parameter)); } }
@Override public void visitFile(PsiFile file) { file.acceptChildren(this); }
@Override public void doApplyInformationToEditor() { PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document); if (psiFile == null) { return; } psiFile.acceptChildren(new PsiClassVisitor(this)); }
public void testMultipleQueriesInOneLine() { parametersService.registerParametersProvider(emptyParametersProvider); PsiFile psiFile = myFixture.configureByText("test.cyp", "MATCH (n) RETURN n;MATCH (m) RETURN m;"); psiFile.acceptChildren(statementCollector); verify(eventMock, times(0)).handleError(any(), any()); assertThat(statementCollector.hasErrors()) .isFalse(); assertThat(statementCollector.getParameters()) .isEmpty(); assertThat(statementCollector.getQueries()) .containsExactly("MATCH (n) RETURN n;", "MATCH (m) RETURN m;"); }