001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2023 microBean™.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
006 * the License.  You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
011 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
012 * specific language governing permissions and limitations under the License.
013 */
014package org.microbean.scopelet;
015
016import java.lang.constant.ClassDesc;
017import java.lang.constant.Constable;
018import java.lang.constant.DynamicConstantDesc;
019import java.lang.constant.MethodHandleDesc;
020
021import java.util.List;
022import java.util.Optional;
023
024import org.microbean.bean.Id;
025
026import static java.lang.constant.ConstantDescs.BSM_INVOKE;
027
028import static org.microbean.bean.Qualifiers.anyQualifier;
029
030import static org.microbean.lang.Lang.declaredType;
031import static org.microbean.lang.Lang.typeElement;
032
033import static org.microbean.scope.Scope.SINGLETON_ID;
034
035public final class SingletonScopelet extends MapBackedScopelet<SingletonScopelet> implements Constable {
036
037  public static final Id ID =
038    new Id(List.of(declaredType(SingletonScopelet.class),
039                   declaredType(null,
040                                typeElement(Scopelet.class),
041                                declaredType(SingletonScopelet.class))),
042           List.of(SINGLETON_ID, anyQualifier()), // qualifiers
043           SINGLETON_ID); // the scope we belong to
044
045  private static final ClassDesc CD_SingletonScopelet = ClassDesc.of(SingletonScopelet.class.getName());
046
047  public SingletonScopelet() {
048    super(SINGLETON_ID); // the scope we implement
049  }
050
051  @Override // Scopelet<SingletonScopelet>
052  public final Id id() {
053    return ID;
054  }
055
056  @Override // Constable
057  public final Optional<DynamicConstantDesc<SingletonScopelet>> describeConstable() {
058    return Optional.of(DynamicConstantDesc.of(BSM_INVOKE, MethodHandleDesc.ofConstructor(CD_SingletonScopelet)));
059  }
060
061}