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 org.jetbrains.kotlin.js.backend.ast;
006    
007    import org.jetbrains.kotlin.js.backend.ast.metadata.HasMetadata;
008    import org.jetbrains.kotlin.js.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 static int ordinalGenerator;
016      private final JsScope enclosing;
017      private final int ordinal;
018    
019      @NotNull
020      private final String ident;
021    
022      private final boolean temporary;
023    
024      /**
025       * @param ident the unmangled ident to use for this name
026       */
027      JsName(JsScope enclosing, @NotNull String ident, boolean temporary) {
028        this.enclosing = enclosing;
029        this.ident = ident;
030        this.temporary = temporary;
031        ordinal = temporary ? ordinalGenerator++ : 0;
032      }
033    
034      public int getOrdinal() {
035        return ordinal;
036      }
037    
038      public JsScope getEnclosing() {
039        return enclosing;
040      }
041    
042      public boolean isTemporary() {
043        return temporary;
044      }
045    
046      @NotNull
047      public String getIdent() {
048        return ident;
049      }
050    
051      @NotNull
052      public JsNameRef makeRef() {
053        return new JsNameRef(this);
054      }
055    
056      @Override
057      public String toString() {
058        return ident;
059      }
060    }