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) {
|
||||
boolean hasErrors = false;
|
||||
for (Diagnostic diagnostic : sortedDiagnostics(bindingContext.getDiagnostics())) {
|
||||
for (Diagnostic diagnostic : sortedDiagnostics(bindingContext.getDiagnostics().all())) {
|
||||
hasErrors |= reportDiagnostic(diagnostic, messageCollector);
|
||||
}
|
||||
return hasErrors;
|
||||
|
||||
@@ -70,7 +70,7 @@ public class CheckerTestUtil {
|
||||
|
||||
public static List<Diagnostic> getDiagnosticsIncludingSyntaxErrors(BindingContext bindingContext, final PsiElement root) {
|
||||
ArrayList<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
|
||||
diagnostics.addAll(Collections2.filter(bindingContext.getDiagnostics(),
|
||||
diagnostics.addAll(Collections2.filter(bindingContext.getDiagnostics().all(),
|
||||
new Predicate<Diagnostic>() {
|
||||
@Override
|
||||
public boolean apply(Diagnostic diagnostic) {
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
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.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter;
|
||||
@@ -46,8 +45,8 @@ public interface BindingContext {
|
||||
BindingContext EMPTY = new BindingContext() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
return Collections.emptyList();
|
||||
public Diagnostics getDiagnostics() {
|
||||
return Diagnostics.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -265,7 +264,7 @@ public interface BindingContext {
|
||||
Void _static_initializer = BasicWritableSlice.initSliceDebugNames(BindingContext.class);
|
||||
|
||||
@NotNull
|
||||
Collection<Diagnostic> getDiagnostics();
|
||||
Diagnostics getDiagnostics();
|
||||
|
||||
@Nullable
|
||||
<K, V> V get(ReadOnlySlice<K, V> slice, K key);
|
||||
|
||||
@@ -27,7 +27,8 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
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
|
||||
/* package */ final static boolean TRACK_REWRITES = false;
|
||||
@@ -39,7 +40,7 @@ public class BindingTraceContext implements BindingTrace {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
public Diagnostics getDiagnostics() {
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
@@ -64,12 +65,13 @@ public class BindingTraceContext implements BindingTrace {
|
||||
|
||||
public BindingTraceContext() {
|
||||
//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.diagnostics = new SimpleDiagnostics(diagnosticList);
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
@@ -79,11 +81,11 @@ public class BindingTraceContext implements BindingTrace {
|
||||
|
||||
@Override
|
||||
public void report(@NotNull Diagnostic diagnostic) {
|
||||
diagnostics.add(diagnostic);
|
||||
diagnosticList.add(diagnostic);
|
||||
}
|
||||
|
||||
public void clearDiagnostics() {
|
||||
diagnostics.clear();
|
||||
diagnosticList.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,10 +40,10 @@ public class DelegatingBindingTrace implements BindingTrace {
|
||||
private final BindingContext bindingContext = new BindingContext() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
public Diagnostics getDiagnostics() {
|
||||
ArrayList<Diagnostic> mergedDiagnostics = new ArrayList<Diagnostic>(diagnostics);
|
||||
mergedDiagnostics.addAll(parentContext.getDiagnostics());
|
||||
return mergedDiagnostics;
|
||||
mergedDiagnostics.addAll(parentContext.getDiagnostics().noSuppression().all());
|
||||
return new SimpleDiagnostics(mergedDiagnostics);
|
||||
}
|
||||
|
||||
@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() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
public Diagnostics getDiagnostics() {
|
||||
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.resolve.BindingContext;
|
||||
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.WritableSlice;
|
||||
|
||||
@@ -48,7 +49,7 @@ public class LockBasedLazyResolveStorageManager extends LockBasedStorageManager
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
public Diagnostics getDiagnostics() {
|
||||
synchronized (lock) {
|
||||
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.psi.JetFile;
|
||||
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.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyResolveTestUtil;
|
||||
@@ -101,7 +102,7 @@ public class JetTestUtils {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
public Diagnostics getDiagnostics() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@@ -160,7 +161,7 @@ public class JetTestUtils {
|
||||
return new BindingContext() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
public Diagnostics getDiagnostics() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user