Quantcast

How to sort importTypes?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to sort importTypes?

LittleFisher
https://github.com/mybatis/generator/issues/201


Please help me, how to sort importTypes?

I don't know how to code in my project even the author told me something.

Please ignore my poor English, I'm a Chinese coder.

thx

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to sort importTypes?

LittleFisher
I build a javaFormatter, but throw exception which I can not understand.



Caused by: java.lang.NoSuchMethodError: org.mybatis.generator.api.dom.java.TopLevelClass.getFormattedContent(ILorg/mybatis/generator/api/dom/java/CompilationUnit;)Ljava/lang/String;

 

 at com
.yc.room1000.core.mybatis.MyJavaFormatter.getMyFormattedContent(MyJavaFormatter.java:100)

 at com
.yc.room1000.core.mybatis.MyJavaFormatter.getFormattedContent(MyJavaFormatter.java:44)

 at org
.mybatis.generator.api.GeneratedJavaFile.getFormattedContent(GeneratedJavaFile.java:49)

 at org
.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:297)

 at org
.mybatis.generator.maven.MyBatisGeneratorMojo.execute(MyBatisGeneratorMojo.java:203)

 at org
.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)

 
... 21 more




This is my javaFormatter 






public class MyJavaFormatter implements JavaFormatter {




   
/**

     * context

     */


   
protected Context context;

   




   
public String getFormattedContent(CompilationUnit compilationUnit) {

       
return this.getMyFormattedContent(compilationUnit);

//        return compilationUnit.getFormattedContent();

   
}




   
public void setContext(Context context) {

       
this.context = context;

   
}

   

   
public String getMyFormattedContent(CompilationUnit compilationUnit) {

       
StringBuilder sb = new StringBuilder();

       

       
TopLevelClass topLevelClass = (TopLevelClass) compilationUnit;




       
for (String fileCommentLine : topLevelClass.getFileCommentLines()) {

            sb
.append(fileCommentLine);

            newLine
(sb);

       
}




       
if (stringHasValue(topLevelClass.getType().getPackageName())) {

            sb
.append("package "); //$NON-NLS-1$

            sb
.append(topLevelClass.getType().getPackageName());

            sb
.append(';');

            newLine
(sb);

            newLine
(sb);

       
}




       
for (String staticImport : topLevelClass.getStaticImports()) {

            sb
.append("import static "); //$NON-NLS-1$

            sb
.append(staticImport);

            sb
.append(';');

            newLine
(sb);

       
}

       

       
if (topLevelClass.getStaticImports().size() > 0) {

            newLine
(sb);

       
}

       

       
Set<String> importStrings = calculateImports(topLevelClass.getImportedTypes());

       
for (String importString : importStrings) {

            sb
.append(importString);

            newLine
(sb);

       
}




       
if (importStrings.size() > 0) {

            newLine
(sb);

       
}

       

       
String sbStr = topLevelClass.getFormattedContent(0, compilationUnit);

       

        sb
.append(sbStr);




       
return sb.toString();

   
}

   




 




在 2017年3月9日星期四 UTC+8下午8:38:37,LittleFisher写道:
<a href="https://github.com/mybatis/generator/issues/201" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fgenerator%2Fissues%2F201\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHdQfhji3KgieGlMcGPxZM5F-pGVA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fgenerator%2Fissues%2F201\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHdQfhji3KgieGlMcGPxZM5F-pGVA&#39;;return true;">https://github.com/mybatis/generator/issues/201


Please help me, how to sort importTypes?

I don't know how to code in my project even the author told me something.

Please ignore my poor English, I'm a Chinese coder.

thx

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to sort importTypes?

Jeff Butler
That method was added in version 1.3.3.  Please make sure you are using at least that version of the maven plugin as well as the generator.

Jeff Butler


On Thu, Mar 9, 2017 at 6:06 PM LittleFisher <[hidden email]> wrote:
I build a javaFormatter, but throw exception which I can not understand.



Caused by: java.lang.NoSuchMethodError: org.mybatis.generator.api.dom.java.TopLevelClass.getFormattedContent(ILorg/mybatis/generator/api/dom/java/CompilationUnit;)Ljava/lang/String;

 

 at com
.yc.room1000.core.mybatis.MyJavaFormatter.getMyFormattedContent(MyJavaFormatter.java:100)

 at com
.yc.room1000.core.mybatis.MyJavaFormatter.getFormattedContent(MyJavaFormatter.java:44)

 at org
.mybatis.generator.api.GeneratedJavaFile.getFormattedContent(GeneratedJavaFile.java:49)

 at org
.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:297)

 at org
.mybatis.generator.maven.MyBatisGeneratorMojo.execute(MyBatisGeneratorMojo.java:203)

 at org
.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)

 
... 21 more




This is my javaFormatter 






public class MyJavaFormatter implements JavaFormatter {




   
/**

     * context

     */


   
protected Context context;

   




   
public String getFormattedContent(CompilationUnit compilationUnit) {

       
return this.getMyFormattedContent(compilationUnit);

//        return compilationUnit.getFormattedContent();

   
}




   
public void setContext(Context context) {

       
this.context = context;

   
}

   

   
public String getMyFormattedContent(CompilationUnit compilationUnit) {

       
StringBuilder sb = new StringBuilder();

       

       
TopLevelClass topLevelClass = (TopLevelClass) compilationUnit;




       
for (String fileCommentLine : topLevelClass.getFileCommentLines()) {

            sb
.append(fileCommentLine);

            newLine
(sb);

       
}




       
if (stringHasValue(topLevelClass.getType().getPackageName())) {

            sb
.append("package "); //$NON-NLS-1$

            sb
.append(topLevelClass.getType().getPackageName());

            sb
.append(';');

            newLine
(sb);

            newLine
(sb);

       
}




       
for (String staticImport : topLevelClass.getStaticImports()) {

            sb
.append("import static "); //$NON-NLS-1$

            sb
.append(staticImport);

            sb
.append(';');

            newLine
(sb);

       
}

       

       
if (topLevelClass.getStaticImports().size() > 0) {

            newLine
(sb);

       
}

       

       
Set<String> importStrings = calculateImports(topLevelClass.getImportedTypes());

       
for (String importString : importStrings) {

            sb
.append(importString);

            newLine
(sb);

       
}




       
if (importStrings.size() > 0) {

            newLine
(sb);

       
}

       

       
String sbStr = topLevelClass.getFormattedContent(0, compilationUnit);

       

        sb
.append(sbStr);




       
return sb.toString();

   
}

   




 




在 2017年3月9日星期四 UTC+8下午8:38:37,LittleFisher写道:
https://github.com/mybatis/generator/issues/201


Please help me, how to sort importTypes?

I don't know how to code in my project even the author told me something.

Please ignore my poor English, I'm a Chinese coder.

thx

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to sort importTypes?

LittleFisher
The version is 1.3.5

 

<dependency>
   
<groupId>org.mybatis.generator</groupId>
   
<artifactId>mybatis-generator-core</artifactId>
   
<version>1.3.5</version>
 
</dependency>


And when I debug the code, I use reflect to see TopLevelClass's methods, but can not find the method named 'InnerClass.getFormattedContent(int indentLevel, CompilationUnit compilationUnit)', only find 'InnerClass.getFormattedContent(int indentLevel)' which method I can't find in InnerClass.

Another method is 'TopLevelClass.getFormattedContent()' which is useless.












在 2017年3月10日星期五 UTC+8上午7:56:54,Jeff Butler写道:
That method was added in version 1.3.3.  Please make sure you are using at least that version of the maven plugin as well as the generator.

Jeff Butler


On Thu, Mar 9, 2017 at 6:06 PM LittleFisher <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="x41Jn9VKEQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">5055...@...> wrote:
I build a javaFormatter, but throw exception which I can not understand.



Caused by: java.lang.NoSuchMethodError: org.mybatis.generator.api.dom.java.TopLevelClass.getFormattedContent(ILorg/mybatis/generator/api/dom/java/CompilationUnit;)Ljava/lang/String;

 

 at com
.yc.room1000.core.mybatis.MyJavaFormatter.getMyFormattedContent(MyJavaFormatter.java:100)

 at com
.yc.room1000.core.mybatis.MyJavaFormatter.getFormattedContent(MyJavaFormatter.java:44)

 at org
.mybatis.generator.api.GeneratedJavaFile.getFormattedContent(GeneratedJavaFile.java:49)

 at org
.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:297)

 at org
.mybatis.generator.maven.MyBatisGeneratorMojo.execute(MyBatisGeneratorMojo.java:203)

 at org
.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)

 
... 21 more




This is my javaFormatter 






public class MyJavaFormatter implements JavaFormatter {




   
/**

     * context

     */


   
protected Context context;

   




   
public String getFormattedContent(CompilationUnit compilationUnit) {

       
return this.getMyFormattedContent(compilationUnit);

//        return compilationUnit.getFormattedContent();

   
}




   
public void setContext(Context context) {

       
this.context = context;

   
}

   

   
public String getMyFormattedContent(CompilationUnit compilationUnit) {

       
StringBuilder sb = new StringBuilder();

       

       
TopLevelClass topLevelClass = (TopLevelClass) compilationUnit;




       
for (String fileCommentLine : topLevelClass.getFileCommentLines()) {

            sb
.append(fileCommentLine);

            newLine
(sb);

       
}




       
if (stringHasValue(topLevelClass.getType().getPackageName())) {

            sb
.append("package "); //$NON-NLS-1$

            sb
.append(topLevelClass.getType().getPackageName());

            sb
.append(';');

            newLine
(sb);

            newLine
(sb);

       
}




       
for (String staticImport : topLevelClass.getStaticImports()) {

            sb
.append("import static "); //$NON-NLS-1$

            sb
.append(staticImport);

            sb
.append(';');

            newLine
(sb);

       
}

       

       
if (topLevelClass.getStaticImports().size() > 0) {

            newLine
(sb);

       
}

       

       
Set<String> importStrings = calculateImports(topLevelClass.getImportedTypes());

       
for (String importString : importStrings) {

            sb
.append(importString);

            newLine
(sb);

       
}




       
if (importStrings.size() > 0) {

            newLine
(sb);

       
}

       

       
String sbStr = topLevelClass.getFormattedContent(0, compilationUnit);

       

        sb
.append(sbStr);




       
return sb.toString();

   
}

   




 




在 2017年3月9日星期四 UTC+8下午8:38:37,LittleFisher写道:
<a href="https://github.com/mybatis/generator/issues/201" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fgenerator%2Fissues%2F201\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHdQfhji3KgieGlMcGPxZM5F-pGVA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmybatis%2Fgenerator%2Fissues%2F201\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHdQfhji3KgieGlMcGPxZM5F-pGVA&#39;;return true;">https://github.com/mybatis/generator/issues/201


Please help me, how to sort importTypes?

I don't know how to code in my project even the author told me something.

Please ignore my poor English, I'm a Chinese coder.

thx

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="x41Jn9VKEQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to sort importTypes?

LittleFisher
I hava known why.

In my pom.xml









<plugin>


  <groupId>org.mybatis.generator</groupId>


  <artifactId>mybatis-generator-maven-plugin</artifactId>


  <version>1.3.2</version>


  <configuration>


    <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>


    <overwrite>true</overwrite>


    <verbose>true</verbose>


  </configuration>


  <dependencies>


    <dependency>


      <groupId>mysql</groupId>


      <artifactId>mysql-connector-java</artifactId>


      <version>${mysql.version}</version>


    </dependency>


    <dependency>


      <groupId>com.yc.room1000</groupId>


      <artifactId>core-base</artifactId>


      <version>${yc.version}</version>


    </dependency>


    <dependency>


      <groupId>tk.mybatis</groupId>


      <artifactId>mapper</artifactId>


      <version>${mapper.version}</version>


    </dependency>


  </dependencies>


</plugin>



The version is 1.3.2

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...