f) {
+ assertNotNull("Program cannot be null", program);
+
+ R result = null;
+ boolean commit = false;
+ int tx = program.startTransaction("Test");
+ try {
+ result = f.apply(program);
+ commit = true;
+ }
+ catch (Exception e) {
+ failWithException("Exception modifying program '" + program.getName() + "'", e);
+ }
+ finally {
+ program.endTransaction(tx, commit);
+ }
+ return result;
+ }
+
/**
* Undo the last transaction on the domain object and wait for all events to be flushed.
* @param dobj The domain object upon which to perform the undo.
@@ -371,6 +445,7 @@ public abstract class AbstractGhidraHeadlessIntegrationTest extends AbstractDock
*
* @param program the program to search.
* @param name the name of the symbol to find.
+ * @param namespace the parent namespace; may be null
* @return the symbol with the given name if and only if it is the only one in that namespace
*/
public Symbol getUniqueSymbol(Program program, String name, Namespace namespace) {
@@ -389,6 +464,8 @@ public abstract class AbstractGhidraHeadlessIntegrationTest extends AbstractDock
* sleeping.
*
* Do not leave this call in your test when committing changes.
+ * @param p the program
+ * @param address the address
*
* @throws Exception if there is an issue create a {@link TestEnv}
*/
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractProgramBasedTest.java b/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractProgramBasedTest.java
index 21056f04a8..790bbacdbe 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractProgramBasedTest.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/AbstractProgramBasedTest.java
@@ -25,6 +25,8 @@ import org.junit.After;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
import ghidra.framework.plugintool.PluginTool;
+import ghidra.generic.function.ExceptionalConsumer;
+import ghidra.generic.function.ExceptionalFunction;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.*;
import ghidra.program.util.ProgramLocation;
@@ -68,6 +70,7 @@ public abstract class AbstractProgramBasedTest extends AbstractGhidraHeadedInteg
* Override this method if you need to build your own program.
*
* @return the program to use for this test.
+ * @throws Exception if an exceptioun is thrown opening the program
*/
protected Program getProgram() throws Exception {
return env.getProgram(getProgramName());
@@ -163,13 +166,13 @@ public abstract class AbstractProgramBasedTest extends AbstractGhidraHeadedInteg
*
* @param callback the code to execute
*/
- public void modifyProgram(ExceptionalCallback callback) {
+ public void modifyProgram(ExceptionalConsumer callback) {
assertNotNull("Program cannot be null", program);
boolean commit = false;
int tx = program.startTransaction("Test");
try {
- callback.call(program);
+ callback.accept(program);
commit = true;
}
catch (Exception e) {
@@ -187,7 +190,7 @@ public abstract class AbstractProgramBasedTest extends AbstractGhidraHeadedInteg
* @param f the function for modifying the program and creating the desired result
* @return the result
*/
- public R createInProgram(ExceptionalFunction f) {
+ public R createInProgram(ExceptionalFunction f) {
assertNotNull("Program cannot be null", program);
R result = null;
@@ -205,18 +208,4 @@ public abstract class AbstractProgramBasedTest extends AbstractGhidraHeadedInteg
}
return result;
}
-
-//==================================================================================================
-// Inner Classes
-//==================================================================================================
-
- // TODO promote this functional interface (do this later; there is an outstanding branch
- // that has other functional interfaces with which to fraternize)
- public interface ExceptionalCallback {
- public void call(T t) throws Exception;
- }
-
- public interface ExceptionalFunction {
- public R apply(T t) throws Exception;
- }
}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/generic/function/ExceptionalCallback.java b/Ghidra/Framework/Generic/src/main/java/ghidra/generic/function/ExceptionalCallback.java
new file mode 100644
index 0000000000..36741294d9
--- /dev/null
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/generic/function/ExceptionalCallback.java
@@ -0,0 +1,33 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.generic.function;
+
+/**
+ * A generic functional interface that is more semantically sound than {@link Runnable}. Use
+ * anywhere you wish to have a generic callback function and you need to throw an exception.
+ *
+ * @param the exception of your choice
+ */
+@FunctionalInterface
+public interface ExceptionalCallback {
+
+ /**
+ * The method that will be called
+ *
+ * @throws Exception if the call throws an exception
+ */
+ public void call() throws E;
+}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/generic/function/ExceptionalConsumer.java b/Ghidra/Framework/Generic/src/main/java/ghidra/generic/function/ExceptionalConsumer.java
new file mode 100644
index 0000000000..f39088f0a9
--- /dev/null
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/generic/function/ExceptionalConsumer.java
@@ -0,0 +1,35 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.generic.function;
+
+/**
+ * A generic functional interface that allows you to consume an item and potentially throw
+ * an exception.
+ *
+ * @param the input type
+ * @param the exception of your choice
+ */
+@FunctionalInterface
+public interface ExceptionalConsumer {
+
+ /**
+ * The method that will be called
+ *
+ * @param t the input
+ * @throws E if the call throws an exception
+ */
+ public void accept(T t) throws E;
+}
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/generic/function/ExceptionalFunction.java b/Ghidra/Framework/Generic/src/main/java/ghidra/generic/function/ExceptionalFunction.java
new file mode 100644
index 0000000000..82a0f2324d
--- /dev/null
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/generic/function/ExceptionalFunction.java
@@ -0,0 +1,37 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.generic.function;
+
+/**
+ * A generic functional interface that allows you to consume an item, return a result,
+ * and potentially throw an exception.
+ *
+ * @param the input type
+ * @param the result type
+ * @param the exception of your choice
+ */
+@FunctionalInterface
+public interface ExceptionalFunction {
+
+ /**
+ * The method that will be called
+ *
+ * @param i the input
+ * @return the result of the call
+ * @throws E if the call throws an exception
+ */
+ public R apply(I i) throws E;
+}
From e82796a4aab0fa4504b930b8304227e30e60e523 Mon Sep 17 00:00:00 2001
From: dragonmacher <48328597+dragonmacher@users.noreply.github.com>
Date: Wed, 1 May 2019 18:29:50 -0400
Subject: [PATCH 2/3] GT-2732 - Hovers - fixup to escape data
---
.../app/plugin/core/hover/AbstractReferenceHover.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/hover/AbstractReferenceHover.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/hover/AbstractReferenceHover.java
index 9f29269890..c836ee0d3f 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/hover/AbstractReferenceHover.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/hover/AbstractReferenceHover.java
@@ -211,7 +211,9 @@ public abstract class AbstractReferenceHover extends AbstractConfigurableHover {
String newline = HTMLUtilities.HTML_NEW_LINE;
StringBuilder buffy = new StringBuilder(HTML);
buffy.append("Address: ");
- buffy.append(location.getAddress().toString(true, false));
+ String addressString = location.getAddress().toString(true, false);
+ addressString = HTMLUtilities.friendlyEncodeHTML(addressString);
+ buffy.append(addressString);
buffy.append(newline);
Program p = location.getProgram();
@@ -224,7 +226,9 @@ public abstract class AbstractReferenceHover extends AbstractConfigurableHover {
SymbolInspector inspector = new SymbolInspector(tool, null);
for (Symbol s : symbols) {
ColorAndStyle style = inspector.getColorAndStyle(s);
- String html = style.toHtml(s.getName(true));
+ String name = s.getName(true);
+ name = HTMLUtilities.friendlyEncodeHTML(pad);
+ String html = style.toHtml(name);
buffy.append(pad).append(html).append(newline);
}
}
From cee63184d00297d8b1f0210e3ffbdc91c7a30011 Mon Sep 17 00:00:00 2001
From: dragonmacher <48328597+dragonmacher@users.noreply.github.com>
Date: Thu, 2 May 2019 11:02:35 -0400
Subject: [PATCH 3/3] GT-2732 - Hovers - review fixes
---
.../Base/src/main/java/ghidra/app/util/ColorAndStyle.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/ColorAndStyle.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/ColorAndStyle.java
index 22cfe39889..fa2080cb90 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/ColorAndStyle.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/ColorAndStyle.java
@@ -59,10 +59,10 @@ public class ColorAndStyle {
public String toHtml(String text) {
String html = text;
- if (style == Font.BOLD) {
+ if (isBold()) {
html = HTMLUtilities.bold(html);
}
- if (style == Font.ITALIC) {
+ if (isItalic()) {
html = HTMLUtilities.italic(html);
}