org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticFactoryToRendererMap 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.diagnostics.rendering;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.*;
import org.jetbrains.jet.renderer.Renderer;
import java.util.HashMap;
import java.util.Map;
public final class DiagnosticFactoryToRendererMap {
private final Map, DiagnosticRenderer> map =
new HashMap, DiagnosticRenderer>();
private boolean immutable = false;
private void checkMutability() {
if (immutable) {
throw new IllegalStateException("factory to renderer map is already immutable");
}
}
public void put(@NotNull DiagnosticFactory0 factory, @NotNull String message) {
checkMutability();
map.put(factory, new SimpleDiagnosticRenderer(message));
}
public void put(@NotNull DiagnosticFactory1 factory, @NotNull String message, @Nullable Renderer rendererA) {
checkMutability();
map.put(factory, new DiagnosticWithParameters1Renderer(message, rendererA));
}
public void put(@NotNull DiagnosticFactory2 factory,
@NotNull String message,
@Nullable Renderer rendererA,
@Nullable Renderer rendererB) {
checkMutability();
map.put(factory, new DiagnosticWithParameters2Renderer(message, rendererA, rendererB));
}
public void put(@NotNull DiagnosticFactory3 factory,
@NotNull String message,
@Nullable Renderer rendererA,
@Nullable Renderer rendererB,
@Nullable Renderer rendererC) {
checkMutability();
map.put(factory, new DiagnosticWithParameters3Renderer(message, rendererA, rendererB, rendererC));
}
@Nullable
public DiagnosticRenderer get(@NotNull DiagnosticFactory factory) {
return map.get(factory);
}
public void setImmutable() {
immutable = false;
}
}