Strictfp on a class is now a warning #KT-11109 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
173a838f8c
commit
f76efb68f2
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 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.kotlin.resolve.jvm.checkers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
|
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||||
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
|
import org.jetbrains.kotlin.resolve.annotations.findStrictfpAnnotation
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||||
|
|
||||||
|
class StrictfpApplicabilityChecker : DeclarationChecker {
|
||||||
|
override fun check(
|
||||||
|
declaration: KtDeclaration,
|
||||||
|
descriptor: DeclarationDescriptor,
|
||||||
|
diagnosticHolder: DiagnosticSink,
|
||||||
|
bindingContext: BindingContext
|
||||||
|
) {
|
||||||
|
val annotation = descriptor.findStrictfpAnnotation() ?: return
|
||||||
|
if (declaration is KtClassOrObject && descriptor is ClassDescriptor) {
|
||||||
|
val annotationEntry = DescriptorToSourceUtils.getSourceFromAnnotation(annotation) ?: return
|
||||||
|
diagnosticHolder.report(ErrorsJvm.STRICTFP_ON_CLASS.on(annotationEntry))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -100,6 +100,8 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
|||||||
|
|
||||||
MAP.put(ErrorsJvm.JVM_SYNTHETIC_ON_DELEGATE, "''@JvmSynthetic'' annotation cannot be used on delegated properties");
|
MAP.put(ErrorsJvm.JVM_SYNTHETIC_ON_DELEGATE, "''@JvmSynthetic'' annotation cannot be used on delegated properties");
|
||||||
|
|
||||||
|
MAP.put(ErrorsJvm.STRICTFP_ON_CLASS, "''@Strictfp'' annotation on classes is unsupported yet");
|
||||||
|
|
||||||
MAP.put(ErrorsJvm.SUPER_CALL_WITH_DEFAULT_PARAMETERS, "Super-calls with default arguments are not allowed. Please specify all arguments of ''super.{0}'' explicitly", Renderers.TO_STRING);
|
MAP.put(ErrorsJvm.SUPER_CALL_WITH_DEFAULT_PARAMETERS, "Super-calls with default arguments are not allowed. Please specify all arguments of ''super.{0}'' explicitly", Renderers.TO_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ public interface ErrorsJvm {
|
|||||||
|
|
||||||
DiagnosticFactory0<KtAnnotationEntry> JVM_SYNTHETIC_ON_DELEGATE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> JVM_SYNTHETIC_ON_DELEGATE = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
|
DiagnosticFactory0<KtAnnotationEntry> STRICTFP_ON_CLASS = DiagnosticFactory0.create(WARNING);
|
||||||
|
|
||||||
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_VALUE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_VALUE = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_DELEGATE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_DELEGATE = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<KtAnnotationEntry> SYNCHRONIZED_ON_ABSTRACT = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> SYNCHRONIZED_ON_ABSTRACT = DiagnosticFactory0.create(ERROR);
|
||||||
|
|||||||
+2
-1
@@ -41,7 +41,8 @@ object JvmPlatformConfigurator : PlatformConfigurator(
|
|||||||
OverloadsAnnotationChecker(),
|
OverloadsAnnotationChecker(),
|
||||||
JvmFieldApplicabilityChecker(),
|
JvmFieldApplicabilityChecker(),
|
||||||
TypeParameterBoundIsNotArrayChecker(),
|
TypeParameterBoundIsNotArrayChecker(),
|
||||||
JvmSyntheticApplicabilityChecker()
|
JvmSyntheticApplicabilityChecker(),
|
||||||
|
StrictfpApplicabilityChecker()
|
||||||
),
|
),
|
||||||
|
|
||||||
additionalCallCheckers = listOf(
|
additionalCallCheckers = listOf(
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ fun DeclarationDescriptor.hasJvmSyntheticAnnotation() = findJvmSyntheticAnnotati
|
|||||||
fun DeclarationDescriptor.findJvmSyntheticAnnotation() =
|
fun DeclarationDescriptor.findJvmSyntheticAnnotation() =
|
||||||
DescriptorUtils.getAnnotationByFqName(annotations, JVM_SYNTHETIC_ANNOTATION_FQ_NAME)
|
DescriptorUtils.getAnnotationByFqName(annotations, JVM_SYNTHETIC_ANNOTATION_FQ_NAME)
|
||||||
|
|
||||||
|
private val STRICTFP_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.Strictfp")
|
||||||
|
|
||||||
|
fun DeclarationDescriptor.findStrictfpAnnotation() =
|
||||||
|
DescriptorUtils.getAnnotationByFqName(annotations, STRICTFP_ANNOTATION_FQ_NAME)
|
||||||
|
|
||||||
fun CallableDescriptor.isPlatformStaticInObjectOrClass(): Boolean =
|
fun CallableDescriptor.isPlatformStaticInObjectOrClass(): Boolean =
|
||||||
isPlatformStaticIn { DescriptorUtils.isNonCompanionObject(it) || DescriptorUtils.isClassOrEnumClass(it) }
|
isPlatformStaticIn { DescriptorUtils.isNonCompanionObject(it) || DescriptorUtils.isClassOrEnumClass(it) }
|
||||||
|
|
||||||
|
|||||||
+9
-3
@@ -1,11 +1,17 @@
|
|||||||
<!WRONG_ANNOTATION_TARGET!>@kotlin.jvm.Strictfp<!> class A {
|
<!STRICTFP_ON_CLASS!>@kotlin.jvm.Strictfp<!> class A {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<!WRONG_ANNOTATION_TARGET!>@kotlin.jvm.Strictfp<!> object B {
|
<!STRICTFP_ON_CLASS!>@kotlin.jvm.Strictfp<!> object B {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<!WRONG_ANNOTATION_TARGET!>@kotlin.jvm.Strictfp<!> interface C {
|
<!STRICTFP_ON_CLASS!>@kotlin.jvm.Strictfp<!> interface C {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
<!STRICTFP_ON_CLASS!>@kotlin.jvm.Strictfp<!> class D
|
||||||
|
|
||||||
|
<!STRICTFP_ON_CLASS!>@kotlin.jvm.Strictfp<!> object: Any() {}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package
|
package
|
||||||
|
|
||||||
|
public fun foo(): kotlin.Unit
|
||||||
|
|
||||||
@kotlin.jvm.Strictfp() public final class A {
|
@kotlin.jvm.Strictfp() public final class A {
|
||||||
public constructor A()
|
public constructor A()
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ annotation class Transient
|
|||||||
* of floating point operations performed inside the method needs to be restricted in order to
|
* of floating point operations performed inside the method needs to be restricted in order to
|
||||||
* achieve better portability.
|
* achieve better portability.
|
||||||
*/
|
*/
|
||||||
@Target(FUNCTION, CONSTRUCTOR, PROPERTY_GETTER, PROPERTY_SETTER)
|
@Target(FUNCTION, CONSTRUCTOR, PROPERTY_GETTER, PROPERTY_SETTER, CLASS)
|
||||||
@Retention(AnnotationRetention.SOURCE)
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
@MustBeDocumented
|
@MustBeDocumented
|
||||||
annotation class Strictfp
|
annotation class Strictfp
|
||||||
|
|||||||
Reference in New Issue
Block a user