Java Uast: Support static imports

This commit is contained in:
Yan Zhulanow
2016-03-22 16:40:46 +03:00
parent 06a88f417c
commit 9d34df2475
5 changed files with 50 additions and 6 deletions
@@ -15,11 +15,14 @@
*/
package org.jetbrains.uast
import org.jetbrains.uast.kinds.UastImportKind
interface UImportStatement : UElement {
val nameToImport: String?
val fqNameToImport: String?
val isStarImport: Boolean
val kind: UastImportKind
override fun traverse(handler: UastHandler) {}
override fun logString() = "UImport ($nameToImport)"
override fun renderString() = "import ${nameToImport ?: ""}"
override fun logString() = "UImport ($fqNameToImport)"
override fun renderString() = "import ${fqNameToImport ?: ""}"
}
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2016 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.uast.kinds
class UastImportKind(val text: String) {
companion object {
@JvmField
val CLASS = UastImportKind("class")
@JvmField
val MEMBER = UastImportKind("member")
}
}
@@ -18,15 +18,19 @@ package org.jetbrains.uast.java
import com.intellij.psi.PsiImportStatement
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UImportStatement
import org.jetbrains.uast.kinds.UastImportKind
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUImportStatement(
override val psi: PsiImportStatement,
override val parent: UElement
) : JavaAbstractUElement(), UImportStatement, PsiElementBacked {
override val nameToImport: String?
override val fqNameToImport: String?
get() = psi.qualifiedName
override val kind: UastImportKind
get() = UastImportKind.CLASS
override val isStarImport: Boolean
get() = false
}
@@ -18,15 +18,19 @@ package org.jetbrains.uast.java
import com.intellij.psi.PsiImportStaticStatement
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UImportStatement
import org.jetbrains.uast.kinds.UastImportKind
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUStaticImportStatement(
override val psi: PsiImportStaticStatement,
override val parent: UElement
) : JavaAbstractUElement(), UImportStatement, PsiElementBacked {
override val nameToImport: String?
override val fqNameToImport: String?
get() = psi.referenceName
override val kind: UastImportKind
get() = UastImportKind.MEMBER
override val isStarImport: Boolean
get() = true
}
@@ -19,13 +19,18 @@ package org.jetbrains.kotlin.uast
import org.jetbrains.kotlin.psi.KtImportDirective
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UImportStatement
import org.jetbrains.uast.kinds.UastImportKind
import org.jetbrains.uast.psi.PsiElementBacked
class KotlinUImportStatement(
override val psi: KtImportDirective,
override val parent: UElement
) : KotlinAbstractUElement(), UImportStatement, PsiElementBacked {
override val nameToImport = psi.importedFqName?.asString()
override val fqNameToImport = psi.importedFqName?.asString()
//TODO support member imports
override val kind: UastImportKind
get() = UastImportKind.CLASS
override val isStarImport: Boolean
get() = psi.isAllUnder