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

org.modelcc.metamodel.ModelElement 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.metamodel;

import java.util.ArrayList;
import java.util.List;

/**
 * ModelCC metamodel (composite design pattern)
 * 
 * @author Fernando Berzal ([email protected])
 */
public class ModelElement implements java.io.Serializable
{
	/**
	 * Element ID
	 */
	private String id;
	
    /**
     * ModelElement class.
     */
    private Class elementClass;

    /**
     * ModelElement members.
     */
    private List members;
 
    /**
     * Constructor
     * @param elementClass element class
     * @param id element ID
     */
    public ModelElement (Class elementClass, String id) 
    {
    	this.id = id;
        this.elementClass = elementClass;
    	this.members = new ArrayList();    	
    }
 
    /**
     * Constructor
     * @param elementClass element class
     */    
    public ModelElement (Class elementClass) 
    {
    	this(elementClass, elementClass.getCanonicalName());
    }
    
    /**
     * @return the element class
     */
    public Class getElementClass() 
    {
        return elementClass;
    }

    /**
     * @param elementClass the element class
     */
    public void setElementClass(Class elementClass) 
    {
        this.elementClass = elementClass;
    }

    /**
     * @return the element members
     */
    public List getMembers() 
    {
        return members;
    }

    /**
     * Get element member
     * @param i member index
     * @return The i-th element member
     */
    public M getMember (int i)
    {
    	return members.get(i);
    }
    
    /**
     * @param contents the element members
     */
    public void setMembers(List contents) 
    {
        this.members = contents;
    }
    
    /**
     * @param member the member to be added to this element
     */
    public void addMember (M member)
    {
    	members.add(member);
    }

    /**
     * @return element identifier
     */
    public String getID() 
    {
        return id;
    }    
    
    // toString
    
    public String toString ()
    {
    	return elementClass.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy