Ejemplo n.º 1
0
  public void checkRedeclarationsInInnerClassNames(@NotNull TopDownAnalysisContext c) {
    for (ClassDescriptorWithResolutionScopes classDescriptor : c.getDeclaredClasses().values()) {
      if (classDescriptor.getKind() == ClassKind.CLASS_OBJECT) {
        // Class objects should be considered during analysing redeclarations in classes
        continue;
      }

      Collection<DeclarationDescriptor> allDescriptors =
          classDescriptor.getScopeForMemberLookup().getOwnDeclaredDescriptors();

      ClassDescriptorWithResolutionScopes classObj = classDescriptor.getClassObjectDescriptor();
      if (classObj != null) {
        Collection<DeclarationDescriptor> classObjDescriptors =
            classObj.getScopeForMemberLookup().getOwnDeclaredDescriptors();
        if (!classObjDescriptors.isEmpty()) {
          allDescriptors = Lists.newArrayList(allDescriptors);
          allDescriptors.addAll(classObjDescriptors);
        }
      }

      Multimap<Name, DeclarationDescriptor> descriptorMap = HashMultimap.create();
      for (DeclarationDescriptor desc : allDescriptors) {
        if (desc instanceof ClassDescriptor || desc instanceof PropertyDescriptor) {
          descriptorMap.put(desc.getName(), desc);
        }
      }

      reportRedeclarations(descriptorMap);
    }
  }
Ejemplo n.º 2
0
  private void resolveFunctionAndPropertyHeaders(@NotNull TopDownAnalysisContext c) {
    for (Map.Entry<JetFile, WritableScope> entry : c.getFileScopes().entrySet()) {
      JetFile file = entry.getKey();
      WritableScope fileScope = entry.getValue();
      PackageLikeBuilder packageBuilder = c.getPackageFragments().get(file).getBuilder();

      resolveFunctionAndPropertyHeaders(
          c, file.getDeclarations(), fileScope, fileScope, fileScope, packageBuilder);
    }
    for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
        c.getDeclaredClasses().entrySet()) {
      JetClassOrObject classOrObject = entry.getKey();
      MutableClassDescriptor classDescriptor = (MutableClassDescriptor) entry.getValue();

      resolveFunctionAndPropertyHeaders(
          c,
          classOrObject.getDeclarations(),
          classDescriptor.getScopeForMemberDeclarationResolution(),
          classDescriptor.getScopeForInitializerResolution(),
          classDescriptor.getScopeForMemberDeclarationResolution(),
          classDescriptor.getBuilder());
    }

    // TODO : Extensions
  }
Ejemplo n.º 3
0
  private void resolveAnnotationConstructors(@NotNull TopDownAnalysisContext c) {
    for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
        c.getDeclaredClasses().entrySet()) {
      JetClassOrObject classOrObject = entry.getKey();
      MutableClassDescriptor classDescriptor = (MutableClassDescriptor) entry.getValue();

      if (classOrObject instanceof JetClass && DescriptorUtils.isAnnotationClass(classDescriptor)) {
        processPrimaryConstructor(c, classDescriptor, (JetClass) classOrObject);
      }
    }
  }
Ejemplo n.º 4
0
 private void resolveAnnotationStubsOnClassesAndConstructors(@NotNull TopDownAnalysisContext c) {
   for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
       c.getDeclaredClasses().entrySet()) {
     JetModifierList modifierList = entry.getKey().getModifierList();
     if (modifierList != null) {
       MutableClassDescriptor descriptor = (MutableClassDescriptor) entry.getValue();
       descriptor.addAnnotations(
           annotationResolver.resolveAnnotationsWithoutArguments(
               descriptor.getScopeForClassHeaderResolution(), modifierList, trace));
     }
   }
 }
Ejemplo n.º 5
0
  private void createFunctionsForDataClasses(@NotNull TopDownAnalysisContext c) {
    for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
        c.getDeclaredClasses().entrySet()) {
      JetClassOrObject klass = entry.getKey();
      MutableClassDescriptor classDescriptor = (MutableClassDescriptor) entry.getValue();

      if (klass instanceof JetClass
          && klass.hasPrimaryConstructor()
          && KotlinBuiltIns.getInstance().isData(classDescriptor)) {
        ConstructorDescriptor constructor =
            DescriptorUtils.getConstructorOfDataClass(classDescriptor);
        createComponentFunctions(classDescriptor, constructor);
        createCopyFunction(classDescriptor, constructor);
      }
    }
  }