001 /*
002 * Copyright 2010-2014 JetBrains s.r.o.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.jetbrains.jet.lang.resolve.java.diagnostics;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
021 import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
022 import org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticFactoryToRendererMap;
023 import org.jetbrains.jet.renderer.DescriptorRenderer;
024 import org.jetbrains.jet.renderer.Renderer;
025
026 import static org.jetbrains.jet.lang.diagnostics.PositioningStrategies.DECLARATION_SIGNATURE;
027
028 public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
029
030 private static final Renderer<ConflictingJvmDeclarationsData> CONFLICTING_JVM_DECLARATIONS_DATA = new Renderer<ConflictingJvmDeclarationsData>() {
031 @NotNull
032 @Override
033 public String render(@NotNull ConflictingJvmDeclarationsData data) {
034 StringBuilder sb = new StringBuilder();
035 for (JvmDeclarationOrigin origin : data.getSignatureOrigins()) {
036 DeclarationDescriptor descriptor = origin.getDescriptor();
037 if (descriptor != null) {
038 sb.append(" ").append(DescriptorRenderer.COMPACT.render(descriptor)).append("\n");
039 }
040 }
041 return ("The following declarations have the same JVM signature (" + data.getSignature().getName() + data.getSignature().getDesc() + "):\n" + sb).trim();
042 }
043 };
044
045 public static final DiagnosticFactoryToRendererMap MAP = new DiagnosticFactoryToRendererMap();
046 static {
047 MAP.put(ErrorsJvm.CONFLICTING_JVM_DECLARATIONS, "Platform declaration clash: {0}", CONFLICTING_JVM_DECLARATIONS_DATA);
048 MAP.put(ErrorsJvm.ACCIDENTAL_OVERRIDE, "Accidental override: {0}", CONFLICTING_JVM_DECLARATIONS_DATA);
049 MAP.put(ErrorsJvm.PLATFORM_STATIC_NOT_IN_OBJECT, "Only functions in named objects and class objects of classes can be annotated with ''platformStatic''", DescriptorRenderer.SHORT_NAMES_IN_TYPES);
050 MAP.put(ErrorsJvm.OVERRIDE_CANNOT_BE_STATIC, "Override cannot be ''platformStatic'' in object", DescriptorRenderer.SHORT_NAMES_IN_TYPES);
051 MAP.put(ErrorsJvm.PLATFORM_STATIC_ILLEGAL_USAGE, "This declaration does not support ''platformStatic''", DescriptorRenderer.SHORT_NAMES_IN_TYPES);
052 }
053
054
055 @NotNull
056 @Override
057 public DiagnosticFactoryToRendererMap getMap() {
058 return MAP;
059 }
060 }