mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-28 01:07:49 +08:00
remove noisy final keywords in code snippets
This commit is contained in:
parent
4e512d99d3
commit
86c69eec32
@ -43,19 +43,19 @@ So the code would probably look like this:
|
||||
|
||||
```java
|
||||
XmlFile file = ...;
|
||||
final XmlDocument document = file.getDocument();
|
||||
XmlDocument document = file.getDocument();
|
||||
if (document != null) {
|
||||
final XmlTag rootTag = document.getRootTag();
|
||||
if (rootTag != null) {
|
||||
final XmlTag foo = rootTag.findFirstSubTag("foo");
|
||||
if (foo != null) {
|
||||
final XmlTag[] bars = foo.findSubTags("bar");
|
||||
if (bars.length > 1) {
|
||||
String s = bars[1].getValue().getTrimmedText();
|
||||
// do something
|
||||
}
|
||||
}
|
||||
XmlTag rootTag = document.getRootTag();
|
||||
if (rootTag != null) {
|
||||
XmlTag foo = rootTag.findFirstSubTag("foo");
|
||||
if (foo != null) {
|
||||
XmlTag[] bars = foo.findSubTags("bar");
|
||||
if (bars.length > 1) {
|
||||
String s = bars[1].getValue().getTrimmedText();
|
||||
// do something
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -565,9 +565,9 @@ For example, if you have two DOM element classes — `Foo` and `Bar` — your vi
|
||||
|
||||
```java
|
||||
class MyVisitor implements DomElementVisitor {
|
||||
void visitDomElement(DomElement element) {}
|
||||
void visitFoo(Foo foo) {}
|
||||
void visitBar(Bar bar) {}
|
||||
void visitDomElement(DomElement element) {}
|
||||
void visitFoo(Foo foo) {}
|
||||
void visitBar(Bar bar) {}
|
||||
}
|
||||
```
|
||||
|
||||
@ -582,10 +582,10 @@ You can easily write this helper method and annotate it with the `@PropertyAcces
|
||||
For example, you can write:
|
||||
|
||||
```java
|
||||
GenericDomValue<String> getVeryLongName()
|
||||
GenericDomValue<String> getVeryLongName();
|
||||
|
||||
@PropertyAccessor("very-long-name")
|
||||
GenericDomValue<String> getName()
|
||||
GenericDomValue<String> getName();
|
||||
```
|
||||
|
||||
In this case, the second method will return just the same as the first one.
|
||||
|
@ -78,7 +78,7 @@ import org.intellij.sdk.language.SimpleFileType;
|
||||
public class SimpleElementFactory {
|
||||
|
||||
public static SimpleProperty createProperty(Project project, String name) {
|
||||
final SimpleFile file = createFile(project, name);
|
||||
SimpleFile file = createFile(project, name);
|
||||
return (SimpleProperty) file.getFirstChild();
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,8 @@ After ensuring that `Project` and `Editor` objects are available, the `Editor` o
|
||||
public class EditorHandlerIllustration extends AnAction {
|
||||
@Override
|
||||
public void update(@NotNull final AnActionEvent e) {
|
||||
final Project project = e.getProject();
|
||||
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||
Project project = e.getProject();
|
||||
Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||
|
||||
// Make sure at least one caret is available
|
||||
boolean menuAllowed = false;
|
||||
@ -77,9 +77,10 @@ For cloning a caret below the primary caret, the constant is `ACTION_EDITOR_CLON
|
||||
Based on that constant, the `EditorActionManager` returns an instance of [`CloneCaretActionHandler`](upsource:///platform/platform-impl/src/com/intellij/openapi/editor/actions/CloneCaretActionHandler.java), a subclass of `EditorActionHandler`.
|
||||
|
||||
```java
|
||||
// Snippet from EditorHandlerIllustration.actionPerformed()
|
||||
final EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||
final EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW);
|
||||
// Snippet from EditorHandlerIllustration.actionPerformed()
|
||||
EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||
EditorActionHandler actionHandler =
|
||||
actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW);
|
||||
```
|
||||
|
||||
### Using an EditorActionHandler to Clone the Caret
|
||||
@ -90,10 +91,12 @@ To clone the caret requires only calling the `EditorActionHandler.execute()` met
|
||||
public class EditorHandlerIllustration extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull final AnActionEvent e) {
|
||||
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
||||
final EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||
final EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW);
|
||||
actionHandler.execute(editor, editor.getCaretModel().getPrimaryCaret(), e.getDataContext());
|
||||
Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
||||
EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||
EditorActionHandler actionHandler =
|
||||
actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW);
|
||||
actionHandler.execute(editor,
|
||||
editor.getCaretModel().getPrimaryCaret(), e.getDataContext());
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -125,7 +128,7 @@ class MyTypedHandler implements TypedActionHandler {
|
||||
char c,
|
||||
@NotNull DataContext dataContext) {
|
||||
final Document document = editor.getDocument();
|
||||
final Project project = editor.getProject();
|
||||
Project project = editor.getProject();
|
||||
Runnable runnable = () -> document.insertString(0, "editor_basics\n");
|
||||
WriteCommandAction.runWriteCommandAction(project, runnable);
|
||||
}
|
||||
@ -142,11 +145,11 @@ The method `TypedAction.setupHandler()` is used to register the custom `MyTypedH
|
||||
|
||||
```java
|
||||
public class EditorHandlerIllustration extends AnAction {
|
||||
static {
|
||||
final EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||
final TypedAction typedAction = actionManager.getTypedAction();
|
||||
typedAction.setupHandler(new MyTypedHandler());
|
||||
}
|
||||
static {
|
||||
EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||
TypedAction typedAction = actionManager.getTypedAction();
|
||||
typedAction.setupHandler(new MyTypedHandler());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -54,12 +54,13 @@ Similarly, to obtain a project reference, we use the `getProject()` method.
|
||||
|
||||
```java
|
||||
public class EditorIllustrationAction extends AnAction {
|
||||
@Override
|
||||
public void update(@NotNull final AnActionEvent e) {
|
||||
// Get required data keys
|
||||
final Project project = e.getProject();
|
||||
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||
}
|
||||
@Override
|
||||
public void update(@NotNull final AnActionEvent e) {
|
||||
// Get required data keys
|
||||
Project project = e.getProject();
|
||||
Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -78,10 +79,10 @@ Here's how the `EditorIllustrationAction.update(AnActionEvent e)` method should
|
||||
```java
|
||||
public class EditorIllustrationAction extends AnAction {
|
||||
@Override
|
||||
public void update(@NotNull final AnActionEvent e) {
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
// Get required data keys
|
||||
final Project project = e.getProject();
|
||||
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||
Project project = e.getProject();
|
||||
Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||
|
||||
// Set visibility only in the case of
|
||||
// existing project editor, and selection
|
||||
@ -131,8 +132,8 @@ public class EditorIllustrationAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull final AnActionEvent e) {
|
||||
// Get all the required data from data keys
|
||||
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
||||
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
|
||||
Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
||||
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
|
||||
final Document document = editor.getDocument();
|
||||
|
||||
// Work off of the primary caret to get the selection info
|
||||
|
Loading…
x
Reference in New Issue
Block a user