to compilable kotlin
This commit is contained in:
committed by
Pavel V. Talanov
parent
ba16ad3c57
commit
39190533b1
@@ -138,14 +138,16 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
}
|
||||
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit {
|
||||
if (!SuperVisitor.isSuper(expression!!.getMethodExpression()) || !isInsidePrimaryConstructor(expression!!))
|
||||
{
|
||||
myResult = MethodCallExpression(getConverter().expressionToExpression(expression?.getMethodExpression()),
|
||||
getConverter().argumentsToExpressionList(expression!!),
|
||||
getConverter().typesToTypeList(expression?.getTypeArguments()!!),
|
||||
getConverter().typeToType(expression?.getType()).nullable)
|
||||
}
|
||||
convertMethodCallExpression(expression!!)
|
||||
}
|
||||
|
||||
protected fun convertMethodCallExpression(expression: PsiMethodCallExpression) {
|
||||
if (!SuperVisitor.isSuper(expression.getMethodExpression()) || !isInsidePrimaryConstructor(expression)) {
|
||||
myResult = MethodCallExpression(getConverter().expressionToExpression(expression.getMethodExpression()),
|
||||
getConverter().argumentsToExpressionList(expression),
|
||||
getConverter().typesToTypeList(expression.getTypeArguments()),
|
||||
getConverter().typeToType(expression.getType()).nullable)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitNewExpression(expression: PsiNewExpression?): Unit {
|
||||
|
||||
@@ -1,70 +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.visitors;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
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.Identifier;
|
||||
|
||||
import static com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ExpressionVisitorForDirectObjectInheritors extends ExpressionVisitor {
|
||||
public ExpressionVisitorForDirectObjectInheritors(@NotNull Converter converter) {
|
||||
super(converter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(@NotNull final PsiMethodCallExpression expression) {
|
||||
if (superMethodInvocation(expression.getMethodExpression(), "hashCode")) {
|
||||
myResult = new DummyMethodCallExpression(new Identifier("System"), "identityHashCode", new Identifier("this"));
|
||||
}
|
||||
else if (superMethodInvocation(expression.getMethodExpression(), "equals")) {
|
||||
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())));
|
||||
}
|
||||
else {
|
||||
super.visitMethodCallExpression(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReferenceExpression(@NotNull final PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
}
|
||||
|
||||
private static boolean superMethodInvocation(@NotNull final PsiReferenceExpression expression, final String methodName) {
|
||||
String referenceName = expression.getReferenceName();
|
||||
PsiExpression qualifierExpression = expression.getQualifierExpression();
|
||||
if (referenceName != null && referenceName.equals(methodName)) {
|
||||
if (qualifierExpression instanceof PsiSuperExpression) {
|
||||
PsiType type = qualifierExpression.getType();
|
||||
if (type != null && type.getCanonicalText().equals(JAVA_LANG_OBJECT)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.jetbrains.jet.j2k.visitors
|
||||
|
||||
import com.intellij.psi.*
|
||||
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.Identifier
|
||||
import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT
|
||||
|
||||
public open class ExpressionVisitorForDirectObjectInheritors(converter: Converter): ExpressionVisitor(converter) {
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit {
|
||||
val methodExpression = expression?.getMethodExpression()!!
|
||||
if (superMethodInvocation(methodExpression, "hashCode")) {
|
||||
myResult = DummyMethodCallExpression(Identifier("System"), "identityHashCode", Identifier("this"))
|
||||
}
|
||||
else if (superMethodInvocation(methodExpression, "equals")) {
|
||||
myResult = DummyMethodCallExpression(Identifier("this"), "identityEquals", getConverter().elementToElement(expression?.getArgumentList()))
|
||||
}
|
||||
else if (superMethodInvocation(methodExpression, "toString")) {
|
||||
myResult = DummyStringExpression(String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())", ExpressionVisitor.getClassName(methodExpression)))
|
||||
}
|
||||
else {
|
||||
convertMethodCallExpression(expression!!)
|
||||
}
|
||||
}
|
||||
|
||||
class object {
|
||||
private fun superMethodInvocation(expression: PsiReferenceExpression, methodName: String?): Boolean {
|
||||
val referenceName: String? = expression.getReferenceName()
|
||||
val qualifierExpression: PsiExpression? = expression.getQualifierExpression()
|
||||
if (referenceName == methodName && qualifierExpression is PsiSuperExpression) {
|
||||
val `type`: PsiType? = qualifierExpression.getType()
|
||||
if (`type` != null && `type`.getCanonicalText() == JAVA_LANG_OBJECT) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user