simplify class hierarchy
This commit is contained in:
committed by
Pavel V. Talanov
parent
07fcfe3b42
commit
3977db1472
@@ -108,7 +108,7 @@ public open class Converter() {
|
||||
val typeParameters: List<Element> = elementsToElementList(psiClass.getTypeParameters())
|
||||
val implementsTypes: List<Type> = typesToNotNullableTypeList(psiClass.getImplementsListTypes())
|
||||
val extendsTypes: List<Type> = typesToNotNullableTypeList(psiClass.getExtendsListTypes())
|
||||
val name: IdentifierImpl = IdentifierImpl(psiClass.getName())
|
||||
val name: Identifier = Identifier(psiClass.getName())
|
||||
val baseClassParams: List<Expression> = arrayList()
|
||||
val members: List<Member> = getMembers(psiClass)
|
||||
val visitor: SuperVisitor = SuperVisitor()
|
||||
@@ -188,10 +188,10 @@ public open class Converter() {
|
||||
private fun fieldToField(field: PsiField, psiClass: PsiClass?): Field {
|
||||
val modifiers: Set<String> = modifiersListToModifiersSet(field.getModifierList())
|
||||
if (field is PsiEnumConstant?) {
|
||||
return EnumConstant(IdentifierImpl(field.getName()), modifiers, typeToType(field.getType()), elementToElement(field.getArgumentList()))
|
||||
return EnumConstant(Identifier(field.getName()), modifiers, typeToType(field.getType()), elementToElement(field.getArgumentList()))
|
||||
}
|
||||
|
||||
return Field(IdentifierImpl(field.getName()),
|
||||
return Field(Identifier(field.getName()),
|
||||
modifiers,
|
||||
typeToType(field.getType()),
|
||||
expressionToExpression(field.getInitializer(), field.getType()),
|
||||
@@ -210,7 +210,7 @@ public open class Converter() {
|
||||
dispatcher.expressionVisitor = ExpressionVisitor(this)
|
||||
}
|
||||
methodReturnType = method.getReturnType()
|
||||
val identifier: IdentifierImpl = IdentifierImpl(method.getName())
|
||||
val identifier: Identifier = Identifier(method.getName())
|
||||
val returnType: Type = typeToType(method.getReturnType(), ConverterUtil.isAnnotatedAsNotNull(method.getModifierList()))
|
||||
val body: Block = (if (hasFlag(J2KConverterFlags.SKIP_BODIES))
|
||||
Block.EMPTY_BLOCK
|
||||
@@ -245,7 +245,7 @@ public open class Converter() {
|
||||
val result: List<Parameter> = arrayList()
|
||||
for (parameter : PsiParameter? in method.getParameterList().getParameters())
|
||||
{
|
||||
result.add(Parameter(IdentifierImpl(parameter?.getName()),
|
||||
result.add(Parameter(Identifier(parameter?.getName()),
|
||||
typeToType(parameter?.getType(),
|
||||
ConverterUtil.isAnnotatedAsNotNull(parameter?.getModifierList())),
|
||||
ConverterUtil.isReadOnly(parameter, method.getBody())))
|
||||
@@ -377,7 +377,7 @@ public open class Converter() {
|
||||
}
|
||||
|
||||
public open fun parameterToParameter(parameter: PsiParameter): Parameter {
|
||||
return Parameter(IdentifierImpl(parameter.getName()),
|
||||
return Parameter(Identifier(parameter.getName()),
|
||||
typeToType(parameter.getType(),
|
||||
ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList())), true)
|
||||
}
|
||||
@@ -409,7 +409,7 @@ public open class Converter() {
|
||||
|
||||
public open fun expressionToExpression(argument: PsiExpression?, expectedType: PsiType?): Expression {
|
||||
if (argument == null)
|
||||
return (Identifier.EMPTY_IDENTIFIER as IdentifierImpl)
|
||||
return Identifier.EMPTY_IDENTIFIER
|
||||
|
||||
var expression: Expression = expressionToExpression(argument)
|
||||
val actualType: PsiType? = argument.getType()
|
||||
@@ -424,7 +424,7 @@ public open class Converter() {
|
||||
var conversion: String? = PRIMITIVE_TYPE_CONVERSIONS.get(expectedType?.getCanonicalText())
|
||||
if (conversion != null)
|
||||
{
|
||||
expression = DummyMethodCallExpression(expression, conversion, (Identifier.EMPTY_IDENTIFIER as IdentifierImpl?))
|
||||
expression = DummyMethodCallExpression(expression, conversion, Identifier.EMPTY_IDENTIFIER)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -454,7 +454,7 @@ public open class Converter() {
|
||||
?.build()!!
|
||||
|
||||
private fun quoteKeywords(packageName: String): String {
|
||||
return packageName.split("\\.").map { IdentifierImpl(it).toKotlin() }.makeString(".")
|
||||
return packageName.split("\\.").map { Identifier(it).toKotlin() }.makeString(".")
|
||||
}
|
||||
|
||||
private fun getFinalOrWithEmptyInitializer(fields: List<out Field>): List<Field> {
|
||||
@@ -468,7 +468,7 @@ public open class Converter() {
|
||||
}
|
||||
|
||||
private fun createParametersFromFields(fields: List<Field>): List<Parameter> {
|
||||
return fields.map { Parameter(IdentifierImpl("_" + it.identifier.getName()), it.`type`, true) }
|
||||
return fields.map { Parameter(Identifier("_" + it.identifier.getName()), it.`type`, true) }
|
||||
}
|
||||
|
||||
private fun createInitStatementsFromFields(fields: List<out Field>): List<Statement> {
|
||||
@@ -628,7 +628,7 @@ public open class Converter() {
|
||||
if (identifier == null)
|
||||
return Identifier.EMPTY_IDENTIFIER
|
||||
|
||||
return IdentifierImpl(identifier?.getText())
|
||||
return Identifier(identifier?.getText())
|
||||
}
|
||||
|
||||
public open fun modifiersListToModifiersSet(modifierList: PsiModifierList?): Set<String> {
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.List
|
||||
|
||||
public open class AnonymousClass(converter : Converter, members : List<Member>)
|
||||
: Class(converter,
|
||||
IdentifierImpl("anonClass"),
|
||||
Identifier("anonClass"),
|
||||
Collections.emptySet<String>()!!,
|
||||
Collections.emptyList<Element>()!!,
|
||||
Collections.emptyList<Type>()!!,
|
||||
|
||||
@@ -66,12 +66,12 @@ public open class Class(converter : Converter,
|
||||
val modifiers : Set<String> = HashSet<String>(f.getModifiers())
|
||||
modifiers.add(Modifier.STATIC)
|
||||
val statements : List<Statement> = f.block?.statements ?: arrayList()
|
||||
statements.add(ReturnStatement(IdentifierImpl("__")))
|
||||
statements.add(ReturnStatement(Identifier("__")))
|
||||
val block : Block = Block(statements)
|
||||
val constructorTypeParameters : List<Element> = arrayList()
|
||||
constructorTypeParameters.addAll(typeParameters)
|
||||
constructorTypeParameters.addAll(f.typeParameters)
|
||||
return Function(IdentifierImpl("init"), modifiers, ClassType(name, constructorTypeParameters, false),
|
||||
return Function(Identifier("init"), modifiers, ClassType(name, constructorTypeParameters, false),
|
||||
constructorTypeParameters, f.params, block)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class ForeachWithRangeStatement extends Statement {
|
||||
private final Expression myStart;
|
||||
private final IdentifierImpl myIdentifier;
|
||||
private final Identifier myIdentifier;
|
||||
private final Expression myEnd;
|
||||
private final Statement myBody;
|
||||
|
||||
public ForeachWithRangeStatement(IdentifierImpl identifier, Expression start, Expression end, Statement body) {
|
||||
public ForeachWithRangeStatement(Identifier identifier, Expression start, Expression end, Statement body) {
|
||||
myStart = start;
|
||||
myIdentifier = identifier;
|
||||
myEnd = end;
|
||||
|
||||
@@ -1,27 +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.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public interface INode {
|
||||
@NotNull
|
||||
String toKotlin();
|
||||
}
|
||||
@@ -21,11 +21,57 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public interface Identifier extends INode {
|
||||
public class Identifier extends Expression {
|
||||
@NotNull
|
||||
Identifier EMPTY_IDENTIFIER = new IdentifierImpl("");
|
||||
public static Identifier EMPTY_IDENTIFIER = new Identifier("");
|
||||
|
||||
boolean isEmpty();
|
||||
private final String myName;
|
||||
private boolean myIsNullable = true;
|
||||
private boolean myQuotingNeeded = true;
|
||||
|
||||
String getName();
|
||||
public Identifier(String name) {
|
||||
myName = name;
|
||||
}
|
||||
|
||||
public Identifier(String name, boolean isNullable) {
|
||||
myName = name;
|
||||
myIsNullable = isNullable;
|
||||
}
|
||||
|
||||
public Identifier(String name, boolean isNullable, boolean quotingNeeded) {
|
||||
myName = name;
|
||||
myIsNullable = isNullable;
|
||||
myQuotingNeeded = quotingNeeded;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return myName.length() == 0;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String quote(String str) {
|
||||
return BACKTICK + str + BACKTICK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return myIsNullable;
|
||||
}
|
||||
|
||||
private String ifNeedQuote() {
|
||||
if (myQuotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(myName) || myName.contains("$"))) {
|
||||
return quote(myName);
|
||||
}
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return ifNeedQuote();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +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.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class IdentifierImpl extends Expression implements Identifier {
|
||||
private final String myName;
|
||||
private boolean myIsNullable = true;
|
||||
private boolean myQuotingNeeded = true;
|
||||
|
||||
public IdentifierImpl(String name) {
|
||||
myName = name;
|
||||
}
|
||||
|
||||
public IdentifierImpl(String name, boolean isNullable) {
|
||||
myName = name;
|
||||
myIsNullable = isNullable;
|
||||
}
|
||||
|
||||
public IdentifierImpl(String name, boolean isNullable, boolean quotingNeeded) {
|
||||
myName = name;
|
||||
myIsNullable = isNullable;
|
||||
myQuotingNeeded = quotingNeeded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return myName.length() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String quote(String str) {
|
||||
return BACKTICK + str + BACKTICK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return myIsNullable;
|
||||
}
|
||||
|
||||
private String ifNeedQuote() {
|
||||
if (myQuotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(myName) || myName.contains("$"))) {
|
||||
return quote(myName);
|
||||
}
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return ifNeedQuote();
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.eclipse.jdt.internal.core.search.StringOperation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -25,7 +26,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Node implements INode {
|
||||
public abstract class Node {
|
||||
@NotNull
|
||||
final static Set<String> ONLY_KOTLIN_KEYWORDS = new HashSet<String>(Arrays.asList(
|
||||
"package", "as", "type", "val", "var", "fun", "is", "in", "object", "when", "trait", "This"
|
||||
@@ -65,4 +66,7 @@ public abstract class Node implements INode {
|
||||
static final String STAR = "*";
|
||||
@NotNull
|
||||
protected static final String ZERO = "0";
|
||||
|
||||
@NotNull
|
||||
public abstract String toKotlin();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.INode
|
||||
|
||||
public open class ArrayType(val elementType : Type, nullable: Boolean) : Type(nullable) {
|
||||
public override fun toKotlin() : String {
|
||||
if (elementType is PrimitiveType) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.Element
|
||||
import org.jetbrains.jet.j2k.ast.INode
|
||||
|
||||
public abstract class Type(val nullable: Boolean) : Element() {
|
||||
public open fun convertedToNotNull() : Type {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.ast.INode
|
||||
|
||||
public open class VarArg(val `type` : Type) : Type(false) {
|
||||
public override fun toKotlin() : String = `type`.toKotlin()
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.jet.j2k.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.ast.INode;
|
||||
import org.jetbrains.jet.j2k.ast.Node;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -46,7 +46,7 @@ public class AstUtil {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String joinNodes(@NotNull final List<? extends INode> nodes, final String delimiter) {
|
||||
public static String joinNodes(@NotNull final List<? extends Node> nodes, final String delimiter) {
|
||||
return join(nodesToKotlin(nodes), delimiter);
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ public class AstUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> nodesToKotlin(@NotNull List<? extends INode> nodes) {
|
||||
public static List<String> nodesToKotlin(@NotNull List<? extends Node> nodes) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
for (INode n : nodes)
|
||||
for (Node n : nodes)
|
||||
result.add(n.toKotlin());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
|
||||
|
||||
public override fun visitLocalVariable(variable : PsiLocalVariable?) : Unit {
|
||||
val theVariable = variable!!
|
||||
myResult = LocalVariable(IdentifierImpl(theVariable.getName()),
|
||||
myResult = LocalVariable(Identifier(theVariable.getName()),
|
||||
Converter.modifiersListToModifiersSet(theVariable.getModifierList()),
|
||||
myConverter.typeToType(theVariable.getType(), isAnnotatedAsNotNull(theVariable.getModifierList())),
|
||||
myConverter.expressionToExpression(theVariable.getInitializer(), theVariable.getType()))
|
||||
@@ -34,18 +34,18 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
|
||||
val theReference = reference!!
|
||||
val types : List<Type> = myConverter.typesToTypeList(theReference.getTypeParameters()).requireNoNulls()
|
||||
if (!theReference.isQualified()) {
|
||||
myResult = ReferenceElement(IdentifierImpl(theReference.getReferenceName()), types)
|
||||
myResult = ReferenceElement(Identifier(theReference.getReferenceName()), types)
|
||||
}
|
||||
else {
|
||||
var result : String = IdentifierImpl(reference?.getReferenceName()).toKotlin()
|
||||
var result : String = Identifier(reference?.getReferenceName()).toKotlin()
|
||||
var qualifier : PsiElement? = theReference.getQualifier()
|
||||
while (qualifier != null)
|
||||
{
|
||||
val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement)
|
||||
result = IdentifierImpl(p.getReferenceName()).toKotlin() + "." + result
|
||||
result = Identifier(p.getReferenceName()).toKotlin() + "." + result
|
||||
qualifier = p.getQualifier()
|
||||
}
|
||||
myResult = ReferenceElement(IdentifierImpl(result), types)
|
||||
myResult = ReferenceElement(Identifier(result), types)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
|
||||
}
|
||||
|
||||
public override fun visitTypeParameter(classParameter : PsiTypeParameter?) : Unit {
|
||||
myResult = TypeParameter(IdentifierImpl(classParameter!!.getName()),
|
||||
myResult = TypeParameter(Identifier(classParameter!!.getName()),
|
||||
classParameter!!.getExtendsListTypes().map { myConverter.typeToType(it) } )
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
isQuotingNeeded = false;
|
||||
}
|
||||
}
|
||||
myResult = new LiteralExpression(new IdentifierImpl(text, false, isQuotingNeeded));
|
||||
myResult = new LiteralExpression(new Identifier(text, false, isQuotingNeeded));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -289,9 +289,9 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
? getConverter().typesToTypeList(reference.getTypeParameters())
|
||||
: Collections.<Type>emptyList();
|
||||
return new CallChainExpression(
|
||||
new IdentifierImpl(constructor.getName(), false),
|
||||
new Identifier(constructor.getName(), false),
|
||||
new MethodCallExpression(
|
||||
new IdentifierImpl("init"),
|
||||
new Identifier("init"),
|
||||
getConverter().expressionsToExpressionList(arguments),
|
||||
typeParameters, false));
|
||||
}
|
||||
@@ -353,14 +353,14 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
final boolean isNullable = getConverter().typeToType(expression.getType()).getNullable();
|
||||
final String className = getClassNameWithConstructor(expression);
|
||||
|
||||
Expression identifier = new IdentifierImpl(expression.getReferenceName(), isNullable);
|
||||
Expression identifier = new Identifier(expression.getReferenceName(), isNullable);
|
||||
|
||||
final String __ = "__";
|
||||
if (hasReceiver) {
|
||||
identifier = new CallChainExpression(new IdentifierImpl(__, false), new IdentifierImpl(expression.getReferenceName(), isNullable));
|
||||
identifier = new CallChainExpression(new Identifier(__, false), new Identifier(expression.getReferenceName(), isNullable));
|
||||
}
|
||||
else if (insideSecondaryConstructor && isThis) {
|
||||
identifier = new IdentifierImpl("val __ = " + className); // TODO: hack
|
||||
identifier = new Identifier("val __ = " + className); // TODO: hack
|
||||
}
|
||||
|
||||
myResult = new CallChainExpression(
|
||||
@@ -467,7 +467,7 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
final PsiJavaCodeReferenceElement qualifier = expression.getQualifier();
|
||||
myResult = new SuperExpression(
|
||||
qualifier != null ?
|
||||
new IdentifierImpl(qualifier.getQualifiedName()) :
|
||||
new Identifier(qualifier.getQualifiedName()) :
|
||||
Identifier.EMPTY_IDENTIFIER
|
||||
);
|
||||
}
|
||||
@@ -478,7 +478,7 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
final PsiJavaCodeReferenceElement qualifier = expression.getQualifier();
|
||||
myResult = new ThisExpression(
|
||||
qualifier != null ?
|
||||
new IdentifierImpl(qualifier.getQualifiedName()) :
|
||||
new Identifier(qualifier.getQualifiedName()) :
|
||||
Identifier.EMPTY_IDENTIFIER
|
||||
);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.j2k.Converter;
|
||||
import org.jetbrains.jet.j2k.ast.DummyMethodCallExpression;
|
||||
import org.jetbrains.jet.j2k.ast.DummyStringExpression;
|
||||
import org.jetbrains.jet.j2k.ast.IdentifierImpl;
|
||||
import org.jetbrains.jet.j2k.ast.Identifier;
|
||||
|
||||
import static com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT;
|
||||
|
||||
@@ -36,10 +36,10 @@ public class ExpressionVisitorForDirectObjectInheritors extends ExpressionVisito
|
||||
@Override
|
||||
public void visitMethodCallExpression(@NotNull final PsiMethodCallExpression expression) {
|
||||
if (superMethodInvocation(expression.getMethodExpression(), "hashCode")) {
|
||||
myResult = new DummyMethodCallExpression(new IdentifierImpl("System"), "identityHashCode", new IdentifierImpl("this"));
|
||||
myResult = new DummyMethodCallExpression(new Identifier("System"), "identityHashCode", new Identifier("this"));
|
||||
}
|
||||
else if (superMethodInvocation(expression.getMethodExpression(), "equals")) {
|
||||
myResult = new DummyMethodCallExpression(new IdentifierImpl("this"), "identityEquals", getConverter().elementToElement(expression.getArgumentList()));
|
||||
myResult = new DummyMethodCallExpression(new Identifier("this"), "identityEquals", getConverter().elementToElement(expression.getArgumentList()));
|
||||
}
|
||||
else if (superMethodInvocation(expression.getMethodExpression(), "toString")) {
|
||||
myResult = new DummyStringExpression(String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())", getClassName(expression.getMethodExpression())));
|
||||
|
||||
@@ -164,10 +164,10 @@ public class StatementVisitor extends ElementVisitor {
|
||||
) {
|
||||
final Expression end = getConverter().expressionToExpression(((PsiBinaryExpression) condition).getROperand());
|
||||
final Expression endExpression = operationTokenType == JavaTokenType.LT ?
|
||||
new BinaryExpression(end, new IdentifierImpl("1"), "-") :
|
||||
new BinaryExpression(end, new Identifier("1"), "-") :
|
||||
end;
|
||||
myResult = new ForeachWithRangeStatement(
|
||||
new IdentifierImpl(firstChild.getName()),
|
||||
new org.jetbrains.jet.j2k.ast.Identifier(firstChild.getName()),
|
||||
getConverter().expressionToExpression(firstChild.getInitializer()),
|
||||
endExpression,
|
||||
getConverter().statementToStatement(body)
|
||||
|
||||
@@ -18,15 +18,14 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
|
||||
public override fun visitPrimitiveType(primitiveType: PsiPrimitiveType?) : Type {
|
||||
val name : String = primitiveType?.getCanonicalText()!!
|
||||
val identifier : IdentifierImpl = IdentifierImpl(name)
|
||||
if (name == "void") {
|
||||
myResult = PrimitiveType(IdentifierImpl("Unit"))
|
||||
myResult = PrimitiveType(Identifier("Unit"))
|
||||
}
|
||||
else if (Node.PRIMITIVE_TYPES.contains(name)) {
|
||||
myResult = PrimitiveType(IdentifierImpl(AstUtil.upperFirstCharacter(name)))
|
||||
myResult = PrimitiveType(Identifier(AstUtil.upperFirstCharacter(name)))
|
||||
}
|
||||
else {
|
||||
myResult = PrimitiveType(identifier)
|
||||
myResult = PrimitiveType(Identifier(name))
|
||||
}
|
||||
return myResult
|
||||
}
|
||||
@@ -41,7 +40,7 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
|
||||
public override fun visitClassType(classType : PsiClassType?) : Type {
|
||||
if (classType == null) return myResult
|
||||
val identifier : IdentifierImpl = constructClassTypeIdentifier(classType)
|
||||
val identifier : Identifier = constructClassTypeIdentifier(classType)
|
||||
val resolvedClassTypeParams : List<Type> = createRawTypesForResolvedReference(classType)
|
||||
if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0) {
|
||||
myResult = ClassType(identifier, resolvedClassTypeParams, true)
|
||||
@@ -52,21 +51,21 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
return myResult
|
||||
}
|
||||
|
||||
private fun constructClassTypeIdentifier(classType : PsiClassType) : IdentifierImpl {
|
||||
private fun constructClassTypeIdentifier(classType : PsiClassType) : Identifier {
|
||||
val psiClass : PsiClass? = classType.resolve()
|
||||
if (psiClass != null) {
|
||||
val qualifiedName: String? = psiClass.getQualifiedName()
|
||||
if (qualifiedName != null) {
|
||||
if (!qualifiedName.equals("java.lang.Object") && myConverter.hasFlag(J2KConverterFlags.FULLY_QUALIFIED_TYPE_NAMES)) {
|
||||
return IdentifierImpl(qualifiedName)
|
||||
return Identifier(qualifiedName)
|
||||
}
|
||||
|
||||
if (qualifiedName.equals(CommonClassNames.JAVA_LANG_ITERABLE)) {
|
||||
return IdentifierImpl(CommonClassNames.JAVA_LANG_ITERABLE)
|
||||
return Identifier(CommonClassNames.JAVA_LANG_ITERABLE)
|
||||
}
|
||||
|
||||
if (qualifiedName.equals(CommonClassNames.JAVA_UTIL_ITERATOR)) {
|
||||
return IdentifierImpl(CommonClassNames.JAVA_UTIL_ITERATOR)
|
||||
return Identifier(CommonClassNames.JAVA_UTIL_ITERATOR)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,10 +73,10 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
val classTypeName : String? = createQualifiedName(classType)
|
||||
if (classTypeName?.isEmpty().sure())
|
||||
{
|
||||
return IdentifierImpl(getClassTypeName(classType))
|
||||
return Identifier(getClassTypeName(classType))
|
||||
}
|
||||
|
||||
return IdentifierImpl(classTypeName)
|
||||
return Identifier(classTypeName)
|
||||
}
|
||||
|
||||
private fun createRawTypesForResolvedReference(classType : PsiClassType) : List<Type> {
|
||||
@@ -89,7 +88,7 @@ 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(IdentifierImpl(getClassTypeName(superTypes[0]!!)),
|
||||
ClassType(Identifier(getClassTypeName(superTypes[0]!!)),
|
||||
myConverter.typesToTypeList(superTypes[0]!!.getParameters()).requireNoNulls(),
|
||||
true)
|
||||
else
|
||||
@@ -130,12 +129,12 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
val reference : PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference()
|
||||
if (reference != null && reference.isQualified())
|
||||
{
|
||||
var result : String = IdentifierImpl(reference.getReferenceName()).toKotlin()
|
||||
var result : String = Identifier(reference.getReferenceName()).toKotlin()
|
||||
var qualifier : PsiElement? = reference.getQualifier()
|
||||
while (qualifier != null)
|
||||
{
|
||||
val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement)
|
||||
result = IdentifierImpl(p.getReferenceName()).toKotlin() + "." + result
|
||||
result = Identifier(p.getReferenceName()).toKotlin() + "." + result
|
||||
qualifier = p.getQualifier()
|
||||
}
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user