getDiagnostics() in BindingContext returns Diagnostics rather than List<Diagnostic>
This commit is contained in:
+1
-1
@@ -153,7 +153,7 @@ public final class AnalyzerWithCompilerReport {
|
|||||||
|
|
||||||
public static boolean reportDiagnostics(@NotNull BindingContext bindingContext, @NotNull MessageCollector messageCollector) {
|
public static boolean reportDiagnostics(@NotNull BindingContext bindingContext, @NotNull MessageCollector messageCollector) {
|
||||||
boolean hasErrors = false;
|
boolean hasErrors = false;
|
||||||
for (Diagnostic diagnostic : sortedDiagnostics(bindingContext.getDiagnostics())) {
|
for (Diagnostic diagnostic : sortedDiagnostics(bindingContext.getDiagnostics().all())) {
|
||||||
hasErrors |= reportDiagnostic(diagnostic, messageCollector);
|
hasErrors |= reportDiagnostic(diagnostic, messageCollector);
|
||||||
}
|
}
|
||||||
return hasErrors;
|
return hasErrors;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class CheckerTestUtil {
|
|||||||
|
|
||||||
public static List<Diagnostic> getDiagnosticsIncludingSyntaxErrors(BindingContext bindingContext, final PsiElement root) {
|
public static List<Diagnostic> getDiagnosticsIncludingSyntaxErrors(BindingContext bindingContext, final PsiElement root) {
|
||||||
ArrayList<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
|
ArrayList<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
|
||||||
diagnostics.addAll(Collections2.filter(bindingContext.getDiagnostics(),
|
diagnostics.addAll(Collections2.filter(bindingContext.getDiagnostics().all(),
|
||||||
new Predicate<Diagnostic>() {
|
new Predicate<Diagnostic>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Diagnostic diagnostic) {
|
public boolean apply(Diagnostic diagnostic) {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.annotations.TestOnly;
|
import org.jetbrains.annotations.TestOnly;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter;
|
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter;
|
||||||
@@ -46,8 +45,8 @@ public interface BindingContext {
|
|||||||
BindingContext EMPTY = new BindingContext() {
|
BindingContext EMPTY = new BindingContext() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<Diagnostic> getDiagnostics() {
|
public Diagnostics getDiagnostics() {
|
||||||
return Collections.emptyList();
|
return Diagnostics.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -265,7 +264,7 @@ public interface BindingContext {
|
|||||||
Void _static_initializer = BasicWritableSlice.initSliceDebugNames(BindingContext.class);
|
Void _static_initializer = BasicWritableSlice.initSliceDebugNames(BindingContext.class);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Collection<Diagnostic> getDiagnostics();
|
Diagnostics getDiagnostics();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
<K, V> V get(ReadOnlySlice<K, V> slice, K key);
|
<K, V> V get(ReadOnlySlice<K, V> slice, K key);
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BindingTraceContext implements BindingTrace {
|
public class BindingTraceContext implements BindingTrace {
|
||||||
private final List<Diagnostic> diagnostics = Lists.newArrayList();
|
private final List<Diagnostic> diagnosticList = Lists.newArrayList();
|
||||||
|
private final Diagnostics diagnostics;
|
||||||
|
|
||||||
// These flags are used for debugging of "Rewrite at slice..." exceptions
|
// These flags are used for debugging of "Rewrite at slice..." exceptions
|
||||||
/* package */ final static boolean TRACK_REWRITES = false;
|
/* package */ final static boolean TRACK_REWRITES = false;
|
||||||
@@ -39,7 +40,7 @@ public class BindingTraceContext implements BindingTrace {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<Diagnostic> getDiagnostics() {
|
public Diagnostics getDiagnostics() {
|
||||||
return diagnostics;
|
return diagnostics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,12 +65,13 @@ public class BindingTraceContext implements BindingTrace {
|
|||||||
|
|
||||||
public BindingTraceContext() {
|
public BindingTraceContext() {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
this.map = TRACK_REWRITES ? new TrackingSlicedMap(TRACK_WITH_STACK_TRACES) : SlicedMapImpl.create();
|
this(TRACK_REWRITES ? new TrackingSlicedMap(TRACK_WITH_STACK_TRACES) : SlicedMapImpl.create());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private BindingTraceContext(MutableSlicedMap map) {
|
private BindingTraceContext(@NotNull MutableSlicedMap map) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
|
this.diagnostics = new SimpleDiagnostics(diagnosticList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOnly
|
@TestOnly
|
||||||
@@ -79,11 +81,11 @@ public class BindingTraceContext implements BindingTrace {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void report(@NotNull Diagnostic diagnostic) {
|
public void report(@NotNull Diagnostic diagnostic) {
|
||||||
diagnostics.add(diagnostic);
|
diagnosticList.add(diagnostic);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearDiagnostics() {
|
public void clearDiagnostics() {
|
||||||
diagnostics.clear();
|
diagnosticList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -40,10 +40,10 @@ public class DelegatingBindingTrace implements BindingTrace {
|
|||||||
private final BindingContext bindingContext = new BindingContext() {
|
private final BindingContext bindingContext = new BindingContext() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<Diagnostic> getDiagnostics() {
|
public Diagnostics getDiagnostics() {
|
||||||
ArrayList<Diagnostic> mergedDiagnostics = new ArrayList<Diagnostic>(diagnostics);
|
ArrayList<Diagnostic> mergedDiagnostics = new ArrayList<Diagnostic>(diagnostics);
|
||||||
mergedDiagnostics.addAll(parentContext.getDiagnostics());
|
mergedDiagnostics.addAll(parentContext.getDiagnostics().noSuppression().all());
|
||||||
return mergedDiagnostics;
|
return new SimpleDiagnostics(mergedDiagnostics);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package org.jetbrains.jet.lang.resolve;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public interface Diagnostics extends Iterable<Diagnostic> {
|
||||||
|
@NotNull
|
||||||
|
Collection<Diagnostic> all();
|
||||||
|
|
||||||
|
boolean isEmpty();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
Diagnostics noSuppression();
|
||||||
|
|
||||||
|
Diagnostics EMPTY = new Diagnostics() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<Diagnostic> all() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Diagnostics noSuppression() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Iterator<Diagnostic> iterator() {
|
||||||
|
return all().iterator();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.jetbrains.jet.lang.resolve;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public class SimpleDiagnostics implements Diagnostics {
|
||||||
|
private final Collection<Diagnostic> diagnostics;
|
||||||
|
|
||||||
|
public SimpleDiagnostics(@NotNull Collection<Diagnostic> diagnostics) {
|
||||||
|
this.diagnostics = diagnostics;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<Diagnostic> all() {
|
||||||
|
return diagnostics;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Diagnostics noSuppression() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Iterator<Diagnostic> iterator() {
|
||||||
|
return all().iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return all().isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -64,7 +64,7 @@ public class TraceUtil {
|
|||||||
public final static BindingContext BINDING_CONTEXT_STUB = new BindingContext() {
|
public final static BindingContext BINDING_CONTEXT_STUB = new BindingContext() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<Diagnostic> getDiagnostics() {
|
public Diagnostics getDiagnostics() {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.TestOnly;
|
|||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.jet.lang.resolve.Diagnostics;
|
||||||
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
||||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ public class LockBasedLazyResolveStorageManager extends LockBasedStorageManager
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<Diagnostic> getDiagnostics() {
|
public Diagnostics getDiagnostics() {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
return context.getDiagnostics();
|
return context.getDiagnostics();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import org.jetbrains.jet.lang.diagnostics.Severity;
|
|||||||
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||||
@@ -101,7 +102,7 @@ public class JetTestUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<Diagnostic> getDiagnostics() {
|
public Diagnostics getDiagnostics() {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
throw new UnsupportedOperationException(); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +161,7 @@ public class JetTestUtils {
|
|||||||
return new BindingContext() {
|
return new BindingContext() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<Diagnostic> getDiagnostics() {
|
public Diagnostics getDiagnostics() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class IdeRenderers {
|
|||||||
private Set<ValueParameterDescriptor> getParametersToHighlight(ResolvedCall<? extends CallableDescriptor> call) {
|
private Set<ValueParameterDescriptor> getParametersToHighlight(ResolvedCall<? extends CallableDescriptor> call) {
|
||||||
Set<ValueParameterDescriptor> parameters = new HashSet<ValueParameterDescriptor>();
|
Set<ValueParameterDescriptor> parameters = new HashSet<ValueParameterDescriptor>();
|
||||||
if (call instanceof ResolvedCallImpl) {
|
if (call instanceof ResolvedCallImpl) {
|
||||||
Collection<Diagnostic> diagnostics = ((ResolvedCallImpl)call).getTrace().getBindingContext().getDiagnostics();
|
Iterable<Diagnostic> diagnostics = ((ResolvedCallImpl)call).getTrace().getBindingContext().getDiagnostics();
|
||||||
for (Diagnostic diagnostic : diagnostics) {
|
for (Diagnostic diagnostic : diagnostics) {
|
||||||
if (diagnostic.getFactory() == Errors.TOO_MANY_ARGUMENTS) {
|
if (diagnostic.getFactory() == Errors.TOO_MANY_ARGUMENTS) {
|
||||||
parameters.add(null);
|
parameters.add(null);
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class MapPlatformClassToKotlinFix extends JetIntentionAction<JetReference
|
|||||||
@Override
|
@Override
|
||||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||||
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(file);
|
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(file);
|
||||||
Collection<Diagnostic> diagnostics = context.getDiagnostics();
|
Iterable<Diagnostic> diagnostics = context.getDiagnostics();
|
||||||
List<JetImportDirective> imports = new ArrayList<JetImportDirective>();
|
List<JetImportDirective> imports = new ArrayList<JetImportDirective>();
|
||||||
List<JetUserType> usages = new ArrayList<JetUserType>();
|
List<JetUserType> usages = new ArrayList<JetUserType>();
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class DiagnosticMessageTest extends JetLiteFixture {
|
|||||||
BindingContext bindingContext = analyzeExhaust.getBindingContext();
|
BindingContext bindingContext = analyzeExhaust.getBindingContext();
|
||||||
|
|
||||||
final Set<AbstractDiagnosticFactory> factoriesSet = Sets.newHashSet(diagnosticFactories);
|
final Set<AbstractDiagnosticFactory> factoriesSet = Sets.newHashSet(diagnosticFactories);
|
||||||
List<Diagnostic> diagnostics = ContainerUtil.filter(bindingContext.getDiagnostics(), new Condition<Diagnostic>() {
|
List<Diagnostic> diagnostics = ContainerUtil.filter(bindingContext.getDiagnostics().all(), new Condition<Diagnostic>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean value(Diagnostic diagnostic) {
|
public boolean value(Diagnostic diagnostic) {
|
||||||
return factoriesSet.contains(diagnostic.getFactory());
|
return factoriesSet.contains(diagnostic.getFactory());
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class NoErrorsInStdlibTest: LightCodeInsightFixtureTestCase() {
|
|||||||
val psiFile = psiManager.findFile(file)
|
val psiFile = psiManager.findFile(file)
|
||||||
if (psiFile is JetFile) {
|
if (psiFile is JetFile) {
|
||||||
var bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache(psiFile).getBindingContext()
|
var bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache(psiFile).getBindingContext()
|
||||||
val errors = bindingContext.getDiagnostics().filter { it.getSeverity() == Severity.ERROR }
|
val errors = bindingContext.getDiagnostics().all().filter { it.getSeverity() == Severity.ERROR }
|
||||||
|
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
System.err.println("${psiFile.getName()}: ${errors.size()} errors")
|
System.err.println("${psiFile.getName()}: ${errors.size()} errors")
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class QuickFixActionsUtils {
|
|||||||
|
|
||||||
AnalyzeExhaust exhaust = AnalyzerFacadeWithCache.analyzeFileWithCache(file);
|
AnalyzeExhaust exhaust = AnalyzerFacadeWithCache.analyzeFileWithCache(file);
|
||||||
|
|
||||||
Collection<Diagnostic> diagnostics = exhaust.getBindingContext().getDiagnostics();
|
Collection<Diagnostic> diagnostics = exhaust.getBindingContext().getDiagnostics().all();
|
||||||
Collection<Diagnostic> errorDiagnostics = Collections2.filter(diagnostics, new Predicate<Diagnostic>() {
|
Collection<Diagnostic> errorDiagnostics = Collections2.filter(diagnostics, new Predicate<Diagnostic>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable Diagnostic diagnostic) {
|
public boolean apply(@Nullable Diagnostic diagnostic) {
|
||||||
|
|||||||
Reference in New Issue
Block a user