com.intellij.codeInspection.ProblemsHolder Java Examples

The following examples show how to use com.intellij.codeInspection.ProblemsHolder. 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: ValProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #2
Source File: SQFSyntaxChecker.java    From arma-intellij-plugin with 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 #3
Source File: ClassStringLocalInspection.java    From idea-php-generics-plugin with MIT License 6 votes vote down vote up
@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 #4
Source File: EventMethodCallInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
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
Source File: YamlParameterInspection.java    From idea-php-symfony2-plugin with 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 #6
Source File: InternalCommandFunctionOverrideInspection.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: UnknownFiledescriptorInspection.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: IgnoreSyntaxEntryInspection.java    From idea-gitignore with 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 #9
Source File: ContainerConstantInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
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 #10
Source File: ValProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #11
Source File: TwigRouteMissingInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@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 #12
Source File: RouteSettingDeprecatedInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@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 #13
Source File: CaseSensitivityServiceInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@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
Source File: RouteSettingDeprecatedInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void registerRoutePatternProblem(@NotNull ProblemsHolder holder, @NotNull XmlAttribute xmlAttribute) {
    if(!"pattern".equals(xmlAttribute.getName())) {
        return;
    }

    XmlTag xmlTagRoute = PsiElementAssertUtil.getParentOfTypeWithNameOrNull(xmlAttribute, XmlTag.class, "route");
    if(xmlTagRoute != null && xmlAttribute.getFirstChild() != null) {
        holder.registerProblem(xmlAttribute.getFirstChild(), "Pattern is deprecated; use path instead", ProblemHighlightType.LIKE_DEPRECATED);
    }
}
 
Example #15
Source File: PhpRouteMissingInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void invoke(@NotNull String routeName, @NotNull final PsiElement element, @NotNull ProblemsHolder holder) {
    MethodMatcher.MethodMatchParameter methodMatchParameter = new MethodMatcher.StringParameterMatcher(element, 0)
        .withSignature(PhpRouteReferenceContributor.GENERATOR_SIGNATURES)
        .match();

    if(methodMatchParameter == null) {
        return;
    }

    Collection<Route> route = RouteHelper.getRoute(element.getProject(), routeName);
    if(route.size() == 0) {
        holder.registerProblem(element, "Missing Route", ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
    }
}
 
Example #16
Source File: ControllerMethodInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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);
        }
    });
}
 
Example #17
Source File: TaggedExtendsInterfaceClassInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void registerTaggedProblems(@NotNull PsiElement source, @NotNull Set<String> tags, @NotNull String serviceClass, @NotNull ProblemsHolder holder, @NotNull ContainerCollectionResolver.LazyServiceCollector lazyServiceCollector) {

        if(tags.size() == 0) {
            return;
        }

        PhpClass phpClass = null;

        for (String tag : tags) {

            if(!ServiceUtil.TAG_INTERFACES.containsKey(tag)) {
                continue;
            }

            String expectedClass = ServiceUtil.TAG_INTERFACES.get(tag);
            if(expectedClass == null) {
                continue;
            }

            // load PhpClass only if we need it, on error exit
            if(phpClass == null) {
                phpClass = ServiceUtil.getResolvedClassDefinition(holder.getProject(), serviceClass, lazyServiceCollector);
                if(phpClass == null) {
                    return;
                }
            }

            // check interfaces
            if(!PhpElementsUtil.isInstanceOf(phpClass, expectedClass)) {
                holder.registerProblem(source, String.format("Class needs to implement '%s' for tag '%s'", expectedClass, tag), ProblemHighlightType.WEAK_WARNING);
            }

        }

    }
 
Example #18
Source File: InternalVariableInspection.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new BashVisitor() {
        @Override
        public void visitVarDef(BashVarDef varDef) {
            String name = varDef.getName();

            if (LanguageBuiltins.readonlyShellVars.contains(name)) {
                holder.registerProblem(varDef, "Built-in shell variable", LocalQuickFix.EMPTY_ARRAY);
            }
        }
    };
}
 
Example #19
Source File: ContainerConstantInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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);
        }
    });
}
 
Example #20
Source File: CaseSensitivityServiceInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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);
        }
    });
}
 
Example #21
Source File: AbstractCamelInspection.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
private void validateJSonPath(@NotNull PsiElement element, final @NotNull ProblemsHolder holder, @NotNull String text, boolean isOnTheFly) {
    CamelCatalog catalogService = ServiceManager.getService(element.getProject(), CamelCatalogService.class).get();
    CamelService camelService = ServiceManager.getService(element.getProject(), CamelService.class);

    IElementType type = element.getNode().getElementType();
    LOG.trace("Element " + element + " of type: " + type + " to inspect jsonpath: " + text);

    // must have camel-json library
    boolean jsonLib = camelService.containsLibrary("camel-jsonpath", false);
    if (!jsonLib) {
        return;
    }

    try {
        // need to use the classloader that can load classes from the project
        ClassLoader loader = camelService.getProjectClassloader();
        if (loader != null) {
            LanguageValidationResult result;
            boolean predicate = getCamelIdeaUtils().isCamelExpressionUsedAsPredicate(element, "jsonpath");
            if (predicate) {
                LOG.debug("Inspecting jsonpath predicate: " + text);
                result = catalogService.validateLanguagePredicate(loader, "jsonpath", text);
            } else {
                LOG.debug("Inspecting jsonpath expression: " + text);
                result = catalogService.validateLanguageExpression(loader, "jsonpath", text);
            }
            if (!result.isSuccess()) {
                // favor the short error message
                String msg = result.getShortError();
                if (msg == null) {
                    msg = result.getError();
                }
                holder.registerProblem(element, msg);
            }
        }
    } catch (Throwable e) {
        LOG.warn("Error inspection Camel jsonpath: " + text, e);
    }
}
 
Example #22
Source File: AnnotationDeprecatedInspection.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
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 #23
Source File: CypherExplainWarningInspection.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
    return new PsiElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            checkStatement(element, holder);
        }
    };
}
 
Example #24
Source File: AbstractCamelInspection.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
private void extractMapValue(EndpointValidationResult result, Map<String, String> validationMap,
                             String fromElement, @NotNull PsiElement element, final @NotNull ProblemsHolder holder,
                             boolean isOnTheFly, CamelAnnotatorEndpointMessage msg) {

    if ((!result.isSuccess()) && validationMap != null) {
        for (Map.Entry<String, String> entry : validationMap.entrySet()) {
            String desc = summaryErrorMessage(result, entry, msg);
            holder.registerProblem(element, desc);
        }
    }
}
 
Example #25
Source File: TwigAssetMissingInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new MyPsiElementVisitor(holder);
}
 
Example #26
Source File: GlobalLocalVarDefInspection.java    From BashSupport with 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));
                        }
                    }
                }
            }
        }
    };
}
 
Example #27
Source File: EvaluateExpansionInspection.java    From BashSupport with 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 #28
Source File: ShopwareBoostrapInspection.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@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 #29
Source File: YamlReferenceInspection.java    From intellij-swagger with 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 #30
Source File: FormTypeAsClassConstantInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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);
}