diff --git a/spi.editor.hints/nbproject/project.properties b/spi.editor.hints/nbproject/project.properties --- a/spi.editor.hints/nbproject/project.properties +++ b/spi.editor.hints/nbproject/project.properties @@ -43,6 +43,6 @@ javac.source=1.7 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=1.38.0 +spec.version.base=1.39.0 test.config.stableBTD.includes=**/*Test.class diff --git a/spi.editor.hints/src/org/netbeans/modules/editor/hints/AnnotationHolder.java b/spi.editor.hints/src/org/netbeans/modules/editor/hints/AnnotationHolder.java --- a/spi.editor.hints/src/org/netbeans/modules/editor/hints/AnnotationHolder.java +++ b/spi.editor.hints/src/org/netbeans/modules/editor/hints/AnnotationHolder.java @@ -766,7 +766,8 @@ else errorDescriptions = new ArrayList<>(errorDescriptions); Severity mostImportantSeverity = Severity.HINT; - + String customType = null; + for (Iterator it = errorDescriptions.iterator(); it.hasNext();) { ErrorDescription ed = it.next(); List positions = errors2Lines.get(ed); @@ -777,6 +778,7 @@ if (mostImportantSeverity.compareTo(ed.getSeverity()) > 0) { mostImportantSeverity = ed.getSeverity(); } + customType = ed.getCustomType(); } } @@ -791,12 +793,23 @@ Pair fixData = buildUpFixDataForLine(line); - ParseErrorAnnotation pea = new ParseErrorAnnotation( - mostImportantSeverity, - fixData.first(), - fixData.second(), - line, - this); + ParseErrorAnnotation pea; + if (customType == null) { + pea = new ParseErrorAnnotation( + mostImportantSeverity, + fixData.first(), + fixData.second(), + line, + this); + } else { + pea = new ParseErrorAnnotation( + mostImportantSeverity, + customType, + fixData.first(), + fixData.second(), + line, + this); + } ParseErrorAnnotation previous = line2Annotations.put(line, pea); if (previous != null) { diff --git a/spi.editor.hints/src/org/netbeans/modules/editor/hints/ParseErrorAnnotation.java b/spi.editor.hints/src/org/netbeans/modules/editor/hints/ParseErrorAnnotation.java --- a/spi.editor.hints/src/org/netbeans/modules/editor/hints/ParseErrorAnnotation.java +++ b/spi.editor.hints/src/org/netbeans/modules/editor/hints/ParseErrorAnnotation.java @@ -62,6 +62,7 @@ public class ParseErrorAnnotation extends Annotation implements PropertyChangeListener { private final Severity severity; + private final String customType; private final FixData fixes; private final String description; private final String shortDescription; @@ -71,6 +72,21 @@ /** Creates a new instance of ParseErrorAnnotation */ public ParseErrorAnnotation(Severity severity, FixData fixes, String description, Position lineStart, AnnotationHolder holder) { this.severity = severity; + this.customType = null; + this.fixes = fixes; + this.description = description; + this.shortDescription = description + NbBundle.getMessage(ParseErrorAnnotation.class, "LBL_shortcut_promotion"); //NOI18N + this.lineStart = lineStart; + this.holder = holder; + + if (!fixes.isComputed()) { + fixes.addPropertyChangeListener(WeakListeners.propertyChange(this, fixes)); + } + } + + public ParseErrorAnnotation(Severity severity, String customType, FixData fixes, String description, Position lineStart, AnnotationHolder holder) { + this.severity = severity; + this.customType = customType; this.fixes = fixes; this.description = description; this.shortDescription = description + NbBundle.getMessage(ParseErrorAnnotation.class, "LBL_shortcut_promotion"); //NOI18N @@ -85,30 +101,34 @@ public String getAnnotationType() { boolean hasFixes = fixes.isComputed() && !fixes.getFixes().isEmpty(); - switch (severity) { - case ERROR: - if (hasFixes) - return "org-netbeans-spi-editor-hints-parser_annotation_err_fixable"; - else - return "org-netbeans-spi-editor-hints-parser_annotation_err"; - - case WARNING: - if (hasFixes) - return "org-netbeans-spi-editor-hints-parser_annotation_warn_fixable"; - else - return "org-netbeans-spi-editor-hints-parser_annotation_warn"; - case VERIFIER: - if (hasFixes) - return "org-netbeans-spi-editor-hints-parser_annotation_verifier_fixable"; - else - return "org-netbeans-spi-editor-hints-parser_annotation_verifier"; - case HINT: - if (hasFixes) - return "org-netbeans-spi-editor-hints-parser_annotation_hint_fixable"; - else - return "org-netbeans-spi-editor-hints-parser_annotation_hint"; - default: - throw new IllegalArgumentException(String.valueOf(severity)); + if (customType == null) { + switch (severity) { + case ERROR: + if (hasFixes) + return "org-netbeans-spi-editor-hints-parser_annotation_err_fixable"; + else + return "org-netbeans-spi-editor-hints-parser_annotation_err"; + + case WARNING: + if (hasFixes) + return "org-netbeans-spi-editor-hints-parser_annotation_warn_fixable"; + else + return "org-netbeans-spi-editor-hints-parser_annotation_warn"; + case VERIFIER: + if (hasFixes) + return "org-netbeans-spi-editor-hints-parser_annotation_verifier_fixable"; + else + return "org-netbeans-spi-editor-hints-parser_annotation_verifier"; + case HINT: + if (hasFixes) + return "org-netbeans-spi-editor-hints-parser_annotation_hint_fixable"; + else + return "org-netbeans-spi-editor-hints-parser_annotation_hint"; + default: + throw new IllegalArgumentException(String.valueOf(severity)); + } + } else { + return customType; } } @@ -141,6 +161,10 @@ Severity getSeverity() { return severity; } + + String getCustomType() { + return customType; + } private StyledDocument attachedTo; diff --git a/spi.editor.hints/src/org/netbeans/spi/editor/hints/ErrorDescription.java b/spi.editor.hints/src/org/netbeans/spi/editor/hints/ErrorDescription.java --- a/spi.editor.hints/src/org/netbeans/spi/editor/hints/ErrorDescription.java +++ b/spi.editor.hints/src/org/netbeans/spi/editor/hints/ErrorDescription.java @@ -61,6 +61,7 @@ private final String description; private final CharSequence details; private final Severity severity; + private final String customType; private final LazyFixList fixes; private final PositionBounds span; private final FileObject file; @@ -74,6 +75,18 @@ this.description = description; this.details = details; this.severity = severity; + this.customType = null; + this.fixes = fixes; + this.span = span; + this.file = file; + } + + ErrorDescription(FileObject file, String id, String description, CharSequence details, Severity severity, String customType, LazyFixList fixes, PositionBounds span) { + this.id = id; + this.description = description; + this.details = details; + this.severity = severity; + this.customType = customType; this.fixes = fixes; this.span = span; this.file = file; @@ -111,6 +124,10 @@ public Severity getSeverity() { return severity; } + + public String getCustomType() { + return customType; + } /** * The list of fixes that will be associated with the error. diff --git a/spi.editor.hints/src/org/netbeans/spi/editor/hints/ErrorDescriptionFactory.java b/spi.editor.hints/src/org/netbeans/spi/editor/hints/ErrorDescriptionFactory.java --- a/spi.editor.hints/src/org/netbeans/spi/editor/hints/ErrorDescriptionFactory.java +++ b/spi.editor.hints/src/org/netbeans/spi/editor/hints/ErrorDescriptionFactory.java @@ -288,6 +288,34 @@ return new ErrorDescription(file, id, description, details, severity, fixes, errorBounds); } + + /**Create a new {@link ErrorDescription} with the given parameters. + * + * @param id an optional ID of the {@link ErrorDescription}. Should represent a "type" of an error/warning. + * It is recommended that providers prefix the ID with their unique prefix. + * @param severity the desired {@link Severity} + * @param customType custom {@link Severity} + * @param description the text of the error/warning + * @param details optional "more details" describing the error/warning + * @param fixes a collection of {@link Fix}es that should be shown for the error/warning + * @param file for which the {@link ErrorDescription} should be created + * @param errorBounds start and end position of the error/warning + * @return a newly created {@link ErrorDescription} based on the given parameters + * @since 1.39 + */ + public static @NonNull ErrorDescription createErrorDescription(@NullAllowed String id, @NonNull Severity severity, @NullAllowed String customType, @NonNull String description, @NullAllowed CharSequence details, @NonNull List fixes, @NonNull Document doc, @NonNull Position start, @NonNull Position end) { + Parameters.notNull("severity", severity); + Parameters.notNull("description", description); + Parameters.notNull("fixes", fixes); + Parameters.notNull("doc", doc); + Parameters.notNull("start", start); + Parameters.notNull("end", end); + + DataObject od = (DataObject) doc.getProperty(Document.StreamDescriptionProperty); + FileObject file = od != null ? od.getPrimaryFile() : null; + + return new ErrorDescription(file, id, description, details, severity, customType, new StaticFixList(fixes), HintsControllerImpl.linePart(doc, start, end)); + } /** * Converts "normal" list of {@link Fix}es into {@link LazyFixList}