All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.modelcc.io.java.JavaModelVisitor Maven / Gradle / Ivy

Go to download

ModelCC is a model-based parser generator (a.k.a. compiler compiler) that decouples language specification from language processing, avoiding some of the problems caused by grammar-driven parser generators. ModelCC receives a conceptual model as input, along with constraints that annotate it. It is then able to create a parser for the desired textual language and the generated parser fully automates the instantiation of the language conceptual model. ModelCC also includes a built-in reference resolution mechanism that results in abstract syntax graphs, rather than mere abstract syntax trees.

The newest version!
/*
 * ModelCC, distributed under ModelCC Shared Software License, www.modelcc.org
 */

package org.modelcc.io.java;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.logging.Level;

import org.modelcc.metamodel.ModelElement;

/**
 * Java model visitor
 * 
 * @author Fernando Berzal ([email protected])
 */
public abstract class JavaModelVisitor 
{
	private JavaModelReader reader;

	public JavaModelVisitor (JavaModelReader reader)
	{
		this.reader = reader;
	}
	
    public void log(Level level, String string, Object[] object) 
    {
        reader.log(level,string,object);
    }
    
    // Methods to be overriden
    
	public void startVisit (Class type, E element) throws Exception
	{
	}
	
	public void endVisit (Class type, E element) throws Exception
	{
	}
	
	public void visit (Class type, Field field, E element) throws Exception
	{
	}

	public void visit (Class type, Method method, E element) throws Exception
	{
	}
	
	public void visit (Field field, F model)
	{
	}

	// Standard visit: startVisit + visit methods + endVisit
	
	public final void visit (Class type, E element)
		throws Exception
	{
    	startVisit(type,element);
    	   	
    	endVisit(type,element);
	}

	public final void visitFields (Class type, E element)
		throws Exception
	{
		Field[] fields = type.getDeclaredFields();

		startVisit(type,element);

		for (Field f: fields) {
			visit(type, f, element);
		}

		endVisit(type, element);
	}

	public final void visitMethods (Class type, E element)
		throws Exception
	{
		Method[] methods = type.getDeclaredMethods();

		startVisit(type, element);

		for (Method m: methods) {
			visit(type, m, element);
		}

		endVisit(type, element);
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy