001    // Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file
002    // for details. All rights reserved. Use of this source code is governed by a
003    // BSD-style license that can be found in the LICENSE file.
004    
005    package com.google.dart.compiler.backend.js.ast;
006    
007    import com.google.dart.compiler.common.Symbol;
008    import org.jetbrains.annotations.NotNull;
009    
010    /**
011     * An abstract base class for named JavaScript objects.
012     */
013    public class JsName implements Symbol {
014      private final JsScope enclosing;
015      private final String ident;
016    
017      /**
018       * @param ident the unmangled ident to use for this name
019       */
020      JsName(JsScope enclosing, String ident) {
021        this.enclosing = enclosing;
022        this.ident = ident;
023      }
024    
025      public String getIdent() {
026        return ident;
027      }
028    
029      @NotNull
030      public JsNameRef makeRef() {
031        return new JsNameRef(this);
032      }
033    
034      @Override
035      public String toString() {
036        return ident;
037      }
038    
039      @Override
040      public int hashCode() {
041        return ident.hashCode();
042      }
043    
044      @Override
045      public boolean equals(Object obj) {
046        if (this == obj) {
047          return true;
048        }
049        if (!(obj instanceof JsName)) {
050          return false;
051        }
052        JsName other = (JsName) obj;
053        return ident.equals(other.ident) && enclosing == other.enclosing;
054      }
055    }