mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-29 01:37:51 +08:00
62 lines
1.1 KiB
Markdown
62 lines
1.1 KiB
Markdown
---
|
|
title: 17. Commenter
|
|
---
|
|
|
|
A commenter allows user to comment the code at the cursor or selected code automatically via *⌘/*.
|
|
|
|
### 17.1. Define a commenter
|
|
|
|
```java
|
|
package com.simpleplugin;
|
|
|
|
import com.intellij.lang.Commenter;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
public class SimpleCommenter implements Commenter {
|
|
@Nullable
|
|
@Override
|
|
public String getLineCommentPrefix() {
|
|
return "#";
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public String getBlockCommentPrefix() {
|
|
return "";
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public String getBlockCommentSuffix() {
|
|
return null;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public String getCommentedBlockCommentPrefix() {
|
|
return null;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public String getCommentedBlockCommentSuffix() {
|
|
return null;
|
|
}
|
|
}
|
|
```
|
|
|
|
### 17.2. Register the commenter
|
|
|
|
```xml
|
|
<lang.commenter language="Simple" implementationClass="com.simpleplugin.SimpleCommenter"/>
|
|
```
|
|
|
|
### 17.3. Run the project
|
|
|
|

|
|
|
|
[Previous](code_style_settings.md)
|
|
[Top](/tutorials/custom_language_support_tutorial.md)
|
|
[Next](quick_fix.md)
|
|
|