@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());
  }
Exemple #2
0
 /** Add a type arguments parameter to a factory method, if necessary. */
 void maybeAddTypeParameterToFactory(DartMethodDefinition method, JsFunction factory) {
   // TODO(johnlenz):in optimized mode, only add this where it is needed.
   if (isParameterizedFactoryMethod(method)) {
     JsScope scope = factory.getScope();
     JsName typeArgs = scope.declareName("$typeArgs");
     factory.getParameters().add(0, new JsParameter(typeArgs));
   }
 }
Exemple #3
0
  @NotNull
  @Override
  public JsFunction deepCopy() {
    JsFunction functionCopy = new JsFunction(scope.getParent(), scope.getDescription(), name);
    functionCopy.getScope().copyOwnNames(scope);
    functionCopy.setBody(body.deepCopy());
    functionCopy.params = AstUtil.deepCopy(params);

    return functionCopy.withMetadataFrom(this);
  }
Exemple #4
0
 /** Add the appropriate code to a class's constructing factory, if necessary. */
 void maybeAddClassRuntimeTypeToConstructor(
     ClassElement classElement, JsFunction factory, JsExpression thisRef) {
   // TODO(johnlenz):in optimized mode, only add this where it is needed.
   JsScope factoryScope = factory.getScope();
   JsExpression typeInfo;
   if (hasTypeParameters(classElement)) {
     JsName typeinfoParameter = factoryScope.declareName("$rtt");
     factory.getParameters().add(0, new JsParameter(typeinfoParameter));
     typeInfo = typeinfoParameter.makeRef();
   } else {
     // TODO(johnlenz): this is a constant value, it only needs to be evaluated once.
     typeInfo = generateRawRTTLookup(classElement);
   }
   JsExpression setTypeInfo =
       assign(null, nameref(null, Cloner.clone(thisRef), "$typeInfo"), typeInfo);
   factory.getBody().getStatements().add(0, setTypeInfo.makeStmt());
 }