001 /* 002 * Copyright 2010-2015 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.kotlin.load.java; 018 019 import kotlin.KotlinPackage; 020 import org.jetbrains.annotations.NotNull; 021 import org.jetbrains.kotlin.name.ClassId; 022 import org.jetbrains.kotlin.name.FqName; 023 import org.jetbrains.kotlin.name.Name; 024 import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion; 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 change this version. 030 * - Major version should be increased only when the new binary format is neither forward- nor backward compatible. 031 * This shouldn't really ever happen at all. 032 * - Minor version should be increased when the new format is backward compatible, 033 * i.e. the new compiler can process old class files, but the old compiler will not be able to process new class files. 034 * - Patch version can be increased freely and is only supposed to be used for debugging. Increase the patch version when you 035 * make a change to the metadata format or the bytecode which is both forward- and backward compatible. 036 */ 037 public static final BinaryVersion VERSION = BinaryVersion.create(0, 25, 0); 038 039 public static final String TRAIT_IMPL_CLASS_NAME = "$TImpl"; 040 public static final String TRAIT_IMPL_SUFFIX = "$" + TRAIT_IMPL_CLASS_NAME; 041 042 public static final String DEFAULT_PARAMS_IMPL_SUFFIX = "$default"; 043 public static final String GETTER_PREFIX = "get"; 044 public static final String SETTER_PREFIX = "set"; 045 046 public static final String DELEGATED_PROPERTY_NAME_SUFFIX = "$delegate"; 047 public static final String PROPERTY_METADATA_ARRAY_NAME = "$propertyMetadata"; 048 public static final String ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX = "$annotations"; 049 050 public static final String INSTANCE_FIELD = "INSTANCE$"; 051 052 public static final String KOTLIN_CLASS_FIELD_NAME = "$kotlinClass"; 053 public static final String KOTLIN_PACKAGE_FIELD_NAME = "$kotlinPackage"; 054 public static final String MODULE_NAME_FIELD = "$moduleName"; 055 public static final String DEFAULT_MODULE_NAME = "main"; 056 public static final ClassId REFLECTION_FACTORY_IMPL = ClassId.topLevel(new FqName("kotlin.reflect.jvm.internal.ReflectionFactoryImpl")); 057 058 @NotNull 059 public static String getSyntheticMethodNameForAnnotatedProperty(@NotNull Name propertyName) { 060 return propertyName.asString() + ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX; 061 } 062 063 @NotNull 064 public static String getDefaultFieldNameForProperty(@NotNull Name propertyName, boolean isDelegated) { 065 return isDelegated ? propertyName.asString() + DELEGATED_PROPERTY_NAME_SUFFIX : propertyName.asString(); 066 } 067 068 @NotNull 069 public static String getterName(@NotNull String propertyName) { 070 return GETTER_PREFIX + capitalizeWithJavaBeanConvention(propertyName); 071 } 072 073 @NotNull 074 public static String setterName(@NotNull String propertyName) { 075 return SETTER_PREFIX + capitalizeWithJavaBeanConvention(propertyName); 076 } 077 078 /** 079 * @see com.intellij.openapi.util.text.StringUtil#capitalizeWithJavaBeanConvention(String) 080 */ 081 @NotNull 082 private static String capitalizeWithJavaBeanConvention(@NotNull String s) { 083 return s.length() > 1 && Character.isUpperCase(s.charAt(1)) ? s : KotlinPackage.capitalize(s); 084 } 085 }