aphex
aphex

Reputation: 3412

Recursive indentation in XTend

Is it possible to control the indentation of recursive called methods in xtend? I have the following case:

def generateField(Field field)
    '''
    field «field.name» {
        description '«field.description»'
        label '«field.label»'
        «FOR alias : field.aliases BEFORE ' aliases {\n' SEPARATOR ',' AFTER '\n}'»
            «var f = alias.value as Field»«generateField(f)»
        «ENDFOR»
    }
    '''

The generated content looks like this:

    field name {
        description 'field Description'
        label 'fD'
        aliases {
            field nameA {
            description 'field Description'
            label 'fD'
        },
        field nameB {
                description 'field Description'
                label 'Fd'
        }}

The indentation of the brackets and the parameters is wrong generated. I expect auto indentation for recursively called methods.

I'm using Xtend 2.8.0

Upvotes: 0

Views: 601

Answers (1)

Sebastian Zarnekow
Sebastian Zarnekow

Reputation: 6729

Something like this should do the trick for you.

def generateField(Field field) '''
    field «field.name» {
        description '«field.description»'
        label '«field.label»'
        «IF !aliases.isEmpty»
            aliases {
                «FOR a : field.aliases SEPARATOR ','»«f.generateField»«ENDFOR»
            }
        «ENDIF»
    }
'''

Upvotes: 2

Related Questions