Java Code Examples for com.intellij.codeInspection.ProblemsHolder#registerProblem()
The following examples show how to use
com.intellij.codeInspection.ProblemsHolder#registerProblem() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgnoreSyntaxEntryInspection.java From idea-gitignore with MIT License | 6 votes |
/** * Checks if syntax entry has correct value. * * @param holder where visitor will register problems found. * @param isOnTheFly true if inspection was run in non-batch mode * @return not-null visitor for this inspection */ @NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new IgnoreVisitor() { @Override public void visitSyntax(@NotNull IgnoreSyntax syntax) { IgnoreLanguage language = (IgnoreLanguage) syntax.getContainingFile().getLanguage(); if (!language.isSyntaxSupported()) { return; } String value = syntax.getValue().getText(); for (IgnoreBundle.Syntax s : IgnoreBundle.Syntax.values()) { if (s.toString().equals(value)) { return; } } holder.registerProblem(syntax, IgnoreBundle.message("codeInspection.syntaxEntry.message"), new IgnoreSyntaxEntryFix(syntax)); } }; }
Example 2
Source File: UnnecessarySemicolonInspection.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nonnull @Override public PsiElementVisitor buildVisitor(@Nonnull final ProblemsHolder holder, boolean isOnTheFly) { return new CSharpElementVisitor() { @Override @RequiredReadAction public void visitEmptyStatement(CSharpEmptyStatementImpl statement) { PsiElement parent = statement.getParent(); if(parent instanceof CSharpBlockStatementImpl) { holder.registerProblem(statement, null, "Unnecessary Semicolon", new RemoveSemicolonFix(statement)); } } }; }
Example 3
Source File: LegacyClassesForIDEInspection.java From idea-php-typo3-plugin with MIT License | 6 votes |
@NotNull @Override public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) { return new PhpElementVisitor() { @Override public void visitPhpClassReference(ClassReference classReference) { if (classReference.getFQN() != null && LegacyClassesForIDEIndex.isLegacyClass(classReference.getProject(), classReference.getFQN())) { problemsHolder.registerProblem(classReference, "Legacy class usage", ProblemHighlightType.LIKE_DEPRECATED, new LegacyClassesForIdeQuickFix()); } super.visitPhpClassReference(classReference); } @Override public void visitPhpClassConstantReference(ClassConstantReference constantReference) { super.visitPhpClassConstantReference(constantReference); } }; }
Example 4
Source File: ValProcessor.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void verifyParameter(@NotNull final PsiParameter psiParameter, @NotNull final ProblemsHolder holder) { final PsiTypeElement typeElement = psiParameter.getTypeElement(); final String typeElementText = null != typeElement ? typeElement.getText() : null; boolean isVal = isPossibleVal(typeElementText) && isVal(resolveQualifiedName(typeElement)); boolean isVar = isPossibleVar(typeElementText) && isVar(resolveQualifiedName(typeElement)); if (isVar || isVal) { PsiElement scope = psiParameter.getDeclarationScope(); boolean isForeachStatement = scope instanceof PsiForeachStatement; boolean isForStatement = scope instanceof PsiForStatement; if (isVal && !isForeachStatement) { holder.registerProblem(psiParameter, "'val' works only on local variables and on foreach loops", ProblemHighlightType.ERROR); } else if (isVar && !(isForeachStatement || isForStatement)) { holder.registerProblem(psiParameter, "'var' works only on local variables and on for/foreach loops", ProblemHighlightType.ERROR); } } }
Example 5
Source File: RepositoryClassInspection.java From idea-php-annotation-plugin with MIT License | 6 votes |
@NotNull @Override public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) { if(!DoctrineUtil.isDoctrineOrmInVendor(holder.getProject())) { return super.buildVisitor(holder, isOnTheFly); } return new MyAnnotationPropertyPsiElementVisitor("Doctrine\\ORM\\Mapping\\Entity") { @Override protected void visitAnnotationProperty(@NotNull PhpDocTag phpDocTag) { StringLiteralExpression repositoryClass = AnnotationUtil.getPropertyValueAsPsiElement(phpDocTag, "repositoryClass"); if (repositoryClass == null) { return; } if(!DoctrineUtil.repositoryClassExists(phpDocTag)) { holder.registerProblem( repositoryClass, MESSAGE, new DoctrineOrmRepositoryIntention() ); } } }; }
Example 6
Source File: IgnoreIncorrectEntryInspection.java From idea-gitignore with MIT License | 6 votes |
/** * Checks if entry has correct form in specific according to the specific {@link IgnoreBundle.Syntax}. * * @param holder where visitor will register problems found. * @param isOnTheFly true if inspection was run in non-batch mode * @return not-null visitor for this inspection */ @NotNull @Override @SuppressWarnings("ResultOfMethodCallIgnored") public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new IgnoreVisitor() { @Override public void visitEntry(@NotNull IgnoreEntry entry) { String regex = entry.getText(); if (IgnoreBundle.Syntax.GLOB.equals(entry.getSyntax())) { regex = Glob.createRegex(regex, false); } try { Pattern.compile(regex); } catch (PatternSyntaxException e) { holder.registerProblem(entry, IgnoreBundle.message("codeInspection.incorrectEntry.message", e.getDescription())); } } }; }
Example 7
Source File: MethodArgumentDroppedMatcherInspection.java From idea-php-typo3-plugin with MIT License | 6 votes |
@NotNull @Override public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) { return new PhpElementVisitor() { @Override public void visitPhpMethodReference(MethodReference reference) { ParameterList parameterList = reference.getParameterList(); PhpExpression classReference = reference.getClassReference(); if (classReference != null) { PhpType inferredType = classReference.getInferredType(); String compiledClassMethodKey = inferredType.toString() + "->" + reference.getName(); if (ExtensionScannerUtil.classMethodHasDroppedArguments(reference.getProject(), compiledClassMethodKey)) { int maximumNumberOfArguments = ExtensionScannerUtil.getMaximumNumberOfArguments(reference.getProject(), compiledClassMethodKey); if (parameterList != null && maximumNumberOfArguments != -1 && parameterList.getParameters().length != maximumNumberOfArguments) { problemsHolder.registerProblem(reference, "Number of arguments changes with upcoming TYPO3 version, consider refactoring"); } } } super.visitPhpMethodReference(reference); } }; }
Example 8
Source File: UndefinedVariableInspection.java From idea-php-typo3-plugin with MIT License | 6 votes |
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new PsiElementVisitor() { @Override public void visitElement(PsiElement element) { if (!PlatformPatterns.psiElement(FluidTypes.IDENTIFIER).withParent( PlatformPatterns.psiElement(FluidFieldChain.class).withParent(FluidFieldExpr.class)) .accepts(element)) { super.visitElement(element); return; } if (!FluidUtil.findVariablesInCurrentContext(element).containsKey(element.getText())) { holder.registerProblem(element, String.format(MESSAGE, element.getText()), ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } super.visitElement(element); } }; }
Example 9
Source File: RouteSettingDeprecatedInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private void registerAttributeRequirementProblem(@NotNull ProblemsHolder holder, @NotNull XmlAttributeValue xmlAttributeValue, @NotNull final String requirementAttribute) { if(!xmlAttributeValue.getValue().equals(requirementAttribute)) { return; } XmlAttribute xmlAttributeKey = PsiElementAssertUtil.getParentOfTypeWithNameOrNull(xmlAttributeValue, XmlAttribute.class, "key"); if(xmlAttributeKey != null) { XmlTag xmlTagDefault = PsiElementAssertUtil.getParentOfTypeWithNameOrNull(xmlAttributeKey, XmlTag.class, "requirement"); if(xmlTagDefault != null) { XmlTag xmlTagRoute = PsiElementAssertUtil.getParentOfTypeWithNameOrNull(xmlTagDefault, XmlTag.class, "route"); if(xmlTagRoute != null) { // attach to attribute token only we dont want " or ' char included PsiElement target = findAttributeValueToken(xmlAttributeValue, requirementAttribute); holder.registerProblem(target != null ? target : xmlAttributeValue, String.format("The '%s' requirement is deprecated", requirementAttribute), ProblemHighlightType.LIKE_DEPRECATED); } } } }
Example 10
Source File: InvalidQuantityInspection.java From idea-php-typo3-plugin with MIT License | 6 votes |
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) { if (!TYPO3CMSProjectSettings.isEnabled(problemsHolder.getProject())) { return new PhpElementVisitor() { }; } return new PhpElementVisitor() { @Override public void visitPhpElement(PhpPsiElement element) { boolean isArrayStringValue = PhpElementsUtil.isStringArrayValue().accepts(element); if (!isArrayStringValue || !insideTCAColumnDefinition(element)) { return; } String arrayIndex = extractArrayIndexFromValue(element); if (arrayIndex != null && Arrays.asList(TCAUtil.TCA_NUMERIC_CONFIG_KEYS).contains(arrayIndex)) { if (element instanceof StringLiteralExpression) { problemsHolder.registerProblem(element, "Config key only accepts integer values"); } } } }; }
Example 11
Source File: RouteSettingDeprecatedInspection.java From idea-php-symfony2-plugin with MIT License | 5 votes |
private void registerYmlRoutePatternProblem(@NotNull ProblemsHolder holder, @NotNull YAMLKeyValue element) { String s = PsiElementUtils.trimQuote(element.getKeyText()); if("pattern".equals(s) && YamlHelper.isRoutingFile(element.getContainingFile())) { // pattern: foo holder.registerProblem(element.getKey(), "Pattern is deprecated; use path instead", ProblemHighlightType.LIKE_DEPRECATED); } else if(("_method".equals(s) || "_scheme".equals(s)) && YamlHelper.isRoutingFile(element.getContainingFile())) { // requirements: { _method: 'foo', '_scheme': 'foo' } YAMLKeyValue parentOfType = PsiTreeUtil.getParentOfType(element, YAMLKeyValue.class); if(parentOfType != null && "requirements".equals(parentOfType.getKeyText())) { holder.registerProblem(element.getKey(), String.format("The '%s' requirement is deprecated", s), ProblemHighlightType.LIKE_DEPRECATED); } } }
Example 12
Source File: ShopwareBoostrapInspection.java From idea-php-shopware-plugin with MIT License | 5 votes |
@NotNull @Override public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) { PsiFile psiFile = holder.getFile(); if(!ShopwareProjectComponent.isValidForProject(psiFile)) { return super.buildVisitor(holder, isOnTheFly); } if(!"Bootstrap.php".equals(psiFile.getName())) { return super.buildVisitor(holder, isOnTheFly); } return new PsiElementVisitor() { @Override public void visitElement(PsiElement element) { if(element instanceof Method) { String methodName = ((Method) element).getName(); if(INSTALL_METHODS.contains(((Method) element).getName())) { if(PsiTreeUtil.collectElementsOfType(element, PhpReturn.class).size() == 0) { PsiElement psiElement = PsiElementUtils.getChildrenOfType(element, PlatformPatterns.psiElement(PhpTokenTypes.IDENTIFIER).withText(methodName)); if(psiElement != null) { holder.registerProblem(psiElement, "Shopware need return statement", ProblemHighlightType.GENERIC_ERROR); } } } } super.visitElement(element); } }; }
Example 13
Source File: UndefinedNamespaceInspection.java From idea-php-typo3-plugin with MIT License | 5 votes |
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new PsiElementVisitor() { @Override public void visitElement(PsiElement element) { if (!(element instanceof FluidBoundNamespace)) { super.visitElement(element); return; } for (NamespaceProvider extension : NamespaceProvider.EP_NAME.getExtensions()) { Collection<FluidNamespace> fluidNamespaces = extension.provideForElement(element); for (FluidNamespace fluidNamespace : fluidNamespaces) { if (fluidNamespace.prefix.equals(element.getText())) { super.visitElement(element); return; } } } holder.registerProblem(element, "Unbound viewHelper namespace", ProblemHighlightType.GENERIC_ERROR_OR_WARNING); super.visitElement(element); } }; }
Example 14
Source File: MissingModulePHPInspection.java From idea-php-typo3-plugin with MIT License | 5 votes |
@NotNull @Override public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) { return new PhpElementVisitor() { @Override public void visitPhpStringLiteralExpression(StringLiteralExpression expression) { if (!getLoadRequireJsModulePattern().accepts(expression)) { super.visitPhpStringLiteralExpression(expression); return; } PsiElement firstParent = PsiTreeUtil.findFirstParent(expression, e -> e instanceof MethodReference); if (!(firstParent instanceof MethodReference)) { super.visitPhpStringLiteralExpression(expression); return; } MethodReference methodReference = (MethodReference) firstParent; if (methodReference.getName() == null || !methodReference.getName().equals("loadRequireJsModule")) { super.visitPhpStringLiteralExpression(expression); return; } if (expression.getPrevPsiSibling() instanceof StringLiteralExpression) { super.visitPhpStringLiteralExpression(expression); return; } if (JavaScriptUtil.getModuleMap(expression.getProject()).containsKey(expression.getContents())) { return; } problemsHolder.registerProblem(expression, String.format("Unknown JavaScript module \"%s\"", expression.getContents())); } }; }
Example 15
Source File: AnnotationDocBlockClassConstantNotFoundInspection.java From idea-php-annotation-plugin with MIT License | 5 votes |
private void visitAnnotationDocTag(@NotNull PhpDocTag phpDocTag, @NotNull ProblemsHolder holder, @NotNull AnnotationInspectionUtil.LazyNamespaceImportResolver lazyUseImporterCollector) { for (PsiElement element : PsiTreeUtil.collectElements(phpDocTag, psiElement -> psiElement.getNode().getElementType() == PhpDocTokenTypes.DOC_STATIC)) { PsiElement nextSibling = element.getNextSibling(); if (nextSibling == null || nextSibling.getNode().getElementType() != PhpDocTokenTypes.DOC_IDENTIFIER || !"class".equals(nextSibling.getText())) { continue; } PsiElement prevSibling = element.getPrevSibling(); if (prevSibling == null) { return; } String namespaceForDocIdentifier = PhpDocUtil.getNamespaceForDocIdentifier(prevSibling); if (namespaceForDocIdentifier == null) { return; } String clazz = AnnotationInspectionUtil.getClassFqnString(namespaceForDocIdentifier, lazyUseImporterCollector); if (clazz == null) { return; } PhpClass classInterface = PhpElementsUtil.getClassInterface(phpDocTag.getProject(), clazz); if (classInterface == null) { holder.registerProblem( nextSibling, MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING ); } } }
Example 16
Source File: SimpleVarUsageInspection.java From BashSupport with Apache License 2.0 | 5 votes |
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) { return new BashVisitor() { @Override public void visitVarUse(BashVar var) { if (var.getTextLength() != 0 && ReplaceVarWithParamExpansionQuickfix.isAvailableAt(var)) { holder.registerProblem(var, "Simple variable usage", new ReplaceVarWithParamExpansionQuickfix(var)); } } }; }
Example 17
Source File: AnnotationDeprecatedInspection.java From idea-php-annotation-plugin with MIT License | 5 votes |
private void visitAnnotationDocTag(PhpDocTag phpDocTag, @NotNull ProblemsHolder holder) { PhpClass phpClass = AnnotationUtil.getAnnotationReference(phpDocTag); if (phpClass == null || !phpClass.isDeprecated()) { return; } PsiElement firstChild = phpDocTag.getFirstChild(); if (firstChild == null || firstChild.getNode().getElementType() != PhpDocElementTypes.DOC_TAG_NAME) { return; } holder.registerProblem(firstChild, MESSAGE, ProblemHighlightType.LIKE_DEPRECATED); }
Example 18
Source File: ExtbasePropertyInjectionInspection.java From idea-php-typo3-plugin with MIT License | 5 votes |
@NotNull @Override public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) { return new PhpElementVisitor() { @Override public void visitPhpDocTag(PhpDocTag tag) { if ("@inject".equals(tag.getName())) { problemsHolder.registerProblem(tag, "Extbase property injection", new CreateInjectorQuickFix(tag)); } super.visitPhpDocTag(tag); } }; }
Example 19
Source File: ReadonlyVariableInspection.java From BashSupport with Apache License 2.0 | 4 votes |
private void registerWarning(BashVarDef varDef, @NotNull ProblemsHolder holder) { holder.registerProblem(varDef, "Change to a read-only variable", LocalQuickFix.EMPTY_ARRAY); }
Example 20
Source File: DuplicateFunctionDefInspection.java From BashSupport with Apache License 2.0 | 4 votes |
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new BashVisitor() { @Override public void visitFunctionDef(BashFunctionDef functionDef) { BashFunctionProcessor p = new BashFunctionProcessor(functionDef.getName(), true); boolean isOnGlobalLevel = BashPsiUtils.findNextVarDefFunctionDefScope(functionDef) == null; PsiElement start = functionDef.getContext() != null && !isOnGlobalLevel ? functionDef.getContext() : functionDef.getPrevSibling(); if (start != null) { PsiTreeUtil.treeWalkUp(p, start, functionDef.getContainingFile(), ResolveState.initial()); if (p.hasResults()) { List<PsiElement> results = p.getResults() != null ? Lists.newArrayList(p.getResults()) : Lists.<PsiElement>newArrayList(); results.remove(functionDef); if (!results.isEmpty()) { //find the result which has the lowest textOffset in the file PsiElement firstFunctionDef = results.get(0); for (PsiElement e : results) { if (e.getTextOffset() < firstFunctionDef.getTextOffset()) { firstFunctionDef = e; } } if (firstFunctionDef.getTextOffset() < functionDef.getTextOffset()) { BashFunctionDefName nameSymbol = functionDef.getNameSymbol(); if (nameSymbol != null) { String message = String.format("The function '%s' is already defined at line %d.", functionDef.getName(), BashPsiUtils.getElementLineNumber(firstFunctionDef)); holder.registerProblem( nameSymbol, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING ); } } } } } } }; }