JS: don't report about inline modifier on inline extension fun to external class
This commit is contained in:
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.psi.KtNamedFunction;
|
||||
import org.jetbrains.kotlin.psi.KtProperty;
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineAnalyzerExtension;
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
|
||||
import org.jetbrains.kotlin.resolve.inline.ReasonableInlineRule;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -35,9 +36,11 @@ public class AnalyzerExtensions {
|
||||
}
|
||||
|
||||
@NotNull private final BindingTrace trace;
|
||||
@NotNull private final Iterable<ReasonableInlineRule> reasonableInlineRules;
|
||||
|
||||
public AnalyzerExtensions(@NotNull BindingTrace trace) {
|
||||
public AnalyzerExtensions(@NotNull BindingTrace trace, @NotNull Iterable<ReasonableInlineRule> reasonableInlineRules) {
|
||||
this.trace = trace;
|
||||
this.reasonableInlineRules = reasonableInlineRules;
|
||||
}
|
||||
|
||||
public void process(@NotNull BodiesResolveContext bodiesResolveContext) {
|
||||
@@ -61,17 +64,17 @@ public class AnalyzerExtensions {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<InlineAnalyzerExtension> getFunctionExtensions(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
private List<InlineAnalyzerExtension> getFunctionExtensions(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
if (InlineUtil.isInline(functionDescriptor)) {
|
||||
return Collections.singletonList(InlineAnalyzerExtension.INSTANCE);
|
||||
return Collections.singletonList(new InlineAnalyzerExtension(reasonableInlineRules));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<InlineAnalyzerExtension> getPropertyExtensions(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
private List<InlineAnalyzerExtension> getPropertyExtensions(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
if (InlineUtil.hasInlineAccessors(propertyDescriptor)) {
|
||||
return Collections.singletonList(InlineAnalyzerExtension.INSTANCE);
|
||||
return Collections.singletonList(new InlineAnalyzerExtension(reasonableInlineRules));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
+3
-1
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||
|
||||
object InlineAnalyzerExtension : AnalyzerExtensions.AnalyzerExtension {
|
||||
class InlineAnalyzerExtension(private val reasonableInlineRules: Iterable<ReasonableInlineRule>) : AnalyzerExtensions.AnalyzerExtension {
|
||||
|
||||
override fun process(descriptor: CallableMemberDescriptor, functionOrProperty: KtCallableDeclaration, trace: BindingTrace) {
|
||||
checkModalityAndOverrides(descriptor, functionOrProperty, trace)
|
||||
@@ -143,6 +143,8 @@ object InlineAnalyzerExtension : AnalyzerExtensions.AnalyzerExtension {
|
||||
functionDescriptor.isInlineOnlyOrReifiable() ||
|
||||
functionDescriptor.isHeader) return
|
||||
|
||||
if (reasonableInlineRules.any { it.isInlineReasonable(functionDescriptor, function, trace.bindingContext) }) return
|
||||
|
||||
val reportOn = function.modifierList?.getModifier(KtTokens.INLINE_KEYWORD) ?: function
|
||||
trace.report(Errors.NOTHING_TO_INLINE.on(reportOn, functionDescriptor))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.inline
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
|
||||
interface ReasonableInlineRule {
|
||||
fun isInlineReasonable(descriptor: CallableMemberDescriptor, declaration: KtCallableDeclaration, context: BindingContext): Boolean
|
||||
}
|
||||
Reference in New Issue
Block a user