Java Code Examples for com.intellij.codeInspection.ProblemsHolder

The following examples show how to use com.intellij.codeInspection.ProblemsHolder. These examples are extracted from open source projects. 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
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    return new PsiElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(element instanceof StringLiteralExpression || element instanceof ClassConstantReference) {
                PsiElement parent = element.getParent();
                if (parent instanceof ParameterList) {
                    invoke(element, holder);
                }
            }

            super.visitElement(element);
        }
    };
}
 
Example 2
@NotNull
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(TwigPattern.getAutocompletableRoutePattern().accepts(element) && TwigUtil.isValidStringWithoutInterpolatedOrConcat(element)) {
                invoke(element, holder);
            }

            super.visitElement(element);
        }
    };
}
 
Example 3
Source Project: idea-php-symfony2-plugin   Source File: YamlParameterInspection.java    License: MIT License 6 votes vote down vote up
private void invoke(@NotNull final PsiElement psiElement, @NotNull ProblemsHolder holder) {
    // at least %a%
    // and not this one: %kernel.root_dir%/../web/
    // %kernel.root_dir%/../web/%webpath_modelmasks%
    String parameterName = PsiElementUtils.getText(psiElement);
    if(!YamlHelper.isValidParameterName(parameterName)) {
        return;
    }

    // strip "%"
    parameterName = parameterName.substring(1, parameterName.length() - 1);

    // parameter a always lowercase see #179
    parameterName = parameterName.toLowerCase();
    if (!ContainerCollectionResolver.getParameterNames(psiElement.getProject()).contains(parameterName)) {
        holder.registerProblem(psiElement, "Missing Parameter", ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
    }
}
 
Example 4
private void registerMethodProblem(final @NotNull PsiElement psiElement, @NotNull ProblemsHolder holder, @Nullable PhpClass phpClass) {
    if(phpClass == null) {
        return;
    }

    final String methodName = PsiElementUtils.trimQuote(psiElement.getText());
    if(phpClass.findMethodByName(methodName) != null) {
        return;
    }

    holder.registerProblem(
        psiElement,
        "Missing Method",
        ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
        new CreateMethodQuickFix(phpClass, methodName, new MyCreateMethodQuickFix())
    );
}
 
Example 5
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new BashVisitor() {
        @Override
        public void visitFiledescriptor(BashFiledescriptor descriptor) {
            Integer asInt = descriptor.descriptorAsInt();
            if (asInt != null) {
                if (asInt < 0 || asInt > 9) {
                    holder.registerProblem(descriptor, BashPsiUtils.rangeInParent(descriptor, descriptor),
                            "Invalid file descriptor " + asInt);
                }
            }
        }
    };
}
 
Example 6
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);
        }
    });
}
 
Example 7
public void verifyVariable(@NotNull final PsiLocalVariable psiLocalVariable, @NotNull final ProblemsHolder holder) {
  final PsiTypeElement typeElement = psiLocalVariable.getTypeElement();
  final String typeElementText = typeElement.getText();
  boolean isVal = isPossibleVal(typeElementText) && isVal(resolveQualifiedName(typeElement));
  boolean isVar = isPossibleVar(typeElementText) && isVar(resolveQualifiedName(typeElement));
  final String ann = isVal ? "val" : "var";
  if (isVal || isVar) {
    final PsiExpression initializer = psiLocalVariable.getInitializer();
    if (initializer == null) {
      holder.registerProblem(psiLocalVariable, "'" + ann + "' on a local variable requires an initializer expression", ProblemHighlightType.ERROR);
    } else if (initializer instanceof PsiArrayInitializerExpression) {
      holder.registerProblem(psiLocalVariable, "'" + ann + "' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })", ProblemHighlightType.ERROR);
    } else if (initializer instanceof PsiLambdaExpression) {
      holder.registerProblem(psiLocalVariable, "'" + ann + "' is not allowed with lambda expressions.", ProblemHighlightType.ERROR);
    } else if (isVal) {
      final PsiElement typeParentParent = psiLocalVariable.getParent();
      if (typeParentParent instanceof PsiDeclarationStatement && typeParentParent.getParent() instanceof PsiForStatement) {
        holder.registerProblem(psiLocalVariable, "'" + ann + "' is not allowed in old-style for loops", ProblemHighlightType.ERROR);
      }
    }
  }
}
 
Example 8
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 9
@NotNull
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(element instanceof XmlAttributeValue) {
                registerAttributeRequirementProblem(holder, (XmlAttributeValue) element, "_method");
                registerAttributeRequirementProblem(holder, (XmlAttributeValue) element, "_scheme");
            } else if(element instanceof XmlAttribute) {
                registerRoutePatternProblem(holder, (XmlAttribute) element);
            } else if(element instanceof YAMLKeyValue) {
                registerYmlRoutePatternProblem(holder, (YAMLKeyValue) element);
            }

            super.visitElement(element);
        }
    };
}
 
Example 10
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new BashVisitor() {
        @Override
        public void visitFunctionDef(BashFunctionDef functionDef) {
            boolean bash4 = BashProjectSettings.storedSettings(holder.getProject()).isSupportBash4();

            if (LanguageBuiltins.isInternalCommand(functionDef.getName(), bash4)) {
                PsiElement targetElement = functionDef.getNameSymbol();
                if (targetElement == null) {
                    targetElement = functionDef.getNavigationElement();
                }

                holder.registerProblem(targetElement, "Function overrides internal Bash command", ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
            }
        }
    };
}
 
Example 11
Source Project: idea-gitignore   Source File: IgnoreSyntaxEntryInspection.java    License: MIT License 6 votes vote down vote up
/**
 * 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 12
Source Project: arma-intellij-plugin   Source File: SQFSyntaxChecker.java    License: MIT License 6 votes vote down vote up
@Nullable
private ValueType getPeekType(@NotNull LinkedList<ExprPart> parts,
							  @NotNull LinkedList<ExprPart> removedParts,
							  @NotNull ProblemsHolder problems,
							  @NotNull LinkedList<PotentialProblem> potentialProblems,
							  @NotNull Counter reportCount) {
	ExprPart peekPart = parts.peekFirst();
	if (peekPart == null) {
		return null;
	}
	if (peekPart.isOperatorPart()) {
		return getReturnTypeForCommand(
				parts,
				null,
				problems,
				potentialProblems,
				reportCount,
				true
		);
	} else {
		removedParts.push(parts.removeFirst());
		return peekPart.getArgument().getType(this, true, cluster);
	}
}
 
Example 13
@NotNull
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitFile(PsiFile psiFile) {
            if(psiFile.getFileType() == PhpFileType.INSTANCE) {
                phpVisitor(holder, psiFile);
            } else if(psiFile.getFileType() == YAMLFileType.YML) {
                yamlVisitor(holder, psiFile);
            } else if(psiFile.getFileType() == XmlFileType.INSTANCE) {
                xmlVisitor(holder, psiFile);
            }
        }
    };
}
 
Example 14
@NotNull
@Override
public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    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 && arrayIndex.equals("type")) {
                if (element instanceof StringLiteralExpression) {
                    String tableName = ((StringLiteralExpression) element).getContents();
                    boolean isValidRenderType = TCAUtil.getAvailableColumnTypes(element.getProject()).contains(tableName);

                    if (!isValidRenderType) {
                        problemsHolder.registerProblem(element, "Missing column type definition");
                    }
                }
            }
        }
    };
}
 
Example 15
Source Project: idea-php-typo3-plugin   Source File: PluginEnabledPhpInspection.java    License: MIT License 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    if (!TYPO3CMSProjectSettings.getInstance(problemsHolder.getProject()).pluginEnabled) {
        return new PhpElementVisitor() {
        };
    }

    return buildRealVisitor(problemsHolder, b);
}
 
Example 16
@NotNull
@Override
public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    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 && arrayIndex.equals("renderType")) {
                if (element instanceof StringLiteralExpression) {
                    String tableName = ((StringLiteralExpression) element).getContents();
                    boolean isValidRenderType = TCAUtil.getAvailableRenderTypes(element).contains(tableName);

                    if (!isValidRenderType) {
                        problemsHolder.registerProblem(element, "Missing renderType definition");
                    }
                }
            }
        }
    };
}
 
Example 17
Source Project: idea-php-typo3-plugin   Source File: MissingTableInspection.java    License: MIT License 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    return new PhpElementVisitor() {
        @Override
        public void visitPhpElement(PhpPsiElement element) {

            boolean isArrayStringValue = PhpElementsUtil.isStringArrayValue().accepts(element);
            if (element == null || !isArrayStringValue || !insideTCAColumnDefinition(element)) {
                return;
            }

            String arrayKey = extractArrayIndexFromValue(element);
            if (arrayKey != null && arrayKey.equals("allowed") && element instanceof StringLiteralExpression && ((StringLiteralExpression) element).getContents().equals("*")) {
                return;
            }

            boolean valueIsTableNameFieldValue = arrayIndexIsTCATableNameField(element);
            if (valueIsTableNameFieldValue) {
                if (element instanceof StringLiteralExpression) {
                    String tableName = ((StringLiteralExpression) element).getContents();
                    boolean isValidTableName = TableUtil.getAvailableTableNames(element.getProject()).contains(tableName);

                    if (!isValidTableName) {
                        problemsHolder.registerProblem(element, "Missing table definition");
                    }
                }
            }
        }
    };
}
 
Example 18
private void registerXmlAttributeProblem(@NotNull ProblemsHolder holder, @NotNull XmlAttribute xmlAttribute) {
    String name = xmlAttribute.getName();
    if(!("factory-class".equals(name) || "factory-method".equals(name) || "factory-service".equals(name))) {
        return;
    }

    XmlTag xmlTagRoute = PsiElementAssertUtil.getParentOfTypeWithNameOrNull(xmlAttribute, XmlTag.class, "service");
    if(xmlTagRoute != null) {
        registerProblem(holder, xmlAttribute.getFirstChild());
    }
}
 
Example 19
@NotNull
@Override
public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    return new PhpElementVisitor() {
        @Override
        public void visitPhpFunctionCall(FunctionReference reference) {
            if (DeprecationUtility.isDeprecated(problemsHolder.getProject(), reference)) {
                problemsHolder.registerProblem(reference, "Global function scheduled for removal in upcoming TYPO3 version, consider using an alternative");
            }

            super.visitPhpFunctionCall(reference);
        }
    };
}
 
Example 20
@NotNull
@Override
public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    return new PhpElementVisitor() {

        @Override
        public void visitPhpClassConstantReference(ClassConstantReference constantReference) {
            if (DeprecationUtility.isDeprecated(problemsHolder.getProject(), constantReference)) {
                problemsHolder.registerProblem(constantReference, "Deprecated class constant");
            }

            super.visitPhpClassConstantReference(constantReference);
        }
    };
}
 
Example 21
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new MyPsiElementVisitor(holder);
}
 
Example 22
Source Project: idea-php-typo3-plugin   Source File: MissingModuleJSInspection.java    License: MIT License 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, @NotNull LocalInspectionToolSession localInspectionToolSession) {
    return new JSElementVisitor() {
        @Override
        public void visitJSLiteralExpression(JSLiteralExpression node) {
            PsiReference[] references = node.getReferences();
            for (PsiReference reference : references) {
                if (!(reference instanceof JSResolvableModuleReference)) {
                    continue;
                }

                JSResolvableModuleReference moduleReference = (JSResolvableModuleReference) reference;

                String canonicalText = moduleReference.getCanonicalText();
                if (!canonicalText.startsWith(JavaScriptUtil.MODULE_PREFIX)) {
                    super.visitJSLiteralExpression(node);

                    return;
                }

                if (JavaScriptUtil.getModuleMap(node.getProject()).containsKey(canonicalText)) {
                    super.visitJSLiteralExpression(node);

                    return;
                }

                problemsHolder.registerProblem(node, String.format("Unknown JavaScript module \"%s\"", canonicalText));

                return;
            }

            super.visitJSLiteralExpression(node);
        }
    };
}
 
Example 23
Source Project: idea-php-typo3-plugin   Source File: MissingModulePHPInspection.java    License: MIT License 5 votes vote down vote up
@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 24
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);
            }
        });

    }
 
Example 25
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            invoke(holder, element);
            super.visitElement(element);
        }
    };
}
 
Example 26
Source Project: BashSupport   Source File: SimpleArrayUseInspection.java    License: Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new BashVisitor() {
        @Override
        public void visitVarUse(BashVar var) {
            BashVarDef definition = (BashVarDef) var.getReference().resolve();
            if (definition != null) {
                boolean defIsArray = definition.isArray();
                boolean arrayUse = var.isArrayUse();

                if (arrayUse && !defIsArray) {
                    //there's the special case that ${#arrayVar} and ${#nonArrayVar} are both valid (length of array and length of string)
                    //this can't be detected with arrayUse and defIsArray
                    if (!isStringLengthExpr(var)) {
                        holder.registerProblem(var, "Array use of non-array variable", ProblemHighlightType.WEAK_WARNING);
                    }
                } else if (!arrayUse
                        && defIsArray
                        && !BashPsiUtils.hasParentOfType(var, BashString.class, 5)
                        && !BashPsiUtils.hasParentOfType(var, ArithmeticExpression.class, 5)) {

                    holder.registerProblem(var, "Simple use of array variable", ProblemHighlightType.WEAK_WARNING);
                }
            }
        }
    };
}
 
Example 27
@NotNull
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject()) || !SymfonyUtil.isVersionGreaterThenEquals(holder.getProject(), "2.8")) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new MyPsiElementVisitor(holder);
}
 
Example 28
Source Project: intellij-swagger   Source File: YamlReferenceInspection.java    License: MIT License 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(
    @NotNull final ProblemsHolder holder,
    final boolean isOnTheFly,
    @NotNull final LocalInspectionToolSession session) {
  final PsiFile file = holder.getFile();
  final VirtualFile virtualFile = file.getVirtualFile();
  final Project project = holder.getProject();

  boolean checkRefs =
      indexFacade.isMainSpecFile(virtualFile, project)
          || indexFacade.isPartialSpecFile(virtualFile, project);

  return new YamlPsiElementVisitor() {
    @Override
    public void visitKeyValue(@NotNull YAMLKeyValue keyValue) {
      if (!checkRefs) {
        return;
      }
      if ("$ref".equals(keyValue.getKeyText())) {
        YAMLValue value = keyValue.getValue();

        if (!(value instanceof YAMLScalar)) {
          return;
        }

        final String unquotedValue = StringUtil.unquoteString(value.getText());

        if (!unquotedValue.startsWith("http")) {
          doCheck(holder, value, new CreateYamlReferenceIntentionAction(unquotedValue));
        }
      }
      super.visitKeyValue(keyValue);
    }
  };
}
 
Example 29
Source Project: BashSupport   Source File: EvaluateExpansionInspection.java    License: Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new BashVisitor() {
        @Override
        public void visitExpansion(BashExpansion expansion) {
            if (isOnTheFly && expansion.isValidExpansion()) {
                boolean bash4 = BashProjectSettings.storedSettings(holder.getProject()).isSupportBash4();
                holder.registerProblem(expansion, "Evaluate expansion", new EvaluateExpansionQuickfix(expansion, bash4));
            }
        }
    };
}
 
Example 30
Source Project: BashSupport   Source File: GlobalLocalVarDefInspection.java    License: Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new BashVisitor() {
        @Override
        public void visitVarDef(BashVarDef varDef) {
            if (varDef.isFunctionScopeLocal()) {
                PsiElement context = varDef.getContext();

                if (context instanceof BashCommand) {
                    final BashCommand parentCmd = (BashCommand) context;

                    if (parentCmd.isVarDefCommand() && localVarDefCommands.contains(parentCmd.getReferencedCommandName())) {
                        boolean isInFunction = false;

                        PsiElement parent = BashPsiUtils.findEnclosingBlock(varDef);
                        while (parent != null && !isInFunction) {
                            isInFunction = parent instanceof BashFunctionDef;

                            parent = BashPsiUtils.findEnclosingBlock(parent);
                        }

                        if (!isInFunction) {
                            PsiElement problemHolder = varDef.getContext();
                            holder.registerProblem(problemHolder,
                                    "'local' must be used in a function",
                                    ProblemHighlightType.GENERIC_ERROR,
                                    new RemoveLocalQualifierQuickfix(varDef));
                        }
                    }
                }
            }
        }
    };
}