Reformat code is not working with the same way as Code->Reformat Code

已回答

I add some PsiDeclarationStatemento with addAfter method but the code is added in the same line.()

PsiDeclarationStatementImpl psiDeclarationStatement = (PsiDeclarationStatementImpl) psiMethod.getBody()
.getStatements()[0].addAfter(progressSubject, psiMethod.getBody().getStatements()[0].getLastChild());

So i tried to reformat the code with  CodeStyleManager but dosent change the line, its olny adding spaces instead of tabs.

CodeStyleManager.getInstance(psiClass.getProject()).reformat(psiClass);

But when i run ctrl+alt+L the code is reformated corect.

Code after CodeStyleManager.reformat:

super.onCreate(savedInstanceState);BehaviorSubject<String> progressSubject = BehaviorSubject.create();Disposable disposal = myTimelineProgressSubject.observeOn(AndroidSchedulers.mainThread()).subscribe(s -> rxProgressUpdate(s));

code when i run Code->Reformat Code from the Intelij:

super.onCreate(savedInstanceState);
BehaviorSubject<String> progressSubject = BehaviorSubject.create();
Disposable disposal = myTimelineProgressSubject.observeOn(AndroidSchedulers.mainThread()).subscribe(s -> rxProgressUpdate(s));

 

0

Theodosios,

Try using ReformatCodeProcessor on your PsiFile, like:

new ReformatCodeProcessor(PsiFile, false).run()
0
Avatar
Permanently deleted user

Thanks for the fast reply. It worked perfect!

Is any way i can reformat better the lamda code? 

From:

Disposable disposal = progressSubject.observeOn(AndroidSchedulers.mainThread()).subscribe(s -> rxProgressUpdate(s));

To something like that:

Disposable d1 = myTimelineProgressSubject
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> myTimelineProgressUpdate(s));

 

0

You should play with the Code Style settings.

0
Avatar
Permanently deleted user

Okay thank you!

0

请先登录再写评论。