Added getSliceContents() method to BindingContext returning immutable map for particular slice (for testing and debug purposes).

This commit is contained in:
Evgeny Gerashchenko
2012-09-15 21:39:48 +04:00
parent 84c10c1623
commit 27becdec9b
4 changed files with 50 additions and 1 deletions
@@ -16,9 +16,11 @@
package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.ImmutableMap;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
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;
@@ -59,6 +61,13 @@ public interface BindingContext {
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
return Collections.emptyList();
}
@NotNull
@TestOnly
@Override
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
return ImmutableMap.of();
}
};
WritableSlice<AnnotationDescriptor, JetAnnotationEntry> ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT = Slices.createSimpleSlice();
@@ -253,4 +262,9 @@ public interface BindingContext {
// slice.isCollective() must be true
@NotNull
<K, V> Collection<K> getKeys(WritableSlice<K, V> slice);
/** This method should be used only for debug and testing */
@TestOnly
@NotNull
<K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice);
}
@@ -16,8 +16,10 @@
package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.util.slicedmap.MutableSlicedMap;
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
@@ -52,6 +54,13 @@ public class BindingTraceContext implements BindingTrace {
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
return BindingTraceContext.this.getKeys(slice);
}
@NotNull
@TestOnly
@Override
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
return map.getSliceContents(slice);
}
};
@Override
@@ -16,10 +16,11 @@
package org.jetbrains.jet.lang.resolve;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.util.slicedmap.*;
@@ -55,6 +56,15 @@ public class DelegatingBindingTrace implements BindingTrace {
return DelegatingBindingTrace.this.getKeys(slice);
}
@NotNull
@TestOnly
@Override
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
ImmutableMap<K, V> parentContents = parentContext.getSliceContents(slice);
ImmutableMap<K, V> currentContents = map.getSliceContents(slice);
return ImmutableMap.<K, V>builder().putAll(parentContents).putAll(currentContents).build();
}
};
public DelegatingBindingTrace(BindingContext parentContext) {
@@ -16,6 +16,7 @@
package org.jetbrains.jet;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.openapi.Disposable;
@@ -30,6 +31,7 @@ import com.intellij.testFramework.LightVirtualFile;
import junit.framework.TestCase;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode;
@@ -87,6 +89,13 @@ public class JetTestUtils {
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
return DUMMY_TRACE.getKeys(slice);
}
@NotNull
@TestOnly
@Override
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
return ImmutableMap.of();
}
};
}
@@ -138,6 +147,13 @@ public class JetTestUtils {
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
return DUMMY_EXCEPTION_ON_ERROR_TRACE.getKeys(slice);
}
@NotNull
@TestOnly
@Override
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
return ImmutableMap.of();
}
};
}