From c06d70d19002f6a35ba9cbbb518dcda6ea29e2f0 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 25 Nov 2014 16:33:48 +0300 Subject: [PATCH] JS frontend: added checkers for nativeInvoke, nativeGetter, nativeSetter. --- build.xml | 1 + ...s.rendering.DefaultErrorMessages$Extension | 1 - .../rendering/DefaultErrorMessages.java | 7 +- generators/generators.iml | 4 +- .../generators/injectors/GenerateInjectors.kt | 3 +- .../plugin/caches/resolve/JsAnalyzerFacade.kt | 6 +- .../jet/plugin/project/TargetPlatform.java | 3 +- idea/src/META-INF/extensions/common.xml | 2 + idea/src/META-INF/extensions/kotlin2js.xml | 1 + idea/src/META-INF/extensions/kotlin2jvm.xml | 7 ++ idea/src/META-INF/plugin.xml | 1 + .../di/InjectorForTopDownAnalyzerForJs.java | 2 +- .../jetbrains/k2js/PredefinedAnnotation.kt | 5 +- .../k2js/analyze/suppressWarnings.kt | 3 +- .../KotlinJsDeclarationCheckerProvider.kt | 101 ++++++++++++++++++ .../diagnostics/DefaultErrorMessagesJs.kt | 39 +++++++ .../k2js/resolve/diagnostics/ErrorsJs.java | 44 ++++++++ .../translate/utils/AnnotationsUtils.java | 22 ++-- 18 files changed, 228 insertions(+), 24 deletions(-) delete mode 100644 compiler/frontend.java/src/META-INF/services/org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages$Extension create mode 100644 idea/src/META-INF/extensions/kotlin2jvm.xml create mode 100644 js/js.frontend/src/org/jetbrains/k2js/resolve/KotlinJsDeclarationCheckerProvider.kt create mode 100644 js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/DefaultErrorMessagesJs.kt create mode 100644 js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/ErrorsJs.java diff --git a/build.xml b/build.xml index 0616ffab950..aa81361d364 100644 --- a/build.xml +++ b/build.xml @@ -367,6 +367,7 @@ + diff --git a/compiler/frontend.java/src/META-INF/services/org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages$Extension b/compiler/frontend.java/src/META-INF/services/org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages$Extension deleted file mode 100644 index 8f141822f61..00000000000 --- a/compiler/frontend.java/src/META-INF/services/org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages$Extension +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.jet.lang.resolve.java.diagnostics.DefaultErrorMessagesJvm \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java index 8fdb45c5216..81528f2a707 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java @@ -17,6 +17,8 @@ package org.jetbrains.jet.lang.diagnostics.rendering; import com.google.common.collect.ImmutableList; +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.extensions.Extensions; import kotlin.Function1; import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; @@ -35,7 +37,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Collection; import java.util.List; -import java.util.ServiceLoader; import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.*; @@ -44,6 +45,8 @@ import static org.jetbrains.jet.renderer.DescriptorRenderer.*; public class DefaultErrorMessages { public interface Extension { + ExtensionPointName EP_NAME = ExtensionPointName.create("org.jetbrains.kotlin.defaultErrorMessages"); + @NotNull DiagnosticFactoryToRendererMap getMap(); } @@ -52,7 +55,7 @@ public class DefaultErrorMessages { public static final List MAPS = ImmutableList.builder() .addAll( KotlinPackage.map( - ServiceLoader.load(Extension.class, DefaultErrorMessages.class.getClassLoader()), + Extensions.getExtensions(Extension.EP_NAME), new Function1() { @Override public DiagnosticFactoryToRendererMap invoke(Extension extension) { diff --git a/generators/generators.iml b/generators/generators.iml index 602b55f43c5..9a600650886 100644 --- a/generators/generators.iml +++ b/generators/generators.iml @@ -24,6 +24,6 @@ + - - + \ No newline at end of file diff --git a/generators/src/org/jetbrains/jet/generators/injectors/GenerateInjectors.kt b/generators/src/org/jetbrains/jet/generators/injectors/GenerateInjectors.kt index 9997129a3ae..6e6d7e89eac 100644 --- a/generators/src/org/jetbrains/jet/generators/injectors/GenerateInjectors.kt +++ b/generators/src/org/jetbrains/jet/generators/injectors/GenerateInjectors.kt @@ -48,6 +48,7 @@ import org.jetbrains.jet.context.LazyResolveToken import org.jetbrains.jet.lang.resolve.java.JavaLazyAnalyzerPostConstruct import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolverPostConstruct import org.jetbrains.jet.lang.resolve.lazy.ScopeProvider +import org.jetbrains.k2js.resolve.KotlinJsDeclarationCheckerProvider // NOTE: After making changes, you need to re-generate the injectors. // To do that, you can run main in this file. @@ -132,7 +133,7 @@ private fun generatorForTopDownAnalyzerForJs() = field(javaClass()) field(javaClass(), - init = GivenExpression(javaClass().getCanonicalName() + ".INSTANCE$")) + init = GivenExpression(javaClass().getName() + ".INSTANCE$")) } private fun generatorForTopDownAnalyzerForJvm() = diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/caches/resolve/JsAnalyzerFacade.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/caches/resolve/JsAnalyzerFacade.kt index 3cd5b838782..d2d04a7a66b 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/caches/resolve/JsAnalyzerFacade.kt +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/caches/resolve/JsAnalyzerFacade.kt @@ -18,8 +18,6 @@ package org.jetbrains.jet.plugin.caches.resolve import org.jetbrains.jet.lang.resolve.lazy.ResolveSession import org.jetbrains.jet.analyzer.ResolverForModule -import org.jetbrains.jet.lang.psi.JetFile -import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.jet.analyzer.PlatformAnalysisParameters import org.jetbrains.jet.analyzer.AnalyzerFacade import com.intellij.openapi.project.Project @@ -33,7 +31,7 @@ import org.jetbrains.jet.di.InjectorForLazyResolve import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.jet.analyzer.ModuleInfo import org.jetbrains.jet.analyzer.ModuleContent -import org.jetbrains.jet.lang.resolve.AdditionalCheckerProvider +import org.jetbrains.k2js.resolve.KotlinJsDeclarationCheckerProvider public class JsResolverForModule( override val lazyResolveSession: ResolveSession @@ -55,7 +53,7 @@ public object JsAnalyzerFacade : AnalyzerFacadeorg.jetbrains.kotlin + org.jetbrains.kotlin + diff --git a/idea/src/META-INF/extensions/kotlin2jvm.xml b/idea/src/META-INF/extensions/kotlin2jvm.xml new file mode 100644 index 00000000000..ecb644dc6b9 --- /dev/null +++ b/idea/src/META-INF/extensions/kotlin2jvm.xml @@ -0,0 +1,7 @@ + + org.jetbrains.kotlin + + + + + diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 9490a715725..2a56d2afb7f 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -827,6 +827,7 @@ + diff --git a/js/js.frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJs.java b/js/js.frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJs.java index ddc609b647b..017c13588a4 100644 --- a/js/js.frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJs.java +++ b/js/js.frontend/src/org/jetbrains/jet/di/InjectorForTopDownAnalyzerForJs.java @@ -137,7 +137,7 @@ public class InjectorForTopDownAnalyzerForJs { this.resolveSession = new ResolveSession(project, globalContext, module, declarationProviderFactory, bindingTrace); this.lazyTopDownAnalyzer = new LazyTopDownAnalyzer(); this.mutablePackageFragmentProvider = new MutablePackageFragmentProvider(module); - this.additionalCheckerProvider = org.jetbrains.jet.lang.resolve.AdditionalCheckerProvider.Empty.INSTANCE$; + this.additionalCheckerProvider = org.jetbrains.k2js.resolve.KotlinJsDeclarationCheckerProvider.INSTANCE$; this.annotationResolver = new AnnotationResolver(); this.callResolver = new CallResolver(); this.argumentTypeResolver = new ArgumentTypeResolver(); diff --git a/js/js.frontend/src/org/jetbrains/k2js/PredefinedAnnotation.kt b/js/js.frontend/src/org/jetbrains/k2js/PredefinedAnnotation.kt index d73a40484cd..68b75610835 100644 --- a/js/js.frontend/src/org/jetbrains/k2js/PredefinedAnnotation.kt +++ b/js/js.frontend/src/org/jetbrains/k2js/PredefinedAnnotation.kt @@ -17,14 +17,17 @@ package org.jetbrains.k2js import kotlin.properties.Delegates +import org.jetbrains.jet.lang.resolve.name.FqName -public enum class PredefinedAnnotation(public val fqName: String) { +public enum class PredefinedAnnotation(fqName: String) { LIBRARY : PredefinedAnnotation("kotlin.js.library") NATIVE : PredefinedAnnotation("kotlin.js.native") NATIVE_INVOKE : PredefinedAnnotation("kotlin.js.nativeInvoke") NATIVE_GETTER : PredefinedAnnotation("kotlin.js.nativeGetter") NATIVE_SETTER : PredefinedAnnotation("kotlin.js.nativeSetter") + public val fqName: FqName = FqName(fqName) + class object { // TODO: replace with straight assignment when KT-5761 will be fixed val WITH_CUSTOM_NAME by Delegates.lazy { setOf(LIBRARY, NATIVE) } diff --git a/js/js.frontend/src/org/jetbrains/k2js/analyze/suppressWarnings.kt b/js/js.frontend/src/org/jetbrains/k2js/analyze/suppressWarnings.kt index 0bcb34e467f..1911c95f903 100644 --- a/js/js.frontend/src/org/jetbrains/k2js/analyze/suppressWarnings.kt +++ b/js/js.frontend/src/org/jetbrains/k2js/analyze/suppressWarnings.kt @@ -19,7 +19,6 @@ package org.jetbrains.k2js.analyze import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor import org.jetbrains.jet.lang.resolve.DescriptorUtils import org.jetbrains.jet.lang.diagnostics.Errors -import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe import org.jetbrains.jet.lang.resolve.DiagnosticsWithSuppression import org.jetbrains.k2js.PredefinedAnnotation import org.jetbrains.jet.lang.diagnostics.Diagnostic @@ -30,7 +29,7 @@ import org.jetbrains.k2js.config.LibrarySourcesConfig class SuppressUnusedParameterForJsNative : DiagnosticsWithSuppression.SuppressStringProvider { override fun get(annotationDescriptor: AnnotationDescriptor): List { val descriptor = DescriptorUtils.getClassDescriptorForType(annotationDescriptor.getType()) - if (PredefinedAnnotation.NATIVE.fqName == DescriptorUtils.getFqName(descriptor).asString()) { + if (PredefinedAnnotation.NATIVE.fqName == DescriptorUtils.getFqNameSafe(descriptor)) { return listOf(Errors.UNUSED_PARAMETER.getName().toLowerCase()) } diff --git a/js/js.frontend/src/org/jetbrains/k2js/resolve/KotlinJsDeclarationCheckerProvider.kt b/js/js.frontend/src/org/jetbrains/k2js/resolve/KotlinJsDeclarationCheckerProvider.kt new file mode 100644 index 00000000000..ddbe1f4c45c --- /dev/null +++ b/js/js.frontend/src/org/jetbrains/k2js/resolve/KotlinJsDeclarationCheckerProvider.kt @@ -0,0 +1,101 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.k2js.resolve + +import org.jetbrains.jet.lang.resolve.AdditionalCheckerProvider +import org.jetbrains.jet.lang.resolve.AnnotationChecker +import org.jetbrains.jet.lang.psi.JetDeclaration +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor +import org.jetbrains.jet.lang.diagnostics.DiagnosticSink +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor +import org.jetbrains.jet.lang.psi.JetNamedFunction +import org.jetbrains.k2js.resolve.diagnostics.ErrorsJs +import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns +import org.jetbrains.jet.lang.types.TypeUtils +import org.jetbrains.k2js.PredefinedAnnotation +import org.jetbrains.jet.lang.resolve.DescriptorUtils +import org.jetbrains.k2js.translate.utils.AnnotationsUtils +import org.jetbrains.jet.lang.descriptors.Visibilities + +public object KotlinJsDeclarationCheckerProvider : AdditionalCheckerProvider { + override val annotationCheckers: List = listOf(NativeInvokeChecker(), NativeGetterChecker(), NativeSetterChecker()) +} + +private abstract class AbstractNativeAnnotationsChecker(private val requiredAnnotation: PredefinedAnnotation) : AnnotationChecker { + + open fun additionalCheck(declaration: JetNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) {} + + override fun check(declaration: JetDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink) { + val annotationDescriptor = descriptor.getAnnotations().findAnnotation(requiredAnnotation.fqName) + if (annotationDescriptor == null) return + + if (declaration !is JetNamedFunction || descriptor !is FunctionDescriptor) { + diagnosticHolder.report(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN.on(declaration, annotationDescriptor.getType())) + return + } + + val isTopLevel = DescriptorUtils.isTopLevelDeclaration(descriptor) + val hasLocalVisibility = descriptor.getVisibility() == Visibilities.LOCAL + val isExtension = DescriptorUtils.isExtension(descriptor) + + if (!isTopLevel && !hasLocalVisibility && isExtension || + (isTopLevel || hasLocalVisibility) && !isExtension || + !((isTopLevel || hasLocalVisibility) && isExtension) && !AnnotationsUtils.isNativeObject(descriptor) + ) { + diagnosticHolder.report(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN.on(declaration, annotationDescriptor.getType())) + } + + additionalCheck(declaration, descriptor, diagnosticHolder) + } +} + +public class NativeInvokeChecker : AbstractNativeAnnotationsChecker(PredefinedAnnotation.NATIVE_INVOKE) + +private abstract class AbstractNativeIndexerChecker( + requiredAnnotation: PredefinedAnnotation, + private val indexerKind: String, + private val requiredParametersCount: Int +) : AbstractNativeAnnotationsChecker(requiredAnnotation) { + + override fun additionalCheck(declaration: JetNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) { + val parameters = descriptor.getValueParameters() + if (parameters.size() > 0) { + val firstParamClassDescriptor = DescriptorUtils.getClassDescriptorForType(parameters.get(0).getType()) + if (firstParamClassDescriptor != KotlinBuiltIns.getInstance().getString() && + !DescriptorUtils.isSubclass(firstParamClassDescriptor, KotlinBuiltIns.getInstance().getNumber()) + ) { + diagnosticHolder.report(ErrorsJs.NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER.on(declaration.getValueParameters().first, indexerKind)) + } + } + + if (parameters.size() != requiredParametersCount) { + diagnosticHolder.report(ErrorsJs.NATIVE_INDEXER_WRONG_PARAMETER_COUNT.on(declaration, requiredParametersCount, indexerKind)) + } + } +} + +public class NativeGetterChecker : AbstractNativeIndexerChecker(PredefinedAnnotation.NATIVE_GETTER, "getter", requiredParametersCount = 1) { + override fun additionalCheck(declaration: JetNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) { + super.additionalCheck(declaration, descriptor, diagnosticHolder) + + if (!TypeUtils.isNullableType(descriptor.getReturnType())) { + diagnosticHolder.report(ErrorsJs.NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE.on(declaration)) + } + } +} + +public class NativeSetterChecker : AbstractNativeIndexerChecker(PredefinedAnnotation.NATIVE_SETTER, "setter", requiredParametersCount = 2) diff --git a/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/DefaultErrorMessagesJs.kt b/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/DefaultErrorMessagesJs.kt new file mode 100644 index 00000000000..1d45ff3e86e --- /dev/null +++ b/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/DefaultErrorMessagesJs.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.k2js.resolve.diagnostics + +import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages +import org.jetbrains.jet.lang.diagnostics.rendering.DiagnosticFactoryToRendererMap +import org.jetbrains.jet.lang.diagnostics.rendering.Renderers +import kotlin.properties.Delegates + +private val DIAGNOSTIC_FACTORY_TO_RENDERER by Delegates.lazy { + with(DiagnosticFactoryToRendererMap()) { + + put(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN, + "Annotation ''{0}'' is allowed only on member functions of declaration annotated as ''kotlin.js.native'' or on toplevel extension functions", Renderers.RENDER_TYPE) + put(ErrorsJs.NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER, "Native {0}''s first parameter type should be ''kotlin.String'' or subtype of ''kotlin.Number''", Renderers.STRING) + put(ErrorsJs.NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE, "Native getter''s return type should be nullable") + put(ErrorsJs.NATIVE_INDEXER_WRONG_PARAMETER_COUNT, "Expected {0} parameters for native {1}", Renderers.TO_STRING, Renderers.STRING) + + this + } +} + +public class DefaultErrorMessagesJs : DefaultErrorMessages.Extension { + override fun getMap(): DiagnosticFactoryToRendererMap = DIAGNOSTIC_FACTORY_TO_RENDERER +} diff --git a/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/ErrorsJs.java b/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/ErrorsJs.java new file mode 100644 index 00000000000..c5986d07dbf --- /dev/null +++ b/js/js.frontend/src/org/jetbrains/k2js/resolve/diagnostics/ErrorsJs.java @@ -0,0 +1,44 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.k2js.resolve.diagnostics; + +import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory0; +import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory1; +import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory2; +import org.jetbrains.jet.lang.diagnostics.Errors; +import org.jetbrains.jet.lang.psi.JetDeclaration; +import org.jetbrains.jet.lang.psi.JetElement; +import org.jetbrains.jet.lang.types.JetType; + +import static org.jetbrains.jet.lang.diagnostics.PositioningStrategies.DECLARATION_RETURN_TYPE; +import static org.jetbrains.jet.lang.diagnostics.PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT; +import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR; + +public interface ErrorsJs { + + DiagnosticFactory1 NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); + DiagnosticFactory1 NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); + DiagnosticFactory0 NATIVE_GETTER_RETURN_TYPE_SHOULD_BE_NULLABLE = DiagnosticFactory0.create(ERROR, DECLARATION_RETURN_TYPE); + DiagnosticFactory2 NATIVE_INDEXER_WRONG_PARAMETER_COUNT = DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); + + @SuppressWarnings("UnusedDeclaration") + Object _initializer = new Object() { + { + Errors.Initializer.initializeFactoryNames(ErrorsJs.class); + } + }; +} diff --git a/js/js.frontend/src/org/jetbrains/k2js/translate/utils/AnnotationsUtils.java b/js/js.frontend/src/org/jetbrains/k2js/translate/utils/AnnotationsUtils.java index ec82d640b16..799178997d9 100644 --- a/js/js.frontend/src/org/jetbrains/k2js/translate/utils/AnnotationsUtils.java +++ b/js/js.frontend/src/org/jetbrains/k2js/translate/utils/AnnotationsUtils.java @@ -106,14 +106,16 @@ public final class AnnotationsUtils { } @Nullable - private static AnnotationDescriptor getAnnotationByName(@NotNull DeclarationDescriptor descriptor, - @NotNull PredefinedAnnotation annotation) { + private static AnnotationDescriptor getAnnotationByName( + @NotNull DeclarationDescriptor descriptor, + @NotNull PredefinedAnnotation annotation + ) { return getAnnotationByName(descriptor, annotation.getFqName()); } @Nullable - private static AnnotationDescriptor getAnnotationByName(@NotNull DeclarationDescriptor descriptor, @NotNull String fqn) { - return descriptor.getAnnotations().findAnnotation(new FqName(fqn)); + private static AnnotationDescriptor getAnnotationByName(@NotNull DeclarationDescriptor descriptor, @NotNull FqName fqName) { + return descriptor.getAnnotations().findAnnotation(fqName); } public static boolean isNativeObject(@NotNull DeclarationDescriptor descriptor) { @@ -133,16 +135,18 @@ public final class AnnotationsUtils { return false; } - public static boolean hasAnnotationOrInsideAnnotatedClass(@NotNull DeclarationDescriptor descriptor, - @NotNull PredefinedAnnotation annotation) { + public static boolean hasAnnotationOrInsideAnnotatedClass( + @NotNull DeclarationDescriptor descriptor, + @NotNull PredefinedAnnotation annotation + ) { return hasAnnotationOrInsideAnnotatedClass(descriptor, annotation.getFqName()); } - private static boolean hasAnnotationOrInsideAnnotatedClass(@NotNull DeclarationDescriptor descriptor, @NotNull String fqn) { - if (getAnnotationByName(descriptor, fqn) != null) { + private static boolean hasAnnotationOrInsideAnnotatedClass(@NotNull DeclarationDescriptor descriptor, @NotNull FqName fqName) { + if (getAnnotationByName(descriptor, fqName) != null) { return true; } ClassDescriptor containingClass = DescriptorUtils.getContainingClass(descriptor); - return containingClass != null && hasAnnotationOrInsideAnnotatedClass(containingClass, fqn); + return containingClass != null && hasAnnotationOrInsideAnnotatedClass(containingClass, fqName); } }