Refactor converter:
Remove unused flags
This commit is contained in:
@@ -41,21 +41,11 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
|||||||
|
|
||||||
private val dispatcher: Dispatcher = Dispatcher(this)
|
private val dispatcher: Dispatcher = Dispatcher(this)
|
||||||
|
|
||||||
private val flags: MutableSet<J2KConverterFlags?>? = Sets.newHashSet()
|
|
||||||
|
|
||||||
private val javaToKotlinClassMap: JavaToKotlinClassMap = JavaToKotlinClassMap.getInstance()
|
private val javaToKotlinClassMap: JavaToKotlinClassMap = JavaToKotlinClassMap.getInstance()
|
||||||
|
|
||||||
public var methodReturnType: PsiType? = null
|
public var methodReturnType: PsiType? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
public fun addFlag(flag: J2KConverterFlags): Boolean {
|
|
||||||
return flags?.add(flag)!!
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun hasFlag(flag: J2KConverterFlags): Boolean {
|
|
||||||
return flags?.contains(flag)!!
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setClassIdentifiers(identifiers: MutableSet<String>) {
|
public fun setClassIdentifiers(identifiers: MutableSet<String>) {
|
||||||
classIdentifiersSet = identifiers
|
classIdentifiersSet = identifiers
|
||||||
}
|
}
|
||||||
@@ -270,10 +260,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
|||||||
methodReturnType = method.getReturnType()
|
methodReturnType = method.getReturnType()
|
||||||
val identifier: Identifier = Identifier(method.getName())
|
val identifier: Identifier = Identifier(method.getName())
|
||||||
val returnType: Type = typeToType(method.getReturnType(), isAnnotatedAsNotNull(method.getModifierList()))
|
val returnType: Type = typeToType(method.getReturnType(), isAnnotatedAsNotNull(method.getModifierList()))
|
||||||
val body: Block = (if (hasFlag(J2KConverterFlags.SKIP_BODIES))
|
val body = blockToBlock(method.getBody(), notEmpty)
|
||||||
Block.EMPTY_BLOCK
|
|
||||||
else
|
|
||||||
blockToBlock(method.getBody(), notEmpty))
|
|
||||||
|
|
||||||
val params: Element = createFunctionParameters(method)
|
val params: Element = createFunctionParameters(method)
|
||||||
val typeParameters = elementsToElementList(method.getTypeParameters())
|
val typeParameters = elementsToElementList(method.getTypeParameters())
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.jet.j2k
|
|
||||||
|
|
||||||
|
|
||||||
public enum class J2KConverterFlags {
|
|
||||||
FULLY_QUALIFIED_TYPE_NAMES
|
|
||||||
SKIP_BODIES
|
|
||||||
SKIP_NON_PUBLIC_MEMBERS
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.jet.j2k.ast
|
package org.jetbrains.jet.j2k.ast
|
||||||
|
|
||||||
import org.jetbrains.jet.j2k.Converter
|
import org.jetbrains.jet.j2k.Converter
|
||||||
import org.jetbrains.jet.j2k.J2KConverterFlags
|
|
||||||
import org.jetbrains.jet.j2k.ast.types.ClassType
|
import org.jetbrains.jet.j2k.ast.types.ClassType
|
||||||
import org.jetbrains.jet.j2k.ast.types.Type
|
import org.jetbrains.jet.j2k.ast.types.Type
|
||||||
import java.util.HashSet
|
import java.util.HashSet
|
||||||
@@ -31,9 +30,7 @@ public open class Class(val converter: Converter,
|
|||||||
val extendsTypes: List<Type>,
|
val extendsTypes: List<Type>,
|
||||||
val baseClassParams: List<Expression>,
|
val baseClassParams: List<Expression>,
|
||||||
val implementsTypes: List<Type>,
|
val implementsTypes: List<Type>,
|
||||||
members: List<Node>) : Member(modifiers) {
|
val members: List<Node>) : Member(modifiers) {
|
||||||
val members = getMembers(members, converter)
|
|
||||||
|
|
||||||
open val TYPE: String
|
open val TYPE: String
|
||||||
get() = "class"
|
get() = "class"
|
||||||
|
|
||||||
@@ -145,24 +142,12 @@ public open class Class(val converter: Converter,
|
|||||||
typeParameterWhereToKotlin() +
|
typeParameterWhereToKotlin() +
|
||||||
bodyToKotlin()
|
bodyToKotlin()
|
||||||
|
|
||||||
class object {
|
|
||||||
open fun getMembers(members: List<Node>, converter: Converter): List<Node> {
|
|
||||||
if (converter.hasFlag(J2KConverterFlags.SKIP_NON_PUBLIC_MEMBERS)) {
|
|
||||||
return members.filter {
|
|
||||||
it is Comment ||
|
|
||||||
(it as Member).accessModifier() == Modifier.PUBLIC ||
|
|
||||||
(it as Member).accessModifier() == Modifier.PROTECTED
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return members
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getStatic(members: List<Node>): List<Node> {
|
private fun getStatic(members: List<Node>): List<Node> {
|
||||||
return members.filter { it is Member && it.isStatic() }
|
return members.filter { it is Member && it.isStatic() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNonStatic(members: List<Node>): List<Node> {
|
private fun getNonStatic(members: List<Node>): List<Node> {
|
||||||
return members.filterNot { it is Member && it.isStatic() }
|
return members.filterNot { it is Member && it.isStatic() }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.j2k.visitors
|
|||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.impl.source.PsiClassReferenceType
|
import com.intellij.psi.impl.source.PsiClassReferenceType
|
||||||
import org.jetbrains.jet.j2k.Converter
|
import org.jetbrains.jet.j2k.Converter
|
||||||
import org.jetbrains.jet.j2k.J2KConverterFlags
|
|
||||||
import org.jetbrains.jet.j2k.ast.*
|
import org.jetbrains.jet.j2k.ast.*
|
||||||
import org.jetbrains.jet.j2k.ast.types.*
|
import org.jetbrains.jet.j2k.ast.types.*
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
@@ -87,10 +86,6 @@ public open class TypeVisitor(private val myConverter: Converter) : PsiTypeVisit
|
|||||||
if (psiClass != null) {
|
if (psiClass != null) {
|
||||||
val qualifiedName: String? = psiClass.getQualifiedName()
|
val qualifiedName: String? = psiClass.getQualifiedName()
|
||||||
if (qualifiedName != null) {
|
if (qualifiedName != null) {
|
||||||
if (!qualifiedName.equals("java.lang.Object") && myConverter.hasFlag(J2KConverterFlags.FULLY_QUALIFIED_TYPE_NAMES)) {
|
|
||||||
return Identifier(qualifiedName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qualifiedName.equals(CommonClassNames.JAVA_LANG_ITERABLE)) {
|
if (qualifiedName.equals(CommonClassNames.JAVA_LANG_ITERABLE)) {
|
||||||
return Identifier(CommonClassNames.JAVA_LANG_ITERABLE)
|
return Identifier(CommonClassNames.JAVA_LANG_ITERABLE)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user