Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8560303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:14:45+00:00 2026-06-11T16:14:45+00:00

I am generating a class field in my JvmModelinferrer in xtend: val exp =

  • 0

I am generating a class field in my JvmModelinferrer in xtend:

val exp = NodeModelUtils::getNode(rule.expression);
members+=rule.toField("text",rule.newTypeRef('java.lang.String'))[
                            ^static = true
                            val Procedure1<ITreeAppendable> b = [
                                 append('''"«exp.text.replace('"','').replaceAll("\n"," \\n ")»"''')
                            ]
                            initializer = b
                            setFinal(true)
                            setVisibility(JvmVisibility::PUBLIC)
                        ]

given that the initial exp.text was

'a
 b'

I would like the generated field to look like this:

String text = "a \n b";

but instead it look like this:

String text = "a n b";

where as if I dont replace the newline characters at all then I get:

String text = "a
               b";

which of course doesnt compile. The problem seems to be that xtend is evaluating the java string, so even though “\n” gets compiled to “\n” in java, in xtend it evaluates to “n”

How can I get xtend to not evaluate the \n so that it is preserved in the generated java string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:14:46+00:00Added an answer on June 11, 2026 at 4:14 pm

    Turns out you need to replace with “\\\\n”, as the source code you’re writing will get through the lexer too and the backslash needs one more escape.

    courtesy of Vlad Dumitrescu

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm generating a class from an interface using T4 templates, and I want to
Silverlight filter/class for cloud generation? Some HLSL or just C# class for generating clouds?
ok...so i'm randomly generating a level in a class and then pass it to
I am having some problems generating a list for a class in Python. I
SWIG seems to be generating incorrect bindings for converting a struct field of type
On Django 1.2.1 I'm using ModelForm and generating a form with radiobuttons: class myModelForm(ModelForm):
I'm having trouble generating a nested model form. Here are my models: class Workout
Possible Duplicate: XJC Generating Integer Instead of int Need to generate entity class with
I have a model with self-referencing ManyToMany field: class Suite(models.Model): suites = models.ManyToManyField(self, related_name=parents,
If one has a Float field in a domain class, the Grails view generation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.