示例#1
0
  private void processPrimaryConstructor(MutableClassDescriptor classDescriptor, JetClass klass) {
    if (classDescriptor.getKind() == ClassKind.TRAIT) {
      JetParameterList primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
      if (primaryConstructorParameterList != null) {
        context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(primaryConstructorParameterList));
      }
      if (!klass.hasPrimaryConstructor()) return;
    }

    // TODO : not all the parameters are real properties
    JetScope memberScope = classDescriptor.getScopeForSupertypeResolution();
    ConstructorDescriptor constructorDescriptor =
        context
            .getDescriptorResolver()
            .resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass);
    for (JetParameter parameter : klass.getPrimaryConstructorParameters()) {
      if (parameter.getValOrVarNode() != null) {
        PropertyDescriptor propertyDescriptor =
            context
                .getDescriptorResolver()
                .resolvePrimaryConstructorParameterToAProperty(
                    classDescriptor, memberScope, parameter);
        classDescriptor.addPropertyDescriptor(propertyDescriptor);
        context.getPrimaryConstructorParameterProperties().add(propertyDescriptor);
      }
    }
    if (constructorDescriptor != null) {
      classDescriptor.setPrimaryConstructor(constructorDescriptor, context.getTrace());
    }
  }
示例#2
0
 private void processSecondaryConstructor(
     MutableClassDescriptor classDescriptor, JetSecondaryConstructor constructor) {
   if (classDescriptor.getKind() == ClassKind.TRAIT) {
     //            context.getTrace().getErrorHandler().genericError(constructor.getNameNode(), "A
     // trait may not have a constructor");
     context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(constructor.getNameNode()));
   }
   ConstructorDescriptor constructorDescriptor =
       context
           .getDescriptorResolver()
           .resolveSecondaryConstructorDescriptor(
               classDescriptor.getScopeForMemberResolution(), classDescriptor, constructor);
   classDescriptor.addConstructor(constructorDescriptor, context.getTrace());
   context.getConstructors().put(constructor, constructorDescriptor);
   context.getDeclaringScopes().put(constructor, classDescriptor.getScopeForMemberLookup());
 }
示例#3
0
 private void resolveAnnotationStubsOnClassesAndConstructors() {
   AnnotationResolver annotationResolver =
       new AnnotationResolver(context.getSemanticServices(), context.getTrace());
   for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
     JetClass jetClass = entry.getKey();
     MutableClassDescriptor descriptor = entry.getValue();
     resolveAnnotationsForClassOrObject(annotationResolver, jetClass, descriptor);
   }
   for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry :
       context.getObjects().entrySet()) {
     JetObjectDeclaration objectDeclaration = entry.getKey();
     MutableClassDescriptor descriptor = entry.getValue();
     resolveAnnotationsForClassOrObject(annotationResolver, objectDeclaration, descriptor);
   }
 }
示例#4
0
 public DeclarationResolver(TopDownAnalysisContext context) {
   this.context = context;
   this.annotationResolver =
       new AnnotationResolver(context.getSemanticServices(), context.getTrace());
 }