how to insert white space in method?

i want to generate the code:

// Title
mTVTitle = (TextView)findViewById(R.id.tv_title);
// Title
mTVTitle = (TextView)findViewById(R.id.tv_title);


but now my code is:

// Title
mTVTitle = (TextView)findViewById(R.id.tv_title);// Title
mTVTitle = (TextView)findViewById(R.id.tv_title);// Title
mTVTitle = (TextView)findViewById(R.id.tv_title);


how to insert white space before "//Title"?

 
createCommentFromText and createExpressionFromText not work.
new PsiWhiteSpaceImpl always throw error.
0
3 comments

Sorry, I don't see any difference between the two code fragments in terms of whitespace.

0
Avatar
Permanently deleted user

i want the "// Title" code in the new line. don't follow the "findViewBy(R.id.tv_title);".

0
Avatar
Permanently deleted user

it was what i do now :

PsiElement method = mFactory.createCodeBlockFromText(
      String.format("{%s}", generateFindViewById()), mClazz);
method.getFirstChild().delete();// delete "{"
method.getLastChild().delete();// delete "}"
PsiMethod initViews = mClazz.findMethodsByName("initViews", false)[0];
initViews.getBody().add(method);


the content is :

 
// null
mTV = (TextView) findViewById(R.id.tv);
// null
mTV2
= (TextView) findViewById(R.id.tv2);
// null
mTVTitle
= (TextView) findViewById(R.id.tv_title);
// null
mTVContent
= (TextView) findViewById(R.id.tv_content);


it work well,but has any way to do this?

0

Please sign in to leave a comment.