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
@@ -32,7 +32,7 @@ public class KtContainerNode extends KtElementImpl {
}
@Override // for visibility
protected PsiElement findChildByType(IElementType type) {
protected <T extends PsiElement> T findChildByType(IElementType type) {
return super.findChildByType(type);
}
}
@@ -43,6 +43,7 @@ public class KtElementImpl extends ASTWrapperPsiElement implements KtElement {
}
@Override
@SuppressWarnings("unchecked")
public final void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof KtVisitor) {
accept((KtVisitor) visitor, null);
@@ -81,6 +82,7 @@ public class KtElementImpl extends ASTWrapperPsiElement implements KtElement {
}
@Override
@SuppressWarnings("deprecation")
public PsiReference getReference() {
PsiReference[] references = getReferences();
if (references.length == 1) return references[0];
@@ -54,6 +54,7 @@ public class KtElementImplStub<T extends StubElement<?>> extends StubBasedPsiEle
}
@Override
@SuppressWarnings("unchecked")
public final void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof KtVisitor) {
accept((KtVisitor) visitor, null);
@@ -98,6 +99,7 @@ public class KtElementImplStub<T extends StubElement<?>> extends StubBasedPsiEle
}
@Override
@SuppressWarnings("deprecation")
public PsiReference getReference() {
PsiReference[] references = getReferences();
if (references.length == 1) return references[0];
@@ -91,6 +91,7 @@ public class KtLambdaExpression extends LazyParseablePsiElement implements KtExp
}
@Override
@SuppressWarnings("unchecked")
public final void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof KtVisitor) {
accept((KtVisitor) visitor, null);
@@ -266,10 +266,12 @@ public class KtPsiUtil {
}
@Nullable
@SafeVarargs
@Contract("null, _ -> null")
public static PsiElement getTopmostParentOfTypes(
@Nullable PsiElement element,
@NotNull Class<? extends PsiElement>... parentTypes) {
@NotNull Class<? extends PsiElement>... parentTypes
) {
if (element instanceof PsiFile) return null;
PsiElement answer = PsiTreeUtil.getParentOfType(element, parentTypes);
@@ -641,12 +643,13 @@ public class KtPsiUtil {
return parent;
}
@SafeVarargs
@SuppressWarnings("unchecked")
public static <T extends PsiElement> T getLastChildByType(@NotNull PsiElement root, @NotNull Class<? extends T>... elementTypes) {
PsiElement[] children = root.getChildren();
for (int i = children.length - 1; i >= 0; i--) {
if (PsiTreeUtil.instanceOf(children[i], elementTypes)) {
//noinspection unchecked
return (T) children[i];
}
}
@@ -37,13 +37,13 @@ public final class KtStubbedPsiUtil {
//TODO: contribute to idea PsiTreeUtil#getPsiOrStubParent
@Nullable
@SuppressWarnings("unchecked")
public static <T extends KtElement> T getPsiOrStubParent(
@NotNull PsiElement element,
@NotNull Class<T> declarationClass,
boolean strict
) {
if (!strict && declarationClass.isInstance(element)) {
//noinspection unchecked
return (T) element;
}
if (element instanceof KtElementImplStub) {
@@ -23,12 +23,11 @@ import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.KtAnnotationEntry;
import org.jetbrains.kotlin.psi.KtPsiUtil;
import org.jetbrains.kotlin.psi.KtValueArgumentList;
import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub;
import org.jetbrains.kotlin.psi.stubs.impl.KotlinAnnotationEntryStubImpl;
import org.jetbrains.kotlin.name.Name;
import java.io.IOException;
@@ -38,13 +37,14 @@ public class KtAnnotationEntryElementType extends KtStubElementType<KotlinAnnota
super(debugName, KtAnnotationEntry.class, KotlinAnnotationEntryStub.class);
}
@NotNull
@Override
public KotlinAnnotationEntryStub createStub(@NotNull KtAnnotationEntry psi, StubElement parentStub) {
Name shortName = psi.getShortName();
String resultName = shortName != null ? shortName.asString() : null;
KtValueArgumentList valueArgumentList = psi.getValueArgumentList();
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
@@ -58,7 +58,7 @@ public class KtAnnotationEntryElementType extends KtStubElementType<KotlinAnnota
public KotlinAnnotationEntryStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef text = dataStream.readName();
boolean hasValueArguments = dataStream.readBoolean();
return new KotlinAnnotationEntryStubImpl(parentStub, text, hasValueArguments);
return new KotlinAnnotationEntryStubImpl((StubElement<?>) parentStub, text, hasValueArguments);
}
@Override
@@ -52,15 +52,19 @@ public class KtClassElementType extends KtStubElementType<KotlinClassStub, KtCla
return node.getElementType() != KtStubElementTypes.ENUM_ENTRY ? new KtClass(node) : new KtEnumEntry(node);
}
@NotNull
@Override
public KotlinClassStub createStub(@NotNull KtClass psi, StubElement parentStub) {
FqName fqName = KtPsiUtilKt.safeFqNameForLazyResolve(psi);
boolean isEnumEntry = psi instanceof KtEnumEntry;
List<String> superNames = KtPsiUtilKt.getSuperNames(psi);
return new KotlinClassStubImpl(
getStubType(isEnumEntry), parentStub, StringRef.fromString(fqName != null ? fqName.asString() : null),
StringRef.fromString(psi.getName()), Utils.INSTANCE.wrapStrings(superNames), psi.isInterface(), isEnumEntry,
psi.isLocal(), psi.isTopLevel());
getStubType(isEnumEntry), (StubElement<?>) parentStub,
StringRef.fromString(fqName != null ? fqName.asString() : null),
StringRef.fromString(psi.getName()),
Utils.INSTANCE.wrapStrings(superNames),
psi.isInterface(), isEnumEntry, psi.isLocal(), psi.isTopLevel()
);
}
@Override
@@ -96,8 +100,10 @@ public class KtClassElementType extends KtStubElementType<KotlinClassStub, KtCla
superNames[i] = dataStream.readName();
}
return new KotlinClassStubImpl(getStubType(isEnumEntry), parentStub, qualifiedName, name, superNames,
isTrait, isEnumEntry, isLocal, isTopLevel);
return new KotlinClassStubImpl(
getStubType(isEnumEntry), (StubElement<?>) parentStub, qualifiedName, name, superNames,
isTrait, isEnumEntry, isLocal, isTopLevel
);
}
@Override
@@ -38,6 +38,7 @@ public class KtFunctionElementType extends KtStubElementType<KotlinFunctionStub,
super(debugName, KtNamedFunction.class, KotlinFunctionStub.class);
}
@NotNull
@Override
public KotlinFunctionStub createStub(@NotNull KtNamedFunction psi, @NotNull StubElement parentStub) {
boolean isTopLevel = psi.getParent() instanceof KtFile;
@@ -45,9 +46,11 @@ public class KtFunctionElementType extends KtStubElementType<KotlinFunctionStub,
FqName fqName = KtPsiUtilKt.safeFqNameForLazyResolve(psi);
boolean hasBlockBody = psi.hasBlockBody();
boolean hasBody = psi.hasBody();
return new KotlinFunctionStubImpl(parentStub, StringRef.fromString(psi.getName()), isTopLevel, fqName,
isExtension, hasBlockBody, hasBody, psi.hasTypeParameterListBeforeFunctionName(),
psi.mayHaveContract());
return new KotlinFunctionStubImpl(
(StubElement<?>) parentStub, StringRef.fromString(psi.getName()), isTopLevel, fqName,
isExtension, hasBlockBody, hasBody, psi.hasTypeParameterListBeforeFunctionName(),
psi.mayHaveContract()
);
}
@Override
@@ -80,8 +83,10 @@ public class KtFunctionElementType extends KtStubElementType<KotlinFunctionStub,
boolean hasTypeParameterListBeforeFunctionName = dataStream.readBoolean();
boolean mayHaveContract = dataStream.readBoolean();
return new KotlinFunctionStubImpl(parentStub, name, isTopLevel, fqName, isExtension, hasBlockBody, hasBody,
hasTypeParameterListBeforeFunctionName, mayHaveContract);
return new KotlinFunctionStubImpl(
(StubElement<?>) parentStub, name, isTopLevel, fqName, isExtension, hasBlockBody, hasBody,
hasTypeParameterListBeforeFunctionName, mayHaveContract
);
}
@Override
@@ -34,11 +34,12 @@ public class KtImportDirectiveElementType extends KtStubElementType<KotlinImport
super(debugName, KtImportDirective.class, KotlinImportDirectiveStub.class);
}
@NotNull
@Override
public KotlinImportDirectiveStub createStub(@NotNull KtImportDirective psi, StubElement parentStub) {
FqName importedFqName = psi.getImportedFqName();
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
@@ -55,6 +56,6 @@ public class KtImportDirectiveElementType extends KtStubElementType<KotlinImport
boolean isAllUnder = dataStream.readBoolean();
StringRef importedName = dataStream.readName();
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);
}
@NotNull
@Override
public KotlinObjectStub createStub(@NotNull KtObjectDeclaration psi, StubElement parentStub) {
String name = psi.getName();
FqName fqName = KtPsiUtilKt.safeFqNameForLazyResolve(psi);
List<String> superNames = KtPsiUtilKt.getSuperNames(psi);
return new KotlinObjectStubImpl(parentStub, StringRef.fromString(name), fqName, Utils.INSTANCE.wrapStrings(superNames),
psi.isTopLevel(), psi.isCompanion(), psi.isLocal(), psi.isObjectLiteral());
return new KotlinObjectStubImpl(
(StubElement<?>) parentStub, StringRef.fromString(name), fqName, Utils.INSTANCE.wrapStrings(superNames),
psi.isTopLevel(), psi.isCompanion(), psi.isLocal(), psi.isObjectLiteral()
);
}
@Override
@@ -84,7 +87,9 @@ public class KtObjectElementType extends KtStubElementType<KotlinObjectStub, KtO
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
@@ -23,10 +23,10 @@ import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.KtParameter;
import org.jetbrains.kotlin.psi.stubs.KotlinParameterStub;
import org.jetbrains.kotlin.psi.stubs.impl.KotlinParameterStubImpl;
import org.jetbrains.kotlin.name.FqName;
import java.io.IOException;
@@ -35,12 +35,15 @@ public class KtParameterElementType extends KtStubElementType<KotlinParameterStu
super(debugName, KtParameter.class, KotlinParameterStub.class);
}
@NotNull
@Override
public KotlinParameterStub createStub(@NotNull KtParameter psi, StubElement parentStub) {
FqName fqName = psi.getFqName();
StringRef fqNameRef = StringRef.fromString(fqName != null ? fqName.asString() : null);
return new KotlinParameterStubImpl(parentStub, fqNameRef, StringRef.fromString(psi.getName()),
psi.isMutable(), psi.hasValOrVar(), psi.hasDefaultValue());
return new KotlinParameterStubImpl(
(StubElement<?>) parentStub, fqNameRef, StringRef.fromString(psi.getName()),
psi.isMutable(), psi.hasValOrVar(), psi.hasDefaultValue()
);
}
@Override
@@ -62,7 +65,7 @@ public class KtParameterElementType extends KtStubElementType<KotlinParameterStu
boolean hasDefaultValue = dataStream.readBoolean();
StringRef fqName = dataStream.readName();
return new KotlinParameterStubImpl(parentStub, fqName, name, isMutable, hasValOrValNode, hasDefaultValue);
return new KotlinParameterStubImpl((StubElement<?>) parentStub, fqName, name, isMutable, hasValOrValNode, hasDefaultValue);
}
@Override
@@ -36,6 +36,7 @@ public class KtPropertyElementType extends KtStubElementType<KotlinPropertyStub,
super(debugName, KtProperty.class, KotlinPropertyStub.class);
}
@NotNull
@Override
public KotlinPropertyStub createStub(@NotNull KtProperty psi, StubElement parentStub) {
assert !psi.isLocal() :
@@ -43,7 +44,7 @@ public class KtPropertyElementType extends KtStubElementType<KotlinPropertyStub,
psi.getText(), psi.getParent() != null ? psi.getParent().getText() : "<no parent>");
return new KotlinPropertyStubImpl(
parentStub, StringRef.fromString(psi.getName()),
(StubElement<?>) parentStub, StringRef.fromString(psi.getName()),
psi.isVar(), psi.isTopLevel(), psi.hasDelegate(),
psi.hasDelegateExpression(), psi.hasInitializer(),
psi.getReceiverTypeReference() != null, psi.getTypeReference() != null,
@@ -81,9 +82,10 @@ public class KtPropertyElementType extends KtStubElementType<KotlinPropertyStub,
StringRef fqNameAsString = dataStream.readName();
FqName fqName = fqNameAsString != null ? new FqName(fqNameAsString.toString()) : null;
return new KotlinPropertyStubImpl(parentStub, name, isVar, isTopLevel, hasDelegate,
hasDelegateExpression, hasInitializer, hasReceiverTypeRef, hasReturnTypeRef,
fqName);
return new KotlinPropertyStubImpl(
(StubElement<?>) parentStub, name, isVar, isTopLevel, hasDelegate, hasDelegateExpression, hasInitializer,
hasReceiverTypeRef, hasReturnTypeRef, fqName
);
}
@Override
@@ -47,6 +47,7 @@ public abstract class KtStubElementType<StubT extends StubElement, PsiT extends
@NotNull
private final ArrayFactory<PsiT> arrayFactory;
@SuppressWarnings("unchecked")
public KtStubElementType(@NotNull @NonNls String debugName, @NotNull Class<PsiT> psiClass, @NotNull Class<?> stubClass) {
super(debugName, KotlinLanguage.INSTANCE);
try {
@@ -56,13 +57,11 @@ public abstract class KtStubElementType<StubT extends StubElement, PsiT extends
catch (NoSuchMethodException e) {
throw new RuntimeException("Stub element type declaration for " + psiClass.getSimpleName() + " is missing required constructors",e);
}
//noinspection unchecked
emptyArray = (PsiT[]) Array.newInstance(psiClass, 0);
arrayFactory = count -> {
if (count == 0) {
return emptyArray;
}
//noinspection unchecked
return (PsiT[]) Array.newInstance(psiClass, count);
};
}
@@ -34,10 +34,13 @@ public class KtTypeParameterElementType extends KtStubElementType<KotlinTypePara
super(debugName, KtTypeParameter.class, KotlinTypeParameterStub.class);
}
@NotNull
@Override
public KotlinTypeParameterStub createStub(@NotNull KtTypeParameter psi, StubElement parentStub) {
return new KotlinTypeParameterStubImpl(parentStub, StringRef.fromString(psi.getName()),
psi.getVariance() == Variance.IN_VARIANCE, psi.getVariance() == Variance.OUT_VARIANCE);
return new KotlinTypeParameterStubImpl(
(StubElement<?>) parentStub, StringRef.fromString(psi.getName()),
psi.getVariance() == Variance.IN_VARIANCE, psi.getVariance() == Variance.OUT_VARIANCE
);
}
@Override
@@ -54,6 +57,6 @@ public class KtTypeParameterElementType extends KtStubElementType<KotlinTypePara
boolean isInVariance = 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.impl.KotlinUserTypeStubImpl;
import java.io.IOException;
public class KtUserTypeElementType extends KtStubElementType<KotlinUserTypeStub, KtUserType> {
public KtUserTypeElementType(@NotNull @NonNls String debugName) {
super(debugName, KtUserType.class, KotlinUserTypeStub.class);
}
@NotNull
@Override
public KotlinUserTypeStub createStub(@NotNull KtUserType psi, StubElement parentStub) {
return new KotlinUserTypeStubImpl(parentStub);
return new KotlinUserTypeStubImpl((StubElement<?>) parentStub);
}
@Override
public void serialize(@NotNull KotlinUserTypeStub stub, @NotNull StubOutputStream dataStream) throws IOException {
public void serialize(@NotNull KotlinUserTypeStub stub, @NotNull StubOutputStream dataStream) {
}
@NotNull
@Override
public KotlinUserTypeStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
return new KotlinUserTypeStubImpl(parentStub);
public KotlinUserTypeStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) {
return new KotlinUserTypeStubImpl((StubElement<?>) parentStub);
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.psi.stubs.impl
import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.StubElement
import com.intellij.util.io.StringRef
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
class KotlinImportDirectiveStubImpl(
parent: StubElement<PsiElement>,
parent: StubElement<*>,
private val isAllUnder: Boolean,
private val importedFqName: StringRef?,
private val isValid: Boolean