00001 package plp.expressions2.expression;
00002
00003 import plp.expressions1.util.Tipo;
00004 import plp.expressions2.memory.AmbienteCompilacao;
00005 import plp.expressions2.memory.AmbienteExecucao;
00006 import plp.expressions2.memory.VariavelNaoDeclaradaException;
00007
00008 public class Id implements Expressao {
00009
00010 private String idName;
00011
00012 public Id(String strName) {
00013 idName = strName;
00014 }
00015
00016 @Override
00017 public String toString() {
00018 return idName;
00019 }
00020
00021 public Valor avaliar(AmbienteExecucao ambiente)
00022 throws VariavelNaoDeclaradaException {
00023 return ambiente.get(this);
00024 }
00025
00037 public boolean checaTipo(AmbienteCompilacao amb)
00038 throws VariavelNaoDeclaradaException {
00039 boolean result = true;
00040 amb.get(this);
00041 return result;
00042 }
00043
00053 public Tipo getTipo(AmbienteCompilacao amb)
00054 throws VariavelNaoDeclaradaException {
00055 return amb.get(this);
00056 }
00057
00058 public String getIdName() {
00059 return idName;
00060 }
00061
00062 public void setIdName(String idName) {
00063 this.idName = idName;
00064 }
00065
00066 @Override
00067 public int hashCode() {
00068 final int prime = 31;
00069 int result = 1;
00070 result = prime * result + (idName == null ? 0 : idName.hashCode());
00071 return result;
00072 }
00073
00074 @Override
00075 public boolean equals(Object obj) {
00076 if (this == obj)
00077 return true;
00078 if (obj == null)
00079 return false;
00080 if (getClass() != obj.getClass())
00081 return false;
00082 final Id other = (Id) obj;
00083 if (idName == null) {
00084 if (other.idName != null)
00085 return false;
00086 } else if (!idName.equals(other.idName))
00087 return false;
00088 return true;
00089 }
00090
00091 }