String (@NotNull Editor editor, @NotNull PsiFile psiFile, int lineNumber, int startOffset, int endOffset, @Nullable LineData lineData) { final StringBuilder buf = new StringBuilder(); buf.append(CoverageBundle.message("hits.title", "")); if (lineData == null) { buf.append(0); return buf.toString(); } buf.append(lineData.getHits()).append("\n"); for (JavaCoverageEngineExtension extension : JavaCoverageEngineExtension.EP_NAME.getExtensionList()) { String report = extension.generateBriefReport(editor, psiFile, lineNumber, startOffset, endOffset, lineData); if (report != null) { buf.append(report); return report; } } final List<PsiExpression> expressions = new ArrayList<>(); final Project project = editor.getProject(); for(int offset = startOffset; offset < endOffset; offset++) { PsiElement parent = PsiTreeUtil.getParentOfType(psiFile.findElementAt(offset), PsiStatement.class); PsiElement condition = null; if (parent instanceof PsiIfStatement) { condition = ((PsiIfStatement)parent).getCondition(); } else if (parent instanceof PsiSwitchStatement) { condition = ((PsiSwitchStatement)parent).getExpression(); } else if (parent instanceof PsiConditionalLoopStatement) { condition = ((PsiConditionalLoopStatement)parent).getCondition(); } else if (parent instanceof PsiForeachStatement) { condition = ((PsiForeachStatement)parent).getIteratedValue(); } else if (parent instanceof PsiAssertStatement) { condition = ((PsiAssertStatement)parent).getAssertCondition(); } if (PsiTreeUtil.isAncestor(condition, Objects.requireNonNull(psiFile.findElementAt(offset)), false)) { try { final ControlFlow controlFlow = ControlFlowFactory.getInstance(Objects.requireNonNull(project)).getControlFlow( parent, AllVariablesControlFlowPolicy.getInstance()); for (Instruction instruction : controlFlow.getInstructions()) { if (instruction instanceof ConditionalBranchingInstruction) { final PsiExpression expression = ((ConditionalBranchingInstruction)instruction).expression; if (!expressions.contains(expression)) { expressions.add(expression); } } } } catch (AnalysisCanceledException e) { return buf.toString(); } } } try { int idx = 0; int hits = 0; final String indent = " "; if (lineData.getJumps() != null) { for (JumpData jumpData : lineData.getJumps()) { if (jumpData.getTrueHits() + jumpData.getFalseHits() > 0) { final PsiExpression expression = expressions.get(idx++); final PsiElement parentExpression = expression.getParent(); boolean reverse = parentExpression instanceof PsiPolyadicExpression && ((PsiPolyadicExpression)parentExpression).getOperationTokenType() == JavaTokenType.OROR || parentExpression instanceof PsiDoWhileStatement || parentExpression instanceof PsiAssertStatement; buf.append(indent).append(expression.getText()).append("\n"); buf.append(indent).append(indent).append(PsiKeyword.TRUE).append(" ").append(CoverageBundle.message("hits.message", reverse ? jumpData.getFalseHits() : jumpData .getTrueHits())).append("\n"); buf.append(indent).append(indent).append(PsiKeyword.FALSE).append(" ").append(CoverageBundle.message("hits.message", reverse ? jumpData .getTrueHits() : jumpData.getFalseHits())).append("\n"); hits += jumpData.getTrueHits() + jumpData.getFalseHits(); } } } if (lineData.getSwitches() != null) { for (SwitchData switchData : lineData.getSwitches()) { final PsiExpression conditionExpression = expressions.get(idx++); buf.append(indent).append(conditionExpression.getText()).append("\n"); int i = 0; for (int key : switchData.getKeys()) { final int switchHits = switchData.getHits()[i++]; buf.append(indent).append(indent).append("case ").append(key).append(": ").append(switchHits).append("\n"); hits += switchHits; } int defaultHits = switchData.getDefaultHits(); final boolean hasDefaultLabel = hasDefaultLabel(conditionExpression); if (hasDefaultLabel || defaultHits > 0) { if (!hasDefaultLabel) { defaultHits -= hits; } if (hasDefaultLabel || defaultHits > 0) { buf.append(indent).append(indent).append("default: ").append(defaultHits).append("\n"); hits += defaultHits; } } } } if (lineData.getHits() > hits && hits > 0) { buf.append(JavaCoverageBundle.message("report.unknown.outcome",lineData.getHits() - hits)); } } catch (Exception e) { LOG.info(e); return CoverageBundle.message("hits.title", lineData.getHits()); } return buf.toString(); }