Batch create Java classes

Given the list of potential class names: 1. Alaska,,,, 50. Wyoming

Is there a tool that will create empty java class files for each with the provided parameters? I think of something like the "New ... Class" dialog in Eclipse, only on steroids. :-)

Thanks in advance, Kyle

+3
source share
2 answers

I'm not sure if there is a new class class wizard, but it will take so long to find it as if it were generated in a simple bat. I would use a loop for, iterating the contents of the file, which lists the names of the classes that will be created, and in the body of the loop the echotemplate for the newly created file, using the value from the file, they both denote .java, and also fill in the class name in the template.

EDIT: bat example that reads class names from a file with a name classnames.txtand creates very simple stubs:

for /F "tokens=1" %%a in (classnames.txt) do call :createClass %%a

dir *.java

goto :eof

:createClass 
   echo package com.abc; > %1.java 
   echo.  >> %1.java 
   echo public class %1 {>> %1.java 
   echo      public %1() { >> %1.java 
   echo      } >> %1.java 
   echo } >> %1.java
+1
source

maybe try the listings:

package p;

interface Foo {
    void bar();

}

enum State implements Foo {
    Alabama, Alaska, Arizona, Arkansas, California(new Integer(42)) {
        public void bar() {
            System.out.print("is strange ");
            super.bar();
        }

    },
    Colorado, Connecticut, Delaware, Florida, Georgia, Hawaii, Idaho, Illinois, Indiana, Iowa, Kansas, Kentucky, Louisiana, Maine, Maryland, Massachusetts, Michigan, Minnesota, Mississippi, Missouri, Montana, Nebraska, Nevada, NewHampshire, NewJersey, NewMexico, NewYork, NorthCarolina, NorthDakota, Ohio, Oklahoma, Oregon, Pennsylvania, RhodeIsland, SouthCarolina, SouthDakota, Tennessee, Texas, Utah, Vermont, Virginia, Washington, WestVirginia, Wisconsin, Wyoming;

    State() {
        this(null);
    }

    State(Object object) {
        this.object = object;
    }

    public void bar() {
        System.out.println(this + " " + object);
    }

    public static void main(String[] arguments) {
        for (State state : State.values())
            state.bar();
    }

    final Object object;
}
0
source

Source: https://habr.com/ru/post/1746108/


All Articles