CodeGenerator icon indicating copy to clipboard operation
CodeGenerator copied to clipboard

Cannot add own suffix to generated class - default package names starts with redundant '\n'

Open qwazer opened this issue 2 years ago • 4 comments

  1. Plugin version 1.5.2. IDEA Build #IU-223.8214.52 OS - Linux
  2. new template created
        <CodeTemplate>
          <option name="name" value="TestDataFactory" />
          <option name="type" value="class" />
          <option name="template" value="public class ${ClassName} {&#10;     public static ${class0.name} aDefault${class0.name}(){&#10;         return ${class0.name}.build();&#10;     }&#10;}&#10;" />
          <option name="classNameVm" value="${class0.qualifiedName}TestDataFactory" />
          <option name="defaultTargetPackage" value="" />
          <option name="defaultTargetModule" value="" />
        </CodeTemplate>
  1. generate code
package
        ru.test.example;

directory with name started with '\n' created

src/test/java$ ls
''$'\n''ru'   ru

UI file manager screenshot: image

Didn't found the way to fix.

qwazer avatar Feb 03 '23 07:02 qwazer

After some investigation I see that expression

  <option name="classNameVm" value="${class0.qualifiedName}TestDataFactory" />

resolved to ''$'\n''. It caused wrong name of package.

So I didn't find the way to generate new class with my own suffix

qwazer avatar Feb 03 '23 19:02 qwazer

DEBUG logs

2023-02-03 23:00:13,258 [2810998]   FINE - #me.lotabout.codegenerator.action.CodeGeneratorAction - +++ executePipeline - START +++
2023-02-03 23:00:13,260 [2811000]   FINE - #me.lotabout.codegenerator.action.CodeGeneratorAction - Current project leetcode
2023-02-03 23:00:13,268 [2811008]   WARN - #o.j.j.g.e.ElementFactory - This method does not have a valid return type: TreeNode, returnType=null
2023-02-03 23:00:13,269 [2811009]   WARN - #o.j.j.g.e.ElementFactory - This method does not have a valid return type: TreeNode, returnType=null
2023-02-03 23:00:13,269 [2811009]   WARN - #o.j.j.g.e.ElementFactory - This method does not have a valid return type: TreeNode, returnType=null
2023-02-03 23:00:13,269 [2811009]   WARN - #o.j.j.g.e.ElementFactory - This method does not have a valid return type: TreeNode, returnType=null
2023-02-03 23:00:13,269 [2811009]   WARN - #o.j.j.g.e.ElementFactory - This method does not have a valid return type: TreeNode, returnType=null
2023-02-03 23:00:13,269 [2811009]   WARN - #o.j.j.g.e.ElementFactory - This method does not have a valid return type: TreeNode, returnType=null
2023-02-03 23:00:13,270 [2811010]   WARN - #o.j.j.g.e.ElementFactory - This method does not have a valid return type: Object, returnType=null
2023-02-03 23:00:13,273 [2811013]   FINE - #me.lotabout.codegenerator.action.CodeGeneratorAction - Select member/class through pipeline
2023-02-03 23:00:13,274 [2811014]   FINE - #me.lotabout.codegenerator.util.GenerationUtil - Velocity Template:

${class0.name}TestDataFactory
2023-02-03 23:00:13,274 [2811014]   FINE - #me.lotabout.codegenerator.util.GenerationUtil - Executing velocity +++ START +++
2023-02-03 23:00:13,274 [2811014]   FINE - #me.lotabout.codegenerator.util.GenerationUtil - Executing velocity +++ END +++
2023-02-03 23:00:13,274 [2811014]   FINE - #me.lotabout.codegenerator.worker.JavaClassWorker - FQClass generated

TreeNodeTestDataFactory
2023-02-03 23:00:13,274 [2811014]   FINE - #me.lotabout.codegenerator.util.GenerationUtil - Velocity Template:

public class ${ClassName} {
}
2023-02-03 23:00:13,274 [2811014]   FINE - #me.lotabout.codegenerator.util.GenerationUtil - Executing velocity +++ START +++
2023-02-03 23:00:13,274 [2811014]   FINE - #me.lotabout.codegenerator.util.GenerationUtil - Executing velocity +++ END +++
2023-02-03 23:00:13,274 [2811014]   FINE - #me.lotabout.codegenerator.worker.JavaClassWorker - Method body generated from Velocity:

public class 
TreeNodeTestDataFactory {
}

qwazer avatar Feb 03 '23 20:02 qwazer

Looks like RCA is https://github.com/lotabout/CodeGenerator/pull/18/commits/e82d4f0a28ca82b9b2bc596ecf4e729f390952d5#diff-bbabbde4dbf64a0cac897295690b776062d991f172593f4094bde3be1eeca370

    var templateWithDefaultImports = defaultImportParseExpression + System.getProperty("line.separator") + template;

qwazer avatar Feb 03 '23 20:02 qwazer

Not reproduced with 1.4.1. Will use it while waiting for an update. Thanks for the plugin!

qwazer avatar Feb 03 '23 20:02 qwazer