Commit c2374931 authored by Lionel Seinturier's avatar Lionel Seinturier
Browse files

Refactor FileSourceCodeVisitor to enable generating comments at any place of...

Refactor FileSourceCodeVisitor to enable generating comments at any place of the file, and not just for file headers.
parent fa425015
......@@ -38,7 +38,7 @@ public interface SourceCodeGeneratorItf {
/**
* Generate the code in the specified {@link FileSourceCodeVisitor}.
*
* @param fv the visitor for generating the header of the source code file
* @param fv the visitor for generating the source code
*/
public void generate( FileSourceCodeVisitor fv ) throws IOException;
......
......@@ -32,12 +32,12 @@ package org.objectweb.fractal.juliac.api.visit;
public interface FileSourceCodeVisitor {
/**
* Visit the source code file header. This header is printed before the
* package keyword. This header must be a valid Java comment.
* Visit a comment.
*
* @param header the header comment string
* @param comment the comment string
* @since 2.7
*/
public void visitFileHeader( String header );
public void visitComment( String comment );
/**
* Visit the package name.
......
......@@ -47,10 +47,10 @@ public abstract class TypeGenerator implements TypeGeneratorItf {
}
public void generateFileHeaders( FileSourceCodeVisitor fv ) {
fv.visitFileHeader("/*");
fv.visitFileHeader(" * Generated by: "+getClass().getName());
fv.visitFileHeader(" * on: "+new Date().toString());
fv.visitFileHeader(" */");
fv.visitComment("/*");
fv.visitComment(" * Generated by: "+getClass().getName());
fv.visitComment(" * on: "+new Date().toString());
fv.visitComment(" */");
}
public String getPackageName() {
......
......@@ -148,16 +148,16 @@ public class InterceptorClassGenerator extends AbstractProxyClassGenerator {
@Override
public void generateFileHeaders( FileSourceCodeVisitor fv ) {
fv.visitFileHeader("/*");
fv.visitFileHeader(" * Generated by: ");
fv.visitFileHeader(" * "+getClass().getName());
fv.visitComment("/*");
fv.visitComment(" * Generated by: ");
fv.visitComment(" * "+getClass().getName());
for (int i = 0; i < matches.length; i++) {
final String msg =
" * "+iscgs[i].getClass().getName()+" matches "+matches[i];
fv.visitFileHeader(msg);
fv.visitComment(msg);
}
fv.visitFileHeader(" * on: "+new Date().toString());
fv.visitFileHeader(" */");
fv.visitComment(" * on: "+new Date().toString());
fv.visitComment(" */");
}
@Override
......
......@@ -47,20 +47,12 @@ implements FileSourceCodeVisitor {
super(pw);
}
public void visitFileHeader( String header ) {
checkState(
state == STATES.FILE_HEADER_STATE,
"File headers cannot be visited at this stage of the visit" );
writeln(header);
public void visitComment( String comment ) {
writeln(comment);
}
public void visitPackageName( String name ) {
if( state.ordinal() < STATES.PACKAGE_NAME_STATE.ordinal() ) {
state = STATES.PACKAGE_NAME_STATE;
}
checkState(
state == STATES.PACKAGE_NAME_STATE,
"Package name cannot be visited at this stage of the visit" );
......@@ -118,10 +110,9 @@ implements FileSourceCodeVisitor {
// Visitor state constants
// ----------------------------------------------------------------------
private STATES state = STATES.FILE_HEADER_STATE;
private STATES state = STATES.PACKAGE_NAME_STATE;
private static enum STATES {
FILE_HEADER_STATE,
PACKAGE_NAME_STATE,
IMPORTS_STATE,
BODY_STATE,
......
......@@ -150,16 +150,16 @@ public class InterceptorClassGenerator extends AbstractProxyClassGenerator {
@Override
public void generateFileHeaders( FileSourceCodeVisitor fv ) {
fv.visitFileHeader("/*");
fv.visitFileHeader(" * Generated by: ");
fv.visitFileHeader(" * "+getClass().getName());
fv.visitComment("/*");
fv.visitComment(" * Generated by: ");
fv.visitComment(" * "+getClass().getName());
for (int i = 0; i < matches.length; i++) {
final String msg =
" * "+iscgs[i].getClass().getName()+" matches "+matches[i];
fv.visitFileHeader(msg);
fv.visitComment(msg);
}
fv.visitFileHeader(" * on: "+new Date().toString());
fv.visitFileHeader(" */");
fv.visitComment(" * on: "+new Date().toString());
fv.visitComment(" */");
}
@Override
......
Supports Markdown
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