# HG changeset patch # User Danila Sergeyev # Date 1440501699 -14400 # Node ID baa2574c26d8ddc9576417ca9b14e67cec6022cd # Parent b14928c9132e815fe972accd3cb27d5ae401d36a bug #254375 Expand API to allow setup custom icons for hints - patch proposal diff --git a/spi.editor.hints/manifest.mf b/spi.editor.hints/manifest.mf --- a/spi.editor.hints/manifest.mf +++ b/spi.editor.hints/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.spi.editor.hints/0 -OpenIDE-Module-Implementation-Version: 7 +OpenIDE-Module-Implementation-Version: 8 OpenIDE-Module-Layer: org/netbeans/modules/editor/hints/resources/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/hints/resources/Bundle.properties OpenIDE-Module-Install: org/netbeans/modules/editor/hints/HintsModule.class 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.38.1 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); @@ -776,7 +777,8 @@ } else { if (mostImportantSeverity.compareTo(ed.getSeverity()) > 0) { mostImportantSeverity = ed.getSeverity(); - } + } + customType = ed.customType(); } } @@ -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 customType() { + 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,20 @@ return new ErrorDescription(file, id, description, details, severity, fixes, errorBounds); } + + 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}