use of org.jetbrains.kotlin.diagnostics.Diagnostic in project kotlin by JetBrains.
the class TypeSubstitutorTest method resolveType.
private KotlinType resolveType(String typeStr) {
KtTypeReference jetTypeReference = KtPsiFactoryKt.KtPsiFactory(getProject()).createType(typeStr);
AnalyzingUtils.checkForSyntacticErrors(jetTypeReference);
BindingTrace trace = new BindingTraceContext();
KotlinType type = container.getTypeResolver().resolveType(scope, jetTypeReference, trace, true);
if (!trace.getBindingContext().getDiagnostics().isEmpty()) {
fail("Errors:\n" + StringUtil.join(trace.getBindingContext().getDiagnostics(), new Function<Diagnostic, String>() {
@Override
public String fun(Diagnostic diagnostic) {
return DefaultErrorMessages.render(diagnostic);
}
}, "\n"));
}
return type;
}
use of org.jetbrains.kotlin.diagnostics.Diagnostic in project kotlin by JetBrains.
the class CheckerTestUtil method getSortedDiagnosticDescriptors.
@NotNull
private static List<DiagnosticDescriptor> getSortedDiagnosticDescriptors(@NotNull Collection<ActualDiagnostic> diagnostics) {
LinkedListMultimap<TextRange, ActualDiagnostic> diagnosticsGroupedByRanges = LinkedListMultimap.create();
for (ActualDiagnostic actualDiagnostic : diagnostics) {
Diagnostic diagnostic = actualDiagnostic.diagnostic;
if (!diagnostic.isValid())
continue;
for (TextRange textRange : diagnostic.getTextRanges()) {
diagnosticsGroupedByRanges.put(textRange, actualDiagnostic);
}
}
List<DiagnosticDescriptor> diagnosticDescriptors = Lists.newArrayList();
for (TextRange range : diagnosticsGroupedByRanges.keySet()) {
diagnosticDescriptors.add(new DiagnosticDescriptor(range.getStartOffset(), range.getEndOffset(), diagnosticsGroupedByRanges.get(range)));
}
Collections.sort(diagnosticDescriptors, new Comparator<DiagnosticDescriptor>() {
@Override
public int compare(@NotNull DiagnosticDescriptor d1, @NotNull DiagnosticDescriptor d2) {
// Start early -- go first; start at the same offset, the one who end later is the outer, i.e. goes first
return (d1.start != d2.start) ? d1.start - d2.start : d2.end - d1.end;
}
});
return diagnosticDescriptors;
}
use of org.jetbrains.kotlin.diagnostics.Diagnostic in project kotlin by JetBrains.
the class RemovePartsFromPropertyFix method createFactory.
public static KotlinSingleIntentionActionFactory createFactory() {
return new KotlinSingleIntentionActionFactory() {
@Override
public KotlinQuickFixAction<KtProperty> createAction(@NotNull Diagnostic diagnostic) {
PsiElement element = diagnostic.getPsiElement();
assert element instanceof KtElement;
KtProperty property = PsiTreeUtil.getParentOfType(element, KtProperty.class);
if (property == null)
return null;
return new RemovePartsFromPropertyFix(property);
}
};
}
use of org.jetbrains.kotlin.diagnostics.Diagnostic in project kotlin by JetBrains.
the class BasicExpressionTypingVisitor method visitStringTemplateExpression.
@Override
public KotlinTypeInfo visitStringTemplateExpression(@NotNull KtStringTemplateExpression expression, ExpressionTypingContext contextWithExpectedType) {
final ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT);
checkLiteralPrefixAndSuffix(expression, context);
class StringTemplateVisitor extends KtVisitorVoid {
private KotlinTypeInfo typeInfo = TypeInfoFactoryKt.noTypeInfo(context);
@Override
public void visitStringTemplateEntryWithExpression(@NotNull KtStringTemplateEntryWithExpression entry) {
KtExpression entryExpression = entry.getExpression();
if (entryExpression != null) {
typeInfo = facade.getTypeInfo(entryExpression, context.replaceDataFlowInfo(typeInfo.getDataFlowInfo()));
}
}
@Override
public void visitEscapeStringTemplateEntry(@NotNull KtEscapeStringTemplateEntry entry) {
CompileTimeConstantChecker.CharacterWithDiagnostic value = CompileTimeConstantChecker.escapedStringToCharacter(entry.getText(), entry);
Diagnostic diagnostic = value.getDiagnostic();
if (diagnostic != null) {
context.trace.report(diagnostic);
}
}
}
StringTemplateVisitor visitor = new StringTemplateVisitor();
for (KtStringTemplateEntry entry : expression.getEntries()) {
entry.accept(visitor);
}
components.constantExpressionEvaluator.evaluateExpression(expression, context.trace, contextWithExpectedType.expectedType);
return components.dataFlowAnalyzer.checkType(visitor.typeInfo.replaceType(components.builtIns.getStringType()), expression, contextWithExpectedType);
}
Aggregations