Skip to content

Commit

Permalink
jline-groovy: minor fixes & code reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Aug 30, 2020
1 parent 36f8ecd commit 19fedee
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 72 deletions.
10 changes: 5 additions & 5 deletions groovy/src/main/groovy/org/jline/groovy/ObjectInspector.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
*/
package org.jline.groovy

import java.lang.reflect.*
import groovy.inspect.Inspector

public class ObjectInspector {
class ObjectInspector {
public static final List<String> METHOD_COLUMNS = ['language','modifiers','this','return','name','parameters','exception','8']
def obj
def inspector

public ObjectInspector(def obj) {
ObjectInspector(def obj) {
this.obj = obj
this.inspector = new groovy.inspect.Inspector(obj)
this.inspector = new Inspector(obj)
}

List<Map<String, String>> methods() {
Expand All @@ -37,7 +37,7 @@ public class ObjectInspector {
inspector.metaMethods.each {
def mdef = [:]
for (int i = 0; i < it.size(); i++) {
mdef.put(METHOD_COLUMNS.get(i),it.getAt(i))
mdef.put(METHOD_COLUMNS.get(i), it.getAt(i))
}
out.add(mdef)
}
Expand Down
7 changes: 3 additions & 4 deletions groovy/src/main/groovy/org/jline/groovy/Utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
*
* https://opensource.org/licenses/BSD-3-Clause
*/
package org.jline.groovy;
package org.jline.groovy

import java.nio.charset.StandardCharsets
import java.nio.file.Path
import org.jline.script.GroovyEngine.Format
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.json.JsonParserType

public class Utils {
class Utils {

private Utils() {}

Expand Down Expand Up @@ -57,7 +56,7 @@ public class Utils {
} else if (format == Format.NONE) {
file.toFile().write(toString(object))
} else {
throw new IllegalArgumentException();
throw new IllegalArgumentException()
}
}

Expand Down
14 changes: 8 additions & 6 deletions groovy/src/main/java/org/jline/script/GroovyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
public class GroovyCommand extends AbstractCommandRegistry implements CommandRegistry {
public enum Command {INSPECT, CONSOLE, GRAB}
private static final String DEFAULT_NANORC_VALUE = "classpath:/org/jline/groovy/gron.nanorc";
private GroovyEngine engine;
private Printer printer;
private final GroovyEngine engine;
private final Printer printer;
private final Map<Command,CmdDesc> commandDescs = new HashMap<>();
private final Map<Command,List<String>> commandInfos = new HashMap<>();
private boolean consoleUi;
Expand All @@ -56,14 +56,16 @@ public GroovyCommand(Set<Command> commands, GroovyEngine engine, Printer printer
Class.forName("groovy.console.ui.ObjectBrowser");
consoleUi = true;
} catch (Exception e) {
// ignore
}
try {
Class.forName("org.apache.ivy.util.Message");
System.setProperty("groovy.grape.report.downloads","false");
ivy = true;
} catch (Exception e) {
// ignore
}
Set<Command> cmds = new HashSet<>();
Set<Command> cmds;
Map<Command,String> commandName = new HashMap<>();
Map<Command,CommandMethods> commandExecute = new HashMap<>();
if (commands == null) {
Expand Down Expand Up @@ -181,7 +183,7 @@ public Object inspect(CommandInput input) {
if (input.args().length > 2) {
throw new IllegalArgumentException("Wrong number of command parameters: " + input.args().length);
}
int idx = optionIdx(Command.INSPECT, input.args());
int idx = optionIdx(input.args());
String option = idx < 0 ? "--info" : input.args()[idx];
if (option.equals("-?") || option.equals("--help")) {
printer.println(helpDesc(Command.INSPECT));
Expand Down Expand Up @@ -283,9 +285,9 @@ private List<AttributedString> doDescription(String description) {
return out;
}

private int optionIdx(Command cmd, String[] args) {
private int optionIdx(String[] args) {
int out = 0;
for (String a : args) {
int out = 0;
if (a.startsWith("-")) {
return out;
}
Expand Down
Loading

0 comments on commit 19fedee

Please sign in to comment.