Java Code Examples for org.jetbrains.kotlin.psi.KtFile

The following examples show how to use org.jetbrains.kotlin.psi.KtFile. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: intellij   Source File: KotlinSyncStatusContributor.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public PsiFileAndName toPsiFileAndName(BlazeProjectData projectData, ProjectViewNode<?> node) {
  if (!projectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.KOTLIN)) {
    return null;
  }
  if (node instanceof KtFileTreeNode) {
    KtFile file = ((KtFileTreeNode) node).getKtFile();
    return new PsiFileAndName(file, file.getName());
  }
  if (node instanceof KtClassOrObjectTreeNode) {
    KtClassOrObject kt = ((KtClassOrObjectTreeNode) node).getValue();
    return kt != null ? new PsiFileAndName(kt.getContainingKtFile(), kt.getName()) : null;
  }
  return null;
}
 
Example 2
Source Project: jig   Source File: KotlinSdkAliasReader.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TypeAliases readAlias(KotlinSources sources) {
    KotlinSourceVisitor visitor = new KotlinSourceVisitor();

    for (KotlinSource kotlinSource : sources.list()) {
        KtFile ktFile = readKotlinSource(kotlinSource);
        if (ktFile == null) {
            continue;
        }

        ktFile.accept(visitor);
    }

    return new TypeAliases(visitor.typeJapaneseAliases, visitor.methodList);
}
 
Example 3
Source Project: jig   Source File: KotlinSdkAliasReader.java    License: Apache License 2.0 5 votes vote down vote up
private KtFile sourceToKtFile(KotlinSource kotlinSource, String source) {
    CompilerConfiguration configuration = new CompilerConfiguration();
    configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.Companion.getNONE());
    KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForProduction(() -> {
    }, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    Project project = environment.getProject();
    LightVirtualFile virtualFile = new LightVirtualFile(kotlinSource.sourceFilePath().fineName(), KotlinFileType.INSTANCE, source);
    return (KtFile) PsiManager.getInstance(project).findFile(virtualFile);
}
 
Example 4
Source Project: jig   Source File: KotlinSdkAliasReader.java    License: Apache License 2.0 5 votes vote down vote up
private KtFile readKotlinSource(KotlinSource source) {
    try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(source.toInputStream(), Charset.forName("utf8")))) {
        String sourceCode = bufferedReader.lines().collect(Collectors.joining("\n"));
        return sourceToKtFile(source, sourceCode);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 5
Source Project: sputnik   Source File: LoggingFileProcessor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onStart(List<? extends KtFile> list) {
    log.debug("Found {} files for review", list.size());
}
 
Example 6
Source Project: sputnik   Source File: LoggingFileProcessor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onProcess(KtFile ktFile) {
    log.debug("Processing {}", ktFile.getName());
}
 
Example 7
Source Project: sputnik   Source File: LoggingFileProcessor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onProcessComplete(KtFile ktFile, Map<String, ? extends List<? extends Finding>> map) {
    log.debug("Processed {} and found {} problems", ktFile.getName(), countProblems(map));
}
 
Example 8
Source Project: sputnik   Source File: LoggingFileProcessor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void onFinish(List<? extends KtFile> list, Detektion detektion) {
    log.debug("Processed {} files and found {} problems", list.size(), countProblems(detektion));
}