Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatter: remove multiple duplicated, add additional spaces in some cases #1037

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,69 @@ public class GroovyTokenTypeBridge {
// Only the GroovyTokenTypes that we use inside Greclipse are represented here.
// More can be added on an as needed basis.

public static int IDENT = GroovyTokenTypes.IDENT;
public static int LBRACK = GroovyTokenTypes.LBRACK;
public static int LCURLY = GroovyTokenTypes.LCURLY;
public static int LPAREN = GroovyTokenTypes.LPAREN;
public static int RPAREN = GroovyTokenTypes.RPAREN;
public static int RBRACK = GroovyTokenTypes.RBRACK;
public static int RCURLY = GroovyTokenTypes.RCURLY;
public static int STRING_CTOR_START = GroovyTokenTypes.STRING_CTOR_START;
public static int STRING_CTOR_END = GroovyTokenTypes.STRING_CTOR_END;
public static int COMMA = GroovyTokenTypes.COMMA;
public static int SEMI = GroovyTokenTypes.SEMI;
public static int EOF = GroovyTokenTypes.EOF;
public static int NLS = GroovyTokenTypes.NLS;
public static int WS = GroovyTokenTypes.WS;
public static int ML_COMMENT = GroovyTokenTypes.ML_COMMENT;
public static int SL_COMMENT = GroovyTokenTypes.SL_COMMENT;
public static int CLOSABLE_BLOCK_OP = GroovyTokenTypes.CLOSABLE_BLOCK_OP;
public static int LITERAL_as = GroovyTokenTypes.LITERAL_as;
public static int LITERAL_if = GroovyTokenTypes.LITERAL_if;
public static int LITERAL_else = GroovyTokenTypes.LITERAL_else;
public static int LITERAL_for = GroovyTokenTypes.LITERAL_for;
public static int LITERAL_switch = GroovyTokenTypes.LITERAL_switch;
public static int LITERAL_while = GroovyTokenTypes.LITERAL_while;
public static int ASSIGN = GroovyTokenTypes.ASSIGN;
public static int IDENT = GroovyTokenTypes.IDENT;
public static int LBRACK = GroovyTokenTypes.LBRACK;
public static int LCURLY = GroovyTokenTypes.LCURLY;
public static int LPAREN = GroovyTokenTypes.LPAREN;
public static int RPAREN = GroovyTokenTypes.RPAREN;
public static int RBRACK = GroovyTokenTypes.RBRACK;
public static int RCURLY = GroovyTokenTypes.RCURLY;
public static int STRING_CTOR_START = GroovyTokenTypes.STRING_CTOR_START;
public static int STRING_CTOR_END = GroovyTokenTypes.STRING_CTOR_END;
public static int COMMA = GroovyTokenTypes.COMMA;
public static int SEMI = GroovyTokenTypes.SEMI;
public static int EOF = GroovyTokenTypes.EOF;
public static int NLS = GroovyTokenTypes.NLS;
public static int WS = GroovyTokenTypes.WS;
public static int ML_COMMENT = GroovyTokenTypes.ML_COMMENT;
public static int SL_COMMENT = GroovyTokenTypes.SL_COMMENT;
public static int CLOSABLE_BLOCK_OP = GroovyTokenTypes.CLOSABLE_BLOCK_OP;
public static int LITERAL_as = GroovyTokenTypes.LITERAL_as;
public static int GT = GroovyTokenTypes.GT;
public static int LT = GroovyTokenTypes.LT;
public static int GE = GroovyTokenTypes.GE;
public static int LE = GroovyTokenTypes.LE;
public static int LITERAL_if = GroovyTokenTypes.LITERAL_if;
public static int LITERAL_else = GroovyTokenTypes.LITERAL_else;
public static int LITERAL_for = GroovyTokenTypes.LITERAL_for;
public static int LITERAL_switch = GroovyTokenTypes.LITERAL_switch;
public static int LITERAL_while = GroovyTokenTypes.LITERAL_while;
public static int LITERAL_class = GroovyTokenTypes.LITERAL_class;
public static int LITERAL_interface = GroovyTokenTypes.LITERAL_interface;
public static int LITERAL_public = GroovyTokenTypes.LITERAL_public;
public static int LITERAL_private = GroovyTokenTypes.LITERAL_private;
public static int LITERAL_protected = GroovyTokenTypes.LITERAL_protected;
public static int LITERAL_assert = GroovyTokenTypes.LITERAL_assert;
public static int LITERAL_def = GroovyTokenTypes.LITERAL_def;
public static int LITERAL_transient = GroovyTokenTypes.LITERAL_transient;
public static int LITERAL_native = GroovyTokenTypes.LITERAL_native;
public static int LITERAL_threadsafe = GroovyTokenTypes.LITERAL_threadsafe;
public static int LITERAL_synchronized = GroovyTokenTypes.LITERAL_synchronized;
public static int LITERAL_volatile = GroovyTokenTypes.LITERAL_volatile;
public static int LITERAL_static = GroovyTokenTypes.LITERAL_static;
public static int LITERAL_package = GroovyTokenTypes.LITERAL_package;
public static int LITERAL_extends = GroovyTokenTypes.LITERAL_extends;
public static int LITERAL_implements = GroovyTokenTypes.LITERAL_implements;
public static int LITERAL_return = GroovyTokenTypes.LITERAL_return;
public static int LITERAL_void = GroovyTokenTypes.LITERAL_void;
public static int LITERAL_boolean = GroovyTokenTypes.LITERAL_boolean;
public static int LITERAL_byte = GroovyTokenTypes.LITERAL_byte;
public static int LITERAL_char = GroovyTokenTypes.LITERAL_char;
public static int LITERAL_short = GroovyTokenTypes.LITERAL_short;
public static int LITERAL_int = GroovyTokenTypes.LITERAL_int;
public static int LITERAL_float = GroovyTokenTypes.LITERAL_float;
public static int LITERAL_long = GroovyTokenTypes.LITERAL_long;
public static int LITERAL_double = GroovyTokenTypes.LITERAL_double;
public static int ABSTRACT = GroovyTokenTypes.ABSTRACT;
public static int NOT_EQUAL = GroovyTokenTypes.NOT_EQUAL;
public static int EQUAL = GroovyTokenTypes.EQUAL;
public static int NUM_INT = GroovyTokenTypes.NUM_INT;
public static int NUM_FLOAT = GroovyTokenTypes.NUM_FLOAT;
public static int NUM_LONG = GroovyTokenTypes.NUM_LONG;
public static int NUM_DOUBLE = GroovyTokenTypes.NUM_DOUBLE;
public static int NUM_BIG_INT = GroovyTokenTypes.NUM_BIG_INT;
public static int NUM_BIG_DECIMAL = GroovyTokenTypes.NUM_BIG_DECIMAL;
public static int STRING_LITERAL = GroovyTokenTypes.STRING_LITERAL;
public static int COLON = GroovyTokenTypes.COLON;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def test1 () {
###exp
class FormatTest {

def test () {}
def test() {}

def test1 () {
def test1() {
}
}
###end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def foo= { ->
}
foo()
###exp
def foo= {
def foo = {
->
if(true) {
// fragile!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ setPreferences=true
]
###exp
[
a:1,
b:2
a: 1,
b: 2
]
###end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def message = "${foo([])}"
###exp
class FormatTest {

def test () {
def test() {
def message = "${foo([])}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ b) {

class SomeClass {
@Blart(
value1='',
value2='',
value3=''
value1 = '',
value2 = '',
value3 = ''
)
def foo(
s,j,
s, j,
k) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ println 'hello'
}

###exp
String appPath,controller,clazz
new File(appPath,controller).eachLine { String line->
String appPath, controller, clazz
new File(appPath, controller).eachLine { String line->
if(line=~/def index = \{ \}/) {
// fragile!
println 'hello'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ println "hoi"
###exp
class Bongo {

def FLAVOURS = [all:'.all',tiny:'.tiny',form:'.form']
def FLAVOURS = [all: '.all', tiny: '.tiny', form: '.form']
def a = "Flavour must be in: ${FLAVOURS.collect{it.key}}"

def main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
###prop
setPreferences=true
bracesEnd=next
###src
package org.test

public abstract class EmailCommand extends Command implements Serializable , ICommand {
@Annotation ( value = "test" , a=1 )
@Annotation2 ( )
@Annotation3( "test" )
def foo ( int a , Map<String,List<Integer>> collection ) {
def array = [ 1, 2 ]

if ( array.length >= 3 ) {
println "test"
}

def a=i<2
def b=1<2

return 1 <2 && 2>= 1
}
}
###exp
package org.test

public abstract class EmailCommand extends Command implements Serializable,
ICommand {
@Annotation(value = "test", a = 1)
@Annotation2()
@Annotation3("test")
def foo(int a, Map<String, List<Integer>> collection) {
def array = [1, 2]

if (array.length >= 3) {
println "test"
}

def a = i<2
def b = 1<2

return 1 <2 && 2 >= 1
}
}
###end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class EmailCommand {
}
###exp
class EmailCommand {
def foo () {
def foo() {
return 1
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
@SuppressWarnings("deprecation")
public class DefaultGroovyFormatter extends GroovyFormatter {

private static final boolean DEBUG = true;

protected IFormatterPreferences pref;
private ModuleNode rootNode;

Expand Down Expand Up @@ -139,6 +141,10 @@ public TextEdit format() {
GroovyCore.logWarning("Cannot format, probably due to compilation errors. Please fix and try again.", e);
}

if (DEBUG) {
System.out.println(formattedDocument.get());
}

if (formattedDocument.get().equals(document.get())) {
return new MultiTextEdit();
}
Expand Down
Loading