Ejemplo n.º 1
0
  private String doCompareNamespaces(
      @NotNull NamespaceDescriptor nsa, @NotNull NamespaceDescriptor nsb) {
    StringBuilder sb = new StringBuilder();
    Assert.assertEquals(nsa.getName(), nsb.getName());

    sb.append("namespace " + nsa.getName() + "\n\n");

    Assert.assertTrue(!nsa.getMemberScope().getAllDescriptors().isEmpty());

    Set<String> classifierNames = new HashSet<String>();
    Set<String> propertyNames = new HashSet<String>();
    Set<String> functionNames = new HashSet<String>();

    for (DeclarationDescriptor ad : nsa.getMemberScope().getAllDescriptors()) {
      if (ad instanceof ClassifierDescriptor) {
        classifierNames.add(ad.getName());
      } else if (ad instanceof PropertyDescriptor) {
        propertyNames.add(ad.getName());
      } else if (ad instanceof FunctionDescriptor) {
        functionNames.add(ad.getName());
      } else {
        throw new AssertionError("unknown member: " + ad);
      }
    }

    for (String name : classifierNames) {
      ClassifierDescriptor ca = nsa.getMemberScope().getClassifier(name);
      ClassifierDescriptor cb = nsb.getMemberScope().getClassifier(name);
      Assert.assertTrue(ca != null);
      Assert.assertTrue(cb != null);
      compareClassifiers(ca, cb, sb);
    }

    for (String name : propertyNames) {
      Set<VariableDescriptor> pa = nsa.getMemberScope().getProperties(name);
      Set<VariableDescriptor> pb = nsb.getMemberScope().getProperties(name);
      compareDeclarationSets(pa, pb, sb);

      Assert.assertTrue(
          nsb.getMemberScope().getFunctions(PropertyCodegen.getterName(name)).isEmpty());
      Assert.assertTrue(
          nsb.getMemberScope().getFunctions(PropertyCodegen.setterName(name)).isEmpty());
    }

    for (String name : functionNames) {
      Set<FunctionDescriptor> fa = nsa.getMemberScope().getFunctions(name);
      Set<FunctionDescriptor> fb = nsb.getMemberScope().getFunctions(name);
      compareDeclarationSets(fa, fb, sb);
    }

    return sb.toString();
  }
Ejemplo n.º 2
0
 private void generatePrimaryConstructorProperties(
     PropertyCodegen propertyCodegen, JetClassOrObject origin) {
   boolean isAnnotation = origin instanceof JetClass && ((JetClass) origin).isAnnotation();
   for (JetParameter p : getPrimaryConstructorParameters()) {
     if (p.getValOrVarNode() != null) {
       PropertyDescriptor propertyDescriptor =
           state.getBindingContext().get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, p);
       if (propertyDescriptor != null) {
         if (!isAnnotation) {
           propertyCodegen.generatePrimaryConstructorProperty(p, propertyDescriptor);
         } else {
           Type type = state.getTypeMapper().mapType(propertyDescriptor);
           v.newMethod(
               p, ACC_PUBLIC | ACC_ABSTRACT, p.getName(), "()" + type.getDescriptor(), null, null);
         }
       }
     }
   }
 }