null to disable all the language server
- * features.
+ * features.
*/
- public void setLanguageServer(ILanguageServer server) {
+ public void setLanguageServer (ILanguageServer server) {
this.mLanguageServer = server;
-
- if (mLanguageClient == null && IDELanguageClientImpl.isInitialized()) {
- mLanguageClient = IDELanguageClientImpl.getInstance();
+
+ if (mLanguageClient == null && IDELanguageClientImpl.isInitialized ()) {
+ mLanguageClient = IDELanguageClientImpl.getInstance ();
}
}
-
+
/**
* Append the given text at the end of the editor's content.
*
* @param text The text to append.
* @return The line at which the text was appended.
*/
- public int append(CharSequence text) {
- final var content = getText();
- if (getLineCount() <= 0) {
+ public int append (CharSequence text) {
+ final var content = getText ();
+ if (getLineCount () <= 0) {
return 0;
}
- final int line = getLineCount() - 1;
- int col = content.getColumnCount(line);
+ final int line = getLineCount () - 1;
+ int col = content.getColumnCount (line);
if (col < 0) {
col = 0;
}
- content.insert(line, col, text);
+ content.insert (line, col, text);
return line;
}
-
- /** Set the selection of the editor's cursor to the last line of the it's content. */
- public void goToEnd() {
- final var line = getText().getLineCount() - 1;
- setSelection(line, 0);
+
+ /**
+ * Set the selection of the editor's cursor to the last line of the it's content.
+ */
+ public void goToEnd () {
+ final var line = getText ().getLineCount () - 1;
+ setSelection (line, 0);
}
-
- /** Comment the line of the left cursor. */
- public void commentLine() {
- if (getFile() == null) {
+
+ /**
+ * Comment the line of the left cursor.
+ */
+ public void commentLine () {
+ if (getFile () == null) {
return;
}
-
- final var text = getText();
- final var name = getFile().getName();
- int line = getCursor().getLeftLine();
- if (name.endsWith(".java") || name.endsWith(".gradle")) {
- while (line >= getCursor().getLeftLine() && line <= getCursor().getRightLine()) {
- if (!text.getLineString(line).trim().startsWith("//")) {
- text.insert(line, 0, "//");
+
+ final var text = getText ();
+ final var name = getFile ().getName ();
+ int line = getCursor ().getLeftLine ();
+ if (name.endsWith (".java") || name.endsWith (".gradle")) {
+ while (line >= getCursor ().getLeftLine () && line <= getCursor ().getRightLine ()) {
+ if (!text.getLineString (line).trim ().startsWith ("//")) {
+ text.insert (line, 0, "//");
}
line++;
}
- } else if (name.endsWith(".xml")) {
- while (line >= getCursor().getLeftLine() && line <= getCursor().getRightLine()) {
- final String lineString = text.getLineString(line);
- if (!lineString.trim().startsWith("")) {
- text.replace(
+ } else if (name.endsWith (".xml")) {
+ while (line >= getCursor ().getLeftLine () && line <= getCursor ().getRightLine ()) {
+ final String lineString = text.getLineString (line);
+ if (!lineString.trim ().startsWith ("")) {
+ text.replace (
line,
0,
line,
- text.getColumnCount(line),
- ""));
+ text.getColumnCount (line),
+ ""));
}
line++;
}
}
}
-
- /** Uncomment the current line */
- public void uncommentLine() {
- if (getFile() == null) {
+
+ /**
+ * Uncomment the current line
+ */
+ public void uncommentLine () {
+ if (getFile () == null) {
return;
}
-
- final var text = getText();
- final String name = getFile().getName();
- int line = getCursor().getLeftLine();
- if (name.endsWith(".java") || name.endsWith(".gradle")) {
- while (line >= getCursor().getLeftLine() && line <= getCursor().getRightLine()) {
- String l = text.getLineString(line);
- if (l.trim().startsWith("//")) {
- int i = l.indexOf("//");
- text.delete(line, i, line, i + 2);
+
+ final var text = getText ();
+ final String name = getFile ().getName ();
+ int line = getCursor ().getLeftLine ();
+ if (name.endsWith (".java") || name.endsWith (".gradle")) {
+ while (line >= getCursor ().getLeftLine () && line <= getCursor ().getRightLine ()) {
+ String l = text.getLineString (line);
+ if (l.trim ().startsWith ("//")) {
+ int i = l.indexOf ("//");
+ text.delete (line, i, line, i + 2);
}
line++;
}
- } else if (name.endsWith(".xml")) {
+ } else if (name.endsWith (".xml")) {
final String commentStart = "";
- while (line >= getCursor().getLeftLine() && line <= getCursor().getRightLine()) {
- String l = text.getLineString(line);
- if (l.trim().startsWith(commentStart)) {
- int i = l.indexOf(commentStart);
- text.delete(line, i, line, i + commentStart.length());
+ while (line >= getCursor ().getLeftLine () && line <= getCursor ().getRightLine ()) {
+ String l = text.getLineString (line);
+ if (l.trim ().startsWith (commentStart)) {
+ int i = l.indexOf (commentStart);
+ text.delete (line, i, line, i + commentStart.length ());
}
- if (l.trim().endsWith(commentEnd)) {
- int count = text.getColumnCount(line);
- text.delete(line, count - commentEnd.length(), line, count);
+ if (l.trim ().endsWith (commentEnd)) {
+ int count = text.getColumnCount (line);
+ text.delete (line, count - commentEnd.length (), line, count);
}
line++;
}
}
}
-
+
/**
* If any language server is set, asks the language server to find the definition of token at
* the cursor position.
@@ -296,88 +301,88 @@ public class IDEEditor extends CodeEditor {
* file in this editor, the range specified in the response will be selected.
*/
@SuppressWarnings("deprecation")
- public void findDefinition() {
- if (getFile() == null) {
+ public void findDefinition () {
+ if (getFile () == null) {
return;
}
-
+
final ProgressDialog pd =
- ProgressDialog.show(
- getContext(),
+ ProgressDialog.show (
+ getContext (),
null,
- getContext().getString(R.string.msg_finding_definition));
-
+ getContext ().getString (R.string.msg_finding_definition));
+
try {
final CompletableFutureIf the server returns a valid response, that response is forwarded to the {@link
* IDELanguageClientImpl}.
*/
- public void findReferences() {
- if (getFile() == null) {
+ public void findReferences () {
+ if (getFile () == null) {
return;
}
-
- @SuppressWarnings("deprecation")
- final ProgressDialog pd =
- ProgressDialog.show(
- getContext(),
+
+ @SuppressWarnings("deprecation") final ProgressDialog pd =
+ ProgressDialog.show (
+ getContext (),
null,
- getContext().getString(R.string.msg_finding_references));
-
+ getContext ().getString (R.string.msg_finding_references));
+
try {
final CompletableFuturenull.
- */
- public void setTextActionPresenter(@NonNull ITextActionPresenter actionPresenter) {
- Objects.requireNonNull(actionPresenter, "Cannot set text action presenter to null");
-
- if (mTextActionPresenter != null) {
- mTextActionPresenter.destroy();
- mTextActionPresenter = null;
- }
-
- this.mTextActionPresenter = actionPresenter;
-
- actionPresenter.bindEditor(this);
- registerActionsTo(actionPresenter);
- }
-
+
/**
* Get the text action presenter attached with this editor.
*
* @return The attached text action presenter.
*/
@SuppressWarnings("unused")
- public ITextActionPresenter getTextActionPresenter() {
+ public ITextActionPresenter getTextActionPresenter () {
return mTextActionPresenter;
}
-
+
+ /**
+ * Set the text action presenter of this editor.
+ *
+ * @param actionPresenter The presenter to set. Must not be null.
+ */
+ public void setTextActionPresenter (@NonNull ITextActionPresenter actionPresenter) {
+ Objects.requireNonNull (actionPresenter, "Cannot set text action presenter to null");
+
+ if (mTextActionPresenter != null) {
+ mTextActionPresenter.destroy ();
+ mTextActionPresenter = null;
+ }
+
+ this.mTextActionPresenter = actionPresenter;
+
+ actionPresenter.bindEditor (this);
+ registerActionsTo (actionPresenter);
+ }
+
/**
* Register the editor's actions to the given action presenter.
*
* @param actionPresenter The action presenter to register actions to.
*/
- public void registerActionsTo(@NonNull ITextActionPresenter actionPresenter) {
- Objects.requireNonNull(
+ public void registerActionsTo (@NonNull ITextActionPresenter actionPresenter) {
+ Objects.requireNonNull (
actionPresenter, "Cannot register actions to null text action presenter");
-
+
var index = -1;
-
+
TypedArray array =
- getContext()
- .getTheme()
- .obtainStyledAttributes(
- new int[] {
- android.R.attr.actionModeSelectAllDrawable,
- android.R.attr.actionModeCutDrawable,
- android.R.attr.actionModeCopyDrawable,
- android.R.attr.actionModePasteDrawable,
+ getContext ()
+ .getTheme ()
+ .obtainStyledAttributes (
+ new int[]{
+ android.R.attr.actionModeSelectAllDrawable,
+ android.R.attr.actionModeCutDrawable,
+ android.R.attr.actionModeCopyDrawable,
+ android.R.attr.actionModePasteDrawable,
});
-
- actionPresenter.registerAction(
- new TextAction(
- createTextActionDrawable(R.drawable.ic_expand_selection),
+
+ actionPresenter.registerAction (
+ new TextAction (
+ createTextActionDrawable (R.drawable.ic_expand_selection),
R.string.action_expand_selection,
TextAction.EXPAND_SELECTION,
index++));
-
- actionPresenter.registerAction(
- new TextAction(
- array.getDrawable(0),
+
+ actionPresenter.registerAction (
+ new TextAction (
+ array.getDrawable (0),
android.R.string.selectAll,
TextAction.SELECT_ALL,
index++));
-
- actionPresenter.registerAction(
- new TextAction(
- array.getDrawable(1), android.R.string.cut, TextAction.CUT, index++));
-
- actionPresenter.registerAction(
- new TextAction(
- array.getDrawable(2), android.R.string.copy, TextAction.COPY, index++));
-
- actionPresenter.registerAction(
- new TextAction(
- array.getDrawable(3), android.R.string.paste, TextAction.PASTE, index++));
-
- actionPresenter.registerAction(
- new TextAction(
- createTextActionDrawable(R.drawable.ic_goto_definition),
+
+ actionPresenter.registerAction (
+ new TextAction (
+ array.getDrawable (1), android.R.string.cut, TextAction.CUT, index++));
+
+ actionPresenter.registerAction (
+ new TextAction (
+ array.getDrawable (2), android.R.string.copy, TextAction.COPY, index++));
+
+ actionPresenter.registerAction (
+ new TextAction (
+ array.getDrawable (3), android.R.string.paste, TextAction.PASTE, index++));
+
+ actionPresenter.registerAction (
+ new TextAction (
+ createTextActionDrawable (R.drawable.ic_goto_definition),
R.string.menu_navigate_definition,
TextAction.GOTO_DEFINITION,
index++));
-
- actionPresenter.registerAction(
- new TextAction(
- createTextActionDrawable(R.drawable.ic_find_references),
+
+ actionPresenter.registerAction (
+ new TextAction (
+ createTextActionDrawable (R.drawable.ic_find_references),
R.string.menu_navigate_references,
TextAction.FIND_REFERENCES,
index++));
- actionPresenter.registerAction(
- new TextAction(
- createTextActionDrawable(R.drawable.ic_comment_line),
+ actionPresenter.registerAction (
+ new TextAction (
+ createTextActionDrawable (R.drawable.ic_comment_line),
R.string.menu_comment_line,
TextAction.COMMENT_LINE,
index++));
-
+
//noinspection UnusedAssignment
- actionPresenter.registerAction(
- new TextAction(
- createTextActionDrawable(R.drawable.ic_uncomment_line),
+ actionPresenter.registerAction (
+ new TextAction (
+ createTextActionDrawable (R.drawable.ic_uncomment_line),
R.string.menu_uncomment_line,
TextAction.UNCOMMENT_LINE,
index++));
-
- array.recycle();
+
+ array.recycle ();
}
-
+
/**
* Called by text action presenters to check if the action with the given ID should be shown or
* not.
@@ -794,21 +812,21 @@ public class IDEEditor extends CodeEditor {
* @param actionId The action ID to check.
* @return true if the action should be shown, false otherwise.
*/
- public boolean shouldShowTextAction(int actionId) {
- final var capabilities = mLanguageServer != null ? mLanguageServer.getCapabilities() : null;
+ public boolean shouldShowTextAction (int actionId) {
+ final var capabilities = mLanguageServer != null ? mLanguageServer.getCapabilities () : null;
final var notNull = capabilities != null;
- final var expand = notNull && capabilities.getSmartSelectionsEnabled();
- final var definitions = notNull && capabilities.getDefinitionsAvailable();
- final var references = notNull && capabilities.getReferencesAvailable();
+ final var expand = notNull && capabilities.getSmartSelectionsEnabled ();
+ final var definitions = notNull && capabilities.getDefinitionsAvailable ();
+ final var references = notNull && capabilities.getReferencesAvailable ();
final var commentUncomment =
- getFile() != null
- && (getFile().getName().endsWith(".java")
- || getFile().getName().endsWith(".gradle")
- || getFile().getName().endsWith(".xml"));
+ getFile () != null
+ && (getFile ().getName ().endsWith (".java")
+ || getFile ().getName ().endsWith (".gradle")
+ || getFile ().getName ().endsWith (".xml"));
switch (actionId) {
case TextAction.CUT:
case TextAction.PASTE:
- return isEditable();
+ return isEditable ();
case TextAction.GOTO_DEFINITION:
return definitions;
case TextAction.EXPAND_SELECTION:
@@ -819,90 +837,90 @@ public class IDEEditor extends CodeEditor {
case TextAction.UNCOMMENT_LINE:
return commentUncomment;
}
-
+
return true;
}
-
+
/**
* Performs the given text action in this editor.
*
* @param action The action to perform.
*/
- public void performTextAction(@NonNull TextAction action) {
- Objects.requireNonNull(action, "Cannot perform null text action");
-
+ public void performTextAction (@NonNull TextAction action) {
+ Objects.requireNonNull (action, "Cannot perform null text action");
+
switch (action.id) {
case TextAction.SELECT_ALL:
- selectAll();
+ selectAll ();
break;
case TextAction.CUT:
- cutText();
+ cutText ();
break;
case TextAction.COPY:
- copyText();
+ copyText ();
break;
case TextAction.PASTE:
- pasteText();
+ pasteText ();
break;
case TextAction.GOTO_DEFINITION:
- findDefinition();
+ findDefinition ();
break;
case TextAction.FIND_REFERENCES:
- findReferences();
+ findReferences ();
break;
case TextAction.COMMENT_LINE:
- commentLine();
+ commentLine ();
break;
case TextAction.UNCOMMENT_LINE:
- uncommentLine();
+ uncommentLine ();
break;
case TextAction.EXPAND_SELECTION:
- expandSelection();
+ expandSelection ();
break;
}
}
-
- private Drawable createTextActionDrawable(int icon) {
- final Drawable d = ContextCompat.getDrawable(getContext(), icon);
+
+ private Drawable createTextActionDrawable (int icon) {
+ final Drawable d = ContextCompat.getDrawable (getContext (), icon);
if (d != null) {
- d.setColorFilter(
- ContextCompat.getColor(getContext(), secondaryColor), PorterDuff.Mode.SRC_ATOP);
+ d.setColorFilter (
+ ContextCompat.getColor (getContext (), secondaryColor), PorterDuff.Mode.SRC_ATOP);
}
return d;
}
-
- private void handleSelectionChange(SelectionChangeEvent event) {
- if (event.isSelected() || !(getEditorLanguage() instanceof IDELanguage)) {
+
+ private void handleSelectionChange (SelectionChangeEvent event) {
+ if (event.isSelected () || !(getEditorLanguage () instanceof IDELanguage)) {
// do not show diagnostics when text is selected
// or if we cannot get diagnostics
return;
}
-
- final var diagnostics = ((IDELanguage) getEditorLanguage()).getDiagnostics();
- final var line = event.getLeft().line;
- final var column = event.getLeft().column;
-
+
+ final var diagnostics = ((IDELanguage) getEditorLanguage ()).getDiagnostics ();
+ final var line = event.getLeft ().line;
+ final var column = event.getLeft ().column;
+
// diagnostics are expected to be sorted, so, we do a binary search
- getDiagnosticWindow().showDiagnostic(binarySearchDiagnostic(diagnostics, line, column));
+ getDiagnosticWindow ().showDiagnostic (binarySearchDiagnostic (diagnostics, line, column));
}
-
+
@Nullable
- private DiagnosticItem binarySearchDiagnostic(
+ private DiagnosticItem binarySearchDiagnostic (
@NonNull List
*
@@ -982,68 +1000,73 @@ public class IDEEditor extends CodeEditor {
* @author Akash Yadav
*/
public interface ITextActionPresenter {
-
+
/**
* Bind the action presenter with the given editor instance.
*
* @param editor The editor to bind with.
*/
- void bindEditor(@NonNull IDEEditor editor);
-
+ void bindEditor (@NonNull IDEEditor editor);
+
/**
* Register the text action with this presenter.
*
* @param action The action to register.
*/
- void registerAction(@NonNull TextAction action);
-
+ void registerAction (@NonNull TextAction action);
+
/**
* Destroy this action presenter. The presenter should unsubscribe from any subscribed
* events and release any held resources.
*/
- void destroy();
+ void destroy ();
}
-
+
/**
* A model class for text actions.
*
* @author Akash Yadav
*/
public static class TextAction implements Comparable