use of org.jetbrains.kotlin.config.LanguageVersion in project kotlin by JetBrains.
the class AbstractDiagnosticMessageTest method doTest.
public void doTest(String filePath) throws Exception {
File file = new File(filePath);
String fileName = file.getName();
String fileData = KotlinTestUtils.doLoadFile(file);
Map<String, String> directives = KotlinTestUtils.parseDirectives(fileData);
int diagnosticNumber = getDiagnosticNumber(directives);
final Set<DiagnosticFactory<?>> diagnosticFactories = getDiagnosticFactories(directives);
MessageType messageType = getMessageTypeDirective(directives);
String explicitLanguageVersion = InTextDirectivesUtils.findStringWithPrefixes(fileData, "// LANGUAGE_VERSION:");
LanguageVersion version = explicitLanguageVersion == null ? null : LanguageVersion.fromVersionString(explicitLanguageVersion);
KtFile psiFile = KotlinTestUtils.createFile(fileName, KotlinTestUtils.doLoadFile(getTestDataPath(), fileName), getProject());
AnalysisResult analysisResult = analyze(psiFile, version);
BindingContext bindingContext = analysisResult.getBindingContext();
List<Diagnostic> diagnostics = ContainerUtil.filter(bindingContext.getDiagnostics().all(), new Condition<Diagnostic>() {
@Override
public boolean value(Diagnostic diagnostic) {
return diagnosticFactories.contains(diagnostic.getFactory());
}
});
assertEquals("Expected diagnostics number mismatch:", diagnosticNumber, diagnostics.size());
int index = 1;
String name = FileUtil.getNameWithoutExtension(fileName);
for (Diagnostic diagnostic : diagnostics) {
String readableDiagnosticText;
String extension;
if (messageType != MessageType.TEXT && IdeErrorMessages.hasIdeSpecificMessage(diagnostic)) {
readableDiagnosticText = FormatHtmlUtilKt.formatHtml(IdeErrorMessages.render(diagnostic));
extension = MessageType.HTML.extension;
} else {
readableDiagnosticText = DefaultErrorMessages.render(diagnostic);
extension = MessageType.TEXT.extension;
}
String errorMessageFileName = name + index;
String path = getTestDataPath() + "/" + errorMessageFileName + "." + extension;
String actualText = "<!-- " + errorMessageFileName + " -->\n" + readableDiagnosticText;
assertSameLinesWithFile(path, actualText);
index++;
}
}
use of org.jetbrains.kotlin.config.LanguageVersion in project intellij by bazelbuild.
the class BlazeKotlinSyncPlugin method maybeUpdateCompilerConfig.
/**
* Update the compiler settings of the project if needed. The language setting applies to both the
* api version and the language version. Blanket setting this project wide is fine. The rules
* should catch incorrect usage.
*/
private static void maybeUpdateCompilerConfig(Project project, ProjectViewSet projectViewSet) {
LanguageVersion languageLevel = BlazeKotlinLanguageVersionSection.getLanguageLevel(projectViewSet);
String languageLevelVersionString = languageLevel.getVersionString();
CommonCompilerArguments settings = CommonCompilerArgumentsCompatUtils.getUnfrozenSettings(project);
boolean updated = false;
String apiVersion = CommonCompilerArgumentsCompatUtils.getApiVersion(settings);
String languageVersion = CommonCompilerArgumentsCompatUtils.getLanguageVersion(settings);
if (apiVersion == null || !apiVersion.equals(languageLevelVersionString)) {
updated = true;
CommonCompilerArgumentsCompatUtils.setApiVersion(settings, languageLevelVersionString);
}
if (languageVersion == null || !languageVersion.equals(languageLevelVersionString)) {
updated = true;
CommonCompilerArgumentsCompatUtils.setLanguageVersion(settings, languageLevelVersionString);
}
if (updated) {
KotlinCommonCompilerArgumentsHolder.Companion.getInstance(project).setSettings(settings);
}
}
Aggregations