
org.jetbrains.jet.lang.resolve.BindingTraceContext Maven / Gradle / Ivy
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.*;
import java.util.Collection;
import java.util.List;
public class BindingTraceContext implements BindingTrace {
private final List 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;
/* package */ final static boolean TRACK_WITH_STACK_TRACES = true;
private final MutableSlicedMap map;
private final BindingContext bindingContext = new BindingContext() {
@NotNull
@Override
public Diagnostics getDiagnostics() {
return diagnostics;
}
@Override
public V get(ReadOnlySlice slice, K key) {
return BindingTraceContext.this.get(slice, key);
}
@NotNull
@Override
public Collection getKeys(WritableSlice slice) {
return BindingTraceContext.this.getKeys(slice);
}
@NotNull
@TestOnly
@Override
public ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice) {
return map.getSliceContents(slice);
}
};
public BindingTraceContext() {
//noinspection ConstantConditions
this(TRACK_REWRITES ? new TrackingSlicedMap(TRACK_WITH_STACK_TRACES) : SlicedMapImpl.create());
}
private BindingTraceContext(@NotNull MutableSlicedMap map) {
this.map = map;
this.diagnostics = new DiagnosticsWithSuppression(getBindingContext(), diagnosticList);
}
@TestOnly
public static BindingTraceContext createTraceableBindingTrace() {
return new BindingTraceContext(new TrackingSlicedMap(TRACK_WITH_STACK_TRACES));
}
@Override
public void report(@NotNull Diagnostic diagnostic) {
diagnosticList.add(diagnostic);
}
public void clearDiagnostics() {
diagnosticList.clear();
}
@NotNull
@Override
public BindingContext getBindingContext() {
return bindingContext;
}
@Override
public void record(WritableSlice slice, K key, V value) {
map.put(slice, key, value);
}
@Override
public void record(WritableSlice slice, K key) {
record(slice, key, true);
}
@Override
public V get(ReadOnlySlice slice, K key) {
return map.get(slice, key);
}
@NotNull
@Override
public Collection getKeys(WritableSlice slice) {
return map.getKeys(slice);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy