Search in sources :

Example 6 with Diagnostic

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;
}
Also used : KtTypeReference(org.jetbrains.kotlin.psi.KtTypeReference) Diagnostic(org.jetbrains.kotlin.diagnostics.Diagnostic)

Example 7 with Diagnostic

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;
}
Also used : Diagnostic(org.jetbrains.kotlin.diagnostics.Diagnostic) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with Diagnostic

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);
        }
    };
}
Also used : Diagnostic(org.jetbrains.kotlin.diagnostics.Diagnostic) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement)

Example 9 with Diagnostic

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);
}
Also used : Diagnostic(org.jetbrains.kotlin.diagnostics.Diagnostic) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Diagnostic (org.jetbrains.kotlin.diagnostics.Diagnostic)9 NotNull (org.jetbrains.annotations.NotNull)5 PsiElement (com.intellij.psi.PsiElement)3 DiagnosticFactory (org.jetbrains.kotlin.diagnostics.DiagnosticFactory)2 KotlinType (org.jetbrains.kotlin.types.KotlinType)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiErrorElement (com.intellij.psi.PsiErrorElement)1 PsiQualifiedNamedElement (com.intellij.psi.PsiQualifiedNamedElement)1 IElementType (com.intellij.psi.tree.IElementType)1 File (java.io.File)1 Collection (java.util.Collection)1 Map (java.util.Map)1 AnalysisResult (org.jetbrains.kotlin.analyzer.AnalysisResult)1 OutputFile (org.jetbrains.kotlin.backend.common.output.OutputFile)1 OutputFileCollection (org.jetbrains.kotlin.backend.common.output.OutputFileCollection)1 GenerationState (org.jetbrains.kotlin.codegen.state.GenerationState)1 LanguageVersion (org.jetbrains.kotlin.config.LanguageVersion)1 CallableDescriptor (org.jetbrains.kotlin.descriptors.CallableDescriptor)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1