StringLiteral.java :  » JVM » mandarax » org » mandarax » dsl » Java Open Source

Java Open Source » JVM » mandarax 
mandarax » org » mandarax » dsl » StringLiteral.java
/*
 * Copyright 2010 Jens Dietrich 
 * Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE, Version 3 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.gnu.org/licenses/agpl.html 
 * Unless required by applicable law or agreed to in writing, software distributed under the 
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 * either express or implied. See the License for the specific language governing permissions 
 * and limitations under the License.
 */

package org.mandarax.dsl;

import static org.apache.commons.lang.StringEscapeUtils.*;
import java.util.Map;

/**
 * String literal.
 * @author jens dietrich
 */

public class StringLiteral extends Literal<String> {
  private String value = null;

  public StringLiteral(Position position,Context context,String value) {
    super(position,context);
    this.value = unescapeJava(value);
  }

  public String getValue() {
    return value;
  }

  
  public void accept(ASTVisitor visitor) {
    visitor.visit(this);
    visitor.endVisit(this);
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((value == null) ? 0 : value.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    StringLiteral other = (StringLiteral) obj;
    if (value == null) {
      if (other.value != null)
        return false;
    } else if (!value.equals(other.value))
      return false;
    return true;
  }
  
  @Override
  public Expression substitute(Map<Expression,? extends Expression> substitutions) {
    Expression substituteThis = substitutions.get(this);
    if (substituteThis==null) {
      StringLiteral e = new StringLiteral(getPosition(),getContext(),value);
      e.setType(this.getType());
      copyPropertiesTo(e);
      return e;
    }
    else {
      return substituteThis;
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.