From 6c607f221091975a0405b772d262a6d3af77f746 Mon Sep 17 00:00:00 2001 From: Pieter12345 Date: Mon, 30 Apr 2018 17:25:57 +0200 Subject: [PATCH 1/7] Formatting: pom.xml Made Tab/whitespace usage consistent. --- pom.xml | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 57e65d5a87..a130e58c3e 100644 --- a/pom.xml +++ b/pom.xml @@ -198,12 +198,14 @@ - + @@ -305,13 +307,13 @@ jchardet 1.0 - - - - org.apache.oltu.oauth2 - org.apache.oltu.oauth2.client - 1.0.2 - + + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.client + 1.0.2 + @@ -488,7 +490,7 @@ - + @@ -503,13 +505,13 @@ shade - true - full - false - From d74d3159598f9d4346b42c9d57145f4da07b521c Mon Sep 17 00:00:00 2001 From: Pieter12345 Date: Mon, 30 Apr 2018 21:01:54 +0200 Subject: [PATCH 2/7] Added checkstyle. - Added maven's checkstyle plugin (applies to main and test .java files). - Added a check for line length <= 120 (currently marked as ignored due to >7000 violations). - Disallow whitespace indents (force TABs). - Disallow star imports (import blabla.*). - Disallow empty blocks ({}). - Disallow trailing whitespaces/tabs. --- checkstyle.xml | 38 ++++++++++++++++++++++++++++++++++++ pom.xml | 53 +++++++++++++++++++++++++++++++++++++------------- 2 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 checkstyle.xml diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000000..fb32bada19 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index a130e58c3e..6504e1f9bc 100644 --- a/pom.xml +++ b/pom.xml @@ -200,10 +200,10 @@ @@ -280,17 +280,17 @@ @@ -914,6 +914,33 @@ + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.0.0 + + + validate + validate + + ${project.compileSourceRoots} + ${project.testCompileSourceRoots} + true + ${basedir}/checkstyle.xml + UTF-8 + true + true + false + + + check + + + + + From 232db3a2ac594d2c879925a371a327b448684f16 Mon Sep 17 00:00:00 2001 From: Pieter12345 Date: Mon, 30 Apr 2018 21:07:38 +0200 Subject: [PATCH 3/7] Formatting: Disallow whitespaces. - Replaced leading 4-wide whitespaces with tabs. - Removed/replaced remaining leading whitespaces to maintain consistency. - Added *'s to multiline docs where they were missing. --- .../PureUtilities/ArgumentParser.java | 2266 ++++++++--------- .../ClassLoading/ClassMirror/ClassMirror.java | 1204 ++++----- .../com/laytonsmith/PureUtilities/Color.java | 8 +- .../PureUtilities/Common/FileUtil.java | 20 +- .../ConcurrentSingletonHashMap.java | 56 +- .../PureUtilities/ExhaustiveVisitor.java | 30 +- .../PureUtilities/PropertiesManager.java | 12 +- .../laytonsmith/PureUtilities/TermColors.java | 8 +- .../PureUtilities/UI/TextDialog.java | 124 +- .../VirtualFS/FileSystemLayer.java | 76 +- .../laytonsmith/PureUtilities/ZipReader.java | 4 +- .../laytonsmith/PureUtilities/rParser.java | 4 +- .../abstraction/MCInventoryHolder.java | 2 +- .../laytonsmith/abstraction/MCItemMeta.java | 198 +- .../abstraction/bukkit/BukkitConvertor.java | 50 +- .../BukkitDirtyRegisteredListener.java | 286 +-- .../com/laytonsmith/core/CoreProfile.java | 20 +- .../com/laytonsmith/core/GenericTree.java | 8 +- .../com/laytonsmith/core/GenericTreeNode.java | 4 +- .../core/GenericTreeTraversalOrderEnum.java | 4 +- .../core/MethodScriptCompiler.java | 2 +- .../core/compiler/FileOptions.java | 2 +- .../laytonsmith/core/constructs/CSymbol.java | 36 +- .../laytonsmith/core/constructs/Token.java | 18 +- .../core/events/AbstractEvent.java | 8 +- .../laytonsmith/core/events/BoundEvent.java | 40 +- .../laytonsmith/core/events/EventBuilder.java | 6 +- .../exceptions/ConfigRuntimeException.java | 12 +- .../core/functions/DataHandling.java | 22 +- .../com/laytonsmith/core/functions/Debug.java | 674 ++--- .../core/functions/Enchantments.java | 62 +- .../core/functions/EventBinding.java | 8 +- .../core/functions/InventoryManagement.java | 90 +- .../com/laytonsmith/core/functions/Regex.java | 8 +- .../com/laytonsmith/tools/UILauncher.java | 136 +- .../laytonsmith/tools/docgen/DocGenUI.java | 368 +-- .../tools/docgen/SingleFunctionDialog.java | 110 +- .../tools/docgen/sitedeploy/SiteDeploy.java | 18 +- .../pnviewer/ConfigurationLoaderDialog.java | 296 +-- .../tools/pnviewer/ManageBookmarksDialog.java | 318 +-- .../laytonsmith/tools/pnviewer/PNViewer.java | 476 ++-- .../ClassLoading/GeneralTest.java | 12 +- .../PureUtilities/ZipMakerTest.java | 18 +- .../PureUtilities/ZipReaderTest.java | 12 +- .../core/MethodScriptCompilerTest.java | 208 +- .../core/NewExceptionHandlingTest.java | 2 +- .../laytonsmith/core/OptimizationTest.java | 72 +- .../java/com/laytonsmith/core/ScriptTest.java | 174 +- .../com/laytonsmith/core/TypeHintingTest.java | 54 +- .../laytonsmith/core/events/GeneralTest.java | 76 +- .../core/functions/BasicLogicTest.java | 30 +- .../core/functions/DataHandlingTest.java | 20 +- .../core/functions/EchoesTest.java | 22 +- .../core/functions/MinecraftTest.java | 34 +- .../core/functions/PermissionsTest.java | 112 +- .../core/functions/PlayerManangementTest.java | 62 +- .../functions/bash/BashCompilerBasicTest.java | 22 +- .../persistence/TestPersistence.java | 8 +- .../com/laytonsmith/testing/ArrayTest.java | 4 +- .../com/laytonsmith/testing/RandomTests.java | 12 +- .../com/laytonsmith/testing/StaticTest.java | 52 +- 61 files changed, 4048 insertions(+), 4052 deletions(-) diff --git a/src/main/java/com/laytonsmith/PureUtilities/ArgumentParser.java b/src/main/java/com/laytonsmith/PureUtilities/ArgumentParser.java index 3a4b8c59cc..e7aefcea40 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/ArgumentParser.java +++ b/src/main/java/com/laytonsmith/PureUtilities/ArgumentParser.java @@ -14,1137 +14,1137 @@ */ public class ArgumentParser { - /** - * A description of the command itself. - */ - String description = ""; - List argumentModel = new ArrayList(); - - /** - * Returns the default argument, if it exists. - * - * @return - */ - private Argument getArgument() { - for (Argument a : argumentModel) { - if (a.shortArg == null && a.longArg == null) { - return a; - } - } - return null; - } - - private Argument getArgument(Character c) { - for (Argument a : argumentModel) { - if (a.shortArg == null) { - continue; - } - if (a.shortArg.equals(c)) { - return a; - } - } - return null; - } - - private Argument getArgument(String s) { - for (Argument a : argumentModel) { - if (a.longArg == null) { - continue; - } - if (a.longArg.equals(s)) { - return a; - } - } - return null; - } - - private class Argument { - - Character shortArg; - String longArg; - Type argType; - String defaultVal; - List defaultList; - String description; - String usageName; - boolean required; - String singleVal; - List arrayVal; - - private Argument(Argument arg) { - if (arg == null) { - return; - } - this.shortArg = arg.shortArg; - this.longArg = arg.longArg; - this.argType = arg.argType; - this.defaultVal = arg.defaultVal; - this.description = arg.description; - this.usageName = arg.usageName; - this.required = arg.required; - } - - private Argument(Character shortArg, String longArg, Type argType, String defaultVal, String description, String usageName, boolean required) { - this.shortArg = shortArg; - this.longArg = longArg; - this.argType = argType; - this.description = description; - - this.defaultVal = defaultVal; - if (isArray() && defaultVal != null) { - defaultList = ArgumentParser.this.lex(defaultVal); - } - this.usageName = usageName; - this.required = required; - } - - public final boolean isFlag() { - return argType == Type.BOOLEAN; - } - - public final boolean isArray() { - return argType == Type.ARRAY_OF_NUMBERS || argType == Type.ARRAY_OF_STRINGS; - } - - public final boolean isSingle() { - return argType == Type.NUMBER || argType == Type.STRING; - } - - public final boolean isNumeric() { - return argType == Type.NUMBER || argType == Type.ARRAY_OF_NUMBERS; - } - - private void setValue(String val) { - if (isArray()) { - arrayVal = ArgumentParser.this.lex(val); - } else { - singleVal = val; - } - } - - private void setValue(List val) { - arrayVal = new ArrayList<>(val); - } - - public boolean modelEquals(Argument obj) { - if (this.shortArg != null) { - return this.shortArg.equals(obj.shortArg); - } else if (this.longArg != null) { - return this.longArg.equals(obj.longArg); - } else { - return obj.shortArg == null && obj.longArg == null; - } - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder(); - if (longArg != null && shortArg != null) { - b.append("--").append(longArg).append("/").append("-").append(shortArg); - } else if (longArg != null) { - b.append("--").append(longArg); - } else if (shortArg != null) { - b.append("-").append(shortArg); - } - b.append(": "); - if (isSingle()) { - b.append(singleVal); - } else if (isArray()) { - boolean first = true; - b.append("["); - for (String s : arrayVal) { - if (!first) { - b.append(", "); - } - first = false; - b.append("\"").append(s.replaceAll("\"", "\\\"")).append("\""); - } - b.append("]"); - } - b.append("\n"); - return b.toString(); - } - - private String generateDescription(boolean shortCode) { - StringBuilder b = new StringBuilder(); - b.append("\t"); - if (shortArg == null && longArg == null) { - //Default argument - b.append("<").append(usageName).append(">: ").append(description).append("\n"); - } else { - //If short code is false, we need to check to see if there is a short code, if so, - //this is an alias. - if (shortCode) { - b.append("-").append(shortArg); - } else { - b.append("--").append(longArg); - } - b.append(": "); - - if (!shortCode && shortArg != null) { - //Alias - b.append("Alias to -").append(shortArg); - } else { - if (argType != Type.BOOLEAN) { - if (required) { - b.append("Required. "); - } else { - b.append("Optional. "); - } - } - if (argType == Type.NUMBER) { - b.append("A numeric value. "); - } - if (argType == Type.ARRAY_OF_NUMBERS) { - b.append("A list of numbers. "); - } - if (argType == Type.ARRAY_OF_STRINGS) { - b.append("A list. "); - } - b.append(description.replaceAll("\n", "\n\t\t")); - } - b.append("\n"); - } - return b.toString(); - } - } - - private ArgumentParser() { - } - - public static class ValidationException extends Exception { - - private ValidationException(String string) { - super(string); - } - } - - public static class ResultUseException extends RuntimeException { - - ResultUseException(String string) { - super(string); - } - } - - public class ArgumentParserResults { - - List arguments = new ArrayList(); - - private void updateArgument(Argument a) { - if (a == null) { - return; - } - List toRemove = new ArrayList(); - for (Argument arg : arguments) { - if (arg.modelEquals(a)) { - toRemove.add(arg); - } - } - for (Argument arg : toRemove) { - arguments.remove(arg); - } - arguments.add(a); - } - - /** - * Returns true if the flag represented by this short code is set. - * - * @param flag - * @return - */ - public boolean isFlagSet(Character flag) { - return getArg(flag) != null; - } - - /** - * Returns true is the flag represented by this long code is set. - * - * @param flag - * @return - */ - public boolean isFlagSet(String flag) { - return getArg(flag) != null; - } - - /** - * Gets the unassociated arguments passed in as a String. For instance, - * if the arguments were These are arguments, then "These - * are arguments" will be returned. However, assuming -c is registered - * as a single string type, and the arguments are - * -c These are arguments, then only "are arguments" is - * returned. This will return an empty string if no arguments were set. - * - * @return - */ - public String getStringArgument() { - try { - Argument a = getArg(); - if (a.arrayVal == null) { - return ""; - } - StringBuilder b = new StringBuilder(); - boolean first = true; - for (String val : a.arrayVal) { - if (!first) { - b.append(" "); - } - first = false; - b.append(val); - } - return b.toString(); - } catch (ResultUseException e) { - return ""; - } - } - - /** - * Returns the string associated with the switch represented by this - * short code. If the switch wasn't set, null is returned. - * - * @param flag - * @return - * @throws ArgumentParser.ResultUseException - */ - public String getStringArgument(Character flag) throws ResultUseException { - return getStringArgument(getArg(flag)); - } - - /** - * Returns the string associated with the switch represented by this - * long code. If the switch wasn't set, null is returned. - * - * @param flag - * @return - * @throws ArgumentParser.ResultUseException - */ - public String getStringArgument(String flag) throws ResultUseException { - return getStringArgument(getArg(flag)); - } - - private String getStringArgument(Argument arg) { - if (arg == null) { - return null; - } - if (arg.argType != Type.STRING) { - throw new ClassCastException("Argument type not set to " + Type.STRING.name() + ". Cannot return a " + "string" + "."); - } - return arg.singleVal; - } - - /** - * Returns the value associated with the switch represented by this - * short code, pre-parsed as a double. If the switch wasn't set, null is - * returned. - * - * @param flag - * @return - * @throws ResultUseException, NumberFormatException - */ - public Double getNumberArgument(Character flag) throws ResultUseException { - return getNumberArgument(getArg(flag)); - } - - /** - * Returns the value associated with the switch represented by this long - * code, pre-parsed as a double. If the switch wasn't set, null is - * returned. - * - * @param flag - * @return - * @throws ResultUseException, NumberFormatException - */ - public Double getNumberArgument(String flag) throws ResultUseException { - return getNumberArgument(getArg(flag)); - } - - private Double getNumberArgument(Argument arg) { - if (arg == null) { - return null; - } - if (arg.argType != Type.NUMBER) { - throw new ClassCastException("Argument type not set to " + Type.NUMBER.name() + ". Cannot return a " + "number" + "."); - } - return Double.parseDouble(arg.singleVal); - } - - /** - * Gets the unassociated arguments passed in as a List of Strings. For - * instance, if the arguments were These are arguments, - * then ["These", "are", "arguments"] will be returned. However, - * assuming -c is registered as a single string type, and the arguments - * are -c These are arguments, then only ["are", - * "arguments"] is returned. This will return an empty array if no - * arguments were set. - * - * @return - */ - public List getStringListArgument() { - try { - Argument a = getArg(); - if (a.arrayVal == null) { - return new ArrayList(); - } - return new ArrayList(a.arrayVal); - } catch (ResultUseException e) { - return new ArrayList(); - } - } - - /** - * Returns the list of values associated with the switch represented by - * this short code. If the switch wasn't set, null is returned. - * - * @param flag - * @return - * @throws ArgumentParser.ResultUseException - */ - public List getStringListArgument(Character flag) throws ResultUseException { - return getStringListArgument(getArg(flag)); - } - - /** - * Returns the list of values associated with the switch represented by - * this long code. If the switch wasn't set, null is returned. - * - * @param flag - * @return - * @throws ArgumentParser.ResultUseException - */ - public List getStringListArgument(String flag) throws ResultUseException { - return getStringListArgument(getArg(flag)); - } - - private List getStringListArgument(Argument arg) { - if (arg == null) { - return null; - } - if (arg.argType != Type.ARRAY_OF_STRINGS) { - throw new ClassCastException("Argument type not set to " + Type.ARRAY_OF_STRINGS.name() + ". Cannot return a " + "string list" + "."); - } - return new ArrayList(arg.arrayVal); - } - - /** - * Returns the list of values associated with the switch represented by - * this short code, pre-parsed into doubles. If the switch wasn't set, - * null is returned. - * - * @param flag - * @return - * @throws ArgumentParser.ResultUseException - */ - public List getNumberListArgument(Character flag) throws ResultUseException { - return getNumberListArgument(getArg(flag)); - } - - /** - * Returns the list of values associated with the switch represented by - * this long code, pre-parsed into doubles. If the switch wasn't set, - * null is returned. - * - * @param flag - * @return - * @throws ArgumentParser.ResultUseException - */ - public List getNumberListArgument(String flag) throws ResultUseException { - return getNumberListArgument(getArg(flag)); - } - - private List getNumberListArgument(Argument arg) { - if (arg == null) { - return null; - } - if (arg.argType != Type.ARRAY_OF_NUMBERS) { - throw new ClassCastException("Argument type not set to " + Type.ARRAY_OF_NUMBERS.name() + ". Cannot return a " + "number list" + "."); - } - - List list = new ArrayList(); - for (String s : arg.arrayVal) { - list.add(Double.parseDouble(s)); - } - return list; - } - - private Argument getArg() { - for (Argument a : arguments) { - if (a.shortArg == null && a.longArg == null) { - return a; - } - } - return new Argument(ArgumentParser.this.getArgument()); - } - - private Argument getArg(Character flag) throws ResultUseException { - for (Argument a : arguments) { - if (a.shortArg == null) { - continue; - } - if (a.shortArg.equals(flag)) { - return a; - } - } - return null; - } - - private Argument getArg(String flag) throws ResultUseException { - for (Argument a : arguments) { - if (a.longArg == null) { - continue; - } - if (a.longArg.equals(flag)) { - return a; - } - } - return null; - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder(); - for (Argument arg : arguments) { - if (arg.isFlag()) { - b.append("Flag "); - if (arg.longArg != null && arg.shortArg != null) { - b.append("--").append(arg.longArg).append("/").append("-").append(arg.shortArg); - } else if (arg.longArg != null) { - b.append("--").append(arg.longArg); - } else if (arg.shortArg != null) { - b.append("-").append(arg.shortArg); - } - b.append(" is set.\n"); - } else { - b.append(arg.toString()); - } - } - return b.toString(); - } - } - - public static ArgumentParser GetParser() { - return new ArgumentParser(); - } - - public static enum Type { - - STRING, - NUMBER, - ARRAY_OF_STRINGS, - ARRAY_OF_NUMBERS, - BOOLEAN - } - - private ArgumentParser addArgument0(Character shortArg, String longArg, Type argType, String defaultVal, String description, String usageName, boolean required) { - //TODO: Make sure this switch doesn't already exist - argumentModel.add(new Argument(shortArg, longArg, argType, defaultVal, description, usageName, required)); - return this; - } - - /** - * Adds an argument to this argument parser. This is the most complex method - * of adding an argument, all other methods are wrappers around this. - * - * The short code and long code for a switch both represent the underlying - * switch, that is, they both "addresses" of a single underlying switch. - * When accessing the argument later, you may use either the short code or - * the long code to retrieve the value of the switch, but it is important to - * understand that they are both pointing to the same item. - * - * @param shortArg The short code for this switch. - * @param longArg The long code for this switch. - * @param argType The expected type of this switch. - * @param defaultVal The default value of this switch. If defaultVal is not - * null, the switch will always exist when calling get*Argument from the - * results. If argType is BOOLEAN, setting this will cause the switch to - * @param description The description of this argument, which is used when - * building the help text created by getBuiltDescription. - * @return - */ - public ArgumentParser addArgument(Character shortArg, String longArg, Type argType, String defaultVal, String description, String usageName, boolean required) { - if (argType == Type.BOOLEAN) { - throw new IllegalArgumentException("Cannot use addArgument to add a flag. Use addFlag instead."); - } - if (shortArg == null && longArg == null) { - if (argType != Type.STRING && argType != Type.ARRAY_OF_STRINGS) { - throw new IllegalArgumentException("Cannot set the type of the default switch to anything but " + Type.STRING.name() + " or " - + Type.ARRAY_OF_STRINGS.name()); - } - } - return addArgument0(shortArg, longArg, argType, defaultVal, description, usageName, required); - } - - /** - * Sets the default switch's arg type, default value, and description. The - * default switch is the switch that is associated with "loose" arguments, - * for instance, these are args would all be loose arguments, - * because they aren't associated with any explicit switches. Note that - * there is no Type specified here, that's because the arguments can be - * grabbed as either an array of strings or a string. - * - * @param argType - * @param defaultVal - * @param description - * @return - */ - public ArgumentParser addArgument(String defaultVal, String description, String usageName, boolean required) { - return addArgument(null, null, Type.ARRAY_OF_STRINGS, defaultVal, description, usageName, required); - } - - /** - * Sets the default switch with no default value. - * - * @param argType - * @param description - * @return - */ - public ArgumentParser addArgument(String description, String usageName, boolean required) { - return addArgument(null, null, Type.ARRAY_OF_STRINGS, null, description, usageName, required); - } - - /** - * Adds a new argument with no default value. - * - * @param shortArg - * @param longArg - * @param argType - * @param description - * @return - */ - public ArgumentParser addArgument(Character shortArg, String longArg, Type argType, String description, String usageName, boolean required) { - return addArgument(shortArg, longArg, argType, null, description, usageName, required); - } - - /** - * Adds a new argument with no long code. - * - * @param shortArg - * @param argType - * @param defaultVal - * @param description - * @return - */ - public ArgumentParser addArgument(Character shortArg, Type argType, String defaultVal, String description, String usageName, boolean required) { - return addArgument(shortArg, null, argType, defaultVal, description, usageName, required); - } - - /** - * Adds a new argument with no short code. - * - * @param longArg - * @param argType - * @param defaultVal - * @param description - * @return - */ - public ArgumentParser addArgument(String longArg, Type argType, String defaultVal, String description, String usageName, boolean required) { - return addArgument(null, longArg, argType, defaultVal, description, usageName, required); - } - - /** - * Adds a new argument with no long code, and no default value. - * - * @param shortArg - * @param argType - * @param description - * @return - */ - public ArgumentParser addArgument(Character shortArg, Type argType, String description, String usageName, boolean required) { - return addArgument(shortArg, null, argType, null, description, usageName, required); - } - - /** - * Adds a new argument with no short code, and no default value. - * - * @param longArg - * @param argType - * @param description - * @return - */ - public ArgumentParser addArgument(String longArg, Type argType, String description, String usageName, boolean required) { - return addArgument(null, longArg, argType, null, description, usageName, required); - } - - /** - * Adds a new flag. - * - * @param shortArg - * @param longArg - * @param description - * @return - */ - public ArgumentParser addFlag(Character shortArg, String longArg, String description) { - return addArgument0(shortArg, longArg, Type.BOOLEAN, null, description, null, false); - } - - /** - * Adds a new flag with no short code. - * - * @param longArg - * @param description - * @return - */ - public ArgumentParser addFlag(String longArg, String description) { - return addArgument0(null, longArg, Type.BOOLEAN, null, description, null, false); - } - - /** - * Adds a new flag with no long code. - * - * @param shortArg - * @param description - * @return - */ - public ArgumentParser addFlag(Character shortArg, String description) { - return addArgument0(shortArg, null, Type.BOOLEAN, null, description, null, false); - } - - /** - * Adds a description to the ArgumentParser object, which is used when - * building the description returned by getBuiltDescription. - * - * @param description - * @return - */ - public ArgumentParser addDescription(String description) { - this.description = description; - return this; - } - - /** - * Builds a description of this ArgumentParser, which may be useful as - * "Usage" text to provide to a user if a call to match throws a - * ValidationException, for instance. - * - * @return - */ - public String getBuiltDescription() { - StringBuilder b = new StringBuilder(); - //Now, we need to go through and get all the switch names in alphabetical - //order. - b.append("\t").append(this.description).append("\n\n"); - List shortCodes = new ArrayList(); - List longCodes = new ArrayList(); - List shortCodesDone = new ArrayList(); - List longCodesDone = new ArrayList(); - List aliases = new ArrayList(); - for (Argument arg : argumentModel) { - if (arg.shortArg != null) { - shortCodes.add(arg.shortArg); - } - if (arg.longArg != null) { - longCodes.add(arg.longArg); - } - if (arg.shortArg != null && arg.longArg != null) { - aliases.add(arg.longArg); - } - } - Collections.sort(shortCodes); - Collections.sort(longCodes); - //Go through the flags first - boolean hasShortCodeFlags = false; - StringBuilder flags = new StringBuilder(); - List shortFlags = new ArrayList(); - List longFlags = new ArrayList(); - List shortArguments = new ArrayList(); - List longArguments = new ArrayList(); - for (Character c : shortCodes) { - Argument a = getArgument(c); - if (a.isFlag()) { - shortCodesDone.add(c); - flags.append(a.generateDescription(true)); - hasShortCodeFlags = true; - shortFlags.add(c); - } else { - shortArguments.add(c); - } - } - - for (String s : longCodes) { - Argument a = getArgument(s); - if (a.isFlag()) { - longCodesDone.add(s); - flags.append(a.generateDescription(false)); - if (!aliases.contains(s)) { - longFlags.add(s); - } - } else if (!aliases.contains(s)) { - longArguments.add(s); - } - } - - b.append("Usage:\n\t"); - //Get the short flags first, then the long flags, then the short arguments, then the long arguments - List parts = new ArrayList(); - if (!shortFlags.isEmpty()) { - StringBuilder usage = new StringBuilder(); - usage.append("[-"); - for (Character c : shortFlags) { - usage.append(c); - } - usage.append("]"); - parts.add(usage.toString()); - } - - for (String s : longFlags) { - parts.add("[--" + s + "]"); - } - - List usageList = new ArrayList(); - for (Character c : shortArguments) { - usageList.add(getArgument(c)); - } - for (String s : longArguments) { - usageList.add(getArgument(s)); - } - for (Argument a : usageList) { - StringBuilder usage = new StringBuilder(); - if (!a.required) { - usage.append("["); - } - if (a.shortArg != null) { - usage.append("-").append(a.shortArg); - } else { - usage.append("--").append(a.longArg); - } - usage.append(" <"); - if (a.isNumeric()) { - usage.append("#"); - } - usage.append(a.usageName); - if (a.isArray()) { - usage.append(", ..."); - } - usage.append(">"); - - if (a.defaultVal != null && !"".equals(a.defaultVal)) { - usage.append(" (default "); - if (a.argType == Type.STRING) { - usage.append("\""); - } - usage.append(a.defaultVal); - if (a.argType == Type.STRING) { - usage.append("\""); - } - usage.append(")"); - } - - if (!a.required) { - usage.append("]"); - } - parts.add(usage.toString()); - } - - //Now, if the default switch exists, put it here too - if (getArgument() != null) { - parts.add("<" + getArgument().usageName + ", ...>"); - } - - { - StringBuilder usage = new StringBuilder(); - boolean first = true; - for (String part : parts) { - if (!first) { - b.append(" "); - } - first = false; - b.append(part); - } - if (parts.isEmpty()) { - usage.append("No arguments."); - } - b.append(usage.toString()); - } - b.append("\n\nOptions:\n\n"); - Argument def = getArgument(); - if (def != null && def.description != null) { - b.append(def.generateDescription(false)); - } - - if (flags.length() != 0) { - b.append("Flags"); - if (hasShortCodeFlags) { - b.append(" (Short flags may be combined)"); - } - b.append(":\n"); - b.append(flags.toString()); - b.append("\n"); - } - - if (shortCodes.isEmpty() && longCodes.isEmpty() && def == null && flags.length() == 0) { - b.append("\tNo flags or options.\n"); - } else { - if (shortCodes.isEmpty() && longCodes.isEmpty() && def == null) { - b.append("\tNo options.\n"); - } else if (flags.length() == 0) { - b.append("\tNo flags.\n"); - } - } - - for (Character c : shortCodes) { - if (!shortCodesDone.contains(c)) { - b.append(getArgument(c).generateDescription(true)); - } - } - for (String s : longCodes) { - if (!longCodesDone.contains(s)) { - b.append(getArgument(s).generateDescription(false)); - } - } - return b.toString(); - } - - /** - * Returns just the description that was registered with { - * - * @see #addDescription(String)}. - * @return The description, or null, if one has not been set yet. - * @see #getBuiltDescription() - */ - public String getDescription() { - return description; - } - - /** - * This method takes a raw string, which represents the arguments as a - * single string. It supports quoted arguments (both single and double), so - * "this example" would make the string "this example" one argument instead - * of two. Quotes may be escaped with a backslash, like so: "\"quote\"". - * Also, all arguments that start with a dash are considered flags, if you - * need a literal dash, escape it with a backslash too, \-. Instead of - * quoting arguments, you could also add a \ in front of a space to make it - * a literal space, like\ this. Within a string, to add a - * literal backslash in front of an otherwise escapable character, use two - * backslashes "like this\\" - * - * @param args - * @return - */ - public ArgumentParserResults match(String args) throws ValidationException { - return parse(lex(args)); - } - - /** - * Returns a simple List of the arguments, parsed into a proper argument - * list. This will work essentially identically to how general shell - * arguments are parsed. - * - * @param args - * @return - */ - static List lex(String args) { - //First, we have to tokenize the strings. Since we can have quoted arguments, we can't simply split on spaces. - List arguments = new ArrayList(); - StringBuilder buf = new StringBuilder(); - boolean state_in_single_quote = false; - boolean state_in_double_quote = false; - for (int i = 0; i < args.length(); i++) { - Character c0 = args.charAt(i); - Character c1 = i + 1 < args.length() ? args.charAt(i + 1) : null; - - if (c0 == '\\') { - if (c1 == '\'' && state_in_single_quote - || c1 == '"' && state_in_double_quote - || c1 == ' ' && !state_in_double_quote && !state_in_single_quote - || c1 == '\\' && (state_in_double_quote || state_in_single_quote)) { - //We are escaping the next character. Add it to the buffer instead, and - //skip ahead two - buf.append(c1); - i++; - continue; - } - - } - - if (c0 == ' ') { - if (!state_in_double_quote && !state_in_single_quote) { - //argument split - if (buf.length() != 0) { - arguments.add(buf.toString()); - buf = new StringBuilder(); - } - continue; - } - } - if (c0 == '\'' && !state_in_double_quote) { - if (state_in_single_quote) { - state_in_single_quote = false; - arguments.add(buf.toString()); - buf = new StringBuilder(); - } else { - if (buf.length() != 0) { - arguments.add(buf.toString()); - buf = new StringBuilder(); - } - state_in_single_quote = true; - } - continue; - } - if (c0 == '"' && !state_in_single_quote) { - if (state_in_double_quote) { - state_in_double_quote = false; - arguments.add(buf.toString()); - buf = new StringBuilder(); - } else { - if (buf.length() != 0) { - arguments.add(buf.toString()); - buf = new StringBuilder(); - } - state_in_double_quote = true; - } - continue; - } - buf.append(c0); - } - if (buf.length() != 0) { - arguments.add(buf.toString()); - } - return arguments; - } - - private ArgumentParserResults parse(List args) throws ValidationException { - ArgumentParserResults results = new ArgumentParserResults(); - //Fill in results with all the defaults - for (Argument arg : argumentModel) { - if (arg.defaultVal != null) { - //For flags, we simply don't add them if they default to false. - if (!arg.isFlag() || (arg.isFlag() && arg.defaultVal != null)) { - Argument newArg = new Argument(arg); - newArg.setValue(arg.defaultVal); - results.updateArgument(newArg); - } - } - } - //These are arguments that are not flags. - List looseArgs = new ArrayList<>(); - Argument lastArg = null; - for (String arg : args) { - if (arg.matches("^[\\\\]+-.*$")) { - //This is an argument that starts with a literal dash, but we need - //to pull out this first backslash - looseArgs.add(arg.substring(1)); - continue; - } - - //Our regexes have a star, because -(-) is a valid argument that is an empty string. - //"" != null. - if (arg.matches("--[a-zA-Z0-9\\-]*")) { - //Finish up the last argument - results.updateArgument(validateArgument(lastArg, looseArgs)); - //This is a long arg, and so it is the only one. - arg = arg.substring(2); - lastArg = getArgument(arg); - continue; - } - - if (arg.matches("-[a-zA-Z0-9]*")) { - //Finish up the last argument - results.updateArgument(validateArgument(lastArg, looseArgs)); - //This is a short arg, but it could be multiple letters (therefore multiple flags) - //At most, one of these can be a non-flag argument. - boolean hasNonFlagArg = false; - char lastNonFlag = ' '; - for (int i = 1; i < arg.length(); i++) { - Character c = arg.charAt(i); - Argument vArg = getArgument(c); - if (vArg == null) { - throw new ValidationException("Unrecognized flag: " + c); - } - if (!vArg.isFlag() && hasNonFlagArg) { - //We have already come across a non-flag argument, and since this one isn't - //a flag, we need to throw an exception. - throw new ValidationException("Cannot combine multiple non-flag arguments using the short form. Found '" + c - + "' but had already found '" + lastNonFlag + "'. You must split these into multiple arguments, even if they" - + " do not have any parameters, for instance, -" + c + " -" + lastNonFlag); - } - //Is this a non flag? - if (!vArg.isFlag()) { - hasNonFlagArg = true; - lastNonFlag = c; - lastArg = vArg; - //This is all we need to do, it will be dealt with by the next iteration - } else { - //Since it's just a flag, we don't need to worry about it regarding loose arguments, so we - //are just going to go ahead and add it to the results. - results.updateArgument(vArg); - } - } - continue; - } - - //It's just a loose arg, so we'll add it to the list and deal with it at the end - looseArgs.add(arg); - } - - //Finish up the last argument - results.updateArgument(validateArgument(lastArg, looseArgs)); - if (looseArgs.size() > 0) { - //There are loose arguments left, so add them to the loose argument list. - results.updateArgument(validateArgument(null, looseArgs)); - } - //TODO: Check to see if all the required values are here - - return results; - } - - private Argument validateArgument(Argument arg, List looseArgs) throws ValidationException { - if (arg == null) { - if (!looseArgs.isEmpty()) { - //All the loose arguments are accounted for. Either we're done with the arguments, - //or we just hit a -(-)specifier, so we can stop parsing these, and go ahead and - //add them to the results. - Argument a = new Argument(ArgumentParser.this.getArgument()); - a.setValue(looseArgs); - looseArgs.clear(); - return a; - } - return null; - } - Argument finishedArgument = new Argument(arg); - if (arg.isSingle()) { - //Just the first loose argument is associated with this argument, - //the rest (if any) belong to the default loose argument list. - //Of course, looseArgs could be empty, in which case we won't add anything to the list. - if (looseArgs.size() > 0) { - String looseArg = looseArgs.get(0); - looseArgs.remove(0); - finishedArgument.setValue(looseArg); - if (arg.isNumeric()) { - try { - Double.parseDouble(looseArg); - } catch (NumberFormatException e) { - throw new ValidationException("Expecting a numeric value, but \"" + looseArg + "\" was encountered."); - } - } - } else { - finishedArgument.setValue(""); - } - } else if (arg.isArray()) { - finishedArgument.setValue(looseArgs); - if (arg.isNumeric()) { - for (String val : looseArgs) { - try { - Double.parseDouble(val); - } catch (NumberFormatException e) { - throw new ValidationException("Expecting a numeric value, but \"" + val + "\" was encountered."); - } - } - } - looseArgs.clear(); - } - return finishedArgument; - } - - /** - * This method assumes that the arguments have already been parsed out, so, - * for instance, if an argument inside of args[x] contains spaces, it will - * still be considered one argument. So, ["args with spaces", "args"] may - * have looked like this originally: "args with spaces" args - * but through some means or another, you have already parsed the arguments - * out. - * - * @param args - * @return - */ - public ArgumentParserResults match(String[] args) throws ValidationException { - return parse(Arrays.asList(args)); - } + /** + * A description of the command itself. + */ + String description = ""; + List argumentModel = new ArrayList(); + + /** + * Returns the default argument, if it exists. + * + * @return + */ + private Argument getArgument() { + for (Argument a : argumentModel) { + if (a.shortArg == null && a.longArg == null) { + return a; + } + } + return null; + } + + private Argument getArgument(Character c) { + for (Argument a : argumentModel) { + if (a.shortArg == null) { + continue; + } + if (a.shortArg.equals(c)) { + return a; + } + } + return null; + } + + private Argument getArgument(String s) { + for (Argument a : argumentModel) { + if (a.longArg == null) { + continue; + } + if (a.longArg.equals(s)) { + return a; + } + } + return null; + } + + private class Argument { + + Character shortArg; + String longArg; + Type argType; + String defaultVal; + List defaultList; + String description; + String usageName; + boolean required; + String singleVal; + List arrayVal; + + private Argument(Argument arg) { + if (arg == null) { + return; + } + this.shortArg = arg.shortArg; + this.longArg = arg.longArg; + this.argType = arg.argType; + this.defaultVal = arg.defaultVal; + this.description = arg.description; + this.usageName = arg.usageName; + this.required = arg.required; + } + + private Argument(Character shortArg, String longArg, Type argType, String defaultVal, String description, String usageName, boolean required) { + this.shortArg = shortArg; + this.longArg = longArg; + this.argType = argType; + this.description = description; + + this.defaultVal = defaultVal; + if (isArray() && defaultVal != null) { + defaultList = ArgumentParser.this.lex(defaultVal); + } + this.usageName = usageName; + this.required = required; + } + + public final boolean isFlag() { + return argType == Type.BOOLEAN; + } + + public final boolean isArray() { + return argType == Type.ARRAY_OF_NUMBERS || argType == Type.ARRAY_OF_STRINGS; + } + + public final boolean isSingle() { + return argType == Type.NUMBER || argType == Type.STRING; + } + + public final boolean isNumeric() { + return argType == Type.NUMBER || argType == Type.ARRAY_OF_NUMBERS; + } + + private void setValue(String val) { + if (isArray()) { + arrayVal = ArgumentParser.this.lex(val); + } else { + singleVal = val; + } + } + + private void setValue(List val) { + arrayVal = new ArrayList<>(val); + } + + public boolean modelEquals(Argument obj) { + if (this.shortArg != null) { + return this.shortArg.equals(obj.shortArg); + } else if (this.longArg != null) { + return this.longArg.equals(obj.longArg); + } else { + return obj.shortArg == null && obj.longArg == null; + } + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + if (longArg != null && shortArg != null) { + b.append("--").append(longArg).append("/").append("-").append(shortArg); + } else if (longArg != null) { + b.append("--").append(longArg); + } else if (shortArg != null) { + b.append("-").append(shortArg); + } + b.append(": "); + if (isSingle()) { + b.append(singleVal); + } else if (isArray()) { + boolean first = true; + b.append("["); + for (String s : arrayVal) { + if (!first) { + b.append(", "); + } + first = false; + b.append("\"").append(s.replaceAll("\"", "\\\"")).append("\""); + } + b.append("]"); + } + b.append("\n"); + return b.toString(); + } + + private String generateDescription(boolean shortCode) { + StringBuilder b = new StringBuilder(); + b.append("\t"); + if (shortArg == null && longArg == null) { + //Default argument + b.append("<").append(usageName).append(">: ").append(description).append("\n"); + } else { + //If short code is false, we need to check to see if there is a short code, if so, + //this is an alias. + if (shortCode) { + b.append("-").append(shortArg); + } else { + b.append("--").append(longArg); + } + b.append(": "); + + if (!shortCode && shortArg != null) { + //Alias + b.append("Alias to -").append(shortArg); + } else { + if (argType != Type.BOOLEAN) { + if (required) { + b.append("Required. "); + } else { + b.append("Optional. "); + } + } + if (argType == Type.NUMBER) { + b.append("A numeric value. "); + } + if (argType == Type.ARRAY_OF_NUMBERS) { + b.append("A list of numbers. "); + } + if (argType == Type.ARRAY_OF_STRINGS) { + b.append("A list. "); + } + b.append(description.replaceAll("\n", "\n\t\t")); + } + b.append("\n"); + } + return b.toString(); + } + } + + private ArgumentParser() { + } + + public static class ValidationException extends Exception { + + private ValidationException(String string) { + super(string); + } + } + + public static class ResultUseException extends RuntimeException { + + ResultUseException(String string) { + super(string); + } + } + + public class ArgumentParserResults { + + List arguments = new ArrayList(); + + private void updateArgument(Argument a) { + if (a == null) { + return; + } + List toRemove = new ArrayList(); + for (Argument arg : arguments) { + if (arg.modelEquals(a)) { + toRemove.add(arg); + } + } + for (Argument arg : toRemove) { + arguments.remove(arg); + } + arguments.add(a); + } + + /** + * Returns true if the flag represented by this short code is set. + * + * @param flag + * @return + */ + public boolean isFlagSet(Character flag) { + return getArg(flag) != null; + } + + /** + * Returns true is the flag represented by this long code is set. + * + * @param flag + * @return + */ + public boolean isFlagSet(String flag) { + return getArg(flag) != null; + } + + /** + * Gets the unassociated arguments passed in as a String. For instance, + * if the arguments were These are arguments, then "These + * are arguments" will be returned. However, assuming -c is registered + * as a single string type, and the arguments are + * -c These are arguments, then only "are arguments" is + * returned. This will return an empty string if no arguments were set. + * + * @return + */ + public String getStringArgument() { + try { + Argument a = getArg(); + if (a.arrayVal == null) { + return ""; + } + StringBuilder b = new StringBuilder(); + boolean first = true; + for (String val : a.arrayVal) { + if (!first) { + b.append(" "); + } + first = false; + b.append(val); + } + return b.toString(); + } catch (ResultUseException e) { + return ""; + } + } + + /** + * Returns the string associated with the switch represented by this + * short code. If the switch wasn't set, null is returned. + * + * @param flag + * @return + * @throws ArgumentParser.ResultUseException + */ + public String getStringArgument(Character flag) throws ResultUseException { + return getStringArgument(getArg(flag)); + } + + /** + * Returns the string associated with the switch represented by this + * long code. If the switch wasn't set, null is returned. + * + * @param flag + * @return + * @throws ArgumentParser.ResultUseException + */ + public String getStringArgument(String flag) throws ResultUseException { + return getStringArgument(getArg(flag)); + } + + private String getStringArgument(Argument arg) { + if (arg == null) { + return null; + } + if (arg.argType != Type.STRING) { + throw new ClassCastException("Argument type not set to " + Type.STRING.name() + ". Cannot return a " + "string" + "."); + } + return arg.singleVal; + } + + /** + * Returns the value associated with the switch represented by this + * short code, pre-parsed as a double. If the switch wasn't set, null is + * returned. + * + * @param flag + * @return + * @throws ResultUseException, NumberFormatException + */ + public Double getNumberArgument(Character flag) throws ResultUseException { + return getNumberArgument(getArg(flag)); + } + + /** + * Returns the value associated with the switch represented by this long + * code, pre-parsed as a double. If the switch wasn't set, null is + * returned. + * + * @param flag + * @return + * @throws ResultUseException, NumberFormatException + */ + public Double getNumberArgument(String flag) throws ResultUseException { + return getNumberArgument(getArg(flag)); + } + + private Double getNumberArgument(Argument arg) { + if (arg == null) { + return null; + } + if (arg.argType != Type.NUMBER) { + throw new ClassCastException("Argument type not set to " + Type.NUMBER.name() + ". Cannot return a " + "number" + "."); + } + return Double.parseDouble(arg.singleVal); + } + + /** + * Gets the unassociated arguments passed in as a List of Strings. For + * instance, if the arguments were These are arguments, + * then ["These", "are", "arguments"] will be returned. However, + * assuming -c is registered as a single string type, and the arguments + * are -c These are arguments, then only ["are", + * "arguments"] is returned. This will return an empty array if no + * arguments were set. + * + * @return + */ + public List getStringListArgument() { + try { + Argument a = getArg(); + if (a.arrayVal == null) { + return new ArrayList(); + } + return new ArrayList(a.arrayVal); + } catch (ResultUseException e) { + return new ArrayList(); + } + } + + /** + * Returns the list of values associated with the switch represented by + * this short code. If the switch wasn't set, null is returned. + * + * @param flag + * @return + * @throws ArgumentParser.ResultUseException + */ + public List getStringListArgument(Character flag) throws ResultUseException { + return getStringListArgument(getArg(flag)); + } + + /** + * Returns the list of values associated with the switch represented by + * this long code. If the switch wasn't set, null is returned. + * + * @param flag + * @return + * @throws ArgumentParser.ResultUseException + */ + public List getStringListArgument(String flag) throws ResultUseException { + return getStringListArgument(getArg(flag)); + } + + private List getStringListArgument(Argument arg) { + if (arg == null) { + return null; + } + if (arg.argType != Type.ARRAY_OF_STRINGS) { + throw new ClassCastException("Argument type not set to " + Type.ARRAY_OF_STRINGS.name() + ". Cannot return a " + "string list" + "."); + } + return new ArrayList(arg.arrayVal); + } + + /** + * Returns the list of values associated with the switch represented by + * this short code, pre-parsed into doubles. If the switch wasn't set, + * null is returned. + * + * @param flag + * @return + * @throws ArgumentParser.ResultUseException + */ + public List getNumberListArgument(Character flag) throws ResultUseException { + return getNumberListArgument(getArg(flag)); + } + + /** + * Returns the list of values associated with the switch represented by + * this long code, pre-parsed into doubles. If the switch wasn't set, + * null is returned. + * + * @param flag + * @return + * @throws ArgumentParser.ResultUseException + */ + public List getNumberListArgument(String flag) throws ResultUseException { + return getNumberListArgument(getArg(flag)); + } + + private List getNumberListArgument(Argument arg) { + if (arg == null) { + return null; + } + if (arg.argType != Type.ARRAY_OF_NUMBERS) { + throw new ClassCastException("Argument type not set to " + Type.ARRAY_OF_NUMBERS.name() + ". Cannot return a " + "number list" + "."); + } + + List list = new ArrayList(); + for (String s : arg.arrayVal) { + list.add(Double.parseDouble(s)); + } + return list; + } + + private Argument getArg() { + for (Argument a : arguments) { + if (a.shortArg == null && a.longArg == null) { + return a; + } + } + return new Argument(ArgumentParser.this.getArgument()); + } + + private Argument getArg(Character flag) throws ResultUseException { + for (Argument a : arguments) { + if (a.shortArg == null) { + continue; + } + if (a.shortArg.equals(flag)) { + return a; + } + } + return null; + } + + private Argument getArg(String flag) throws ResultUseException { + for (Argument a : arguments) { + if (a.longArg == null) { + continue; + } + if (a.longArg.equals(flag)) { + return a; + } + } + return null; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + for (Argument arg : arguments) { + if (arg.isFlag()) { + b.append("Flag "); + if (arg.longArg != null && arg.shortArg != null) { + b.append("--").append(arg.longArg).append("/").append("-").append(arg.shortArg); + } else if (arg.longArg != null) { + b.append("--").append(arg.longArg); + } else if (arg.shortArg != null) { + b.append("-").append(arg.shortArg); + } + b.append(" is set.\n"); + } else { + b.append(arg.toString()); + } + } + return b.toString(); + } + } + + public static ArgumentParser GetParser() { + return new ArgumentParser(); + } + + public static enum Type { + + STRING, + NUMBER, + ARRAY_OF_STRINGS, + ARRAY_OF_NUMBERS, + BOOLEAN + } + + private ArgumentParser addArgument0(Character shortArg, String longArg, Type argType, String defaultVal, String description, String usageName, boolean required) { + //TODO: Make sure this switch doesn't already exist + argumentModel.add(new Argument(shortArg, longArg, argType, defaultVal, description, usageName, required)); + return this; + } + + /** + * Adds an argument to this argument parser. This is the most complex method + * of adding an argument, all other methods are wrappers around this. + * + * The short code and long code for a switch both represent the underlying + * switch, that is, they both "addresses" of a single underlying switch. + * When accessing the argument later, you may use either the short code or + * the long code to retrieve the value of the switch, but it is important to + * understand that they are both pointing to the same item. + * + * @param shortArg The short code for this switch. + * @param longArg The long code for this switch. + * @param argType The expected type of this switch. + * @param defaultVal The default value of this switch. If defaultVal is not + * null, the switch will always exist when calling get*Argument from the + * results. If argType is BOOLEAN, setting this will cause the switch to + * @param description The description of this argument, which is used when + * building the help text created by getBuiltDescription. + * @return + */ + public ArgumentParser addArgument(Character shortArg, String longArg, Type argType, String defaultVal, String description, String usageName, boolean required) { + if (argType == Type.BOOLEAN) { + throw new IllegalArgumentException("Cannot use addArgument to add a flag. Use addFlag instead."); + } + if (shortArg == null && longArg == null) { + if (argType != Type.STRING && argType != Type.ARRAY_OF_STRINGS) { + throw new IllegalArgumentException("Cannot set the type of the default switch to anything but " + Type.STRING.name() + " or " + + Type.ARRAY_OF_STRINGS.name()); + } + } + return addArgument0(shortArg, longArg, argType, defaultVal, description, usageName, required); + } + + /** + * Sets the default switch's arg type, default value, and description. The + * default switch is the switch that is associated with "loose" arguments, + * for instance, these are args would all be loose arguments, + * because they aren't associated with any explicit switches. Note that + * there is no Type specified here, that's because the arguments can be + * grabbed as either an array of strings or a string. + * + * @param argType + * @param defaultVal + * @param description + * @return + */ + public ArgumentParser addArgument(String defaultVal, String description, String usageName, boolean required) { + return addArgument(null, null, Type.ARRAY_OF_STRINGS, defaultVal, description, usageName, required); + } + + /** + * Sets the default switch with no default value. + * + * @param argType + * @param description + * @return + */ + public ArgumentParser addArgument(String description, String usageName, boolean required) { + return addArgument(null, null, Type.ARRAY_OF_STRINGS, null, description, usageName, required); + } + + /** + * Adds a new argument with no default value. + * + * @param shortArg + * @param longArg + * @param argType + * @param description + * @return + */ + public ArgumentParser addArgument(Character shortArg, String longArg, Type argType, String description, String usageName, boolean required) { + return addArgument(shortArg, longArg, argType, null, description, usageName, required); + } + + /** + * Adds a new argument with no long code. + * + * @param shortArg + * @param argType + * @param defaultVal + * @param description + * @return + */ + public ArgumentParser addArgument(Character shortArg, Type argType, String defaultVal, String description, String usageName, boolean required) { + return addArgument(shortArg, null, argType, defaultVal, description, usageName, required); + } + + /** + * Adds a new argument with no short code. + * + * @param longArg + * @param argType + * @param defaultVal + * @param description + * @return + */ + public ArgumentParser addArgument(String longArg, Type argType, String defaultVal, String description, String usageName, boolean required) { + return addArgument(null, longArg, argType, defaultVal, description, usageName, required); + } + + /** + * Adds a new argument with no long code, and no default value. + * + * @param shortArg + * @param argType + * @param description + * @return + */ + public ArgumentParser addArgument(Character shortArg, Type argType, String description, String usageName, boolean required) { + return addArgument(shortArg, null, argType, null, description, usageName, required); + } + + /** + * Adds a new argument with no short code, and no default value. + * + * @param longArg + * @param argType + * @param description + * @return + */ + public ArgumentParser addArgument(String longArg, Type argType, String description, String usageName, boolean required) { + return addArgument(null, longArg, argType, null, description, usageName, required); + } + + /** + * Adds a new flag. + * + * @param shortArg + * @param longArg + * @param description + * @return + */ + public ArgumentParser addFlag(Character shortArg, String longArg, String description) { + return addArgument0(shortArg, longArg, Type.BOOLEAN, null, description, null, false); + } + + /** + * Adds a new flag with no short code. + * + * @param longArg + * @param description + * @return + */ + public ArgumentParser addFlag(String longArg, String description) { + return addArgument0(null, longArg, Type.BOOLEAN, null, description, null, false); + } + + /** + * Adds a new flag with no long code. + * + * @param shortArg + * @param description + * @return + */ + public ArgumentParser addFlag(Character shortArg, String description) { + return addArgument0(shortArg, null, Type.BOOLEAN, null, description, null, false); + } + + /** + * Adds a description to the ArgumentParser object, which is used when + * building the description returned by getBuiltDescription. + * + * @param description + * @return + */ + public ArgumentParser addDescription(String description) { + this.description = description; + return this; + } + + /** + * Builds a description of this ArgumentParser, which may be useful as + * "Usage" text to provide to a user if a call to match throws a + * ValidationException, for instance. + * + * @return + */ + public String getBuiltDescription() { + StringBuilder b = new StringBuilder(); + //Now, we need to go through and get all the switch names in alphabetical + //order. + b.append("\t").append(this.description).append("\n\n"); + List shortCodes = new ArrayList(); + List longCodes = new ArrayList(); + List shortCodesDone = new ArrayList(); + List longCodesDone = new ArrayList(); + List aliases = new ArrayList(); + for (Argument arg : argumentModel) { + if (arg.shortArg != null) { + shortCodes.add(arg.shortArg); + } + if (arg.longArg != null) { + longCodes.add(arg.longArg); + } + if (arg.shortArg != null && arg.longArg != null) { + aliases.add(arg.longArg); + } + } + Collections.sort(shortCodes); + Collections.sort(longCodes); + //Go through the flags first + boolean hasShortCodeFlags = false; + StringBuilder flags = new StringBuilder(); + List shortFlags = new ArrayList(); + List longFlags = new ArrayList(); + List shortArguments = new ArrayList(); + List longArguments = new ArrayList(); + for (Character c : shortCodes) { + Argument a = getArgument(c); + if (a.isFlag()) { + shortCodesDone.add(c); + flags.append(a.generateDescription(true)); + hasShortCodeFlags = true; + shortFlags.add(c); + } else { + shortArguments.add(c); + } + } + + for (String s : longCodes) { + Argument a = getArgument(s); + if (a.isFlag()) { + longCodesDone.add(s); + flags.append(a.generateDescription(false)); + if (!aliases.contains(s)) { + longFlags.add(s); + } + } else if (!aliases.contains(s)) { + longArguments.add(s); + } + } + + b.append("Usage:\n\t"); + //Get the short flags first, then the long flags, then the short arguments, then the long arguments + List parts = new ArrayList(); + if (!shortFlags.isEmpty()) { + StringBuilder usage = new StringBuilder(); + usage.append("[-"); + for (Character c : shortFlags) { + usage.append(c); + } + usage.append("]"); + parts.add(usage.toString()); + } + + for (String s : longFlags) { + parts.add("[--" + s + "]"); + } + + List usageList = new ArrayList(); + for (Character c : shortArguments) { + usageList.add(getArgument(c)); + } + for (String s : longArguments) { + usageList.add(getArgument(s)); + } + for (Argument a : usageList) { + StringBuilder usage = new StringBuilder(); + if (!a.required) { + usage.append("["); + } + if (a.shortArg != null) { + usage.append("-").append(a.shortArg); + } else { + usage.append("--").append(a.longArg); + } + usage.append(" <"); + if (a.isNumeric()) { + usage.append("#"); + } + usage.append(a.usageName); + if (a.isArray()) { + usage.append(", ..."); + } + usage.append(">"); + + if (a.defaultVal != null && !"".equals(a.defaultVal)) { + usage.append(" (default "); + if (a.argType == Type.STRING) { + usage.append("\""); + } + usage.append(a.defaultVal); + if (a.argType == Type.STRING) { + usage.append("\""); + } + usage.append(")"); + } + + if (!a.required) { + usage.append("]"); + } + parts.add(usage.toString()); + } + + //Now, if the default switch exists, put it here too + if (getArgument() != null) { + parts.add("<" + getArgument().usageName + ", ...>"); + } + + { + StringBuilder usage = new StringBuilder(); + boolean first = true; + for (String part : parts) { + if (!first) { + b.append(" "); + } + first = false; + b.append(part); + } + if (parts.isEmpty()) { + usage.append("No arguments."); + } + b.append(usage.toString()); + } + b.append("\n\nOptions:\n\n"); + Argument def = getArgument(); + if (def != null && def.description != null) { + b.append(def.generateDescription(false)); + } + + if (flags.length() != 0) { + b.append("Flags"); + if (hasShortCodeFlags) { + b.append(" (Short flags may be combined)"); + } + b.append(":\n"); + b.append(flags.toString()); + b.append("\n"); + } + + if (shortCodes.isEmpty() && longCodes.isEmpty() && def == null && flags.length() == 0) { + b.append("\tNo flags or options.\n"); + } else { + if (shortCodes.isEmpty() && longCodes.isEmpty() && def == null) { + b.append("\tNo options.\n"); + } else if (flags.length() == 0) { + b.append("\tNo flags.\n"); + } + } + + for (Character c : shortCodes) { + if (!shortCodesDone.contains(c)) { + b.append(getArgument(c).generateDescription(true)); + } + } + for (String s : longCodes) { + if (!longCodesDone.contains(s)) { + b.append(getArgument(s).generateDescription(false)); + } + } + return b.toString(); + } + + /** + * Returns just the description that was registered with { + * + * @see #addDescription(String)}. + * @return The description, or null, if one has not been set yet. + * @see #getBuiltDescription() + */ + public String getDescription() { + return description; + } + + /** + * This method takes a raw string, which represents the arguments as a + * single string. It supports quoted arguments (both single and double), so + * "this example" would make the string "this example" one argument instead + * of two. Quotes may be escaped with a backslash, like so: "\"quote\"". + * Also, all arguments that start with a dash are considered flags, if you + * need a literal dash, escape it with a backslash too, \-. Instead of + * quoting arguments, you could also add a \ in front of a space to make it + * a literal space, like\ this. Within a string, to add a + * literal backslash in front of an otherwise escapable character, use two + * backslashes "like this\\" + * + * @param args + * @return + */ + public ArgumentParserResults match(String args) throws ValidationException { + return parse(lex(args)); + } + + /** + * Returns a simple List of the arguments, parsed into a proper argument + * list. This will work essentially identically to how general shell + * arguments are parsed. + * + * @param args + * @return + */ + static List lex(String args) { + //First, we have to tokenize the strings. Since we can have quoted arguments, we can't simply split on spaces. + List arguments = new ArrayList(); + StringBuilder buf = new StringBuilder(); + boolean state_in_single_quote = false; + boolean state_in_double_quote = false; + for (int i = 0; i < args.length(); i++) { + Character c0 = args.charAt(i); + Character c1 = i + 1 < args.length() ? args.charAt(i + 1) : null; + + if (c0 == '\\') { + if (c1 == '\'' && state_in_single_quote + || c1 == '"' && state_in_double_quote + || c1 == ' ' && !state_in_double_quote && !state_in_single_quote + || c1 == '\\' && (state_in_double_quote || state_in_single_quote)) { + //We are escaping the next character. Add it to the buffer instead, and + //skip ahead two + buf.append(c1); + i++; + continue; + } + + } + + if (c0 == ' ') { + if (!state_in_double_quote && !state_in_single_quote) { + //argument split + if (buf.length() != 0) { + arguments.add(buf.toString()); + buf = new StringBuilder(); + } + continue; + } + } + if (c0 == '\'' && !state_in_double_quote) { + if (state_in_single_quote) { + state_in_single_quote = false; + arguments.add(buf.toString()); + buf = new StringBuilder(); + } else { + if (buf.length() != 0) { + arguments.add(buf.toString()); + buf = new StringBuilder(); + } + state_in_single_quote = true; + } + continue; + } + if (c0 == '"' && !state_in_single_quote) { + if (state_in_double_quote) { + state_in_double_quote = false; + arguments.add(buf.toString()); + buf = new StringBuilder(); + } else { + if (buf.length() != 0) { + arguments.add(buf.toString()); + buf = new StringBuilder(); + } + state_in_double_quote = true; + } + continue; + } + buf.append(c0); + } + if (buf.length() != 0) { + arguments.add(buf.toString()); + } + return arguments; + } + + private ArgumentParserResults parse(List args) throws ValidationException { + ArgumentParserResults results = new ArgumentParserResults(); + //Fill in results with all the defaults + for (Argument arg : argumentModel) { + if (arg.defaultVal != null) { + //For flags, we simply don't add them if they default to false. + if (!arg.isFlag() || (arg.isFlag() && arg.defaultVal != null)) { + Argument newArg = new Argument(arg); + newArg.setValue(arg.defaultVal); + results.updateArgument(newArg); + } + } + } + //These are arguments that are not flags. + List looseArgs = new ArrayList<>(); + Argument lastArg = null; + for (String arg : args) { + if (arg.matches("^[\\\\]+-.*$")) { + //This is an argument that starts with a literal dash, but we need + //to pull out this first backslash + looseArgs.add(arg.substring(1)); + continue; + } + + //Our regexes have a star, because -(-) is a valid argument that is an empty string. + //"" != null. + if (arg.matches("--[a-zA-Z0-9\\-]*")) { + //Finish up the last argument + results.updateArgument(validateArgument(lastArg, looseArgs)); + //This is a long arg, and so it is the only one. + arg = arg.substring(2); + lastArg = getArgument(arg); + continue; + } + + if (arg.matches("-[a-zA-Z0-9]*")) { + //Finish up the last argument + results.updateArgument(validateArgument(lastArg, looseArgs)); + //This is a short arg, but it could be multiple letters (therefore multiple flags) + //At most, one of these can be a non-flag argument. + boolean hasNonFlagArg = false; + char lastNonFlag = ' '; + for (int i = 1; i < arg.length(); i++) { + Character c = arg.charAt(i); + Argument vArg = getArgument(c); + if (vArg == null) { + throw new ValidationException("Unrecognized flag: " + c); + } + if (!vArg.isFlag() && hasNonFlagArg) { + //We have already come across a non-flag argument, and since this one isn't + //a flag, we need to throw an exception. + throw new ValidationException("Cannot combine multiple non-flag arguments using the short form. Found '" + c + + "' but had already found '" + lastNonFlag + "'. You must split these into multiple arguments, even if they" + + " do not have any parameters, for instance, -" + c + " -" + lastNonFlag); + } + //Is this a non flag? + if (!vArg.isFlag()) { + hasNonFlagArg = true; + lastNonFlag = c; + lastArg = vArg; + //This is all we need to do, it will be dealt with by the next iteration + } else { + //Since it's just a flag, we don't need to worry about it regarding loose arguments, so we + //are just going to go ahead and add it to the results. + results.updateArgument(vArg); + } + } + continue; + } + + //It's just a loose arg, so we'll add it to the list and deal with it at the end + looseArgs.add(arg); + } + + //Finish up the last argument + results.updateArgument(validateArgument(lastArg, looseArgs)); + if (looseArgs.size() > 0) { + //There are loose arguments left, so add them to the loose argument list. + results.updateArgument(validateArgument(null, looseArgs)); + } + //TODO: Check to see if all the required values are here + + return results; + } + + private Argument validateArgument(Argument arg, List looseArgs) throws ValidationException { + if (arg == null) { + if (!looseArgs.isEmpty()) { + //All the loose arguments are accounted for. Either we're done with the arguments, + //or we just hit a -(-)specifier, so we can stop parsing these, and go ahead and + //add them to the results. + Argument a = new Argument(ArgumentParser.this.getArgument()); + a.setValue(looseArgs); + looseArgs.clear(); + return a; + } + return null; + } + Argument finishedArgument = new Argument(arg); + if (arg.isSingle()) { + //Just the first loose argument is associated with this argument, + //the rest (if any) belong to the default loose argument list. + //Of course, looseArgs could be empty, in which case we won't add anything to the list. + if (looseArgs.size() > 0) { + String looseArg = looseArgs.get(0); + looseArgs.remove(0); + finishedArgument.setValue(looseArg); + if (arg.isNumeric()) { + try { + Double.parseDouble(looseArg); + } catch (NumberFormatException e) { + throw new ValidationException("Expecting a numeric value, but \"" + looseArg + "\" was encountered."); + } + } + } else { + finishedArgument.setValue(""); + } + } else if (arg.isArray()) { + finishedArgument.setValue(looseArgs); + if (arg.isNumeric()) { + for (String val : looseArgs) { + try { + Double.parseDouble(val); + } catch (NumberFormatException e) { + throw new ValidationException("Expecting a numeric value, but \"" + val + "\" was encountered."); + } + } + } + looseArgs.clear(); + } + return finishedArgument; + } + + /** + * This method assumes that the arguments have already been parsed out, so, + * for instance, if an argument inside of args[x] contains spaces, it will + * still be considered one argument. So, ["args with spaces", "args"] may + * have looked like this originally: "args with spaces" args + * but through some means or another, you have already parsed the arguments + * out. + * + * @param args + * @return + */ + public ArgumentParserResults match(String[] args) throws ValidationException { + return parse(Arrays.asList(args)); + } } diff --git a/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java b/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java index 080cf69a0c..8322472768 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java +++ b/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java @@ -25,606 +25,606 @@ */ public class ClassMirror implements Serializable { - private static final long serialVersionUID = 1L; - private final ClassInfo info; - - /** - * If this is just a wrapper for an already loaded Class, this will be - * non-null, and should override all the existing methods with the wrapped - * return. - */ - private final Class underlyingClass; - - /** - * The original URL that houses this class. - * - */ - private final URL originalURL; - - protected ClassMirror(ClassInfo info, URL originalURL) { - this.underlyingClass = null; - this.originalURL = originalURL; - this.info = info; - } - - /** - * Creates a ClassMirror object from an already loaded Class. While this - * obviously defeats the purpose of not loading the Class into PermGen, this - * does allow already loaded classes to fit into the ClassMirror ecosystem. - * Essentially, calls to the ClassMirror are simply forwarded to the Class - * and the return re-wrapped in sub mirror types. Some operations are not - * possible, namely non-runtime annotation processing and generics - * information, but in general, all other operations work the same. - * - * @param c - */ - public ClassMirror(Class c) { - this.underlyingClass = c; - originalURL = ClassDiscovery.GetClassContainer(c); - this.info = new ClassInfo<>(); - } - - /** - * Return the container that houses this class. - * - * @return - */ - public URL getContainer() { - return originalURL; - } - - /** - * Returns the modifiers on this class. - * - * @return - */ - public ModifierMirror getModifiers() { - if (underlyingClass != null) { - return new ModifierMirror(underlyingClass.getModifiers()); - } - return info.modifiers; - } - - /** - * Returns the name of this class as recognized by the JVM, not the common - * class name. Use {@link #getClassName()} instead, if you want the common - * name. - * - * @return - */ - public String getJVMClassName() { - if (underlyingClass != null) { - return ClassUtils.getJVMName(underlyingClass); - } - return "L" + info.name + ";"; - } - - /** - * Returns the class name of this class. This is the "normal" name, that is, - * what you would type in code to reference a class, without / or $. - * - * @return - */ - public String getClassName() { - if (underlyingClass != null) { - return underlyingClass.getName().replace('$', '.'); - } - return info.name.replaceAll("[/$]", "."); - } - - /** - * Returns true if this class is an enum - * - * @return - */ - public boolean isEnum() { - if (underlyingClass != null) { - return underlyingClass.isEnum(); - } - return info.isEnum; - } - - /** - * Returns true if this class is an interface. - * - * @return - */ - public boolean isInterface() { - if (underlyingClass != null) { - return underlyingClass.isInterface(); - } - return info.isInterface; - } - - /** - * Returns true iff the underlying class is an abstract class (not an - * interface). - * - * @return - */ - public boolean isAbstract() { - if (underlyingClass != null) { - return (underlyingClass.getModifiers() & Modifier.ABSTRACT) > 0; - } - return info.modifiers.isAbstract(); - } - - /** - * Returns a {@link ClassReferenceMirror} to the class's superclass. - * - * @return - */ - public ClassReferenceMirror getSuperClass() { - if (underlyingClass != null) { - return ClassReferenceMirror.fromClass(underlyingClass.getSuperclass()); - } - return new ClassReferenceMirror<>("L" + info.superClass + ";"); - } - - /** - * Returns a list of {@link ClassReferenceMirror}s of all the interfaces - * that this implements. - * - * @return - */ - public List> getInterfaces() { - List> l = new ArrayList<>(); - if (underlyingClass != null) { - for (Class inter : underlyingClass.getInterfaces()) { - l.add(ClassReferenceMirror.fromClass(inter)); - } - } else { - for (String inter : info.interfaces) { - l.add(new ClassReferenceMirror<>("L" + inter + ";")); - } - } - return l; - } - - /** - * Returns true if this class contains the annotation specified. - * - * @param annotation - * @return - */ - public boolean hasAnnotation(Class annotation) { - if (underlyingClass != null) { - return underlyingClass.getAnnotation(annotation) != null; - } - String name = ClassUtils.getJVMName(annotation); - for (AnnotationMirror a : info.annotations) { - if (a.getType().getJVMName().equals(name)) { - return true; - } - } - return false; - } - - /** - * Because ClassMirror works with annotations that were declared as either - * {@link RetentionPolicy#CLASS} or {@link RetentionPolicy#RUNTIME}, you may - * also want to check visibility. If this returns false, then the class does - * have the annotation, but {@link Class#getAnnotation(java.lang.Class)} - * would return false. If the class doesn't have the annotation, null is - * returned. Note that if this ClassMirror was initialized from a loaded - * Class object, this may not return correct information, because it - * essentially will be returning the result of - * {@link #hasAnnotation(java.lang.Class)}, since there is no way to tell if - * an annotation is anything but runtime. - * - * @param annotation - * @return - */ - public Boolean isAnnotationVisible(Class annotation) { - if (underlyingClass != null) { - return hasAnnotation(annotation); - } - String name = ClassUtils.getJVMName(annotation); - for (AnnotationMirror a : info.annotations) { - if (a.getType().getJVMName().equals(name)) { - return a.isVisible(); - } - } - return null; - } - - /** - * Returns the annotation defined on this class. - * - * @param clazz - * @return - */ - public AnnotationMirror getAnnotation(Class clazz) { - if (underlyingClass != null) { - Annotation ann = underlyingClass.getAnnotation(clazz); - if (ann == null) { - return null; - } - return new AnnotationMirror(ann); - } - String name = ClassUtils.getJVMName(clazz); - for (AnnotationMirror a : info.annotations) { - if (a.getType().getJVMName().equals(name)) { - return a; - } - } - return null; - } - - /** - * Returns a list of annotations on this class. - * - * @return - */ - public List getAnnotations() { - if (underlyingClass != null) { - List list = new ArrayList<>(); - for (Annotation a : underlyingClass.getAnnotations()) { - list.add(new AnnotationMirror(ClassReferenceMirror.fromClass(a.annotationType()), true)); - } - return list; - } - return new ArrayList<>(info.annotations); - } - - /** - * Loads the corresponding Annotation type for this field or method. This - * actually loads the Annotation class into memory. This is equivalent to - * getAnnotation(type).getProxy(type), however this checks for null first, - * and returns null instead of causing a NPE. In the case that this is a - * wrapper for a real Class object, this simply returns the real Annotation - * object (or null). - * - * @param - * @param type - * @return - */ - public T loadAnnotation(Class type) { - if (underlyingClass != null) { - return underlyingClass.getAnnotation(type); - } - AnnotationMirror mirror = getAnnotation(type); - if (mirror == null) { - return null; - } - return mirror.getProxy(type); - } - - /** - * Returns the fields in this class. This works like - * {@link Class#getDeclaredFields()}, as only the methods in this class are - * loaded. - * - * @return - */ - public FieldMirror[] getFields() { - if (underlyingClass != null) { - FieldMirror[] fields = new FieldMirror[this.underlyingClass.getDeclaredFields().length]; - for (int i = 0; i < fields.length; i++) { - Field f = this.underlyingClass.getDeclaredFields()[i]; - fields[i] = new FieldMirror(f); - } - return fields; - } - return info.fields.toArray(new FieldMirror[info.fields.size()]); - } - - /** - * This method returns a map for all classes which this class - * extends/implements of the the generic parameters. For instance, if a - * class has the signature - * {@code class C extends E implements J, K} then this - * method would return the map: {@code {E: [String], J[Integer], K:[]}}. - * Note that for the purposes of this method, interfaces and classes are not - * distinguished, and while the extended class will be first in the list, - * the first item in the list is not necessarily a class. - * - * @return - * @throws IllegalArgumentException If the underlying mechanism backing this - * ClassMirror object is a real loaded class, this method will throw an - * IllegalArgumentException - */ - public Map, List>> getGenerics() throws IllegalArgumentException { - if (underlyingClass != null) { - throw new IllegalArgumentException("Cannot get generics of a real class"); - } - Map, List>> map = new HashMap<>(info.genericParameters.size()); - for (Map.Entry, List>> k : info.genericParameters.entrySet()) { - map.put(k.getKey(), new ArrayList<>(k.getValue())); - } - return map; - } - - /** - * Returns the field, given by name. This does not traverse the Object - * hierarchy, unlike {@link Class#getField(java.lang.String)}. - * - * @param name - * @return - * @throws java.lang.NoSuchFieldException - */ - public FieldMirror getField(String name) throws NoSuchFieldException { - for (FieldMirror m : getFields()) { - if (m.getName().equals(name)) { - return m; - } - } - throw new NoSuchFieldException("The field \"" + name + "\" was not found."); - } - - /** - * Returns the methods in this class. This traverses the parent Object - * heirarchy if the methods are apart of the visible interface, as well as - * private methods in this class itself. - * - * @return - */ - public MethodMirror[] getMethods() { - List l = new ArrayList<>(); - for (AbstractMethodMirror m : getAllMethods()) { - if (m instanceof MethodMirror) { - l.add((MethodMirror) m); - } - } - return l.toArray(new MethodMirror[l.size()]); - } - - /** - * Returns the Constructors in this class. - * - * @return - */ - @SuppressWarnings("unchecked") - public ConstructorMirror[] getConstructors() { - List> l = new ArrayList<>(); - for (AbstractMethodMirror m : getAllMethods()) { - if (m instanceof ConstructorMirror) { - l.add((ConstructorMirror) m); - } - } - return l.toArray(new ConstructorMirror[l.size()]); - } - - /** - * Returns all methods in this class, including constructors. - * - * @return - */ - public AbstractMethodMirror[] getAllMethods() { - if (underlyingClass != null) { - MethodMirror[] mirrors = new MethodMirror[underlyingClass.getDeclaredMethods().length]; - for (int i = 0; i < mirrors.length; i++) { - mirrors[i] = new MethodMirror(underlyingClass.getDeclaredMethods()[i]); - } - return mirrors; - } - return info.methods.toArray(new AbstractMethodMirror[info.methods.size()]); - } - - /** - * Returns the method, given by name. This traverses the parent Object - * heirarchy if the methods are apart of the visible interface, as well as - * private methods in this class itself. - * - * @param name - * @param params - * @return - * @throws java.lang.NoSuchMethodException - */ - public MethodMirror getMethod(String name, Class... params) throws NoSuchMethodException { - ClassReferenceMirror mm[] = new ClassReferenceMirror[params.length]; - for (int i = 0; i < params.length; i++) { - mm[i] = new ClassReferenceMirror<>(ClassUtils.getJVMName(params[i])); - } - return getMethod(name, mm); - } - - /** - * Returns the method, given by name. This traverses the parent Object - * heirarchy if the methods are apart of the visible interface, as well as - * private methods in this class itself. - * - * @param name - * @param params - * @return - * @throws NoSuchMethodException - */ - public MethodMirror getMethod(String name, ClassReferenceMirror... params) throws NoSuchMethodException { - List> crmParams = new ArrayList<>(); - crmParams.addAll(Arrays.asList(params)); - for (AbstractMethodMirror m : getAllMethods()) { - if (m instanceof MethodMirror && m.getName().equals(name) && m.getParams().equals(crmParams)) { - return (MethodMirror) m; - } - } - throw new NoSuchMethodException("No method matching the signature " + name + "(" + StringUtils.Join(crmParams, ", ") + ") was found."); - - } - - /** - * Loads the class into memory and returns the class object. For this call - * to succeed, the class must otherwise be on the class path. The standard - * class loader is used, and the class is initialized. If this is a wrapper - * for an already loaded Class object, that object is simply returned. - * - * @return - */ - @SuppressWarnings("unchecked") - public Class loadClass() throws NoClassDefFoundError { - if (underlyingClass != null) { - return (Class) underlyingClass; - } - try { - return info.classReferenceMirror.loadClass(); - } catch (ClassNotFoundException ex) { - throw new NoClassDefFoundError(); - } - } - - /** - * Loads the class into memory and returns the class object. For this call - * to succeed, the classloader specified must be able to find the class. If - * this is a wrapper for an already loaded Class object, that object is - * simply returned. - * - * @param loader - * @param initialize - * @return - */ - @SuppressWarnings("unchecked") - public Class loadClass(ClassLoader loader, boolean initialize) throws NoClassDefFoundError { - if (underlyingClass != null) { - return (Class) underlyingClass; - } - try { - return info.classReferenceMirror.loadClass(loader, initialize); - } catch (ClassNotFoundException ex) { - throw new NoClassDefFoundError(ex.getMessage()); - } - } - - /** - * Returns true if this class either extends or implements the class - * specified, or is the same as that class. Note that if it transiently - * extends from this class, it can't necessarily find that information - * without actually loading the intermediate class, so this is a less useful - * method than {@link Class#isAssignableFrom(java.lang.Class)}, however, in - * combination with a system that is aware of all classes in a class - * ecosystem, this can be used to piece together that information without - * actually loading the classes. - * - * @param superClass - * @return - */ - public boolean directlyExtendsFrom(Class superClass) { - if (underlyingClass != null) { - if (underlyingClass == superClass) { - return true; - } - if (underlyingClass.isInterface()) { - return Arrays.asList(underlyingClass.getInterfaces()).contains(superClass); - } else { - return (underlyingClass.getSuperclass() == superClass); - } - } - String name = superClass.getName().replace('.', '/'); - if (info.superClass.equals(name)) { - return true; - } - for (String in : info.interfaces) { - if (in.equals(name)) { - return true; - } - } - return false; - } - - /** - * Returns the Package this class is in. If this is not in a package, null - * is returned. - * - * @return - */ - public PackageMirror getPackage() { - if (underlyingClass != null) { - return new PackageMirror(underlyingClass.getPackage().getName()); - } - String[] split = getClassName().split("\\."); - if (split.length == 1) { - return null; - } - StringBuilder b = new StringBuilder(); - for (int i = 0; i < split.length - 1; i++) { - if (i != 0) { - b.append("."); - } - b.append(split[i]); - } - return new PackageMirror(b.toString()); - } - - /** - * Returns the simple name of this class. I.e. for java.lang.String, - * "String" is returned. - * - * @return - */ - public String getSimpleName() { - if (underlyingClass != null) { - return underlyingClass.getSimpleName(); - } - String[] split = getClassName().split("\\."); - return split[split.length - 1]; - } - - /** - * Returns a string representation of this object. The string will match the - * toString that would be generated by that of the Class object. - * - * @return - */ - @Override - public String toString() { - return (isInterface() - ? "interface" - : (isEnum() ? "enum" : "class")) - + " " + getClassName(); - } - - /** - * Returns a {@link ClassReferenceMirror} to the object. This is useful for - * classes that may not exist, as it doesn't require an actual known - * reference to the class to exist. - * - * @return - */ - @SuppressWarnings("unchecked") - public ClassReferenceMirror getClassReference() { - if (underlyingClass != null) { - return ClassReferenceMirror.fromClass(underlyingClass); - } - return new ClassReferenceMirror<>(getJVMClassName()); - } - - @Override - public int hashCode() { - int hash = 5; - hash = 97 * hash + Objects.hashCode(this.getJVMClassName()); - return hash; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final ClassMirror other = (ClassMirror) obj; - return Objects.equals(this.getJVMClassName(), other.getJVMClassName()); - } - - protected static class ClassInfo implements Serializable { - - private static final long serialVersionUID = 1L; - public ModifierMirror modifiers; - public String name; - public String superClass; - public String[] interfaces; - public List annotations = new ArrayList<>(); - public boolean isInterface = false; - public boolean isEnum = false; - public ClassReferenceMirror classReferenceMirror; - public List fields = new ArrayList<>(); - public List methods = new ArrayList<>(); - /** - * Maps inherited classes to the generic parameters passed along to the - * inhereted class. For instance, if we have class Base implements - * A, B {...} then this object would contain {A: - * [Integer, Long], B: [String]} - */ - public Map, List>> genericParameters - = new HashMap<>(); - } + private static final long serialVersionUID = 1L; + private final ClassInfo info; + + /** + * If this is just a wrapper for an already loaded Class, this will be + * non-null, and should override all the existing methods with the wrapped + * return. + */ + private final Class underlyingClass; + + /** + * The original URL that houses this class. + * + */ + private final URL originalURL; + + protected ClassMirror(ClassInfo info, URL originalURL) { + this.underlyingClass = null; + this.originalURL = originalURL; + this.info = info; + } + + /** + * Creates a ClassMirror object from an already loaded Class. While this + * obviously defeats the purpose of not loading the Class into PermGen, this + * does allow already loaded classes to fit into the ClassMirror ecosystem. + * Essentially, calls to the ClassMirror are simply forwarded to the Class + * and the return re-wrapped in sub mirror types. Some operations are not + * possible, namely non-runtime annotation processing and generics + * information, but in general, all other operations work the same. + * + * @param c + */ + public ClassMirror(Class c) { + this.underlyingClass = c; + originalURL = ClassDiscovery.GetClassContainer(c); + this.info = new ClassInfo<>(); + } + + /** + * Return the container that houses this class. + * + * @return + */ + public URL getContainer() { + return originalURL; + } + + /** + * Returns the modifiers on this class. + * + * @return + */ + public ModifierMirror getModifiers() { + if (underlyingClass != null) { + return new ModifierMirror(underlyingClass.getModifiers()); + } + return info.modifiers; + } + + /** + * Returns the name of this class as recognized by the JVM, not the common + * class name. Use {@link #getClassName()} instead, if you want the common + * name. + * + * @return + */ + public String getJVMClassName() { + if (underlyingClass != null) { + return ClassUtils.getJVMName(underlyingClass); + } + return "L" + info.name + ";"; + } + + /** + * Returns the class name of this class. This is the "normal" name, that is, + * what you would type in code to reference a class, without / or $. + * + * @return + */ + public String getClassName() { + if (underlyingClass != null) { + return underlyingClass.getName().replace('$', '.'); + } + return info.name.replaceAll("[/$]", "."); + } + + /** + * Returns true if this class is an enum + * + * @return + */ + public boolean isEnum() { + if (underlyingClass != null) { + return underlyingClass.isEnum(); + } + return info.isEnum; + } + + /** + * Returns true if this class is an interface. + * + * @return + */ + public boolean isInterface() { + if (underlyingClass != null) { + return underlyingClass.isInterface(); + } + return info.isInterface; + } + + /** + * Returns true iff the underlying class is an abstract class (not an + * interface). + * + * @return + */ + public boolean isAbstract() { + if (underlyingClass != null) { + return (underlyingClass.getModifiers() & Modifier.ABSTRACT) > 0; + } + return info.modifiers.isAbstract(); + } + + /** + * Returns a {@link ClassReferenceMirror} to the class's superclass. + * + * @return + */ + public ClassReferenceMirror getSuperClass() { + if (underlyingClass != null) { + return ClassReferenceMirror.fromClass(underlyingClass.getSuperclass()); + } + return new ClassReferenceMirror<>("L" + info.superClass + ";"); + } + + /** + * Returns a list of {@link ClassReferenceMirror}s of all the interfaces + * that this implements. + * + * @return + */ + public List> getInterfaces() { + List> l = new ArrayList<>(); + if (underlyingClass != null) { + for (Class inter : underlyingClass.getInterfaces()) { + l.add(ClassReferenceMirror.fromClass(inter)); + } + } else { + for (String inter : info.interfaces) { + l.add(new ClassReferenceMirror<>("L" + inter + ";")); + } + } + return l; + } + + /** + * Returns true if this class contains the annotation specified. + * + * @param annotation + * @return + */ + public boolean hasAnnotation(Class annotation) { + if (underlyingClass != null) { + return underlyingClass.getAnnotation(annotation) != null; + } + String name = ClassUtils.getJVMName(annotation); + for (AnnotationMirror a : info.annotations) { + if (a.getType().getJVMName().equals(name)) { + return true; + } + } + return false; + } + + /** + * Because ClassMirror works with annotations that were declared as either + * {@link RetentionPolicy#CLASS} or {@link RetentionPolicy#RUNTIME}, you may + * also want to check visibility. If this returns false, then the class does + * have the annotation, but {@link Class#getAnnotation(java.lang.Class)} + * would return false. If the class doesn't have the annotation, null is + * returned. Note that if this ClassMirror was initialized from a loaded + * Class object, this may not return correct information, because it + * essentially will be returning the result of + * {@link #hasAnnotation(java.lang.Class)}, since there is no way to tell if + * an annotation is anything but runtime. + * + * @param annotation + * @return + */ + public Boolean isAnnotationVisible(Class annotation) { + if (underlyingClass != null) { + return hasAnnotation(annotation); + } + String name = ClassUtils.getJVMName(annotation); + for (AnnotationMirror a : info.annotations) { + if (a.getType().getJVMName().equals(name)) { + return a.isVisible(); + } + } + return null; + } + + /** + * Returns the annotation defined on this class. + * + * @param clazz + * @return + */ + public AnnotationMirror getAnnotation(Class clazz) { + if (underlyingClass != null) { + Annotation ann = underlyingClass.getAnnotation(clazz); + if (ann == null) { + return null; + } + return new AnnotationMirror(ann); + } + String name = ClassUtils.getJVMName(clazz); + for (AnnotationMirror a : info.annotations) { + if (a.getType().getJVMName().equals(name)) { + return a; + } + } + return null; + } + + /** + * Returns a list of annotations on this class. + * + * @return + */ + public List getAnnotations() { + if (underlyingClass != null) { + List list = new ArrayList<>(); + for (Annotation a : underlyingClass.getAnnotations()) { + list.add(new AnnotationMirror(ClassReferenceMirror.fromClass(a.annotationType()), true)); + } + return list; + } + return new ArrayList<>(info.annotations); + } + + /** + * Loads the corresponding Annotation type for this field or method. This + * actually loads the Annotation class into memory. This is equivalent to + * getAnnotation(type).getProxy(type), however this checks for null first, + * and returns null instead of causing a NPE. In the case that this is a + * wrapper for a real Class object, this simply returns the real Annotation + * object (or null). + * + * @param + * @param type + * @return + */ + public T loadAnnotation(Class type) { + if (underlyingClass != null) { + return underlyingClass.getAnnotation(type); + } + AnnotationMirror mirror = getAnnotation(type); + if (mirror == null) { + return null; + } + return mirror.getProxy(type); + } + + /** + * Returns the fields in this class. This works like + * {@link Class#getDeclaredFields()}, as only the methods in this class are + * loaded. + * + * @return + */ + public FieldMirror[] getFields() { + if (underlyingClass != null) { + FieldMirror[] fields = new FieldMirror[this.underlyingClass.getDeclaredFields().length]; + for (int i = 0; i < fields.length; i++) { + Field f = this.underlyingClass.getDeclaredFields()[i]; + fields[i] = new FieldMirror(f); + } + return fields; + } + return info.fields.toArray(new FieldMirror[info.fields.size()]); + } + + /** + * This method returns a map for all classes which this class + * extends/implements of the the generic parameters. For instance, if a + * class has the signature + * {@code class C extends E implements J, K} then this + * method would return the map: {@code {E: [String], J[Integer], K:[]}}. + * Note that for the purposes of this method, interfaces and classes are not + * distinguished, and while the extended class will be first in the list, + * the first item in the list is not necessarily a class. + * + * @return + * @throws IllegalArgumentException If the underlying mechanism backing this + * ClassMirror object is a real loaded class, this method will throw an + * IllegalArgumentException + */ + public Map, List>> getGenerics() throws IllegalArgumentException { + if (underlyingClass != null) { + throw new IllegalArgumentException("Cannot get generics of a real class"); + } + Map, List>> map = new HashMap<>(info.genericParameters.size()); + for (Map.Entry, List>> k : info.genericParameters.entrySet()) { + map.put(k.getKey(), new ArrayList<>(k.getValue())); + } + return map; + } + + /** + * Returns the field, given by name. This does not traverse the Object + * hierarchy, unlike {@link Class#getField(java.lang.String)}. + * + * @param name + * @return + * @throws java.lang.NoSuchFieldException + */ + public FieldMirror getField(String name) throws NoSuchFieldException { + for (FieldMirror m : getFields()) { + if (m.getName().equals(name)) { + return m; + } + } + throw new NoSuchFieldException("The field \"" + name + "\" was not found."); + } + + /** + * Returns the methods in this class. This traverses the parent Object + * heirarchy if the methods are apart of the visible interface, as well as + * private methods in this class itself. + * + * @return + */ + public MethodMirror[] getMethods() { + List l = new ArrayList<>(); + for (AbstractMethodMirror m : getAllMethods()) { + if (m instanceof MethodMirror) { + l.add((MethodMirror) m); + } + } + return l.toArray(new MethodMirror[l.size()]); + } + + /** + * Returns the Constructors in this class. + * + * @return + */ + @SuppressWarnings("unchecked") + public ConstructorMirror[] getConstructors() { + List> l = new ArrayList<>(); + for (AbstractMethodMirror m : getAllMethods()) { + if (m instanceof ConstructorMirror) { + l.add((ConstructorMirror) m); + } + } + return l.toArray(new ConstructorMirror[l.size()]); + } + + /** + * Returns all methods in this class, including constructors. + * + * @return + */ + public AbstractMethodMirror[] getAllMethods() { + if (underlyingClass != null) { + MethodMirror[] mirrors = new MethodMirror[underlyingClass.getDeclaredMethods().length]; + for (int i = 0; i < mirrors.length; i++) { + mirrors[i] = new MethodMirror(underlyingClass.getDeclaredMethods()[i]); + } + return mirrors; + } + return info.methods.toArray(new AbstractMethodMirror[info.methods.size()]); + } + + /** + * Returns the method, given by name. This traverses the parent Object + * heirarchy if the methods are apart of the visible interface, as well as + * private methods in this class itself. + * + * @param name + * @param params + * @return + * @throws java.lang.NoSuchMethodException + */ + public MethodMirror getMethod(String name, Class... params) throws NoSuchMethodException { + ClassReferenceMirror mm[] = new ClassReferenceMirror[params.length]; + for (int i = 0; i < params.length; i++) { + mm[i] = new ClassReferenceMirror<>(ClassUtils.getJVMName(params[i])); + } + return getMethod(name, mm); + } + + /** + * Returns the method, given by name. This traverses the parent Object + * heirarchy if the methods are apart of the visible interface, as well as + * private methods in this class itself. + * + * @param name + * @param params + * @return + * @throws NoSuchMethodException + */ + public MethodMirror getMethod(String name, ClassReferenceMirror... params) throws NoSuchMethodException { + List> crmParams = new ArrayList<>(); + crmParams.addAll(Arrays.asList(params)); + for (AbstractMethodMirror m : getAllMethods()) { + if (m instanceof MethodMirror && m.getName().equals(name) && m.getParams().equals(crmParams)) { + return (MethodMirror) m; + } + } + throw new NoSuchMethodException("No method matching the signature " + name + "(" + StringUtils.Join(crmParams, ", ") + ") was found."); + + } + + /** + * Loads the class into memory and returns the class object. For this call + * to succeed, the class must otherwise be on the class path. The standard + * class loader is used, and the class is initialized. If this is a wrapper + * for an already loaded Class object, that object is simply returned. + * + * @return + */ + @SuppressWarnings("unchecked") + public Class loadClass() throws NoClassDefFoundError { + if (underlyingClass != null) { + return (Class) underlyingClass; + } + try { + return info.classReferenceMirror.loadClass(); + } catch (ClassNotFoundException ex) { + throw new NoClassDefFoundError(); + } + } + + /** + * Loads the class into memory and returns the class object. For this call + * to succeed, the classloader specified must be able to find the class. If + * this is a wrapper for an already loaded Class object, that object is + * simply returned. + * + * @param loader + * @param initialize + * @return + */ + @SuppressWarnings("unchecked") + public Class loadClass(ClassLoader loader, boolean initialize) throws NoClassDefFoundError { + if (underlyingClass != null) { + return (Class) underlyingClass; + } + try { + return info.classReferenceMirror.loadClass(loader, initialize); + } catch (ClassNotFoundException ex) { + throw new NoClassDefFoundError(ex.getMessage()); + } + } + + /** + * Returns true if this class either extends or implements the class + * specified, or is the same as that class. Note that if it transiently + * extends from this class, it can't necessarily find that information + * without actually loading the intermediate class, so this is a less useful + * method than {@link Class#isAssignableFrom(java.lang.Class)}, however, in + * combination with a system that is aware of all classes in a class + * ecosystem, this can be used to piece together that information without + * actually loading the classes. + * + * @param superClass + * @return + */ + public boolean directlyExtendsFrom(Class superClass) { + if (underlyingClass != null) { + if (underlyingClass == superClass) { + return true; + } + if (underlyingClass.isInterface()) { + return Arrays.asList(underlyingClass.getInterfaces()).contains(superClass); + } else { + return (underlyingClass.getSuperclass() == superClass); + } + } + String name = superClass.getName().replace('.', '/'); + if (info.superClass.equals(name)) { + return true; + } + for (String in : info.interfaces) { + if (in.equals(name)) { + return true; + } + } + return false; + } + + /** + * Returns the Package this class is in. If this is not in a package, null + * is returned. + * + * @return + */ + public PackageMirror getPackage() { + if (underlyingClass != null) { + return new PackageMirror(underlyingClass.getPackage().getName()); + } + String[] split = getClassName().split("\\."); + if (split.length == 1) { + return null; + } + StringBuilder b = new StringBuilder(); + for (int i = 0; i < split.length - 1; i++) { + if (i != 0) { + b.append("."); + } + b.append(split[i]); + } + return new PackageMirror(b.toString()); + } + + /** + * Returns the simple name of this class. I.e. for java.lang.String, + * "String" is returned. + * + * @return + */ + public String getSimpleName() { + if (underlyingClass != null) { + return underlyingClass.getSimpleName(); + } + String[] split = getClassName().split("\\."); + return split[split.length - 1]; + } + + /** + * Returns a string representation of this object. The string will match the + * toString that would be generated by that of the Class object. + * + * @return + */ + @Override + public String toString() { + return (isInterface() + ? "interface" + : (isEnum() ? "enum" : "class")) + + " " + getClassName(); + } + + /** + * Returns a {@link ClassReferenceMirror} to the object. This is useful for + * classes that may not exist, as it doesn't require an actual known + * reference to the class to exist. + * + * @return + */ + @SuppressWarnings("unchecked") + public ClassReferenceMirror getClassReference() { + if (underlyingClass != null) { + return ClassReferenceMirror.fromClass(underlyingClass); + } + return new ClassReferenceMirror<>(getJVMClassName()); + } + + @Override + public int hashCode() { + int hash = 5; + hash = 97 * hash + Objects.hashCode(this.getJVMClassName()); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ClassMirror other = (ClassMirror) obj; + return Objects.equals(this.getJVMClassName(), other.getJVMClassName()); + } + + protected static class ClassInfo implements Serializable { + + private static final long serialVersionUID = 1L; + public ModifierMirror modifiers; + public String name; + public String superClass; + public String[] interfaces; + public List annotations = new ArrayList<>(); + public boolean isInterface = false; + public boolean isEnum = false; + public ClassReferenceMirror classReferenceMirror; + public List fields = new ArrayList<>(); + public List methods = new ArrayList<>(); + /** + * Maps inherited classes to the generic parameters passed along to the + * inhereted class. For instance, if we have class Base implements + * A, B {...} then this object would contain {A: + * [Integer, Long], B: [String]} + */ + public Map, List>> genericParameters + = new HashMap<>(); + } } diff --git a/src/main/java/com/laytonsmith/PureUtilities/Color.java b/src/main/java/com/laytonsmith/PureUtilities/Color.java index 9264d01e7f..76d66eacb0 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/Color.java +++ b/src/main/java/com/laytonsmith/PureUtilities/Color.java @@ -118,7 +118,7 @@ public class Color implements java.io.Serializable { private float falpha = 0.0f; /* - * JDK 1.1 serialVersionUID + * JDK 1.1 serialVersionUID */ private static final long serialVersionUID = 118526816881161077L; @@ -403,9 +403,9 @@ public Color brighter() { int alpha = getAlpha(); /* From 2D group: - * 1. black.brighter() should return grey - * 2. applying brighter to blue will always return blue, brighter - * 3. non pure color (non zero rgb) will eventually return white + * 1. black.brighter() should return grey + * 2. applying brighter to blue will always return blue, brighter + * 3. non pure color (non zero rgb) will eventually return white */ int i = (int) (1.0 / (1.0 - FACTOR)); if(r == 0 && g == 0 && b == 0) { diff --git a/src/main/java/com/laytonsmith/PureUtilities/Common/FileUtil.java b/src/main/java/com/laytonsmith/PureUtilities/Common/FileUtil.java index 9b564c6aa4..41497a9ee5 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/Common/FileUtil.java +++ b/src/main/java/com/laytonsmith/PureUtilities/Common/FileUtil.java @@ -118,14 +118,14 @@ public static InputStream readAsStream(File file) throws IOException { // } finally { // freeLock(file); // } -// FileInputStream fis = new FileInputStream(f); -// try{ +// FileInputStream fis = new FileInputStream(f); +// try{ // return StreamUtils.GetString(fis, charset); -// } finally { -// fis.close(); -// fis = null; -// System.gc(); -// } +// } finally { +// fis.close(); +// fis = null; +// System.gc(); +// } } /** @@ -221,9 +221,9 @@ public static void write(byte[] data, File file, int mode, boolean create) throw // } finally { // freeLock(file); // } -// FileWriter fw = new FileWriter(f, append); -// fw.write(s); -// fw.close(); +// FileWriter fw = new FileWriter(f, append); +// fw.write(s); +// fw.close(); } /** diff --git a/src/main/java/com/laytonsmith/PureUtilities/ConcurrentSingletonHashMap.java b/src/main/java/com/laytonsmith/PureUtilities/ConcurrentSingletonHashMap.java index c24b7d7ebc..4a54e51e27 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/ConcurrentSingletonHashMap.java +++ b/src/main/java/com/laytonsmith/PureUtilities/ConcurrentSingletonHashMap.java @@ -21,34 +21,34 @@ public class ConcurrentSingletonHashMap implements Map { /* - * You might notice that no fields in this class are volatile. Normally, when you double lock, you must do - * something like this to be totally correct: - * - *
-     * volatile Object value = null; // Note the volatility
-     * construct() {
-     *	Object result = value;
-     *	if(result == null) {
-     *	    synchronized(result) {
-     *		if(result == null) {
-     *		    result = new Object();
-     *		    value = result;
-     *		}
-     *	    }
-     *	}
-     *	return result;
-     * }
-     * 
- * - * Note that we are doing the double locking per usual, but the value is volatile. The local result value seems - * unnecessary at first, but the effect of this is that in cases where value is already initialized - * (i.e., most of the time), the volatile field is only accessed once (due to "return result;" instead of - * "return value;"), which can improve the method's overall performance by as much as 25 percent. - * - * However, in the case that we have before us, the ConcurrentHashMap handles this for us, by guaranteeing that - * we never get a value that is partially constructed in the get() method. - * - * + * You might notice that no fields in this class are volatile. Normally, when you double lock, you must do + * something like this to be totally correct: + * + *
+	 * volatile Object value = null; // Note the volatility
+	 * construct() {
+	 *	Object result = value;
+	 *	if(result == null) {
+	 *		synchronized(result) {
+	 *		if(result == null) {
+	 *			result = new Object();
+	 *			value = result;
+	 *		}
+	 *		}
+	 *	}
+	 *	return result;
+	 * }
+	 * 
+ * + * Note that we are doing the double locking per usual, but the value is volatile. The local result value seems + * unnecessary at first, but the effect of this is that in cases where value is already initialized + * (i.e., most of the time), the volatile field is only accessed once (due to "return result;" instead of + * "return value;"), which can improve the method's overall performance by as much as 25 percent. + * + * However, in the case that we have before us, the ConcurrentHashMap handles this for us, by guaranteeing that + * we never get a value that is partially constructed in the get() method. + * + * */ private final Map map = new ConcurrentHashMap<>(); private final ValueGenerator generator; diff --git a/src/main/java/com/laytonsmith/PureUtilities/ExhaustiveVisitor.java b/src/main/java/com/laytonsmith/PureUtilities/ExhaustiveVisitor.java index b145df3ecc..4a8a7e7486 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/ExhaustiveVisitor.java +++ b/src/main/java/com/laytonsmith/PureUtilities/ExhaustiveVisitor.java @@ -56,20 +56,20 @@ * public static class PhoneNumber implements UserID { * {@code @Override} * public void accept(UserIDVisitor visitor) { - * visitor.handle(this); + * visitor.handle(this); * } * } * public static abstract class GeneratedID implements UserID {} * public static class GeneratedIDV1 extends GeneratedID { * {@code @Override} * public void accept(UserIDVisitor visitor) { - * visitor.handle(this); + * visitor.handle(this); * } * } * public static class GeneratedIDV2 extends GeneratedID { * {@code @Override} * public void accept(UserIDVisitor visitor) { - * visitor.handle(this); + * visitor.handle(this); * } * } * @@ -78,17 +78,17 @@ * * {@code @Override} * public void handle(PhoneNumber m) { - * System.out.println("Canadian PhoneNumber"); + * System.out.println("Canadian PhoneNumber"); * } * * {@code @Override} * public void handle(GeneratedIDV1 c) { - * System.out.println("Canadian GeneratedIDV1"); + * System.out.println("Canadian GeneratedIDV1"); * } * * {@code @Override} * public void handle(GeneratedIDV2 c) { - * System.out.println("Canadian GeneratedIDV2"); + * System.out.println("Canadian GeneratedIDV2"); * } * * } @@ -97,17 +97,17 @@ * * {@code @Override} * public void handle(PhoneNumber m) { - * System.out.println("American PhoneNumber"); + * System.out.println("American PhoneNumber"); * } * * {@code @Override} * public void handle(GeneratedIDV1 c) { - * System.out.println("American GeneratedIDV1"); + * System.out.println("American GeneratedIDV1"); * } * * {@code @Override} * public void handle(GeneratedIDV2 c) { - * System.out.println("American GeneratedIDV2"); + * System.out.println("American GeneratedIDV2"); * } * * } @@ -141,30 +141,30 @@ * {@code @ExhaustiveVisitor.VisitorInfo(baseClass = UserID.class, directSubclassOnly = false)} * public static class CanadianVisitor extends ExhaustiveVisitor { * public void visit(PhoneNumber n) { - * System.out.println("Canadian PhoneNumber"); + * System.out.println("Canadian PhoneNumber"); * } * * public void visit(GeneratedIDV1 id) { - * System.out.println("Canadian GeneratedIDV1"); + * System.out.println("Canadian GeneratedIDV1"); * } * * public void visit(GeneratedIDV2 id) { - * System.out.println("Canadian GeneratedIDV1"); + * System.out.println("Canadian GeneratedIDV1"); * } * } * * {@code @ExhaustiveVisitor.VisitorInfo(baseClass = UserID.class, directSubclassOnly = false)} * public static class AmericanVisitor extends ExhaustiveVisitor { * public void visit(PhoneNumber n) { - * System.out.println("American PhoneNumber"); + * System.out.println("American PhoneNumber"); * } * * public void visit(GeneratedIDV1 id) { - * System.out.println("American GeneratedIDV1"); + * System.out.println("American GeneratedIDV1"); * } * * public void visit(GeneratedIDV2 id) { - * System.out.println("American GeneratedIDV1"); + * System.out.println("American GeneratedIDV1"); * } * } * diff --git a/src/main/java/com/laytonsmith/PureUtilities/PropertiesManager.java b/src/main/java/com/laytonsmith/PureUtilities/PropertiesManager.java index 6cb9bda86c..b1ff77153c 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/PropertiesManager.java +++ b/src/main/java/com/laytonsmith/PureUtilities/PropertiesManager.java @@ -185,10 +185,10 @@ private void load(LineReader lr) throws IOException { } /* Read in a "logical line" from an InputStream/Reader, skip all comment - * and blank lines and filter out those leading whitespace characters - * (\u0020, \u0009 and \u000c) from the beginning of a "natural line". - * Method returns the char length of the "logical line" and stores - * the line in "lineBuf". + * and blank lines and filter out those leading whitespace characters + * (\u0020, \u0009 and \u000c) from the beginning of a "natural line". + * Method returns the char length of the "logical line" and stores + * the line in "lineBuf". */ class LineReader { @@ -317,8 +317,8 @@ int readLine() throws IOException { } /* - * Converts encoded \uxxxx to unicode chars - * and changes special saved chars to their original forms + * Converts encoded \uxxxx to unicode chars + * and changes special saved chars to their original forms */ private String loadConvert(char[] in, int off, int len, char[] convtBuf) { if(convtBuf.length < len) { diff --git a/src/main/java/com/laytonsmith/PureUtilities/TermColors.java b/src/main/java/com/laytonsmith/PureUtilities/TermColors.java index 1fe6540aa6..c79a9bf759 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/TermColors.java +++ b/src/main/java/com/laytonsmith/PureUtilities/TermColors.java @@ -57,7 +57,7 @@ public static void cls() { } /* - * Standard foreground colors + * Standard foreground colors */ @color public static String RED = color(Color.RED); @@ -77,7 +77,7 @@ public static void cls() { public static String WHITE = color(Color.WHITE); /* - * Bright foreground colors + * Bright foreground colors */ @color public static String BRIGHT_RED = color(Color.RED, true, true, true); @@ -97,7 +97,7 @@ public static void cls() { public static String BRIGHT_WHITE = color(Color.WHITE, true, true, true); /* - * Standard background colors + * Standard background colors */ @color public static String BG_RED = color(Color.RED, false, false, false); @@ -117,7 +117,7 @@ public static void cls() { public static String BG_WHITE = color(Color.WHITE, false, false, false); /* - * Bright background colors + * Bright background colors */ @color public static String BG_BRIGHT_RED = color(Color.RED, true, false, false); diff --git a/src/main/java/com/laytonsmith/PureUtilities/UI/TextDialog.java b/src/main/java/com/laytonsmith/PureUtilities/UI/TextDialog.java index 7f52ec45af..81ffee9893 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/UI/TextDialog.java +++ b/src/main/java/com/laytonsmith/PureUtilities/UI/TextDialog.java @@ -126,62 +126,62 @@ public void setOKButtonText(String text) { * content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jPanel1 = new javax.swing.JPanel(); - okButton = new javax.swing.JButton(); - jScrollPane2 = new javax.swing.JScrollPane(); - inputDialog = new javax.swing.JEditorPane(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - - okButton.setText("Ok"); - okButton.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); - okButton.setSelected(true); - - jScrollPane2.setAutoscrolls(true); - - inputDialog.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); - inputDialog.setMinimumSize(new java.awt.Dimension(20, 10)); - jScrollPane2.setViewportView(inputDialog); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE) - .addContainerGap()) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(okButton) - .addContainerGap()) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - ); - - pack(); - }// //GEN-END:initComponents + // //GEN-BEGIN:initComponents + private void initComponents() { + + jPanel1 = new javax.swing.JPanel(); + okButton = new javax.swing.JButton(); + jScrollPane2 = new javax.swing.JScrollPane(); + inputDialog = new javax.swing.JEditorPane(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + okButton.setText("Ok"); + okButton.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + okButton.setSelected(true); + + jScrollPane2.setAutoscrolls(true); + + inputDialog.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); + inputDialog.setMinimumSize(new java.awt.Dimension(20, 10)); + jScrollPane2.setViewportView(inputDialog); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE) + .addContainerGap()) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(okButton) + .addContainerGap()) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + + pack(); + }// //GEN-END:initComponents public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @@ -195,10 +195,10 @@ public void run() { }); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JEditorPane inputDialog; - private javax.swing.JPanel jPanel1; - private javax.swing.JScrollPane jScrollPane2; - private javax.swing.JButton okButton; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JEditorPane inputDialog; + private javax.swing.JPanel jPanel1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JButton okButton; + // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/com/laytonsmith/PureUtilities/VirtualFS/FileSystemLayer.java b/src/main/java/com/laytonsmith/PureUtilities/VirtualFS/FileSystemLayer.java index f5917126c0..39f99359fb 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/VirtualFS/FileSystemLayer.java +++ b/src/main/java/com/laytonsmith/PureUtilities/VirtualFS/FileSystemLayer.java @@ -20,58 +20,58 @@ */ public abstract class FileSystemLayer { - protected final VirtualFile path; - protected final VirtualFileSystem fileSystem; + protected final VirtualFile path; + protected final VirtualFileSystem fileSystem; - protected FileSystemLayer(VirtualFile path, VirtualFileSystem fileSystem) { - this.path = path; - this.fileSystem = fileSystem; - } + protected FileSystemLayer(VirtualFile path, VirtualFileSystem fileSystem) { + this.path = path; + this.fileSystem = fileSystem; + } - public abstract InputStream getInputStream() throws IOException; + public abstract InputStream getInputStream() throws IOException; - public abstract void writeByteArray(byte[] bytes) throws IOException; + public abstract void writeByteArray(byte[] bytes) throws IOException; - public abstract VirtualFile[] listFiles() throws IOException; + public abstract VirtualFile[] listFiles() throws IOException; - public abstract void delete() throws IOException; + public abstract void delete() throws IOException; - /** - * This may work the exact same as delete in some cases, but otherwise, the - * file will be deleted upon exit of the virtual machine. - * - * @throws IOException - */ - public abstract void deleteOnExit() throws IOException; + /** + * This may work the exact same as delete in some cases, but otherwise, the + * file will be deleted upon exit of the virtual machine. + * + * @throws IOException + */ + public abstract void deleteOnExit() throws IOException; - public abstract boolean exists() throws IOException; + public abstract boolean exists() throws IOException; - public abstract boolean canRead() throws IOException; + public abstract boolean canRead() throws IOException; - public abstract boolean canWrite() throws IOException; + public abstract boolean canWrite() throws IOException; - public abstract boolean isDirectory() throws IOException; + public abstract boolean isDirectory() throws IOException; - public abstract boolean isFile() throws IOException; + public abstract boolean isFile() throws IOException; - public abstract void mkdirs() throws IOException; + public abstract void mkdirs() throws IOException; - public abstract void createNewFile() throws IOException; + public abstract void createNewFile() throws IOException; - /** - * Used to denote a FileSystemLayer protocol - */ - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.TYPE) - public static @interface fslayer { + /** + * Used to denote a FileSystemLayer protocol + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + public static @interface fslayer { - /** - * The protocol identifier, for instance, "file", which would map to a - * file://uri type uri. - * - * @return - */ - String value(); - } + /** + * The protocol identifier, for instance, "file", which would map to a + * file://uri type uri. + * + * @return + */ + String value(); + } } diff --git a/src/main/java/com/laytonsmith/PureUtilities/ZipReader.java b/src/main/java/com/laytonsmith/PureUtilities/ZipReader.java index 63da20a6b0..cc68eb7322 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/ZipReader.java +++ b/src/main/java/com/laytonsmith/PureUtilities/ZipReader.java @@ -203,8 +203,8 @@ public boolean isZipped() { } /* - * This function recurses down into a zip file, ultimately returning the InputStream for the file, - * or throwing exceptions if it can't be found. + * This function recurses down into a zip file, ultimately returning the InputStream for the file, + * or throwing exceptions if it can't be found. */ private InputStream getFile(Deque fullChain, String zipName, final ZipInputStream zis) throws FileNotFoundException, IOException { ZipEntry entry; diff --git a/src/main/java/com/laytonsmith/PureUtilities/rParser.java b/src/main/java/com/laytonsmith/PureUtilities/rParser.java index e031476873..86bef079a5 100644 --- a/src/main/java/com/laytonsmith/PureUtilities/rParser.java +++ b/src/main/java/com/laytonsmith/PureUtilities/rParser.java @@ -17,7 +17,7 @@ private rParser() { private static final int lineLength = 312; /* - * Finds the last color sequence used in the string + * Finds the last color sequence used in the string */ public static String lastColor(String findColor) { int i = findColor.lastIndexOf('§'); @@ -29,7 +29,7 @@ public static String lastColor(String findColor) { } /* - * + * */ public static String combineSplit(int beginHere, String[] split, String seperator) { StringBuilder combined = new StringBuilder(split[beginHere]); diff --git a/src/main/java/com/laytonsmith/abstraction/MCInventoryHolder.java b/src/main/java/com/laytonsmith/abstraction/MCInventoryHolder.java index 95d8f2ed2f..28a54a27ee 100644 --- a/src/main/java/com/laytonsmith/abstraction/MCInventoryHolder.java +++ b/src/main/java/com/laytonsmith/abstraction/MCInventoryHolder.java @@ -2,5 +2,5 @@ public interface MCInventoryHolder extends AbstractionObject { - MCInventory getInventory(); + MCInventory getInventory(); } diff --git a/src/main/java/com/laytonsmith/abstraction/MCItemMeta.java b/src/main/java/com/laytonsmith/abstraction/MCItemMeta.java index 257383a675..5610809bd0 100644 --- a/src/main/java/com/laytonsmith/abstraction/MCItemMeta.java +++ b/src/main/java/com/laytonsmith/abstraction/MCItemMeta.java @@ -7,103 +7,103 @@ public interface MCItemMeta extends AbstractionObject { - /** - * Checks for existence of a display name - * - * @return true if this has a display name - */ - boolean hasDisplayName(); - - /** - * Gets the display name that is set - * - * @return the display name that is set - */ - String getDisplayName(); - - /** - * Sets the display name - * - * @param name the name to set - */ - void setDisplayName(String name); - - /** - * Checks for existence of lore - * - * @return true if this has lore - */ - boolean hasLore(); - - /** - * Gets the lore that is set - * - * @return a list of lore that is set - */ - List getLore(); - - /** - * Sets the lore for this item - * - * @param lore the lore that will be set - */ - void setLore(List lore); - - /** - * Checks if this item has any enchantments - * - * @return true if there are enchantments - */ - boolean hasEnchants(); - - /** - * Gets the enchantments on this items - * - * @return a map of MCEnchantment keys and enchantLevel values - */ - Map getEnchants(); - - /** - * Adds a given enchantment to this meta - * - * @param ench The type of enchantment to add - * @param level The level of enchantment - * @param ignoreLevelRestriction Should adding an outrageous level be - * allowed? - * @return whether the enchantment was added successfully - */ - boolean addEnchant(MCEnchantment ench, int level, boolean ignoreLevelRestriction); - - /** - * Set itemflags which should be ignored when rendering a MCItemStack in the - * Client. - * - * @param flags The flags to ignore. - */ - void addItemFlags(MCItemFlag... flags); - - /** - * Get current set itemFlags. - * - * @return A set of all itemFlags set - */ - Set getItemFlags(); - - /** - * Removes a given enchantment from this meta - * - * @param ench The type of enchantment to remove - * @return whether the enchantment was removed successfully - */ - boolean removeEnchant(MCEnchantment ench); - - boolean hasRepairCost(); - - int getRepairCost(); - - void setRepairCost(int cost); - - boolean isUnbreakable(); - - void setUnbreakable(boolean unbreakable); + /** + * Checks for existence of a display name + * + * @return true if this has a display name + */ + boolean hasDisplayName(); + + /** + * Gets the display name that is set + * + * @return the display name that is set + */ + String getDisplayName(); + + /** + * Sets the display name + * + * @param name the name to set + */ + void setDisplayName(String name); + + /** + * Checks for existence of lore + * + * @return true if this has lore + */ + boolean hasLore(); + + /** + * Gets the lore that is set + * + * @return a list of lore that is set + */ + List getLore(); + + /** + * Sets the lore for this item + * + * @param lore the lore that will be set + */ + void setLore(List lore); + + /** + * Checks if this item has any enchantments + * + * @return true if there are enchantments + */ + boolean hasEnchants(); + + /** + * Gets the enchantments on this items + * + * @return a map of MCEnchantment keys and enchantLevel values + */ + Map getEnchants(); + + /** + * Adds a given enchantment to this meta + * + * @param ench The type of enchantment to add + * @param level The level of enchantment + * @param ignoreLevelRestriction Should adding an outrageous level be + * allowed? + * @return whether the enchantment was added successfully + */ + boolean addEnchant(MCEnchantment ench, int level, boolean ignoreLevelRestriction); + + /** + * Set itemflags which should be ignored when rendering a MCItemStack in the + * Client. + * + * @param flags The flags to ignore. + */ + void addItemFlags(MCItemFlag... flags); + + /** + * Get current set itemFlags. + * + * @return A set of all itemFlags set + */ + Set getItemFlags(); + + /** + * Removes a given enchantment from this meta + * + * @param ench The type of enchantment to remove + * @return whether the enchantment was removed successfully + */ + boolean removeEnchant(MCEnchantment ench); + + boolean hasRepairCost(); + + int getRepairCost(); + + void setRepairCost(int cost); + + boolean isUnbreakable(); + + void setUnbreakable(boolean unbreakable); } diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java index 7a0f41d1d5..b2bfa5382f 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java @@ -301,32 +301,32 @@ public Object call() throws Exception { } } -// /** -// * We don't want to allow scripts to clear other plugin's tasks -// * on accident, so only ids registered through our interface -// * can also be cancelled. -// */ -// private static final Set validIDs = new TreeSet(); +// /** +// * We don't want to allow scripts to clear other plugin's tasks +// * on accident, so only ids registered through our interface +// * can also be cancelled. +// */ +// private static final Set validIDs = new TreeSet(); // // @Override -// public synchronized int SetFutureRunnable(DaemonManager dm, long ms, Runnable r) { -// int id = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CommandHelperPlugin.self, r, Static.msToTicks(ms)); -// validIDs.add(id); -// return id; -// } +// public synchronized int SetFutureRunnable(DaemonManager dm, long ms, Runnable r) { +// int id = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CommandHelperPlugin.self, r, Static.msToTicks(ms)); +// validIDs.add(id); +// return id; +// } // // @Override -// public synchronized int SetFutureRepeater(DaemonManager dm, long ms, long initialDelay, Runnable r){ -// int id = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CommandHelperPlugin.self, r, Static.msToTicks(initialDelay), Static.msToTicks(ms)); -// validIDs.add(id); -// return id; -// } +// public synchronized int SetFutureRepeater(DaemonManager dm, long ms, long initialDelay, Runnable r){ +// int id = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CommandHelperPlugin.self, r, Static.msToTicks(initialDelay), Static.msToTicks(ms)); +// validIDs.add(id); +// return id; +// } // // @Override -// public synchronized void ClearAllRunnables() { +// public synchronized void ClearAllRunnables() { // //Doing cancelTasks apparently does not work, so let's just manually cancel each task, which does appear to work. // //Anyways, it's better that way anyhow, because we actually remove IDs from validIDs that way. -// //((BukkitMCServer)Static.getServer()).__Server().getScheduler().cancelTasks(CommandHelperPlugin.self); +// //((BukkitMCServer)Static.getServer()).__Server().getScheduler().cancelTasks(CommandHelperPlugin.self); // Set ids = new TreeSet(validIDs); // for(int id : ids){ // try{ @@ -336,15 +336,15 @@ public Object call() throws Exception { // Logger.getLogger(BukkitConvertor.class.getName()).log(null, Level.SEVERE, e); // } // } -// } +// } // // @Override -// public void ClearFutureRunnable(int id) { -// if(validIDs.contains(id)){ -// Bukkit.getServer().getScheduler().cancelTask(id); -// validIDs.remove(id); -// } -// } +// public void ClearFutureRunnable(int id) { +// if(validIDs.contains(id)){ +// Bukkit.getServer().getScheduler().cancelTask(id); +// validIDs.remove(id); +// } +// } public static MCEntity BukkitGetCorrectEntity(Entity be) { if(be == null) { return null; diff --git a/src/main/java/com/laytonsmith/commandhelper/BukkitDirtyRegisteredListener.java b/src/main/java/com/laytonsmith/commandhelper/BukkitDirtyRegisteredListener.java index 21505e9468..ab4ab759a5 100644 --- a/src/main/java/com/laytonsmith/commandhelper/BukkitDirtyRegisteredListener.java +++ b/src/main/java/com/laytonsmith/commandhelper/BukkitDirtyRegisteredListener.java @@ -101,64 +101,64 @@ public static void Repopulate() throws NoSuchFieldException, ClassCastException, + " to get rid of this message.", false); //Go through the list of registered listeners, and inject our //our own poisoned DirtyRegisteredListeners in instead -// SimplePluginManager pm = (SimplePluginManager) AliasCore.parent.getServer().getPluginManager(); -// Field fListener = SimplePluginManager.class.getDeclaredField("listeners"); -// //set it to public -// fListener.setAccessible(true); -// EnumMap> listeners = -// (EnumMap>) fListener.get(pm); +// SimplePluginManager pm = (SimplePluginManager) AliasCore.parent.getServer().getPluginManager(); +// Field fListener = SimplePluginManager.class.getDeclaredField("listeners"); +// //set it to public +// fListener.setAccessible(true); +// EnumMap> listeners = +// (EnumMap>) fListener.get(pm); // -// if (listeners instanceof DirtyEnumMap) { -// return; //We don't need to bother with it, we've already injected our poisoned EnumMap, -// //so further additions will go through that instead. -// } -// -// //Remove final from the listeners, so we can modify it -// Field modifiersField = Field.class.getDeclaredField("modifiers"); -// modifiersField.setAccessible(true); -// modifiersField.setInt(fListener, fListener.getModifiers() & ~Modifier.FINAL); +// if (listeners instanceof DirtyEnumMap) { +// return; //We don't need to bother with it, we've already injected our poisoned EnumMap, +// //so further additions will go through that instead. +// } +// +// //Remove final from the listeners, so we can modify it +// Field modifiersField = Field.class.getDeclaredField("modifiers"); +// modifiersField.setAccessible(true); +// modifiersField.setInt(fListener, fListener.getModifiers() & ~Modifier.FINAL); // -// Map> newListeners = new DirtyEnumMap>(Event.Type.class); +// Map> newListeners = new DirtyEnumMap>(Event.Type.class); // -// //We need the comparator, so we can create a new listener map -// Field fComparator = SimplePluginManager.class.getDeclaredField("comparer"); -// fComparator.setAccessible(true); -// Comparator comparator = (Comparator) fComparator.get(pm); +// //We need the comparator, so we can create a new listener map +// Field fComparator = SimplePluginManager.class.getDeclaredField("comparer"); +// fComparator.setAccessible(true); +// Comparator comparator = (Comparator) fComparator.get(pm); // -// //Ok, now we have the listeners, so lets loop through them, and shove them into our own newListener object, so that -// //we can replace the reference later, without modifying the existing variable, because it is currently being walked -// //through elsewhere in the code. +// //Ok, now we have the listeners, so lets loop through them, and shove them into our own newListener object, so that +// //we can replace the reference later, without modifying the existing variable, because it is currently being walked +// //through elsewhere in the code. // -// boolean doReplace = false; +// boolean doReplace = false; // -// Set>> entrySet = listeners.entrySet(); -// Iterator i = entrySet.iterator(); -// while (i.hasNext()) { -// final Map.Entry> mySet = (Map.Entry>) i.next(); -// Iterator k = mySet.getValue().iterator(); -// SortedSet rls = new DirtyTreeSet(comparator); -// newListeners.put(mySet.getKey(), rls); -// while (k.hasNext()) { -// final RegisteredListener rl = (RegisteredListener) k.next(); -// if (!(rl instanceof BukkitDirtyRegisteredListener)) { -// doReplace = true; -// } -// rls.add(BukkitDirtyRegisteredListener.Generate(rl)); -// } -// } +// Set>> entrySet = listeners.entrySet(); +// Iterator i = entrySet.iterator(); +// while (i.hasNext()) { +// final Map.Entry> mySet = (Map.Entry>) i.next(); +// Iterator k = mySet.getValue().iterator(); +// SortedSet rls = new DirtyTreeSet(comparator); +// newListeners.put(mySet.getKey(), rls); +// while (k.hasNext()) { +// final RegisteredListener rl = (RegisteredListener) k.next(); +// if (!(rl instanceof BukkitDirtyRegisteredListener)) { +// doReplace = true; +// } +// rls.add(BukkitDirtyRegisteredListener.Generate(rl)); +// } +// } // -// if (doReplace) { -// //Only replace it if we've made changes -// fListener.set(pm, newListeners); -// } +// if (doReplace) { +// //Only replace it if we've made changes +// fListener.set(pm, newListeners); +// } } -// public static class MyEntry { +// public static class MyEntry { // -// public Type key; -// public DirtyRegisteredListener value; -// } +// public Type key; +// public DirtyRegisteredListener value; +// } public static void setCancelled(Event superCancelledEvent) { if(cancelledEvents.size() >= queueCapacity) { cancelledEvents.poll(); @@ -201,105 +201,105 @@ public static BukkitDirtyRegisteredListener Generate(RegisteredListener real) th */ @Override public void callEvent(Event event) { -// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin)) { -// Debug.DoLog(event.getType(), 1, "Bukkit Event received: " + event.getType().name()); -// } -// //If it isn't super cancelled, call it, even if it is cancelled -// if (!BukkitDirtyRegisteredListener.cancelledEvents.contains(event)) { -// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin) -// && Debug.EVENT_LOGGING_FILTER.contains(event.getType())) { -// Debug.DoLog(event.getType(), 3, "\tEvent is not super cancelled, so triggering now"); -// } -// callEvent0(event); -// } else { -// //If it's a cancellable event, and this listener isn't Monitor priority, just return -// if (event instanceof Cancellable && this.priority != EventPriority.MONITOR) { -// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin) -// && Debug.EVENT_LOGGING_FILTER.contains(event.getType())) { -// Debug.DoLog(event.getType(), 3, "\tEvent is being ignored, due to play-dirty mode rules"); -// } -// return; -// } else { -// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin) -// && Debug.EVENT_LOGGING_FILTER.contains(event.getType())) { -// Debug.DoLog(event.getType(), 3, "\tEvent is super cancelled, but this listener is either monitor priority (Y/N:" -// + (this.priority == EventPriority.MONITOR ? "y" : "n") + " or it it is not cancellable (Y/N:" -// + (event instanceof Cancellable ? "n" : "y")); -// } -// callEvent0(event); -// } -// } +// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin)) { +// Debug.DoLog(event.getType(), 1, "Bukkit Event received: " + event.getType().name()); +// } +// //If it isn't super cancelled, call it, even if it is cancelled +// if (!BukkitDirtyRegisteredListener.cancelledEvents.contains(event)) { +// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin) +// && Debug.EVENT_LOGGING_FILTER.contains(event.getType())) { +// Debug.DoLog(event.getType(), 3, "\tEvent is not super cancelled, so triggering now"); +// } +// callEvent0(event); +// } else { +// //If it's a cancellable event, and this listener isn't Monitor priority, just return +// if (event instanceof Cancellable && this.priority != EventPriority.MONITOR) { +// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin) +// && Debug.EVENT_LOGGING_FILTER.contains(event.getType())) { +// Debug.DoLog(event.getType(), 3, "\tEvent is being ignored, due to play-dirty mode rules"); +// } +// return; +// } else { +// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin) +// && Debug.EVENT_LOGGING_FILTER.contains(event.getType())) { +// Debug.DoLog(event.getType(), 3, "\tEvent is super cancelled, but this listener is either monitor priority (Y/N:" +// + (this.priority == EventPriority.MONITOR ? "y" : "n") + " or it it is not cancellable (Y/N:" +// + (event instanceof Cancellable ? "n" : "y")); +// } +// callEvent0(event); +// } +// } } private void callEvent0(Event event) { -// StopWatch stopWatch = null; -// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin) -// && Debug.EVENT_LOGGING_FILTER.contains(event.getType())) { -// if (Debug.EVENT_LOGGING_LEVEL >= 1) { -// Debug.DoLog(event.getType(), 1, "\tEvent type: " + event.getType().name()); -// Debug.DoLog(event.getType(), 1, "\tCalled from plugin: " + this.plugin.getClass().getSimpleName()); -// } -// if (Debug.EVENT_LOGGING_LEVEL >= 2) { -// Debug.DoLog(event.getType(), 1, "\tListener Registered: " + this.listener.getClass().getCanonicalName()); -// Debug.DoLog(event.getType(), 2, "\tIs Cancellable? " + (event instanceof Cancellable ? "Y" : "N")); -// if (event instanceof Cancellable) { -// Debug.DoLog(event.getType(), 2, "\t\tIs Cancelled? " + (((Cancellable) event).isCancelled() ? "Y" : "N")); -// } -// } -// if (Debug.EVENT_LOGGING_LEVEL >= 3) { -// Debug.DoLog(event.getType(), 3, "\tEvent class: " + event.getClass().getCanonicalName()); -// } -// if (Debug.EVENT_LOGGING_LEVEL >= 4) { -// //Let's just dump the fields -// StringBuilder b = new StringBuilder("\n\tFields in this event:\n"); -// for (Field f : event.getClass().getSuperclass().getDeclaredFields()) { -// b.append("\t\t").append(f.getType().getSimpleName()).append(" ").append(f.getName()); -// f.setAccessible(true); -// try { -// Object o = f.get(event); -// b.append(" = (actual type: ").append(o.getClass().getSimpleName()).append(") ").append(o.toString()).append("\n"); -// } catch (IllegalArgumentException ex) { -// Logger.getLogger(BukkitDirtyRegisteredListener.class.getName()).log(Level.SEVERE, null, ex); -// } catch (IllegalAccessException ex) { -// Logger.getLogger(BukkitDirtyRegisteredListener.class.getName()).log(Level.SEVERE, null, ex); -// } -// } -// Debug.DoLog(event.getType(), 4, b.toString()); -// } -// if (Debug.EVENT_LOGGING_LEVEL == 5) { -// //dump ALL the things -// StringBuilder b = new StringBuilder("\n\tMethods in this event:\n"); -// for (Method m : event.getClass().getSuperclass().getDeclaredMethods()) { -// b.append("\t\t").append(m.getReturnType().getSimpleName()).append(" ").append(m.getName()).append("(").append(Static.strJoin(m.getParameterTypes(), ", ")).append(");\n"); -// } -// Debug.DoLog(event.getType(), 5, b.toString()); -// } -// } -// if ((Debug.EVENT_LOGGING && Debug.IsFiltered(plugin) -// && Debug.EVENT_LOGGING_FILTER.contains(event.getType()) && Debug.EVENT_LOGGING_LEVEL >= 2) || Performance.PERFORMANCE_LOGGING) { -// stopWatch = new StopWatch( -// this.plugin.getClass().getSimpleName() + "."//Plugin name -// + this.listener.getClass().getCanonicalName().replaceAll("\\.", "/") + "." //File event is being called from -// + (event.getType() == Event.Type.CUSTOM_EVENT ? "CUSTOM_EVENT/" + event.getEventName() : event.getType().name()) //Event name -// ); -// } -// try{ -// executor.execute(listener, event); -// } catch(EventException e){ -// Logger.getLogger(BukkitDirtyRegisteredListener.class.getName()).log(Level.SEVERE, e.getMessage(), e); -// } -// if (stopWatch != null) { -// stopWatch.stop(); -// if (Debug.EVENT_LOGGING) { -// Debug.DoLog(event.getType(), 2, "\t\t\tEvent completed in " + stopWatch.getElapsedTime() + " milliseconds"); -// } -// if (Performance.PERFORMANCE_LOGGING) { -// Performance.DoLog(stopWatch); -// } -// } -// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin)) { -// Debug.DoLog(event.getType(), 1, "--------------------------------------------------------------\n"); -// } +// StopWatch stopWatch = null; +// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin) +// && Debug.EVENT_LOGGING_FILTER.contains(event.getType())) { +// if (Debug.EVENT_LOGGING_LEVEL >= 1) { +// Debug.DoLog(event.getType(), 1, "\tEvent type: " + event.getType().name()); +// Debug.DoLog(event.getType(), 1, "\tCalled from plugin: " + this.plugin.getClass().getSimpleName()); +// } +// if (Debug.EVENT_LOGGING_LEVEL >= 2) { +// Debug.DoLog(event.getType(), 1, "\tListener Registered: " + this.listener.getClass().getCanonicalName()); +// Debug.DoLog(event.getType(), 2, "\tIs Cancellable? " + (event instanceof Cancellable ? "Y" : "N")); +// if (event instanceof Cancellable) { +// Debug.DoLog(event.getType(), 2, "\t\tIs Cancelled? " + (((Cancellable) event).isCancelled() ? "Y" : "N")); +// } +// } +// if (Debug.EVENT_LOGGING_LEVEL >= 3) { +// Debug.DoLog(event.getType(), 3, "\tEvent class: " + event.getClass().getCanonicalName()); +// } +// if (Debug.EVENT_LOGGING_LEVEL >= 4) { +// //Let's just dump the fields +// StringBuilder b = new StringBuilder("\n\tFields in this event:\n"); +// for (Field f : event.getClass().getSuperclass().getDeclaredFields()) { +// b.append("\t\t").append(f.getType().getSimpleName()).append(" ").append(f.getName()); +// f.setAccessible(true); +// try { +// Object o = f.get(event); +// b.append(" = (actual type: ").append(o.getClass().getSimpleName()).append(") ").append(o.toString()).append("\n"); +// } catch (IllegalArgumentException ex) { +// Logger.getLogger(BukkitDirtyRegisteredListener.class.getName()).log(Level.SEVERE, null, ex); +// } catch (IllegalAccessException ex) { +// Logger.getLogger(BukkitDirtyRegisteredListener.class.getName()).log(Level.SEVERE, null, ex); +// } +// } +// Debug.DoLog(event.getType(), 4, b.toString()); +// } +// if (Debug.EVENT_LOGGING_LEVEL == 5) { +// //dump ALL the things +// StringBuilder b = new StringBuilder("\n\tMethods in this event:\n"); +// for (Method m : event.getClass().getSuperclass().getDeclaredMethods()) { +// b.append("\t\t").append(m.getReturnType().getSimpleName()).append(" ").append(m.getName()).append("(").append(Static.strJoin(m.getParameterTypes(), ", ")).append(");\n"); +// } +// Debug.DoLog(event.getType(), 5, b.toString()); +// } +// } +// if ((Debug.EVENT_LOGGING && Debug.IsFiltered(plugin) +// && Debug.EVENT_LOGGING_FILTER.contains(event.getType()) && Debug.EVENT_LOGGING_LEVEL >= 2) || Performance.PERFORMANCE_LOGGING) { +// stopWatch = new StopWatch( +// this.plugin.getClass().getSimpleName() + "."//Plugin name +// + this.listener.getClass().getCanonicalName().replaceAll("\\.", "/") + "." //File event is being called from +// + (event.getType() == Event.Type.CUSTOM_EVENT ? "CUSTOM_EVENT/" + event.getEventName() : event.getType().name()) //Event name +// ); +// } +// try{ +// executor.execute(listener, event); +// } catch(EventException e){ +// Logger.getLogger(BukkitDirtyRegisteredListener.class.getName()).log(Level.SEVERE, e.getMessage(), e); +// } +// if (stopWatch != null) { +// stopWatch.stop(); +// if (Debug.EVENT_LOGGING) { +// Debug.DoLog(event.getType(), 2, "\t\t\tEvent completed in " + stopWatch.getElapsedTime() + " milliseconds"); +// } +// if (Performance.PERFORMANCE_LOGGING) { +// Performance.DoLog(stopWatch); +// } +// } +// if (Debug.EVENT_LOGGING && Debug.IsFiltered(plugin)) { +// Debug.DoLog(event.getType(), 1, "--------------------------------------------------------------\n"); +// } } /** diff --git a/src/main/java/com/laytonsmith/core/CoreProfile.java b/src/main/java/com/laytonsmith/core/CoreProfile.java index e8a4c9a58b..2db23aa779 100644 --- a/src/main/java/com/laytonsmith/core/CoreProfile.java +++ b/src/main/java/com/laytonsmith/core/CoreProfile.java @@ -20,16 +20,16 @@ public static void main(String[] args) { StreamUtils.GetSystemOut().println(finish - start + "ms"); /* - Equivalent mscript: - - @start = time() - @array = array() - for(1..1000000, @i, - @array[] = @i - sys_out(@i) - ) - @finish = time() - sys_out(@finish - @start . 'ms') + * Equivalent mscript: + * + * @start = time() + * @array = array() + * for(1..1000000, @i, + * @array[] = @i + * sys_out(@i) + * ) + * @finish = time() + * sys_out(@finish - @start . 'ms') */ } diff --git a/src/main/java/com/laytonsmith/core/GenericTree.java b/src/main/java/com/laytonsmith/core/GenericTree.java index 037cf6f4cb..206228d9ad 100644 --- a/src/main/java/com/laytonsmith/core/GenericTree.java +++ b/src/main/java/com/laytonsmith/core/GenericTree.java @@ -1,6 +1,6 @@ /* - Copyright 2010 Vivin Suresh Paliath - Distributed under the BSD License + * Copyright 2010 Vivin Suresh Paliath + * Distributed under the BSD License */ package com.laytonsmith.core; @@ -159,7 +159,7 @@ private void buildPostOrderWithDepth(GenericTreeNode node, Map suppressWarnings; diff --git a/src/main/java/com/laytonsmith/core/constructs/CSymbol.java b/src/main/java/com/laytonsmith/core/constructs/CSymbol.java index bddbbf1fac..ce8526cd99 100644 --- a/src/main/java/com/laytonsmith/core/constructs/CSymbol.java +++ b/src/main/java/com/laytonsmith/core/constructs/CSymbol.java @@ -70,15 +70,15 @@ public CSymbol(String symbol, Token.TType type, Target target) { case LOGICAL_NOT: conversion = "not"; break; -// case BIT_AND: -// conversion = "bit_and"; -// break; -// case BIT_OR: -// conversion = "bit_or"; -// break; -// case BIT_XOR: -// conversion = "bit_xor"; -// break; +// case BIT_AND: +// conversion = "bit_and"; +// break; +// case BIT_OR: +// conversion = "bit_or"; +// break; +// case BIT_XOR: +// conversion = "bit_xor"; +// break; case MODULO: conversion = "mod"; break; @@ -125,17 +125,17 @@ public boolean isEquality() { return symbolType.isEquality(); } -// public boolean isBitwiseAnd() { -// return symbolType.isBitwiseAnd(); -// } +// public boolean isBitwiseAnd() { +// return symbolType.isBitwiseAnd(); +// } // -// public boolean isBitwiseXor() { -// return symbolType.isBitwiseXor(); -// } +// public boolean isBitwiseXor() { +// return symbolType.isBitwiseXor(); +// } // -// public boolean isBitwiseOr() { -// return symbolType.isBitwiseOr(); -// } +// public boolean isBitwiseOr() { +// return symbolType.isBitwiseOr(); +// } public boolean isLogicalAnd() { return symbolType.isLogicalAnd(); } diff --git a/src/main/java/com/laytonsmith/core/constructs/Token.java b/src/main/java/com/laytonsmith/core/constructs/Token.java index e44db21052..f697313bfa 100644 --- a/src/main/java/com/laytonsmith/core/constructs/Token.java +++ b/src/main/java/com/laytonsmith/core/constructs/Token.java @@ -165,17 +165,17 @@ public boolean isEquality() { return this.variants.contains(TokenVariant.EQUALITY); } -// public boolean isBitwiseAnd(){ -// return (this == BIT_AND); -// } +// public boolean isBitwiseAnd(){ +// return (this == BIT_AND); +// } // -// public boolean isBitwiseXor(){ -// return (this == BIT_XOR); -// } +// public boolean isBitwiseXor(){ +// return (this == BIT_XOR); +// } // -// public boolean isBitwiseOr(){ -// return (this == BIT_OR); -// } +// public boolean isBitwiseOr(){ +// return (this == BIT_OR); +// } /** * Returns true if this is a logical and * diff --git a/src/main/java/com/laytonsmith/core/events/AbstractEvent.java b/src/main/java/com/laytonsmith/core/events/AbstractEvent.java index 24409b89fb..5e8c0cb8e7 100644 --- a/src/main/java/com/laytonsmith/core/events/AbstractEvent.java +++ b/src/main/java/com/laytonsmith/core/events/AbstractEvent.java @@ -36,11 +36,11 @@ public abstract class AbstractEvent implements Event, Comparable { private EventMixinInterface mixin; -// protected EventHandlerInterface handler; +// protected EventHandlerInterface handler; // -// protected AbstractEvent(EventHandlerInterface handler){ -// this.handler = handler; -// } +// protected AbstractEvent(EventHandlerInterface handler){ +// this.handler = handler; +// } // public final void setAbstractEventMixin(EventMixinInterface mixin) { diff --git a/src/main/java/com/laytonsmith/core/events/BoundEvent.java b/src/main/java/com/laytonsmith/core/events/BoundEvent.java index 5339f8790d..754e68cc09 100644 --- a/src/main/java/com/laytonsmith/core/events/BoundEvent.java +++ b/src/main/java/com/laytonsmith/core/events/BoundEvent.java @@ -301,21 +301,21 @@ private void execute(Environment env, ActiveEvent activeEvent) throws EventExcep } //TODO: Once ParseTree supports these again, we may bring this back -// /** -// * Returns true if this event MUST be synchronous. -// * @return -// */ -// public boolean isSync(){ -// return tree.isSync(); -// } +// /** +// * Returns true if this event MUST be synchronous. +// * @return +// */ +// public boolean isSync(){ +// return tree.isSync(); +// } // -// /** -// * Returns true if this event MUST be asynchronous. -// * @return -// */ -// public boolean isAsync(){ -// return tree.isAsync(); -// } +// /** +// * Returns true if this event MUST be asynchronous. +// * @return +// */ +// public boolean isAsync(){ +// return tree.isAsync(); +// } public ParseTree getParseTree() { return tree; } @@ -514,15 +514,15 @@ public void addWhenCancelled(CClosure tree) { } public void executeTriggered() { -// for(Pair pair : whenTriggered){ -// MethodScriptCompiler.execute(pair.fst, pair.snd, null, null); -// } +// for(Pair pair : whenTriggered){ +// MethodScriptCompiler.execute(pair.fst, pair.snd, null, null); +// } } public void executeCancelled() { -// for(Pair pair : whenCancelled){ -// MethodScriptCompiler.execute(pair.fst, pair.snd, null, null); -// } +// for(Pair pair : whenCancelled){ +// MethodScriptCompiler.execute(pair.fst, pair.snd, null, null); +// } } } } diff --git a/src/main/java/com/laytonsmith/core/events/EventBuilder.java b/src/main/java/com/laytonsmith/core/events/EventBuilder.java index e2cc2d88c3..baa6b47924 100644 --- a/src/main/java/com/laytonsmith/core/events/EventBuilder.java +++ b/src/main/java/com/laytonsmith/core/events/EventBuilder.java @@ -110,7 +110,7 @@ public static T instantiate(Class children) throws ConfigCompileException, ConfigRuntimeException { -// //We seriously lose out on the ability to optimize this procedure -// //if we are assigning a dynamic value as a default, but we have to check -// //that here. If we don't, we lose the information -// return ; -// } +// @Override +// public ParseTree optimizeDynamic(Target t, List children) throws ConfigCompileException, ConfigRuntimeException { +// //We seriously lose out on the ability to optimize this procedure +// //if we are assigning a dynamic value as a default, but we have to check +// //that here. If we don't, we lose the information +// return ; +// } } @api diff --git a/src/main/java/com/laytonsmith/core/functions/Debug.java b/src/main/java/com/laytonsmith/core/functions/Debug.java index bbc1546705..847f4c1cb1 100644 --- a/src/main/java/com/laytonsmith/core/functions/Debug.java +++ b/src/main/java/com/laytonsmith/core/functions/Debug.java @@ -31,30 +31,30 @@ */ public class Debug { -// public static boolean EVENT_LOGGING = false; -// public static int EVENT_LOGGING_LEVEL = 1; -// public static final Set EVENT_LOGGING_FILTER = new HashSet(); -// public static final Set EVENT_PLUGIN_FILTER = new HashSet(); +// public static boolean EVENT_LOGGING = false; +// public static int EVENT_LOGGING_LEVEL = 1; +// public static final Set EVENT_LOGGING_FILTER = new HashSet(); +// public static final Set EVENT_PLUGIN_FILTER = new HashSet(); //public static boolean LOG_TO_SCREEN = false; -// public static void DoLog(Event.Type filter, int verbosity, String message) { -// synchronized (EVENT_LOGGING_FILTER) { -// if (EVENT_LOGGING && EVENT_LOGGING_FILTER.contains(filter) && EVENT_LOGGING_LEVEL >= verbosity) { -// try { -// Static.LogDebug(message); -// } catch (IOException ex) { -// Logger.getLogger(Debug.class.getVariableName()).log(Level.SEVERE, null, ex); -// } -// } -// } -// } -// -// public static boolean IsFiltered(Plugin plugin) { -// if (EVENT_PLUGIN_FILTER.isEmpty()) { -// return true; -// } else { -// return EVENT_PLUGIN_FILTER.contains(plugin.getClass().getSimpleName().toUpperCase()); -// } -// } +// public static void DoLog(Event.Type filter, int verbosity, String message) { +// synchronized (EVENT_LOGGING_FILTER) { +// if (EVENT_LOGGING && EVENT_LOGGING_FILTER.contains(filter) && EVENT_LOGGING_LEVEL >= verbosity) { +// try { +// Static.LogDebug(message); +// } catch (IOException ex) { +// Logger.getLogger(Debug.class.getVariableName()).log(Level.SEVERE, null, ex); +// } +// } +// } +// } +// +// public static boolean IsFiltered(Plugin plugin) { +// if (EVENT_PLUGIN_FILTER.isEmpty()) { +// return true; +// } else { +// return EVENT_PLUGIN_FILTER.contains(plugin.getClass().getSimpleName().toUpperCase()); +// } +// } public static String docs() { return "Provides methods for viewing data about both CommandHelper and the other plugins in your server. Though not meant to" + " be called by normal scripts, these methods are available everywhere other methods are available. Note that for" @@ -62,135 +62,135 @@ public static String docs() { + " interpreter mode."; } -// @api -// public static class dump_listeners extends AbstractFunction { -// -// public String getVariableName() { -// return "dump_listeners"; -// } -// -// public Integer[] numArgs() { -// return new Integer[]{0, 1, 2}; -// } -// -// public String docs() { -// return " {[typeFilter], [verboseLevel]} Send null as the typeFilter to see possibilities. VerboseLevel can be 1-4"; -// } -// -// public Class[] thrown() { -// return new Class[]{CRECastException.class, CRESecurityException.class}; -// } -// -// public boolean isRestricted() { -// return true; -// } -// -// public boolean preResolveVariables() { -// return true; -// } -// -// public CHVersion since() { -// return "0.0.0"; -// } -// -// public Boolean runAsync() { -// return false; -// } -// -// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { -// if (!(Boolean) Static.getPreferences().getPreference("allow-debug-logging")) { -// throw new ConfigRuntimeException("allow-debug-logging is currently set to false. To use " + this.getVariableName() + ", enable it in your preferences.", CRESecurityException.class, t); -// } -// StringBuilder b = new StringBuilder("\n"); -// if (args.length >= 1 && args[0] instanceof CNull) { -// b.append("You can sort the listeners further by specifying one of the options:\n"); -// for (Event.Type t : Event.Type.values()) { -// b.append(t.name()).append("\n"); -// } -// return new CString(b.toString(), 0, null); -// } -// int verbosity = 1; -// if (args.length == 2) { -// verbosity = Static.getInt32(args[1]); -// } -// try { -// SimplePluginManager pm = (SimplePluginManager) AliasCore.parent.getServer().getPluginManager(); -// Field fListener = SimplePluginManager.class.getDeclaredField("listeners"); -// //set it to public -// fListener.setAccessible(true); -// EnumMap> listeners = -// (EnumMap>) fListener.get(pm); -// -// if (args.length >= 1) { -// for (RegisteredListener l : listeners.get(Event.Type.valueOf(args[0].val().toUpperCase()))) { -// b.append(Build(l, verbosity)); -// } -// } else { -// for (Event.Type type : listeners.keySet()) { -// b.append("Type: ").append(type.name()).append("\n"); -// for (RegisteredListener l : listeners.get(type)) { -// b.append(Build(l, verbosity)); -// } -// } -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } -// return new CString(b.toString(), 0, null); -// } -// -// public String Build(RegisteredListener l, int verbosity) { -// StringBuilder b = new StringBuilder(); -// switch (Static.Normalize(verbosity, 1, 5)) { -// case 1: -// b.append("Plugin: ").append(l.getPlugin().getClass().getSimpleName()).append("; Priority: ").append(l.getPriority().toString()).append("\n"); -// break; -// case 2: -// b.append("Plugin: ").append(l.getPlugin().getClass().getSimpleName()).append(":").append(l.getListener().getClass().getSimpleName()).append("; Priority: ").append(l.getPriority().toString()).append("\n"); -// break; -// case 3: -// b.append("Plugin: ").append(l.getPlugin().getClass().getSimpleName()).append(":").append(l.getListener().getClass().getCanonicalName()).append("; Priority: ").append(l.getPriority().toString()).append("\n"); -// break; -// case 4: -// b.append("Plugin: ").append(l.getPlugin().getClass().getSimpleName()).append(":").append(l.getListener().getClass().getCanonicalName()).append("\n\t").append("; Priority: ").append(l.getPriority().toString()).append("\n"); -// break; -// case 5: -// b.append("Plugin: ").append(l.getPlugin().getClass().getSimpleName()).append(":").append(l.getListener().getClass().getCanonicalName()).append("; Priority: ").append(l.getPriority().toString()).append("\n"); -// b.append("\tMethods defined in listener that override "); -// try { -// Class parent = (Class) l.getListener().getClass().getSuperclass(); -// while (parent.getSuperclass() != null && parent.getSuperclass().equals(Listener.class)) { -// parent = (Class) parent.getSuperclass(); -// } -// b.append(parent.getSimpleName()).append(":\n"); -// Set parentSet = new HashSet(Arrays.asList(parent.getDeclaredMethods())); -// for (Method m : l.getListener().getClass().getDeclaredMethods()) { -// for (Method pm : parentSet) { -// if (pm.getVariableName().equals(m.getVariableName()) && Arrays.equals(pm.getParameterTypes(), m.getParameterTypes())) { -// b.append("\t\t").append(m.getReturnType().getSimpleName()).append(" ").append(m.getVariableName()).append("(").append(Static.strJoin(m.getParameterTypes(), ", ")).append(");\n"); -// } -// } -// } -// } catch (NoClassDefFoundError e) { -// b.append("Could not get methods for ").append(l.getListener().getClass()); -// } -// break; -// } -// return b.toString(); -// } -// -// public String BuildClassList(Class[] list) { -// StringBuilder b = new StringBuilder(); -// ArrayList l = new ArrayList(); -// for (Class c : list) { -// try { -// l.add(c.getSimpleName()); -// } catch (NoClassDefFoundError e) { -// } -// } -// return Static.strJoin(list, ", "); -// } -// } +// @api +// public static class dump_listeners extends AbstractFunction { +// +// public String getVariableName() { +// return "dump_listeners"; +// } +// +// public Integer[] numArgs() { +// return new Integer[]{0, 1, 2}; +// } +// +// public String docs() { +// return " {[typeFilter], [verboseLevel]} Send null as the typeFilter to see possibilities. VerboseLevel can be 1-4"; +// } +// +// public Class[] thrown() { +// return new Class[]{CRECastException.class, CRESecurityException.class}; +// } +// +// public boolean isRestricted() { +// return true; +// } +// +// public boolean preResolveVariables() { +// return true; +// } +// +// public CHVersion since() { +// return "0.0.0"; +// } +// +// public Boolean runAsync() { +// return false; +// } +// +// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { +// if (!(Boolean) Static.getPreferences().getPreference("allow-debug-logging")) { +// throw new ConfigRuntimeException("allow-debug-logging is currently set to false. To use " + this.getVariableName() + ", enable it in your preferences.", CRESecurityException.class, t); +// } +// StringBuilder b = new StringBuilder("\n"); +// if (args.length >= 1 && args[0] instanceof CNull) { +// b.append("You can sort the listeners further by specifying one of the options:\n"); +// for (Event.Type t : Event.Type.values()) { +// b.append(t.name()).append("\n"); +// } +// return new CString(b.toString(), 0, null); +// } +// int verbosity = 1; +// if (args.length == 2) { +// verbosity = Static.getInt32(args[1]); +// } +// try { +// SimplePluginManager pm = (SimplePluginManager) AliasCore.parent.getServer().getPluginManager(); +// Field fListener = SimplePluginManager.class.getDeclaredField("listeners"); +// //set it to public +// fListener.setAccessible(true); +// EnumMap> listeners = +// (EnumMap>) fListener.get(pm); +// +// if (args.length >= 1) { +// for (RegisteredListener l : listeners.get(Event.Type.valueOf(args[0].val().toUpperCase()))) { +// b.append(Build(l, verbosity)); +// } +// } else { +// for (Event.Type type : listeners.keySet()) { +// b.append("Type: ").append(type.name()).append("\n"); +// for (RegisteredListener l : listeners.get(type)) { +// b.append(Build(l, verbosity)); +// } +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// return new CString(b.toString(), 0, null); +// } +// +// public String Build(RegisteredListener l, int verbosity) { +// StringBuilder b = new StringBuilder(); +// switch (Static.Normalize(verbosity, 1, 5)) { +// case 1: +// b.append("Plugin: ").append(l.getPlugin().getClass().getSimpleName()).append("; Priority: ").append(l.getPriority().toString()).append("\n"); +// break; +// case 2: +// b.append("Plugin: ").append(l.getPlugin().getClass().getSimpleName()).append(":").append(l.getListener().getClass().getSimpleName()).append("; Priority: ").append(l.getPriority().toString()).append("\n"); +// break; +// case 3: +// b.append("Plugin: ").append(l.getPlugin().getClass().getSimpleName()).append(":").append(l.getListener().getClass().getCanonicalName()).append("; Priority: ").append(l.getPriority().toString()).append("\n"); +// break; +// case 4: +// b.append("Plugin: ").append(l.getPlugin().getClass().getSimpleName()).append(":").append(l.getListener().getClass().getCanonicalName()).append("\n\t").append("; Priority: ").append(l.getPriority().toString()).append("\n"); +// break; +// case 5: +// b.append("Plugin: ").append(l.getPlugin().getClass().getSimpleName()).append(":").append(l.getListener().getClass().getCanonicalName()).append("; Priority: ").append(l.getPriority().toString()).append("\n"); +// b.append("\tMethods defined in listener that override "); +// try { +// Class parent = (Class) l.getListener().getClass().getSuperclass(); +// while (parent.getSuperclass() != null && parent.getSuperclass().equals(Listener.class)) { +// parent = (Class) parent.getSuperclass(); +// } +// b.append(parent.getSimpleName()).append(":\n"); +// Set parentSet = new HashSet(Arrays.asList(parent.getDeclaredMethods())); +// for (Method m : l.getListener().getClass().getDeclaredMethods()) { +// for (Method pm : parentSet) { +// if (pm.getVariableName().equals(m.getVariableName()) && Arrays.equals(pm.getParameterTypes(), m.getParameterTypes())) { +// b.append("\t\t").append(m.getReturnType().getSimpleName()).append(" ").append(m.getVariableName()).append("(").append(Static.strJoin(m.getParameterTypes(), ", ")).append(");\n"); +// } +// } +// } +// } catch (NoClassDefFoundError e) { +// b.append("Could not get methods for ").append(l.getListener().getClass()); +// } +// break; +// } +// return b.toString(); +// } +// +// public String BuildClassList(Class[] list) { +// StringBuilder b = new StringBuilder(); +// ArrayList l = new ArrayList(); +// for (Class c : list) { +// try { +// l.add(c.getSimpleName()); +// } catch (NoClassDefFoundError e) { +// } +// } +// return Static.strJoin(list, ", "); +// } +// } @api(environments = {GlobalEnv.class}) public static class debug extends AbstractFunction { @@ -305,191 +305,191 @@ public CHVersion since() { } -// @api -// public static class debug_log_events extends AbstractFunction { -// -// public String getVariableName() { -// return "debug_log_events"; -// } -// -// public Integer[] numArgs() { -// return new Integer[]{1, 2, 3}; -// } -// -// public String docs() { -// return "void {boolean, [level, [logToScreen]]} Turns the event logging on or off. Event logging may be useful in determining the problem if CommandHelper isn't" -// + " able to receive events, you can track what's actually happening. play-dirty mode must be enabled for this to work properly however." -// + " This feature may also be useful in diagnosing other problems with other plugins as well. Level varies from 1-5, and shows more" -// + " information as it increases. You must also set at least one filter with the set_debug_event_filter function before anything" -// + " will happen. logToScreen defaults to false. This should only be turned on when you are testing, or have very strict filters set."; -// } -// -// public Class[] thrown() { -// return new Class[]{CRECastException.class, CRESecurityException.class}; -// } -// -// public boolean isRestricted() { -// return true; -// } -// -// public boolean preResolveVariables() { -// return true; -// } -// -// public CHVersion since() { -// return CHVersion.V3_3_0; -// } -// -// public Boolean runAsync() { -// return false; -// } -// -// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { -// if (!(Boolean) Static.getPreferences().getPreference("allow-debug-logging")) { -// throw new ConfigRuntimeException("allow-debug-logging is currently set to false. To use " + this.getVariableName() + ", enable it in your preferences.", CRESecurityException.class, t); -// } -// boolean on = Static.getBoolean(args[0]); -// int level = 1; -// if(args.length >= 2){ -// level = Static.Normalize(Static.getInt32(args[1]), 1, 5); -// } -// Debug.EVENT_LOGGING = on; -// Debug.EVENT_LOGGING_LEVEL = level; -// if(args.length >= 3){ -// Debug.LOG_TO_SCREEN = Static.getBoolean(args[2]); -// } -// return CVoid.VOID; -// } -// } -// @api -// public static class set_debug_event_filter extends AbstractFunction { -// -// public String getVariableName() { -// return "set_debug_event_filter"; -// } -// -// public Integer[] numArgs() { -// return new Integer[]{1}; -// } -// -// public String docs() { -// return "void {array} Logs the specified event types as they occur, assuming that logging is currently enabled. For a list of" -// + " available filters, you can run dump_listeners(null). As these events occur, they will be logged according to the logging level."; -// } -// -// public Class[] thrown() { -// return new Class[]{CRECastException.class, CREFormatException.class, CRESecurityException.class}; -// } -// -// public boolean isRestricted() { -// return true; -// } -// -// public boolean preResolveVariables() { -// return true; -// } -// -// public CHVersion since() { -// return CHVersion.V3_3_0; -// } -// -// public Boolean runAsync() { -// return true; -// } -// -// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { -// if (!(Boolean) Static.getPreferences().getPreference("allow-debug-logging")) { -// throw new ConfigRuntimeException("allow-debug-logging is currently set to false. To use " + this.getVariableName() + ", enable it in your preferences.", CRESecurityException.class, t); -// } -// Set set = new HashSet(); -// if (args[0] instanceof CString) { -// if (args[0].val().equals("*")) { -// for (Event.Type t : Event.Type.values()) { -// set.add(t); -// } -// } else { -// try { -// Event.Type t = Event.Type.valueOf(args[0].val().toUpperCase()); -// set.add(t); -// } catch (IllegalArgumentException e) { -// throw new ConfigRuntimeException(args[0].val() + " is not a valid filter type. The filter log has not been changed.", CREFormatException.class, t); -// } -// } -// } else if (args[0] instanceof CArray) { -// for (String c : ((CArray) args[0]).keySet()) { -// try { -// set.add(Event.Type.valueOf(((CArray) args[0]).get(c, t).val().toUpperCase())); -// } catch (IllegalArgumentException e) { -// throw new ConfigRuntimeException(c + " is not a valid filter type. The filter log has not been changed.", CREFormatException.class, t); -// } -// } -// } else { -// throw new ConfigRuntimeException("The parameter specified to " + this.getVariableName() + " must be an array (or a single string). The filter array has not been changed.", CRECastException.class, t); -// } -// synchronized (EVENT_LOGGING_FILTER) { -// EVENT_LOGGING_FILTER.clear(); -// for (Event.Type t : set) { -// EVENT_LOGGING_FILTER.add(t); -// } -// } -// return CVoid.VOID; -// } -// } -// @api -// public static class set_debug_plugin_filter extends AbstractFunction { -// -// public String getVariableName() { -// return "set_debug_plugin_filter"; -// } -// -// public Integer[] numArgs() { -// return new Integer[]{1}; -// } -// -// public String docs() { -// return "void {array} Often times you just are interested in the events a particular plugin is outputting. If the plugin filter" -// + " is empty, all plugins are reported (assuming their event types are not filtered out) otherwise, only the ones in" -// + " the list are logged. The name of the plugin is the field \"Called from Plugin: \" in the output, not the name" -// + " it may be commonly referred to as."; -// } -// -// public Class[] thrown() { -// return new Class[]{CRECastException.class, CRESecurityException.class}; -// } -// -// public boolean isRestricted() { -// return true; -// } -// -// public boolean preResolveVariables() { -// return true; -// } -// -// public CHVersion since() { -// return CHVersion.V3_3_0; -// } -// -// public Boolean runAsync() { -// return false; -// } -// -// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { -// if (!(Boolean) Static.getPreferences().getPreference("allow-debug-logging")) { -// throw new ConfigRuntimeException("allow-debug-logging is currently set to false. To use " + this.getVariableName() + ", enable it in your preferences.", CRESecurityException.class, t); -// } -// if (args[0] instanceof CString) { -// EVENT_PLUGIN_FILTER.clear(); -// EVENT_PLUGIN_FILTER.add(args[0].val().toUpperCase()); -// } else if (args[0] instanceof CArray) { -// for (String c : ((CArray) args[0]).keySet()) { -// EVENT_PLUGIN_FILTER.add(((CArray) args[0]).get(c, t).val().toUpperCase()); -// } -// } else { -// throw new ConfigRuntimeException(this.getVariableName() + " expects the argument to be a single string, or an array of strings.", CRECastException.class, t); -// } -// return CVoid.VOID; -// } -// } +// @api +// public static class debug_log_events extends AbstractFunction { +// +// public String getVariableName() { +// return "debug_log_events"; +// } +// +// public Integer[] numArgs() { +// return new Integer[]{1, 2, 3}; +// } +// +// public String docs() { +// return "void {boolean, [level, [logToScreen]]} Turns the event logging on or off. Event logging may be useful in determining the problem if CommandHelper isn't" +// + " able to receive events, you can track what's actually happening. play-dirty mode must be enabled for this to work properly however." +// + " This feature may also be useful in diagnosing other problems with other plugins as well. Level varies from 1-5, and shows more" +// + " information as it increases. You must also set at least one filter with the set_debug_event_filter function before anything" +// + " will happen. logToScreen defaults to false. This should only be turned on when you are testing, or have very strict filters set."; +// } +// +// public Class[] thrown() { +// return new Class[]{CRECastException.class, CRESecurityException.class}; +// } +// +// public boolean isRestricted() { +// return true; +// } +// +// public boolean preResolveVariables() { +// return true; +// } +// +// public CHVersion since() { +// return CHVersion.V3_3_0; +// } +// +// public Boolean runAsync() { +// return false; +// } +// +// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { +// if (!(Boolean) Static.getPreferences().getPreference("allow-debug-logging")) { +// throw new ConfigRuntimeException("allow-debug-logging is currently set to false. To use " + this.getVariableName() + ", enable it in your preferences.", CRESecurityException.class, t); +// } +// boolean on = Static.getBoolean(args[0]); +// int level = 1; +// if(args.length >= 2){ +// level = Static.Normalize(Static.getInt32(args[1]), 1, 5); +// } +// Debug.EVENT_LOGGING = on; +// Debug.EVENT_LOGGING_LEVEL = level; +// if(args.length >= 3){ +// Debug.LOG_TO_SCREEN = Static.getBoolean(args[2]); +// } +// return CVoid.VOID; +// } +// } +// @api +// public static class set_debug_event_filter extends AbstractFunction { +// +// public String getVariableName() { +// return "set_debug_event_filter"; +// } +// +// public Integer[] numArgs() { +// return new Integer[]{1}; +// } +// +// public String docs() { +// return "void {array} Logs the specified event types as they occur, assuming that logging is currently enabled. For a list of" +// + " available filters, you can run dump_listeners(null). As these events occur, they will be logged according to the logging level."; +// } +// +// public Class[] thrown() { +// return new Class[]{CRECastException.class, CREFormatException.class, CRESecurityException.class}; +// } +// +// public boolean isRestricted() { +// return true; +// } +// +// public boolean preResolveVariables() { +// return true; +// } +// +// public CHVersion since() { +// return CHVersion.V3_3_0; +// } +// +// public Boolean runAsync() { +// return true; +// } +// +// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { +// if (!(Boolean) Static.getPreferences().getPreference("allow-debug-logging")) { +// throw new ConfigRuntimeException("allow-debug-logging is currently set to false. To use " + this.getVariableName() + ", enable it in your preferences.", CRESecurityException.class, t); +// } +// Set set = new HashSet(); +// if (args[0] instanceof CString) { +// if (args[0].val().equals("*")) { +// for (Event.Type t : Event.Type.values()) { +// set.add(t); +// } +// } else { +// try { +// Event.Type t = Event.Type.valueOf(args[0].val().toUpperCase()); +// set.add(t); +// } catch (IllegalArgumentException e) { +// throw new ConfigRuntimeException(args[0].val() + " is not a valid filter type. The filter log has not been changed.", CREFormatException.class, t); +// } +// } +// } else if (args[0] instanceof CArray) { +// for (String c : ((CArray) args[0]).keySet()) { +// try { +// set.add(Event.Type.valueOf(((CArray) args[0]).get(c, t).val().toUpperCase())); +// } catch (IllegalArgumentException e) { +// throw new ConfigRuntimeException(c + " is not a valid filter type. The filter log has not been changed.", CREFormatException.class, t); +// } +// } +// } else { +// throw new ConfigRuntimeException("The parameter specified to " + this.getVariableName() + " must be an array (or a single string). The filter array has not been changed.", CRECastException.class, t); +// } +// synchronized (EVENT_LOGGING_FILTER) { +// EVENT_LOGGING_FILTER.clear(); +// for (Event.Type t : set) { +// EVENT_LOGGING_FILTER.add(t); +// } +// } +// return CVoid.VOID; +// } +// } +// @api +// public static class set_debug_plugin_filter extends AbstractFunction { +// +// public String getVariableName() { +// return "set_debug_plugin_filter"; +// } +// +// public Integer[] numArgs() { +// return new Integer[]{1}; +// } +// +// public String docs() { +// return "void {array} Often times you just are interested in the events a particular plugin is outputting. If the plugin filter" +// + " is empty, all plugins are reported (assuming their event types are not filtered out) otherwise, only the ones in" +// + " the list are logged. The name of the plugin is the field \"Called from Plugin: \" in the output, not the name" +// + " it may be commonly referred to as."; +// } +// +// public Class[] thrown() { +// return new Class[]{CRECastException.class, CRESecurityException.class}; +// } +// +// public boolean isRestricted() { +// return true; +// } +// +// public boolean preResolveVariables() { +// return true; +// } +// +// public CHVersion since() { +// return CHVersion.V3_3_0; +// } +// +// public Boolean runAsync() { +// return false; +// } +// +// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { +// if (!(Boolean) Static.getPreferences().getPreference("allow-debug-logging")) { +// throw new ConfigRuntimeException("allow-debug-logging is currently set to false. To use " + this.getVariableName() + ", enable it in your preferences.", CRESecurityException.class, t); +// } +// if (args[0] instanceof CString) { +// EVENT_PLUGIN_FILTER.clear(); +// EVENT_PLUGIN_FILTER.add(args[0].val().toUpperCase()); +// } else if (args[0] instanceof CArray) { +// for (String c : ((CArray) args[0]).keySet()) { +// EVENT_PLUGIN_FILTER.add(((CArray) args[0]).get(c, t).val().toUpperCase()); +// } +// } else { +// throw new ConfigRuntimeException(this.getVariableName() + " expects the argument to be a single string, or an array of strings.", CRECastException.class, t); +// } +// return CVoid.VOID; +// } +// } @api public static class dump_threads extends AbstractFunction { diff --git a/src/main/java/com/laytonsmith/core/functions/Enchantments.java b/src/main/java/com/laytonsmith/core/functions/Enchantments.java index c78c4f5ab9..ac69baf0ba 100644 --- a/src/main/java/com/laytonsmith/core/functions/Enchantments.java +++ b/src/main/java/com/laytonsmith/core/functions/Enchantments.java @@ -107,19 +107,19 @@ public static String ConvertLevel(String romanNumeral) { //Maybe roman numeral? } int i = romanToWestern(lc); -// if(lc.equals("i")){ -// i = 1; -// } else if(lc.equals("ii")){ -// i = 2; -// } else if(lc.equals("iii")){ -// i = 3; -// } else if(lc.equals("iv")){ -// i = 4; -// } else if(lc.equals("v")){ -// i = 5; -// } else { -// return romanNumeral; -// } +// if(lc.equals("i")){ +// i = 1; +// } else if(lc.equals("ii")){ +// i = 2; +// } else if(lc.equals("iii")){ +// i = 3; +// } else if(lc.equals("iv")){ +// i = 4; +// } else if(lc.equals("v")){ +// i = 5; +// } else { +// return romanNumeral; +// } return Integer.toString(i); } @@ -234,12 +234,12 @@ public Construct exec(Target t, Environment environment, Construct... args) thro if(is == null) { throw new CRECastException("There is no item at slot " + args[1 - offset], t); } -// if (args[1 - offset] instanceof CNull) { -// is = m.getItemInHand(); -// } else { -// int slot = Static.getInt32(args[1 - offset]); -// is = m.getInventory().getItem(slot); -// } +// if (args[1 - offset] instanceof CNull) { +// is = m.getItemInHand(); +// } else { +// int slot = Static.getInt32(args[1 - offset]); +// is = m.getInventory().getItem(slot); +// } CArray enchantArray = new CArray(t); if(!(args[2 - offset] instanceof CArray)) { enchantArray.push(args[2 - offset], t); @@ -326,12 +326,12 @@ public Construct exec(Target t, Environment environment, Construct... args) thro if(is == null) { throw new CRECastException("There is no item at slot " + args[1 - offset], t); } -// if (args[1 - offset] instanceof CNull) { -// is = m.getItemInHand(); -// } else { -// int slot = Static.getInt32(args[1 - offset]); -// is = m.getInventory().getItem(slot); -// } +// if (args[1 - offset] instanceof CNull) { +// is = m.getItemInHand(); +// } else { +// int slot = Static.getInt32(args[1 - offset]); +// is = m.getInventory().getItem(slot); +// } CArray enchantArray = new CArray(t); if(!(args[2 - offset] instanceof CArray) && !(args[2 - offset] instanceof CNull)) { @@ -411,12 +411,12 @@ public Construct exec(Target t, Environment environment, Construct... args) thro if(is == null) { throw new CRECastException("There is no item at slot " + slot, t); } -// if(slot instanceof CNull){ -// is = m.getItemInHand(); -// } else { -// int slotID = Static.getInt32(slot); -// is = m.getInventory().getItem(slotID); -// } +// if(slot instanceof CNull){ +// is = m.getItemInHand(); +// } else { +// int slotID = Static.getInt32(slot); +// is = m.getInventory().getItem(slotID); +// } CArray enchants = new CArray(t); CArray levels = new CArray(t); for(Map.Entry entry : is.getEnchantments().entrySet()) { diff --git a/src/main/java/com/laytonsmith/core/functions/EventBinding.java b/src/main/java/com/laytonsmith/core/functions/EventBinding.java index 0802cdd212..c3cc3b7f25 100644 --- a/src/main/java/com/laytonsmith/core/functions/EventBinding.java +++ b/src/main/java/com/laytonsmith/core/functions/EventBinding.java @@ -804,12 +804,12 @@ public CHVersion since() { } } -// @api public static class when_triggered extends AbstractFunction{ +// @api public static class when_triggered extends AbstractFunction{ // -// } -// @api public static class when_cancelled extends AbstractFunction{ +// } +// @api public static class when_cancelled extends AbstractFunction{ // -// } +// } @api(environments = CommandHelperEnvironment.class) public static class event_meta extends AbstractFunction { diff --git a/src/main/java/com/laytonsmith/core/functions/InventoryManagement.java b/src/main/java/com/laytonsmith/core/functions/InventoryManagement.java index 16d02245fe..0a7f8e4b91 100644 --- a/src/main/java/com/laytonsmith/core/functions/InventoryManagement.java +++ b/src/main/java/com/laytonsmith/core/functions/InventoryManagement.java @@ -2193,61 +2193,61 @@ public CHVersion since() { } } -// @api -// public static class pinv_consolidate extends AbstractFunction { +// @api +// public static class pinv_consolidate extends AbstractFunction { // -// public String getName() { -// return "pinv_consolidate"; -// } +// public String getName() { +// return "pinv_consolidate"; +// } // -// public Integer[] numArgs() { -// return new Integer[]{0, 1}; -// } +// public Integer[] numArgs() { +// return new Integer[]{0, 1}; +// } // -// public String docs() { -// return "void {[player]} Consolidates a player's inventory as much as possible." -// + " There is no guarantee anything will happen after this function" -// + " is called, and there is no way to specify details about how" -// + " consolidation occurs, however, the following heuristics are followed:" -// + " The hotbar items will not be moved from the hotbar, unless there are" -// + " two+ slots that have the same item. Items in the main inventory area" -// + " will be moved closer to the bottom of the main inventory. No empty slots" -// + " will be filled in the hotbar."; -// } +// public String docs() { +// return "void {[player]} Consolidates a player's inventory as much as possible." +// + " There is no guarantee anything will happen after this function" +// + " is called, and there is no way to specify details about how" +// + " consolidation occurs, however, the following heuristics are followed:" +// + " The hotbar items will not be moved from the hotbar, unless there are" +// + " two+ slots that have the same item. Items in the main inventory area" +// + " will be moved closer to the bottom of the main inventory. No empty slots" +// + " will be filled in the hotbar."; +// } // -// public Class[] thrown() { -// return new Class[]{}; -// } +// public Class[] thrown() { +// return new Class[]{}; +// } // -// public boolean isRestricted() { -// return true; -// } +// public boolean isRestricted() { +// return true; +// } // -// public boolean preResolveVariables() { -// return true; -// } +// public boolean preResolveVariables() { +// return true; +// } // -// public Boolean runAsync() { -// return false; -// } +// public Boolean runAsync() { +// return false; +// } // -// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { -// MCPlayer p = environment.GetPlayer(); -// if(args.length == 1){ -// p = Static.GetPlayer(args[0], t); -// } -// //First, we need to address the hotbar -// for(int i = 0; i < 10; i++){ -// //If the stack size is maxed out, we're done. -// } +// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException { +// MCPlayer p = environment.GetPlayer(); +// if(args.length == 1){ +// p = Static.GetPlayer(args[0], t); +// } +// //First, we need to address the hotbar +// for(int i = 0; i < 10; i++){ +// //If the stack size is maxed out, we're done. +// } // -// return CVoid.VOID; -// } +// return CVoid.VOID; +// } // -// public CHVersion since() { -// return CHVersion.V3_3_1; -// } -// } +// public CHVersion since() { +// return CHVersion.V3_3_1; +// } +// } private static MCInventory GetInventory(Construct specifier, MCWorld w, Target t) { MCInventory inv; if(specifier instanceof CArray) { diff --git a/src/main/java/com/laytonsmith/core/functions/Regex.java b/src/main/java/com/laytonsmith/core/functions/Regex.java index 9d424a896c..3ffbd6cfb3 100644 --- a/src/main/java/com/laytonsmith/core/functions/Regex.java +++ b/src/main/java/com/laytonsmith/core/functions/Regex.java @@ -321,10 +321,10 @@ public ParseTree optimizeDynamic(Target t, List children, FileOptions } } return null; -// if(!children.get(0).getData().isDynamic()){ -// getPattern(children.get(0).getData(), t); -// } -// return null; +// if(!children.get(0).getData().isDynamic()){ +// getPattern(children.get(0).getData(), t); +// } +// return null; } @Override diff --git a/src/main/java/com/laytonsmith/tools/UILauncher.java b/src/main/java/com/laytonsmith/tools/UILauncher.java index dcab13a282..f11e778fd7 100644 --- a/src/main/java/com/laytonsmith/tools/UILauncher.java +++ b/src/main/java/com/laytonsmith/tools/UILauncher.java @@ -111,66 +111,66 @@ public void mouseClicked(MouseEvent e) { * content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jScrollPane1 = new javax.swing.JScrollPane(); - launcherList = new javax.swing.JList(); - launchButton = new javax.swing.JButton(); - exitButton = new javax.swing.JButton(); - jScrollPane2 = new javax.swing.JScrollPane(); - descriptionTextArea = new javax.swing.JTextArea(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - launcherList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); - jScrollPane1.setViewportView(launcherList); - - launchButton.setText("Launch"); - - exitButton.setText("Exit"); - - descriptionTextArea.setEditable(false); - descriptionTextArea.setColumns(20); - descriptionTextArea.setLineWrap(true); - descriptionTextArea.setRows(5); - descriptionTextArea.setWrapStyleWord(true); - descriptionTextArea.setEnabled(false); - jScrollPane2.setViewportView(descriptionTextArea); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addComponent(launchButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(exitButton))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE) - .addComponent(jScrollPane2)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(launchButton) - .addComponent(exitButton)) - .addContainerGap()) - ); - - pack(); - }// //GEN-END:initComponents + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + launcherList = new javax.swing.JList(); + launchButton = new javax.swing.JButton(); + exitButton = new javax.swing.JButton(); + jScrollPane2 = new javax.swing.JScrollPane(); + descriptionTextArea = new javax.swing.JTextArea(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + launcherList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + jScrollPane1.setViewportView(launcherList); + + launchButton.setText("Launch"); + + exitButton.setText("Exit"); + + descriptionTextArea.setEditable(false); + descriptionTextArea.setColumns(20); + descriptionTextArea.setLineWrap(true); + descriptionTextArea.setRows(5); + descriptionTextArea.setWrapStyleWord(true); + descriptionTextArea.setEnabled(false); + jScrollPane2.setViewportView(descriptionTextArea); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(launchButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(exitButton))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE) + .addComponent(jScrollPane2)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(launchButton) + .addComponent(exitButton)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents /** * @param args the command line arguments @@ -237,12 +237,12 @@ public String toString() { } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JTextArea descriptionTextArea; - private javax.swing.JButton exitButton; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JScrollPane jScrollPane2; - private javax.swing.JButton launchButton; - private javax.swing.JList launcherList; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JTextArea descriptionTextArea; + private javax.swing.JButton exitButton; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JButton launchButton; + private javax.swing.JList launcherList; + // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java b/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java index 6455fee674..4ae43f8a99 100644 --- a/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java +++ b/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java @@ -112,168 +112,168 @@ public void run() { * content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jLabel1 = new javax.swing.JLabel(); - wikiURL = new javax.swing.JTextField(); - jLabel2 = new javax.swing.JLabel(); - username = new javax.swing.JTextField(); - jLabel3 = new javax.swing.JLabel(); - password = new javax.swing.JPasswordField(); - staged = new javax.swing.JCheckBox(); - jPanel1 = new javax.swing.JPanel(); - functions = new javax.swing.JCheckBox(); - examples = new javax.swing.JCheckBox(); - events = new javax.swing.JCheckBox(); - templates = new javax.swing.JCheckBox(); - jLabel4 = new javax.swing.JLabel(); - singleFunctionUploadButton = new javax.swing.JButton(); - uploadButton = new javax.swing.JButton(); - progress = new javax.swing.JProgressBar(); - infoLabel = new javax.swing.JLabel(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jLabel1.setText("Wiki hostname:"); - - wikiURL.setText("wiki.sk89q.com"); - - jLabel2.setText("Username:"); - - jLabel3.setText("Password:"); - - staged.setSelected(true); - staged.setText("Staged?"); - - jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); - - functions.setSelected(true); - functions.setText("Functions"); - - examples.setSelected(true); - examples.setText("Examples"); - - events.setSelected(true); - events.setText("Events"); - - templates.setSelected(true); - templates.setText("Templates"); - - jLabel4.setText("Upload what?"); - - singleFunctionUploadButton.setText("Single Function..."); - singleFunctionUploadButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - singleFunctionUploadButtonActionPerformed(evt); - } - }); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(functions) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(examples) - .addGap(18, 18, 18) - .addComponent(singleFunctionUploadButton)) - .addComponent(events) - .addComponent(templates) - .addComponent(jLabel4)) - .addContainerGap(171, Short.MAX_VALUE)) - ); - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel4) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(functions) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(examples) - .addComponent(singleFunctionUploadButton)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(events) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(templates) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - uploadButton.setText("Upload"); - uploadButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - uploadButtonActionPerformed(evt); - } - }); - - infoLabel.setText("Info: Waiting"); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1) - .addComponent(jLabel2) - .addComponent(jLabel3)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(password) - .addComponent(wikiURL) - .addComponent(username))) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addComponent(staged) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addComponent(uploadButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 222, Short.MAX_VALUE) - .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(infoLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(wikiURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel2) - .addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addComponent(staged) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(uploadButton)) - .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(infoLabel) - .addContainerGap(14, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadButtonActionPerformed + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + wikiURL = new javax.swing.JTextField(); + jLabel2 = new javax.swing.JLabel(); + username = new javax.swing.JTextField(); + jLabel3 = new javax.swing.JLabel(); + password = new javax.swing.JPasswordField(); + staged = new javax.swing.JCheckBox(); + jPanel1 = new javax.swing.JPanel(); + functions = new javax.swing.JCheckBox(); + examples = new javax.swing.JCheckBox(); + events = new javax.swing.JCheckBox(); + templates = new javax.swing.JCheckBox(); + jLabel4 = new javax.swing.JLabel(); + singleFunctionUploadButton = new javax.swing.JButton(); + uploadButton = new javax.swing.JButton(); + progress = new javax.swing.JProgressBar(); + infoLabel = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jLabel1.setText("Wiki hostname:"); + + wikiURL.setText("wiki.sk89q.com"); + + jLabel2.setText("Username:"); + + jLabel3.setText("Password:"); + + staged.setSelected(true); + staged.setText("Staged?"); + + jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); + + functions.setSelected(true); + functions.setText("Functions"); + + examples.setSelected(true); + examples.setText("Examples"); + + events.setSelected(true); + events.setText("Events"); + + templates.setSelected(true); + templates.setText("Templates"); + + jLabel4.setText("Upload what?"); + + singleFunctionUploadButton.setText("Single Function..."); + singleFunctionUploadButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + singleFunctionUploadButtonActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(functions) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(examples) + .addGap(18, 18, 18) + .addComponent(singleFunctionUploadButton)) + .addComponent(events) + .addComponent(templates) + .addComponent(jLabel4)) + .addContainerGap(171, Short.MAX_VALUE)) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel4) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(functions) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(examples) + .addComponent(singleFunctionUploadButton)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(events) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(templates) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + uploadButton.setText("Upload"); + uploadButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + uploadButtonActionPerformed(evt); + } + }); + + infoLabel.setText("Info: Waiting"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addComponent(jLabel2) + .addComponent(jLabel3)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(password) + .addComponent(wikiURL) + .addComponent(username))) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(staged) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(uploadButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 222, Short.MAX_VALUE) + .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(infoLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(wikiURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addComponent(staged) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(uploadButton)) + .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(infoLabel) + .addContainerGap(14, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadButtonActionPerformed uploadButton.setText("Stop"); if(handler != null) { handler.stop(); @@ -292,11 +292,11 @@ public void run() { } }, "UploadThread").start(); } - }//GEN-LAST:event_uploadButtonActionPerformed + }//GEN-LAST:event_uploadButtonActionPerformed - private void singleFunctionUploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleFunctionUploadButtonActionPerformed + private void singleFunctionUploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleFunctionUploadButtonActionPerformed // TODO add your handling code here: - }//GEN-LAST:event_singleFunctionUploadButtonActionPerformed + }//GEN-LAST:event_singleFunctionUploadButtonActionPerformed /** * @param args the command line arguments @@ -349,23 +349,23 @@ public void run() { //This goes ahead and initializes the platform. FunctionList.getFunctionList(api.Platforms.INTERPRETER_JAVA); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JCheckBox events; - private javax.swing.JCheckBox examples; - private javax.swing.JCheckBox functions; - private javax.swing.JLabel infoLabel; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JPanel jPanel1; - private javax.swing.JPasswordField password; - private javax.swing.JProgressBar progress; - private javax.swing.JButton singleFunctionUploadButton; - private javax.swing.JCheckBox staged; - private javax.swing.JCheckBox templates; - private javax.swing.JButton uploadButton; - private javax.swing.JTextField username; - private javax.swing.JTextField wikiURL; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox events; + private javax.swing.JCheckBox examples; + private javax.swing.JCheckBox functions; + private javax.swing.JLabel infoLabel; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JPanel jPanel1; + private javax.swing.JPasswordField password; + private javax.swing.JProgressBar progress; + private javax.swing.JButton singleFunctionUploadButton; + private javax.swing.JCheckBox staged; + private javax.swing.JCheckBox templates; + private javax.swing.JButton uploadButton; + private javax.swing.JTextField username; + private javax.swing.JTextField wikiURL; + // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.java b/src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.java index 5a753d696d..7b184ea758 100644 --- a/src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.java +++ b/src/main/java/com/laytonsmith/tools/docgen/SingleFunctionDialog.java @@ -30,62 +30,62 @@ public SingleFunctionDialog(DocGenUI parent) { * content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { + // //GEN-BEGIN:initComponents + private void initComponents() { - jLabel1 = new javax.swing.JLabel(); - functionNameField = new javax.swing.JTextField(); - uploadButton = new javax.swing.JButton(); - statusLabel = new javax.swing.JLabel(); + jLabel1 = new javax.swing.JLabel(); + functionNameField = new javax.swing.JTextField(); + uploadButton = new javax.swing.JButton(); + statusLabel = new javax.swing.JLabel(); - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - jLabel1.setText("Function:"); + jLabel1.setText("Function:"); - uploadButton.setText("Upload"); - uploadButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - uploadButtonActionPerformed(evt); - } - }); + uploadButton.setText("Upload"); + uploadButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + uploadButtonActionPerformed(evt); + } + }); - statusLabel.setText("Waiting..."); + statusLabel.setText("Waiting..."); - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(functionNameField)) - .addGroup(layout.createSequentialGroup() - .addComponent(uploadButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 222, Short.MAX_VALUE) - .addComponent(statusLabel))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(functionNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(uploadButton) - .addComponent(statusLabel)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(functionNameField)) + .addGroup(layout.createSequentialGroup() + .addComponent(uploadButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 222, Short.MAX_VALUE) + .addComponent(statusLabel))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(functionNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(uploadButton) + .addComponent(statusLabel)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); - pack(); - }// //GEN-END:initComponents + pack(); + }// //GEN-END:initComponents - private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadButtonActionPerformed + private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadButtonActionPerformed Function f; try { f = (Function) FunctionList.getFunction(functionNameField.getText(), Target.UNKNOWN); @@ -105,12 +105,12 @@ private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN- return; } - }//GEN-LAST:event_uploadButtonActionPerformed + }//GEN-LAST:event_uploadButtonActionPerformed - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JTextField functionNameField; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel statusLabel; - private javax.swing.JButton uploadButton; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JTextField functionNameField; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel statusLabel; + private javax.swing.JButton uploadButton; + // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/com/laytonsmith/tools/docgen/sitedeploy/SiteDeploy.java b/src/main/java/com/laytonsmith/tools/docgen/sitedeploy/SiteDeploy.java index 6c9aa92a30..fe579ba596 100644 --- a/src/main/java/com/laytonsmith/tools/docgen/sitedeploy/SiteDeploy.java +++ b/src/main/java/com/laytonsmith/tools/docgen/sitedeploy/SiteDeploy.java @@ -1475,30 +1475,30 @@ public int compare(Class o1, Class o2) { private void deployFunctions() { // generateQueue.submit(new Runnable() { -// @Override -// public void run() { +// @Override +// public void run() { // currentGenerateTask.addAndGet(1); -// } +// } // }); // totalGenerateTasks.addAndGet(1); } private void deployEvents() { // generateQueue.submit(new Runnable() { -// @Override -// public void run() { +// @Override +// public void run() { // currentGenerateTask.addAndGet(1); -// } +// } // }); // totalGenerateTasks.addAndGet(1); } private void deployObjects() { // generateQueue.submit(new Runnable() { -// @Override -// public void run() { +// @Override +// public void run() { // currentGenerateTask.addAndGet(1); -// } +// } // }); // totalGenerateTasks.addAndGet(1); } diff --git a/src/main/java/com/laytonsmith/tools/pnviewer/ConfigurationLoaderDialog.java b/src/main/java/com/laytonsmith/tools/pnviewer/ConfigurationLoaderDialog.java index 44343ae46d..26400bc1c9 100644 --- a/src/main/java/com/laytonsmith/tools/pnviewer/ConfigurationLoaderDialog.java +++ b/src/main/java/com/laytonsmith/tools/pnviewer/ConfigurationLoaderDialog.java @@ -175,135 +175,135 @@ public void setLoaderDialogFinish(LoaderDialogFinish finish) { * content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - localOrRemoteGroup = new javax.swing.ButtonGroup(); - jLabel1 = new javax.swing.JLabel(); - localRadioButton = new javax.swing.JRadioButton(); - localFileField = new javax.swing.JTextField(); - browseLocalFileButton = new javax.swing.JButton(); - remoteRadioButton = new javax.swing.JRadioButton(); - hostLabel = new javax.swing.JLabel(); - hostField = new javax.swing.JTextField(); - passwordLabel = new javax.swing.JLabel(); - passwordField = new javax.swing.JPasswordField(); - jSeparator1 = new javax.swing.JSeparator(); - loadButton = new javax.swing.JButton(); - cancelButton = new javax.swing.JButton(); - portLabel = new javax.swing.JLabel(); - portField = new javax.swing.JTextField(); - remoteFileLabel = new javax.swing.JLabel(); - remoteFileField = new javax.swing.JTextField(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - - jLabel1.setText("Load Configuration from:"); - - localOrRemoteGroup.add(localRadioButton); - localRadioButton.setSelected(true); - localRadioButton.setText("Local"); - - browseLocalFileButton.setText("Browse..."); - - localOrRemoteGroup.add(remoteRadioButton); - remoteRadioButton.setText("Remote"); - - hostLabel.setText("Host:"); - - passwordLabel.setText("Password:"); - - loadButton.setText("Load"); - - cancelButton.setText("Cancel"); - - portLabel.setText("Port:"); - - remoteFileLabel.setText("Remote File:"); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(localFileField) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(browseLocalFileButton)) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(hostLabel) - .addComponent(portLabel)) - .addGap(54, 54, 54) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(portField) - .addComponent(hostField))) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(passwordLabel) - .addGap(30, 30, 30)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(remoteFileLabel) - .addGap(18, 18, 18))) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(remoteFileField) - .addComponent(passwordField))) - .addComponent(jSeparator1) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(localRadioButton) - .addComponent(jLabel1) - .addComponent(remoteRadioButton) - .addGroup(layout.createSequentialGroup() - .addComponent(loadButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton))) - .addGap(0, 236, Short.MAX_VALUE))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(localRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(localFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(browseLocalFileButton)) - .addGap(18, 18, 18) - .addComponent(remoteRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(hostLabel) - .addComponent(hostField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(portLabel) - .addComponent(portField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(passwordLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(remoteFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(remoteFileLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(loadButton) - .addComponent(cancelButton)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents + // //GEN-BEGIN:initComponents + private void initComponents() { + + localOrRemoteGroup = new javax.swing.ButtonGroup(); + jLabel1 = new javax.swing.JLabel(); + localRadioButton = new javax.swing.JRadioButton(); + localFileField = new javax.swing.JTextField(); + browseLocalFileButton = new javax.swing.JButton(); + remoteRadioButton = new javax.swing.JRadioButton(); + hostLabel = new javax.swing.JLabel(); + hostField = new javax.swing.JTextField(); + passwordLabel = new javax.swing.JLabel(); + passwordField = new javax.swing.JPasswordField(); + jSeparator1 = new javax.swing.JSeparator(); + loadButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + portLabel = new javax.swing.JLabel(); + portField = new javax.swing.JTextField(); + remoteFileLabel = new javax.swing.JLabel(); + remoteFileField = new javax.swing.JTextField(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jLabel1.setText("Load Configuration from:"); + + localOrRemoteGroup.add(localRadioButton); + localRadioButton.setSelected(true); + localRadioButton.setText("Local"); + + browseLocalFileButton.setText("Browse..."); + + localOrRemoteGroup.add(remoteRadioButton); + remoteRadioButton.setText("Remote"); + + hostLabel.setText("Host:"); + + passwordLabel.setText("Password:"); + + loadButton.setText("Load"); + + cancelButton.setText("Cancel"); + + portLabel.setText("Port:"); + + remoteFileLabel.setText("Remote File:"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(localFileField) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(browseLocalFileButton)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(hostLabel) + .addComponent(portLabel)) + .addGap(54, 54, 54) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(portField) + .addComponent(hostField))) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(passwordLabel) + .addGap(30, 30, 30)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(remoteFileLabel) + .addGap(18, 18, 18))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(remoteFileField) + .addComponent(passwordField))) + .addComponent(jSeparator1) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(localRadioButton) + .addComponent(jLabel1) + .addComponent(remoteRadioButton) + .addGroup(layout.createSequentialGroup() + .addComponent(loadButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton))) + .addGap(0, 236, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(localRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(localFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(browseLocalFileButton)) + .addGap(18, 18, 18) + .addComponent(remoteRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(hostLabel) + .addComponent(hostField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(portLabel) + .addComponent(portField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(passwordLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(remoteFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(remoteFileLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(loadButton) + .addComponent(cancelButton)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents /** * @param args the command line arguments @@ -360,23 +360,23 @@ public interface LoaderDialogFinish { void data(boolean isLocal, String localPath, String host, int port, String password, String remoteFile); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton browseLocalFileButton; - private javax.swing.JButton cancelButton; - private javax.swing.JTextField hostField; - private javax.swing.JLabel hostLabel; - private javax.swing.JLabel jLabel1; - private javax.swing.JSeparator jSeparator1; - private javax.swing.JButton loadButton; - private javax.swing.JTextField localFileField; - private javax.swing.ButtonGroup localOrRemoteGroup; - private javax.swing.JRadioButton localRadioButton; - private javax.swing.JPasswordField passwordField; - private javax.swing.JLabel passwordLabel; - private javax.swing.JTextField portField; - private javax.swing.JLabel portLabel; - private javax.swing.JTextField remoteFileField; - private javax.swing.JLabel remoteFileLabel; - private javax.swing.JRadioButton remoteRadioButton; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton browseLocalFileButton; + private javax.swing.JButton cancelButton; + private javax.swing.JTextField hostField; + private javax.swing.JLabel hostLabel; + private javax.swing.JLabel jLabel1; + private javax.swing.JSeparator jSeparator1; + private javax.swing.JButton loadButton; + private javax.swing.JTextField localFileField; + private javax.swing.ButtonGroup localOrRemoteGroup; + private javax.swing.JRadioButton localRadioButton; + private javax.swing.JPasswordField passwordField; + private javax.swing.JLabel passwordLabel; + private javax.swing.JTextField portField; + private javax.swing.JLabel portLabel; + private javax.swing.JTextField remoteFileField; + private javax.swing.JLabel remoteFileLabel; + private javax.swing.JRadioButton remoteRadioButton; + // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/com/laytonsmith/tools/pnviewer/ManageBookmarksDialog.java b/src/main/java/com/laytonsmith/tools/pnviewer/ManageBookmarksDialog.java index 7200e41138..3bca057f28 100644 --- a/src/main/java/com/laytonsmith/tools/pnviewer/ManageBookmarksDialog.java +++ b/src/main/java/com/laytonsmith/tools/pnviewer/ManageBookmarksDialog.java @@ -129,143 +129,143 @@ private static class Bookmark { * content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - localOrRemoteGroup = new javax.swing.ButtonGroup(); - jScrollPane1 = new javax.swing.JScrollPane(); - bookmarkList = new javax.swing.JList(); - newButton = new javax.swing.JButton(); - deleteButton = new javax.swing.JButton(); - nameLabel = new javax.swing.JLabel(); - localRadioButton = new javax.swing.JRadioButton(); - localFileLabel = new javax.swing.JLabel(); - remoteRadioButton = new javax.swing.JRadioButton(); - hostLabel = new javax.swing.JLabel(); - portLabel = new javax.swing.JLabel(); - passwordLabel = new javax.swing.JLabel(); - remoteFileLabel = new javax.swing.JLabel(); - localFileField = new javax.swing.JTextField(); - hostField = new javax.swing.JTextField(); - portField = new javax.swing.JTextField(); - passwordField = new javax.swing.JPasswordField(); - remoteFileField = new javax.swing.JTextField(); - saveButton = new javax.swing.JButton(); - nameField = new javax.swing.JTextField(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - - jScrollPane1.setViewportView(bookmarkList); - - newButton.setText("New"); - - deleteButton.setText("Delete"); - - nameLabel.setText("Name"); - - localOrRemoteGroup.add(localRadioButton); - localRadioButton.setSelected(true); - localRadioButton.setText("Local"); - - localFileLabel.setText("Local File"); - - localOrRemoteGroup.add(remoteRadioButton); - remoteRadioButton.setText("Remote"); - - hostLabel.setText("Host"); - - portLabel.setText("Port"); - - passwordLabel.setText("Password"); - - remoteFileLabel.setText("Remote File"); - - saveButton.setText("Save"); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(localFileLabel) - .addGap(43, 43, 43) - .addComponent(localFileField, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)) - .addComponent(remoteRadioButton) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(hostLabel) - .addComponent(localRadioButton) - .addComponent(portLabel) - .addComponent(passwordLabel) - .addComponent(remoteFileLabel) - .addComponent(nameLabel)) - .addGap(29, 29, 29) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(hostField) - .addComponent(portField) - .addComponent(passwordField) - .addComponent(remoteFileField) - .addComponent(nameField))))) - .addGroup(layout.createSequentialGroup() - .addComponent(newButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(deleteButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(saveButton))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(nameLabel) - .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(localRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(localFileLabel) - .addComponent(localFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(18, 18, 18) - .addComponent(remoteRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(hostLabel) - .addComponent(hostField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(portLabel) - .addComponent(portField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(passwordLabel) - .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(remoteFileLabel) - .addComponent(remoteFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(0, 7, Short.MAX_VALUE))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(newButton) - .addComponent(deleteButton) - .addComponent(saveButton)) - .addContainerGap()) - ); - - pack(); - }// //GEN-END:initComponents + // //GEN-BEGIN:initComponents + private void initComponents() { + + localOrRemoteGroup = new javax.swing.ButtonGroup(); + jScrollPane1 = new javax.swing.JScrollPane(); + bookmarkList = new javax.swing.JList(); + newButton = new javax.swing.JButton(); + deleteButton = new javax.swing.JButton(); + nameLabel = new javax.swing.JLabel(); + localRadioButton = new javax.swing.JRadioButton(); + localFileLabel = new javax.swing.JLabel(); + remoteRadioButton = new javax.swing.JRadioButton(); + hostLabel = new javax.swing.JLabel(); + portLabel = new javax.swing.JLabel(); + passwordLabel = new javax.swing.JLabel(); + remoteFileLabel = new javax.swing.JLabel(); + localFileField = new javax.swing.JTextField(); + hostField = new javax.swing.JTextField(); + portField = new javax.swing.JTextField(); + passwordField = new javax.swing.JPasswordField(); + remoteFileField = new javax.swing.JTextField(); + saveButton = new javax.swing.JButton(); + nameField = new javax.swing.JTextField(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jScrollPane1.setViewportView(bookmarkList); + + newButton.setText("New"); + + deleteButton.setText("Delete"); + + nameLabel.setText("Name"); + + localOrRemoteGroup.add(localRadioButton); + localRadioButton.setSelected(true); + localRadioButton.setText("Local"); + + localFileLabel.setText("Local File"); + + localOrRemoteGroup.add(remoteRadioButton); + remoteRadioButton.setText("Remote"); + + hostLabel.setText("Host"); + + portLabel.setText("Port"); + + passwordLabel.setText("Password"); + + remoteFileLabel.setText("Remote File"); + + saveButton.setText("Save"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(localFileLabel) + .addGap(43, 43, 43) + .addComponent(localFileField, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)) + .addComponent(remoteRadioButton) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(hostLabel) + .addComponent(localRadioButton) + .addComponent(portLabel) + .addComponent(passwordLabel) + .addComponent(remoteFileLabel) + .addComponent(nameLabel)) + .addGap(29, 29, 29) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(hostField) + .addComponent(portField) + .addComponent(passwordField) + .addComponent(remoteFileField) + .addComponent(nameField))))) + .addGroup(layout.createSequentialGroup() + .addComponent(newButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(deleteButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(saveButton))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(nameLabel) + .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(localRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(localFileLabel) + .addComponent(localFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addComponent(remoteRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(hostLabel) + .addComponent(hostField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(portLabel) + .addComponent(portField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(passwordLabel) + .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(remoteFileLabel) + .addComponent(remoteFileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(0, 7, Short.MAX_VALUE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(newButton) + .addComponent(deleteButton) + .addComponent(saveButton)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents /** * @param args the command line arguments @@ -306,26 +306,26 @@ public void windowClosing(java.awt.event.WindowEvent e) { }); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JList bookmarkList; - private javax.swing.JButton deleteButton; - private javax.swing.JTextField hostField; - private javax.swing.JLabel hostLabel; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTextField localFileField; - private javax.swing.JLabel localFileLabel; - private javax.swing.ButtonGroup localOrRemoteGroup; - private javax.swing.JRadioButton localRadioButton; - private javax.swing.JTextField nameField; - private javax.swing.JLabel nameLabel; - private javax.swing.JButton newButton; - private javax.swing.JPasswordField passwordField; - private javax.swing.JLabel passwordLabel; - private javax.swing.JTextField portField; - private javax.swing.JLabel portLabel; - private javax.swing.JTextField remoteFileField; - private javax.swing.JLabel remoteFileLabel; - private javax.swing.JRadioButton remoteRadioButton; - private javax.swing.JButton saveButton; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JList bookmarkList; + private javax.swing.JButton deleteButton; + private javax.swing.JTextField hostField; + private javax.swing.JLabel hostLabel; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextField localFileField; + private javax.swing.JLabel localFileLabel; + private javax.swing.ButtonGroup localOrRemoteGroup; + private javax.swing.JRadioButton localRadioButton; + private javax.swing.JTextField nameField; + private javax.swing.JLabel nameLabel; + private javax.swing.JButton newButton; + private javax.swing.JPasswordField passwordField; + private javax.swing.JLabel passwordLabel; + private javax.swing.JTextField portField; + private javax.swing.JLabel portLabel; + private javax.swing.JTextField remoteFileField; + private javax.swing.JLabel remoteFileLabel; + private javax.swing.JRadioButton remoteRadioButton; + private javax.swing.JButton saveButton; + // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/com/laytonsmith/tools/pnviewer/PNViewer.java b/src/main/java/com/laytonsmith/tools/pnviewer/PNViewer.java index 81e42aff80..cacfad0693 100644 --- a/src/main/java/com/laytonsmith/tools/pnviewer/PNViewer.java +++ b/src/main/java/com/laytonsmith/tools/pnviewer/PNViewer.java @@ -833,212 +833,212 @@ private static interface VirtualPersistenceNetwork { * content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jSplitPane1 = new javax.swing.JSplitPane(); - jScrollPane1 = new javax.swing.JScrollPane(); - keyTree = new javax.swing.JTree(); - jPanel1 = new javax.swing.JPanel(); - jLabel1 = new javax.swing.JLabel(); - jLabel2 = new javax.swing.JLabel(); - jLabel3 = new javax.swing.JLabel(); - jLabel4 = new javax.swing.JLabel(); - namespaceLabel = new javax.swing.JLabel(); - keyLabel = new javax.swing.JLabel(); - valueTypeLabel = new javax.swing.JLabel(); - jScrollPane2 = new javax.swing.JScrollPane(); - valueTextArea = new javax.swing.JTextArea(); - jLabel6 = new javax.swing.JLabel(); - sourceLabel = new javax.swing.JLabel(); - jLabel5 = new javax.swing.JLabel(); - configurationFromLabel = new javax.swing.JLabel(); - statusLabel = new javax.swing.JLabel(); - statusProgressBar = new javax.swing.JProgressBar(); - reloadButton = new javax.swing.JButton(); - jMenuBar1 = new javax.swing.JMenuBar(); - fileMenu = new javax.swing.JMenu(); - loadFromConfigurationMenu = new javax.swing.JMenuItem(); - closeRemoteConnectionMenu = new javax.swing.JMenuItem(); - bookmarksMenu = new javax.swing.JMenu(); - manageBookmarksMenu = new javax.swing.JMenuItem(); - jSeparator1 = new javax.swing.JPopupMenu.Separator(); - jMenu1 = new javax.swing.JMenu(); - helpMenu = new javax.swing.JMenuItem(); - aboutMenu = new javax.swing.JMenuItem(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jSplitPane1.setDividerLocation(200); - - javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root"); - keyTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1)); - keyTree.setToolTipText(""); - keyTree.setRootVisible(false); - jScrollPane1.setViewportView(keyTree); - - jSplitPane1.setLeftComponent(jScrollPane1); - - jLabel1.setText("Namespace:"); - - jLabel2.setText("Key:"); - - jLabel3.setText("Value type:"); - - jLabel4.setText("Value:"); - - namespaceLabel.setText("............."); - - keyLabel.setText("............."); - - valueTypeLabel.setText("............"); - - valueTextArea.setEditable(false); - valueTextArea.setColumns(20); - valueTextArea.setFont(new java.awt.Font("Monospaced", 0, 11)); // NOI18N - valueTextArea.setLineWrap(true); - valueTextArea.setRows(5); - jScrollPane2.setViewportView(valueTextArea); - - jLabel6.setText("Source:"); - - sourceLabel.setText("..........."); - - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 722, Short.MAX_VALUE) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel4) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(namespaceLabel)) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(keyLabel)) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(jLabel6) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(sourceLabel)) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(jLabel3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(valueTypeLabel))) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - ); - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) - .addComponent(namespaceLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel2) - .addComponent(keyLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel6) - .addComponent(sourceLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel3) - .addComponent(valueTypeLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel4) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)) - ); - - jSplitPane1.setRightComponent(jPanel1); - - jLabel5.setText("Configuration from:"); - - configurationFromLabel.setText("..............."); - - statusLabel.setText("........."); - - reloadButton.setText("Reload"); - reloadButton.setToolTipText("Reloads the data from the configuration"); - - fileMenu.setText("File"); - - loadFromConfigurationMenu.setText("Load from Configuration..."); - fileMenu.add(loadFromConfigurationMenu); - - closeRemoteConnectionMenu.setText("Close Remote Connection"); - fileMenu.add(closeRemoteConnectionMenu); - - jMenuBar1.add(fileMenu); - - bookmarksMenu.setText("Bookmarks"); - - manageBookmarksMenu.setText("Manage Bookmarks..."); - bookmarksMenu.add(manageBookmarksMenu); - bookmarksMenu.add(jSeparator1); - - jMenuBar1.add(bookmarksMenu); - - jMenu1.setText("Help"); - - helpMenu.setText("Help..."); - jMenu1.add(helpMenu); - - aboutMenu.setText("About..."); - jMenu1.add(aboutMenu); - - jMenuBar1.add(jMenu1); - - setJMenuBar(jMenuBar1); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(configurationFromLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(reloadButton)) - .addGroup(layout.createSequentialGroup() - .addComponent(statusLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(statusProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel5) - .addComponent(configurationFromLabel) - .addComponent(reloadButton)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jSplitPane1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(statusProgressBar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(statusLabel, javax.swing.GroupLayout.Alignment.TRAILING)) - .addContainerGap()) - ); - - pack(); - }// //GEN-END:initComponents + // //GEN-BEGIN:initComponents + private void initComponents() { + + jSplitPane1 = new javax.swing.JSplitPane(); + jScrollPane1 = new javax.swing.JScrollPane(); + keyTree = new javax.swing.JTree(); + jPanel1 = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + namespaceLabel = new javax.swing.JLabel(); + keyLabel = new javax.swing.JLabel(); + valueTypeLabel = new javax.swing.JLabel(); + jScrollPane2 = new javax.swing.JScrollPane(); + valueTextArea = new javax.swing.JTextArea(); + jLabel6 = new javax.swing.JLabel(); + sourceLabel = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); + configurationFromLabel = new javax.swing.JLabel(); + statusLabel = new javax.swing.JLabel(); + statusProgressBar = new javax.swing.JProgressBar(); + reloadButton = new javax.swing.JButton(); + jMenuBar1 = new javax.swing.JMenuBar(); + fileMenu = new javax.swing.JMenu(); + loadFromConfigurationMenu = new javax.swing.JMenuItem(); + closeRemoteConnectionMenu = new javax.swing.JMenuItem(); + bookmarksMenu = new javax.swing.JMenu(); + manageBookmarksMenu = new javax.swing.JMenuItem(); + jSeparator1 = new javax.swing.JPopupMenu.Separator(); + jMenu1 = new javax.swing.JMenu(); + helpMenu = new javax.swing.JMenuItem(); + aboutMenu = new javax.swing.JMenuItem(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jSplitPane1.setDividerLocation(200); + + javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root"); + keyTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1)); + keyTree.setToolTipText(""); + keyTree.setRootVisible(false); + jScrollPane1.setViewportView(keyTree); + + jSplitPane1.setLeftComponent(jScrollPane1); + + jLabel1.setText("Namespace:"); + + jLabel2.setText("Key:"); + + jLabel3.setText("Value type:"); + + jLabel4.setText("Value:"); + + namespaceLabel.setText("............."); + + keyLabel.setText("............."); + + valueTypeLabel.setText("............"); + + valueTextArea.setEditable(false); + valueTextArea.setColumns(20); + valueTextArea.setFont(new java.awt.Font("Monospaced", 0, 11)); // NOI18N + valueTextArea.setLineWrap(true); + valueTextArea.setRows(5); + jScrollPane2.setViewportView(valueTextArea); + + jLabel6.setText("Source:"); + + sourceLabel.setText("..........."); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 722, Short.MAX_VALUE) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel4) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(namespaceLabel)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(keyLabel)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel6) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(sourceLabel)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(jLabel3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(valueTypeLabel))) + .addGap(0, 0, Short.MAX_VALUE))) + .addContainerGap()) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(namespaceLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(keyLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel6) + .addComponent(sourceLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(valueTypeLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel4) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)) + ); + + jSplitPane1.setRightComponent(jPanel1); + + jLabel5.setText("Configuration from:"); + + configurationFromLabel.setText("..............."); + + statusLabel.setText("........."); + + reloadButton.setText("Reload"); + reloadButton.setToolTipText("Reloads the data from the configuration"); + + fileMenu.setText("File"); + + loadFromConfigurationMenu.setText("Load from Configuration..."); + fileMenu.add(loadFromConfigurationMenu); + + closeRemoteConnectionMenu.setText("Close Remote Connection"); + fileMenu.add(closeRemoteConnectionMenu); + + jMenuBar1.add(fileMenu); + + bookmarksMenu.setText("Bookmarks"); + + manageBookmarksMenu.setText("Manage Bookmarks..."); + bookmarksMenu.add(manageBookmarksMenu); + bookmarksMenu.add(jSeparator1); + + jMenuBar1.add(bookmarksMenu); + + jMenu1.setText("Help"); + + helpMenu.setText("Help..."); + jMenu1.add(helpMenu); + + aboutMenu.setText("About..."); + jMenu1.add(aboutMenu); + + jMenuBar1.add(jMenu1); + + setJMenuBar(jMenuBar1); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel5) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(configurationFromLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(reloadButton)) + .addGroup(layout.createSequentialGroup() + .addComponent(statusLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(statusProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel5) + .addComponent(configurationFromLabel) + .addComponent(reloadButton)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSplitPane1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(statusProgressBar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(statusLabel, javax.swing.GroupLayout.Alignment.TRAILING)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents /** * @param args the command line arguments @@ -1072,36 +1072,36 @@ public void run() { }); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JMenuItem aboutMenu; - private javax.swing.JMenu bookmarksMenu; - private javax.swing.JMenuItem closeRemoteConnectionMenu; - private javax.swing.JLabel configurationFromLabel; - private javax.swing.JMenu fileMenu; - private javax.swing.JMenuItem helpMenu; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JLabel jLabel3; - private javax.swing.JLabel jLabel4; - private javax.swing.JLabel jLabel5; - private javax.swing.JLabel jLabel6; - private javax.swing.JMenu jMenu1; - private javax.swing.JMenuBar jMenuBar1; - private javax.swing.JPanel jPanel1; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JScrollPane jScrollPane2; - private javax.swing.JPopupMenu.Separator jSeparator1; - private javax.swing.JSplitPane jSplitPane1; - private javax.swing.JLabel keyLabel; - private javax.swing.JTree keyTree; - private javax.swing.JMenuItem loadFromConfigurationMenu; - private javax.swing.JMenuItem manageBookmarksMenu; - private javax.swing.JLabel namespaceLabel; - private javax.swing.JButton reloadButton; - private javax.swing.JLabel sourceLabel; - private javax.swing.JLabel statusLabel; - private javax.swing.JProgressBar statusProgressBar; - private javax.swing.JTextArea valueTextArea; - private javax.swing.JLabel valueTypeLabel; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JMenuItem aboutMenu; + private javax.swing.JMenu bookmarksMenu; + private javax.swing.JMenuItem closeRemoteConnectionMenu; + private javax.swing.JLabel configurationFromLabel; + private javax.swing.JMenu fileMenu; + private javax.swing.JMenuItem helpMenu; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; + private javax.swing.JMenu jMenu1; + private javax.swing.JMenuBar jMenuBar1; + private javax.swing.JPanel jPanel1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JPopupMenu.Separator jSeparator1; + private javax.swing.JSplitPane jSplitPane1; + private javax.swing.JLabel keyLabel; + private javax.swing.JTree keyTree; + private javax.swing.JMenuItem loadFromConfigurationMenu; + private javax.swing.JMenuItem manageBookmarksMenu; + private javax.swing.JLabel namespaceLabel; + private javax.swing.JButton reloadButton; + private javax.swing.JLabel sourceLabel; + private javax.swing.JLabel statusLabel; + private javax.swing.JProgressBar statusProgressBar; + private javax.swing.JTextArea valueTextArea; + private javax.swing.JLabel valueTypeLabel; + // End of variables declaration//GEN-END:variables } diff --git a/src/test/java/com/laytonsmith/PureUtilities/ClassLoading/GeneralTest.java b/src/test/java/com/laytonsmith/PureUtilities/ClassLoading/GeneralTest.java index f05c4819ab..8517451ab3 100644 --- a/src/test/java/com/laytonsmith/PureUtilities/ClassLoading/GeneralTest.java +++ b/src/test/java/com/laytonsmith/PureUtilities/ClassLoading/GeneralTest.java @@ -148,13 +148,11 @@ public void testAnnotationValue() throws Exception { } /* - A -> B - | - | -> C -> D - | | - | | -> F - | - | -> E + * A -> B + * | + * | -> C -> D -> F + * | + * | -> E */ public static interface A extends B, C { } diff --git a/src/test/java/com/laytonsmith/PureUtilities/ZipMakerTest.java b/src/test/java/com/laytonsmith/PureUtilities/ZipMakerTest.java index 7ef24872ad..884fdb8ae0 100644 --- a/src/test/java/com/laytonsmith/PureUtilities/ZipMakerTest.java +++ b/src/test/java/com/laytonsmith/PureUtilities/ZipMakerTest.java @@ -33,13 +33,13 @@ public void tearDown() { } //TODO: Why doesn't this work? Am I missing a resource or something? -// @Test public void testMakingZip() throws IOException, URISyntaxException{ -// ZipMaker.MakeZip(new File(resourceDir, "zippables"), "zippables.zip"); -// File zippable = new File(resourceDir, "zippables.zip"); -// assertTrue("The zip file doesn't exist!", zippable.exists()); -// File inner = new File(resourceDir, "zippables.zip/test.txt"); -// assertEquals("Hello World!", new ZipReader(inner).getFileContents().trim()); -// File innerFile = new File(resourceDir, "zippables.zip/inner/test.txt"); -// assertEquals("Hello World!", new ZipReader(innerFile).getFileContents().trim()); -// } +// @Test public void testMakingZip() throws IOException, URISyntaxException{ +// ZipMaker.MakeZip(new File(resourceDir, "zippables"), "zippables.zip"); +// File zippable = new File(resourceDir, "zippables.zip"); +// assertTrue("The zip file doesn't exist!", zippable.exists()); +// File inner = new File(resourceDir, "zippables.zip/test.txt"); +// assertEquals("Hello World!", new ZipReader(inner).getFileContents().trim()); +// File innerFile = new File(resourceDir, "zippables.zip/inner/test.txt"); +// assertEquals("Hello World!", new ZipReader(innerFile).getFileContents().trim()); +// } } diff --git a/src/test/java/com/laytonsmith/PureUtilities/ZipReaderTest.java b/src/test/java/com/laytonsmith/PureUtilities/ZipReaderTest.java index da8653784a..e5697dd7b4 100644 --- a/src/test/java/com/laytonsmith/PureUtilities/ZipReaderTest.java +++ b/src/test/java/com/laytonsmith/PureUtilities/ZipReaderTest.java @@ -37,12 +37,12 @@ public static void setUpClass() throws Exception { //TODO: Nested reads may be easier than I'm trying to make it, but either way, this //is a deeper problem, and I don't care to support this just yet. -// @Test -// public void testNestedRead() throws IOException{ -// String contents = new ZipReader(TestNestedZip).getFileContents(); -// assertNotNull("Could not read contents!", contents); -// assertEquals("Hello World!", contents.trim()); -// } +// @Test +// public void testNestedRead() throws IOException{ +// String contents = new ZipReader(TestNestedZip).getFileContents(); +// assertNotNull("Could not read contents!", contents); +// assertEquals("Hello World!", contents.trim()); +// } @Test public void testStringRead() throws FileNotFoundException, IOException { // TODO review the generated test code and remove the default call to fail. diff --git a/src/test/java/com/laytonsmith/core/MethodScriptCompilerTest.java b/src/test/java/com/laytonsmith/core/MethodScriptCompilerTest.java index 04c6f4ba86..558a148487 100644 --- a/src/test/java/com/laytonsmith/core/MethodScriptCompilerTest.java +++ b/src/test/java/com/laytonsmith/core/MethodScriptCompilerTest.java @@ -444,40 +444,40 @@ public void testCompile1() { } } -// @Test -// public void testCompileWithDoubleSlashCommand() throws Exception{ -// AliasCore ac = mock(AliasCore.class); -// ac.autoIncludes = new ArrayList(); -// PowerMockito.mockStatic(CommandHelperPlugin.class); -// when(CommandHelperPlugin.getCore()).thenReturn(ac); -// assertEquals(ac, CommandHelperPlugin.getCore()); -// String config = "//cmd blah = msg('success')"; -// Script s = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null, false)).get(0); -// s.compile(); -// env.getEnv(CommandHelperEnvironment.class).SetPlayer(fakePlayer); -// s.run(Arrays.asList(new Variable("$var", "hello", Target.UNKNOWN)), env, null); -// verify(fakePlayer).sendMessage("success"); -// } +// @Test +// public void testCompileWithDoubleSlashCommand() throws Exception{ +// AliasCore ac = mock(AliasCore.class); +// ac.autoIncludes = new ArrayList(); +// PowerMockito.mockStatic(CommandHelperPlugin.class); +// when(CommandHelperPlugin.getCore()).thenReturn(ac); +// assertEquals(ac, CommandHelperPlugin.getCore()); +// String config = "//cmd blah = msg('success')"; +// Script s = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null, false)).get(0); +// s.compile(); +// env.getEnv(CommandHelperEnvironment.class).SetPlayer(fakePlayer); +// s.run(Arrays.asList(new Variable("$var", "hello", Target.UNKNOWN)), env, null); +// verify(fakePlayer).sendMessage("success"); +// } // -// @Test -// public void testCompileTwoAliases() throws Exception{ -// AliasCore ac = mock(AliasCore.class); -// ac.autoIncludes = new ArrayList(); -// PowerMockito.mockStatic(CommandHelperPlugin.class); -// when(CommandHelperPlugin.getCore()).thenReturn(ac); -// assertEquals(ac, CommandHelperPlugin.getCore()); -// String config = "/cmd1 = msg('success')\n" -// + " \n" //Spaces and tabs are here -// + "/cmd2 = msg('success')"; -// env.getEnv(CommandHelperEnvironment.class).SetPlayer(fakePlayer); -// Script s1 = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null, false)).get(0); -// s1.compile(); -// s1.run(Arrays.asList(new Variable("$var", "hello", Target.UNKNOWN)), env, null); -// Script s2 = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null, false)).get(1); -// s2.compile(); -// s2.run(Arrays.asList(new Variable("$var", "hello", Target.UNKNOWN)), env, null); -// verify(fakePlayer, times(2)).sendMessage("success"); -// } +// @Test +// public void testCompileTwoAliases() throws Exception{ +// AliasCore ac = mock(AliasCore.class); +// ac.autoIncludes = new ArrayList(); +// PowerMockito.mockStatic(CommandHelperPlugin.class); +// when(CommandHelperPlugin.getCore()).thenReturn(ac); +// assertEquals(ac, CommandHelperPlugin.getCore()); +// String config = "/cmd1 = msg('success')\n" +// + " \n" //Spaces and tabs are here +// + "/cmd2 = msg('success')"; +// env.getEnv(CommandHelperEnvironment.class).SetPlayer(fakePlayer); +// Script s1 = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null, false)).get(0); +// s1.compile(); +// s1.run(Arrays.asList(new Variable("$var", "hello", Target.UNKNOWN)), env, null); +// Script s2 = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null, false)).get(1); +// s2.compile(); +// s2.run(Arrays.asList(new Variable("$var", "hello", Target.UNKNOWN)), env, null); +// verify(fakePlayer, times(2)).sendMessage("success"); +// } @Test public void testCompile2() { try { @@ -527,36 +527,36 @@ public void testCompile7() throws Exception { } //TODO: Make these tests possible -// @Test -// public void testCompile8() throws Exception { -// String config = "/cmd $one $ = >>>\n" -// + "msg($one) \\ msg($)" -// + "<<<"; +// @Test +// public void testCompile8() throws Exception { +// String config = "/cmd $one $ = >>>\n" +// + "msg($one) \\ msg($)" +// + "<<<"; // -// RunVars(Arrays.asList(new Variable[]{new Variable("$one", "first", false, false, Target.UNKNOWN), -// new Variable("$", "several variables", false, true, Target.UNKNOWN)}), config, fakePlayer); -// Script s = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null), env).get(0); -// s.compile(); -// s.run(Arrays.asList(new Variable[]{new Variable("$one", "first", false, false, Target.UNKNOWN), -// new Variable("$", "several variables", false, true, Target.UNKNOWN)}), env, null); -// verify(fakePlayer).sendMessage("first"); -// verify(fakePlayer).sendMessage("several variables"); -// } +// RunVars(Arrays.asList(new Variable[]{new Variable("$one", "first", false, false, Target.UNKNOWN), +// new Variable("$", "several variables", false, true, Target.UNKNOWN)}), config, fakePlayer); +// Script s = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null), env).get(0); +// s.compile(); +// s.run(Arrays.asList(new Variable[]{new Variable("$one", "first", false, false, Target.UNKNOWN), +// new Variable("$", "several variables", false, true, Target.UNKNOWN)}), env, null); +// verify(fakePlayer).sendMessage("first"); +// verify(fakePlayer).sendMessage("several variables"); +// } // -// @Test -// public void testCompile9() throws Exception { -// String config = "/test [$var=1] = >>>\n" -// + "msg($var)" -// + "<<<"; -// Script s = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null), env).get(0); -// s.compile(); -// assertTrue(s.match("/test 2")); -// s.run(Arrays.asList(new Variable[]{new Variable("$var", "2", true, false, Target.UNKNOWN)}), env, null); -// verify(fakePlayer).sendMessage("2"); -// assertTrue(s.match("/test")); -// s.run(new ArrayList(), env, null); -// verify(fakePlayer).sendMessage("1"); -// } +// @Test +// public void testCompile9() throws Exception { +// String config = "/test [$var=1] = >>>\n" +// + "msg($var)" +// + "<<<"; +// Script s = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null), env).get(0); +// s.compile(); +// assertTrue(s.match("/test 2")); +// s.run(Arrays.asList(new Variable[]{new Variable("$var", "2", true, false, Target.UNKNOWN)}), env, null); +// verify(fakePlayer).sendMessage("2"); +// assertTrue(s.match("/test")); +// s.run(new ArrayList(), env, null); +// verify(fakePlayer).sendMessage("1"); +// } @Test public void testCompile10() throws Exception { String config = "/test $var = >>>\n" @@ -570,24 +570,24 @@ public void testCompile10() throws Exception { } //TODO: Make this test possible -// @Test public void testCompile11() throws Exception{ +// @Test public void testCompile11() throws Exception{ // -// CommandHelperPlugin.perms = mock(PermissionsResolverManager.class); -// when(CommandHelperPlugin.perms.hasPermission(fakePlayer.getVariableName(), "ch.alias.safe")).thenReturn(true); -// CommandHelperPlugin.myServer = fakeServer; -// when(fakeServer.getOnlinePlayers()).thenReturn(new MCPlayer[]{fakePlayer}); -// String config = "safe:/test $var = >>>\n" -// + "all_players()\n" -// + "msg($var)\n" -// + "<<<"; -// Script s = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null), env).get(0); -// s.compile(); -// assertEquals("safe", s.getLabel()); -// assertTrue(s.match("/test 2")); -// s.run(Arrays.asList(new Variable[]{new Variable("$var", "2", true, false, Target.UNKNOWN)}), env, null); -// verify(fakePlayer).sendMessage("2"); -// verify(CommandHelperPlugin.perms).hasPermission(fakePlayer.getVariableName(), "ch.alias.safe"); -// } +// CommandHelperPlugin.perms = mock(PermissionsResolverManager.class); +// when(CommandHelperPlugin.perms.hasPermission(fakePlayer.getVariableName(), "ch.alias.safe")).thenReturn(true); +// CommandHelperPlugin.myServer = fakeServer; +// when(fakeServer.getOnlinePlayers()).thenReturn(new MCPlayer[]{fakePlayer}); +// String config = "safe:/test $var = >>>\n" +// + "all_players()\n" +// + "msg($var)\n" +// + "<<<"; +// Script s = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(config, null), env).get(0); +// s.compile(); +// assertEquals("safe", s.getLabel()); +// assertTrue(s.match("/test 2")); +// s.run(Arrays.asList(new Variable[]{new Variable("$var", "2", true, false, Target.UNKNOWN)}), env, null); +// verify(fakePlayer).sendMessage("2"); +// verify(CommandHelperPlugin.perms).hasPermission(fakePlayer.getVariableName(), "ch.alias.safe"); +// } @Test public void testCompile12() throws Exception { String config = "/*/one = bad()*/\n" @@ -726,17 +726,17 @@ public void testCompileErrorOfStaticConstructOptimization() throws Exception { // If people complain that the old format is broken, I can see about re-adding this. For now, // this is covered in the other exception handler test -// @Test public void testLineNumberCorrectInException1() throws Exception{ -// String script = -// "try(\n" //Line 1 -// + "assign(@a, array(1, 2))\n" //Line 2 -// + "\n" //Line 3 -// + "assign(@d, @a[2])\n" //Line 4 -// + "\n" //Line 5 -// + ", @e, msg(@e))\n"; //Line 6 -// SRun(script, fakePlayer); -// verify(fakePlayer).sendMessage("4"); -// } +// @Test public void testLineNumberCorrectInException1() throws Exception{ +// String script = +// "try(\n" //Line 1 +// + "assign(@a, array(1, 2))\n" //Line 2 +// + "\n" //Line 3 +// + "assign(@d, @a[2])\n" //Line 4 +// + "\n" //Line 5 +// + ", @e, msg(@e))\n"; //Line 6 +// SRun(script, fakePlayer); +// verify(fakePlayer).sendMessage("4"); +// } @Test public void testLineNumberCorrectInException2() throws Exception { String script @@ -981,23 +981,23 @@ public void testWhitespaceAroundSymbol1() throws Exception { // } //TODO: Once the lexer is rewritten, this should work -// @Test -// public void testAssignmentWithEquals1() throws Exception{ -// SRun("@var=yep nope msg(@var)", fakePlayer); -// verify(fakePlayer).sendMessage("yep"); -// } +// @Test +// public void testAssignmentWithEquals1() throws Exception{ +// SRun("@var=yep nope msg(@var)", fakePlayer); +// verify(fakePlayer).sendMessage("yep"); +// } // -// @Test -// public void testAssignmentWithEquals2() throws Exception{ -// SRun("@var = yep nope msg(@var)", fakePlayer); -// verify(fakePlayer).sendMessage("yep"); -// } +// @Test +// public void testAssignmentWithEquals2() throws Exception{ +// SRun("@var = yep nope msg(@var)", fakePlayer); +// verify(fakePlayer).sendMessage("yep"); +// } // -// @Test -// public void testAssignmentWithEquals3() throws Exception{ -// SRun("@var = 'yep yep' msg(@var)", fakePlayer); -// verify(fakePlayer).sendMessage("yep yep"); -// } +// @Test +// public void testAssignmentWithEquals3() throws Exception{ +// SRun("@var = 'yep yep' msg(@var)", fakePlayer); +// verify(fakePlayer).sendMessage("yep yep"); +// } @Test @Ignore("Ignore for now, until the feature is implemented") public void testLiteralDecimal() throws Exception { diff --git a/src/test/java/com/laytonsmith/core/NewExceptionHandlingTest.java b/src/test/java/com/laytonsmith/core/NewExceptionHandlingTest.java index de654791dd..f86d99365c 100644 --- a/src/test/java/com/laytonsmith/core/NewExceptionHandlingTest.java +++ b/src/test/java/com/laytonsmith/core/NewExceptionHandlingTest.java @@ -243,7 +243,7 @@ public void testCausedBy() throws Exception { /* 13 */ + "} catch(CastException @e){\n" /* 14 */ + " msg(@e);\n" /* 15 */ + "}\n", - fakePlayer); + fakePlayer); verify(fakePlayer).sendMessage( "{" + "causedBy: {" diff --git a/src/test/java/com/laytonsmith/core/OptimizationTest.java b/src/test/java/com/laytonsmith/core/OptimizationTest.java index 859ed592f1..504ee6614a 100644 --- a/src/test/java/com/laytonsmith/core/OptimizationTest.java +++ b/src/test/java/com/laytonsmith/core/OptimizationTest.java @@ -67,32 +67,32 @@ public void testMultipleLinesInBraces() throws Exception { } //TODO: These tests are not intended to be corrected in master, so I'm removing them for now -// @Test public void testProcOptimization1() throws Exception{ -// //The proc stays there, but the call to it should be consolidated -// assertEquals("sconcat(proc('_add',@a,@b,return(add(@a,@b))),4)", optimize("proc(_add, @a, @b, return(@a + @b)) _add(2, 2)")); -// } +// @Test public void testProcOptimization1() throws Exception{ +// //The proc stays there, but the call to it should be consolidated +// assertEquals("sconcat(proc('_add',@a,@b,return(add(@a,@b))),4)", optimize("proc(_add, @a, @b, return(@a + @b)) _add(2, 2)")); +// } @Test public void testProcOptimizationRecursion() throws Exception { assertEquals("sconcat(proc('_loop',@a,if(gt(@a,0),_loop(subtract(@a,1)),return(@a))),_loop(2))", optimize("proc(_loop, @a, if(@a > 0, _loop(@a - 1), return(@a))) _loop(2)")); } -// @Test(expected=ConfigCompileException.class) -// public void testProcOptimization2() throws Exception{ -// optimize("proc(_divide, @a, return(@a / 0)) _divide(1)"); -// } +// @Test(expected=ConfigCompileException.class) +// public void testProcOptimization2() throws Exception{ +// optimize("proc(_divide, @a, return(@a / 0)) _divide(1)"); +// } @Test public void testProcOptimization3() throws Exception { //Rather, lack of optimization assertEquals("sconcat(proc('_nope',msg('Hi')),_nope())", optimize("proc(_nope, msg('Hi')) _nope()")); } -// @Test -// public void testProcOptimiztion4() throws Exception{ -// //Test embedded procs -// assertEquals("sconcat(proc('_outer',sconcat(proc('_inner',@a,return(@a)),'blah')),_inner('huh'))", -// optimize("proc(_outer, proc(_inner, @a, return(@a)) _inner('blah')) _inner('huh')")); -// } +// @Test +// public void testProcOptimiztion4() throws Exception{ +// //Test embedded procs +// assertEquals("sconcat(proc('_outer',sconcat(proc('_inner',@a,return(@a)),'blah')),_inner('huh'))", +// optimize("proc(_outer, proc(_inner, @a, return(@a)) _inner('blah')) _inner('huh')")); +// } @Test public void testProcReturn() throws Exception { assertEquals("sconcat(proc('_proc',return(array(1))),array_get(_proc(),0))", @@ -314,28 +314,28 @@ public void testMinusWithoutValueInFront() throws Exception { } //TODO: This is a bit ambitious for now, put this back at some point, and then make it pass. -// @Test public void testAssign() throws Exception{ -// //In this test, there's no way it won't ever be 'hi', so do a replacement (we still need to keep -// //the assign, because it does need to go into the variable table for reflective purposes) -// assertEquals("sconcat(assign(@a,'hi'),msg('hi'))", optimize("assign(@a, 'hi') msg(@a)")); -// //In this case, the first use may be hardcoded, but after the if, it may have changed, so we -// //can no longer assume it's always going to be 'hi' -// assertEquals("sconcat(assign(@a,'hi'),msg('hi'),if(dyn(),assign(@a,'bye')),msg(@a))", -// optimize("" -// + "assign(@a, 'hi')" -// + "msg(@a)" -// + "if(dyn(), assign(@a, 'bye'))" -// + "msg(@a)")); -// //In this case, we have a worthless assignment; We know @a is already 'hi' and it's always going -// //to be that, and we're trying to assign 'hi' again, so we can completely remove this from -// //the code, at which point the last msg can be optimized. -// assertEquals("sconcat(assign(@a,'hi'),msg('hi'),if(dyn(),null),msg('hi'))", -// optimize("" -// + "assign(@a, 'hi')" -// + "msg(@a)" -// + "if(dyn(), assign(@a, 'hi'))" -// + "msg(@a)")); -// } +// @Test public void testAssign() throws Exception{ +// //In this test, there's no way it won't ever be 'hi', so do a replacement (we still need to keep +// //the assign, because it does need to go into the variable table for reflective purposes) +// assertEquals("sconcat(assign(@a,'hi'),msg('hi'))", optimize("assign(@a, 'hi') msg(@a)")); +// //In this case, the first use may be hardcoded, but after the if, it may have changed, so we +// //can no longer assume it's always going to be 'hi' +// assertEquals("sconcat(assign(@a,'hi'),msg('hi'),if(dyn(),assign(@a,'bye')),msg(@a))", +// optimize("" +// + "assign(@a, 'hi')" +// + "msg(@a)" +// + "if(dyn(), assign(@a, 'bye'))" +// + "msg(@a)")); +// //In this case, we have a worthless assignment; We know @a is already 'hi' and it's always going +// //to be that, and we're trying to assign 'hi' again, so we can completely remove this from +// //the code, at which point the last msg can be optimized. +// assertEquals("sconcat(assign(@a,'hi'),msg('hi'),if(dyn(),null),msg('hi'))", +// optimize("" +// + "assign(@a, 'hi')" +// + "msg(@a)" +// + "if(dyn(), assign(@a, 'hi'))" +// + "msg(@a)")); +// } @Test public void testNotinstanceofKeyword() throws Exception { assertEquals("msg(not(instanceof(dyn(2),int)))", optimize("msg(dyn(2) notinstanceof int);")); diff --git a/src/test/java/com/laytonsmith/core/ScriptTest.java b/src/test/java/com/laytonsmith/core/ScriptTest.java index 04603dd2b3..9a9b042cce 100644 --- a/src/test/java/com/laytonsmith/core/ScriptTest.java +++ b/src/test/java/com/laytonsmith/core/ScriptTest.java @@ -30,98 +30,98 @@ public void setUp() { public void tearDown() { } -// @Test -// public void testToString() { -// System.out.println("toString"); -// Script instance = new Script(null, null); -// assertTrue(instance.toString().length() > 0); -// } -// @Test -// public void testUncompilable() { -// System.out.println("uncompilable"); -// Script instance = null; -// boolean expResult = false; -// boolean result = instance.uncompilable(); -// assertEquals(expResult, result); -// // TODO review the generated test code and remove the default call to fail. -// fail("The test case is a prototype."); -// } +// @Test +// public void testToString() { +// System.out.println("toString"); +// Script instance = new Script(null, null); +// assertTrue(instance.toString().length() > 0); +// } +// @Test +// public void testUncompilable() { +// System.out.println("uncompilable"); +// Script instance = null; +// boolean expResult = false; +// boolean result = instance.uncompilable(); +// assertEquals(expResult, result); +// // TODO review the generated test code and remove the default call to fail. +// fail("The test case is a prototype."); +// } // -// @Test -// public void testRun() { -// System.out.println("run"); -// List vars = null; -// Player p = null; -// MethodScriptComplete done = null; -// Script instance = null; -// instance.run(vars, p, done); -// // TODO review the generated test code and remove the default call to fail. -// fail("The test case is a prototype."); -// } +// @Test +// public void testRun() { +// System.out.println("run"); +// List vars = null; +// Player p = null; +// MethodScriptComplete done = null; +// Script instance = null; +// instance.run(vars, p, done); +// // TODO review the generated test code and remove the default call to fail. +// fail("The test case is a prototype."); +// } // -// @Test -// public void testEval() throws Exception { -// System.out.println("eval"); -// GenericTreeNode c = null; -// Player player = null; -// List vars = null; -// Script instance = null; -// Construct expResult = null; -// Construct result = instance.eval(c, player, vars); -// assertEquals(expResult, result); -// // TODO review the generated test code and remove the default call to fail. -// fail("The test case is a prototype."); -// } +// @Test +// public void testEval() throws Exception { +// System.out.println("eval"); +// GenericTreeNode c = null; +// Player player = null; +// List vars = null; +// Script instance = null; +// Construct expResult = null; +// Construct result = instance.eval(c, player, vars); +// assertEquals(expResult, result); +// // TODO review the generated test code and remove the default call to fail. +// fail("The test case is a prototype."); +// } // -// @Test -// public void testMatch() { -// System.out.println("match"); -// String command = ""; -// Script instance = null; -// boolean expResult = false; -// boolean result = instance.match(command); -// assertEquals(expResult, result); -// // TODO review the generated test code and remove the default call to fail. -// fail("The test case is a prototype."); -// } +// @Test +// public void testMatch() { +// System.out.println("match"); +// String command = ""; +// Script instance = null; +// boolean expResult = false; +// boolean result = instance.match(command); +// assertEquals(expResult, result); +// // TODO review the generated test code and remove the default call to fail. +// fail("The test case is a prototype."); +// } // -// @Test -// public void testGetVariables() { -// System.out.println("getVariables"); -// String command = ""; -// Script instance = null; -// List expResult = null; -// List result = instance.getVariables(command); -// assertEquals(expResult, result); -// // TODO review the generated test code and remove the default call to fail. -// fail("The test case is a prototype."); -// } +// @Test +// public void testGetVariables() { +// System.out.println("getVariables"); +// String command = ""; +// Script instance = null; +// List expResult = null; +// List result = instance.getVariables(command); +// assertEquals(expResult, result); +// // TODO review the generated test code and remove the default call to fail. +// fail("The test case is a prototype."); +// } // -// @Test -// public void testCompile() throws Exception { -// System.out.println("compile"); -// Script instance = null; -// instance.compile(); -// // TODO review the generated test code and remove the default call to fail. -// fail("The test case is a prototype."); -// } +// @Test +// public void testCompile() throws Exception { +// System.out.println("compile"); +// Script instance = null; +// instance.compile(); +// // TODO review the generated test code and remove the default call to fail. +// fail("The test case is a prototype."); +// } // -// @Test -// public void testCompileRight() throws Exception { -// System.out.println("compileRight"); -// Script instance = null; -// instance.compileRight(); -// // TODO review the generated test code and remove the default call to fail. -// fail("The test case is a prototype."); -// } +// @Test +// public void testCompileRight() throws Exception { +// System.out.println("compileRight"); +// Script instance = null; +// instance.compileRight(); +// // TODO review the generated test code and remove the default call to fail. +// fail("The test case is a prototype."); +// } // -// @Test -// public void testCheckAmbiguous() throws Exception { -// System.out.println("checkAmbiguous"); -// ArrayList