Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-2759: Code formatting and certify

Ryan Kurtzb4bb4a45a72c
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/console/CodeCompletion.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/console/CodeCompletion.java
index 39272f2935..7b58194c66 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/console/CodeCompletion.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/console/CodeCompletion.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +17,6 @@ package ghidra.app.plugin.core.console;
import javax.swing.JComponent;
-
/**
* This class encapsulates a code completion.
*
@@ -47,18 +45,16 @@ public class CodeCompletion implements Comparable<CodeCompletion> {
private JComponent component;
private int charsToRemove;
-
/**
* Returns true if the given CodeCompletion actually would insert something.
*
* @param completion a CodeCompletion
+ * @return true if the given CodeCompletion actually would insert something
*/
public static boolean isValid(CodeCompletion completion) {
- return ((completion != null) &&
- (completion.getInsertion() != null));
+ return completion != null && completion.getInsertion() != null;
}
-
/**
* Construct a new CodeCompletion.
*
@@ -66,15 +62,13 @@ public class CodeCompletion implements Comparable<CodeCompletion> {
* @param insertion what will be inserted (or null)
* @param comp (optional) Component to appear in completion List (or null)
*/
- public CodeCompletion(String description, String insertion,
- JComponent comp) {
+ public CodeCompletion(String description, String insertion, JComponent comp) {
this.description = description;
this.insertion = insertion;
this.component = comp;
this.charsToRemove = 0;
}
-
/**
* Construct a new CodeCompletion.
*
@@ -83,15 +77,14 @@ public class CodeCompletion implements Comparable<CodeCompletion> {
* @param comp (optional) Component to appear in completion List (or null)
* @param charsToRemove the number of characters that should be removed before the insertion
*/
- public CodeCompletion(String description, String insertion,
- JComponent comp, int charsToRemove) {
+ public CodeCompletion(String description, String insertion, JComponent comp,
+ int charsToRemove) {
this.description = description;
this.insertion = insertion;
this.component = comp;
this.charsToRemove = charsToRemove;
}
-
/**
* Returns the Component to display in the completion list
*
@@ -101,7 +94,6 @@ public class CodeCompletion implements Comparable<CodeCompletion> {
return component;
}
-
/**
* Returns the description of this CodeCompletion.
*
@@ -113,7 +105,6 @@ public class CodeCompletion implements Comparable<CodeCompletion> {
return description;
}
-
/**
* Returns the text to insert to complete the code.
*
@@ -122,7 +113,7 @@ public class CodeCompletion implements Comparable<CodeCompletion> {
public String getInsertion() {
return insertion;
}
-
+
/**
* Returns the number of characters to remove from the input before the insertion
* of the code completion
@@ -132,15 +123,14 @@ public class CodeCompletion implements Comparable<CodeCompletion> {
public int getCharsToRemove() {
return charsToRemove;
}
-
-
+
/**
* Returns a String representation of this CodeCompletion.
*
* @return a String representation of this CodeCompletion
*/
@Override
- public String toString() {
+ public String toString() {
return "CodeCompletion: '" + getDescription() + "' (" + getInsertion() + ")";
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/interpreter/InterpreterPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/interpreter/InterpreterPanel.java
index 3ccd14e177..aff3b9932d 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/interpreter/InterpreterPanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/interpreter/InterpreterPanel.java
@@ -626,7 +626,8 @@ public class InterpreterPanel extends JPanel implements OptionsChangeListener {
/* insert completion string */
int insertedTextStart = position - completion.getCharsToRemove();
int insertedTextEnd = insertedTextStart + insertion.length();
- var inputText = text.substring(0, insertedTextStart) + insertion + text.substring(position);
+ String inputText =
+ text.substring(0, insertedTextStart) + insertion + text.substring(position);
setInputTextPaneText(inputText);
/* Select what we inserted so that the user can easily
@@ -634,11 +635,12 @@ public class InterpreterPanel extends JPanel implements OptionsChangeListener {
if (highlightCompletion) {
inputTextPane.setSelectionStart(insertedTextStart);
inputTextPane.moveCaretPosition(insertedTextEnd);
- } else {
+ }
+ else {
/* Then put the caret right after what we inserted. */
inputTextPane.setCaretPosition(insertedTextEnd);
}
-
+
updateCompletionList();
}
@@ -673,7 +675,6 @@ public class InterpreterPanel extends JPanel implements OptionsChangeListener {
// Inner Classes
//==================================================================================================
-
/**
* An {@link InputStream} that has as its source text strings being pushed into
* it by a thread, and being read by another thread.
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/interpreter/InterpreterPanelTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/interpreter/InterpreterPanelTest.java
index de8eda1d0d..f3bd6f404e 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/interpreter/InterpreterPanelTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/interpreter/InterpreterPanelTest.java
@@ -160,26 +160,25 @@ public class InterpreterPanelTest extends AbstractGhidraHeadedIntegrationTest {
// test the general ability to insert text with the code completion popup;
// and also make sure that the completion doesn't accidentally destroy
// a part of the input near the caret
-
+
// case 1: "simple." => "simple.completion"
- testingCodeCompletions = List.of(
- new CodeCompletion("test", "completion", null, 0));
+ testingCodeCompletions = List.of(new CodeCompletion("test", "completion", null, 0));
triggerText(inputTextPane, "simple.");
insertFirstCodeCompletion();
assertEquals("simple.completion", inputTextPane.getText());
triggerEnter(inputTextPane);
-
+
// case 2: "simple." => "not.so.simple.completion"
testingCodeCompletions = List.of(
- new CodeCompletion("test", "not.so.simple.completion", null, "simple.".length()));
+ new CodeCompletion("test", "not.so.simple.completion", null, "simple.".length()));
triggerText(inputTextPane, "simple.");
insertFirstCodeCompletion();
assertEquals("not.so.simple.completion", inputTextPane.getText());
triggerEnter(inputTextPane);
-
+
// case 3: "( check.both.sides.of<caret> )" => "( check.is.ok )"
- testingCodeCompletions = List.of(
- new CodeCompletion("test", "is.ok", null, "both.sides.of".length()));
+ testingCodeCompletions =
+ List.of(new CodeCompletion("test", "is.ok", null, "both.sides.of".length()));
triggerText(inputTextPane, "( check.both.sides.of )");
inputTextPane.setCaretPosition("( check.both.sides.of".length());
insertFirstCodeCompletion();
diff --git a/Ghidra/Features/Python/src/test.slow/java/ghidra/python/PythonCodeCompletionTest.java b/Ghidra/Features/Python/src/test.slow/java/ghidra/python/PythonCodeCompletionTest.java
index 8353d3d8d7..75bbdae580 100644
--- a/Ghidra/Features/Python/src/test.slow/java/ghidra/python/PythonCodeCompletionTest.java
+++ b/Ghidra/Features/Python/src/test.slow/java/ghidra/python/PythonCodeCompletionTest.java
@@ -20,10 +20,7 @@ import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
@@ -91,8 +88,8 @@ public class PythonCodeCompletionTest extends AbstractGhidraHeadedIntegrationTes
// test the "insertion" field
// it should be equal to the full name of a variable we want to complete
- List<String> completions = List.of("my_bool", "my_dictionary", "my_int",
- "my_list", "mY_None", "my_string", "my_tuple");
+ List<String> completions = List.of("my_bool", "my_dictionary", "my_int", "my_list",
+ "mY_None", "my_string", "my_tuple");
assertCompletionsInclude("My", completions);
assertCompletionsInclude("employee.Get", List.of("getId", "getName"));
assertCompletionsInclude("('noise', (1 + fact", List.of("factorial"));
@@ -114,8 +111,7 @@ public class PythonCodeCompletionTest extends AbstractGhidraHeadedIntegrationTes
assertCharsToRemoveEqualsTo("employee.getId(", 0);
}
- private void assertCompletionsInclude(String command,
- Collection<String> expectedCompletions) {
+ private void assertCompletionsInclude(String command, Collection<String> expectedCompletions) {
Set<String> completions = interpreter.getCommandCompletions(command, false)
.stream()
.map(c -> c.getInsertion())
@@ -130,8 +126,8 @@ public class PythonCodeCompletionTest extends AbstractGhidraHeadedIntegrationTes
private void assertCharsToRemoveEqualsTo(String command, int expectedCharsToRemove) {
for (CodeCompletion comp : interpreter.getCommandCompletions(command, false)) {
- assertEquals(String.format("%s; field 'charsToRemove' ", comp),
- expectedCharsToRemove, comp.getCharsToRemove());
+ assertEquals(String.format("%s; field 'charsToRemove' ", comp), expectedCharsToRemove,
+ comp.getCharsToRemove());
}
}
@@ -140,7 +136,8 @@ public class PythonCodeCompletionTest extends AbstractGhidraHeadedIntegrationTes
File tempFile = tempScriptFolder.newFile();
FileUtils.writeStringToFile(tempFile, code, Charset.defaultCharset());
interpreter.execFile(new ResourceFile(tempFile), null);
- } catch (IOException e) {
+ }
+ catch (IOException e) {
fail("couldn't create a test script: " + e.getMessage());
}
}