11package cz .jiripudil .intellij .nette .factoryGenerator .codeGeneration ;
22
3+ import com .intellij .codeStyle .CodeStyleFacade ;
34import com .intellij .openapi .components .ApplicationComponent ;
45import com .intellij .openapi .project .Project ;
56import com .intellij .openapi .util .text .StringUtil ;
67import com .intellij .psi .PsiFile ;
78import com .jetbrains .php .config .PhpLanguageFeature ;
89import com .jetbrains .php .config .PhpLanguageLevel ;
910import com .jetbrains .php .config .PhpProjectConfigurationFacade ;
11+ import com .jetbrains .php .lang .PhpFileType ;
1012import com .jetbrains .php .lang .psi .elements .Parameter ;
1113import com .jetbrains .php .lang .psi .elements .PhpClass ;
1214import com .jetbrains .php .refactoring .PhpFileCreator ;
@@ -26,18 +28,36 @@ public PsiFile generateFactory(Project project, PsiFile psiFile, PhpClass origin
2628 String trimmedNamespace = StringUtil .trimStart (StringUtil .trimEnd (namespace , "\\ " ), "\\ " );
2729 StringBuilder contentBuilder = new StringBuilder ();
2830
29- contentBuilder .append ("\n \n namespace " )
31+ CodeStyleFacade cs = CodeStyleFacade .getInstance (project );
32+ boolean useTab = cs .useTabCharacter (PhpFileType .INSTANCE );
33+ int indentSize = cs .getIndentSize (PhpFileType .INSTANCE );
34+ String indent = useTab ? "\t " : StringUtil .repeat (" " , indentSize );
35+ String newline = cs .getLineSeparator ();
36+
37+ contentBuilder .append (StringUtil .repeat (newline , 2 ))
38+ .append ("namespace " )
3039 .append (trimmedNamespace )
31- .append (";\n \n \n " );
40+ .append (";" )
41+ .append (StringUtil .repeat (newline , 3 ));
3242
3343 contentBuilder .append ("interface " )
3444 .append (factoryName )
35- .append ("\n {\n \n \t " );
45+ .append (newline )
46+ .append ("{" )
47+ .append (StringUtil .repeat (newline , 2 ))
48+ .append (indent );
3649
3750 if ( ! languageLevel .hasFeature (PhpLanguageFeature .RETURN_TYPES )) {
38- contentBuilder .append ("/**\n \t * @return " )
51+ contentBuilder .append ("/**" )
52+ .append (newline )
53+ .append (indent )
54+ .append (" * @return " )
3955 .append (originalClass .getName ())
40- .append ("\n \t */\n \t " );
56+ .append (newline )
57+ .append (indent )
58+ .append (" */" )
59+ .append (newline )
60+ .append (indent );
4161 }
4262
4363 contentBuilder .append ("public function create(" );
@@ -73,7 +93,10 @@ public PsiFile generateFactory(Project project, PsiFile psiFile, PhpClass origin
7393 .append (originalClass .getName ());
7494 }
7595
76- contentBuilder .append (";\n \n }\n " );
96+ contentBuilder .append (";" )
97+ .append (StringUtil .repeat (newline , 2 ))
98+ .append ("}" )
99+ .append (newline );
77100
78101 return PhpFileCreator .createPhpFile (
79102 project ,
0 commit comments