From c9499da055be5cdd057e78cf4fe7cb529e72c261 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 30 May 2012 19:11:06 +0200 Subject: [PATCH] to kotlin --- .../jet/j2k/visitors/ThisVisitor.java | 56 ------------------- .../jetbrains/jet/j2k/visitors/ThisVisitor.kt | 34 +++++++++++ 2 files changed, 34 insertions(+), 56 deletions(-) delete mode 100644 src/org/jetbrains/jet/j2k/visitors/ThisVisitor.java create mode 100644 src/org/jetbrains/jet/j2k/visitors/ThisVisitor.kt diff --git a/src/org/jetbrains/jet/j2k/visitors/ThisVisitor.java b/src/org/jetbrains/jet/j2k/visitors/ThisVisitor.java deleted file mode 100644 index 65954a86087..00000000000 --- a/src/org/jetbrains/jet/j2k/visitors/ThisVisitor.java +++ /dev/null @@ -1,56 +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.google.common.collect.Sets; -import com.intellij.psi.*; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Set; - -/** - * @author ignatov - */ -public class ThisVisitor extends JavaRecursiveElementVisitor { - @NotNull - private final Set myResolvedConstructors = Sets.newLinkedHashSet(); - - @Override - public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { - for (PsiReference r : expression.getReferences()) - if (r.getCanonicalText().equals("this")) { - final PsiElement res = r.resolve(); - if (res != null && res instanceof PsiMethod && ((PsiMethod) res).isConstructor()) { - myResolvedConstructors.add((PsiMethod) res); - } - } - } - - @Nullable - public PsiMethod getPrimaryConstructor() { - if (myResolvedConstructors.size() > 0) { - PsiMethod first = myResolvedConstructors.toArray(new PsiMethod[myResolvedConstructors.size()])[0]; - for (PsiMethod m : myResolvedConstructors) - if (m.hashCode() != first.hashCode()) { - return null; - } - return first; - } - return null; - } -} diff --git a/src/org/jetbrains/jet/j2k/visitors/ThisVisitor.kt b/src/org/jetbrains/jet/j2k/visitors/ThisVisitor.kt new file mode 100644 index 00000000000..13c29e60178 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/visitors/ThisVisitor.kt @@ -0,0 +1,34 @@ +package org.jetbrains.jet.j2k.visitors + +import com.intellij.psi.* +import org.jetbrains.annotations.Nullable +import java.util.Set +import java.util.LinkedHashSet + +public open class ThisVisitor(): JavaRecursiveElementVisitor() { + private val myResolvedConstructors: Set = LinkedHashSet() + + public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit { + for (r : PsiReference? in expression?.getReferences()) { + if (r?.getCanonicalText() == "this") { + val res: PsiElement? = r?.resolve() + if (res is PsiMethod && res.isConstructor()) { + myResolvedConstructors.add(res) + } + } + } + } + + public open fun getPrimaryConstructor(): PsiMethod? { + if (myResolvedConstructors.size() > 0) { + val first: PsiMethod = myResolvedConstructors.iterator().next() + for (m in myResolvedConstructors) + if (m.hashCode() != first.hashCode()) { + return null + } + + return first + } + return null + } +}