if (!(PsiTreeUtil.getParentOfType(element, GoForStatement.class, GoFunctionLit.class) instanceof GoForStatement)) { Annotation annotation = holder.createErrorAnnotation(element, "Continue statement not inside a for loop"); annotation.registerFix(new GoReplaceWithReturnStatementQuickFix(element)); if (GoPsiImplUtil.getBreakStatementOwner(element) == null) { Annotation annotation = holder.createErrorAnnotation(element, "Break statement not inside a for loop, select or switch"); annotation.registerFix(new GoReplaceWithReturnStatementQuickFix(element)); Annotation annotation = holder.createErrorAnnotation(result, declaration.getName() + " function must have no arguments and no return values"); annotation.registerFix(new GoEmptySignatureQuickFix(declaration)); Annotation annotation = holder.createErrorAnnotation(parameters, declaration.getName() + " function must have no arguments and no return values"); annotation.registerFix(new GoEmptySignatureQuickFix(declaration)); TextRange r = TextRange.create(secondColon.getTextRange().getStartOffset(), thirdIndex.getTextRange().getEndOffset()); Annotation annotation = holder.createErrorAnnotation(r, "Invalid operation " + slice.getText() + " (3-index slice of string)"); annotation.registerFix(new GoDeleteRangeQuickFix(secondColon, thirdIndex, "Delete third index"));
void validate( final String key, final List<Field> availableKeys, final PsiElement psiElement, final AnnotationHolder annotationHolder) { if (shouldIgnore(key, psiElement)) { return; } if (isInvalid(key, availableKeys)) { final Annotation errorAnnotation = annotationHolder.createErrorAnnotation(psiElement, "Invalid key"); errorAnnotation.registerFix(intentionAction); } }
void validateParameterReference( final PsiElement psiElement, final AnnotationHolder annotationHolder) { if (isLocalReference(psiElement)) { final boolean parameterFound = getAvailableParameters(psiElement) .contains(ReferenceValueExtractor.extractValue(psiElement.getText())); if (!parameterFound) { final Annotation errorAnnotation = annotationHolder.createErrorAnnotation(psiElement, "Parameter not found"); errorAnnotation.registerFix(intentionAction); } } }
void validateDefinitionReference( final PsiElement psiElement, final AnnotationHolder annotationHolder) { if (isLocalReference(psiElement)) { final boolean definitionFound = getAvailableDefinitions(psiElement) .contains(ReferenceValueExtractor.extractValue(psiElement.getText())); if (!definitionFound) { final Annotation errorAnnotation = annotationHolder.createErrorAnnotation(psiElement, "Definition not found"); errorAnnotation.registerFix(intentionAction); } } }
void validateResponseReference( final PsiElement psiElement, final AnnotationHolder annotationHolder) { if (isLocalReference(psiElement)) { final boolean responseFound = getAvailableResponses(psiElement) .contains(ReferenceValueExtractor.extractValue(psiElement.getText())); if (!responseFound) { final Annotation errorAnnotation = annotationHolder.createErrorAnnotation(psiElement, "Response not found"); errorAnnotation.registerFix(intentionAction); } } }
.registerFix(new TemplateCreateByNameLocalQuickFix(templateName))
private void addAnnotation(LiveIssue issue, AnnotationHolder annotationHolder) { TextRange textRange; if (issue.getRange() != null) { textRange = createTextRange(issue.getRange()); } else { textRange = issue.psiFile().getTextRange(); } String htmlMsg = getHtmlMessage(issue); Annotation annotation = annotationHolder .createAnnotation(getSeverity(issue.getSeverity()), textRange, issue.getMessage(), htmlMsg); annotation.registerFix(new DisableRuleQuickFix(issue.getRuleKey())); if (!issue.flows().isEmpty()) { annotation.registerFix(new ShowLocationsIntention(issue.getRange(), issue.getMessage(), issue.flows())); } if (issue.getRange() == null) { annotation.setFileLevelAnnotation(true); } else { annotation.setTextAttributes(getTextAttrsKey(issue.getSeverity())); } /* * 3 possible ways to set text attributes and error stripe color: * - enforce text attributes ({@link Annotation#setEnforcedTextAttributes}) and we need to set everything * manually (including error stripe color). This won't be configurable in a standard way and won't change based on used color scheme * - rely on one of the default attributes by giving a key {@link com.intellij.openapi.editor.colors.CodeInsightColors} or your own * key (SonarLintTextAttributes) to Annotation#setTextAttributes * - let Annotation#getTextAttributes decide it based on highlight type and severity. */ annotation.setHighlightType(getType(issue.getSeverity())); }