Use Java 8 lambdas instead of anonymous classes in compiler modules
This commit is contained in:
@@ -31,7 +31,6 @@ import com.intellij.util.containers.Stack;
|
||||
import kotlin.Pair;
|
||||
import kotlin.TuplesKt;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.text.StringsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -55,30 +54,27 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CheckerTestUtil {
|
||||
public static final Comparator<ActualDiagnostic> DIAGNOSTIC_COMPARATOR = new Comparator<ActualDiagnostic>() {
|
||||
@Override
|
||||
public int compare(@NotNull ActualDiagnostic o1, @NotNull ActualDiagnostic o2) {
|
||||
List<TextRange> ranges1 = o1.diagnostic.getTextRanges();
|
||||
List<TextRange> ranges2 = o2.diagnostic.getTextRanges();
|
||||
int minNumberOfRanges = ranges1.size() < ranges2.size() ? ranges1.size() : ranges2.size();
|
||||
for (int i = 0; i < minNumberOfRanges; i++) {
|
||||
TextRange range1 = ranges1.get(i);
|
||||
TextRange range2 = ranges2.get(i);
|
||||
int startOffset1 = range1.getStartOffset();
|
||||
int startOffset2 = range2.getStartOffset();
|
||||
if (startOffset1 != startOffset2) {
|
||||
// Start early -- go first
|
||||
return startOffset1 - range2.getStartOffset();
|
||||
}
|
||||
int endOffset1 = range1.getEndOffset();
|
||||
int endOffset2 = range2.getEndOffset();
|
||||
if (endOffset1 != endOffset2) {
|
||||
// start at the same offset, the one who end later is the outer, i.e. goes first
|
||||
return endOffset2 - endOffset1;
|
||||
}
|
||||
public static final Comparator<ActualDiagnostic> DIAGNOSTIC_COMPARATOR = (o1, o2) -> {
|
||||
List<TextRange> ranges1 = o1.diagnostic.getTextRanges();
|
||||
List<TextRange> ranges2 = o2.diagnostic.getTextRanges();
|
||||
int minNumberOfRanges = ranges1.size() < ranges2.size() ? ranges1.size() : ranges2.size();
|
||||
for (int i = 0; i < minNumberOfRanges; i++) {
|
||||
TextRange range1 = ranges1.get(i);
|
||||
TextRange range2 = ranges2.get(i);
|
||||
int startOffset1 = range1.getStartOffset();
|
||||
int startOffset2 = range2.getStartOffset();
|
||||
if (startOffset1 != startOffset2) {
|
||||
// Start early -- go first
|
||||
return startOffset1 - range2.getStartOffset();
|
||||
}
|
||||
int endOffset1 = range1.getEndOffset();
|
||||
int endOffset2 = range2.getEndOffset();
|
||||
if (endOffset1 != endOffset2) {
|
||||
// start at the same offset, the one who end later is the outer, i.e. goes first
|
||||
return endOffset2 - endOffset1;
|
||||
}
|
||||
return ranges1.size() - ranges2.size();
|
||||
}
|
||||
return ranges1.size() - ranges2.size();
|
||||
};
|
||||
|
||||
private static final String IGNORE_DIAGNOSTIC_PARAMETER = "IGNORE";
|
||||
@@ -104,12 +100,7 @@ public class CheckerTestUtil {
|
||||
|
||||
List<Pair<MultiTargetPlatform, BindingContext>> sortedBindings = CollectionsKt.sortedWith(
|
||||
implementingModulesBindings,
|
||||
new Comparator<Pair<MultiTargetPlatform, BindingContext>>() {
|
||||
@Override
|
||||
public int compare(Pair<MultiTargetPlatform, BindingContext> o1, Pair<MultiTargetPlatform, BindingContext> o2) {
|
||||
return o1.getFirst().compareTo(o2.getFirst());
|
||||
}
|
||||
}
|
||||
(o1, o2) -> o1.getFirst().compareTo(o2.getFirst())
|
||||
);
|
||||
|
||||
for (Pair<MultiTargetPlatform, BindingContext> binding : sortedBindings) {
|
||||
@@ -299,12 +290,7 @@ public class CheckerTestUtil {
|
||||
|
||||
for (TextDiagnostic expectedDiagnostic : expectedDiagnostics) {
|
||||
Map.Entry<ActualDiagnostic, TextDiagnostic> actualDiagnosticEntry = CollectionsKt.firstOrNull(
|
||||
actualDiagnostics.entrySet(), new Function1<Map.Entry<ActualDiagnostic, TextDiagnostic>, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(Map.Entry<ActualDiagnostic, TextDiagnostic> entry) {
|
||||
return expectedDiagnostic.getDescription().equals(entry.getValue().getDescription());
|
||||
}
|
||||
}
|
||||
actualDiagnostics.entrySet(), entry -> expectedDiagnostic.getDescription().equals(entry.getValue().getDescription())
|
||||
);
|
||||
|
||||
if (actualDiagnosticEntry != null) {
|
||||
@@ -403,12 +389,7 @@ public class CheckerTestUtil {
|
||||
public static StringBuffer addDiagnosticMarkersToText(@NotNull PsiFile psiFile, @NotNull Collection<ActualDiagnostic> diagnostics) {
|
||||
return addDiagnosticMarkersToText(
|
||||
psiFile, diagnostics, Collections.<ActualDiagnostic, TextDiagnostic>emptyMap(),
|
||||
new Function<PsiFile, String>() {
|
||||
@Override
|
||||
public String fun(PsiFile file) {
|
||||
return file.getText();
|
||||
}
|
||||
}
|
||||
PsiElement::getText
|
||||
);
|
||||
}
|
||||
|
||||
@@ -623,12 +604,9 @@ public class CheckerTestUtil {
|
||||
diagnosticDescriptors.add(
|
||||
new DiagnosticDescriptor(range.getStartOffset(), range.getEndOffset(), diagnosticsGroupedByRanges.get(range)));
|
||||
}
|
||||
Collections.sort(diagnosticDescriptors, new Comparator<DiagnosticDescriptor>() {
|
||||
@Override
|
||||
public int compare(@NotNull DiagnosticDescriptor d1, @NotNull DiagnosticDescriptor d2) {
|
||||
// Start early -- go first; start at the same offset, the one who end later is the outer, i.e. goes first
|
||||
return (d1.start != d2.start) ? d1.start - d2.start : d2.end - d1.end;
|
||||
}
|
||||
Collections.sort(diagnosticDescriptors, (d1, d2) -> {
|
||||
// Start early -- go first; start at the same offset, the one who end later is the outer, i.e. goes first
|
||||
return (d1.start != d2.start) ? d1.start - d2.start : d2.end - d1.end;
|
||||
});
|
||||
return diagnosticDescriptors;
|
||||
}
|
||||
@@ -746,12 +724,7 @@ public class CheckerTestUtil {
|
||||
if (renderer instanceof AbstractDiagnosticWithParametersRenderer) {
|
||||
//noinspection unchecked
|
||||
Object[] renderParameters = ((AbstractDiagnosticWithParametersRenderer) renderer).renderParameters(diagnostic);
|
||||
List<String> parameters = ContainerUtil.map(renderParameters, new Function<Object, String>() {
|
||||
@Override
|
||||
public String fun(Object o) {
|
||||
return o != null ? o.toString() : "null";
|
||||
}
|
||||
});
|
||||
List<String> parameters = ContainerUtil.map(renderParameters, Object::toString);
|
||||
return new TextDiagnostic(diagnosticName, actualDiagnostic.platform, parameters);
|
||||
}
|
||||
return new TextDiagnostic(diagnosticName, actualDiagnostic.platform, null);
|
||||
@@ -817,12 +790,7 @@ public class CheckerTestUtil {
|
||||
result.append(name);
|
||||
if (parameters != null) {
|
||||
result.append("(");
|
||||
result.append(StringUtil.join(parameters, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String s) {
|
||||
return escape(s);
|
||||
}
|
||||
}, "; "));
|
||||
result.append(StringUtil.join(parameters, TextDiagnostic::escape, "; "));
|
||||
result.append(")");
|
||||
}
|
||||
return result.toString();
|
||||
|
||||
@@ -38,14 +38,11 @@ import java.util.List;
|
||||
|
||||
public class DiagnosticUtils {
|
||||
@NotNull
|
||||
private static final Comparator<TextRange> TEXT_RANGE_COMPARATOR = new Comparator<TextRange>() {
|
||||
@Override
|
||||
public int compare(@NotNull TextRange o1, @NotNull TextRange o2) {
|
||||
if (o1.getStartOffset() != o2.getStartOffset()) {
|
||||
return o1.getStartOffset() - o2.getStartOffset();
|
||||
}
|
||||
return o1.getEndOffset() - o2.getEndOffset();
|
||||
private static final Comparator<TextRange> TEXT_RANGE_COMPARATOR = (o1, o2) -> {
|
||||
if (o1.getStartOffset() != o2.getStartOffset()) {
|
||||
return o1.getStartOffset() - o2.getStartOffset();
|
||||
}
|
||||
return o1.getEndOffset() - o2.getEndOffset();
|
||||
};
|
||||
|
||||
private DiagnosticUtils() {
|
||||
@@ -163,22 +160,19 @@ public class DiagnosticUtils {
|
||||
|
||||
@NotNull
|
||||
public static List<Diagnostic> sortedDiagnostics(@NotNull Collection<Diagnostic> diagnostics) {
|
||||
Comparator<Diagnostic> diagnosticComparator = new Comparator<Diagnostic>() {
|
||||
@Override
|
||||
public int compare(@NotNull Diagnostic d1, @NotNull Diagnostic d2) {
|
||||
String path1 = d1.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||
String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||
if (!path1.equals(path2)) return path1.compareTo(path2);
|
||||
Comparator<Diagnostic> diagnosticComparator = (d1, d2) -> {
|
||||
String path1 = d1.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||
String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||
if (!path1.equals(path2)) return path1.compareTo(path2);
|
||||
|
||||
TextRange range1 = firstRange(d1.getTextRanges());
|
||||
TextRange range2 = firstRange(d2.getTextRanges());
|
||||
TextRange range1 = firstRange(d1.getTextRanges());
|
||||
TextRange range2 = firstRange(d2.getTextRanges());
|
||||
|
||||
if (!range1.equals(range2)) {
|
||||
return TEXT_RANGE_COMPARATOR.compare(range1, range2);
|
||||
}
|
||||
|
||||
return d1.getFactory().getName().compareTo(d2.getFactory().getName());
|
||||
if (!range1.equals(range2)) {
|
||||
return TEXT_RANGE_COMPARATOR.compare(range1, range2);
|
||||
}
|
||||
|
||||
return d1.getFactory().getName().compareTo(d2.getFactory().getName());
|
||||
};
|
||||
List<Diagnostic> result = Lists.newArrayList(diagnostics);
|
||||
Collections.sort(result, diagnosticComparator);
|
||||
|
||||
+63
-123
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.diagnostics.rendering;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import kotlin.Pair;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
@@ -27,14 +26,8 @@ import org.jetbrains.kotlin.config.LanguageVersion;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.diagnostics.TypeMismatchDueToTypeProjectionsData;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.KtTypeConstraint;
|
||||
import org.jetbrains.kotlin.resolve.VarianceConflictDiagnosticData;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.SinceKotlinInfo;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.util.MappedExtensionProvider;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
|
||||
@@ -59,16 +52,13 @@ public class DefaultErrorMessages {
|
||||
private static final DiagnosticFactoryToRendererMap MAP = new DiagnosticFactoryToRendererMap("Default");
|
||||
private static final MappedExtensionProvider<Extension, List<DiagnosticFactoryToRendererMap>> RENDERER_MAPS = MappedExtensionProvider.create(
|
||||
Extension.EP_NAME,
|
||||
new Function1<List<? extends Extension>, List<DiagnosticFactoryToRendererMap>>() {
|
||||
@Override
|
||||
public List<DiagnosticFactoryToRendererMap> invoke(List<? extends Extension> extensions) {
|
||||
List<DiagnosticFactoryToRendererMap> result = new ArrayList<DiagnosticFactoryToRendererMap>(extensions.size() + 1);
|
||||
for (Extension extension : extensions) {
|
||||
result.add(extension.getMap());
|
||||
}
|
||||
result.add(MAP);
|
||||
return result;
|
||||
extensions -> {
|
||||
List<DiagnosticFactoryToRendererMap> result = new ArrayList<DiagnosticFactoryToRendererMap>(extensions.size() + 1);
|
||||
for (Extension extension : extensions) {
|
||||
result.add(extension.getMap());
|
||||
}
|
||||
result.add(MAP);
|
||||
return result;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
@@ -133,19 +123,15 @@ public class DefaultErrorMessages {
|
||||
RENDER_TYPE);
|
||||
MAP.put(TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS,
|
||||
"Type mismatch: inferred type is {1} but {0} was expected. Projected type {2} restricts use of {3}",
|
||||
new MultiRenderer<TypeMismatchDueToTypeProjectionsData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] render(@NotNull TypeMismatchDueToTypeProjectionsData object) {
|
||||
RenderingContext context =
|
||||
of(object.getExpectedType(), object.getExpressionType(), object.getReceiverType(), object.getCallableDescriptor());
|
||||
return new String[] {
|
||||
RENDER_TYPE.render(object.getExpectedType(), context),
|
||||
RENDER_TYPE.render(object.getExpressionType(), context),
|
||||
RENDER_TYPE.render(object.getReceiverType(), context),
|
||||
FQ_NAMES_IN_TYPES.render(object.getCallableDescriptor(), context)
|
||||
};
|
||||
}
|
||||
object -> {
|
||||
RenderingContext context =
|
||||
of(object.getExpectedType(), object.getExpressionType(), object.getReceiverType(), object.getCallableDescriptor());
|
||||
return new String[] {
|
||||
RENDER_TYPE.render(object.getExpectedType(), context),
|
||||
RENDER_TYPE.render(object.getExpressionType(), context),
|
||||
RENDER_TYPE.render(object.getReceiverType(), context),
|
||||
FQ_NAMES_IN_TYPES.render(object.getCallableDescriptor(), context)
|
||||
};
|
||||
});
|
||||
|
||||
MAP.put(MEMBER_PROJECTED_OUT, "Out-projected type ''{1}'' prohibits the use of ''{0}''", FQ_NAMES_IN_TYPES, RENDER_TYPE);
|
||||
@@ -198,20 +184,16 @@ public class DefaultErrorMessages {
|
||||
MAP.put(MIXING_NAMED_AND_POSITIONED_ARGUMENTS, "Mixing named and positioned arguments is not allowed");
|
||||
MAP.put(ARGUMENT_PASSED_TWICE, "An argument is already passed for this parameter");
|
||||
MAP.put(NAMED_PARAMETER_NOT_FOUND, "Cannot find a parameter with this name: {0}", ELEMENT_TEXT);
|
||||
MAP.put(NAMED_ARGUMENTS_NOT_ALLOWED, "Named arguments are not allowed for {0}", new DiagnosticParameterRenderer<BadNamedArgumentsTarget>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull BadNamedArgumentsTarget target, @NotNull RenderingContext context) {
|
||||
switch (target) {
|
||||
case NON_KOTLIN_FUNCTION:
|
||||
return "non-Kotlin functions";
|
||||
case INVOKE_ON_FUNCTION_TYPE:
|
||||
return "function types";
|
||||
case HEADER_CLASS_MEMBER:
|
||||
return "members of header classes";
|
||||
default:
|
||||
throw new AssertionError(target);
|
||||
}
|
||||
MAP.put(NAMED_ARGUMENTS_NOT_ALLOWED, "Named arguments are not allowed for {0}", (target, context) -> {
|
||||
switch (target) {
|
||||
case NON_KOTLIN_FUNCTION:
|
||||
return "non-Kotlin functions";
|
||||
case INVOKE_ON_FUNCTION_TYPE:
|
||||
return "function types";
|
||||
case HEADER_CLASS_MEMBER:
|
||||
return "members of header classes";
|
||||
default:
|
||||
throw new AssertionError(target);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -333,28 +315,14 @@ public class DefaultErrorMessages {
|
||||
MAP.put(DEPRECATION, "''{0}'' is deprecated. {1}", DEPRECATION_RENDERER, STRING);
|
||||
MAP.put(DEPRECATION_ERROR, "Using ''{0}'' is an error. {1}", DEPRECATION_RENDERER, STRING);
|
||||
|
||||
DiagnosticParameterRenderer<Pair<LanguageVersion, String>> sinceKotlinInfoMessage = new DiagnosticParameterRenderer<Pair<LanguageVersion, String>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull Pair<LanguageVersion, String> pair, @NotNull RenderingContext renderingContext) {
|
||||
String message = pair.getSecond();
|
||||
return pair.getFirst().getVersionString() + (message != null ? ". " + message : "");
|
||||
}
|
||||
DiagnosticParameterRenderer<Pair<LanguageVersion, String>> sinceKotlinInfoMessage = (pair, renderingContext) -> {
|
||||
String message = pair.getSecond();
|
||||
return pair.getFirst().getVersionString() + (message != null ? ". " + message : "");
|
||||
};
|
||||
MAP.put(SINCE_KOTLIN_INFO_DEPRECATION, "''{0}''{1} should not be used in Kotlin {2}", DEPRECATION_RENDERER, new DiagnosticParameterRenderer<SinceKotlinInfo.Version>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull SinceKotlinInfo.Version obj, @NotNull RenderingContext renderingContext) {
|
||||
return obj.equals(SinceKotlinInfo.Version.INFINITY) ? "" : " is only supported since Kotlin " + obj.asString() + " and";
|
||||
}
|
||||
}, sinceKotlinInfoMessage);
|
||||
MAP.put(SINCE_KOTLIN_INFO_DEPRECATION_ERROR, "''{0}''{1} cannot be used in Kotlin {2}", DEPRECATION_RENDERER, new DiagnosticParameterRenderer<SinceKotlinInfo.Version>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull SinceKotlinInfo.Version obj, @NotNull RenderingContext renderingContext) {
|
||||
return obj.equals(SinceKotlinInfo.Version.INFINITY) ? "" : " is only available since Kotlin " + obj.asString() + " and";
|
||||
}
|
||||
}, sinceKotlinInfoMessage);
|
||||
MAP.put(SINCE_KOTLIN_INFO_DEPRECATION, "''{0}''{1} should not be used in Kotlin {2}", DEPRECATION_RENDERER,
|
||||
(obj, renderingContext) -> obj.equals(SinceKotlinInfo.Version.INFINITY) ? "" : " is only supported since Kotlin " + obj.asString() + " and", sinceKotlinInfoMessage);
|
||||
MAP.put(SINCE_KOTLIN_INFO_DEPRECATION_ERROR, "''{0}''{1} cannot be used in Kotlin {2}", DEPRECATION_RENDERER,
|
||||
(obj, renderingContext) -> obj.equals(SinceKotlinInfo.Version.INFINITY) ? "" : " is only available since Kotlin " + obj.asString() + " and", sinceKotlinInfoMessage);
|
||||
|
||||
MAP.put(API_NOT_AVAILABLE, "This declaration is only available since Kotlin {0} and cannot be used with the specified API version {1}", STRING, STRING);
|
||||
|
||||
@@ -362,15 +330,12 @@ public class DefaultErrorMessages {
|
||||
MAP.put(PRE_RELEASE_CLASS, "{0} is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler", TO_STRING);
|
||||
MAP.put(INCOMPATIBLE_CLASS,
|
||||
"{0} was compiled with an incompatible version of Kotlin. {1}",
|
||||
TO_STRING, new DiagnosticParameterRenderer<IncompatibleVersionErrorData<?>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull IncompatibleVersionErrorData<?> incompatibility, @NotNull RenderingContext renderingContext) {
|
||||
return "The binary version of its metadata is " + incompatibility.getActualVersion() +
|
||||
", expected version is " + incompatibility.getExpectedVersion() + ".\n" +
|
||||
"The class is loaded from " + FileUtil.toSystemIndependentName(incompatibility.getFilePath());
|
||||
}
|
||||
});
|
||||
TO_STRING,
|
||||
(incompatibility, renderingContext) ->
|
||||
"The binary version of its metadata is " + incompatibility.getActualVersion() +
|
||||
", expected version is " + incompatibility.getExpectedVersion() + ".\n" +
|
||||
"The class is loaded from " + FileUtil.toSystemIndependentName(incompatibility.getFilePath())
|
||||
);
|
||||
|
||||
MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME);
|
||||
MAP.put(LOCAL_INTERFACE_NOT_ALLOWED, "''{0}'' is an interface so it cannot be local. Try to use anonymous object or abstract class instead", NAME);
|
||||
@@ -493,14 +458,10 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(IMPLICIT_CAST_TO_ANY, "Conditional branch result of type {0} is implicitly cast to {1}",
|
||||
RENDER_TYPE, RENDER_TYPE);
|
||||
MAP.put(EXPRESSION_EXPECTED, "{0} is not an expression, and only expressions are allowed here", new DiagnosticParameterRenderer<KtExpression>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull KtExpression expression, @NotNull RenderingContext context) {
|
||||
String expressionType = expression.toString();
|
||||
return expressionType.substring(0, 1) +
|
||||
expressionType.substring(1).toLowerCase();
|
||||
}
|
||||
MAP.put(EXPRESSION_EXPECTED, "{0} is not an expression, and only expressions are allowed here", (expression, context) -> {
|
||||
String expressionType = expression.toString();
|
||||
return expressionType.substring(0, 1) +
|
||||
expressionType.substring(1).toLowerCase();
|
||||
});
|
||||
|
||||
MAP.put(UPPER_BOUND_VIOLATED, "Type argument is not within its bounds: should be subtype of ''{0}''", RENDER_TYPE, RENDER_TYPE);
|
||||
@@ -613,13 +574,9 @@ public class DefaultErrorMessages {
|
||||
MAP.put(UNEXPECTED_SAFE_CALL, "Safe-call is not allowed here");
|
||||
MAP.put(UNNECESSARY_NOT_NULL_ASSERTION, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE);
|
||||
MAP.put(NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION, "Non-null assertion (!!) is called on a lambda expression");
|
||||
MAP.put(NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER, "{0} does not refer to a type parameter of {1}", new DiagnosticParameterRenderer<KtTypeConstraint>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull KtTypeConstraint typeConstraint, @NotNull RenderingContext context) {
|
||||
//noinspection ConstantConditions
|
||||
return typeConstraint.getSubjectTypeParameterName().getReferencedName();
|
||||
}
|
||||
MAP.put(NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER, "{0} does not refer to a type parameter of {1}", (typeConstraint, context) -> {
|
||||
//noinspection ConstantConditions
|
||||
return typeConstraint.getSubjectTypeParameterName().getReferencedName();
|
||||
}, DECLARATION_NAME);
|
||||
MAP.put(SMARTCAST_IMPOSSIBLE,
|
||||
"Smart cast to ''{0}'' is impossible, because ''{1}'' is a {2}", RENDER_TYPE, STRING, STRING);
|
||||
@@ -637,20 +594,16 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(MISPLACED_TYPE_PARAMETER_CONSTRAINTS, "If a type parameter has multiple constraints, they all need to be placed in the 'where' clause");
|
||||
|
||||
MultiRenderer<VarianceConflictDiagnosticData> varianceConflictDataRenderer = new MultiRenderer<VarianceConflictDiagnosticData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] render(@NotNull VarianceConflictDiagnosticData data) {
|
||||
RenderingContext context =
|
||||
of(data.getTypeParameter(), data.getTypeParameter().getVariance(), data.getOccurrencePosition(),
|
||||
data.getContainingType());
|
||||
return new String[] {
|
||||
NAME.render(data.getTypeParameter(), context),
|
||||
RENDER_POSITION_VARIANCE.render(data.getTypeParameter().getVariance(), context),
|
||||
RENDER_POSITION_VARIANCE.render(data.getOccurrencePosition(), context),
|
||||
RENDER_TYPE.render(data.getContainingType(), context)
|
||||
};
|
||||
}
|
||||
MultiRenderer<VarianceConflictDiagnosticData> varianceConflictDataRenderer = data -> {
|
||||
RenderingContext context =
|
||||
of(data.getTypeParameter(), data.getTypeParameter().getVariance(), data.getOccurrencePosition(),
|
||||
data.getContainingType());
|
||||
return new String[] {
|
||||
NAME.render(data.getTypeParameter(), context),
|
||||
RENDER_POSITION_VARIANCE.render(data.getTypeParameter().getVariance(), context),
|
||||
RENDER_POSITION_VARIANCE.render(data.getOccurrencePosition(), context),
|
||||
RENDER_TYPE.render(data.getContainingType(), context)
|
||||
};
|
||||
};
|
||||
MAP.put(TYPE_VARIANCE_CONFLICT, "Type parameter {0} is declared as ''{1}'' but occurs in ''{2}'' position in type {3}",
|
||||
varianceConflictDataRenderer);
|
||||
@@ -687,13 +640,9 @@ public class DefaultErrorMessages {
|
||||
MAP.put(INCONSISTENT_TYPE_PARAMETER_VALUES, "Type parameter {0} of ''{1}'' has inconsistent values: {2}", NAME, NAME, RENDER_COLLECTION_OF_TYPES);
|
||||
MAP.put(INCONSISTENT_TYPE_PARAMETER_BOUNDS, "Type parameter {0} of ''{1}'' has inconsistent bounds: {2}", NAME, NAME, RENDER_COLLECTION_OF_TYPES);
|
||||
|
||||
MAP.put(EQUALITY_NOT_APPLICABLE, "Operator ''{0}'' cannot be applied to ''{1}'' and ''{2}''", new DiagnosticParameterRenderer<KtSimpleNameExpression>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull KtSimpleNameExpression nameExpression, @NotNull RenderingContext context) {
|
||||
//noinspection ConstantConditions
|
||||
return nameExpression.getReferencedName();
|
||||
}
|
||||
MAP.put(EQUALITY_NOT_APPLICABLE, "Operator ''{0}'' cannot be applied to ''{1}'' and ''{2}''", (nameExpression, context) -> {
|
||||
//noinspection ConstantConditions
|
||||
return nameExpression.getReferencedName();
|
||||
}, RENDER_TYPE, RENDER_TYPE);
|
||||
|
||||
MAP.put(SENSELESS_COMPARISON, "Condition ''{0}'' is always ''{1}''", ELEMENT_TEXT, TO_STRING);
|
||||
@@ -745,21 +694,12 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(FUNCTION_EXPECTED, "Expression ''{0}''{1} cannot be invoked as a function. " +
|
||||
"The function ''" + OperatorNameConventions.INVOKE.asString() + "()'' is not found",
|
||||
ELEMENT_TEXT, new DiagnosticParameterRenderer<KotlinType>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull KotlinType type, @NotNull RenderingContext context) {
|
||||
if (type.isError()) return "";
|
||||
return " of type '" + RENDER_TYPE.render(type, context) + "'";
|
||||
}
|
||||
ELEMENT_TEXT, (type, context) -> {
|
||||
if (type.isError()) return "";
|
||||
return " of type '" + RENDER_TYPE.render(type, context) + "'";
|
||||
});
|
||||
MAP.put(FUNCTION_CALL_EXPECTED, "Function invocation ''{0}({1})'' expected", ELEMENT_TEXT, new DiagnosticParameterRenderer<Boolean>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull Boolean hasValueParameters, @NotNull RenderingContext context) {
|
||||
return hasValueParameters ? "..." : "";
|
||||
}
|
||||
});
|
||||
MAP.put(FUNCTION_CALL_EXPECTED, "Function invocation ''{0}({1})'' expected", ELEMENT_TEXT,
|
||||
(hasValueParameters, context) -> hasValueParameters ? "..." : "");
|
||||
MAP.put(NON_TAIL_RECURSIVE_CALL, "Recursive call is not a tail call");
|
||||
MAP.put(TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED, "Tail recursion optimization inside try/catch/finally is not supported");
|
||||
|
||||
|
||||
@@ -17,20 +17,13 @@
|
||||
package org.jetbrains.kotlin.psi;
|
||||
|
||||
import com.intellij.util.ArrayFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc;
|
||||
|
||||
public interface KtDeclaration extends KtExpression, KtModifierListOwner {
|
||||
KtDeclaration[] EMPTY_ARRAY = new KtDeclaration[0];
|
||||
|
||||
ArrayFactory<KtDeclaration> ARRAY_FACTORY = new ArrayFactory<KtDeclaration>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public KtDeclaration[] create(int count) {
|
||||
return count == 0 ? EMPTY_ARRAY : new KtDeclaration[count];
|
||||
}
|
||||
};
|
||||
ArrayFactory<KtDeclaration> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new KtDeclaration[count];
|
||||
|
||||
@Nullable
|
||||
KDoc getDocComment();
|
||||
|
||||
@@ -22,13 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public interface KtExpression extends KtElement {
|
||||
KtExpression[] EMPTY_ARRAY = new KtExpression[0];
|
||||
|
||||
ArrayFactory<KtExpression> ARRAY_FACTORY = new ArrayFactory<KtExpression>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public KtExpression[] create(int count) {
|
||||
return count == 0 ? EMPTY_ARRAY : new KtExpression[count];
|
||||
}
|
||||
};
|
||||
ArrayFactory<KtExpression> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new KtExpression[count];
|
||||
|
||||
@Override
|
||||
<R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data);
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class KtExpressionImplStub<T extends StubElement<?>> extends KtElementImplStub<T> implements KtExpression {
|
||||
@@ -41,12 +40,7 @@ public abstract class KtExpressionImplStub<T extends StubElement<?>> extends KtE
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException {
|
||||
return KtExpressionImpl.Companion.replaceExpression(this, newElement, new Function1<PsiElement, PsiElement>() {
|
||||
@Override
|
||||
public PsiElement invoke(PsiElement element) {
|
||||
return rawReplace(element);
|
||||
}
|
||||
});
|
||||
return KtExpressionImpl.Companion.replaceExpression(this, newElement, this::rawReplace);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.intellij.util.FileContentUtilCore;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.KtNodeTypes;
|
||||
@@ -258,19 +257,12 @@ public class KtFile extends PsiFileBase implements KtDeclarationContainer, KtAnn
|
||||
public List<KtAnnotationEntry> getDanglingAnnotations() {
|
||||
KotlinFileStub stub = getStub();
|
||||
KtModifierList[] danglingModifierLists = stub == null
|
||||
? findChildrenByClass(KtModifierList.class)
|
||||
: stub.getChildrenByType(
|
||||
KtStubElementTypes.MODIFIER_LIST,
|
||||
KtStubElementTypes.MODIFIER_LIST.getArrayFactory()
|
||||
);
|
||||
return ArraysKt.flatMap(
|
||||
danglingModifierLists,
|
||||
new Function1<KtModifierList, Iterable<KtAnnotationEntry>>() {
|
||||
@Override
|
||||
public Iterable<KtAnnotationEntry> invoke(KtModifierList modifierList) {
|
||||
return modifierList.getAnnotationEntries();
|
||||
}
|
||||
});
|
||||
? findChildrenByClass(KtModifierList.class)
|
||||
: stub.getChildrenByType(
|
||||
KtStubElementTypes.MODIFIER_LIST,
|
||||
KtStubElementTypes.MODIFIER_LIST.getArrayFactory()
|
||||
);
|
||||
return ArraysKt.flatMap(danglingModifierLists, KtModifierList::getAnnotationEntries);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.psi;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.resolve.ImportPath;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -37,7 +35,7 @@ public class KtImportsFactory {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public KtImportDirective createImportDirective(@NotNull ImportPath importPath) {
|
||||
private KtImportDirective createImportDirective(@NotNull ImportPath importPath) {
|
||||
KtImportDirective directive = importsCache.get(importPath);
|
||||
if (directive != null) {
|
||||
return directive;
|
||||
@@ -51,13 +49,6 @@ public class KtImportsFactory {
|
||||
|
||||
@NotNull
|
||||
public Collection<KtImportDirective> createImportDirectives(@NotNull Collection<ImportPath> importPaths) {
|
||||
return Collections2.transform(importPaths,
|
||||
new Function<ImportPath, KtImportDirective>() {
|
||||
@Override
|
||||
public KtImportDirective apply(@Nullable ImportPath path) {
|
||||
assert path != null;
|
||||
return createImportDirective(path);
|
||||
}
|
||||
});
|
||||
return CollectionsKt.map(importPaths, this::createImportDirective);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +25,9 @@ import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
|
||||
|
||||
public class KtSuperTypeListEntry extends KtElementImplStub<KotlinPlaceHolderStub<? extends KtSuperTypeListEntry>> {
|
||||
|
||||
private static final KtSuperTypeListEntry[] EMPTY_ARRAY = new KtSuperTypeListEntry[0];
|
||||
|
||||
public static ArrayFactory<KtSuperTypeListEntry> ARRAY_FACTORY = new ArrayFactory<KtSuperTypeListEntry>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public KtSuperTypeListEntry[] create(int count) {
|
||||
return count == 0 ? EMPTY_ARRAY : new KtSuperTypeListEntry[count];
|
||||
}
|
||||
};
|
||||
public static ArrayFactory<KtSuperTypeListEntry> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new KtSuperTypeListEntry[count];
|
||||
|
||||
public KtSuperTypeListEntry(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
|
||||
@@ -24,13 +24,7 @@ import java.util.List;
|
||||
public interface KtTypeElement extends KtElement {
|
||||
KtTypeElement[] EMPTY_ARRAY = new KtTypeElement[0];
|
||||
|
||||
ArrayFactory<KtTypeElement> ARRAY_FACTORY = new ArrayFactory<KtTypeElement>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public KtTypeElement[] create(int count) {
|
||||
return count == 0 ? EMPTY_ARRAY : new KtTypeElement[count];
|
||||
}
|
||||
};
|
||||
ArrayFactory<KtTypeElement> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new KtTypeElement[count];
|
||||
|
||||
// may contain null
|
||||
@NotNull
|
||||
|
||||
+5
-9
@@ -58,16 +58,12 @@ public abstract class KtStubElementType<StubT extends StubElement, PsiT extends
|
||||
}
|
||||
//noinspection unchecked
|
||||
emptyArray = (PsiT[]) Array.newInstance(psiClass, 0);
|
||||
arrayFactory = new ArrayFactory<PsiT>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiT[] create(int count) {
|
||||
if (count == 0) {
|
||||
return emptyArray;
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (PsiT[]) Array.newInstance(psiClass, count);
|
||||
arrayFactory = count -> {
|
||||
if (count == 0) {
|
||||
return emptyArray;
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (PsiT[]) Array.newInstance(psiClass, count);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import kotlin.jvm.functions.Function3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
@@ -36,7 +35,8 @@ import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||
import org.jetbrains.kotlin.util.slicedMap.*;
|
||||
import org.jetbrains.kotlin.util.slicedMap.MutableSlicedMap;
|
||||
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -233,15 +233,12 @@ public class BindingContextUtils {
|
||||
@NotNull BindingTrace trace, @Nullable TraceEntryFilter filter, boolean commitDiagnostics,
|
||||
@NotNull MutableSlicedMap map, MutableDiagnosticsWithSuppression diagnostics
|
||||
) {
|
||||
map.forEach(new Function3<WritableSlice, Object, Object, Void>() {
|
||||
@Override
|
||||
public Void invoke(WritableSlice slice, Object key, Object value) {
|
||||
if (filter == null || filter.accept(slice, key)) {
|
||||
trace.record(slice, key, value);
|
||||
}
|
||||
|
||||
return null;
|
||||
map.forEach((slice, key, value) -> {
|
||||
if (filter == null || filter.accept(slice, key)) {
|
||||
trace.record(slice, key, value);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!commitDiagnostics) return;
|
||||
|
||||
@@ -50,7 +50,6 @@ import org.jetbrains.kotlin.types.expressions.ValueParameterResolver;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||
import org.jetbrains.kotlin.util.Box;
|
||||
import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException;
|
||||
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -149,21 +148,13 @@ public class BodyResolver {
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor.getAnnotations());
|
||||
|
||||
resolveFunctionBody(outerDataFlowInfo, trace, constructor, descriptor, declaringScope,
|
||||
new Function1<LexicalScope, DataFlowInfo>() {
|
||||
@Override
|
||||
public DataFlowInfo invoke(@NotNull LexicalScope headerInnerScope) {
|
||||
return resolveSecondaryConstructorDelegationCall(outerDataFlowInfo, trace, headerInnerScope,
|
||||
constructor, descriptor);
|
||||
}
|
||||
},
|
||||
new Function1<LexicalScope, LexicalScope>() {
|
||||
@Override
|
||||
public LexicalScope invoke(LexicalScope scope) {
|
||||
return new LexicalScopeImpl(
|
||||
scope, descriptor, scope.isOwnerDescriptorAccessibleByLabel(), scope.getImplicitReceiver(),
|
||||
LexicalScopeKind.CONSTRUCTOR_HEADER);
|
||||
}
|
||||
});
|
||||
headerInnerScope -> resolveSecondaryConstructorDelegationCall(
|
||||
outerDataFlowInfo, trace, headerInnerScope, constructor, descriptor
|
||||
),
|
||||
scope -> new LexicalScopeImpl(
|
||||
scope, descriptor, scope.isOwnerDescriptorAccessibleByLabel(), scope.getImplicitReceiver(),
|
||||
LexicalScopeKind.CONSTRUCTOR_HEADER
|
||||
));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -637,15 +628,11 @@ public class BodyResolver {
|
||||
) {
|
||||
return new LexicalScopeImpl(originalScope, unsubstitutedPrimaryConstructor, false, null,
|
||||
LexicalScopeKind.DEFAULT_VALUE, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
for (ValueParameterDescriptor
|
||||
valueParameterDescriptor : unsubstitutedPrimaryConstructor.getValueParameters()) {
|
||||
handler.addVariableDescriptor(valueParameterDescriptor);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
handler -> {
|
||||
for (ValueParameterDescriptor valueParameter : unsubstitutedPrimaryConstructor.getValueParameters()) {
|
||||
handler.addVariableDescriptor(valueParameter);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -739,20 +726,14 @@ public class BodyResolver {
|
||||
private ObservableBindingTrace createFieldTrackingTrace(PropertyDescriptor propertyDescriptor) {
|
||||
return new ObservableBindingTrace(trace).addHandler(
|
||||
BindingContext.REFERENCE_TARGET,
|
||||
new ObservableBindingTrace.RecordHandler<KtReferenceExpression, DeclarationDescriptor>() {
|
||||
@Override
|
||||
public void handleRecord(
|
||||
WritableSlice<KtReferenceExpression, DeclarationDescriptor> slice,
|
||||
KtReferenceExpression expression,
|
||||
DeclarationDescriptor descriptor
|
||||
) {
|
||||
if (expression instanceof KtSimpleNameExpression &&
|
||||
descriptor instanceof SyntheticFieldDescriptor) {
|
||||
trace.record(BindingContext.BACKING_FIELD_REQUIRED,
|
||||
propertyDescriptor);
|
||||
(slice, expression, descriptor) -> {
|
||||
if (expression instanceof KtSimpleNameExpression &&
|
||||
descriptor instanceof SyntheticFieldDescriptor) {
|
||||
trace.record(BindingContext.BACKING_FIELD_REQUIRED,
|
||||
propertyDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
private void resolvePropertyDelegate(
|
||||
@@ -850,13 +831,10 @@ public class BodyResolver {
|
||||
SyntheticFieldDescriptor fieldDescriptor = new SyntheticFieldDescriptor(accessorDescriptor, property);
|
||||
innerScope = new LexicalScopeImpl(innerScope, functionDescriptor, true, null,
|
||||
LexicalScopeKind.PROPERTY_ACCESSOR_BODY,
|
||||
LocalRedeclarationChecker.DO_NOTHING.INSTANCE, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
handler.addVariableDescriptor(fieldDescriptor);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
});
|
||||
LocalRedeclarationChecker.DO_NOTHING.INSTANCE, handler -> {
|
||||
handler.addVariableDescriptor(fieldDescriptor);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
// Check parameter name shadowing
|
||||
for (KtParameter parameter : function.getValueParameters()) {
|
||||
if (SyntheticFieldDescriptor.NAME.equals(parameter.getNameAsName())) {
|
||||
@@ -914,16 +892,7 @@ public class BodyResolver {
|
||||
}
|
||||
// +1 is a work around against new Queue(0).addLast(...) bug // stepan.koltsov@ 2011-11-21
|
||||
Queue<DeferredType> queue = new Queue<DeferredType>(deferredTypes.size() + 1);
|
||||
trace.addHandler(DEFERRED_TYPE, new ObservableBindingTrace.RecordHandler<Box<DeferredType>, Boolean>() {
|
||||
@Override
|
||||
public void handleRecord(
|
||||
WritableSlice<Box<DeferredType>, Boolean> deferredTypeKeyDeferredTypeWritableSlice,
|
||||
Box<DeferredType> key,
|
||||
Boolean value
|
||||
) {
|
||||
queue.addLast(key.getData());
|
||||
}
|
||||
});
|
||||
trace.addHandler(DEFERRED_TYPE, (deferredTypeKeyDeferredTypeWritableSlice, key, value) -> queue.addLast(key.getData()));
|
||||
for (Box<DeferredType> deferredType : deferredTypes) {
|
||||
queue.addLast(deferredType.getData());
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import kotlin.TuplesKt;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.collections.SetsKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
|
||||
@@ -35,7 +34,6 @@ import org.jetbrains.kotlin.config.LanguageFeature;
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationSplitter;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.*;
|
||||
@@ -335,26 +333,23 @@ public class DescriptorResolver {
|
||||
TuplesKt.to(LanguageFeature.DestructuringLambdaParameters, languageVersionSettings)));
|
||||
}
|
||||
|
||||
destructuringVariables = new Function0<List<VariableDescriptor>>() {
|
||||
@Override
|
||||
public List<VariableDescriptor> invoke() {
|
||||
assert owner.getDispatchReceiverParameter() == null
|
||||
: "Destructuring declarations are only be parsed for lambdas, and they must not have a dispatch receiver";
|
||||
LexicalScope scopeForDestructuring =
|
||||
ScopeUtilsKt.createScopeForDestructuring(scope, owner.getExtensionReceiverParameter());
|
||||
destructuringVariables = () -> {
|
||||
assert owner.getDispatchReceiverParameter() == null
|
||||
: "Destructuring declarations are only be parsed for lambdas, and they must not have a dispatch receiver";
|
||||
LexicalScope scopeForDestructuring =
|
||||
ScopeUtilsKt.createScopeForDestructuring(scope, owner.getExtensionReceiverParameter());
|
||||
|
||||
List<VariableDescriptor> result =
|
||||
destructuringDeclarationResolver.resolveLocalVariablesFromDestructuringDeclaration(
|
||||
scope,
|
||||
destructuringDeclaration, new TransientReceiver(type), /* initializer = */ null,
|
||||
ExpressionTypingContext.newContext(
|
||||
trace, scopeForDestructuring, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE
|
||||
)
|
||||
);
|
||||
List<VariableDescriptor> result =
|
||||
destructuringDeclarationResolver.resolveLocalVariablesFromDestructuringDeclaration(
|
||||
scope,
|
||||
destructuringDeclaration, new TransientReceiver(type), /* initializer = */ null,
|
||||
ExpressionTypingContext.newContext(
|
||||
trace, scopeForDestructuring, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE
|
||||
)
|
||||
);
|
||||
|
||||
modifiersChecker.withTrace(trace).checkModifiersForDestructuringDeclaration(destructuringDeclaration);
|
||||
return result;
|
||||
}
|
||||
modifiersChecker.withTrace(trace).checkModifiersForDestructuringDeclaration(destructuringDeclaration);
|
||||
return result;
|
||||
};
|
||||
}
|
||||
else {
|
||||
@@ -460,17 +455,14 @@ public class DescriptorResolver {
|
||||
KtPsiUtil.safeName(typeParameter.getName()),
|
||||
index,
|
||||
KotlinSourceElementKt.toSourceElement(typeParameter),
|
||||
new Function1<KotlinType, Void>() {
|
||||
@Override
|
||||
public Void invoke(KotlinType type) {
|
||||
if (!(containingDescriptor instanceof TypeAliasDescriptor)) {
|
||||
trace.report(Errors.CYCLIC_GENERIC_UPPER_BOUND.on(typeParameter));
|
||||
}
|
||||
return null;
|
||||
type -> {
|
||||
if (!(containingDescriptor instanceof TypeAliasDescriptor)) {
|
||||
trace.report(Errors.CYCLIC_GENERIC_UPPER_BOUND.on(typeParameter));
|
||||
}
|
||||
return null;
|
||||
},
|
||||
supertypeLoopsResolver
|
||||
);
|
||||
);
|
||||
trace.record(BindingContext.TYPE_PARAMETER, typeParameter, typeParameterDescriptor);
|
||||
return typeParameterDescriptor;
|
||||
}
|
||||
@@ -761,21 +753,11 @@ public class DescriptorResolver {
|
||||
typeAliasDescriptor.initialize(
|
||||
typeParameterDescriptors,
|
||||
storageManager.createRecursionTolerantLazyValue(
|
||||
new Function0<SimpleType>() {
|
||||
@Override
|
||||
public SimpleType invoke() {
|
||||
return typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace);
|
||||
}
|
||||
},
|
||||
() -> typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace),
|
||||
ErrorUtils.createErrorType("Recursive type alias expansion for " + typeAliasDescriptor.getName().asString())
|
||||
),
|
||||
storageManager.createRecursionTolerantLazyValue(
|
||||
new Function0<SimpleType>() {
|
||||
@Override
|
||||
public SimpleType invoke() {
|
||||
return typeResolver.resolveExpandedTypeForTypeAlias(typeAliasDescriptor);
|
||||
}
|
||||
},
|
||||
() -> typeResolver.resolveExpandedTypeForTypeAlias(typeAliasDescriptor),
|
||||
ErrorUtils.createErrorType("Recursive type alias expansion for " + typeAliasDescriptor.getName().asString())
|
||||
)
|
||||
);
|
||||
@@ -817,12 +799,8 @@ public class DescriptorResolver {
|
||||
|
||||
Annotations allAnnotations = annotationResolver.resolveAnnotationsWithoutArguments(scopeForDeclarationResolution, modifierList, trace);
|
||||
AnnotationSplitter annotationSplitter =
|
||||
new AnnotationSplitter(storageManager, allAnnotations, new Function0<Set<AnnotationUseSiteTarget>>() {
|
||||
@Override
|
||||
public Set<AnnotationUseSiteTarget> invoke() {
|
||||
return AnnotationSplitter.getTargetSet(false, trace.getBindingContext(), wrapper);
|
||||
}
|
||||
});
|
||||
new AnnotationSplitter(storageManager, allAnnotations,
|
||||
() -> AnnotationSplitter.getTargetSet(false, trace.getBindingContext(), wrapper));
|
||||
|
||||
Annotations propertyAnnotations = new CompositeAnnotations(CollectionsKt.listOf(
|
||||
annotationSplitter.getAnnotationsForTargets(PROPERTY, FIELD, PROPERTY_DELEGATE_FIELD),
|
||||
@@ -1117,16 +1095,13 @@ public class DescriptorResolver {
|
||||
@NotNull KtDeclarationWithBody function,
|
||||
@NotNull FunctionDescriptor functionDescriptor
|
||||
) {
|
||||
return wrappedTypeFactory.createRecursionIntolerantDeferredType(trace, new Function0<KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke() {
|
||||
PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace);
|
||||
KotlinType type = expressionTypingServices.getBodyExpressionType(
|
||||
trace, scope, dataFlowInfo, function, functionDescriptor);
|
||||
KotlinType result = transformAnonymousTypeIfNeeded(functionDescriptor, function, type, trace);
|
||||
functionsTypingVisitor.checkTypesForReturnStatements(function, trace, result);
|
||||
return result;
|
||||
}
|
||||
return wrappedTypeFactory.createRecursionIntolerantDeferredType(trace, () -> {
|
||||
PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace);
|
||||
KotlinType type = expressionTypingServices.getBodyExpressionType(
|
||||
trace, scope, dataFlowInfo, function, functionDescriptor);
|
||||
KotlinType result = transformAnonymousTypeIfNeeded(functionDescriptor, function, type, trace);
|
||||
functionsTypingVisitor.checkTypesForReturnStatements(function, trace, result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1152,12 +1127,8 @@ public class DescriptorResolver {
|
||||
AnnotationSplitter.PropertyWrapper propertyWrapper = new AnnotationSplitter.PropertyWrapper(parameter);
|
||||
Annotations allAnnotations = annotationResolver.resolveAnnotationsWithoutArguments(scope, parameter.getModifierList(), trace);
|
||||
AnnotationSplitter annotationSplitter =
|
||||
new AnnotationSplitter(storageManager, allAnnotations, new Function0<Set<AnnotationUseSiteTarget>>() {
|
||||
@Override
|
||||
public Set<AnnotationUseSiteTarget> invoke() {
|
||||
return AnnotationSplitter.getTargetSet(true, trace.getBindingContext(), propertyWrapper);
|
||||
}
|
||||
});
|
||||
new AnnotationSplitter(storageManager, allAnnotations,
|
||||
() -> AnnotationSplitter.getTargetSet(true, trace.getBindingContext(), propertyWrapper));
|
||||
|
||||
Annotations propertyAnnotations = new CompositeAnnotations(
|
||||
annotationSplitter.getAnnotationsForTargets(PROPERTY, FIELD),
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.resolve;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
@@ -66,31 +65,29 @@ public class FunctionDescriptorUtil {
|
||||
@NotNull FunctionDescriptor descriptor,
|
||||
@NotNull LocalRedeclarationChecker redeclarationChecker
|
||||
) {
|
||||
ReceiverParameterDescriptor receiver = descriptor.getExtensionReceiverParameter();
|
||||
|
||||
return new LexicalScopeImpl(outerScope, descriptor, true, receiver, LexicalScopeKind.FUNCTION_INNER_SCOPE, redeclarationChecker,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
|
||||
handler.addClassifierDescriptor(typeParameter);
|
||||
}
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : descriptor.getValueParameters()) {
|
||||
if (valueParameterDescriptor instanceof ValueParameterDescriptorImpl.WithDestructuringDeclaration) {
|
||||
List<VariableDescriptor> entries =
|
||||
((ValueParameterDescriptorImpl.WithDestructuringDeclaration) valueParameterDescriptor)
|
||||
.getDestructuringVariables();
|
||||
for (VariableDescriptor entry : entries) {
|
||||
handler.addVariableDescriptor(entry);
|
||||
}
|
||||
}
|
||||
else {
|
||||
handler.addVariableDescriptor(valueParameterDescriptor);
|
||||
}
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
});
|
||||
return new LexicalScopeImpl(
|
||||
outerScope, descriptor, true, descriptor.getExtensionReceiverParameter(),
|
||||
LexicalScopeKind.FUNCTION_INNER_SCOPE, redeclarationChecker,
|
||||
handler -> {
|
||||
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
|
||||
handler.addClassifierDescriptor(typeParameter);
|
||||
}
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : descriptor.getValueParameters()) {
|
||||
if (valueParameterDescriptor instanceof ValueParameterDescriptorImpl.WithDestructuringDeclaration) {
|
||||
List<VariableDescriptor> entries =
|
||||
((ValueParameterDescriptorImpl.WithDestructuringDeclaration) valueParameterDescriptor)
|
||||
.getDestructuringVariables();
|
||||
for (VariableDescriptor entry : entries) {
|
||||
handler.addVariableDescriptor(entry);
|
||||
}
|
||||
}
|
||||
else {
|
||||
handler.addVariableDescriptor(valueParameterDescriptor);
|
||||
}
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.resolve.calls;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import kotlin.Pair;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
|
||||
@@ -181,14 +180,9 @@ public class CallResolver {
|
||||
@NotNull TracingStrategy tracing,
|
||||
@NotNull NewResolutionOldInference.ResolutionKind<D> kind
|
||||
) {
|
||||
return callResolvePerfCounter.time(new Function0<OverloadResolutionResults<D>>() {
|
||||
@Override
|
||||
public OverloadResolutionResults<D> invoke() {
|
||||
ResolutionTask<D> resolutionTask = new ResolutionTask<D>(
|
||||
kind, name, null
|
||||
);
|
||||
return doResolveCallOrGetCachedResults(context, resolutionTask, tracing);
|
||||
}
|
||||
return callResolvePerfCounter.<OverloadResolutionResults<D>>time(() -> {
|
||||
ResolutionTask<D> resolutionTask = new ResolutionTask<>(kind, name, null);
|
||||
return doResolveCallOrGetCachedResults(context, resolutionTask, tracing);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -208,14 +202,11 @@ public class CallResolver {
|
||||
@NotNull Collection<ResolutionCandidate<D>> candidates,
|
||||
@NotNull TracingStrategy tracing
|
||||
) {
|
||||
return callResolvePerfCounter.time(new Function0<OverloadResolutionResults<D>>() {
|
||||
@Override
|
||||
public OverloadResolutionResults<D> invoke() {
|
||||
ResolutionTask<D> resolutionTask = new ResolutionTask<D>(
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates<D>(), null, candidates
|
||||
);
|
||||
return doResolveCallOrGetCachedResults(context, resolutionTask, tracing);
|
||||
}
|
||||
return callResolvePerfCounter.<OverloadResolutionResults<D>>time(() -> {
|
||||
ResolutionTask<D> resolutionTask = new ResolutionTask<>(
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates<>(), null, candidates
|
||||
);
|
||||
return doResolveCallOrGetCachedResults(context, resolutionTask, tracing);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -498,22 +489,18 @@ public class CallResolver {
|
||||
@NotNull ResolutionCandidate<FunctionDescriptor> candidate,
|
||||
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
|
||||
) {
|
||||
return callResolvePerfCounter.time(new Function0<OverloadResolutionResults<FunctionDescriptor>>() {
|
||||
@Override
|
||||
public OverloadResolutionResults<FunctionDescriptor> invoke() {
|
||||
BasicCallResolutionContext basicCallResolutionContext =
|
||||
BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments);
|
||||
return callResolvePerfCounter.<OverloadResolutionResults<FunctionDescriptor>>time(() -> {
|
||||
BasicCallResolutionContext basicCallResolutionContext =
|
||||
BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments);
|
||||
|
||||
Set<ResolutionCandidate<FunctionDescriptor>> candidates = Collections.singleton(candidate);
|
||||
Set<ResolutionCandidate<FunctionDescriptor>> candidates = Collections.singleton(candidate);
|
||||
|
||||
ResolutionTask<FunctionDescriptor> resolutionTask =
|
||||
new ResolutionTask<FunctionDescriptor>(
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates<FunctionDescriptor>(), null, candidates
|
||||
);
|
||||
ResolutionTask<FunctionDescriptor> resolutionTask =
|
||||
new ResolutionTask<FunctionDescriptor>(
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates<FunctionDescriptor>(), null, candidates
|
||||
);
|
||||
|
||||
|
||||
return doResolveCallOrGetCachedResults(basicCallResolutionContext, resolutionTask, tracing);
|
||||
}
|
||||
return doResolveCallOrGetCachedResults(basicCallResolutionContext, resolutionTask, tracing);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+1
-6
@@ -70,12 +70,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
|
||||
@NotNull
|
||||
public final Function1<KtExpression, KtExpression> expressionContextProvider;
|
||||
|
||||
public static final Function1<KtExpression, KtExpression> DEFAULT_EXPRESSION_CONTEXT_PROVIDER = new Function1<KtExpression, KtExpression>() {
|
||||
@Override
|
||||
public KtExpression invoke(KtExpression expression) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
public static final Function1<KtExpression, KtExpression> DEFAULT_EXPRESSION_CONTEXT_PROVIDER = expression -> null;
|
||||
|
||||
protected ResolutionContext(
|
||||
@NotNull BindingTrace trace,
|
||||
|
||||
+3
-16
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.calls.inference;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
@@ -96,15 +95,8 @@ public class ConstraintsUtil {
|
||||
KotlinType type = constraintSystem.getTypeBounds(typeVariable).getValue();
|
||||
if (type == null) return true;
|
||||
|
||||
List<TypeParameterDescriptor> typeParametersUsedInSystem = CollectionsKt.map(
|
||||
constraintSystem.getTypeVariables(),
|
||||
new Function1<TypeVariable, TypeParameterDescriptor>() {
|
||||
@Override
|
||||
public TypeParameterDescriptor invoke(TypeVariable variable) {
|
||||
return variable.getOriginalTypeParameter();
|
||||
}
|
||||
}
|
||||
);
|
||||
List<TypeParameterDescriptor> typeParametersUsedInSystem =
|
||||
CollectionsKt.map(constraintSystem.getTypeVariables(), TypeVariable::getOriginalTypeParameter);
|
||||
|
||||
for (KotlinType upperBound : typeParameter.getUpperBounds()) {
|
||||
if (!substituteOtherTypeParametersInBound &&
|
||||
@@ -131,12 +123,7 @@ public class ConstraintsUtil {
|
||||
interestingMethods.add(method);
|
||||
}
|
||||
}
|
||||
Collections.sort(interestingMethods, new Comparator<Method>() {
|
||||
@Override
|
||||
public int compare(@NotNull Method method1, @NotNull Method method2) {
|
||||
return method1.getName().compareTo(method2.getName());
|
||||
}
|
||||
});
|
||||
Collections.sort(interestingMethods, Comparator.comparing(Method::getName));
|
||||
for (Iterator<Method> iterator = interestingMethods.iterator(); iterator.hasNext(); ) {
|
||||
Method method = iterator.next();
|
||||
try {
|
||||
|
||||
+2
-7
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.diagnostics;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.ModificationTracker;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.FilteringIterator;
|
||||
@@ -49,12 +48,8 @@ public class DiagnosticsWithSuppression implements Diagnostics {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<Diagnostic> iterator() {
|
||||
return new FilteringIterator<Diagnostic, Diagnostic>(diagnostics.iterator(), new Condition<Diagnostic>() {
|
||||
@Override
|
||||
public boolean value(Diagnostic diagnostic) {
|
||||
return kotlinSuppressCache.getFilter().invoke(diagnostic);
|
||||
}
|
||||
});
|
||||
return new FilteringIterator<Diagnostic, Diagnostic>(diagnostics.iterator(),
|
||||
diagnostic -> kotlinSuppressCache.getFilter().invoke(diagnostic));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.resolve.lazy;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -36,7 +35,6 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.*;
|
||||
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.KtClassLikeInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.KtClassOrObjectInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.KtScriptInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||
@@ -165,14 +163,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
this.trace = lockBasedLazyResolveStorageManager.createSafeTrace(delegationTrace);
|
||||
this.module = rootDescriptor;
|
||||
|
||||
this.packages =
|
||||
storageManager.createMemoizedFunctionWithNullableValues(new Function1<FqName, LazyPackageDescriptor>() {
|
||||
@Override
|
||||
@Nullable
|
||||
public LazyPackageDescriptor invoke(FqName fqName) {
|
||||
return createPackage(fqName);
|
||||
}
|
||||
});
|
||||
this.packages = storageManager.createMemoizedFunctionWithNullableValues(this::createPackage);
|
||||
|
||||
this.declarationProviderFactory = declarationProviderFactory;
|
||||
|
||||
@@ -196,19 +187,9 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
}
|
||||
};
|
||||
|
||||
fileAnnotations = storageManager.createMemoizedFunction(new Function1<KtFile, LazyAnnotations>() {
|
||||
@Override
|
||||
public LazyAnnotations invoke(KtFile file) {
|
||||
return createAnnotations(file, file.getAnnotationEntries());
|
||||
}
|
||||
});
|
||||
fileAnnotations = storageManager.createMemoizedFunction(file -> createAnnotations(file, file.getAnnotationEntries()));
|
||||
|
||||
danglingAnnotations = storageManager.createMemoizedFunction(new Function1<KtFile, LazyAnnotations>() {
|
||||
@Override
|
||||
public LazyAnnotations invoke(KtFile file) {
|
||||
return createAnnotations(file, file.getDanglingAnnotations());
|
||||
}
|
||||
});
|
||||
danglingAnnotations = storageManager.createMemoizedFunction(file -> createAnnotations(file, file.getDanglingAnnotations()));
|
||||
|
||||
syntheticResolveExtension = SyntheticResolveExtension.Companion.getInstance(project);
|
||||
}
|
||||
@@ -271,33 +252,25 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
|
||||
result.addAll(ContainerUtil.mapNotNull(
|
||||
provider.getClassOrObjectDeclarations(fqName.shortName()),
|
||||
new Function<KtClassLikeInfo, ClassifierDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor fun(KtClassLikeInfo classLikeInfo) {
|
||||
if (classLikeInfo instanceof KtClassOrObjectInfo) {
|
||||
//noinspection RedundantCast
|
||||
return getClassDescriptor(((KtClassOrObjectInfo) classLikeInfo).getCorrespondingClassOrObject(), location);
|
||||
}
|
||||
else if (classLikeInfo instanceof KtScriptInfo) {
|
||||
return getScriptDescriptor(((KtScriptInfo) classLikeInfo).getScript());
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"Unexpected " + classLikeInfo + " of type " + classLikeInfo.getClass().getName()
|
||||
);
|
||||
}
|
||||
classLikeInfo -> {
|
||||
if (classLikeInfo instanceof KtClassOrObjectInfo) {
|
||||
//noinspection RedundantCast
|
||||
return getClassDescriptor(((KtClassOrObjectInfo) classLikeInfo).getCorrespondingClassOrObject(), location);
|
||||
}
|
||||
else if (classLikeInfo instanceof KtScriptInfo) {
|
||||
return getScriptDescriptor(((KtScriptInfo) classLikeInfo).getScript());
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"Unexpected " + classLikeInfo + " of type " + classLikeInfo.getClass().getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
result.addAll(ContainerUtil.map(
|
||||
provider.getTypeAliasDeclarations(fqName.shortName()),
|
||||
new Function<KtTypeAlias, ClassifierDescriptor>() {
|
||||
@Override
|
||||
public ClassifierDescriptor fun(KtTypeAlias alias) {
|
||||
return (ClassifierDescriptor) lazyDeclarationResolver.resolveToDescriptor(alias);
|
||||
}
|
||||
}
|
||||
alias -> (ClassifierDescriptor) lazyDeclarationResolver.resolveToDescriptor(alias)
|
||||
));
|
||||
|
||||
return result;
|
||||
|
||||
+1
-7
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.lazy.declarations;
|
||||
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
@@ -29,12 +28,7 @@ public abstract class AbstractDeclarationProviderFactory implements DeclarationP
|
||||
|
||||
public AbstractDeclarationProviderFactory(@NotNull StorageManager storageManager) {
|
||||
this.packageDeclarationProviders =
|
||||
storageManager.createMemoizedFunctionWithNullableValues(new Function1<FqName, PackageMemberDeclarationProvider>() {
|
||||
@Override
|
||||
public PackageMemberDeclarationProvider invoke(FqName fqName) {
|
||||
return createPackageMemberDeclarationProvider(fqName);
|
||||
}
|
||||
});
|
||||
storageManager.createMemoizedFunctionWithNullableValues(this::createPackageMemberDeclarationProvider);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-7
@@ -20,7 +20,6 @@ import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
@@ -45,12 +44,7 @@ public class FileBasedDeclarationProviderFactory extends AbstractDeclarationProv
|
||||
public FileBasedDeclarationProviderFactory(@NotNull StorageManager storageManager, @NotNull Collection<KtFile> files) {
|
||||
super(storageManager);
|
||||
this.storageManager = storageManager;
|
||||
this.index = storageManager.createLazyValue(new Function0<Index>() {
|
||||
@Override
|
||||
public Index invoke() {
|
||||
return computeFilesByPackage(files);
|
||||
}
|
||||
});
|
||||
this.index = storageManager.createLazyValue(() -> computeFilesByPackage(files));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+48
-105
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.lazy.descriptors;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -142,24 +141,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
KtModifierList modifierList = classLikeInfo.getModifierList();
|
||||
if (kind.isSingleton()) {
|
||||
this.modality = storageManager.createLazyValue(new Function0<Modality>() {
|
||||
@Override
|
||||
public Modality invoke() {
|
||||
return Modality.FINAL;
|
||||
}
|
||||
});
|
||||
this.modality = storageManager.createLazyValue(() -> Modality.FINAL);
|
||||
}
|
||||
else {
|
||||
Modality defaultModality = kind == ClassKind.INTERFACE ? Modality.ABSTRACT : Modality.FINAL;
|
||||
this.modality = storageManager.createLazyValue(new Function0<Modality>() {
|
||||
@Override
|
||||
public Modality invoke() {
|
||||
return resolveModalityFromModifiers(classOrObject, defaultModality,
|
||||
c.getTrace().getBindingContext(),
|
||||
null,
|
||||
/* allowSealed = */ true);
|
||||
}
|
||||
});
|
||||
this.modality = storageManager.createLazyValue(
|
||||
() -> resolveModalityFromModifiers(classOrObject, defaultModality, c.getTrace().getBindingContext(),
|
||||
null, /* allowSealed = */ true));
|
||||
}
|
||||
|
||||
boolean isLocal = classOrObject != null && KtPsiUtil.isLocal(classOrObject);
|
||||
@@ -227,76 +215,49 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
);
|
||||
}
|
||||
|
||||
this.companionObjectDescriptor = storageManager.createNullableLazyValue(new Function0<ClassDescriptorWithResolutionScopes>() {
|
||||
@Override
|
||||
public ClassDescriptorWithResolutionScopes invoke() {
|
||||
return computeCompanionObjectDescriptor(getCompanionObjectIfAllowed());
|
||||
}
|
||||
});
|
||||
this.extraCompanionObjectDescriptors = storageManager.createMemoizedFunction(new Function1<KtObjectDeclaration, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(KtObjectDeclaration companionObject) {
|
||||
return computeCompanionObjectDescriptor(companionObject);
|
||||
}
|
||||
});
|
||||
this.forceResolveAllContents = storageManager.createRecursionTolerantNullableLazyValue(new Function0<Void>() {
|
||||
@Override
|
||||
public Void invoke() {
|
||||
doForceResolveAllContents();
|
||||
return null;
|
||||
}
|
||||
this.companionObjectDescriptor = storageManager.createNullableLazyValue(
|
||||
() -> computeCompanionObjectDescriptor(getCompanionObjectIfAllowed())
|
||||
);
|
||||
this.extraCompanionObjectDescriptors = storageManager.createMemoizedFunction(this::computeCompanionObjectDescriptor);
|
||||
this.forceResolveAllContents = storageManager.createRecursionTolerantNullableLazyValue(() -> {
|
||||
doForceResolveAllContents();
|
||||
return null;
|
||||
}, null);
|
||||
|
||||
this.resolutionScopesSupport = new ClassResolutionScopesSupport(this, storageManager, new Function0<LexicalScope>() {
|
||||
@Override
|
||||
public LexicalScope invoke() {
|
||||
return getOuterScope();
|
||||
this.resolutionScopesSupport = new ClassResolutionScopesSupport(this, storageManager, this::getOuterScope);
|
||||
|
||||
this.parameters = c.getStorageManager().createLazyValue(() -> {
|
||||
KtClassLikeInfo classInfo = declarationProvider.getOwnerInfo();
|
||||
KtTypeParameterList typeParameterList = classInfo.getTypeParameterList();
|
||||
if (typeParameterList == null) return Collections.emptyList();
|
||||
|
||||
if (classInfo.getClassKind() == ClassKind.ENUM_CLASS) {
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_ENUM.on(typeParameterList));
|
||||
}
|
||||
if (classInfo.getClassKind() == ClassKind.OBJECT) {
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_OBJECT.on(typeParameterList));
|
||||
}
|
||||
|
||||
List<KtTypeParameter> typeParameters = typeParameterList.getParameters();
|
||||
if (typeParameters.isEmpty()) return Collections.emptyList();
|
||||
|
||||
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>(typeParameters.size());
|
||||
|
||||
for (int i = 0; i < typeParameters.size(); i++) {
|
||||
parameters.add(new LazyTypeParameterDescriptor(c, this, typeParameters.get(i), i));
|
||||
}
|
||||
|
||||
return parameters;
|
||||
});
|
||||
|
||||
this.parameters = c.getStorageManager().createLazyValue(new Function0<List<TypeParameterDescriptor>>() {
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> invoke() {
|
||||
KtClassLikeInfo classInfo = declarationProvider.getOwnerInfo();
|
||||
KtTypeParameterList typeParameterList = classInfo.getTypeParameterList();
|
||||
if (typeParameterList == null) return Collections.emptyList();
|
||||
this.scopeForInitializerResolution = storageManager.createLazyValue(
|
||||
() -> ClassResolutionScopesSupportKt.scopeForInitializerResolution(
|
||||
this, createInitializerScopeParent(), classLikeInfo.getPrimaryConstructorParameters()
|
||||
)
|
||||
);
|
||||
|
||||
if (classInfo.getClassKind() == ClassKind.ENUM_CLASS) {
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_ENUM.on(typeParameterList));
|
||||
}
|
||||
if (classInfo.getClassKind() == ClassKind.OBJECT) {
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_OBJECT.on(typeParameterList));
|
||||
}
|
||||
|
||||
List<KtTypeParameter> typeParameters = typeParameterList.getParameters();
|
||||
if (typeParameters.isEmpty()) return Collections.emptyList();
|
||||
|
||||
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>(typeParameters.size());
|
||||
|
||||
for (int i = 0; i < typeParameters.size(); i++) {
|
||||
parameters.add(new LazyTypeParameterDescriptor(c, LazyClassDescriptor.this, typeParameters.get(i), i));
|
||||
}
|
||||
|
||||
return parameters;
|
||||
}
|
||||
});
|
||||
|
||||
this.scopeForInitializerResolution = storageManager.createLazyValue(new Function0<LexicalScope>() {
|
||||
@Override
|
||||
public LexicalScope invoke() {
|
||||
return ClassResolutionScopesSupportKt.scopeForInitializerResolution(LazyClassDescriptor.this,
|
||||
createInitializerScopeParent(),
|
||||
classLikeInfo.getPrimaryConstructorParameters());
|
||||
}
|
||||
});
|
||||
|
||||
this.sealedSubclasses = storageManager.createLazyValue(new Function0<Collection<ClassDescriptor>>() {
|
||||
@Override
|
||||
public Collection<ClassDescriptor> invoke() {
|
||||
// TODO: only consider classes from the same file, not the whole package fragment
|
||||
return DescriptorUtilsKt.computeSealedSubclasses(LazyClassDescriptor.this);
|
||||
}
|
||||
});
|
||||
// TODO: only consider classes from the same file, not the whole package fragment
|
||||
this.sealedSubclasses = storageManager.createLazyValue(() -> DescriptorUtilsKt.computeSealedSubclasses(this));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -390,13 +351,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
//noinspection unchecked
|
||||
return (Collection) CollectionsKt.filter(
|
||||
DescriptorUtils.getAllDescriptors(unsubstitutedMemberScope),
|
||||
new Function1<DeclarationDescriptor, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(DeclarationDescriptor descriptor) {
|
||||
return descriptor instanceof CallableMemberDescriptor
|
||||
&& ((CallableMemberDescriptor) descriptor).getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE;
|
||||
}
|
||||
}
|
||||
descriptor -> descriptor instanceof CallableMemberDescriptor
|
||||
&& ((CallableMemberDescriptor) descriptor).getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE
|
||||
);
|
||||
}
|
||||
|
||||
@@ -436,19 +392,9 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
return CollectionsKt.map(
|
||||
CollectionsKt.filter(
|
||||
declarationProvider.getOwnerInfo().getCompanionObjects(),
|
||||
new Function1<KtObjectDeclaration, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(KtObjectDeclaration companionObject) {
|
||||
return companionObject != allowedCompanionObject;
|
||||
}
|
||||
}
|
||||
companionObject -> companionObject != allowedCompanionObject
|
||||
),
|
||||
new Function1<KtObjectDeclaration, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(KtObjectDeclaration companionObject) {
|
||||
return extraCompanionObjectDescriptors.invoke(companionObject);
|
||||
}
|
||||
}
|
||||
extraCompanionObjectDescriptors
|
||||
);
|
||||
}
|
||||
|
||||
@@ -623,12 +569,9 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
private class LazyClassTypeConstructor extends AbstractClassTypeConstructor {
|
||||
private final NotNullLazyValue<List<TypeParameterDescriptor>> parameters = c.getStorageManager().createLazyValue(new Function0<List<TypeParameterDescriptor>>() {
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> invoke() {
|
||||
return TypeParameterUtilsKt.computeConstructorTypeParameters(LazyClassDescriptor.this);
|
||||
}
|
||||
});
|
||||
private final NotNullLazyValue<List<TypeParameterDescriptor>> parameters = c.getStorageManager().createLazyValue(
|
||||
() -> TypeParameterUtilsKt.computeConstructorTypeParameters(LazyClassDescriptor.this)
|
||||
);
|
||||
|
||||
public LazyClassTypeConstructor() {
|
||||
super(LazyClassDescriptor.this.c.getStorageManager());
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.types;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
@@ -31,13 +29,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BoundsSubstitutor {
|
||||
private static final Function<TypeProjection,KotlinType> PROJECTIONS_TO_TYPES = new Function<TypeProjection, KotlinType>() {
|
||||
@Override
|
||||
public KotlinType apply(TypeProjection projection) {
|
||||
return projection.getType();
|
||||
}
|
||||
};
|
||||
|
||||
private BoundsSubstitutor() {
|
||||
}
|
||||
|
||||
@@ -79,14 +70,8 @@ public class BoundsSubstitutor {
|
||||
// In the end, we want every parameter to have no references to those after it in the list
|
||||
// This gives us the reversed order: the one that refers to everybody else comes first
|
||||
List<TypeParameterDescriptor> topOrder = DFS.topologicalOrder(
|
||||
typeParameters,
|
||||
new DFS.Neighbors<TypeParameterDescriptor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterable<TypeParameterDescriptor> getNeighbors(TypeParameterDescriptor current) {
|
||||
return getTypeParametersFromUpperBounds(current, typeParameters);
|
||||
}
|
||||
});
|
||||
typeParameters, current -> getTypeParametersFromUpperBounds(current, typeParameters)
|
||||
);
|
||||
|
||||
assert topOrder.size() == typeParameters.size() : "All type parameters must be visited, but only " + topOrder + " were";
|
||||
|
||||
@@ -102,13 +87,7 @@ public class BoundsSubstitutor {
|
||||
) {
|
||||
return DFS.dfs(
|
||||
current.getUpperBounds(),
|
||||
new DFS.Neighbors<KotlinType>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterable<KotlinType> getNeighbors(KotlinType current) {
|
||||
return Collections2.transform(current.getArguments(), PROJECTIONS_TO_TYPES);
|
||||
}
|
||||
},
|
||||
typeParameter -> CollectionsKt.map(typeParameter.getArguments(), TypeProjection::getType),
|
||||
new DFS.NodeHandlerWithListResult<KotlinType, TypeParameterDescriptor>() {
|
||||
@Override
|
||||
public boolean beforeChildren(KotlinType current) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.types;
|
||||
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -68,15 +67,12 @@ public class CommonSupertypes {
|
||||
}
|
||||
|
||||
private static int depth(@NotNull KotlinType type) {
|
||||
return 1 + maxDepth(CollectionsKt.map(type.getArguments(), new Function1<TypeProjection, KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke(TypeProjection projection) {
|
||||
if (projection.isStarProjection()) {
|
||||
// any type is good enough for depth here
|
||||
return type.getConstructor().getBuiltIns().getAnyType();
|
||||
}
|
||||
return projection.getType();
|
||||
return 1 + maxDepth(CollectionsKt.map(type.getArguments(), projection -> {
|
||||
if (projection.isStarProjection()) {
|
||||
// any type is good enough for depth here
|
||||
return type.getConstructor().getBuiltIns().getAnyType();
|
||||
}
|
||||
return projection.getType();
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -336,28 +332,19 @@ public class CommonSupertypes {
|
||||
) {
|
||||
return DFS.dfs(
|
||||
Collections.singletonList(type),
|
||||
new DFS.Neighbors<SimpleType>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterable<? extends SimpleType> getNeighbors(SimpleType current) {
|
||||
TypeSubstitutor substitutor = TypeSubstitutor.create(current);
|
||||
Collection<KotlinType> supertypes = current.getConstructor().getSupertypes();
|
||||
List<SimpleType> result = new ArrayList<SimpleType>(supertypes.size());
|
||||
for (KotlinType supertype : supertypes) {
|
||||
if (visited.contains(supertype.getConstructor())) {
|
||||
continue;
|
||||
}
|
||||
result.add(FlexibleTypesKt.lowerIfFlexible(substitutor.safeSubstitute(supertype, Variance.INVARIANT)));
|
||||
current -> {
|
||||
TypeSubstitutor substitutor = TypeSubstitutor.create(current);
|
||||
Collection<KotlinType> supertypes = current.getConstructor().getSupertypes();
|
||||
List<SimpleType> result = new ArrayList<SimpleType>(supertypes.size());
|
||||
for (KotlinType supertype : supertypes) {
|
||||
if (visited.contains(supertype.getConstructor())) {
|
||||
continue;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
},
|
||||
new DFS.Visited<SimpleType>() {
|
||||
@Override
|
||||
public boolean checkAndMarkVisited(SimpleType current) {
|
||||
return visited.add(current.getConstructor());
|
||||
result.add(FlexibleTypesKt.lowerIfFlexible(substitutor.safeSubstitute(supertype, Variance.INVARIANT)));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
current -> visited.add(current.getConstructor()),
|
||||
new DFS.NodeHandlerWithListResult<SimpleType, TypeConstructor>() {
|
||||
@Override
|
||||
public boolean beforeChildren(SimpleType current) {
|
||||
|
||||
@@ -28,20 +28,9 @@ import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.DEFERRED_TYPE;
|
||||
|
||||
public class DeferredType extends WrappedType {
|
||||
|
||||
private static final Function1 EMPTY_CONSUMER = new Function1<Object, Void>() {
|
||||
@Override
|
||||
public Void invoke(Object t) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
private static final Function1<Boolean,KotlinType> RECURSION_PREVENTER = new Function1<Boolean, KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke(Boolean firstTime) {
|
||||
if (firstTime) throw new ReenteringLazyValueComputationException();
|
||||
return ErrorUtils.createErrorType("Recursive dependency");
|
||||
}
|
||||
private static final Function1<Boolean, KotlinType> RECURSION_PREVENTER = firstTime -> {
|
||||
if (firstTime) throw new ReenteringLazyValueComputationException();
|
||||
return ErrorUtils.createErrorType("Recursive dependency");
|
||||
};
|
||||
|
||||
@NotNull
|
||||
@@ -62,11 +51,8 @@ public class DeferredType extends WrappedType {
|
||||
@NotNull Function0<KotlinType> compute
|
||||
) {
|
||||
//noinspection unchecked
|
||||
DeferredType deferredType = new DeferredType(storageManager.createLazyValueWithPostCompute(
|
||||
compute,
|
||||
RECURSION_PREVENTER,
|
||||
EMPTY_CONSUMER
|
||||
));
|
||||
DeferredType deferredType =
|
||||
new DeferredType(storageManager.createLazyValueWithPostCompute(compute, RECURSION_PREVENTER, t -> null));
|
||||
trace.record(DEFERRED_TYPE, new Box<DeferredType>(deferredType));
|
||||
return deferredType;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.CallHandle;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl;
|
||||
import org.jetbrains.kotlin.resolve.scopes.TypeIntersectionScope;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
|
||||
import java.util.*;
|
||||
@@ -174,17 +173,14 @@ public class TypeIntersector {
|
||||
private static boolean unify(KotlinType withParameters, KotlinType expected) {
|
||||
// T -> how T is used
|
||||
Map<TypeParameterDescriptor, Variance> parameters = new HashMap<TypeParameterDescriptor, Variance>();
|
||||
Function1<TypeParameterUsage, Unit> processor = new Function1<TypeParameterUsage, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(TypeParameterUsage parameterUsage) {
|
||||
Variance howTheTypeIsUsedBefore = parameters.get(parameterUsage.typeParameterDescriptor);
|
||||
if (howTheTypeIsUsedBefore == null) {
|
||||
howTheTypeIsUsedBefore = Variance.INVARIANT;
|
||||
}
|
||||
parameters.put(parameterUsage.typeParameterDescriptor,
|
||||
parameterUsage.howTheTypeParameterIsUsed.superpose(howTheTypeIsUsedBefore));
|
||||
return Unit.INSTANCE;
|
||||
Function1<TypeParameterUsage, Unit> processor = parameterUsage -> {
|
||||
Variance howTheTypeIsUsedBefore = parameters.get(parameterUsage.typeParameterDescriptor);
|
||||
if (howTheTypeIsUsedBefore == null) {
|
||||
howTheTypeIsUsedBefore = Variance.INVARIANT;
|
||||
}
|
||||
parameters.put(parameterUsage.typeParameterDescriptor,
|
||||
parameterUsage.howTheTypeParameterIsUsed.superpose(howTheTypeIsUsedBefore));
|
||||
return Unit.INSTANCE;
|
||||
};
|
||||
processAllTypeParameters(withParameters, Variance.INVARIANT, processor);
|
||||
processAllTypeParameters(expected, Variance.INVARIANT, processor);
|
||||
|
||||
+12
-45
@@ -23,8 +23,6 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import kotlin.TuplesKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.KtNodeTypes;
|
||||
@@ -73,7 +71,6 @@ import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.Resolv
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||
import org.jetbrains.kotlin.types.expressions.unqualifiedSuper.UnqualifiedSuperKt;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -720,30 +717,12 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
KotlinType[] result = new KotlinType[1];
|
||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace,
|
||||
"trace to resolve object literal expression", expression);
|
||||
ObservableBindingTrace.RecordHandler<PsiElement, ClassDescriptor> handler =
|
||||
new ObservableBindingTrace.RecordHandler<PsiElement, ClassDescriptor>() {
|
||||
|
||||
@Override
|
||||
public void handleRecord(
|
||||
WritableSlice<PsiElement, ClassDescriptor> slice,
|
||||
PsiElement declaration,
|
||||
ClassDescriptor descriptor
|
||||
) {
|
||||
if (slice == CLASS && declaration == expression.getObjectDeclaration()) {
|
||||
KotlinType defaultType = components.wrappedTypeFactory.createRecursionIntolerantDeferredType(
|
||||
context.trace,
|
||||
new Function0<KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke() {
|
||||
return descriptor.getDefaultType();
|
||||
}
|
||||
});
|
||||
result[0] = defaultType;
|
||||
}
|
||||
}
|
||||
};
|
||||
ObservableBindingTrace traceAdapter = new ObservableBindingTrace(temporaryTrace);
|
||||
traceAdapter.addHandler(CLASS, handler);
|
||||
traceAdapter.addHandler(CLASS, (slice, declaration, descriptor) -> {
|
||||
if (slice == CLASS && declaration == expression.getObjectDeclaration()) {
|
||||
result[0] = components.wrappedTypeFactory.createRecursionIntolerantDeferredType(context.trace, descriptor::getDefaultType);
|
||||
}
|
||||
});
|
||||
components.localClassifierAnalyzer.processClassOrObject(null, // don't need to add classifier of object literal to any scope
|
||||
context.replaceBindingTrace(traceAdapter)
|
||||
.replaceContextDependency(INDEPENDENT),
|
||||
@@ -1199,13 +1178,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
OverloadResolutionResults<FunctionDescriptor> resolutionResults =
|
||||
components.callResolver.resolveCallWithGivenName(newContext, call, operationSign, OperatorNameConventions.EQUALS);
|
||||
|
||||
traceInterpretingRightAsNullableAny.commit(new TraceEntryFilter() {
|
||||
@Override
|
||||
public boolean accept(@Nullable WritableSlice<?, ?> slice, Object key) {
|
||||
// the type of the right (and sometimes left) expression isn't 'Any?' actually
|
||||
if ((key == right || key == left) && slice == EXPRESSION_TYPE_INFO) return false;
|
||||
return true;
|
||||
}
|
||||
traceInterpretingRightAsNullableAny.commit((slice, key) -> {
|
||||
// the type of the right (and sometimes left) expression isn't 'Any?' actually
|
||||
if ((key == right || key == left) && slice == EXPRESSION_TYPE_INFO) return false;
|
||||
return true;
|
||||
}, true);
|
||||
|
||||
if (resolutionResults.isSuccess()) {
|
||||
@@ -1462,18 +1438,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
SenselessComparisonChecker.checkSenselessComparisonWithNull(
|
||||
expression, left, right, context,
|
||||
new Function1<KtExpression, KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke(KtExpression expression) {
|
||||
return facade.getTypeInfo(expression, context).getType();
|
||||
}
|
||||
},
|
||||
new Function1<DataFlowValue, Nullability>() {
|
||||
@Override
|
||||
public Nullability invoke(DataFlowValue value) {
|
||||
return context.dataFlowInfo.getStableNullability(value);
|
||||
}
|
||||
});
|
||||
expr -> facade.getTypeInfo(expr, context).getType(),
|
||||
context.dataFlowInfo::getStableNullability
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-6
@@ -111,12 +111,7 @@ public class ExpressionTypingServices {
|
||||
trace, scope, dataFlowInfo, expectedType, contextDependency, statementFilter
|
||||
);
|
||||
if (contextExpression != expression) {
|
||||
context = context.replaceExpressionContextProvider(new Function1<KtExpression, KtExpression>() {
|
||||
@Override
|
||||
public KtExpression invoke(KtExpression arg) {
|
||||
return arg == expression ? contextExpression : null;
|
||||
}
|
||||
});
|
||||
context = context.replaceExpressionContextProvider(arg -> arg == expression ? contextExpression : null);
|
||||
}
|
||||
return expressionTypingFacade.getTypeInfo(expression, context, isStatement);
|
||||
}
|
||||
|
||||
+48
-52
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.types.expressions;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils;
|
||||
@@ -169,64 +168,61 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
|
||||
|
||||
@NotNull
|
||||
private KotlinTypeInfo getTypeInfo(@NotNull KtExpression expression, ExpressionTypingContext context, KtVisitor<KotlinTypeInfo, ExpressionTypingContext> visitor) {
|
||||
return typeInfoPerfCounter.time(new Function0<KotlinTypeInfo>() {
|
||||
@Override
|
||||
public KotlinTypeInfo invoke() {
|
||||
return typeInfoPerfCounter.time(() -> {
|
||||
try {
|
||||
KotlinTypeInfo recordedTypeInfo = BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext());
|
||||
if (recordedTypeInfo != null) {
|
||||
return recordedTypeInfo;
|
||||
}
|
||||
|
||||
context.trace.record(BindingContext.DATA_FLOW_INFO_BEFORE, expression, context.dataFlowInfo);
|
||||
|
||||
KotlinTypeInfo result;
|
||||
try {
|
||||
KotlinTypeInfo recordedTypeInfo = BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext());
|
||||
if (recordedTypeInfo != null) {
|
||||
return recordedTypeInfo;
|
||||
result = expression.accept(visitor, context);
|
||||
// Some recursive definitions (object expressions) must put their types in the cache manually:
|
||||
//noinspection ConstantConditions
|
||||
if (context.trace.get(BindingContext.PROCESSED, expression) == Boolean.TRUE) {
|
||||
KotlinType type = context.trace.getBindingContext().getType(expression);
|
||||
return result.replaceType(type);
|
||||
}
|
||||
|
||||
context.trace.record(BindingContext.DATA_FLOW_INFO_BEFORE, expression, context.dataFlowInfo);
|
||||
|
||||
KotlinTypeInfo result;
|
||||
try {
|
||||
result = expression.accept(visitor, context);
|
||||
// Some recursive definitions (object expressions) must put their types in the cache manually:
|
||||
//noinspection ConstantConditions
|
||||
if (context.trace.get(BindingContext.PROCESSED, expression) == Boolean.TRUE) {
|
||||
KotlinType type = context.trace.getBindingContext().getType(expression);
|
||||
return result.replaceType(type);
|
||||
}
|
||||
|
||||
if (result.getType() instanceof DeferredType) {
|
||||
result = result.replaceType(((DeferredType) result.getType()).getDelegate());
|
||||
}
|
||||
context.trace.record(BindingContext.EXPRESSION_TYPE_INFO, expression, result);
|
||||
if (result.getType() instanceof DeferredType) {
|
||||
result = result.replaceType(((DeferredType) result.getType()).getDelegate());
|
||||
}
|
||||
catch (ReenteringLazyValueComputationException e) {
|
||||
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
|
||||
result = TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
|
||||
context.trace.record(BindingContext.PROCESSED, expression);
|
||||
|
||||
// todo save scope before analyze and fix debugger: see CodeFragmentAnalyzer.correctContextForExpression
|
||||
BindingContextUtilsKt.recordScope(context.trace, context.scope, expression);
|
||||
BindingContextUtilsKt.recordDataFlowInfo(context.replaceDataFlowInfo(result.getDataFlowInfo()), expression);
|
||||
try {
|
||||
// Here we have to resolve some types, so the following exception is possible
|
||||
// Example: val a = ::a, fun foo() = ::foo
|
||||
recordTypeInfo(expression, result);
|
||||
}
|
||||
catch (ReenteringLazyValueComputationException e) {
|
||||
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
|
||||
return TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
return result;
|
||||
context.trace.record(BindingContext.EXPRESSION_TYPE_INFO, expression, result);
|
||||
}
|
||||
catch (ProcessCanceledException | KotlinFrontEndException e) {
|
||||
throw e;
|
||||
catch (ReenteringLazyValueComputationException e) {
|
||||
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
|
||||
result = TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
context.trace.report(Errors.EXCEPTION_FROM_ANALYZER.on(expression, e));
|
||||
logOrThrowException(expression, e);
|
||||
return TypeInfoFactoryKt.createTypeInfo(
|
||||
ErrorUtils.createErrorType(e.getClass().getSimpleName() + " from analyzer"),
|
||||
context
|
||||
);
|
||||
|
||||
context.trace.record(BindingContext.PROCESSED, expression);
|
||||
|
||||
// todo save scope before analyze and fix debugger: see CodeFragmentAnalyzer.correctContextForExpression
|
||||
BindingContextUtilsKt.recordScope(context.trace, context.scope, expression);
|
||||
BindingContextUtilsKt.recordDataFlowInfo(context.replaceDataFlowInfo(result.getDataFlowInfo()), expression);
|
||||
try {
|
||||
// Here we have to resolve some types, so the following exception is possible
|
||||
// Example: val a = ::a, fun foo() = ::foo
|
||||
recordTypeInfo(expression, result);
|
||||
}
|
||||
catch (ReenteringLazyValueComputationException e) {
|
||||
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
|
||||
return TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (ProcessCanceledException | KotlinFrontEndException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
context.trace.report(Errors.EXCEPTION_FROM_ANALYZER.on(expression, e));
|
||||
logOrThrowException(expression, e);
|
||||
return TypeInfoFactoryKt.createTypeInfo(
|
||||
ErrorUtils.createErrorType(e.getClass().getSimpleName() + " from analyzer"),
|
||||
context
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,12 +54,9 @@ public class TrackingSlicedMap extends SlicedMapImpl {
|
||||
|
||||
@Override
|
||||
public void forEach(@NotNull Function3<WritableSlice, Object, Object, Void> f) {
|
||||
super.forEach(new Function3<WritableSlice, Object, Object, Void>() {
|
||||
@Override
|
||||
public Void invoke(WritableSlice slice, Object key, Object value) {
|
||||
f.invoke(((SliceWithStackTrace) slice).getWritableDelegate(), key, ((TrackableValue<?>) value).value);
|
||||
return null;
|
||||
}
|
||||
super.forEach((slice, key, value) -> {
|
||||
f.invoke(((SliceWithStackTrace) slice).getWritableDelegate(), key, ((TrackableValue<?>) value).value);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user