get rid of AstUtil
This commit is contained in:
committed by
Pavel V. Talanov
parent
7064ccd320
commit
197d1d7a85
@@ -11,7 +11,6 @@ import org.jetbrains.jet.j2k.ast.Enum
|
||||
import org.jetbrains.jet.j2k.ast.types.ClassType
|
||||
import org.jetbrains.jet.j2k.ast.types.EmptyType
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import org.jetbrains.jet.j2k.visitors.*
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||
import java.util.*
|
||||
@@ -663,18 +662,18 @@ public open class Converter() {
|
||||
return false
|
||||
}
|
||||
|
||||
var typeMap: Map<String?, String?> = HashMap<String?, String?>()
|
||||
typeMap?.put(JAVA_LANG_BYTE, "byte")
|
||||
typeMap?.put(JAVA_LANG_SHORT, "short")
|
||||
typeMap?.put(JAVA_LANG_INTEGER, "int")
|
||||
typeMap?.put(JAVA_LANG_LONG, "long")
|
||||
typeMap?.put(JAVA_LANG_FLOAT, "float")
|
||||
typeMap?.put(JAVA_LANG_DOUBLE, "double")
|
||||
typeMap?.put(JAVA_LANG_CHARACTER, "char")
|
||||
var expectedStr: String? = expected.getCanonicalText()
|
||||
var actualStr: String? = actual.getCanonicalText()
|
||||
var o1: Boolean = AstUtil.getOrElse(typeMap, actualStr, "")?.equals(expectedStr)!!
|
||||
var o2: Boolean = AstUtil.getOrElse(typeMap, expectedStr, "")?.equals(actualStr)!!
|
||||
val typeMap: Map<String, String> = HashMap<String, String>()
|
||||
typeMap.put(JAVA_LANG_BYTE, "byte")
|
||||
typeMap.put(JAVA_LANG_SHORT, "short")
|
||||
typeMap.put(JAVA_LANG_INTEGER, "int")
|
||||
typeMap.put(JAVA_LANG_LONG, "long")
|
||||
typeMap.put(JAVA_LANG_FLOAT, "float")
|
||||
typeMap.put(JAVA_LANG_DOUBLE, "double")
|
||||
typeMap.put(JAVA_LANG_CHARACTER, "char")
|
||||
val expectedStr: String? = expected.getCanonicalText()
|
||||
val actualStr: String? = actual.getCanonicalText()
|
||||
val o1: Boolean = expectedStr == typeMap[actualStr]
|
||||
val o2: Boolean = actualStr == typeMap[expectedStr]
|
||||
return actualStr != expectedStr && (!(o1 xor o2))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||
import java.util.*
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
|
||||
public open class ArrayInitializerExpression(val `type` : Type, val initializers : List<Expression>) : Expression() {
|
||||
public override fun toKotlin() : String {
|
||||
@@ -16,12 +16,11 @@ public open class ArrayInitializerExpression(val `type` : Type, val initializers
|
||||
|
||||
private fun createArrayFunction() : String {
|
||||
var sType : String? = innerTypeStr()
|
||||
if (Node.PRIMITIVE_TYPES.contains(sType))
|
||||
{
|
||||
if (Node.PRIMITIVE_TYPES.contains(sType)) {
|
||||
return sType + "Array"
|
||||
}
|
||||
|
||||
return AstUtil.lowerFirstCharacter(`type`.convertedToNotNull().toKotlin())
|
||||
return StringUtil.decapitalize(`type`.convertedToNotNull().toKotlin())!!
|
||||
}
|
||||
|
||||
private fun innerTypeStr() : String {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import org.jetbrains.jet.j2k.ast.types.ArrayType
|
||||
import java.util.List
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.Arrays
|
||||
import java.util.List
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.LinkedList
|
||||
import java.util.List
|
||||
|
||||
|
||||
@@ -5,12 +5,10 @@ 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.Type
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.HashSet
|
||||
import java.util.LinkedList
|
||||
import java.util.List
|
||||
import java.util.Set
|
||||
import org.jetbrains.jet.j2k.util.AstUtil.*
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class Class(converter : Converter,
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.List
|
||||
import java.util.Set
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.List
|
||||
|
||||
public open class ExpressionList(val expressions: List<Expression>): Expression() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.LinkedList
|
||||
import java.util.List
|
||||
import java.util.Set
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.List
|
||||
|
||||
public open class File(val packageName: String,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.LinkedList
|
||||
import java.util.List
|
||||
import java.util.Set
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.List
|
||||
|
||||
public open class MethodCallExpression(val methodCall: Expression,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.List
|
||||
|
||||
public open class NewClassExpression(val name: Element,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.List
|
||||
|
||||
public open class ReferenceElement(val reference : Identifier, val types : List<Type>) : Element() {
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.Element
|
||||
import org.jetbrains.jet.j2k.ast.Identifier
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.Collections
|
||||
import java.util.List
|
||||
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.ast.Node;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class AstUtil {
|
||||
private AstUtil() {
|
||||
}
|
||||
|
||||
private static String join(@NotNull final String[] array, @Nullable final String delimiter) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
boolean haveDelimiter = (delimiter != null);
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
buffer.append(array[i]);
|
||||
|
||||
if (haveDelimiter && (i + 1) < array.length) {
|
||||
buffer.append(delimiter);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String joinNodes(@NotNull final List<? extends Node> nodes, final String delimiter) {
|
||||
return join(nodesToKotlin(nodes), delimiter);
|
||||
}
|
||||
|
||||
public static String join(@NotNull final List<String> array, final String delimiter) {
|
||||
return join(array.toArray(new String[array.size()]), delimiter);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> nodesToKotlin(@NotNull List<? extends Node> nodes) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
for (Node n : nodes)
|
||||
result.add(n.toKotlin());
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String upperFirstCharacter(@NotNull String string) {
|
||||
return string.substring(0, 1).toUpperCase() + string.substring(1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String lowerFirstCharacter(@NotNull String string) {
|
||||
return string.substring(0, 1).toLowerCase() + string.substring(1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> T getOrElse(@NotNull Map<T, T> map, @NotNull T e, @NotNull T orElse) {
|
||||
if (map.containsKey(e)) {
|
||||
return map.get(e);
|
||||
}
|
||||
return orElse;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,9 @@ import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.J2KConverterFlags
|
||||
import org.jetbrains.jet.j2k.ast.*
|
||||
import org.jetbrains.jet.j2k.ast.types.*
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.LinkedList
|
||||
import java.util.List
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
|
||||
public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisitor<Type>() {
|
||||
private var myResult : Type = EmptyType()
|
||||
@@ -22,7 +22,7 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
myResult = PrimitiveType(Identifier("Unit"))
|
||||
}
|
||||
else if (Node.PRIMITIVE_TYPES.contains(name)) {
|
||||
myResult = PrimitiveType(Identifier(AstUtil.upperFirstCharacter(name)))
|
||||
myResult = PrimitiveType(Identifier(StringUtil.capitalize(name)))
|
||||
}
|
||||
else {
|
||||
myResult = PrimitiveType(Identifier(name))
|
||||
|
||||
Reference in New Issue
Block a user