001 /*
002 * Copyright 2010-2013 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.resolver;
018
019 import com.intellij.openapi.diagnostic.Logger;
020 import com.intellij.psi.PsiElement;
021 import org.jetbrains.annotations.NotNull;
022 import org.jetbrains.annotations.Nullable;
023 import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
024 import org.jetbrains.jet.lang.psi.JetDeclaration;
025 import org.jetbrains.jet.lang.resolve.BindingContextUtils;
026 import org.jetbrains.jet.lang.resolve.BindingTrace;
027 import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass;
028 import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass;
029 import org.jetbrains.jet.util.slicedmap.Slices;
030 import org.jetbrains.jet.util.slicedmap.WritableSlice;
031
032 import javax.inject.Inject;
033
034 import static org.jetbrains.jet.lang.diagnostics.Errors.CANNOT_INFER_VISIBILITY;
035
036 public class TraceBasedErrorReporter implements ErrorReporter {
037 private static final Logger LOG = Logger.getInstance(TraceBasedErrorReporter.class);
038
039 public static final WritableSlice<VirtualFileKotlinClass, Integer> ABI_VERSION_ERRORS = Slices.createCollectiveSlice();
040
041 private BindingTrace trace;
042
043 @Inject
044 public void setTrace(BindingTrace trace) {
045 this.trace = trace;
046 }
047
048 @Override
049 public void reportIncompatibleAbiVersion(@NotNull KotlinJvmBinaryClass kotlinClass, int actualVersion) {
050 trace.record(ABI_VERSION_ERRORS, (VirtualFileKotlinClass) kotlinClass, actualVersion);
051 }
052
053 @Override
054 public void reportCannotInferVisibility(@NotNull CallableMemberDescriptor descriptor) {
055 PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), descriptor);
056 if (element instanceof JetDeclaration) {
057 trace.report(CANNOT_INFER_VISIBILITY.on((JetDeclaration) element));
058 }
059 }
060
061 @Override
062 public void reportAnnotationLoadingError(@NotNull String message, @Nullable Exception exception) {
063 LOG.error(message, exception);
064 }
065 }