public MutableClassDescriptor(
      @NotNull DeclarationDescriptor containingDeclaration,
      @NotNull JetScope outerScope,
      @NotNull ClassKind kind,
      boolean isInner,
      @NotNull Name name,
      @NotNull SourceElement source) {
    super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source);
    this.kind = kind;
    this.isInner = isInner;

    RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING;

    setScopeForMemberLookup(
        new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler, "MemberLookup")
            .changeLockLevel(WritableScope.LockLevel.BOTH));
    this.scopeForSupertypeResolution =
        new WritableScopeImpl(outerScope, this, redeclarationHandler, "SupertypeResolution")
            .changeLockLevel(WritableScope.LockLevel.BOTH);
    this.scopeForMemberResolution =
        new WritableScopeImpl(
                scopeForSupertypeResolution, this, redeclarationHandler, "MemberResolution")
            .changeLockLevel(WritableScope.LockLevel.BOTH);

    if (kind == ClassKind.TRAIT) {
      setUpScopeForInitializers(this);
    }

    scopeForMemberResolution.importScope(staticScope);
    scopeForMemberResolution.addLabeledDeclaration(this);
  }
示例#2
0
  @Nullable
  private ScriptDescriptor doAnalyze(
      @NotNull JetFile psiFile, @NotNull MessageCollector messageCollector) {
    WritableScope scope =
        new WritableScopeImpl(
            JetScope.EMPTY,
            module,
            new TraceBasedRedeclarationHandler(trace),
            "Root scope in analyzePackage");

    scope.changeLockLevel(WritableScope.LockLevel.BOTH);

    // Import a scope that contains all top-level packages that come from dependencies
    // This makes the packages visible at all, does not import themselves
    scope.importScope(module.getPackage(FqName.ROOT).getMemberScope());

    if (lastLineScope != null) {
      scope.importScope(lastLineScope);
    }

    scope.changeLockLevel(WritableScope.LockLevel.READING);

    // dummy builder is used because "root" is module descriptor,
    // packages added to module explicitly in
    injector
        .getTopDownAnalyzer()
        .doProcess(
            topDownAnalysisContext,
            scope,
            new PackageLikeBuilderDummy(),
            Collections.singletonList(psiFile));

    boolean hasErrors =
        AnalyzerWithCompilerReport.reportDiagnostics(trace.getBindingContext(), messageCollector);
    if (hasErrors) {
      return null;
    }

    ScriptDescriptor scriptDescriptor =
        topDownAnalysisContext.getScripts().get(psiFile.getScript());
    lastLineScope = trace.get(BindingContext.SCRIPT_SCOPE, scriptDescriptor);
    if (lastLineScope == null) {
      throw new IllegalStateException("last line scope is not initialized");
    }

    return scriptDescriptor;
  }
 @Override
 public void extendNamespaceScope(
     @NotNull BindingTrace trace,
     @NotNull NamespaceDescriptor namespaceDescriptor,
     @NotNull WritableScope namespaceMemberScope) {
   namespaceMemberScope.importScope(
       javaSemanticServices
           .getDescriptorResolver()
           .createJavaPackageScope(
               DescriptorUtils.getFQName(namespaceDescriptor).toSafe(), namespaceDescriptor));
   delegateConfiguration.extendNamespaceScope(trace, namespaceDescriptor, namespaceMemberScope);
 }