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.backend.js.ast.metadata.HasMetadata; 008 import com.google.dart.compiler.common.Symbol; 009 import org.jetbrains.annotations.NotNull; 010 011 /** 012 * An abstract base class for named JavaScript objects. 013 */ 014 public class JsName extends HasMetadata implements Symbol { 015 private final JsScope enclosing; 016 017 @NotNull 018 private final String ident; 019 020 /** 021 * @param ident the unmangled ident to use for this name 022 */ 023 JsName(JsScope enclosing, @NotNull String ident) { 024 this.enclosing = enclosing; 025 this.ident = ident; 026 } 027 028 @NotNull 029 public String getIdent() { 030 return ident; 031 } 032 033 @NotNull 034 public JsNameRef makeRef() { 035 return new JsNameRef(this); 036 } 037 038 @Override 039 public String toString() { 040 return ident; 041 } 042 043 @Override 044 public int hashCode() { 045 return ident.hashCode(); 046 } 047 048 @Override 049 public boolean equals(Object obj) { 050 if (this == obj) { 051 return true; 052 } 053 if (!(obj instanceof JsName)) { 054 return false; 055 } 056 JsName other = (JsName) obj; 057 return ident.equals(other.ident) && enclosing == other.enclosing; 058 } 059 }