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;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
021 import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
022
023 import java.lang.annotation.Annotation;
024 import java.util.*;
025
026 public abstract class JavaToKotlinClassMapBuilder {
027
028 public enum Direction {
029 JAVA_TO_KOTLIN,
030 KOTLIN_TO_JAVA,
031 BOTH
032 }
033
034 protected void init() {
035 KotlinBuiltIns kotlinBuiltIns = KotlinBuiltIns.getInstance();
036
037 register(Object.class, KotlinBuiltIns.getInstance().getAny());
038 register(String.class, kotlinBuiltIns.getString());
039 register(CharSequence.class, kotlinBuiltIns.getCharSequence());
040 register(Throwable.class, kotlinBuiltIns.getThrowable());
041 register(Number.class, kotlinBuiltIns.getNumber());
042 register(Comparable.class, kotlinBuiltIns.getComparable());
043 register(Enum.class, kotlinBuiltIns.getEnum());
044 register(Annotation.class, kotlinBuiltIns.getAnnotation());
045 register(Deprecated.class, kotlinBuiltIns.getDeprecatedAnnotation(), Direction.JAVA_TO_KOTLIN);
046
047 register(Iterable.class, kotlinBuiltIns.getIterable(), kotlinBuiltIns.getMutableIterable());
048 register(Iterator.class, kotlinBuiltIns.getIterator(), kotlinBuiltIns.getMutableIterator());
049 register(Collection.class, kotlinBuiltIns.getCollection(), kotlinBuiltIns.getMutableCollection());
050 register(List.class, kotlinBuiltIns.getList(), kotlinBuiltIns.getMutableList());
051 register(Set.class, kotlinBuiltIns.getSet(), kotlinBuiltIns.getMutableSet());
052 register(Map.class, kotlinBuiltIns.getMap(), kotlinBuiltIns.getMutableMap());
053 register(Map.Entry.class, kotlinBuiltIns.getMapEntry(), kotlinBuiltIns.getMutableMapEntry());
054 register(ListIterator.class, kotlinBuiltIns.getListIterator(), kotlinBuiltIns.getMutableListIterator());
055 }
056
057 /*package*/ void register(@NotNull Class<?> javaClass, @NotNull ClassDescriptor kotlinDescriptor) {
058 register(javaClass, kotlinDescriptor, Direction.BOTH);
059 }
060 protected abstract void register(@NotNull Class<?> javaClass, @NotNull ClassDescriptor kotlinDescriptor, @NotNull Direction direction);
061
062 /*package*/ void register(@NotNull Class<?> javaClass, @NotNull ClassDescriptor kotlinDescriptor, @NotNull ClassDescriptor kotlinMutableDescriptor) {
063 register(javaClass, kotlinDescriptor, kotlinMutableDescriptor, Direction.BOTH);
064 }
065 protected abstract void register(@NotNull Class<?> javaClass, @NotNull ClassDescriptor kotlinDescriptor, @NotNull ClassDescriptor kotlinMutableDescriptor, @NotNull Direction direction);
066 }