couple more classes converted
This commit is contained in:
committed by
Pavel V. Talanov
parent
d32aa47e72
commit
ee3eb05e7d
@@ -1,45 +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;
|
|
||||||
import org.jetbrains.jet.j2k.ast.types.Type;
|
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class ReferenceElement extends Element {
|
|
||||||
@NotNull
|
|
||||||
private final Identifier myReference;
|
|
||||||
@NotNull
|
|
||||||
private final List<Type> myTypes;
|
|
||||||
|
|
||||||
public ReferenceElement(@NotNull Identifier reference, @NotNull List<Type> types) {
|
|
||||||
myReference = reference;
|
|
||||||
myTypes = types;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
String typesIfNeeded = myTypes.size() > 0 ? "<" + AstUtil.joinNodes(myTypes, COMMA_WITH_SPACE) + ">" : EMPTY;
|
|
||||||
return myReference.toKotlin() + typesIfNeeded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
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() {
|
||||||
|
public override fun toKotlin() : String {
|
||||||
|
val typesIfNeeded : String = (if (types.size() > 0)
|
||||||
|
"<" + AstUtil.joinNodes(types, ", ") + ">"
|
||||||
|
else
|
||||||
|
"")
|
||||||
|
return reference.toKotlin() + typesIfNeeded
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,39 +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 SuperExpression extends Expression {
|
|
||||||
private final Identifier myIdentifier;
|
|
||||||
|
|
||||||
public SuperExpression(Identifier identifier) {
|
|
||||||
myIdentifier = identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
if (myIdentifier.isEmpty()) {
|
|
||||||
return "super";
|
|
||||||
}
|
|
||||||
return "super" + AT + myIdentifier.toKotlin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast
|
||||||
|
|
||||||
|
|
||||||
|
public open class SuperExpression(val identifier : Identifier) : Expression() {
|
||||||
|
public override fun toKotlin() : String {
|
||||||
|
if (identifier.isEmpty()) {
|
||||||
|
return "super"
|
||||||
|
}
|
||||||
|
return "super@" + identifier.toKotlin()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,124 +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.*;
|
|
||||||
import org.jetbrains.jet.j2k.ast.types.Type;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.jetbrains.jet.j2k.Converter.modifiersListToModifiersSet;
|
|
||||||
import static org.jetbrains.jet.j2k.ConverterUtil.isAnnotatedAsNotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class ElementVisitor extends JavaElementVisitor implements J2KVisitor {
|
|
||||||
|
|
||||||
private final Converter myConverter;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Element myResult = Element.EMPTY_ELEMENT;
|
|
||||||
|
|
||||||
public ElementVisitor(@NotNull Converter converter) {
|
|
||||||
this.myConverter = converter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public Converter getConverter() {
|
|
||||||
return myConverter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Element getResult() {
|
|
||||||
return myResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitLocalVariable(@NotNull PsiLocalVariable variable) {
|
|
||||||
super.visitLocalVariable(variable);
|
|
||||||
|
|
||||||
myResult = new LocalVariable(
|
|
||||||
new IdentifierImpl(variable.getName()), // TODO
|
|
||||||
modifiersListToModifiersSet(variable.getModifierList()),
|
|
||||||
getConverter().typeToType(variable.getType(), isAnnotatedAsNotNull(variable.getModifierList())),
|
|
||||||
getConverter().createSureCallOnlyForChain(variable.getInitializer(), variable.getType())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitExpressionList(@NotNull PsiExpressionList list) {
|
|
||||||
super.visitExpressionList(list);
|
|
||||||
myResult = new ExpressionList(
|
|
||||||
getConverter().expressionsToExpressionList(list.getExpressions()),
|
|
||||||
getConverter().typesToTypeList(list.getExpressionTypes())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement reference) {
|
|
||||||
super.visitReferenceElement(reference);
|
|
||||||
|
|
||||||
final List<Type> types = getConverter().typesToTypeList(reference.getTypeParameters());
|
|
||||||
if (!reference.isQualified()) {
|
|
||||||
myResult = new ReferenceElement(
|
|
||||||
new IdentifierImpl(reference.getReferenceName()),
|
|
||||||
types
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
String result = new IdentifierImpl(reference.getReferenceName()).toKotlin();
|
|
||||||
PsiElement qualifier = reference.getQualifier();
|
|
||||||
while (qualifier != null) {
|
|
||||||
final PsiJavaCodeReferenceElement p = (PsiJavaCodeReferenceElement) qualifier;
|
|
||||||
result = new IdentifierImpl(p.getReferenceName()).toKotlin() + "." + result; // TODO: maybe need to replace by safe call?
|
|
||||||
qualifier = p.getQualifier();
|
|
||||||
}
|
|
||||||
myResult = new ReferenceElement(
|
|
||||||
new IdentifierImpl(result),
|
|
||||||
types
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitTypeElement(@NotNull PsiTypeElement type) {
|
|
||||||
super.visitTypeElement(type);
|
|
||||||
myResult = new TypeElement(getConverter().typeToType(type.getType()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitTypeParameter(@NotNull PsiTypeParameter classParameter) {
|
|
||||||
super.visitTypeParameter(classParameter);
|
|
||||||
myResult = new TypeParameter(
|
|
||||||
new IdentifierImpl(classParameter.getName()), // TODO
|
|
||||||
getConverter().typesToTypeList(classParameter.getExtendsListTypes())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitParameterList(@NotNull PsiParameterList list) {
|
|
||||||
super.visitParameterList(list);
|
|
||||||
myResult = new ParameterList(
|
|
||||||
getConverter().parametersToParameterList(list.getParameters())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package org.jetbrains.jet.j2k.visitors
|
||||||
|
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import org.jetbrains.jet.j2k.Converter
|
||||||
|
import org.jetbrains.jet.j2k.ast.*
|
||||||
|
import org.jetbrains.jet.j2k.ast.types.Type
|
||||||
|
import java.util.List
|
||||||
|
import org.jetbrains.jet.j2k.Converter.modifiersListToModifiersSet
|
||||||
|
import org.jetbrains.jet.j2k.ConverterUtil.isAnnotatedAsNotNull
|
||||||
|
|
||||||
|
public open class ElementVisitor(val myConverter : Converter) : JavaElementVisitor(), J2KVisitor {
|
||||||
|
private var myResult : Element = Element.EMPTY_ELEMENT
|
||||||
|
|
||||||
|
public override fun getConverter() : Converter {
|
||||||
|
return myConverter
|
||||||
|
}
|
||||||
|
|
||||||
|
public open fun getResult() : Element {
|
||||||
|
return myResult
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun visitLocalVariable(variable : PsiLocalVariable?) : Unit {
|
||||||
|
val theVariable = variable!!
|
||||||
|
myResult = LocalVariable(IdentifierImpl(theVariable.getName()),
|
||||||
|
modifiersListToModifiersSet(theVariable.getModifierList()),
|
||||||
|
myConverter.typeToType(theVariable.getType(), isAnnotatedAsNotNull(theVariable.getModifierList())),
|
||||||
|
myConverter.createSureCallOnlyForChain(theVariable.getInitializer(), theVariable.getType()))
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun visitExpressionList(list : PsiExpressionList?) : Unit {
|
||||||
|
myResult = ExpressionList(myConverter.expressionsToExpressionList(list!!.getExpressions()),
|
||||||
|
myConverter.typesToTypeList(list!!.getExpressionTypes()))
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun visitReferenceElement(reference : PsiJavaCodeReferenceElement?) : Unit {
|
||||||
|
val theReference = reference!!
|
||||||
|
val types : List<Type> = myConverter.typesToTypeList(theReference.getTypeParameters()).requireNoNulls()
|
||||||
|
if (!theReference.isQualified()) {
|
||||||
|
myResult = ReferenceElement(IdentifierImpl(theReference.getReferenceName()), types)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var result : String = IdentifierImpl(reference?.getReferenceName()).toKotlin()
|
||||||
|
var qualifier : PsiElement? = theReference.getQualifier()
|
||||||
|
while (qualifier != null)
|
||||||
|
{
|
||||||
|
val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement)
|
||||||
|
result = IdentifierImpl(p.getReferenceName()).toKotlin() + "." + result
|
||||||
|
qualifier = p.getQualifier()
|
||||||
|
}
|
||||||
|
myResult = ReferenceElement(IdentifierImpl(result), types)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun visitTypeElement(`type` : PsiTypeElement?) : Unit {
|
||||||
|
myResult = TypeElement(myConverter.typeToType(`type`!!.getType()))
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun visitTypeParameter(classParameter : PsiTypeParameter?) : Unit {
|
||||||
|
myResult = TypeParameter(IdentifierImpl(classParameter!!.getName()),
|
||||||
|
classParameter!!.getExtendsListTypes().map { myConverter.typeToType(it) } )
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun visitParameterList(list : PsiParameterList?) : Unit {
|
||||||
|
myResult = ParameterList(myConverter.parametersToParameterList(list!!.getParameters()))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user