コード例 #1
0
 @Nullable
 private static FqName findMainClass(
     @NotNull GenerationState generationState, @NotNull List<KtFile> files) {
   MainFunctionDetector mainFunctionDetector =
       new MainFunctionDetector(generationState.getBindingContext());
   FqName mainClass = null;
   for (KtFile file : files) {
     if (mainFunctionDetector.hasMain(file.getDeclarations())) {
       if (mainClass != null) {
         // more than one main
         return null;
       }
       FqName fqName = file.getPackageFqName();
       mainClass = JvmFileClassUtil.getFileClassInfoNoResolve(file).getFacadeClassFqName();
     }
   }
   return mainClass;
 }
コード例 #2
0
ファイル: KotlinTestUtils.java プロジェクト: yilab/kotlin
  @NotNull
  public static List<String> getLastCommentsInFile(
      @NotNull KtFile file, CommentType commentType, boolean assertMustExist) {
    PsiElement lastChild = file.getLastChild();
    if (lastChild != null && lastChild.getNode().getElementType().equals(KtTokens.WHITE_SPACE)) {
      lastChild = lastChild.getPrevSibling();
    }
    assert lastChild != null;

    List<String> comments = ContainerUtil.newArrayList();

    while (true) {
      if (lastChild.getNode().getElementType().equals(KtTokens.BLOCK_COMMENT)) {
        if (commentType == CommentType.ALL || commentType == CommentType.BLOCK_COMMENT) {
          String lastChildText = lastChild.getText();
          comments.add(lastChildText.substring(2, lastChildText.length() - 2).trim());
        }
      } else if (lastChild.getNode().getElementType().equals(KtTokens.EOL_COMMENT)) {
        if (commentType == CommentType.ALL || commentType == CommentType.LINE_COMMENT) {
          comments.add(lastChild.getText().substring(2).trim());
        }
      } else {
        break;
      }

      lastChild = lastChild.getPrevSibling();
    }

    if (comments.isEmpty() && assertMustExist) {
      throw new AssertionError(
          String.format(
              "Test file '%s' should end in a comment of type %s; last node was: %s",
              file.getName(), commentType, lastChild));
    }

    return comments;
  }
コード例 #3
0
  @Nullable
  static KtClass getClassDeclarationInFile(KtFile jetFile) {
    KtClass tempSingleDeclaration = null;

    for (KtDeclaration ktDeclaration : jetFile.getDeclarations()) {
      if (ktDeclaration instanceof KtClass) {
        KtClass declaration = (KtClass) ktDeclaration;

        if (tempSingleDeclaration == null) {
          tempSingleDeclaration = declaration;
        } else {
          // There are several class declarations in file
          return null;
        }
      }
    }

    return tempSingleDeclaration;
  }