Merge remote-tracking branch 'origin/GT-2925-dragonmacher-window-menu-key-bindings'

This commit is contained in:
Ryan Kurtz 2019-07-15 16:12:09 -04:00
commit 10372c2e13
200 changed files with 3955 additions and 3195 deletions

View file

@ -1092,6 +1092,26 @@ public abstract class AbstractGenericTest extends AbstractGTest {
runSwing(runnable, true);
}
/**
* Call this version of {@link #runSwing(Runnable)} when you expect your runnable to throw
* an exception
* @param runnable the runnable
* @param wait true signals to wait for the Swing operation to finish
* @throws Throwable any excption that is thrown on the Swing thread
*/
public static void runSwingWithExceptions(Runnable runnable, boolean wait) throws Throwable {
if (Swing.isSwingThread()) {
throw new AssertException("Unexpectedly called from the Swing thread");
}
ExceptionHandlingRunner exceptionHandlingRunner = new ExceptionHandlingRunner(runnable);
Throwable throwable = exceptionHandlingRunner.getException();
if (throwable != null) {
throw throwable;
}
}
public static void runSwing(Runnable runnable, boolean wait) {
if (SwingUtilities.isEventDispatchThread()) {
runnable.run();
@ -1115,7 +1135,6 @@ public abstract class AbstractGenericTest extends AbstractGTest {
};
SwingUtilities.invokeLater(swingExceptionCatcher);
}
protected static class ExceptionHandlingRunner {

View file

@ -303,7 +303,7 @@ public class JavaSourceFile {
if (nameAndMaybeDeclaraction.length == 2) {
return nameAndMaybeDeclaraction[0].endsWith("Action");
}
return StringUtilities.containsIgnoreCase(nameAndMaybeDeclaraction[0], "action");
return StringUtils.containsIgnoreCase(nameAndMaybeDeclaraction[0], "action");
}
private JavaSourceLine findEndOfUnknownLine(int lineNumber) {

View file

@ -348,22 +348,6 @@ public class StringUtilities {
return string.regionMatches(true, startIndex, postfix, 0, postfix.length());
}
/**
* Returns true if the given <tt>containingString</tt> contains the given
* <tt>substring</tt>, ignoring case.
*
* @param containingString the string which may contain the prefix
* @param substring the string for which to search within the containing string
* @return true if the given <tt>containingString</tt> contains the given
* <tt>substring</tt>, ignoring case.
*/
public static boolean containsIgnoreCase(String containingString, String substring) {
if ((containingString == null) || (substring == null)) {
return false;
}
return (indexOfIgnoreCase(containingString, substring, 0) >= 0);
}
/**
* Returns true if all the given <tt>searches</tt> are contained in the given string.
*
@ -455,61 +439,6 @@ public class StringUtilities {
return true;
}
/**
* Returns the index of the first occurrence the given <tt>substring</tt> in the given
* <tt>containingString</tt>, ignoring case to look for the substring.
* <p>
* This method is a convenience method for calling:
* <pre>
* <tt>indexOfIgnoreCase( containingString, substring, 0 );</tt>
* </pre>
* @param containingString the string which may contain the substring
* @param substring the string for which to search within the containing string
* @return index of substring within the given containing string
*/
public static int indexOfIgnoreCase(String containingString, String substring) {
if ((containingString == null) || (substring == null)) {
return -1;
}
return indexOfIgnoreCase(containingString, substring, 0);
}
/**
* Returns the index of the first occurrence the given <tt>substring</tt> in the given
* <tt>containingString</tt>, starting at the given <tt>index</tt>,
* ignoring case to look for the substring.
* <p>
* @param containingString the string which may contain the substring
* @param substring the string for which to search within the containing string
* @param index the index from which to start the comparison
* @return index of substring within the given containing string
*/
public static int indexOfIgnoreCase(String containingString, String substring, int index) {
if ((containingString == null) || (substring == null)) {
return -1;
}
return (containingString.toLowerCase().indexOf(substring.toLowerCase(), index));
}
/**
* Returns the index of the last occurrence the given <tt>substring</tt> in the given
* <tt>containingString</tt>, ignoring case to look for the substring.
* <p>
* This method is a convenience method for calling:
* <pre>
* <tt>lastIndexOfIgnoreCase( containingString, substring, 0 );</tt>
* </pre>
* @param containingString the string which may contain the substring
* @param substring the string for which to search within the containing string
* @return index of substring within the given containing string
*/
public static int lastIndexOfIgnoreCase(String containingString, String substring) {
if ((containingString == null) || (substring == null)) {
return -1;
}
return (containingString.toLowerCase().lastIndexOf(substring.toLowerCase()));
}
/**
* Convert tabs in the given string to spaces.
*
@ -532,10 +461,8 @@ public class StringUtilities {
char c = str.charAt(i);
if (c == '\t') {
int nSpaces = tabSize - (linepos % tabSize);
String pad = padString("", ' ', nSpaces);
String pad = pad("", ' ', nSpaces);
buffer.append(pad);
linepos += nSpaces;
}
else {
@ -606,23 +533,6 @@ public class StringUtilities {
return padded;
}
/**
* Pads the source string to the specified length, using the filler string
* as the pad. If length is negative, left justifies the string, appending
* the filler; if length is positive, right justifies the source string.
*
* @param source the original string to pad.
* @param filler the type of characters with which to pad
* @param length the length of padding to add (0 results in no changes)
* @return the padded string
* @deprecated use {@link #pad(String, char, int)}; functionally the same, but smaller
* and more consistent name
*/
@Deprecated
public static String padString(String source, char filler, int length) {
return pad(source, filler, length);
}
/**
* Pads the source string to the specified length, using the filler string
* as the pad. If length is negative, left justifies the string, appending

View file

@ -53,6 +53,9 @@ public abstract class WeakSet<T> implements Iterable<T> {
return;
}
// Note: sadly, this code does not work with labmda's, as we cannot get the enclosing
// method/constructor
Class<? extends Object> clazz = t.getClass();
if (!clazz.isAnonymousClass()) {
return; // O.K.

View file

@ -33,6 +33,8 @@ import resources.icons.TranslateIcon;
*/
public class Icons {
public static final ImageIcon EMPTY_ICON = ResourceManager.loadImage("images/EmptyIcon16.gif");
public static final ImageIcon ADD_ICON = ResourceManager.loadImage("images/Plus2.png");
public static final ImageIcon COLLAPSE_ALL_ICON =

View file

@ -17,10 +17,8 @@ package ghidra.util;
import static ghidra.util.HTMLUtilities.HTML;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.awt.Color;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
@ -53,7 +51,7 @@ public class HTMLUtilitiesTest {
String s = "This text has<BR>an existing BR tag";
String html = HTMLUtilities.toHTML(s);
assertEquals(HTML + s, html);
assertLogMessage("cannot", "wrap");
spyLogger.assertLogMessage("cannot", "wrap");
}
@Test
@ -61,7 +59,7 @@ public class HTMLUtilitiesTest {
String s = "This text has<BR>\nan existing BR tag and a newline";
String html = HTMLUtilities.toHTML(s);
assertEquals(HTML + s, html);
assertLogMessage("cannot", "wrap");
spyLogger.assertLogMessage("cannot", "wrap");
}
@Test
@ -140,16 +138,6 @@ public class HTMLUtilitiesTest {
assertEquals("#FF0000", rgb);
}
private void assertLogMessage(String... words) {
for (String message : spyLogger) {
if (StringUtilities.containsAllIgnoreCase(message, words)) {
return;
}
}
fail("Did not find log message containing all these words: " + Arrays.toString(words));
}
@Test
public void testLinkPlaceholder() {
String placeholderStr =

View file

@ -94,26 +94,6 @@ public class StringUtilitiesTest {
assertEquals(-1, StringUtilities.indexOfWord(sentenceWithTestNotAsAWord, word));
}
@Test
public void testLastIndexOfIgnoresCase() {
String bob = "bob";
String endsWithBob = "endsWithBob";
assertEquals(8, StringUtilities.lastIndexOfIgnoreCase(endsWithBob, bob));
String endsWithBobUpperCase = "endsWithBOB";
assertEquals(8, StringUtilities.lastIndexOfIgnoreCase(endsWithBobUpperCase, bob));
String startsWithBob = "bobWithTrailingText";
assertEquals(0, StringUtilities.lastIndexOfIgnoreCase(startsWithBob, bob));
String justBob = "bOb";
assertEquals(0, StringUtilities.lastIndexOfIgnoreCase(justBob, bob));
String manyBobs = "This is a string, bob, that has bob, many bobs...and then some text";
assertEquals(42, StringUtilities.lastIndexOfIgnoreCase(manyBobs, bob));
}
@Test
public void testIsAllBlank() {