Fixed compiler warnings
Removed unnecessary !! operations, ?. calls and "out" declarations.
This commit is contained in:
committed by
Pavel V. Talanov
parent
1cab2d1245
commit
6576eb8ce3
@@ -60,7 +60,7 @@ public open class Converter() {
|
||||
}
|
||||
|
||||
public open fun getClassIdentifiers(): Set<String> {
|
||||
return Collections.unmodifiableSet(classIdentifiers)!!
|
||||
return Collections.unmodifiableSet(classIdentifiers)
|
||||
}
|
||||
|
||||
public open fun getMethodReturnType(): PsiType? {
|
||||
@@ -88,11 +88,11 @@ public open class Converter() {
|
||||
}
|
||||
|
||||
public open fun fileToFile(javaFile: PsiJavaFile): File {
|
||||
return fileToFile(javaFile, Collections.emptyList<String>()!!)
|
||||
return fileToFile(javaFile, Collections.emptyList<String>())
|
||||
}
|
||||
|
||||
public open fun fileToFileWithCompatibilityImport(javaFile: PsiJavaFile): File {
|
||||
return fileToFile(javaFile, Collections.singletonList("kotlin.compatibility.*")!!)
|
||||
return fileToFile(javaFile, Collections.singletonList("kotlin.compatibility.*"))
|
||||
}
|
||||
|
||||
private fun fileToFile(javaFile: PsiJavaFile, additionalImports: List<String>): File {
|
||||
@@ -218,20 +218,20 @@ public open class Converter() {
|
||||
}
|
||||
}
|
||||
}
|
||||
members.add(Constructor(Identifier.EMPTY_IDENTIFIER, arrayList(), Collections.emptySet<Modifier>()!!,
|
||||
ClassType(name, Collections.emptyList<Element>()!!, false),
|
||||
Collections.emptyList<Element>()!!,
|
||||
members.add(Constructor(Identifier.EMPTY_IDENTIFIER, arrayList(), Collections.emptySet<Modifier>(),
|
||||
ClassType(name, Collections.emptyList<Element>(), false),
|
||||
Collections.emptyList<Element>(),
|
||||
ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)),
|
||||
Block(createInitStatementsFromFields(finalOrWithEmptyInitializer)),
|
||||
true))
|
||||
}
|
||||
|
||||
if (psiClass.isInterface()) {
|
||||
return Trait(this, name, docComments, modifiers, typeParameters, extendsTypes, Collections.emptyList<Expression>()!!, implementsTypes, members)
|
||||
return Trait(this, name, docComments, modifiers, typeParameters, extendsTypes, Collections.emptyList<Expression>(), implementsTypes, members)
|
||||
}
|
||||
|
||||
if (psiClass.isEnum()) {
|
||||
return Enum(this, name, docComments, modifiers, typeParameters, Collections.emptyList<Type>()!!, Collections.emptyList<Expression>()!!, implementsTypes, members)
|
||||
return Enum(this, name, docComments, modifiers, typeParameters, Collections.emptyList<Type>(), Collections.emptyList<Expression>(), implementsTypes, members)
|
||||
}
|
||||
|
||||
return Class(this, name, docComments, modifiers, typeParameters, extendsTypes, baseClassParams, implementsTypes, members)
|
||||
@@ -242,7 +242,7 @@ public open class Converter() {
|
||||
}
|
||||
|
||||
private fun fieldsToFieldList(fields: Array<PsiField>, psiClass: PsiClass): List<Field> {
|
||||
return fields.map { fieldToField(it!!, psiClass) }
|
||||
return fields.map { fieldToField(it, psiClass) }
|
||||
}
|
||||
|
||||
private fun fieldToField(field: PsiField, psiClass: PsiClass?): Field {
|
||||
@@ -452,7 +452,7 @@ public open class Converter() {
|
||||
}
|
||||
|
||||
public open fun parametersToParameterList(parameters: Array<PsiParameter>): List<Parameter?> {
|
||||
return parameters.map { parameterToParameter(it!!) }
|
||||
return parameters.map { parameterToParameter(it) }
|
||||
}
|
||||
|
||||
public open fun parameterToParameter(parameter: PsiParameter, forceNotNull: Boolean = false): Parameter {
|
||||
@@ -534,7 +534,7 @@ public open class Converter() {
|
||||
return packageName.split("\\.").map { Identifier(it).toKotlin() }.makeString(".")
|
||||
}
|
||||
|
||||
private fun getFinalOrWithEmptyInitializer(fields: List<out Field>): List<Field> {
|
||||
private fun getFinalOrWithEmptyInitializer(fields: List<Field>): List<Field> {
|
||||
val result = ArrayList<Field>()
|
||||
for (f : Field in fields)
|
||||
if (f.isVal() || f.initializer.toKotlin().isEmpty()) {
|
||||
@@ -548,7 +548,7 @@ public open class Converter() {
|
||||
return fields.map { Parameter(Identifier("_" + it.identifier.name), it.`type`, true) }
|
||||
}
|
||||
|
||||
private fun createInitStatementsFromFields(fields: List<out Field>): List<Element> {
|
||||
private fun createInitStatementsFromFields(fields: List<Field>): List<Element> {
|
||||
val result = ArrayList<Element>()
|
||||
for (f : Field in fields) {
|
||||
val identifierToKotlin: String? = f.identifier.toKotlin()
|
||||
@@ -644,7 +644,7 @@ public open class Converter() {
|
||||
}
|
||||
|
||||
private fun isInheritFromObject(method: PsiMethod): Boolean {
|
||||
var superSignatures: List<HierarchicalMethodSignature?> = method.getHierarchicalMethodSignature().getSuperSignatures()!!
|
||||
var superSignatures: List<HierarchicalMethodSignature?> = method.getHierarchicalMethodSignature().getSuperSignatures()
|
||||
for (s : HierarchicalMethodSignature? in superSignatures) {
|
||||
var containingClass: PsiClass? = s?.getMethod()?.getContainingClass()
|
||||
var qualifiedName: String? = (if (containingClass != null)
|
||||
@@ -819,7 +819,7 @@ public fun isMainMethod(method: PsiMethod?): Boolean {
|
||||
if (parameters?.size!! != 1)
|
||||
return false
|
||||
|
||||
val `type`: PsiType? = parameters!![0]?.getType()
|
||||
val `type`: PsiType? = parameters!![0].getType()
|
||||
if (`type` !is PsiArrayType)
|
||||
return false
|
||||
|
||||
@@ -833,7 +833,7 @@ public fun countWritingAccesses(element: PsiElement?, container: PsiElement?): I
|
||||
val visitor: ReferenceCollector = ReferenceCollector()
|
||||
container.accept(visitor)
|
||||
for (e : PsiReferenceExpression in visitor.getCollectedReferences())
|
||||
if (e?.isReferenceTo(element)!! && PsiUtil.isAccessedForWriting(e)) {
|
||||
if (e.isReferenceTo(element) && PsiUtil.isAccessedForWriting(e)) {
|
||||
counter++
|
||||
}
|
||||
}
|
||||
@@ -864,7 +864,7 @@ public fun isAnnotatedAsNotNull(modifierList: PsiModifierList?): Boolean {
|
||||
if (modifierList != null) {
|
||||
val annotations: Array<PsiAnnotation> = modifierList.getAnnotations()
|
||||
for (a : PsiAnnotation in annotations) {
|
||||
val qualifiedName: String? = a?.getQualifiedName()
|
||||
val qualifiedName: String? = a.getQualifiedName()
|
||||
if (qualifiedName != null && Converter.NOT_NULL_ANNOTATIONS.contains(qualifiedName)) {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ public open class AnonymousClass(converter : Converter, members : List<Node>)
|
||||
: Class(converter,
|
||||
Identifier("anonClass"),
|
||||
arrayList(),
|
||||
Collections.emptySet<Modifier>()!!,
|
||||
Collections.emptyList<Element>()!!,
|
||||
Collections.emptyList<Type>()!!,
|
||||
Collections.emptyList<Expression>()!!,
|
||||
Collections.emptyList<Type>()!!, members) {
|
||||
Collections.emptySet<Modifier>(),
|
||||
Collections.emptyList<Element>(),
|
||||
Collections.emptyList<Type>(),
|
||||
Collections.emptyList<Expression>(),
|
||||
Collections.emptyList<Type>(), members) {
|
||||
public override fun toKotlin() = bodyToKotlin()
|
||||
}
|
||||
|
||||
@@ -48,10 +48,10 @@ public open class ArrayInitializerExpression(val `type` : Type, val initializers
|
||||
|
||||
class object {
|
||||
private open fun getConversion(afterReplace : String) : String {
|
||||
if (afterReplace.contains("double")!!)
|
||||
if (afterReplace.contains("double"))
|
||||
return "." + OperatorConventions.DOUBLE + "()"
|
||||
|
||||
if (afterReplace.contains("float")!!)
|
||||
if (afterReplace.contains("float"))
|
||||
return "." + OperatorConventions.FLOAT + "()"
|
||||
|
||||
return ""
|
||||
|
||||
@@ -7,11 +7,11 @@ public open class NewClassExpression(val name: Element,
|
||||
val qualifier: Expression = Expression.EMPTY_EXPRESSION,
|
||||
val anonymousClass: AnonymousClass? = null): Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
val callOperator: String? = (if (qualifier.isNullable()!!)
|
||||
val callOperator: String? = (if (qualifier.isNullable())
|
||||
"?."
|
||||
else
|
||||
".")
|
||||
val qualifier: String? = (if (qualifier.isEmpty()!!)
|
||||
val qualifier: String? = (if (qualifier.isEmpty())
|
||||
""
|
||||
else
|
||||
qualifier.toKotlin() + callOperator)
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.jetbrains.jet.j2k.ast.Identifier
|
||||
import java.util.Collections
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class ClassType(val `type` : Identifier, val parameters : List<out Element>, nullable : Boolean) : Type(nullable) {
|
||||
public open class ClassType(val `type` : Identifier, val parameters : List<Element>, nullable : Boolean) : Type(nullable) {
|
||||
public override fun toKotlin() : String {
|
||||
// TODO change to map() when KT-2051 is fixed
|
||||
val parametersToKotlin = ArrayList<String>()
|
||||
|
||||
@@ -41,7 +41,7 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
|
||||
myResult = ReferenceElement(Identifier(theReference.getReferenceName()!!), types)
|
||||
}
|
||||
else {
|
||||
var result : String = Identifier(reference?.getReferenceName()!!).toKotlin()
|
||||
var result : String = Identifier(reference.getReferenceName()!!).toKotlin()
|
||||
var qualifier : PsiElement? = theReference.getQualifier()
|
||||
while (qualifier != null)
|
||||
{
|
||||
@@ -59,7 +59,7 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
|
||||
|
||||
public override fun visitTypeParameter(classParameter : PsiTypeParameter?) : Unit {
|
||||
myResult = TypeParameter(Identifier(classParameter!!.getName()!!),
|
||||
classParameter!!.getExtendsListTypes().map { myConverter.typeToType(it) } )
|
||||
classParameter.getExtendsListTypes().map { myConverter.typeToType(it) } )
|
||||
}
|
||||
|
||||
public override fun visitParameterList(list : PsiParameterList?) : Unit {
|
||||
|
||||
@@ -167,7 +167,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
{
|
||||
return NewClassExpression(getConverter().elementToElement(classReference),
|
||||
getConverter().argumentsToExpressionList(expression!!),
|
||||
getConverter().expressionToExpression(expression?.getQualifier()),
|
||||
getConverter().expressionToExpression(expression.getQualifier()),
|
||||
(if (anonymousClass != null)
|
||||
getConverter().anonymousClassToAnonymousClass(anonymousClass)
|
||||
else
|
||||
@@ -178,7 +178,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
val typeParameters: List<Type> = (if (reference != null)
|
||||
getConverter().typesToTypeList(reference.getTypeParameters())
|
||||
else
|
||||
Collections.emptyList<Type>()!!)
|
||||
Collections.emptyList<Type>())
|
||||
return CallChainExpression(Identifier(constructor.getName(), false),
|
||||
MethodCallExpression(Identifier("init"), getConverter().expressionsToExpressionList(arguments), typeParameters, false))
|
||||
}
|
||||
@@ -199,7 +199,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
|
||||
public override fun visitPostfixExpression(expression: PsiPostfixExpression?): Unit {
|
||||
myResult = PostfixOperator(getOperatorString(expression!!.getOperationSign().getTokenType()!!),
|
||||
getConverter().expressionToExpression(expression?.getOperand()))
|
||||
getConverter().expressionToExpression(expression.getOperand()))
|
||||
}
|
||||
|
||||
public override fun visitPrefixExpression(expression: PsiPrefixExpression?): Unit {
|
||||
@@ -214,16 +214,16 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
}
|
||||
|
||||
public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit {
|
||||
val isFieldReference: Boolean = isFieldReference(expression!!, getContainingClass(expression!!))
|
||||
val insideSecondaryConstructor: Boolean = isInsideSecondaryConstructor(expression!!)
|
||||
val isFieldReference: Boolean = isFieldReference(expression!!, getContainingClass(expression))
|
||||
val insideSecondaryConstructor: Boolean = isInsideSecondaryConstructor(expression)
|
||||
val hasReceiver: Boolean = isFieldReference && insideSecondaryConstructor
|
||||
val isThis: Boolean = isThisExpression(expression!!)
|
||||
val isNullable: Boolean = getConverter().typeToType(expression?.getType()).nullable
|
||||
val className: String = getClassNameWithConstructor(expression!!)
|
||||
val referencedName = expression?.getReferenceName()!!
|
||||
val isThis: Boolean = isThisExpression(expression)
|
||||
val isNullable: Boolean = getConverter().typeToType(expression.getType()).nullable
|
||||
val className: String = getClassNameWithConstructor(expression)
|
||||
val referencedName = expression.getReferenceName()!!
|
||||
var identifier: Expression = Identifier(referencedName, isNullable)
|
||||
val __: String = "__"
|
||||
val qualifier = expression?.getQualifierExpression()
|
||||
val qualifier = expression.getQualifierExpression()
|
||||
if (hasReceiver){
|
||||
identifier = CallChainExpression(Identifier(__, false), Identifier(referencedName, isNullable))
|
||||
}
|
||||
@@ -234,11 +234,11 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
identifier = Identifier("size", isNullable)
|
||||
}
|
||||
else if (qualifier == null) {
|
||||
val resolved = expression?.getReference()?.resolve()
|
||||
val resolved = expression.getReference()?.resolve()
|
||||
if (resolved is PsiMember && resolved.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
resolved.getContainingClass() != null &&
|
||||
PsiTreeUtil.getParentOfType(expression, javaClass<PsiClass>()) != resolved.getContainingClass() &&
|
||||
!isStaticallyImported(resolved, expression!!)) {
|
||||
!isStaticallyImported(resolved, expression)) {
|
||||
var member = resolved as PsiMember
|
||||
var result = Identifier(referencedName).toKotlin()
|
||||
while(member.getContainingClass() != null) {
|
||||
|
||||
@@ -18,7 +18,7 @@ public open class ExpressionVisitorForDirectObjectInheritors(converter: Converte
|
||||
}
|
||||
else if (superMethodInvocation(methodExpression, "toString")) {
|
||||
myResult = DummyStringExpression(java.lang.String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())",
|
||||
ExpressionVisitor.getClassName(methodExpression))!!)
|
||||
ExpressionVisitor.getClassName(methodExpression)))
|
||||
}
|
||||
else {
|
||||
convertMethodCallExpression(expression!!)
|
||||
|
||||
@@ -83,7 +83,7 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
null)
|
||||
if (initialization is PsiDeclarationStatement && initialization.getFirstChild() == initialization.getLastChild() &&
|
||||
condition != null && update != null && update.getChildren().size == 1 &&
|
||||
(isPlusPlusExpression(update.getChildren()[0]!!)) && (operationTokenType == JavaTokenType.LT || operationTokenType == JavaTokenType.LE) &&
|
||||
(isPlusPlusExpression(update.getChildren()[0])) && (operationTokenType == JavaTokenType.LT || operationTokenType == JavaTokenType.LE) &&
|
||||
initialization.getFirstChild() != null && (initialization.getFirstChild() is PsiLocalVariable) &&
|
||||
firstChild != null && firstChild.getNameIdentifier() != null && onceWritableIterator) {
|
||||
val end: Expression = getConverter().expressionToExpression((condition as PsiBinaryExpression).getROperand())
|
||||
@@ -188,7 +188,7 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
val catchBlocks = statement?.getCatchBlocks()!!
|
||||
val catchBlockParameters = statement?.getCatchBlockParameters()!!
|
||||
for (i in 0..catchBlocks.size - 1) {
|
||||
catches.add(CatchStatement(getConverter().parameterToParameter(catchBlockParameters[i]!!, true),
|
||||
catches.add(CatchStatement(getConverter().parameterToParameter(catchBlockParameters[i], true),
|
||||
getConverter().blockToBlock(catchBlocks[i], true)))
|
||||
}
|
||||
myResult = TryStatement(getConverter().blockToBlock(statement?.getTryBlock(), true),
|
||||
|
||||
@@ -86,8 +86,8 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
for (p : PsiTypeParameter? in (resolve as PsiClass).getTypeParameters()) {
|
||||
val superTypes = p!!.getSuperTypes()
|
||||
val boundType : Type = (if (superTypes.size > 0)
|
||||
ClassType(Identifier(getClassTypeName(superTypes[0]!!)),
|
||||
myConverter.typesToTypeList(superTypes[0]!!.getParameters()),
|
||||
ClassType(Identifier(getClassTypeName(superTypes[0])),
|
||||
myConverter.typesToTypeList(superTypes[0].getParameters()),
|
||||
true)
|
||||
else
|
||||
StarProjectionType())
|
||||
@@ -101,11 +101,11 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
|
||||
public override fun visitWildcardType(wildcardType : PsiWildcardType?) : Type {
|
||||
if (wildcardType!!.isExtends()) {
|
||||
myResult = OutProjectionType(myConverter.typeToType(wildcardType!!.getExtendsBound()))
|
||||
myResult = OutProjectionType(myConverter.typeToType(wildcardType.getExtendsBound()))
|
||||
}
|
||||
else
|
||||
if (wildcardType!!.isSuper()) {
|
||||
myResult = InProjectionType(myConverter.typeToType(wildcardType?.getSuperBound()))
|
||||
if (wildcardType.isSuper()) {
|
||||
myResult = InProjectionType(myConverter.typeToType(wildcardType.getSuperBound()))
|
||||
}
|
||||
else {
|
||||
myResult = StarProjectionType()
|
||||
|
||||
Reference in New Issue
Block a user