예제 #1
0
  @Nullable
  public JsPropertyInitializer translate(
      @NotNull JetClassOrObject declaration, TranslationContext context) {
    ClassDescriptor descriptor = getClassDescriptor(context().bindingContext(), declaration);
    JsExpression value;
    if (descriptor.getModality() == Modality.FINAL) {
      value =
          new ClassTranslator(declaration, classDescriptorToQualifiedLabel, context).translate();
    } else {
      String label = createNameForClass(descriptor);
      JsName name = dummyFunction.getScope().declareName(label);
      JsNameRef qualifiedLabel = openClassDescriptorToQualifiedLabel.get(descriptor);
      if (qualifiedLabel == null) {
        qualifiedLabel = new JsNameRef(name);
        openClassDescriptorToQualifiedLabel.put(descriptor, qualifiedLabel);
      } else {
        qualifiedLabel.resolve(name);
      }
      qualifiedLabel.setQualifier(declarationsObjectRef);

      OpenClassInfo item = new OpenClassInfo((JetClass) declaration, descriptor, name.makeRef());

      openList.add(item);
      openClassDescriptorToItem.put(descriptor, item);

      value = qualifiedLabel;

      // not public api classes referenced to internal var _c
      if (!descriptor.getVisibility().isPublicAPI()) {
        return null;
      }
    }

    return InitializerUtils.createPropertyInitializer(descriptor, value, context());
  }
예제 #2
0
  public ClassDeclarationTranslator(@NotNull TranslationContext context) {
    super(context);

    dummyFunction = new JsFunction(context.scope());
    JsName declarationsObject = context().scope().declareName(Namer.nameForClassesVariable());
    classesVar = new JsVars.JsVar(declarationsObject);
    declarationsObjectRef = declarationsObject.makeRef();
  }
예제 #3
0
  @Nullable
  private JsNameRef getTargetLabel(@NotNull Node statementWithLabel) {
    int type = statementWithLabel.getType();
    if (type != TokenStream.BREAK && type != TokenStream.CONTINUE) {
      String tokenTypeName = TokenStream.tokenToName(statementWithLabel.getType());
      throw new AssertionError("Unexpected node type with label: " + tokenTypeName);
    }

    Node label = statementWithLabel.getFirstChild();
    if (label == null) return null;

    String identifier = label.getString();
    assert identifier != null : "If label exists identifier should not be null";

    JsName labelName = scopeContext.labelFor(identifier);
    assert labelName != null : "Unknown label name: " + identifier;

    return labelName.makeRef();
  }
예제 #4
0
 private JsFunction(
     @NotNull JsScope parentScope, @NotNull String description, @Nullable JsName name) {
   this.name = name;
   scope = new JsFunctionScope(parentScope, name == null ? description : name.getIdent());
 }
예제 #5
0
 @NotNull
 public JsPropertyInitializer getDeclarationAsInitializer() {
   return new JsPropertyInitializer(namespaceName.makeRef(), getNamespaceDeclaration());
 }