コード例 #1
0
 @NotNull
 private List<KotlinLightPackageClassInfo> findPackageClassesInfos(
     @NotNull FqName fqName, @NotNull GlobalSearchScope wholeScope) {
   Collection<JetFile> allFiles = findFilesForPackage(fqName, wholeScope);
   Map<IdeaModuleInfo, List<JetFile>> filesByInfo = groupByModuleInfo(allFiles);
   List<KotlinLightPackageClassInfo> result = new ArrayList<KotlinLightPackageClassInfo>();
   for (Map.Entry<IdeaModuleInfo, List<JetFile>> entry : filesByInfo.entrySet()) {
     result.add(new KotlinLightPackageClassInfo(entry.getValue(), entry.getKey()));
   }
   return result;
 }
コード例 #2
0
ファイル: InlineCodegen.java プロジェクト: grigala/kotlin
 public void leaveTemps() {
   FrameMap frameMap = codegen.getFrameMap();
   List<ParameterInfo> infos = invocationParamBuilder.listAllParams();
   for (ListIterator<? extends ParameterInfo> iterator = infos.listIterator(infos.size());
       iterator.hasPrevious(); ) {
     ParameterInfo param = iterator.previous();
     if (!param.isSkippedOrRemapped()) {
       frameMap.leaveTemp(param.type);
     }
   }
 }
コード例 #3
0
 @Nullable
 private static PsiClass getLightClassForDecompiledPackage(
     @NotNull FqName packageFqName, @NotNull List<JetFile> filesWithCallables) {
   JetFile firstFile = filesWithCallables.iterator().next();
   if (firstFile.isCompiled()) {
     if (filesWithCallables.size() > 1) {
       LOG.error("Several files with callables for package: " + packageFqName);
     }
     return createLightClassForDecompiledKotlinFile(firstFile);
   }
   return null;
 }
コード例 #4
0
  @NotNull
  @Override
  public LightClassConstructionContext getContextForPackage(@NotNull Collection<JetFile> files) {
    assert !files.isEmpty() : "No files in package";

    List<JetFile> sortedFiles = new ArrayList<JetFile>(files);
    Collections.sort(sortedFiles, scopeFileComparator);

    JetFile file = sortedFiles.get(0);
    ResolveSessionForBodies session =
        KotlinCacheService.getInstance(file.getProject()).getLazyResolveSession(file);
    forceResolvePackageDeclarations(files, session);
    return new LightClassConstructionContext(
        session.getBindingContext(), session.getModuleDescriptor());
  }
コード例 #5
0
  @NotNull
  @Override
  public Collection<PsiClass> getPackageClasses(
      @NotNull FqName packageFqName, @NotNull GlobalSearchScope scope) {
    List<PsiClass> result = new ArrayList<PsiClass>();
    List<KotlinLightPackageClassInfo> packageClassesInfos =
        findPackageClassesInfos(packageFqName, scope);
    for (KotlinLightPackageClassInfo info : packageClassesInfos) {
      List<JetFile> files = PackagePartClassUtils.getPackageFilesWithCallables(info.getFiles());
      if (files.isEmpty()) continue;

      IdeaModuleInfo moduleInfo = info.getModuleInfo();
      if (moduleInfo instanceof ModuleSourceInfo) {
        KotlinLightClassForPackage lightClass =
            KotlinLightClassForPackage.Factory.create(
                psiManager, packageFqName, moduleInfo.contentScope(), files);
        if (lightClass == null) continue;

        result.add(lightClass);

        if (files.size() > 1) {
          for (JetFile file : files) {
            result.add(new FakeLightClassForFileOfPackage(psiManager, lightClass, file));
          }
        }
      } else {
        PsiClass clsClass = getLightClassForDecompiledPackage(packageFqName, files);
        if (clsClass != null) {
          result.add(clsClass);
        }
      }
    }
    return result;
  }
コード例 #6
0
ファイル: InlineCodegen.java プロジェクト: grigala/kotlin
  @Override
  public void putHiddenParams() {
    List<JvmMethodParameterSignature> valueParameters = jvmSignature.getValueParameters();

    if (!isStaticMethod(functionDescriptor, context)) {
      invocationParamBuilder.addNextParameter(AsmTypes.OBJECT_TYPE, false, null);
    }

    for (JvmMethodParameterSignature param : valueParameters) {
      if (param.getKind() == JvmMethodParameterKind.VALUE) {
        break;
      }
      invocationParamBuilder.addNextParameter(param.getAsmType(), false, null);
    }

    List<ParameterInfo> infos = invocationParamBuilder.listNotCaptured();
    putParameterOnStack(infos.toArray(new ParameterInfo[infos.size()]));
  }
コード例 #7
0
  private void checkEnumEntry(
      @NotNull JetEnumEntry enumEntry, @NotNull ClassDescriptor classDescriptor) {
    DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration();
    assert DescriptorUtils.isEnumClass(declaration)
        : "Enum entry should be declared in enum class: " + classDescriptor;
    ClassDescriptor enumClass = (ClassDescriptor) declaration;

    if (enumEntryUsesDeprecatedSuperConstructor(enumEntry)) {
      trace.report(
          Errors.ENUM_ENTRY_USES_DEPRECATED_SUPER_CONSTRUCTOR.on(enumEntry, classDescriptor));
    }
    String neededDelimiter = enumEntryExpectedDelimiter(enumEntry);
    if (!neededDelimiter.isEmpty()) {
      trace.report(
          Errors.ENUM_ENTRY_USES_DEPRECATED_OR_NO_DELIMITER.on(
              enumEntry, classDescriptor, neededDelimiter));
    }
    if (enumEntryAfterEnumMember(enumEntry)) {
      trace.report(Errors.ENUM_ENTRY_AFTER_ENUM_MEMBER.on(enumEntry, classDescriptor));
    }

    List<JetDelegationSpecifier> delegationSpecifiers = enumEntry.getDelegationSpecifiers();
    ConstructorDescriptor constructor = enumClass.getUnsubstitutedPrimaryConstructor();
    if ((constructor == null || !constructor.getValueParameters().isEmpty())
        && delegationSpecifiers.isEmpty()) {
      trace.report(ENUM_ENTRY_SHOULD_BE_INITIALIZED.on(enumEntry, enumClass));
    }

    for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
      JetTypeReference typeReference = delegationSpecifier.getTypeReference();
      if (typeReference != null) {
        JetType type = trace.getBindingContext().get(TYPE, typeReference);
        if (type != null) {
          JetType enumType = enumClass.getDefaultType();
          if (!type.getConstructor().equals(enumType.getConstructor())) {
            trace.report(ENUM_ENTRY_ILLEGAL_TYPE.on(typeReference, enumClass));
          }
        }
      }
    }
  }
コード例 #8
0
  @Nullable
  private KtNamedDeclaration[] getVariables(Expression[] params, ExpressionContext context) {
    if (params.length != 0) return null;

    Project project = context.getProject();
    PsiDocumentManager.getInstance(project).commitAllDocuments();

    PsiFile psiFile =
        PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
    if (!(psiFile instanceof KtFile)) return null;

    KtExpression contextExpression = findContextExpression(psiFile, context.getStartOffset());
    if (contextExpression == null) return null;

    ResolutionFacade resolutionFacade = ResolutionUtils.getResolutionFacade(contextExpression);

    BindingContext bindingContext =
        resolutionFacade.analyze(contextExpression, BodyResolveMode.FULL);
    LexicalScope scope =
        ScopeUtils.getResolutionScope(contextExpression, bindingContext, resolutionFacade);

    IterableTypesDetector detector =
        resolutionFacade.getIdeService(IterableTypesDetection.class).createDetector(scope);

    DataFlowInfo dataFlowInfo =
        BindingContextUtilsKt.getDataFlowInfo(bindingContext, contextExpression);

    List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
    for (DeclarationDescriptor declarationDescriptor : getAllVariables(scope)) {
      if (declarationDescriptor instanceof VariableDescriptor) {
        VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;

        if (variableDescriptor.getExtensionReceiverParameter() != null
            && ExtensionUtils.substituteExtensionIfCallableWithImplicitReceiver(
                    variableDescriptor, scope, bindingContext, dataFlowInfo)
                .isEmpty()) {
          continue;
        }

        if (isSuitable(variableDescriptor, project, detector)) {
          filteredDescriptors.add(variableDescriptor);
        }
      }
    }

    List<KtNamedDeclaration> declarations = new ArrayList<KtNamedDeclaration>();
    for (DeclarationDescriptor declarationDescriptor : filteredDescriptors) {
      PsiElement declaration =
          DescriptorToSourceUtils.descriptorToDeclaration(declarationDescriptor);
      assert declaration == null || declaration instanceof PsiNamedElement;

      if (declaration instanceof KtProperty || declaration instanceof KtParameter) {
        declarations.add((KtNamedDeclaration) declaration);
      }
    }

    return declarations.toArray(new KtNamedDeclaration[declarations.size()]);
  }