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.annotations.Nullable;
021 import org.jetbrains.asm4.Type;
022 import org.jetbrains.asm4.commons.Method;
023 import org.jetbrains.jet.lang.resolve.name.FqName;
024 import org.jetbrains.jet.lang.resolve.name.Name;
025
026 public final class JvmAbi {
027 /**
028 * This constant is used to identify binary format (class file) versions
029 * If you change class file metadata format and/or naming conventions, please increase this number
030 */
031 public static final int VERSION = 11;
032
033 public static final String TRAIT_IMPL_CLASS_NAME = "$TImpl";
034 public static final String TRAIT_IMPL_SUFFIX = "$" + TRAIT_IMPL_CLASS_NAME;
035
036 public static final String DEFAULT_PARAMS_IMPL_SUFFIX = "$default";
037 public static final String GETTER_PREFIX = "get";
038 public static final String SETTER_PREFIX = "set";
039
040 public static final String CLASS_OBJECT_CLASS_NAME = "object";
041 public static final String CLASS_OBJECT_SUFFIX = "$" + CLASS_OBJECT_CLASS_NAME;
042
043 public static final String DELEGATED_PROPERTY_NAME_SUFFIX = "$delegate";
044 public static final String ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX = "$annotations";
045
046 public static final String INSTANCE_FIELD = "instance$";
047 public static final String CLASS_OBJECT_FIELD = "object$";
048
049 public static final JvmClassName JET_OBJECT = JvmClassName.byFqNameWithoutInnerClasses("jet.JetObject");
050
051 public static boolean isClassObjectFqName(@NotNull FqName fqName) {
052 return fqName.lastSegmentIs(Name.identifier(CLASS_OBJECT_CLASS_NAME));
053 }
054
055 @NotNull
056 public static String getPropertyDelegateName(@NotNull Name name) {
057 return name.asString() + DELEGATED_PROPERTY_NAME_SUFFIX;
058 }
059
060 @NotNull
061 public static Method getSyntheticMethodSignatureForAnnotatedProperty(@NotNull Name propertyName, @Nullable Type receiver) {
062 return new Method(
063 propertyName.asString() + ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX,
064 Type.VOID_TYPE,
065 receiver == null ? new Type[0] : new Type[] {receiver}
066 );
067 }
068
069 @NotNull
070 public static String getDefaultPropertyName(@NotNull Name propertyName, boolean isDelegated, boolean isExtensionProperty) {
071 if (isDelegated) {
072 return getPropertyDelegateName(propertyName);
073 }
074
075 String name = propertyName.asString();
076 if (isExtensionProperty) {
077 name += "$ext";
078 }
079 return name;
080
081 }
082
083 private JvmAbi() {
084 }
085 }