/**
  *
  *                      OOAS Compiler
  *
  *       Copyright 2015, AIT Austrian Institute of Technology.
  * This code is based on the C# Version of the OOAS Compiler, which is
  * copyright 2015 by the Institute of Software Technology, Graz University
  * of Technology with portions copyright by the AIT Austrian Institute of
  * Technology. All rights reserved.
  *
  * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
  *
  * If you modify the file please update the list of contributors below to in-
  * clude your name. Please also stick to the coding convention of using TABs
  * to do the basic (block-level) indentation and spaces for anything after
  * that. (Enable the display of special chars and it should be pretty obvious
  * what this means.) Also, remove all trailing whitespace.
  *
  * Contributors:
  *               Willibald Krenn (AIT)
  *               Stephan Zimmerer (AIT)
  *               Markus Demetz (AIT)
  *               Christoph Czurda (AIT)
  *               Stefan Tiran (AIT)
  *
  */


package org.momut.ooas.ast.identifiers;

import org.antlr.runtime.Token;
import org.momut.ooas.ast.IAstVisitor;
import org.momut.ooas.ast.IScope;
import org.momut.ooas.ast.expressions.Expression;
import org.momut.ooas.ast.types.Type;
import org.momut.ooas.utils.exceptions.ArgumentException;

public final class AttributeIdentifier extends ValueReferenceIdentifier
{
	private Expression m_initializer;
	private final boolean m_isStatic;
	private final boolean m_isObservable;    // used for qualitative values
	private final boolean m_isControllable;  // used for qualitative values

	public Expression initializer() { return m_initializer; }
	public boolean isStatic() { return m_isStatic; }
	public boolean isObservable() { return m_isObservable; }
	public boolean isControllable() { return m_isControllable; }

	public AttributeIdentifier(Token aToken,
			Type aType,
			IScope aDefiningScope,
			Expression anInitializer,
			boolean isStatic,
			boolean isObservable,
			boolean isControllable)
	{
		super(aToken, aType, IdentifierKind.AttributeIdentifier, aDefiningScope);
		m_initializer = anInitializer;
		m_isStatic = isStatic;
		m_isControllable = isControllable;
		m_isObservable = isObservable;
	}

	public AttributeIdentifier(String name,
			Type aType,
			IScope aDefiningScope,
			Expression anInitializer,
			boolean isStatic,
			boolean isObservable,
			boolean isControllable)
	{
		super(name, aType, IdentifierKind.AttributeIdentifier, aDefiningScope);
		m_initializer = anInitializer;
		m_isStatic = isStatic;
		m_isControllable = isControllable;
		m_isObservable = isObservable;
	}

	public AttributeIdentifier(AttributeIdentifier toCopy)
	{
		super(toCopy);
		m_initializer = toCopy.initializer();
		m_isStatic = toCopy.m_isStatic;
		m_isControllable = toCopy.m_isControllable;
		m_isObservable = toCopy.m_isObservable;
	}


	@Override
	public /*override*/ Identifier Clone()
	{
		return new AttributeIdentifier(this);
	}

	@Override
	public /*override*/ void Accept(IAstVisitor visitor)
	{
		visitor.visit(this);
	}

	public void SetInitializer(Expression newExpr)
	{
		if (newExpr == null)
			throw new ArgumentException();
		m_initializer = newExpr;
	}
}
