From 7812e7d651c850e7ebb675960cfd070b68f2691f Mon Sep 17 00:00:00 2001 From: JohnHake Date: Fri, 9 Aug 2019 17:44:08 -0700 Subject: [PATCH] Add Review --- action_basics/build.gradle | 17 ++++++----- action_basics/settings.gradle | 3 +- .../src/main/resources/META-INF/plugin.xml | 2 +- editor_basics/build.gradle | 4 +-- .../sdk/editor/EditorAreaIllustration.java | 30 +++++++++++-------- .../sdk/editor/EditorHandlerIllustration.java | 20 ++++++------- ...ion.java => EditorIllustrationAction.java} | 19 ++++++------ .../intellij/sdk/editor/MyTypedHandler.java | 4 +-- .../src/main/resources/META-INF/plugin.xml | 6 ++-- gradle_plugin_demo/settings.gradle | 1 + .../src/main/resources/META-INF/plugin.xml | 2 +- inspection_basics/build.gradle | 2 +- inspection_basics/settings.gradle | 2 +- .../src/main/resources/META-INF/plugin.xml | 2 +- kotlin_demo/build.gradle | 6 +++- kotlin_demo/settings.gradle | 2 +- .../src/main/resources/META-INF/plugin.xml | 2 +- 17 files changed, 67 insertions(+), 57 deletions(-) rename editor_basics/src/main/java/org/intellij/sdk/editor/{EditorIllustration.java => EditorIllustrationAction.java} (75%) create mode 100644 gradle_plugin_demo/settings.gradle diff --git a/action_basics/build.gradle b/action_basics/build.gradle index 645b67c37..14993e221 100644 --- a/action_basics/build.gradle +++ b/action_basics/build.gradle @@ -1,8 +1,13 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + plugins { id 'java' - id 'org.jetbrains.intellij' version '0.4.9' + id 'org.jetbrains.intellij' version '0.4.10' } +group 'org.intellij.sdk' +version '2.0.0' + sourceCompatibility = 1.8 repositories { @@ -15,15 +20,11 @@ dependencies { // See https://github.com/JetBrains/gradle-intellij-plugin/ intellij { - - // Define IntelliJ Platform API version to use for building this plugin version '2019.1' - -// Prevents patching attributes in plugin.xml updateSinceUntilBuild = false -// Define a shared sandbox directory for running code sample plugins within an IDE. - sandboxDirectory = file("${project.projectDir}/../_idea-sandbox") - +} +patchPluginXml { + version = project.version } // Force javadoc rebuild before jar is built diff --git a/action_basics/settings.gradle b/action_basics/settings.gradle index 45b6826e6..19950c586 100644 --- a/action_basics/settings.gradle +++ b/action_basics/settings.gradle @@ -1,2 +1 @@ -rootProject.name = 'action_basics' - +rootProject.name = 'action' diff --git a/action_basics/src/main/resources/META-INF/plugin.xml b/action_basics/src/main/resources/META-INF/plugin.xml index af4bfe885..cfcb07b0c 100644 --- a/action_basics/src/main/resources/META-INF/plugin.xml +++ b/action_basics/src/main/resources/META-INF/plugin.xml @@ -12,7 +12,7 @@ - + com.intellij.modules.lang diff --git a/editor_basics/build.gradle b/editor_basics/build.gradle index ecf47fa2c..310c0afa9 100644 --- a/editor_basics/build.gradle +++ b/editor_basics/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java' - id 'org.jetbrains.intellij' version '0.4.9' + id 'org.jetbrains.intellij' version '0.4.10' } group 'org.intellij.sdk' @@ -20,7 +20,7 @@ dependencies { // See https://github.com/JetBrains/gradle-intellij-plugin/ intellij { - version '2019.2' + version '2019.1' updateSinceUntilBuild = false } patchPluginXml { diff --git a/editor_basics/src/main/java/org/intellij/sdk/editor/EditorAreaIllustration.java b/editor_basics/src/main/java/org/intellij/sdk/editor/EditorAreaIllustration.java index 042b90b85..b3c89ac0f 100644 --- a/editor_basics/src/main/java/org/intellij/sdk/editor/EditorAreaIllustration.java +++ b/editor_basics/src/main/java/org/intellij/sdk/editor/EditorAreaIllustration.java @@ -6,13 +6,14 @@ import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.editor.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; +import org.jetbrains.annotations.NotNull; import java.util.List; /** * If conditions support it, makes a menu visible to display information * about the caret. - * @author Anna Bulenkova + * * @see com.intellij.openapi.actionSystem.AnAction */ public class EditorAreaIllustration extends AnAction { @@ -22,32 +23,35 @@ public class EditorAreaIllustration extends AnAction { * @param e Event related to this action */ @Override - public void actionPerformed(AnActionEvent e) { + public void actionPerformed(@NotNull final AnActionEvent e) { // Get access to the editor and caret model. update() validated editor's existence. final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR); - CaretModel caretModel = editor.getCaretModel(); - // Getting the primary caret ensures we get the right one of a possible many. - Caret primaryCaret = caretModel.getPrimaryCaret(); + final CaretModel caretModel = editor.getCaretModel(); + // Getting the primary caret ensures we get the correct one of a possible many. + final Caret primaryCaret = caretModel.getPrimaryCaret(); + // Get the caret information + LogicalPosition logicalPos = primaryCaret.getLogicalPosition(); + VisualPosition visualPos = primaryCaret.getVisualPosition(); + int caretOffset = primaryCaret.getOffset(); // Build and display the caret report. - StringBuilder report = new StringBuilder(); - report.append(primaryCaret.getLogicalPosition().toString() + "\n"); - report.append(primaryCaret.getVisualPosition().toString() + "\n"); - report.append("Offset: " + primaryCaret.getOffset()); + StringBuilder report = new StringBuilder(logicalPos.toString() + "\n"); + report.append(visualPos.toString() + "\n"); + report.append("Offset: " + caretOffset); Messages.showInfoMessage(report.toString(), "Caret Parameters Inside The Editor"); } /** - * Sets visibility of this action menu item if: + * Sets visibility and enables this action menu item if: * A project is open, * An editor is active, * @param e Event related to this action */ @Override - public void update(AnActionEvent e) { - //Get required data keys + public void update(@NotNull final AnActionEvent e) { + // Get required data keys final Project project = e.getProject(); final Editor editor = e.getData(CommonDataKeys.EDITOR); //Set visibility only in case of existing project and editor - e.getPresentation().setVisible(project != null && editor != null); + e.getPresentation().setEnabledAndVisible(project != null && editor != null); } } diff --git a/editor_basics/src/main/java/org/intellij/sdk/editor/EditorHandlerIllustration.java b/editor_basics/src/main/java/org/intellij/sdk/editor/EditorHandlerIllustration.java index 6645b935c..d1ef02a44 100644 --- a/editor_basics/src/main/java/org/intellij/sdk/editor/EditorHandlerIllustration.java +++ b/editor_basics/src/main/java/org/intellij/sdk/editor/EditorHandlerIllustration.java @@ -10,14 +10,14 @@ import org.jetbrains.annotations.NotNull; /** * Menu action to clone a new caret based on an existing one. - * @author Anna Bulenkova + * * @see com.intellij.openapi.actionSystem.AnAction */ public class EditorHandlerIllustration extends AnAction { /** * This block of static code does not pertain to this class. - * It registers the custom MyTypedHandler, an TypedActionHandler + * It registers the custom MyTypedHandler, a TypedActionHandler * that handles actions activated by typing in the editor. * This registration code just needs to appear in a class (like AnAction class) * that gets instantiated as part of IntelliJ startup. @@ -33,19 +33,19 @@ public class EditorHandlerIllustration extends AnAction { * @param e Event related to this action */ @Override - public void actionPerformed(@NotNull AnActionEvent e) { + public void actionPerformed(@NotNull final AnActionEvent e) { // Editor is known to exist from update, so it's not null final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR); // Get the action manager in order to get the necessary action handler... - EditorActionManager actionManager = EditorActionManager.getInstance(); + final EditorActionManager actionManager = EditorActionManager.getInstance(); // Get the action handler registered to clone carets - EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW); + final EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW); // Clone one caret below the active caret actionHandler.execute(editor, editor.getCaretModel().getPrimaryCaret(), e.getDataContext()); } /** - * Sets visibility of this action menu item if: + * Enables and sets visibility of this action menu item if: * A project is open, * An editor is active, * At least one caret exists @@ -53,15 +53,15 @@ public class EditorHandlerIllustration extends AnAction { */ @Override public void update(@NotNull final AnActionEvent e) { - boolean visibility = false; - //Set visible if at least one caret is available final Project project = e.getProject(); final Editor editor = e.getData(CommonDataKeys.EDITOR); + // Make sure at least one caret is available + boolean menuAllowed = false; if (editor != null && project != null) { // Ensure the list of carets in the editor is not empty - visibility = !editor.getCaretModel().getAllCarets().isEmpty(); + menuAllowed = !editor.getCaretModel().getAllCarets().isEmpty(); } - e.getPresentation().setVisible(visibility); + e.getPresentation().setEnabledAndVisible(menuAllowed); } } diff --git a/editor_basics/src/main/java/org/intellij/sdk/editor/EditorIllustration.java b/editor_basics/src/main/java/org/intellij/sdk/editor/EditorIllustrationAction.java similarity index 75% rename from editor_basics/src/main/java/org/intellij/sdk/editor/EditorIllustration.java rename to editor_basics/src/main/java/org/intellij/sdk/editor/EditorIllustrationAction.java index a0cbb859c..4d67309e7 100644 --- a/editor_basics/src/main/java/org/intellij/sdk/editor/EditorIllustration.java +++ b/editor_basics/src/main/java/org/intellij/sdk/editor/EditorIllustrationAction.java @@ -7,21 +7,22 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.actionSystem.*; import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; /** * Menu action to replace a selection of characters with a fixed string. - * @author Anna Bulenkova + * * @see com.intellij.openapi.actionSystem.AnAction */ -public class EditorIllustration extends AnAction { +public class EditorIllustrationAction extends AnAction { /** * Replaces the run of text selected by the primary caret with a fixed string. * @param e Event related to this action */ @Override - public void actionPerformed(final AnActionEvent e) { - //Get all the required data from data keys + public void actionPerformed(@NotNull final AnActionEvent e) { + // Get all the required data from data keys // Editor and Project were verified in update(), so they are not null. final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR); final Project project = e.getRequiredData(CommonDataKeys.PROJECT); @@ -40,18 +41,18 @@ public class EditorIllustration extends AnAction { } /** - * Sets visibility of this action menu item if: + * Sets visibility and enables this action menu item if: * A project is open, * An editor is active, * Some characters are selected * @param e Event related to this action */ @Override - public void update(final AnActionEvent e) { - //Get required data keys + public void update(@NotNull final AnActionEvent e) { + // Get required data keys final Project project = e.getProject(); final Editor editor = e.getData(CommonDataKeys.EDITOR); - //Set visibility only in case of existing project and editor and if a selection exists - e.getPresentation().setVisible((project != null && editor != null && editor.getSelectionModel().hasSelection())); + // Set visibility and enable only in case of existing project and editor and if a selection exists + e.getPresentation().setEnabledAndVisible( project != null && editor != null && editor.getSelectionModel().hasSelection() ); } } diff --git a/editor_basics/src/main/java/org/intellij/sdk/editor/MyTypedHandler.java b/editor_basics/src/main/java/org/intellij/sdk/editor/MyTypedHandler.java index 1e93b9927..43e8fbb8c 100644 --- a/editor_basics/src/main/java/org/intellij/sdk/editor/MyTypedHandler.java +++ b/editor_basics/src/main/java/org/intellij/sdk/editor/MyTypedHandler.java @@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull; * The execute method inserts a fixed string at Offset 0 of the document. * Document changes are made in the context of a write action. * MyTypedHandler is registered by static code in the EditorHandlerIllustration class. - * @author Anna Bulenkova + * * @see com.intellij.openapi.editor.actionSystem.TypedActionHandler */ class MyTypedHandler implements TypedActionHandler { @@ -23,7 +23,7 @@ class MyTypedHandler implements TypedActionHandler { public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) { // Get the document and project final Document document = editor.getDocument(); - Project project = editor.getProject(); + final Project project = editor.getProject(); // Construct the runnable to substitute the string at offset 0 in the document Runnable runnable = () -> document.insertString(0, "editor_basics\n"); // Make the document change in the context of a write action. diff --git a/editor_basics/src/main/resources/META-INF/plugin.xml b/editor_basics/src/main/resources/META-INF/plugin.xml index e527e45d8..c17fc5116 100644 --- a/editor_basics/src/main/resources/META-INF/plugin.xml +++ b/editor_basics/src/main/resources/META-INF/plugin.xml @@ -12,7 +12,7 @@ 2.0.0 - + com.intellij.modules.lang @@ -36,8 +36,8 @@ IntelliJ Platform SDK - diff --git a/gradle_plugin_demo/settings.gradle b/gradle_plugin_demo/settings.gradle new file mode 100644 index 000000000..110e55e2f --- /dev/null +++ b/gradle_plugin_demo/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'gradle_demo' diff --git a/gradle_plugin_demo/src/main/resources/META-INF/plugin.xml b/gradle_plugin_demo/src/main/resources/META-INF/plugin.xml index f0b4b05bc..c0157b52f 100644 --- a/gradle_plugin_demo/src/main/resources/META-INF/plugin.xml +++ b/gradle_plugin_demo/src/main/resources/META-INF/plugin.xml @@ -6,7 +6,7 @@ com.intellij.modules.lang - + diff --git a/inspection_basics/build.gradle b/inspection_basics/build.gradle index 4cb0a63e8..d96d474b2 100644 --- a/inspection_basics/build.gradle +++ b/inspection_basics/build.gradle @@ -18,7 +18,7 @@ dependencies { // See https://github.com/JetBrains/gradle-intellij-plugin/ intellij { - version '2017.1' + version '2019.1' updateSinceUntilBuild = false } diff --git a/inspection_basics/settings.gradle b/inspection_basics/settings.gradle index a67c7c467..59e36c103 100644 --- a/inspection_basics/settings.gradle +++ b/inspection_basics/settings.gradle @@ -1,2 +1,2 @@ -rootProject.name = 'inspection_basics' +rootProject.name = 'inspection' diff --git a/inspection_basics/src/main/resources/META-INF/plugin.xml b/inspection_basics/src/main/resources/META-INF/plugin.xml index fd25a6ca5..ec45b60f2 100644 --- a/inspection_basics/src/main/resources/META-INF/plugin.xml +++ b/inspection_basics/src/main/resources/META-INF/plugin.xml @@ -10,7 +10,7 @@ 2.0.0 - + com.intellij.modules.lang diff --git a/kotlin_demo/build.gradle b/kotlin_demo/build.gradle index dedfc6303..57730a925 100644 --- a/kotlin_demo/build.gradle +++ b/kotlin_demo/build.gradle @@ -20,9 +20,13 @@ dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' } +sourceSets { + main.kotlin.srcDirs += 'src/main/kotlin' +} + // See https://github.com/JetBrains/gradle-intellij-plugin/ intellij { - version '2019.1.3' + version '2019.1' updateSinceUntilBuild = false } compileKotlin { diff --git a/kotlin_demo/settings.gradle b/kotlin_demo/settings.gradle index 540f4adea..d0714de6b 100644 --- a/kotlin_demo/settings.gradle +++ b/kotlin_demo/settings.gradle @@ -1,2 +1,2 @@ -rootProject.name = 'kotlin_demo' +rootProject.name = 'kotlin' diff --git a/kotlin_demo/src/main/resources/META-INF/plugin.xml b/kotlin_demo/src/main/resources/META-INF/plugin.xml index 990ba1726..762d99085 100644 --- a/kotlin_demo/src/main/resources/META-INF/plugin.xml +++ b/kotlin_demo/src/main/resources/META-INF/plugin.xml @@ -13,7 +13,7 @@ 2.0.0 - + com.intellij.modules.lang