Java Code Examples for com.intellij.codeInspection.ProblemsHolder#getFile()

The following examples show how to use com.intellij.codeInspection.ProblemsHolder#getFile() . 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: YamlSchemaInspection.java    From intellij-swagger with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(
    @NotNull final ProblemsHolder holder,
    final boolean isOnTheFly,
    @NotNull final LocalInspectionToolSession session) {

  PsiFile file = holder.getFile();

  if (fileDetector.isMainOpenApiYamlFile(file)) {
    return createVisitor("openapi.json", holder, session, file);
  } else if (fileDetector.isMainSwaggerYamlFile(file)) {
    return createVisitor("swagger.json", holder, session, file);
  } else {
    return PsiElementVisitor.EMPTY_VISITOR;
  }
}
 
Example 2
Source File: JsonSchemaInspection.java    From intellij-swagger with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(
    @NotNull final ProblemsHolder holder,
    final boolean isOnTheFly,
    @NotNull final LocalInspectionToolSession session) {

  PsiFile file = holder.getFile();

  if (fileDetector.isMainOpenApiJsonFile(file)) {
    return createVisitor("openapi.json", holder, session, file);
  } else if (fileDetector.isMainSwaggerJsonFile(file)) {
    return createVisitor("swagger.json", holder, session, file);
  } else {
    return PsiElementVisitor.EMPTY_VISITOR;
  }
}
 
Example 3
Source File: ShopwareSubscriperMethodInspection.java    From idea-php-shopware-plugin with MIT License 6 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);
    }

    String name = psiFile.getName();

    if(name.contains("Bootstrap")) {
        psiFile.acceptChildren(new MyBootstrapRecursiveElementWalkingVisitor(holder));
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new MySubscriberRecursiveElementWalkingVisitor(holder);
}
 
Example 4
Source File: YamlDuplicateServiceKeyInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {

    PsiFile psiFile = holder.getFile();
    if(!Symfony2ProjectComponent.isEnabled(psiFile.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitFile(PsiFile file) {
            visitRoot(file, "services", holder);
        }
    };
}
 
Example 5
Source File: YamlDuplicateParameterKeyInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {

    PsiFile psiFile = holder.getFile();
    if(!Symfony2ProjectComponent.isEnabled(psiFile.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitFile(PsiFile file) {
            visitRoot(file, "parameters", holder);
        }
    };
}
 
Example 6
Source File: JsonReferenceInspection.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 JsonElementVisitor() {
    @Override
    public void visitProperty(@NotNull JsonProperty o) {
      if (!checkRefs) {
        return;
      }
      if ("$ref".equals(o.getName())) {
        JsonValue value = o.getValue();

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

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

        if (!unquotedValue.startsWith("http")) {
          doCheck(holder, value, new CreateJsonReferenceIntentionAction(unquotedValue));
        }
      }
      super.visitProperty(o);
    }
  };
}
 
Example 7
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 8
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 9
Source File: MatchNamespaceInspection.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public PsiElementVisitor buildVisitor(@Nonnull ProblemsHolder holder, boolean isOnTheFly, @Nonnull LocalInspectionToolSession session)
{
	PsiFile file = holder.getFile();
	if(!(file instanceof CSharpFile))
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	if(file instanceof PsiCodeFragment)
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	DotNetSimpleModuleExtension extension = ModuleUtilCore.getExtension(file, DotNetSimpleModuleExtension.class);
	if(extension == null)
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	MatchNamespaceVisitor visitor = session.getUserData(KEY);
	if(visitor == null)
	{
		session.putUserData(KEY, visitor = new MatchNamespaceVisitor(holder, extension));
	}
	return visitor;
}