Skip to content

Commit 1d8c85d

Browse files
CsCherrYYrgrunber
authored andcommitted
Support java.compile.nullAnalysis.mode
Signed-off-by: Shi Chen <[email protected]>
1 parent 7b3f1b1 commit 1d8c85d

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,17 @@ The following settings are supported:
203203
* `java.configuration.workspaceCacheLimit` : The number of days (if enabled) to keep unused workspace cache data. Beyond this limit, cached workspace data may be removed.
204204
* `java.import.generatesMetadataFilesAtProjectRoot` : Specify whether the project metadata files(.project, .classpath, .factorypath, .settings/) will be generated at the project root. Defaults to `false`.
205205
* `java.inlayHints.parameterNames.enabled`: Enable/disable inlay hints for parameter names. Supported values are: `none`(disable parameter name hints), `literals`(Enable parameter name hints only for literal arguments) and `all`(Enable parameter name hints for literal and non-literal arguments). Defaults to `literals`.
206-
* `java.compile.nullAnalysis.nonnull`: Specify the Nonnull annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies.
207-
* `java.compile.nullAnalysis.nullable`: Specify the Nullable annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies.
206+
* `java.compile.nullAnalysis.nonnull`: Specify the Nonnull annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies. This setting will be ignored if `java.compile.nullAnalysis.enabled` is set to `disabled`.
207+
* `java.compile.nullAnalysis.nullable`: Specify the Nullable annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies. This setting will be ignored if `java.compile.nullAnalysis.enabled` is set to `disabled`.
208208
* `java.import.maven.offline.enabled`: Enable/disable the Maven offline mode. Defaults to `false`.
209209
* `java.codeAction.sortMembers.avoidVolatileChanges`: Reordering of fields, enum constants, and initializers can result in semantic and runtime changes due to different initialization and persistence order. This setting prevents this from occurring. Defaults to `true`.
210210
* `java.jdt.ls.protobufSupport.enabled`: Specify whether to automatically add Protobuf output source directories to the classpath. **Note:** Only works for Gradle `com.google.protobuf` plugin `0.8.4` or higher. Defaults to `true`.
211211
* `java.jdt.ls.androidSupport.enabled`: [Experimental] Specify whether to enable Android project importing. When set to `auto`, the Android support will be enabled in Visual Studio Code - Insiders. **Note:** Only works for Android Gradle Plugin `3.2.0` or higher. Defaults to `auto`.
212212
* `java.completion.postfix.enabled`: Enable/disable postfix completion support. Defaults to `true`.
213213

214+
New in 1.13.0
215+
* `java.compile.nullAnalysis.mode`: Specify how to enable the annotation-based null analysis. Supported values are `disabled` (disable the null analysis), `interactive` (asks when null annotation types are detected), `automatic` (automatically enable null analysis when null annotation types are detected). Defaults to `disabled`.
216+
214217
Semantic Highlighting
215218
===============
216219
[Semantic Highlighting](https://github.com/redhat-developer/vscode-java/wiki/Semantic-Highlighting) fixes numerous syntax highlighting issues with the default Java Textmate grammar. However, you might experience a few minor issues, particularly a delay when it kicks in, as it needs to be computed by the Java Language server, when opening a new file or when typing. Semantic highlighting can be disabled for all languages using the `editor.semanticHighlighting.enabled` setting, or for Java only using [language-specific editor settings](https://code.visualstudio.com/docs/getstarted/settings#_languagespecific-editor-settings).

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@
974974
"org.eclipse.jdt.annotation.NonNull",
975975
"org.springframework.lang.NonNull"
976976
],
977-
"markdownDescription": "Specify the Nonnull annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies.",
977+
"markdownDescription": "Specify the Nonnull annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in project dependencies. This setting will be ignored if `java.compile.nullAnalysis.enabled` is set to `disabled`",
978978
"scope": "window"
979979
},
980980
"java.compile.nullAnalysis.nullable": {
@@ -984,7 +984,18 @@
984984
"org.eclipse.jdt.annotation.Nullable",
985985
"org.springframework.lang.Nullable"
986986
],
987-
"markdownDescription": "Specify the Nullable annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in your project dependencies.",
987+
"markdownDescription": "Specify the Nullable annotation types to be used for null analysis. If more than one annotation is specified, then the topmost annotation will be used first if it exists in project dependencies. This setting will be ignored if `java.compile.nullAnalysis.enabled` is set to `disabled`",
988+
"scope": "window"
989+
},
990+
"java.compile.nullAnalysis.mode": {
991+
"type": "string",
992+
"enum": [
993+
"disabled",
994+
"interactive",
995+
"automatic"
996+
],
997+
"default": "disabled",
998+
"markdownDescription": "Specify how to enable the annotation-based null analysis.",
988999
"scope": "window"
9891000
}
9901001
}

src/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export namespace Commands {
6464
*/
6565
export const PROJECT_CONFIGURATION_STATUS = 'java.projectConfiguration.status';
6666

67+
/**
68+
* Set null analysis mode
69+
*/
70+
export const NULL_ANALYSIS_SET_MODE = 'java.compile.nullAnalysis.setMode';
71+
6772
/**
6873
* Apply Workspace Edit
6974
*/

src/standardLanguageClient.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ export class StandardLanguageClient {
330330

331331
context.subscriptions.push(commands.registerCommand(Commands.PROJECT_CONFIGURATION_STATUS, (uri, status) => setProjectConfigurationUpdate(this.languageClient, uri, status)));
332332

333+
context.subscriptions.push(commands.registerCommand(Commands.NULL_ANALYSIS_SET_MODE, (status) => setNullAnalysisStatus(status)));
334+
333335
context.subscriptions.push(commands.registerCommand(Commands.APPLY_WORKSPACE_EDIT, (obj) => {
334336
applyWorkspaceEdit(obj, this.languageClient);
335337
}));
@@ -684,6 +686,17 @@ function setProjectConfigurationUpdate(languageClient: LanguageClient, uri: Uri,
684686
}
685687
}
686688

689+
function setNullAnalysisStatus(status: FeatureStatus) {
690+
const config = getJavaConfiguration();
691+
const section = 'compile.nullAnalysis.mode';
692+
693+
const st = FeatureStatus[status];
694+
config.update(section, st).then(
695+
() => logger.info(`${section} set to ${st}`),
696+
(error) => logger.error(error)
697+
);
698+
}
699+
687700
function decodeBase64(text: string): string {
688701
return Buffer.from(text, 'base64').toString('ascii');
689702
}

0 commit comments

Comments
 (0)