Commit fc3e70bc authored by Lionel Seinturier's avatar Lionel Seinturier

Refactor as a class generator.

parent 4de02e2a
......@@ -23,22 +23,15 @@
package org.ow2.frascati.tinfi.tinfilet;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.util.Date;
import org.objectweb.fractal.juliac.api.SourceCodeGeneratorItf;
import org.objectweb.fractal.juliac.visit.ClassSourceCodeVisitor;
import org.objectweb.fractal.juliac.visit.FileSourceCodeVisitor;
import org.objectweb.fractal.juliac.opt.ClassGenerator;
/**
* Generate an empty class which extends the one specified in the constructor.
* This generator is used by Tinfi.
* Generate an empty class that extends the one specified in the constructor.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 1.3.1
*/
public class EmptySubClassGenerator implements SourceCodeGeneratorItf {
public class EmptySubClassGenerator extends ClassGenerator {
/**
* @param targetname the fully-qualified name of the class to be generated
......@@ -52,56 +45,12 @@ public class EmptySubClassGenerator implements SourceCodeGeneratorItf {
private String targetname;
private String superclname;
/**
* Return the name of the class generated by this generator.
*/
public String getTargetTypeName() {
return targetname;
}
/**
* Generate the header of the source code file associated with this
* generator. The header is the section which precedes the source code of
* the class. The header may be composed of an initial comment, the
* declaration of the package name and some import clauses.
*
* @param fv the visitor for generating the header of the source code file
*/
public void generate( FileSourceCodeVisitor fv ) throws IOException {
int lastdot = targetname.lastIndexOf('.');
String packagename = (lastdot==-1) ? null : targetname.substring(0,lastdot);
/*
* File header.
*/
fv.visitFileHeader("/*");
fv.visitFileHeader(" * Generated by "+getClass().getName()+" on: "+new Date());
fv.visitFileHeader(" */");
/*
* Package.
*/
if( packagename != null ) {
fv.visitPackageName(packagename);
}
/*
* Class.
*/
ClassSourceCodeVisitor cv = fv.visitPublicClass();
generate(cv);
}
/**
* Generate the source code of the class associated with this generator.
*
* @param cv the visitor for generating the source code of the class
*/
public void generate( ClassSourceCodeVisitor cv ) {
int lastdot = targetname.lastIndexOf('.');
String classname = targetname.substring(lastdot+1);
cv.visit( Modifier.PUBLIC, classname, null, superclname, null );
cv.visitEnd();
@Override
public String getSuperClassName() {
return superclname;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment