Skip to content

Commit

Permalink
Support java.compile.nullAnalysis.mode
Browse files Browse the repository at this point in the history
Signed-off-by: Shi Chen <[email protected]>
  • Loading branch information
CsCherrYY committed Oct 21, 2022
1 parent c582159 commit 7b6f271
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ New in 1.10.0
* `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`.

New in 1.11.0
* `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.
* `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.
* `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`.
* `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`.

New in 1.12.0
* `java.compile.nullAnalysis.mode`: Specify how to enable the annotation-based null analysis. When set to `interactive`, you will have a chance to choose whether to turn on the null analysis when the null annotation types are detected in your project dependencies. Defaults to `interactive`.

Semantic Highlighting
===============
Expand Down
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@
"org.eclipse.jdt.annotation.NonNull",
"org.springframework.lang.NonNull"
],
"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.",
"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. This setting will be ignored if `java.compile.nullAnalysis.enabled` is set to `disabled`",
"scope": "window"
},
"java.compile.nullAnalysis.nullable": {
Expand All @@ -978,7 +978,18 @@
"org.eclipse.jdt.annotation.Nullable",
"org.springframework.lang.Nullable"
],
"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.",
"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. This setting will be ignored if `java.compile.nullAnalysis.enabled` is set to `disabled`",
"scope": "window"
},
"java.compile.nullAnalysis.mode": {
"type": "string",
"enum": [
"disabled",
"interactive",
"automatic"
],
"default": "interactive",
"markdownDescription": "Specify how to enable the annotation-based null analysis. When set to `interactive`, you will have a chance to turn on the null analysis when the null annotations are detected in your project dependencies.",
"scope": "window"
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export namespace Commands {
*/
export const PROJECT_CONFIGURATION_STATUS = 'java.projectConfiguration.status';

/**
* Set null analysis mode
*/
export const NULL_ANALYSIS_SET_MODE = 'java.compile.nullAnalysis.setMode';

/**
* Apply Workspace Edit
*/
Expand Down
13 changes: 13 additions & 0 deletions src/standardLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ export class StandardLanguageClient {

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

context.subscriptions.push(commands.registerCommand(Commands.NULL_ANALYSIS_SET_MODE, (status) => setNullAnalysisStatus(status)));

context.subscriptions.push(commands.registerCommand(Commands.APPLY_WORKSPACE_EDIT, (obj) => {
applyWorkspaceEdit(obj, this.languageClient);
}));
Expand Down Expand Up @@ -684,6 +686,17 @@ function setProjectConfigurationUpdate(languageClient: LanguageClient, uri: Uri,
}
}

function setNullAnalysisStatus(status: FeatureStatus) {
const config = getJavaConfiguration();
const section = 'compile.nullAnalysis.mode';

const st = FeatureStatus[status];
config.update(section, st).then(
() => logger.info(`${section} set to ${st}`),
(error) => logger.error(error)
);
}

function decodeBase64(text: string): string {
return Buffer.from(text, 'base64').toString('ascii');
}
Expand Down

0 comments on commit 7b6f271

Please sign in to comment.