Fix most unchecked/deprecation javac warnings in compiler modules

This commit is contained in:
Alexander Udalov
2018-06-22 12:57:04 +02:00
parent 4f0c31eff3
commit f868964e25
64 changed files with 182 additions and 132 deletions
@@ -361,7 +361,7 @@ public abstract class AnnotationCodegen {
@NotNull ConstantValue<?> value, @NotNull ConstantValue<?> value,
@NotNull AnnotationVisitor annotationVisitor @NotNull AnnotationVisitor annotationVisitor
) { ) {
AnnotationArgumentVisitor argumentVisitor = new AnnotationArgumentVisitor<Void, Void>() { AnnotationArgumentVisitor<Void, Void> argumentVisitor = new AnnotationArgumentVisitor<Void, Void>() {
@Override @Override
public Void visitLongValue(@NotNull LongValue value, Void data) { public Void visitLongValue(@NotNull LongValue value, Void data) {
return visitSimpleValue(value); return visitSimpleValue(value);
@@ -2069,7 +2069,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
CallableMethod callableGetter = null; CallableMethod callableGetter = null;
CallableMethod callableSetter = null; CallableMethod callableSetter = null;
CodegenContext backingFieldContext = getBackingFieldContext(fieldAccessorKind, containingDeclaration); CodegenContext<?> backingFieldContext = getBackingFieldContext(fieldAccessorKind, containingDeclaration);
boolean isPrivateProperty = boolean isPrivateProperty =
fieldAccessorKind != AccessorKind.NORMAL && fieldAccessorKind != AccessorKind.NORMAL &&
(AsmUtil.getVisibilityForBackingField(propertyDescriptor, isDelegatedProperty) & ACC_PRIVATE) != 0; (AsmUtil.getVisibilityForBackingField(propertyDescriptor, isDelegatedProperty) & ACC_PRIVATE) != 0;
@@ -73,7 +73,7 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
public final GenerationState state; public final GenerationState state;
protected final T element; protected final T element;
protected final FieldOwnerContext context; protected final FieldOwnerContext<?> context;
public final ClassBuilder v; public final ClassBuilder v;
public final FunctionCodegen functionCodegen; public final FunctionCodegen functionCodegen;
@@ -25,15 +25,16 @@ import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor;
public class SamCodegenUtil { public class SamCodegenUtil {
@Nullable @Nullable
@SuppressWarnings("unchecked")
public static FunctionDescriptor getOriginalIfSamAdapter(@NotNull FunctionDescriptor fun) { public static FunctionDescriptor getOriginalIfSamAdapter(@NotNull FunctionDescriptor fun) {
if (fun instanceof SamAdapterDescriptor<?> || fun instanceof SamAdapterExtensionFunctionDescriptor) { if (fun instanceof SamAdapterDescriptor<?> || fun instanceof SamAdapterExtensionFunctionDescriptor) {
//noinspection unchecked
return ((SyntheticMemberDescriptor<FunctionDescriptor>) fun).getBaseDescriptorForSynthetic(); return ((SyntheticMemberDescriptor<FunctionDescriptor>) fun).getBaseDescriptorForSynthetic();
} }
return null; return null;
} }
@SuppressWarnings("unchecked")
public static <T extends FunctionDescriptor> T resolveSamAdapter(@NotNull T descriptor) { public static <T extends FunctionDescriptor> T resolveSamAdapter(@NotNull T descriptor) {
FunctionDescriptor original = getOriginalIfSamAdapter(descriptor); FunctionDescriptor original = getOriginalIfSamAdapter(descriptor);
return original != null ? (T) original : descriptor; return original != null ? (T) original : descriptor;
@@ -413,7 +413,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
return getAccessor(propertyDescriptor, AccessorKind.NORMAL, null, superCallTarget, getterAccessorRequired, setterAccessorRequired); return getAccessor(propertyDescriptor, AccessorKind.NORMAL, null, superCallTarget, getterAccessorRequired, setterAccessorRequired);
} }
@SuppressWarnings("unchecked")
public <D extends CallableMemberDescriptor> D getAccessorForJvmDefaultCompatibility(@NotNull D descriptor) { public <D extends CallableMemberDescriptor> D getAccessorForJvmDefaultCompatibility(@NotNull D descriptor) {
if (descriptor instanceof PropertyAccessorDescriptor) { if (descriptor instanceof PropertyAccessorDescriptor) {
PropertyDescriptor propertyAccessor = getAccessor(((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty(), PropertyDescriptor propertyAccessor = getAccessor(((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty(),
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.load.java.structure.impl;
import com.intellij.psi.PsiEnumConstant; import com.intellij.psi.PsiEnumConstant;
import com.intellij.psi.PsiField; import com.intellij.psi.PsiField;
import com.intellij.psi.impl.JavaConstantExpressionEvaluator; import com.intellij.psi.PsiVariable;
import com.intellij.psi.util.PsiUtil; import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -51,6 +51,6 @@ public class JavaFieldImpl extends JavaMemberImpl<PsiField> implements JavaField
public boolean getHasConstantNotNullInitializer() { public boolean getHasConstantNotNullInitializer() {
// PsiUtil.isCompileTimeConstant returns false for null-initialized fields, // PsiUtil.isCompileTimeConstant returns false for null-initialized fields,
// see com.intellij.psi.util.IsConstantExpressionVisitor.visitLiteralExpression() // see com.intellij.psi.util.IsConstantExpressionVisitor.visitLiteralExpression()
return PsiUtil.isCompileTimeConstant(getPsi()); return PsiUtil.isCompileTimeConstant((PsiVariable) getPsi());
} }
} }
@@ -870,13 +870,13 @@ public class CheckerTestUtil {
} }
@NotNull @NotNull
@SuppressWarnings("unchecked")
public static TextDiagnostic asTextDiagnostic(@NotNull ActualDiagnostic actualDiagnostic) { public static TextDiagnostic asTextDiagnostic(@NotNull ActualDiagnostic actualDiagnostic) {
Diagnostic diagnostic = actualDiagnostic.diagnostic; Diagnostic diagnostic = actualDiagnostic.diagnostic;
//noinspection TestOnlyProblems //noinspection TestOnlyProblems
DiagnosticRenderer renderer = DefaultErrorMessages.getRendererForDiagnostic(diagnostic); DiagnosticRenderer renderer = DefaultErrorMessages.getRendererForDiagnostic(diagnostic);
String diagnosticName = actualDiagnostic.getName(); String diagnosticName = actualDiagnostic.getName();
if (renderer instanceof AbstractDiagnosticWithParametersRenderer) { if (renderer instanceof AbstractDiagnosticWithParametersRenderer) {
//noinspection unchecked
Object[] renderParameters = ((AbstractDiagnosticWithParametersRenderer) renderer).renderParameters(diagnostic); Object[] renderParameters = ((AbstractDiagnosticWithParametersRenderer) renderer).renderParameters(diagnostic);
List<String> parameters = ContainerUtil.map(renderParameters, Object::toString); List<String> parameters = ContainerUtil.map(renderParameters, Object::toString);
return new TextDiagnostic(diagnosticName, actualDiagnostic.platform, parameters, actualDiagnostic.inferenceCompatibility); return new TextDiagnostic(diagnosticName, actualDiagnostic.platform, parameters, actualDiagnostic.inferenceCompatibility);
@@ -111,6 +111,7 @@ public class LocalVariableDescriptor extends VariableDescriptorWithInitializerIm
// This override is not deprecated because local variables can only come from sources, // This override is not deprecated because local variables can only come from sources,
// and we can be sure that they won't be recompiled independently // and we can be sure that they won't be recompiled independently
@Override @Override
@SuppressWarnings("deprecation")
public boolean isDelegated() { public boolean isDelegated() {
return isDelegated; return isDelegated;
} }
@@ -50,16 +50,17 @@ public abstract class DiagnosticFactory<D extends Diagnostic> {
} }
@NotNull @NotNull
@SuppressWarnings("unchecked")
public D cast(@NotNull Diagnostic diagnostic) { public D cast(@NotNull Diagnostic diagnostic) {
if (diagnostic.getFactory() != this) { if (diagnostic.getFactory() != this) {
throw new IllegalArgumentException("Factory mismatch: expected " + this + " but was " + diagnostic.getFactory()); throw new IllegalArgumentException("Factory mismatch: expected " + this + " but was " + diagnostic.getFactory());
} }
//noinspection unchecked
return (D) diagnostic; return (D) diagnostic;
} }
@NotNull @NotNull
@SafeVarargs
public static <D extends Diagnostic> D cast(@NotNull Diagnostic diagnostic, @NotNull DiagnosticFactory<? extends D>... factories) { public static <D extends Diagnostic> D cast(@NotNull Diagnostic diagnostic, @NotNull DiagnosticFactory<? extends D>... factories) {
return cast(diagnostic, Arrays.asList(factories)); return cast(diagnostic, Arrays.asList(factories));
} }
@@ -229,6 +229,7 @@ public class BindingContextUtils {
return bindingContext.get(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructorDescriptor); return bindingContext.get(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructorDescriptor);
} }
@SuppressWarnings("unchecked")
static void addOwnDataTo( static void addOwnDataTo(
@NotNull BindingTrace trace, @Nullable TraceEntryFilter filter, boolean commitDiagnostics, @NotNull BindingTrace trace, @Nullable TraceEntryFilter filter, boolean commitDiagnostics,
@NotNull MutableSlicedMap map, MutableDiagnosticsWithSuppression diagnostics @NotNull MutableSlicedMap map, MutableDiagnosticsWithSuppression diagnostics
@@ -515,12 +515,12 @@ public class BodyResolver {
return parentEnumOrSealed; return parentEnumOrSealed;
} }
@SuppressWarnings("unchecked")
private static void recordConstructorDelegationCall( private static void recordConstructorDelegationCall(
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull ConstructorDescriptor constructor, @NotNull ConstructorDescriptor constructor,
@NotNull ResolvedCall<?> call @NotNull ResolvedCall<?> call
) { ) {
//noinspection unchecked
trace.record(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructor, (ResolvedCall<ConstructorDescriptor>) call); trace.record(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructor, (ResolvedCall<ConstructorDescriptor>) call);
} }
@@ -52,9 +52,10 @@ public class ObservableBindingTrace implements BindingTrace {
} }
@Override @Override
@SuppressWarnings("unchecked")
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) { public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
originalTrace.record(slice, key, value); originalTrace.record(slice, key, value);
RecordHandler recordHandler = handlers.get(slice); RecordHandler<K, V> recordHandler = (RecordHandler) handlers.get(slice);
if (recordHandler != null) { if (recordHandler != null) {
recordHandler.handleRecord(slice, key, value); recordHandler.handleRecord(slice, key, value);
} }
@@ -303,6 +303,7 @@ public class CallResolver {
} }
@NotNull @NotNull
@SuppressWarnings("unchecked")
public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(@NotNull BasicCallResolutionContext context) { public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(@NotNull BasicCallResolutionContext context) {
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled(); ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
@@ -89,7 +89,7 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
@NotNull @NotNull
public static BasicCallResolutionContext create( public static BasicCallResolutionContext create(
@NotNull ResolutionContext context, @NotNull Call call, @NotNull CheckArgumentTypesMode checkArguments, @NotNull ResolutionContext<?> context, @NotNull Call call, @NotNull CheckArgumentTypesMode checkArguments,
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
) { ) {
return new BasicCallResolutionContext( return new BasicCallResolutionContext(
@@ -124,8 +124,8 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
); );
@NotNull @NotNull
@SuppressWarnings("unchecked")
private Context self() { private Context self() {
//noinspection unchecked
return (Context) this; return (Context) this;
} }
@@ -220,14 +220,15 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
} }
@Nullable @Nullable
public <T extends PsiElement> T getContextParentOfType(@NotNull KtExpression expression, @NotNull Class<? extends T>... classes) { @SafeVarargs
@SuppressWarnings("unchecked")
public final <T extends PsiElement> T getContextParentOfType(@NotNull KtExpression expression, @NotNull Class<? extends T>... classes) {
KtExpression context = expressionContextProvider.invoke(expression); KtExpression context = expressionContextProvider.invoke(expression);
PsiElement current = context != null ? context : expression.getParent(); PsiElement current = context != null ? context : expression.getParent();
while (current != null) { while (current != null) {
for (Class<? extends T> klass : classes) { for (Class<? extends T> klass : classes) {
if (klass.isInstance(current)) { if (klass.isInstance(current)) {
//noinspection unchecked
return (T) current; return (T) current;
} }
} }
@@ -195,6 +195,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
} }
@Override @Override
@SuppressWarnings("unchecked")
public void setResultingSubstitutor(@NotNull TypeSubstitutor substitutor) { public void setResultingSubstitutor(@NotNull TypeSubstitutor substitutor) {
resultingDescriptor = (D) candidateDescriptor.substitute(substitutor); resultingDescriptor = (D) candidateDescriptor.substitute(substitutor);
//noinspection ConstantConditions //noinspection ConstantConditions
@@ -32,6 +32,7 @@ import java.util.Collection;
public class OverloadResolutionResultsUtil { public class OverloadResolutionResultsUtil {
@NotNull @NotNull
@SuppressWarnings("unchecked")
public static <D extends CallableDescriptor> OverloadResolutionResults<D> ambiguity(OverloadResolutionResults<D> results1, OverloadResolutionResults<D> results2) { public static <D extends CallableDescriptor> OverloadResolutionResults<D> ambiguity(OverloadResolutionResults<D> results1, OverloadResolutionResults<D> results2) {
Collection<MutableResolvedCall<D>> resultingCalls = Lists.newArrayList(); Collection<MutableResolvedCall<D>> resultingCalls = Lists.newArrayList();
resultingCalls.addAll((Collection<MutableResolvedCall<D>>) results1.getResultingCalls()); resultingCalls.addAll((Collection<MutableResolvedCall<D>>) results1.getResultingCalls());
@@ -94,7 +94,7 @@ public class ResolutionResultsHandler {
@NotNull @NotNull
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> computeSuccessfulResult( private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> computeSuccessfulResult(
@NotNull CallResolutionContext context, @NotNull CallResolutionContext<?> context,
@NotNull TracingStrategy tracing, @NotNull TracingStrategy tracing,
@NotNull Set<MutableResolvedCall<D>> successfulCandidates, @NotNull Set<MutableResolvedCall<D>> successfulCandidates,
@NotNull Set<MutableResolvedCall<D>> incompleteCandidates, @NotNull Set<MutableResolvedCall<D>> incompleteCandidates,
@@ -192,6 +192,7 @@ public class ResolutionResultsHandler {
} }
@NotNull @NotNull
@SuppressWarnings("unchecked")
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> chooseAndReportMaximallySpecific( private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> chooseAndReportMaximallySpecific(
@NotNull Set<MutableResolvedCall<D>> candidates, @NotNull Set<MutableResolvedCall<D>> candidates,
boolean discriminateGenerics, boolean discriminateGenerics,
@@ -13,7 +13,6 @@ import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.config.LanguageFeature;
import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorBase; import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorBase;
@@ -352,8 +351,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
@NotNull @NotNull
@Override @Override
@SuppressWarnings("unchecked")
public Collection<CallableMemberDescriptor> getDeclaredCallableMembers() { public Collection<CallableMemberDescriptor> getDeclaredCallableMembers() {
//noinspection unchecked
return (Collection) CollectionsKt.filter( return (Collection) CollectionsKt.filter(
DescriptorUtils.getAllDescriptors(unsubstitutedMemberScope), DescriptorUtils.getAllDescriptors(unsubstitutedMemberScope),
descriptor -> descriptor instanceof CallableMemberDescriptor descriptor -> descriptor instanceof CallableMemberDescriptor
@@ -80,7 +80,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
} }
@NotNull @NotNull
public static ExpressionTypingContext newContext(@NotNull ResolutionContext context) { public static ExpressionTypingContext newContext(@NotNull ResolutionContext<?> context) {
return new ExpressionTypingContext( return new ExpressionTypingContext(
context.trace, context.scope, context.dataFlowInfo, context.expectedType, context.trace, context.scope, context.dataFlowInfo, context.expectedType,
context.contextDependency, context.resolutionResultsCache, context.contextDependency, context.resolutionResultsCache,
@@ -91,7 +91,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
} }
@NotNull @NotNull
public static ExpressionTypingContext newContext(@NotNull ResolutionContext context, boolean isDebuggerContext) { public static ExpressionTypingContext newContext(@NotNull ResolutionContext<?> context, boolean isDebuggerContext) {
return new ExpressionTypingContext( return new ExpressionTypingContext(
context.trace, context.scope, context.dataFlowInfo, context.expectedType, context.trace, context.scope, context.dataFlowInfo, context.expectedType,
context.contextDependency, context.resolutionResultsCache, context.contextDependency, context.resolutionResultsCache,
@@ -120,6 +120,7 @@ public class SlicedMapImpl implements MutableSlicedMap {
@NotNull @NotNull
@Override @Override
@SuppressWarnings("unchecked")
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) { public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
if (map == null) return ImmutableMap.of(); if (map == null) return ImmutableMap.of();
@@ -129,7 +130,6 @@ public class SlicedMapImpl implements MutableSlicedMap {
V value = holder.get(slice.getKey()); V value = holder.get(slice.getKey());
if (value != null) { if (value != null) {
//noinspection unchecked
builder.put((K) key, value); builder.put((K) key, value);
} }
}); });
@@ -112,7 +112,8 @@ public class Slices {
this.rewritePolicy = rewritePolicy; this.rewritePolicy = rewritePolicy;
} }
public SliceBuilder<K, V> setFurtherLookupSlices(ReadOnlySlice<K, V>... furtherLookupSlices) { @SafeVarargs
public final SliceBuilder<K, V> setFurtherLookupSlices(ReadOnlySlice<K, V>... furtherLookupSlices) {
this.furtherLookupSlices = Arrays.asList(furtherLookupSlices); this.furtherLookupSlices = Arrays.asList(furtherLookupSlices);
return this; return this;
} }
@@ -33,10 +33,9 @@ public class TrackingSlicedMap extends SlicedMapImpl {
this.trackWithStackTraces = trackWithStackTraces; this.trackWithStackTraces = trackWithStackTraces;
} }
@SuppressWarnings("unchecked")
private <K, V> SliceWithStackTrace<K, V> wrapSlice(ReadOnlySlice<K, V> slice) { private <K, V> SliceWithStackTrace<K, V> wrapSlice(ReadOnlySlice<K, V> slice) {
SliceWithStackTrace<?, ?> translated = sliceTranslationMap.computeIfAbsent(slice, k -> new SliceWithStackTrace<>(slice)); return (SliceWithStackTrace) sliceTranslationMap.computeIfAbsent(slice, k -> new SliceWithStackTrace<>(slice));
//noinspection unchecked
return (SliceWithStackTrace) translated;
} }
@Override @Override
@@ -514,7 +514,7 @@ public class InterceptionInstrumenter {
} }
} }
ia.invokevirtual(methodData.getDeclaringClass(), methodData.getName(), methodData.getDesc()); ia.invokevirtual(methodData.getDeclaringClass(), methodData.getName(), methodData.getDesc(), false);
Type type = asmMethod.getReturnType(); Type type = asmMethod.getReturnType();
if (type.getSort() != Type.VOID) { if (type.getSort() != Type.VOID) {
if (type.getSize() == 1) { if (type.getSize() == 1) {
@@ -32,7 +32,7 @@ public class KtContainerNode extends KtElementImpl {
} }
@Override // for visibility @Override // for visibility
protected PsiElement findChildByType(IElementType type) { protected <T extends PsiElement> T findChildByType(IElementType type) {
return super.findChildByType(type); return super.findChildByType(type);
} }
} }
@@ -43,6 +43,7 @@ public class KtElementImpl extends ASTWrapperPsiElement implements KtElement {
} }
@Override @Override
@SuppressWarnings("unchecked")
public final void accept(@NotNull PsiElementVisitor visitor) { public final void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof KtVisitor) { if (visitor instanceof KtVisitor) {
accept((KtVisitor) visitor, null); accept((KtVisitor) visitor, null);
@@ -81,6 +82,7 @@ public class KtElementImpl extends ASTWrapperPsiElement implements KtElement {
} }
@Override @Override
@SuppressWarnings("deprecation")
public PsiReference getReference() { public PsiReference getReference() {
PsiReference[] references = getReferences(); PsiReference[] references = getReferences();
if (references.length == 1) return references[0]; if (references.length == 1) return references[0];
@@ -54,6 +54,7 @@ public class KtElementImplStub<T extends StubElement<?>> extends StubBasedPsiEle
} }
@Override @Override
@SuppressWarnings("unchecked")
public final void accept(@NotNull PsiElementVisitor visitor) { public final void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof KtVisitor) { if (visitor instanceof KtVisitor) {
accept((KtVisitor) visitor, null); accept((KtVisitor) visitor, null);
@@ -98,6 +99,7 @@ public class KtElementImplStub<T extends StubElement<?>> extends StubBasedPsiEle
} }
@Override @Override
@SuppressWarnings("deprecation")
public PsiReference getReference() { public PsiReference getReference() {
PsiReference[] references = getReferences(); PsiReference[] references = getReferences();
if (references.length == 1) return references[0]; if (references.length == 1) return references[0];
@@ -91,6 +91,7 @@ public class KtLambdaExpression extends LazyParseablePsiElement implements KtExp
} }
@Override @Override
@SuppressWarnings("unchecked")
public final void accept(@NotNull PsiElementVisitor visitor) { public final void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof KtVisitor) { if (visitor instanceof KtVisitor) {
accept((KtVisitor) visitor, null); accept((KtVisitor) visitor, null);
@@ -266,10 +266,12 @@ public class KtPsiUtil {
} }
@Nullable @Nullable
@SafeVarargs
@Contract("null, _ -> null") @Contract("null, _ -> null")
public static PsiElement getTopmostParentOfTypes( public static PsiElement getTopmostParentOfTypes(
@Nullable PsiElement element, @Nullable PsiElement element,
@NotNull Class<? extends PsiElement>... parentTypes) { @NotNull Class<? extends PsiElement>... parentTypes
) {
if (element instanceof PsiFile) return null; if (element instanceof PsiFile) return null;
PsiElement answer = PsiTreeUtil.getParentOfType(element, parentTypes); PsiElement answer = PsiTreeUtil.getParentOfType(element, parentTypes);
@@ -641,12 +643,13 @@ public class KtPsiUtil {
return parent; return parent;
} }
@SafeVarargs
@SuppressWarnings("unchecked")
public static <T extends PsiElement> T getLastChildByType(@NotNull PsiElement root, @NotNull Class<? extends T>... elementTypes) { public static <T extends PsiElement> T getLastChildByType(@NotNull PsiElement root, @NotNull Class<? extends T>... elementTypes) {
PsiElement[] children = root.getChildren(); PsiElement[] children = root.getChildren();
for (int i = children.length - 1; i >= 0; i--) { for (int i = children.length - 1; i >= 0; i--) {
if (PsiTreeUtil.instanceOf(children[i], elementTypes)) { if (PsiTreeUtil.instanceOf(children[i], elementTypes)) {
//noinspection unchecked
return (T) children[i]; return (T) children[i];
} }
} }
@@ -37,13 +37,13 @@ public final class KtStubbedPsiUtil {
//TODO: contribute to idea PsiTreeUtil#getPsiOrStubParent //TODO: contribute to idea PsiTreeUtil#getPsiOrStubParent
@Nullable @Nullable
@SuppressWarnings("unchecked")
public static <T extends KtElement> T getPsiOrStubParent( public static <T extends KtElement> T getPsiOrStubParent(
@NotNull PsiElement element, @NotNull PsiElement element,
@NotNull Class<T> declarationClass, @NotNull Class<T> declarationClass,
boolean strict boolean strict
) { ) {
if (!strict && declarationClass.isInstance(element)) { if (!strict && declarationClass.isInstance(element)) {
//noinspection unchecked
return (T) element; return (T) element;
} }
if (element instanceof KtElementImplStub) { if (element instanceof KtElementImplStub) {
@@ -23,12 +23,11 @@ import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef; import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.KtAnnotationEntry; import org.jetbrains.kotlin.psi.KtAnnotationEntry;
import org.jetbrains.kotlin.psi.KtPsiUtil;
import org.jetbrains.kotlin.psi.KtValueArgumentList; import org.jetbrains.kotlin.psi.KtValueArgumentList;
import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub; import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub;
import org.jetbrains.kotlin.psi.stubs.impl.KotlinAnnotationEntryStubImpl; import org.jetbrains.kotlin.psi.stubs.impl.KotlinAnnotationEntryStubImpl;
import org.jetbrains.kotlin.name.Name;
import java.io.IOException; import java.io.IOException;
@@ -38,13 +37,14 @@ public class KtAnnotationEntryElementType extends KtStubElementType<KotlinAnnota
super(debugName, KtAnnotationEntry.class, KotlinAnnotationEntryStub.class); super(debugName, KtAnnotationEntry.class, KotlinAnnotationEntryStub.class);
} }
@NotNull
@Override @Override
public KotlinAnnotationEntryStub createStub(@NotNull KtAnnotationEntry psi, StubElement parentStub) { public KotlinAnnotationEntryStub createStub(@NotNull KtAnnotationEntry psi, StubElement parentStub) {
Name shortName = psi.getShortName(); Name shortName = psi.getShortName();
String resultName = shortName != null ? shortName.asString() : null; String resultName = shortName != null ? shortName.asString() : null;
KtValueArgumentList valueArgumentList = psi.getValueArgumentList(); KtValueArgumentList valueArgumentList = psi.getValueArgumentList();
boolean hasValueArguments = valueArgumentList != null && !valueArgumentList.getArguments().isEmpty(); boolean hasValueArguments = valueArgumentList != null && !valueArgumentList.getArguments().isEmpty();
return new KotlinAnnotationEntryStubImpl(parentStub, StringRef.fromString(resultName), hasValueArguments); return new KotlinAnnotationEntryStubImpl((StubElement<?>) parentStub, StringRef.fromString(resultName), hasValueArguments);
} }
@Override @Override
@@ -58,7 +58,7 @@ public class KtAnnotationEntryElementType extends KtStubElementType<KotlinAnnota
public KotlinAnnotationEntryStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { public KotlinAnnotationEntryStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef text = dataStream.readName(); StringRef text = dataStream.readName();
boolean hasValueArguments = dataStream.readBoolean(); boolean hasValueArguments = dataStream.readBoolean();
return new KotlinAnnotationEntryStubImpl(parentStub, text, hasValueArguments); return new KotlinAnnotationEntryStubImpl((StubElement<?>) parentStub, text, hasValueArguments);
} }
@Override @Override
@@ -52,15 +52,19 @@ public class KtClassElementType extends KtStubElementType<KotlinClassStub, KtCla
return node.getElementType() != KtStubElementTypes.ENUM_ENTRY ? new KtClass(node) : new KtEnumEntry(node); return node.getElementType() != KtStubElementTypes.ENUM_ENTRY ? new KtClass(node) : new KtEnumEntry(node);
} }
@NotNull
@Override @Override
public KotlinClassStub createStub(@NotNull KtClass psi, StubElement parentStub) { public KotlinClassStub createStub(@NotNull KtClass psi, StubElement parentStub) {
FqName fqName = KtPsiUtilKt.safeFqNameForLazyResolve(psi); FqName fqName = KtPsiUtilKt.safeFqNameForLazyResolve(psi);
boolean isEnumEntry = psi instanceof KtEnumEntry; boolean isEnumEntry = psi instanceof KtEnumEntry;
List<String> superNames = KtPsiUtilKt.getSuperNames(psi); List<String> superNames = KtPsiUtilKt.getSuperNames(psi);
return new KotlinClassStubImpl( return new KotlinClassStubImpl(
getStubType(isEnumEntry), parentStub, StringRef.fromString(fqName != null ? fqName.asString() : null), getStubType(isEnumEntry), (StubElement<?>) parentStub,
StringRef.fromString(psi.getName()), Utils.INSTANCE.wrapStrings(superNames), psi.isInterface(), isEnumEntry, StringRef.fromString(fqName != null ? fqName.asString() : null),
psi.isLocal(), psi.isTopLevel()); StringRef.fromString(psi.getName()),
Utils.INSTANCE.wrapStrings(superNames),
psi.isInterface(), isEnumEntry, psi.isLocal(), psi.isTopLevel()
);
} }
@Override @Override
@@ -96,8 +100,10 @@ public class KtClassElementType extends KtStubElementType<KotlinClassStub, KtCla
superNames[i] = dataStream.readName(); superNames[i] = dataStream.readName();
} }
return new KotlinClassStubImpl(getStubType(isEnumEntry), parentStub, qualifiedName, name, superNames, return new KotlinClassStubImpl(
isTrait, isEnumEntry, isLocal, isTopLevel); getStubType(isEnumEntry), (StubElement<?>) parentStub, qualifiedName, name, superNames,
isTrait, isEnumEntry, isLocal, isTopLevel
);
} }
@Override @Override
@@ -38,6 +38,7 @@ public class KtFunctionElementType extends KtStubElementType<KotlinFunctionStub,
super(debugName, KtNamedFunction.class, KotlinFunctionStub.class); super(debugName, KtNamedFunction.class, KotlinFunctionStub.class);
} }
@NotNull
@Override @Override
public KotlinFunctionStub createStub(@NotNull KtNamedFunction psi, @NotNull StubElement parentStub) { public KotlinFunctionStub createStub(@NotNull KtNamedFunction psi, @NotNull StubElement parentStub) {
boolean isTopLevel = psi.getParent() instanceof KtFile; boolean isTopLevel = psi.getParent() instanceof KtFile;
@@ -45,9 +46,11 @@ public class KtFunctionElementType extends KtStubElementType<KotlinFunctionStub,
FqName fqName = KtPsiUtilKt.safeFqNameForLazyResolve(psi); FqName fqName = KtPsiUtilKt.safeFqNameForLazyResolve(psi);
boolean hasBlockBody = psi.hasBlockBody(); boolean hasBlockBody = psi.hasBlockBody();
boolean hasBody = psi.hasBody(); boolean hasBody = psi.hasBody();
return new KotlinFunctionStubImpl(parentStub, StringRef.fromString(psi.getName()), isTopLevel, fqName, return new KotlinFunctionStubImpl(
isExtension, hasBlockBody, hasBody, psi.hasTypeParameterListBeforeFunctionName(), (StubElement<?>) parentStub, StringRef.fromString(psi.getName()), isTopLevel, fqName,
psi.mayHaveContract()); isExtension, hasBlockBody, hasBody, psi.hasTypeParameterListBeforeFunctionName(),
psi.mayHaveContract()
);
} }
@Override @Override
@@ -80,8 +83,10 @@ public class KtFunctionElementType extends KtStubElementType<KotlinFunctionStub,
boolean hasTypeParameterListBeforeFunctionName = dataStream.readBoolean(); boolean hasTypeParameterListBeforeFunctionName = dataStream.readBoolean();
boolean mayHaveContract = dataStream.readBoolean(); boolean mayHaveContract = dataStream.readBoolean();
return new KotlinFunctionStubImpl(parentStub, name, isTopLevel, fqName, isExtension, hasBlockBody, hasBody, return new KotlinFunctionStubImpl(
hasTypeParameterListBeforeFunctionName, mayHaveContract); (StubElement<?>) parentStub, name, isTopLevel, fqName, isExtension, hasBlockBody, hasBody,
hasTypeParameterListBeforeFunctionName, mayHaveContract
);
} }
@Override @Override
@@ -34,11 +34,12 @@ public class KtImportDirectiveElementType extends KtStubElementType<KotlinImport
super(debugName, KtImportDirective.class, KotlinImportDirectiveStub.class); super(debugName, KtImportDirective.class, KotlinImportDirectiveStub.class);
} }
@NotNull
@Override @Override
public KotlinImportDirectiveStub createStub(@NotNull KtImportDirective psi, StubElement parentStub) { public KotlinImportDirectiveStub createStub(@NotNull KtImportDirective psi, StubElement parentStub) {
FqName importedFqName = psi.getImportedFqName(); FqName importedFqName = psi.getImportedFqName();
StringRef fqName = StringRef.fromString(importedFqName == null ? null : importedFqName.asString()); StringRef fqName = StringRef.fromString(importedFqName == null ? null : importedFqName.asString());
return new KotlinImportDirectiveStubImpl(parentStub, psi.isAllUnder(), fqName, psi.isValidImport()); return new KotlinImportDirectiveStubImpl((StubElement<?>) parentStub, psi.isAllUnder(), fqName, psi.isValidImport());
} }
@Override @Override
@@ -55,6 +56,6 @@ public class KtImportDirectiveElementType extends KtStubElementType<KotlinImport
boolean isAllUnder = dataStream.readBoolean(); boolean isAllUnder = dataStream.readBoolean();
StringRef importedName = dataStream.readName(); StringRef importedName = dataStream.readName();
boolean isValid = dataStream.readBoolean(); boolean isValid = dataStream.readBoolean();
return new KotlinImportDirectiveStubImpl(parentStub, isAllUnder, importedName, isValid); return new KotlinImportDirectiveStubImpl((StubElement<?>) parentStub, isAllUnder, importedName, isValid);
} }
} }
@@ -38,13 +38,16 @@ public class KtObjectElementType extends KtStubElementType<KotlinObjectStub, KtO
super(debugName, KtObjectDeclaration.class, KotlinObjectStub.class); super(debugName, KtObjectDeclaration.class, KotlinObjectStub.class);
} }
@NotNull
@Override @Override
public KotlinObjectStub createStub(@NotNull KtObjectDeclaration psi, StubElement parentStub) { public KotlinObjectStub createStub(@NotNull KtObjectDeclaration psi, StubElement parentStub) {
String name = psi.getName(); String name = psi.getName();
FqName fqName = KtPsiUtilKt.safeFqNameForLazyResolve(psi); FqName fqName = KtPsiUtilKt.safeFqNameForLazyResolve(psi);
List<String> superNames = KtPsiUtilKt.getSuperNames(psi); List<String> superNames = KtPsiUtilKt.getSuperNames(psi);
return new KotlinObjectStubImpl(parentStub, StringRef.fromString(name), fqName, Utils.INSTANCE.wrapStrings(superNames), return new KotlinObjectStubImpl(
psi.isTopLevel(), psi.isCompanion(), psi.isLocal(), psi.isObjectLiteral()); (StubElement<?>) parentStub, StringRef.fromString(name), fqName, Utils.INSTANCE.wrapStrings(superNames),
psi.isTopLevel(), psi.isCompanion(), psi.isLocal(), psi.isObjectLiteral()
);
} }
@Override @Override
@@ -84,7 +87,9 @@ public class KtObjectElementType extends KtStubElementType<KotlinObjectStub, KtO
superNames[i] = dataStream.readName(); superNames[i] = dataStream.readName();
} }
return new KotlinObjectStubImpl(parentStub, name, fqName, superNames, isTopLevel, isCompanion, isLocal, isObjectLiteral); return new KotlinObjectStubImpl(
(StubElement<?>) parentStub, name, fqName, superNames, isTopLevel, isCompanion, isLocal, isObjectLiteral
);
} }
@Override @Override
@@ -23,10 +23,10 @@ import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef; import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.KtParameter; import org.jetbrains.kotlin.psi.KtParameter;
import org.jetbrains.kotlin.psi.stubs.KotlinParameterStub; import org.jetbrains.kotlin.psi.stubs.KotlinParameterStub;
import org.jetbrains.kotlin.psi.stubs.impl.KotlinParameterStubImpl; import org.jetbrains.kotlin.psi.stubs.impl.KotlinParameterStubImpl;
import org.jetbrains.kotlin.name.FqName;
import java.io.IOException; import java.io.IOException;
@@ -35,12 +35,15 @@ public class KtParameterElementType extends KtStubElementType<KotlinParameterStu
super(debugName, KtParameter.class, KotlinParameterStub.class); super(debugName, KtParameter.class, KotlinParameterStub.class);
} }
@NotNull
@Override @Override
public KotlinParameterStub createStub(@NotNull KtParameter psi, StubElement parentStub) { public KotlinParameterStub createStub(@NotNull KtParameter psi, StubElement parentStub) {
FqName fqName = psi.getFqName(); FqName fqName = psi.getFqName();
StringRef fqNameRef = StringRef.fromString(fqName != null ? fqName.asString() : null); StringRef fqNameRef = StringRef.fromString(fqName != null ? fqName.asString() : null);
return new KotlinParameterStubImpl(parentStub, fqNameRef, StringRef.fromString(psi.getName()), return new KotlinParameterStubImpl(
psi.isMutable(), psi.hasValOrVar(), psi.hasDefaultValue()); (StubElement<?>) parentStub, fqNameRef, StringRef.fromString(psi.getName()),
psi.isMutable(), psi.hasValOrVar(), psi.hasDefaultValue()
);
} }
@Override @Override
@@ -62,7 +65,7 @@ public class KtParameterElementType extends KtStubElementType<KotlinParameterStu
boolean hasDefaultValue = dataStream.readBoolean(); boolean hasDefaultValue = dataStream.readBoolean();
StringRef fqName = dataStream.readName(); StringRef fqName = dataStream.readName();
return new KotlinParameterStubImpl(parentStub, fqName, name, isMutable, hasValOrValNode, hasDefaultValue); return new KotlinParameterStubImpl((StubElement<?>) parentStub, fqName, name, isMutable, hasValOrValNode, hasDefaultValue);
} }
@Override @Override
@@ -36,6 +36,7 @@ public class KtPropertyElementType extends KtStubElementType<KotlinPropertyStub,
super(debugName, KtProperty.class, KotlinPropertyStub.class); super(debugName, KtProperty.class, KotlinPropertyStub.class);
} }
@NotNull
@Override @Override
public KotlinPropertyStub createStub(@NotNull KtProperty psi, StubElement parentStub) { public KotlinPropertyStub createStub(@NotNull KtProperty psi, StubElement parentStub) {
assert !psi.isLocal() : assert !psi.isLocal() :
@@ -43,7 +44,7 @@ public class KtPropertyElementType extends KtStubElementType<KotlinPropertyStub,
psi.getText(), psi.getParent() != null ? psi.getParent().getText() : "<no parent>"); psi.getText(), psi.getParent() != null ? psi.getParent().getText() : "<no parent>");
return new KotlinPropertyStubImpl( return new KotlinPropertyStubImpl(
parentStub, StringRef.fromString(psi.getName()), (StubElement<?>) parentStub, StringRef.fromString(psi.getName()),
psi.isVar(), psi.isTopLevel(), psi.hasDelegate(), psi.isVar(), psi.isTopLevel(), psi.hasDelegate(),
psi.hasDelegateExpression(), psi.hasInitializer(), psi.hasDelegateExpression(), psi.hasInitializer(),
psi.getReceiverTypeReference() != null, psi.getTypeReference() != null, psi.getReceiverTypeReference() != null, psi.getTypeReference() != null,
@@ -81,9 +82,10 @@ public class KtPropertyElementType extends KtStubElementType<KotlinPropertyStub,
StringRef fqNameAsString = dataStream.readName(); StringRef fqNameAsString = dataStream.readName();
FqName fqName = fqNameAsString != null ? new FqName(fqNameAsString.toString()) : null; FqName fqName = fqNameAsString != null ? new FqName(fqNameAsString.toString()) : null;
return new KotlinPropertyStubImpl(parentStub, name, isVar, isTopLevel, hasDelegate, return new KotlinPropertyStubImpl(
hasDelegateExpression, hasInitializer, hasReceiverTypeRef, hasReturnTypeRef, (StubElement<?>) parentStub, name, isVar, isTopLevel, hasDelegate, hasDelegateExpression, hasInitializer,
fqName); hasReceiverTypeRef, hasReturnTypeRef, fqName
);
} }
@Override @Override
@@ -47,6 +47,7 @@ public abstract class KtStubElementType<StubT extends StubElement, PsiT extends
@NotNull @NotNull
private final ArrayFactory<PsiT> arrayFactory; private final ArrayFactory<PsiT> arrayFactory;
@SuppressWarnings("unchecked")
public KtStubElementType(@NotNull @NonNls String debugName, @NotNull Class<PsiT> psiClass, @NotNull Class<?> stubClass) { public KtStubElementType(@NotNull @NonNls String debugName, @NotNull Class<PsiT> psiClass, @NotNull Class<?> stubClass) {
super(debugName, KotlinLanguage.INSTANCE); super(debugName, KotlinLanguage.INSTANCE);
try { try {
@@ -56,13 +57,11 @@ public abstract class KtStubElementType<StubT extends StubElement, PsiT extends
catch (NoSuchMethodException e) { catch (NoSuchMethodException e) {
throw new RuntimeException("Stub element type declaration for " + psiClass.getSimpleName() + " is missing required constructors",e); throw new RuntimeException("Stub element type declaration for " + psiClass.getSimpleName() + " is missing required constructors",e);
} }
//noinspection unchecked
emptyArray = (PsiT[]) Array.newInstance(psiClass, 0); emptyArray = (PsiT[]) Array.newInstance(psiClass, 0);
arrayFactory = count -> { arrayFactory = count -> {
if (count == 0) { if (count == 0) {
return emptyArray; return emptyArray;
} }
//noinspection unchecked
return (PsiT[]) Array.newInstance(psiClass, count); return (PsiT[]) Array.newInstance(psiClass, count);
}; };
} }
@@ -34,10 +34,13 @@ public class KtTypeParameterElementType extends KtStubElementType<KotlinTypePara
super(debugName, KtTypeParameter.class, KotlinTypeParameterStub.class); super(debugName, KtTypeParameter.class, KotlinTypeParameterStub.class);
} }
@NotNull
@Override @Override
public KotlinTypeParameterStub createStub(@NotNull KtTypeParameter psi, StubElement parentStub) { public KotlinTypeParameterStub createStub(@NotNull KtTypeParameter psi, StubElement parentStub) {
return new KotlinTypeParameterStubImpl(parentStub, StringRef.fromString(psi.getName()), return new KotlinTypeParameterStubImpl(
psi.getVariance() == Variance.IN_VARIANCE, psi.getVariance() == Variance.OUT_VARIANCE); (StubElement<?>) parentStub, StringRef.fromString(psi.getName()),
psi.getVariance() == Variance.IN_VARIANCE, psi.getVariance() == Variance.OUT_VARIANCE
);
} }
@Override @Override
@@ -54,6 +57,6 @@ public class KtTypeParameterElementType extends KtStubElementType<KotlinTypePara
boolean isInVariance = dataStream.readBoolean(); boolean isInVariance = dataStream.readBoolean();
boolean isOutVariance = dataStream.readBoolean(); boolean isOutVariance = dataStream.readBoolean();
return new KotlinTypeParameterStubImpl(parentStub, name, isInVariance, isOutVariance); return new KotlinTypeParameterStubImpl((StubElement<?>) parentStub, name, isInVariance, isOutVariance);
} }
} }
@@ -25,25 +25,24 @@ import org.jetbrains.kotlin.psi.KtUserType;
import org.jetbrains.kotlin.psi.stubs.KotlinUserTypeStub; import org.jetbrains.kotlin.psi.stubs.KotlinUserTypeStub;
import org.jetbrains.kotlin.psi.stubs.impl.KotlinUserTypeStubImpl; import org.jetbrains.kotlin.psi.stubs.impl.KotlinUserTypeStubImpl;
import java.io.IOException;
public class KtUserTypeElementType extends KtStubElementType<KotlinUserTypeStub, KtUserType> { public class KtUserTypeElementType extends KtStubElementType<KotlinUserTypeStub, KtUserType> {
public KtUserTypeElementType(@NotNull @NonNls String debugName) { public KtUserTypeElementType(@NotNull @NonNls String debugName) {
super(debugName, KtUserType.class, KotlinUserTypeStub.class); super(debugName, KtUserType.class, KotlinUserTypeStub.class);
} }
@NotNull
@Override @Override
public KotlinUserTypeStub createStub(@NotNull KtUserType psi, StubElement parentStub) { public KotlinUserTypeStub createStub(@NotNull KtUserType psi, StubElement parentStub) {
return new KotlinUserTypeStubImpl(parentStub); return new KotlinUserTypeStubImpl((StubElement<?>) parentStub);
} }
@Override @Override
public void serialize(@NotNull KotlinUserTypeStub stub, @NotNull StubOutputStream dataStream) throws IOException { public void serialize(@NotNull KotlinUserTypeStub stub, @NotNull StubOutputStream dataStream) {
} }
@NotNull @NotNull
@Override @Override
public KotlinUserTypeStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { public KotlinUserTypeStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) {
return new KotlinUserTypeStubImpl(parentStub); return new KotlinUserTypeStubImpl((StubElement<?>) parentStub);
} }
} }
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.psi.stubs.impl package org.jetbrains.kotlin.psi.stubs.impl
import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.StubElement import com.intellij.psi.stubs.StubElement
import com.intellij.util.io.StringRef import com.intellij.util.io.StringRef
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
@@ -25,7 +24,7 @@ import org.jetbrains.kotlin.psi.stubs.KotlinImportDirectiveStub
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
class KotlinImportDirectiveStubImpl( class KotlinImportDirectiveStubImpl(
parent: StubElement<PsiElement>, parent: StubElement<*>,
private val isAllUnder: Boolean, private val isAllUnder: Boolean,
private val importedFqName: StringRef?, private val importedFqName: StringRef?,
private val isValid: Boolean private val isValid: Boolean
@@ -16,9 +16,10 @@
package org.jetbrains.kotlin.codegen; package org.jetbrains.kotlin.codegen;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.ArrayUtil; import com.intellij.util.ArrayUtil;
import kotlin.collections.CollectionsKt; import kotlin.collections.CollectionsKt;
import kotlin.io.FilesKt;
import kotlin.sequences.SequencesKt;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
@@ -28,28 +29,19 @@ import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestJdkKind; import org.jetbrains.kotlin.test.TestJdkKind;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public abstract class AbstractTopLevelMembersInvocationTest extends AbstractBytecodeTextTest { public abstract class AbstractTopLevelMembersInvocationTest extends AbstractBytecodeTextTest {
private static final String LIBRARY = "library";
@Override @Override
public void doTest(@NotNull String filename) throws Exception { public void doTest(@NotNull String filename) throws Exception {
File root = new File(filename); File root = new File(filename);
List<String> sourceFiles = new ArrayList<>(2); List<String> sourceFiles = SequencesKt.toList(SequencesKt.map(
SequencesKt.filter(FilesKt.walkTopDown(root).maxDepth(1), File::isFile),
this::relativePath
));
FileUtil.processFilesRecursively(root, file -> { File library = new File(root, "library");
if (file.getName().endsWith(".kt")) {
sourceFiles.add(relativePath(file));
return true;
}
return true;
}, file -> !LIBRARY.equals(file.getName()));
File library = new File(root, LIBRARY);
List<File> classPath = List<File> classPath =
library.exists() library.exists()
? Collections.singletonList(CompilerTestUtil.compileJvmLibrary(library)) ? Collections.singletonList(CompilerTestUtil.compileJvmLibrary(library))
@@ -308,7 +308,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
assert configurationKeyField != null : "Expected [+|-][namespace.]configurationKey, got: " + flag; assert configurationKeyField != null : "Expected [+|-][namespace.]configurationKey, got: " + flag;
try { try {
//noinspection unchecked @SuppressWarnings("unchecked")
CompilerConfigurationKey<Boolean> configurationKey = (CompilerConfigurationKey<Boolean>) configurationKeyField.get(null); CompilerConfigurationKey<Boolean> configurationKey = (CompilerConfigurationKey<Boolean>) configurationKeyField.get(null);
configuration.put(configurationKey, flagEnabled); configuration.put(configurationKey, flagEnabled);
} }
@@ -615,9 +615,9 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
} }
@NotNull @NotNull
@SuppressWarnings("unchecked")
public Class<? extends Annotation> loadAnnotationClassQuietly(@NotNull String fqName) { public Class<? extends Annotation> loadAnnotationClassQuietly(@NotNull String fqName) {
try { try {
//noinspection unchecked
return (Class<? extends Annotation>) initializedClassLoader.loadClass(fqName); return (Class<? extends Annotation>) initializedClassLoader.loadClass(fqName);
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException e) {
@@ -70,11 +70,11 @@ public abstract class KtPlatformLiteFixture extends KtUsefulTestCase {
} }
} }
@SuppressWarnings("unchecked")
public static <T> T registerComponentInstance(MutablePicoContainer container, Class<T> key, T implementation) { public static <T> T registerComponentInstance(MutablePicoContainer container, Class<T> key, T implementation) {
Object old = container.getComponentInstance(key); Object old = container.getComponentInstance(key);
container.unregisterComponent(key); container.unregisterComponent(key);
container.registerComponentInstance(key, implementation); container.registerComponentInstance(key, implementation);
//noinspection unchecked
return (T)old; return (T)old;
} }
} }
@@ -180,6 +180,7 @@ public abstract class KtUsefulTestCase extends TestCase {
catch (Exception e) { catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@SuppressWarnings("unchecked")
Set<String> files = ReflectionUtil.getStaticFieldValue(aClass, Set.class, "files"); Set<String> files = ReflectionUtil.getStaticFieldValue(aClass, Set.class, "files");
DELETE_ON_EXIT_HOOK_CLASS = aClass; DELETE_ON_EXIT_HOOK_CLASS = aClass;
DELETE_ON_EXIT_HOOK_DOT_FILES = files; DELETE_ON_EXIT_HOOK_DOT_FILES = files;
@@ -307,7 +308,9 @@ public abstract class KtUsefulTestCase extends TestCase {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (Object o : collection) { for (Object o : collection) {
if (o instanceof THashSet) { if (o instanceof THashSet) {
builder.append(new TreeSet<Object>((THashSet)o)); @SuppressWarnings("unchecked")
Set<Object> set = new TreeSet<Object>((THashSet) o);
builder.append(set);
} }
else { else {
builder.append(o); builder.append(o);
@@ -317,6 +320,7 @@ public abstract class KtUsefulTestCase extends TestCase {
return builder.toString(); return builder.toString();
} }
@SafeVarargs
private static <T> void assertOrderedEquals(String errorMsg, @NotNull Iterable<T> actual, @NotNull T... expected) { private static <T> void assertOrderedEquals(String errorMsg, @NotNull Iterable<T> actual, @NotNull T... expected) {
Assert.assertNotNull(actual); Assert.assertNotNull(actual);
Assert.assertNotNull(expected); Assert.assertNotNull(expected);
@@ -339,10 +343,12 @@ public abstract class KtUsefulTestCase extends TestCase {
} }
} }
@SafeVarargs
public static <T> void assertSameElements(T[] collection, T... expected) { public static <T> void assertSameElements(T[] collection, T... expected) {
assertSameElements(Arrays.asList(collection), expected); assertSameElements(Arrays.asList(collection), expected);
} }
@SafeVarargs
public static <T> void assertSameElements(Collection<? extends T> collection, T... expected) { public static <T> void assertSameElements(Collection<? extends T> collection, T... expected) {
assertSameElements(collection, Arrays.asList(expected)); assertSameElements(collection, Arrays.asList(expected));
} }
@@ -388,7 +394,6 @@ public abstract class KtUsefulTestCase extends TestCase {
} }
protected static <T> void assertEmpty(String errorMsg, Collection<T> collection) { protected static <T> void assertEmpty(String errorMsg, Collection<T> collection) {
//noinspection unchecked
assertOrderedEquals(errorMsg, collection); assertOrderedEquals(errorMsg, collection);
} }
@@ -167,8 +167,8 @@ public class AnnotationGenTest extends CodegenTestCase {
public void testConstructor() throws NoSuchFieldException, NoSuchMethodException { public void testConstructor() throws NoSuchFieldException, NoSuchMethodException {
loadText("class A @[java.lang.Deprecated] constructor() {}"); loadText("class A @[java.lang.Deprecated] constructor() {}");
Class<?> aClass = generateClass("A"); Class<?> aClass = generateClass("A");
Constructor x = aClass.getDeclaredConstructor(); Constructor<?> x = aClass.getDeclaredConstructor();
Deprecated annotation = (Deprecated) x.getAnnotation(Deprecated.class); Deprecated annotation = x.getAnnotation(Deprecated.class);
assertNotNull(annotation); assertNotNull(annotation);
} }
@@ -181,8 +181,8 @@ public class AnnotationGenTest extends CodegenTestCase {
public void testClass() throws NoSuchFieldException, NoSuchMethodException { public void testClass() throws NoSuchFieldException, NoSuchMethodException {
loadText("@[java.lang.Deprecated] class A () {}"); loadText("@[java.lang.Deprecated] class A () {}");
Class aClass = generateClass("A"); Class<?> aClass = generateClass("A");
Deprecated annotation = (Deprecated) aClass.getAnnotation(Deprecated.class); Deprecated annotation = aClass.getAnnotation(Deprecated.class);
assertNotNull(annotation); assertNotNull(annotation);
} }
@@ -209,9 +209,10 @@ public class AnnotationGenTest extends CodegenTestCase {
"@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: String)\n" + "@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: String)\n" +
"" + "" +
"@A(\"239\") class B()"); "@A(\"239\") class B()");
Class aClass = generateClass("A"); @SuppressWarnings("unchecked")
Class<? extends Annotation> aClass = (Class) generateClass("A");
Retention annotation = (Retention)aClass.getAnnotation(Retention.class); Retention annotation = aClass.getAnnotation(Retention.class);
RetentionPolicy value = annotation.value(); RetentionPolicy value = annotation.value();
assertEquals(RetentionPolicy.RUNTIME, value); assertEquals(RetentionPolicy.RUNTIME, value);
@@ -243,9 +244,10 @@ public class AnnotationGenTest extends CodegenTestCase {
"@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: C)\n" + "@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: C)\n" +
"" + "" +
"@A(C(\"239\")) class B()"); "@A(C(\"239\")) class B()");
Class aClass = generateClass("A"); @SuppressWarnings("unchecked")
Class<? extends Annotation> aClass = (Class) generateClass("A");
Retention annotation = (Retention)aClass.getAnnotation(Retention.class); Retention annotation = aClass.getAnnotation(Retention.class);
RetentionPolicy value = annotation.value(); RetentionPolicy value = annotation.value();
assertEquals(RetentionPolicy.RUNTIME, value); assertEquals(RetentionPolicy.RUNTIME, value);
@@ -280,9 +282,10 @@ public class AnnotationGenTest extends CodegenTestCase {
"@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<String>)\n" + "@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<String>)\n" +
"" + "" +
"@A(arrayOf(\"239\",\"932\")) class B()"); "@A(arrayOf(\"239\",\"932\")) class B()");
Class aClass = generateClass("A"); @SuppressWarnings("unchecked")
Class<? extends Annotation> aClass = (Class) generateClass("A");
Retention annotation = (Retention)aClass.getAnnotation(Retention.class); Retention annotation = aClass.getAnnotation(Retention.class);
RetentionPolicy value = annotation.value(); RetentionPolicy value = annotation.value();
assertEquals(RetentionPolicy.RUNTIME, value); assertEquals(RetentionPolicy.RUNTIME, value);
@@ -315,9 +318,10 @@ public class AnnotationGenTest extends CodegenTestCase {
"@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: IntArray)\n" + "@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: IntArray)\n" +
"" + "" +
"@A(intArrayOf(239,932)) class B()"); "@A(intArrayOf(239,932)) class B()");
Class aClass = generateClass("A"); @SuppressWarnings("unchecked")
Class<? extends Annotation> aClass = (Class) generateClass("A");
Retention annotation = (Retention)aClass.getAnnotation(Retention.class); Retention annotation = aClass.getAnnotation(Retention.class);
RetentionPolicy value = annotation.value(); RetentionPolicy value = annotation.value();
assertEquals(RetentionPolicy.RUNTIME, value); assertEquals(RetentionPolicy.RUNTIME, value);
@@ -348,9 +352,9 @@ public class AnnotationGenTest extends CodegenTestCase {
loadText("import java.lang.annotation.*\n" + loadText("import java.lang.annotation.*\n" +
"" + "" +
"@java.lang.annotation.Target(ElementType.TYPE, ElementType.METHOD) annotation class A"); "@java.lang.annotation.Target(ElementType.TYPE, ElementType.METHOD) annotation class A");
Class aClass = generateClass("A"); Class<?> aClass = generateClass("A");
Target annotation = (Target)aClass.getAnnotation(Target.class); Target annotation = aClass.getAnnotation(Target.class);
ElementType[] value = annotation.value(); ElementType[] value = annotation.value();
assertEquals(2, value.length); assertEquals(2, value.length);
@@ -372,7 +376,8 @@ public class AnnotationGenTest extends CodegenTestCase {
"@Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<Retention>)\n" + "@Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<Retention>)\n" +
"" + "" +
"@A(arrayOf(Retention(RetentionPolicy.RUNTIME),Retention(RetentionPolicy.SOURCE))) class B()"); "@A(arrayOf(Retention(RetentionPolicy.RUNTIME),Retention(RetentionPolicy.SOURCE))) class B()");
Class aClass = generateClass("A"); @SuppressWarnings("unchecked")
Class<? extends Annotation> aClass = (Class) generateClass("A");
Method[] methods = aClass.getDeclaredMethods(); Method[] methods = aClass.getDeclaredMethods();
assertEquals(1, methods.length); assertEquals(1, methods.length);
@@ -168,9 +168,9 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja
@Nullable @Nullable
@Override @Override
@SuppressWarnings("unchecked")
public <V> V getUserData(UserDataKey<V> key) { public <V> V getUserData(UserDataKey<V> key) {
if (singleUserData != null && singleUserData.getFirst().equals(key)) { if (singleUserData != null && singleUserData.getFirst().equals(key)) {
//noinspection unchecked
return (V) singleUserData.getSecond(); return (V) singleUserData.getSecond();
} }
@@ -261,9 +261,9 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
} }
@Override @Override
@SuppressWarnings("unchecked")
public <V> V getUserData(UserDataKey<V> key) { public <V> V getUserData(UserDataKey<V> key) {
if (userDataMap == null) return null; if (userDataMap == null) return null;
//noinspection unchecked
return (V) userDataMap.get(key); return (V) userDataMap.get(key);
} }
@@ -273,8 +273,8 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
} }
@Override @Override
@SuppressWarnings("unchecked")
public void setOverriddenDescriptors(@NotNull Collection<? extends CallableMemberDescriptor> overriddenDescriptors) { public void setOverriddenDescriptors(@NotNull Collection<? extends CallableMemberDescriptor> overriddenDescriptors) {
//noinspection unchecked
overriddenFunctions = (Collection<? extends FunctionDescriptor>) overriddenDescriptors; overriddenFunctions = (Collection<? extends FunctionDescriptor>) overriddenDescriptors;
for (FunctionDescriptor function : overriddenFunctions) { for (FunctionDescriptor function : overriddenFunctions) {
if (function.isHiddenForResolutionEverywhereBesideSupercalls()) { if (function.isHiddenForResolutionEverywhereBesideSupercalls()) {
@@ -522,8 +522,8 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
} }
@Override @Override
@SuppressWarnings("unchecked")
public void setOverriddenDescriptors(@NotNull Collection<? extends CallableMemberDescriptor> overriddenDescriptors) { public void setOverriddenDescriptors(@NotNull Collection<? extends CallableMemberDescriptor> overriddenDescriptors) {
//noinspection unchecked
this.overriddenProperties = (Collection<? extends PropertyDescriptor>) overriddenDescriptors; this.overriddenProperties = (Collection<? extends PropertyDescriptor>) overriddenDescriptors;
} }
@@ -126,8 +126,8 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
@NotNull @NotNull
@Override @Override
@SuppressWarnings("unchecked")
public CopyBuilder<? extends SimpleFunctionDescriptor> newCopyBuilder() { public CopyBuilder<? extends SimpleFunctionDescriptor> newCopyBuilder() {
//noinspection unchecked
return (CopyBuilder<? extends SimpleFunctionDescriptor>) super.newCopyBuilder(); return (CopyBuilder<? extends SimpleFunctionDescriptor>) super.newCopyBuilder();
} }
} }
@@ -6,6 +6,7 @@
package kotlin.reflect.jvm.internal; package kotlin.reflect.jvm.internal;
/* package */ class Util { /* package */ class Util {
@SuppressWarnings("unchecked")
public static Object getEnumConstantByName(Class<? extends Enum<?>> enumClass, String name) { public static Object getEnumConstantByName(Class<? extends Enum<?>> enumClass, String name) {
// This is a workaround for KT-5191. Enum#valueOf cannot be called in Kotlin // This is a workaround for KT-5191. Enum#valueOf cannot be called in Kotlin
return Enum.valueOf((Class) enumClass, name); return Enum.valueOf((Class) enumClass, name);
@@ -28,13 +28,13 @@ abstract class AbstractNode extends HasMetadata implements JsNode {
return out.toString(); return out.toString();
} }
@SuppressWarnings("unchecked")
protected <T extends HasMetadata & JsNode> T withMetadataFrom(T other) { protected <T extends HasMetadata & JsNode> T withMetadataFrom(T other) {
this.copyMetadataFrom(other); this.copyMetadataFrom(other);
Object otherSource = other.getSource(); Object otherSource = other.getSource();
if (otherSource != null) { if (otherSource != null) {
source(otherSource); source(otherSource);
} }
//noinspection unchecked
return (T) this; return (T) this;
} }
} }
@@ -100,6 +100,7 @@ public class JsFor extends SourceInfoAwareJsNode implements JsLoop {
} }
@Override @Override
@SuppressWarnings("unchecked")
public void traverse(JsVisitorWithContext v, JsContext ctx) { public void traverse(JsVisitorWithContext v, JsContext ctx) {
if (v.visit(this, ctx)) { if (v.visit(this, ctx)) {
assert (!(initExpression != null && initVars != null)); assert (!(initExpression != null && initVars != null));
@@ -48,10 +48,10 @@ public abstract class JsVisitorWithContext {
doAcceptList(collection); doAcceptList(collection);
} }
@SuppressWarnings("unchecked")
public final <T extends JsStatement> T acceptStatement(T statement) { public final <T extends JsStatement> T acceptStatement(T statement) {
if (statement == null) return null; if (statement == null) return null;
//noinspection unchecked
return (T) doAcceptStatement(statement); return (T) doAcceptStatement(statement);
} }
@@ -7,9 +7,6 @@ package org.jetbrains.kotlin.js.util;
import com.intellij.util.SmartList; import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation;
import org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator;
import org.jetbrains.kotlin.js.backend.ast.JsExpression;
import org.jetbrains.kotlin.js.backend.ast.JsNode; import org.jetbrains.kotlin.js.backend.ast.JsNode;
import java.util.ArrayList; import java.util.ArrayList;
@@ -20,10 +17,10 @@ public final class AstUtil {
} }
@Nullable @Nullable
@SuppressWarnings("unchecked")
public static <T extends JsNode> T deepCopy(@Nullable T node) { public static <T extends JsNode> T deepCopy(@Nullable T node) {
if (node == null) return null; if (node == null) return null;
//noinspection unchecked
return (T) node.deepCopy(); return (T) node.deepCopy();
} }
@@ -10,7 +10,8 @@ import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.backend.common.CommonCoroutineCodegenUtilKt; import org.jetbrains.kotlin.backend.common.CommonCoroutineCodegenUtilKt;
import org.jetbrains.kotlin.config.*; import org.jetbrains.kotlin.config.CommonConfigurationKeysKt;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.descriptors.CallableDescriptor; import org.jetbrains.kotlin.descriptors.CallableDescriptor;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.FunctionDescriptor; import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
@@ -24,7 +25,6 @@ import org.jetbrains.kotlin.js.inline.context.FunctionContext;
import org.jetbrains.kotlin.js.inline.context.InliningContext; import org.jetbrains.kotlin.js.inline.context.InliningContext;
import org.jetbrains.kotlin.js.inline.context.NamingContext; import org.jetbrains.kotlin.js.inline.context.NamingContext;
import org.jetbrains.kotlin.js.inline.util.*; import org.jetbrains.kotlin.js.inline.util.*;
import org.jetbrains.kotlin.js.translate.expression.InlineMetadata;
import org.jetbrains.kotlin.resolve.inline.InlineStrategy; import org.jetbrains.kotlin.resolve.inline.InlineStrategy;
import java.util.*; import java.util.*;
@@ -303,7 +303,9 @@ public class JsInliner extends JsVisitorWithContextImpl {
@Override @Override
public void endVisit(@NotNull JsInvocation x, @NotNull JsContext ctx) { public void endVisit(@NotNull JsInvocation x, @NotNull JsContext ctx) {
if (hasToBeInlined(x)) { if (hasToBeInlined(x)) {
inline(x, ctx); @SuppressWarnings("unchecked")
JsContext<JsNode> context = (JsContext) ctx;
inline(x, context);
} }
JsCallInfo lastCallInfo = null; JsCallInfo lastCallInfo = null;
@@ -335,7 +337,7 @@ public class JsInliner extends JsVisitorWithContextImpl {
super.doAcceptStatementList(statements); super.doAcceptStatementList(statements);
} }
private void inline(@NotNull JsInvocation call, @NotNull JsContext context) { private void inline(@NotNull JsInvocation call, @NotNull JsContext<JsNode> context) {
DeclarationDescriptor callDescriptor = MetadataProperties.getDescriptor(call); DeclarationDescriptor callDescriptor = MetadataProperties.getDescriptor(call);
if (isSuspendWithCurrentContinuation(callDescriptor, if (isSuspendWithCurrentContinuation(callDescriptor,
CommonConfigurationKeysKt.getLanguageVersionSettings(config.getConfiguration()))) { CommonConfigurationKeysKt.getLanguageVersionSettings(config.getConfiguration()))) {
@@ -403,7 +405,7 @@ public class JsInliner extends JsVisitorWithContextImpl {
) { ) {
// Apparently we should avoid this trick when we implement fair support for crossinline // Apparently we should avoid this trick when we implement fair support for crossinline
Function<JsWrapperKey, Map<JsName, JsNameRef>> replacementGen = k -> { Function<JsWrapperKey, Map<JsName, JsNameRef>> replacementGen = k -> {
JsContext ctx = k.context; JsContext<JsStatement> ctx = k.context;
Map<JsName, JsNameRef> newReplacements = new HashMap<>(); Map<JsName, JsNameRef> newReplacements = new HashMap<>();
@@ -499,9 +501,11 @@ public class JsInliner extends JsVisitorWithContextImpl {
replaceIfNecessary(x, ctx); replaceIfNecessary(x, ctx);
} }
private void replaceIfNecessary(@NotNull JsExpression expression, @NotNull JsContext context) { private void replaceIfNecessary(@NotNull JsExpression expression, @NotNull JsContext ctx) {
JsName alias = MetadataProperties.getLocalAlias(expression); JsName alias = MetadataProperties.getLocalAlias(expression);
if (alias != null) { if (alias != null) {
@SuppressWarnings("unchecked")
JsContext<JsNode> context = (JsContext) ctx;
context.replaceMe(alias.makeRef()); context.replaceMe(alias.makeRef());
} }
} }
@@ -519,7 +523,7 @@ public class JsInliner extends JsVisitorWithContextImpl {
); );
} }
private void inlineSuspendWithCurrentContinuation(@NotNull JsInvocation call, @NotNull JsContext context) { private void inlineSuspendWithCurrentContinuation(@NotNull JsInvocation call, @NotNull JsContext<JsNode> context) {
JsExpression lambda = call.getArguments().get(0); JsExpression lambda = call.getArguments().get(0);
JsExpression continuationArg = call.getArguments().get(call.getArguments().size() - 1); JsExpression continuationArg = call.getArguments().get(call.getArguments().size() - 1);
@@ -632,10 +636,10 @@ public class JsInliner extends JsVisitorWithContextImpl {
} }
static class JsWrapperKey { static class JsWrapperKey {
final JsContext context; final JsContext<JsStatement> context;
private final JsFunction function; private final JsFunction function;
public JsWrapperKey(@NotNull JsContext context, @NotNull JsFunction function) { public JsWrapperKey(@NotNull JsContext<JsStatement> context, @NotNull JsFunction function) {
this.context = context; this.context = context;
this.function = function; this.function = function;
} }
@@ -210,6 +210,7 @@ public class Context {
return (Context) threadContexts.get(t); return (Context) threadContexts.get(t);
} }
@SuppressWarnings("unchecked")
private static void setThreadContext(Context cx) { private static void setThreadContext(Context cx) {
if (threadLocalCx != null) { if (threadLocalCx != null) {
try { try {
@@ -70,6 +70,7 @@ public class SourceMap3Builder implements SourceMapBuilder {
@Override @Override
public String build() { public String build() {
@SuppressWarnings("unchecked")
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
json.getProperties().put("version", new JsonNumber(3)); json.getProperties().put("version", new JsonNumber(3));
json.getProperties().put("file", new JsonString(generatedFile.getName())); json.getProperties().put("file", new JsonString(generatedFile.getName()));
@@ -49,14 +49,15 @@ public final class BindingUtils {
private BindingUtils() { private BindingUtils() {
} }
@SuppressWarnings("unchecked")
@NotNull @NotNull
static private <E extends PsiElement, D extends DeclarationDescriptor> private static <E extends PsiElement, D extends DeclarationDescriptor> D getDescriptorForExpression(
D getDescriptorForExpression(@NotNull BindingContext context, @NotNull E expression, Class<D> descriptorClass) { @NotNull BindingContext context, @NotNull E expression, Class<D> descriptorClass
) {
DeclarationDescriptor descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expression); DeclarationDescriptor descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expression);
assert descriptor != null; assert descriptor != null;
assert descriptorClass.isInstance(descriptor) assert descriptorClass.isInstance(descriptor)
: message(expression, expression.toString() + " expected to have of type" + descriptorClass.toString()); : message(expression, expression.toString() + " expected to have of type" + descriptorClass.toString());
//noinspection unchecked
return (D) descriptor; return (D) descriptor;
} }
@@ -10,6 +10,7 @@ import kotlin.reflect.KCallable;
import kotlin.reflect.KMutableProperty1; import kotlin.reflect.KMutableProperty1;
import kotlin.reflect.KProperty1; import kotlin.reflect.KProperty1;
@SuppressWarnings("unchecked")
public abstract class MutablePropertyReference1 extends MutablePropertyReference implements KMutableProperty1 { public abstract class MutablePropertyReference1 extends MutablePropertyReference implements KMutableProperty1 {
public MutablePropertyReference1() { public MutablePropertyReference1() {
} }
@@ -10,6 +10,7 @@ import kotlin.reflect.KCallable;
import kotlin.reflect.KMutableProperty2; import kotlin.reflect.KMutableProperty2;
import kotlin.reflect.KProperty2; import kotlin.reflect.KProperty2;
@SuppressWarnings("unchecked")
public abstract class MutablePropertyReference2 extends MutablePropertyReference implements KMutableProperty2 { public abstract class MutablePropertyReference2 extends MutablePropertyReference implements KMutableProperty2 {
@Override @Override
protected KCallable computeReflected() { protected KCallable computeReflected() {
@@ -9,6 +9,7 @@ import kotlin.SinceKotlin;
import kotlin.reflect.KCallable; import kotlin.reflect.KCallable;
import kotlin.reflect.KProperty1; import kotlin.reflect.KProperty1;
@SuppressWarnings("unchecked")
public abstract class PropertyReference1 extends PropertyReference implements KProperty1 { public abstract class PropertyReference1 extends PropertyReference implements KProperty1 {
public PropertyReference1() { public PropertyReference1() {
} }
@@ -9,6 +9,7 @@ import kotlin.SinceKotlin;
import kotlin.reflect.KCallable; import kotlin.reflect.KCallable;
import kotlin.reflect.KProperty2; import kotlin.reflect.KProperty2;
@SuppressWarnings("unchecked")
public abstract class PropertyReference2 extends PropertyReference implements KProperty2 { public abstract class PropertyReference2 extends PropertyReference implements KProperty2 {
@Override @Override
protected KCallable computeReflected() { protected KCallable computeReflected() {
@@ -5,9 +5,9 @@
package kotlin.jvm.internal; package kotlin.jvm.internal;
import java.lang.Object;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
public class SpreadBuilder { public class SpreadBuilder {
@@ -18,6 +18,7 @@ public class SpreadBuilder {
list = new ArrayList<Object>(size); list = new ArrayList<Object>(size);
} }
@SuppressWarnings("unchecked")
public void addSpread(Object container) { public void addSpread(Object container) {
if (container == null) return; if (container == null) return;
@@ -25,9 +26,7 @@ public class SpreadBuilder {
Object[] array = (Object[]) container; Object[] array = (Object[]) container;
if (array.length > 0) { if (array.length > 0) {
list.ensureCapacity(list.size() + array.length); list.ensureCapacity(list.size() + array.length);
for (Object element : array) { Collections.addAll(list, array);
list.add(element);
}
} }
} }
else if (container instanceof Collection) { else if (container instanceof Collection) {