enumtype.java

来自「plugin for eclipse」· Java 代码 · 共 156 行

JAVA
156
字号
/*
 * Created on May 8, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package isis.anp.nesc.ot.types;

import isis.anp.nesc.ot.Attribute;
import isis.anp.nesc.ot.EnumSpecifier;
import isis.anp.nesc.ot.Enumerator;
import isis.anp.nesc.ot.Outline;

import java.util.ArrayList;
import java.util.Iterator;


/**
 * @author sallai
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class EnumType extends CompoundType {
	
	ArrayList enumeratorList;
	ArrayList attributeList;
	boolean declaredAsComplete;
	boolean isSpecifierComplete;
	
	private EnumType() {
	}
	
	public EnumType(EnumSpecifier es) {
		this.setDefNode(es.getDefNode());
		this.setNameNode(es.getSpecifierNameNode());
		this.setEnumeratorList(es.getEnumeratorList());
		this.setAttributeList(es.getAttributeList());
		isSpecifierComplete = es.isComplete();
	}
	
	public boolean isComplete() {
		return !enumeratorList.isEmpty();
	}

	/**
	 * @return Returns the enumeratorList.
	 */
	public ArrayList getEnumeratorList() {
		return enumeratorList;
	}
	/**
	 * @param enumeratorList The enumeratorList to set.
	 */
	public void setEnumeratorList(ArrayList enumeratorList) {
//		Iterator i = enumeratorList.iterator();
//		while (i.hasNext()) {
//			Enumerator e = (Enumerator) i.next();
//			e.setType(this);
//			this.enumeratorList.add(e);
//		}
		
		this.enumeratorList = enumeratorList;
	}
	
	public void outline(Outline o) {
		o.append(getTypeQualifierString());
		
		o.ensureSpace();
		o.append(getName());
		o.ensureSpace();
		
//		if (isComplete()) {
//			o.append("<complete:"+ enumeratorList.hashCode()+">");
//		} else {
//			o.append("<incomplete>");
//		}
//		o.ensureSpace();

		if (isSpecifierComplete()) {

			if (this.enumeratorList != null) {
				o.append("{\n");
				o.incTabs();
				Iterator i = this.enumeratorList.iterator();
				while (i.hasNext()) {
					Enumerator d = (Enumerator) i.next();
					o.addTabs();
					d.outline(o);	
					if(i.hasNext()) {
						o.append(',');
					}
					o.addNewLine();
				}
				o.decTabs();
				o.addTabs();
				o.append("}");
				
				Iterator j = getAttributeList().iterator();
				while (j.hasNext()) {
					Attribute a = (Attribute) j.next();
					o.ensureSpace();
					a.outline(o);
				}
				
				o.ensureSpace();
			}
		}
		
		
	}
	
	/**
	 * @return Returns the declaredAsComplete.
	 */
	public boolean isSpecifierComplete() {
		return isSpecifierComplete;
	}

	/* (non-Javadoc)
	 * @see parser.nesc.ot.types.CompoundType#complete(parser.nesc.ot.types.CompoundType)
	 */
	public void complete(CompoundType typeProduct) {
		((EnumType)typeProduct).setEnumeratorList(this.getEnumeratorList());
	}
	/**
	 * @return Returns the attributeList.
	 */
	public ArrayList getAttributeList() {
		return attributeList;
	}
	/**
	 * @param attributeList The attributeList to set.
	 */
	public void setAttributeList(ArrayList attributeList) {
		this.attributeList = attributeList;
	}

    /* (non-Javadoc)
     * @see parser.nesc.ot.types.Type#clone()
     */
    public Object clone() {
        EnumType rval = new EnumType();
        rval.attributeList = this.attributeList;
        rval.declaredAsComplete = this.declaredAsComplete;
        rval.defNode = this.defNode;
        rval.enumeratorList = this.enumeratorList;
        rval.isSpecifierComplete = this.isSpecifierComplete;
        rval.name = this.name;
        rval.nameNode = this.nameNode;
        rval.parentScope = this.parentScope;
        rval.typeQualifiers = this.typeQualifiers;
        return rval;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?