Added DiagnosticFactoryToRendererMap.put(Renderers.MultiRenderer)

This commit is contained in:
Stanislav Erokhin
2014-09-09 16:11:28 +04:00
parent 65c9ea2465
commit 12f2c0861f
4 changed files with 70 additions and 1 deletions
@@ -470,7 +470,7 @@ public class DefaultErrorMessages {
MAP.put(TYPE_INFERENCE_UPPER_BOUND_VIOLATED, "{0}", TYPE_INFERENCE_UPPER_BOUND_VIOLATED_RENDERER);
MAP.put(TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, "Type inference failed. Expected type mismatch: found: {1} required: {0}", RENDER_TYPE, RENDER_TYPE);
MAP.put(WRONG_NUMBER_OF_TYPE_ARGUMENTS, "{0,choice,0#No type arguments|1#Type argument|1<{0,number,integer} type arguments} expected", null);
MAP.put(WRONG_NUMBER_OF_TYPE_ARGUMENTS, "{0,choice,0#No type arguments|1#Type argument|1<{0,number,integer} type arguments} expected", (Renderer) null);
MAP.put(NO_TYPE_ARGUMENTS_ON_RHS, "{0,choice,0#No type arguments|1#Type argument|1<{0,number,integer} type arguments} expected. " +
"Use ''{1}'' if you don''t want to pass type arguments", null, STRING);
@@ -20,6 +20,7 @@ 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.MultiRenderer;
import org.jetbrains.jet.renderer.Renderer;
import java.util.HashMap;
@@ -46,6 +47,11 @@ public final class DiagnosticFactoryToRendererMap {
map.put(factory, new DiagnosticWithParameters1Renderer<A>(message, rendererA));
}
public <E extends PsiElement, A> void put(@NotNull DiagnosticFactory1<E, A> factory, @NotNull String message, @NotNull MultiRenderer<? super A> rendererA) {
checkMutability();
map.put(factory, new DiagnosticWithMultiParametersRenderer<A>(message, rendererA));
}
public <E extends PsiElement, A, B> void put(@NotNull DiagnosticFactory2<E, A, B> factory,
@NotNull String message,
@Nullable Renderer<? super A> rendererA,
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2014 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 org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1;
import org.jetbrains.jet.renderer.MultiRenderer;
import java.text.MessageFormat;
public class DiagnosticWithMultiParametersRenderer<A> implements DiagnosticRenderer<DiagnosticWithParameters1<?, A>> {
@NotNull private final MessageFormat messageFormat;
@NotNull private final MultiRenderer<? super A> renderersForA;
public DiagnosticWithMultiParametersRenderer(@NotNull String message, @NotNull MultiRenderer<? super A> renderersForA) {
this.messageFormat = new MessageFormat(message);
this.renderersForA = renderersForA;
}
@NotNull
@Override
public String render(@NotNull DiagnosticWithParameters1<?, A> diagnostic) {
return messageFormat.format(renderersForA.render(diagnostic.getA()));
}
}
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2014 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.renderer;
import org.jetbrains.annotations.NotNull;
public interface MultiRenderer<O> {
@NotNull
String[] render(@NotNull O object);
}