com.intellij.problems.Problem Java Examples

The following examples show how to use com.intellij.problems.Problem. 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: ErrorAnnotator.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Override
public void apply(@NotNull PsiFile file, @NotNull Collection<BsbErrorAnnotation> annotationResult, @NotNull AnnotationHolder holder) {
    WolfTheProblemSolver problemSolver = WolfTheProblemSolver.getInstance(file.getProject());
    Collection<Problem> problems = new ArrayList<>();

    for (BsbErrorAnnotation annotation : annotationResult) {
        if (annotation.isError) {
            holder.createErrorAnnotation(annotation.range, annotation.message);
            problems.add(problemSolver.convertToProblem(file.getVirtualFile(), annotation.startPos.line, annotation.startPos.column,
                                                        new String[]{annotation.message}));
        } else {
            holder.createWarningAnnotation(annotation.range, annotation.message);
        }
    }

    problemSolver.reportProblems(file.getVirtualFile(), problems);
}
 
Example #2
Source File: GeneralHighlightingPass.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void reportErrorsToWolf() {
  if (!getFile().getViewProvider().isPhysical()) return; // e.g. errors in evaluate expression
  Project project = getFile().getProject();
  if (!PsiManager.getInstance(project).isInProject(getFile())) return; // do not report problems in libraries
  VirtualFile file = getFile().getVirtualFile();
  if (file == null) return;

  List<Problem> problems = convertToProblems(getInfos(), file, myHasErrorElement);
  WolfTheProblemSolver wolf = WolfTheProblemSolver.getInstance(project);

  boolean hasErrors = DaemonCodeAnalyzerEx.hasErrors(project, getDocument());
  if (!hasErrors || isWholeFileHighlighting()) {
    wolf.reportProblems(file, problems);
  }
  else {
    wolf.weHaveGotProblems(file, problems);
  }
}
 
Example #3
Source File: WolfTheProblemSolverImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void weHaveGotNonIgnorableProblems(@Nonnull VirtualFile virtualFile, @Nonnull List<Problem> problems) {
  if (problems.isEmpty()) return;
  boolean fireListener = false;
  synchronized (myProblems) {
    ProblemFileInfo storedProblems = myProblems.get(virtualFile);
    if (storedProblems == null) {
      storedProblems = new ProblemFileInfo();

      myProblems.put(virtualFile, storedProblems);
      fireListener = true;
    }
    storedProblems.problems.addAll(problems);
  }
  doQueue(virtualFile);
  if (fireListener) {
    myProject.getMessageBus().syncPublisher(com.intellij.problems.ProblemListener.TOPIC).problemsAppeared(virtualFile);
  }
}
 
Example #4
Source File: Unity3dConsoleToolWindowService.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
private void process(Collection<UnityLogPostHandlerRequest> list)
{
	UIUtil.invokeLaterIfNeeded(() ->
	{
		NewErrorTreeViewPanel panel = getOrInitPanel();
		WolfTheProblemSolver solver = WolfTheProblemSolver.getInstance(myProject);
		VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();

		for(UnityLogPostHandlerRequest request : list)
		{
			DotNetCompilerMessage message = UnityLogParser.extractFileInfo(myProject, request.condition);

			int value = request.getMessageCategory();

			if(message != null)
			{
				VirtualFile fileByUrl = message.getFileUrl() == null ? null : virtualFileManager.findFileByUrl(message.getFileUrl());
				if(fileByUrl != null && value == MessageCategory.ERROR)
				{
					Problem problem = solver.convertToProblem(fileByUrl, message.getLine(), message.getColumn(), new String[]{message.getMessage()});
					if(problem != null)
					{
						solver.reportProblems(fileByUrl, Collections.singletonList(problem));
					}
				}

				panel.addMessage(value, new String[]{message.getMessage()}, fileByUrl, message.getLine() - 1, message.getColumn(), null);
			}
			else
			{
				panel.addMessage(value, new String[]{
						request.condition,
						request.stackTrace
				}, null, -1, -1, null);
			}
		}
	});
}
 
Example #5
Source File: GeneralHighlightingPass.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<Problem> convertToProblems(@Nonnull Collection<? extends HighlightInfo> infos, @Nonnull VirtualFile file, final boolean hasErrorElement) {
  List<Problem> problems = new SmartList<>();
  for (HighlightInfo info : infos) {
    if (info.getSeverity() == HighlightSeverity.ERROR) {
      Problem problem = new ProblemImpl(file, info, hasErrorElement);
      problems.add(problem);
    }
  }
  return problems;
}
 
Example #6
Source File: WolfTheProblemSolverImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Problem convertToProblem(@Nullable final VirtualFile virtualFile, final int line, final int column, @Nonnull final String[] message) {
  if (virtualFile == null || virtualFile.isDirectory() || virtualFile.getFileType().isBinary()) return null;
  HighlightInfo info = ReadAction.compute(() -> {
    TextRange textRange = getTextRange(virtualFile, line, column);
    String description = StringUtil.join(message, "\n");
    return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(description).create();
  });
  if (info == null) return null;
  return new ProblemImpl(virtualFile, info, false);
}
 
Example #7
Source File: WolfTheProblemSolverImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void reportProblems(@Nonnull final VirtualFile file, @Nonnull Collection<Problem> problems) {
  if (problems.isEmpty()) {
    clearProblems(file);
    return;
  }
  if (!isToBeHighlighted(file)) return;
  boolean hasProblemsBefore;
  boolean fireChanged;
  synchronized (myProblems) {
    final ProblemFileInfo oldInfo = myProblems.remove(file);
    hasProblemsBefore = oldInfo != null;
    ProblemFileInfo newInfo = new ProblemFileInfo();
    myProblems.put(file, newInfo);
    for (Problem problem : problems) {
      newInfo.problems.add(problem);
      newInfo.hasSyntaxErrors |= ((ProblemImpl)problem).isSyntaxOnly();
    }
    fireChanged = hasProblemsBefore && !oldInfo.equals(newInfo);
  }
  doQueue(file);
  if (!hasProblemsBefore) {
    myProject.getMessageBus().syncPublisher(com.intellij.problems.ProblemListener.TOPIC).problemsAppeared(file);
  }
  else if (fireChanged) {
    myProject.getMessageBus().syncPublisher(com.intellij.problems.ProblemListener.TOPIC).problemsChanged(file);
  }
}
 
Example #8
Source File: MockWolfTheProblemSolver.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void weHaveGotProblems(@Nonnull final VirtualFile virtualFile, @Nonnull final List<Problem> problems) {
  if (myDelegate != null) myDelegate.weHaveGotProblems(virtualFile, problems);
}
 
Example #9
Source File: MockWolfTheProblemSolver.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void weHaveGotNonIgnorableProblems(@Nonnull VirtualFile virtualFile, @Nonnull List<Problem> problems) {
  if (myDelegate != null) myDelegate.weHaveGotNonIgnorableProblems(virtualFile, problems);
}
 
Example #10
Source File: MockWolfTheProblemSolver.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Problem convertToProblem(VirtualFile virtualFile, int line, int column, String[] message) {
  return myDelegate == null ? null : myDelegate.convertToProblem(virtualFile, line, column, message);
}
 
Example #11
Source File: MockWolfTheProblemSolver.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void reportProblems(final VirtualFile file, Collection<Problem> problems) {
  if (myDelegate != null) myDelegate.reportProblems(file,problems);
}
 
Example #12
Source File: WolfTheProblemSolverImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void weHaveGotProblems(@Nonnull final VirtualFile virtualFile, @Nonnull List<Problem> problems) {
  if (problems.isEmpty()) return;
  if (!isToBeHighlighted(virtualFile)) return;
  weHaveGotNonIgnorableProblems(virtualFile, problems);
}