From ee838a7d4cc3f79b2fd9fc16c1fa16ea3b9af689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sun, 12 Jan 2025 19:45:26 +0100 Subject: [PATCH] csl.api: Fix wrong @NonNull annotation in methods of Language The methods: - getOccurrencesFinder - getSemanticAnalyzer - getIndexSearcher - getOverridingMethods can return null, if the implemention does not provide these services. The @NonNull annotation is thus wrong. As Language is not API the use-sites that relied on the non-null assertion were fixed and the annotations updated. --- .../src/org/netbeans/modules/csl/core/Language.java | 8 ++++---- .../csl/editor/semantic/MarkOccurrencesHighlighter.java | 6 ++++-- .../modules/csl/editor/semantic/SemanticHighlighter.java | 6 +++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ide/csl.api/src/org/netbeans/modules/csl/core/Language.java b/ide/csl.api/src/org/netbeans/modules/csl/core/Language.java index 31681bd95938..db72b2bd9a0c 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/core/Language.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/core/Language.java @@ -610,7 +610,7 @@ public boolean hasHints() { /** * Return the occurrences finder for this language */ - @NonNull + @CheckForNull public OccurrencesFinder getOccurrencesFinder() { if (occurrences == null) { if (occurrencesFile != null) { @@ -653,7 +653,7 @@ public boolean hasOccurrencesFinder() { /** * Return the semantic analyzer for this language */ - @NonNull + @CheckForNull public SemanticAnalyzer getSemanticAnalyzer() { if (semantic == null) { if (semanticFile != null) { @@ -679,7 +679,7 @@ void setSemanticAnalyzer(FileObject semanticFile) { /** * Return the semantic analyzer for this language */ - @NonNull + @CheckForNull public IndexSearcher getIndexSearcher() { if (indexSearcher == null) { if (indexSearcherFile != null) { @@ -735,7 +735,7 @@ public Set getBinaryLibraryPathIds() { /** * Return the overriding methods computer for this language */ - @NonNull + @CheckForNull public OverridingMethods getOverridingMethods() { if (overridingMethods == null) { if (overridingMethodsFile != null) { diff --git a/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java b/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java index 33fc076f6ec5..283a2780cabd 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java @@ -135,8 +135,10 @@ public void run(ParserResult info, SchedulerEvent event) { @NonNull List processImpl(ParserResult info, Document doc, int caretPosition) { OccurrencesFinder finder = language.getOccurrencesFinder(); - assert finder != null; - + if(finder == null) { + return List.of(); + } + finder.setCaretPosition(caretPosition); try { finder.run(info, null); diff --git a/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/SemanticHighlighter.java b/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/SemanticHighlighter.java index ac6499cc031f..624fb4a31b71 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/SemanticHighlighter.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/SemanticHighlighter.java @@ -142,7 +142,11 @@ private void process(Language language, ParserResult result, Set