Uast: Unified AST (Kotlin, Java) interfaces set.

Goal: support Android Lint diagnostics in Kotlin by switching Lint scanners from the Java Lombok AST to the abstract AST (uast) with Java and Kotlin PsiElement-backed implementations.
This commit is contained in:
Yan Zhulanow
2016-03-03 17:46:24 +03:00
parent aca7050656
commit 16de31aebe
59 changed files with 2288 additions and 0 deletions
@@ -0,0 +1,34 @@
/*
* Copyright 2000-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
interface UastContext {
val converters: List<UastConverter>
fun convert(element: Any?): UElement? {
if (element == null) {
return null
}
for (converter in converters) {
val uelement = converter.convertWithParent(element)
if (uelement != null) {
return uelement
}
}
return null
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 2000-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
interface UastConverter {
fun convert(element: Any?, parent: UElement): UElement?
fun convertWithParent(element: Any?): UElement?
fun isFileSupported(path: String): Boolean
}
object UastConverterUtils {
@JvmStatic
fun isFileSupported(converters: List<UastConverter>, path: String): Boolean {
return converters.any { it.isFileSupported(path) }
}
}
@@ -0,0 +1,20 @@
/*
* Copyright 2000-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;
public interface UastHandler {
void invoke(UElement element);
}
@@ -0,0 +1,129 @@
/*
* Copyright 2000-2015 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.
*/
@file:JvmName("UastUtils")
package org.jetbrains.uast
tailrec fun UElement?.getContainingClass(): UClass? {
val parent = this?.parent ?: return null
if (parent is UClass) return parent
return parent.getContainingClass()
}
tailrec fun UElement?.getContainingFile(): UFile? {
val parent = this?.parent ?: return null
if (parent is UFile) return parent
return parent.getContainingFile()
}
fun UElement?.getContainingClassOrEmpty() = getContainingClass() ?: UClassNotResolved
tailrec fun UElement?.getContainingFunction(): UFunction? {
val parent = this?.parent ?: return null
if (parent is UFunction) return parent
return parent.getContainingFunction()
}
tailrec fun UElement?.getContainingDeclaration(): UDeclaration? {
val parent = this?.parent ?: return null
if (parent is UDeclaration) return parent
return parent.getContainingDeclaration()
}
fun UClass.findProperty(name: String) = declarations.firstOrNull { it is UVariable && it.name == name } as? UVariable
fun UElement.handleTraverse(handler: UastHandler) {
handler(this)
this.traverse(handler)
}
fun UDeclaration.isTopLevel() = parent is UFile
fun UElement.log(firstLine: String, vararg nested: Any?): String {
return (if (firstLine.isBlank()) "" else firstLine + "\n") + nested.joinToString("\n") {
when (it) {
null -> "<no element>".withMargin
is List<*> ->
@Suppress("UNCHECKED_CAST")
(it as List<UElement>).logString()
is UElement -> it.logString().withMargin
else -> error("Invalid element type: $it")
}
}
}
val String.withMargin: String
get() = lines().joinToString("\n") { " " + it }
fun List<UElement>.handleTraverseList(handler: UastHandler) {
for (element in this) {
handler(element)
element.traverse(handler)
}
}
@Suppress("UNCHECKED_CAST")
fun UClass.findFunctions(name: String) = declarations.filter { it is UFunction && it.matchesName(name) } as List<UFunction>
fun UCallExpression.getReceiver(): UExpression? = (this.parent as? UQualifiedExpression)?.receiver
fun UCallExpression.getReceiverOrEmpty(): UExpression = (this.parent as? UQualifiedExpression)?.receiver ?: EmptyExpression(this)
fun UElement.resolveIfCan(context: UastContext): UDeclaration? = (this as? UResolvable)?.resolve(context)
fun UElement.isThrow() = this is USpecialExpressionList && this.kind == UastSpecialExpressionKind.THROW
fun UAnnotated.findAnnotation(fqName: String) = annotations.firstOrNull { it.fqName == fqName }
fun UClass.getAllDeclarations(context: UastContext): List<UDeclaration> = mutableListOf<UDeclaration>().apply {
this += declarations
for (superType in superTypes) {
superType.resolveClass(context)?.declarations?.let { this += it }
}
}
fun UClass.getAllFunctions(context: UastContext) = getAllDeclarations(context).filterIsInstance<UFunction>()
fun UCallExpression.getQualifiedCallElement(): UExpression {
fun findParent(element: UExpression?): UExpression? = when (element) {
is UQualifiedExpression -> findParent(element.parent as? UExpression) ?: element
else -> null
}
return findParent(parent as? UExpression) ?: this
}
val UDeclaration.fqName: String
get() {
val containingFqName = this.getContainingDeclaration()?.fqName
?: this.getContainingFile()?.packageFqName
val containingFqNameWithDot = containingFqName?.let { it + "." } ?: ""
return containingFqNameWithDot + this.name
}
inline fun <reified T: UElement> UElement.getParentOfType(): T? = getParentOfType(T::class.java)
fun <T: UElement> UElement.getParentOfType(clazz: Class<T>): T? {
tailrec fun findParent(element: UElement): UElement? {
val parent = element.parent
return when {
parent == null -> null
clazz.isInstance(parent) -> parent
else -> findParent(parent)
}
}
@Suppress("UNCHECKED_CAST")
return findParent(this) as T
}
@@ -0,0 +1,109 @@
/*
* Copyright 2000-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.visitor
import org.jetbrains.uast.*
abstract class UastVisitor {
open fun visitFile(node: UFile): Boolean = false
// Declarations
open fun visitClass(node: UClass): Boolean = false
open fun visitFunction(node: UFunction): Boolean = false
open fun visitVariable(node: UVariable): Boolean = false
open fun visitImportStatement(node: UImportStatement): Boolean = false
open fun visitAnnotation(node: UAnnotation): Boolean = false
// Expressions
open fun visitLabeledExpression(node: ULabeledExpression): Boolean = false
open fun visitDeclarationsExpression(node: UDeclarationsExpression): Boolean = false
open fun visitBlockExpression(node: UBlockExpression): Boolean = false
open fun visitQualifiedExpression(node: UQualifiedExpression): Boolean = false
open fun visitSimpleReferenceExpression(node: USimpleReferenceExpression): Boolean = false
open fun visitCallExpression(node: UCallExpression): Boolean = false
open fun visitAssignmentExpression(node: UAssignmentExpression): Boolean = false
open fun visitBinaryExpression(node: UBinaryExpression): Boolean = false
open fun visitBinaryExpressionWithType(node: UBinaryExpressionWithType): Boolean = false
open fun visitParenthesizedExpression(node: UParenthesizedExpression): Boolean = false
open fun visitPrefixExpression(node: UPrefixExpression): Boolean = false
open fun visitPostfixExpression(node: UPostfixExpression): Boolean = false
open fun visitSpecialExpressionList(node: USpecialExpressionList): Boolean = false
open fun visitExpressionList(node: UExpressionList): Boolean = false
open fun visitIfExpression(node: UIfExpression): Boolean = false
open fun visitSwitchExpression(node: USwitchExpression): Boolean = false
open fun visitSwitchClauseExpression(node: USwitchClauseExpression): Boolean = false
open fun visitWhileExpression(node: UWhileExpression): Boolean = false
open fun visitDoWhileExpression(node: UDoWhileExpression): Boolean = false
open fun visitForExpression(node: UForExpression): Boolean = false
open fun visitForEachExpression(node: UForEachExpression): Boolean = false
open fun visitTryExpression(node: UTryExpression): Boolean = false
open fun visitLiteralExpression(node: ULiteralExpression): Boolean = false
open fun visitThisExpression(node: UThisExpression): Boolean = false
open fun visitSuperExpression(node: USuperExpression): Boolean = false
fun handle(node: UElement): Boolean {
return when (node) {
is UFile -> visitFile(node)
is UClass -> visitClass(node)
is UFunction -> visitFunction(node)
is UVariable -> visitVariable(node)
is UImportStatement -> visitImportStatement(node)
is UAnnotation -> visitAnnotation(node)
is ULabeledExpression -> visitLabeledExpression(node)
is UDeclarationsExpression -> visitDeclarationsExpression(node)
is UBlockExpression -> visitBlockExpression(node)
is UQualifiedExpression -> visitQualifiedExpression(node)
is USimpleReferenceExpression -> visitSimpleReferenceExpression(node)
is UCallExpression -> visitCallExpression(node)
is UAssignmentExpression -> visitAssignmentExpression(node)
is UBinaryExpression -> visitBinaryExpression(node)
is UBinaryExpressionWithType -> visitBinaryExpressionWithType(node)
is UParenthesizedExpression -> visitParenthesizedExpression(node)
is UPrefixExpression -> visitPrefixExpression(node)
is UPostfixExpression -> visitPostfixExpression(node)
is USpecialExpressionList -> visitSpecialExpressionList(node)
is UExpressionList -> visitExpressionList(node)
is UIfExpression -> visitIfExpression(node)
is USwitchExpression -> visitSwitchExpression(node)
is USwitchClauseExpression -> visitSwitchClauseExpression(node)
is UWhileExpression -> visitWhileExpression(node)
is UDoWhileExpression -> visitDoWhileExpression(node)
is UForExpression -> visitForExpression(node)
is UForEachExpression -> visitForEachExpression(node)
is UTryExpression -> visitTryExpression(node)
is ULiteralExpression -> visitLiteralExpression(node)
is UThisExpression -> visitThisExpression(node)
is USuperExpression -> visitSuperExpression(node)
else -> true
}
}
open fun process(element: UElement) {
if (!handle(element)) {
processChildren(element)
}
}
fun processChildren(element: UElement) {
element.traverse(UastHandler { handle(it) })
}
}
object EmptyUastVisitor : UastVisitor() {
override fun process(element: UElement) {}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2000-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
interface UAnnotation : UElement, UNamed, UFqNamed, NoTraverse {
fun resolve(context: UastContext): UClass?
val valueArguments: List<UNamedExpression>
fun getValue(name: String) = valueArguments.firstOrNull { it.name == name }?.expression?.evaluate()
fun getValues() = valueArguments.map { it.expression.evaluate() }
override fun logString() = log("UAnnotation ($name)")
override fun renderString() = if (valueArguments.isEmpty()) "@$name" else "@$name(" +
valueArguments.joinToString { it.renderString() } + ")"
}
interface UAnnotated {
val annotations: List<UAnnotation>
}
@@ -0,0 +1,53 @@
/*
* Copyright 2000-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
interface UElement {
val parent: UElement?
fun logString(): String
fun renderString(): String = logString()
fun traverse(handler: UastHandler)
}
interface UNamed {
val name: String
fun matchesName(name: String) = this.name == name
}
interface UFqNamed : UNamed {
val fqName: String?
val fqNameOrName: String
get() = fqName ?: name
fun matchesFqName(fqName: String) = this.fqName == fqName
}
interface UModifierOwner {
fun hasModifier(modifier: UastModifier): Boolean
}
interface NoTraverse : UElement {
override fun traverse(handler: UastHandler) {}
}
interface UResolvable {
fun resolve(context: UastContext): UDeclaration?
fun resolveOrEmpty(context: UastContext): UDeclaration = resolve(context) ?: UDeclarationNotResolved
fun resolveClass(context: UastContext): UClass? = resolve(context) as? UClass
}
@@ -0,0 +1,39 @@
/*
* Copyright 2000-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
interface UExpression : UElement {
fun evaluate(): Any?
fun evaluateString(): String? = evaluate() as? String
fun getExpressionType(): UType? = null
}
interface NoEvaluate : UExpression {
override fun evaluate() = null
}
interface NoAnnotations : UAnnotated {
override val annotations: List<UAnnotation>
get() = emptyList()
}
interface NoModifiers : UModifierOwner {
override fun hasModifier(modifier: UastModifier) = false
}
class EmptyExpression(override val parent: UElement) : UExpression, NoTraverse, NoEvaluate {
override fun logString() = "EmptyExpression"
}
@@ -0,0 +1,44 @@
/*
* Copyright 2000-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
interface UFile: UElement {
val packageFqName: String?
val importStatements: List<UImportStatement>
val declarations: List<UDeclaration>
val classes: List<UClass>
get() = declarations.filterIsInstance<UClass>()
override val parent: UElement?
get() = null
override fun traverse(handler: UastHandler) {
declarations.handleTraverseList(handler)
importStatements.handleTraverseList(handler)
}
override fun logString() = "UFile (package = $packageFqName)\n" + declarations.joinToString("\n") { it.logString().withMargin }
override fun renderString() = buildString {
if (packageFqName != null) {
appendln("package $packageFqName")
appendln()
}
declarations.forEach { appendln(it.renderString()) }
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2000-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
interface UDoWhileExpression : ULoopExpression {
val condition: UExpression
override fun traverse(handler: UastHandler) {
condition.handleTraverse(handler)
body.handleTraverse(handler)
}
override fun renderString() = buildString {
append("do ")
append(body.renderString())
appendln("while (${condition.renderString()})")
}
override fun logString() = log("UDoWhileExpression", condition, body)
}
@@ -0,0 +1,42 @@
/*
* Copyright 2000-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
interface UForExpression : ULoopExpression {
val declaration: UExpression?
val condition: UExpression?
val update: UExpression?
override fun traverse(handler: UastHandler) {
declaration?.handleTraverse(handler)
condition?.handleTraverse(handler)
update?.handleTraverse(handler)
body.handleTraverse(handler)
}
override fun renderString() = buildString {
append("for (")
declaration?.let { append(it.renderString()) }
append("; ")
condition?.let { append(it.renderString()) }
append("; ")
update?.let { append(it.renderString()) }
append(") ")
append(body.renderString())
}
override fun logString() = log("UForExpression", declaration, condition, update, body)
}
@@ -0,0 +1,49 @@
/*
* Copyright 2000-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
interface UIfExpression : UExpression {
val condition: UExpression
val thenBranch: UExpression?
val elseBranch: UExpression?
val isTernary: Boolean
override fun traverse(handler: UastHandler) {
condition.handleTraverse(handler)
thenBranch?.handleTraverse(handler)
elseBranch?.handleTraverse(handler)
}
override fun logString() = log("UIfExpression", condition, thenBranch, elseBranch)
override fun renderString() = buildString {
if (isTernary) {
append("(" + condition.renderString() + ")")
append(" ? ")
append("(" + (thenBranch?.renderString() ?: "<noexpr>") + ")")
append(" : ")
append("(" + (elseBranch?.renderString() ?: "<noexpr>") + ")")
} else {
append("if (${condition.renderString()}) ")
thenBranch?.let { append(it.renderString()) }
val elseBranch = elseBranch
if (elseBranch != null && elseBranch !is EmptyExpression) {
if (thenBranch !is UBlockExpression) append(" ")
append("else ")
append(elseBranch.renderString())
}
}
}
}
@@ -0,0 +1,54 @@
/*
* Copyright 2000-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
interface USwitchExpression : UExpression {
val expression: UExpression?
val body: UExpression
override fun traverse(handler: UastHandler) {
expression?.handleTraverse(handler)
body.handleTraverse(handler)
}
override fun logString() = log("USwitchExpression", expression, body)
override fun renderString() = buildString {
val expr = expression?.let { "(" + it.renderString() + ") " } ?: ""
appendln("switch $expr")
appendln(body.renderString())
}
}
interface USwitchClauseExpression : UExpression
interface UExpressionSwitchClauseExpression : USwitchClauseExpression {
val caseValue: UExpression
override fun traverse(handler: UastHandler) {
caseValue.handleTraverse(handler)
}
override fun renderString() = caseValue.renderString() + " -> "
override fun logString() = log("UExpressionSwitchClauseExpression", caseValue)
}
interface UDefaultSwitchClauseExpression : USwitchClauseExpression {
override fun traverse(handler: UastHandler) {}
override fun logString() = "UDefaultSwitchClause"
override fun renderString() = "else -> "
}
class SimpleUDefaultSwitchClauseExpression(override val parent: UElement) : UDefaultSwitchClauseExpression, NoEvaluate
@@ -0,0 +1,53 @@
/*
* Copyright 2000-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
interface UTryExpression : UExpression {
val tryClause: UExpression
val catchClauses: List<UCatchClause>
val finallyClause: UExpression?
override fun traverse(handler: UastHandler) {
tryClause.handleTraverse(handler)
catchClauses.handleTraverseList(handler)
finallyClause?.handleTraverse(handler)
}
override fun renderString() = buildString {
append("try ")
appendln(tryClause.renderString())
catchClauses.forEach { appendln(it.renderString()) }
finallyClause?.let { append("finally ").append(it.renderString()) }
}
override fun logString() = "UTryExpression\n" +
tryClause.logString().withMargin +
catchClauses.joinToString("\n") { it.logString().withMargin } +
(finallyClause?.let { it.logString().withMargin } ?: "<no finally clause>" )
}
interface UCatchClause : UElement {
val body: UExpression
val parameters: List<UVariable>
val types: List<UType>
override fun traverse(handler: UastHandler) {
body.handleTraverse(handler)
}
override fun logString() = log("UCatchClause", body)
override fun renderString() = "catch (e) " + body.renderString()
}
@@ -0,0 +1,32 @@
/*
* Copyright 2000-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
interface UWhileExpression : ULoopExpression {
val condition: UExpression
override fun traverse(handler: UastHandler) {
condition.handleTraverse(handler)
body.handleTraverse(handler)
}
override fun renderString() = buildString {
append("while (${condition.renderString()}) ")
append(body.renderString())
}
override fun logString() = log("UWhileExpression", condition, body)
}
@@ -0,0 +1,100 @@
/*
* Copyright 2000-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
interface UClass : UDeclaration, UFqNamed, UModifierOwner, UAnnotated {
val isEnum: Boolean
val isInterface: Boolean
val isObject: Boolean
val isAnonymous: Boolean
val isAnnotation: Boolean
val visibility: UastVisibility
val internalName: String?
val superTypes: List<UType>
val declarations: List<UDeclaration>
val nestedClasses: List<UClass>
get() = declarations.filterIsInstance<UClass>()
val functions: List<UFunction>
get() = declarations.filterIsInstance<UFunction>()
val properties: List<UVariable>
get() = declarations.filterIsInstance<UVariable>()
@Suppress("UNCHECKED_CAST")
val constructors: List<UFunction>
get() = declarations.filter { it is UFunction && it.kind == UastFunctionKind.CONSTRUCTOR } as List<UFunction>
fun isSubclassOf(name: String) : Boolean
fun getSuperClass(context: UastContext): UClass?
override fun traverse(handler: UastHandler) {
nameElement?.handleTraverse(handler)
declarations.handleTraverseList(handler)
annotations.handleTraverseList(handler)
}
override fun renderString(): String {
val keyword = when {
isEnum -> "enum"
isInterface -> "interface"
isObject -> "object"
else -> "class"
}
val modifiers = listOf(UastModifier.ABSTRACT, UastModifier.FINAL, UastModifier.INNER)
.filter { hasModifier(it) }.joinToString(" ") { it.name }.let { if (it.isBlank()) it else "$it " }
val name = if (isAnonymous) "" else " $name"
val declarations = if (declarations.isEmpty()) "" else buildString {
appendln("{")
append(declarations.joinToString("\n") { it.renderString() }.withMargin)
append("\n}")
}
return "${visibility.name} " + modifiers + keyword + name + " " + declarations
}
override fun logString() = "UClass ($name, enum = $isEnum, interface = $isInterface, object = $isObject)\n" + declarations.logString()
}
object UClassNotResolved : UClass {
override val isEnum = false
override val isInterface = false
override val isObject = false
override val isAnonymous = true
override val isAnnotation = false
override val visibility = UastVisibility.PRIVATE
override val superTypes = emptyList<UType>()
override val declarations = emptyList<UDeclaration>()
override fun isSubclassOf(name: String) = false
override val nameElement = null
override val parent = null
override val name = "<class not resolved>"
override val fqName = null
override val internalName = null
override fun hasModifier(modifier: UastModifier) = false
override val annotations = emptyList<UAnnotation>()
override fun getSuperClass(context: UastContext) = null
}
@@ -0,0 +1,29 @@
/*
* Copyright 2000-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
interface UDeclaration : UElement, UNamed {
val nameElement: UElement?
}
object UDeclarationNotResolved : UDeclaration, NoTraverse {
override val name = "<declaration not resolved>"
override val nameElement = null
override val parent = null
override fun logString() = "[!] $name"
override fun renderString() = name
}
@@ -0,0 +1,70 @@
/*
* Copyright 2000-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
interface UFunction : UDeclaration, UModifierOwner, UAnnotated {
val kind: UastFunctionKind
val valueParameters: List<UVariable>
val valueParameterCount: Int
val typeParameters: List<UTypeReference>
val typeParameterCount: Int
val returnType: UType?
val body: UExpression
val visibility: UastVisibility
fun getSuperFunctions(context: UastContext): List<UFunction>
override fun traverse(handler: UastHandler) {
nameElement?.handleTraverse(handler)
valueParameters.handleTraverseList(handler)
body.handleTraverse(handler)
annotations.handleTraverseList(handler)
typeParameters.handleTraverseList(handler)
returnType?.handleTraverse(handler)
}
override fun renderString(): String {
val typeParameters = if (typeParameterCount == 0) "" else "<" + typeParameters.joinToString { it.renderString() } + "> "
val valueParameters = valueParameters.joinToString { it.renderString() }
val returnType = returnType?.let { ": " + it.renderString() } ?: ""
val body = when (body) {
is UBlockExpression -> " " + body.renderString()
else -> " = " + body.renderString()
}
return "${visibility.name} fun " + typeParameters + name + "(" + valueParameters + ")" + returnType + body
}
override fun logString() = "UFunction ($name, kind = ${kind.name}, " +
"paramCount = $valueParameterCount)\n" + body.logString().withMargin
}
object UFunctionNotResolved : UFunction {
override val kind = UastFunctionKind("<unknown>")
override val valueParameters = emptyList<UVariable>()
override val valueParameterCount = 0
override val typeParameters = emptyList<UTypeReference>()
override val typeParameterCount = 0
override val returnType = null
override val body = EmptyExpression(this)
override val visibility = UastVisibility.PRIVATE
override val nameElement = null
override val parent = null
override val name = "<function not resolved>"
override fun hasModifier(modifier: UastModifier) = false
override fun getSuperFunctions(context: UastContext) = emptyList<UFunction>()
override val annotations = emptyList<UAnnotation>()
}
@@ -0,0 +1,25 @@
/*
* Copyright 2000-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
interface UImportStatement : UElement {
val nameToImport: String?
val isStarImport: Boolean
override fun traverse(handler: UastHandler) {}
override fun logString() = "UImport ($nameToImport)"
override fun renderString() = "import ${nameToImport ?: ""}"
}
@@ -0,0 +1,37 @@
/*
* Copyright 2000-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
interface UType : UElement, UNamed, UFqNamed, UAnnotated, UResolvable, NoTraverse {
override fun matchesName(name: String) = this.name == name || this.name.endsWith(".$name")
val isInt: Boolean
val isBoolean: Boolean
override fun logString() = "UType ($name)"
override fun renderString() = name
override fun resolve(context: UastContext): UClass?
override fun resolveOrEmpty(context: UastContext) = resolve(context) ?: UClassNotResolved
}
interface UTypeReference : UDeclaration, UResolvable, NoTraverse {
override fun renderString() = ""
override fun logString() = log("UTypeReference")
override fun resolve(context: UastContext): UClass?
override fun resolveOrEmpty(context: UastContext) = resolve(context) ?: UClassNotResolved
}
@@ -0,0 +1,39 @@
/*
* Copyright 2000-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
interface UVariable : UDeclaration, UModifierOwner, UAnnotated {
val initializer: UExpression?
val kind: UastVariableKind
val type: UType
override fun traverse(handler: UastHandler) {
nameElement?.handleTraverse(handler)
initializer?.handleTraverse(handler)
annotations.handleTraverseList(handler)
type.handleTraverse(handler)
}
override fun renderString(): String {
val initializer = if (initializer != null && initializer !is EmptyExpression) " = ${initializer!!.renderString()}" else ""
val prefix = if (kind == UastVariableKind.VALUE_PARAMETER) "" else "var "
val emptyLine = if (kind == UastVariableKind.MEMBER) "\n" else ""
return "$prefix$name: " + type.name + initializer + emptyLine
}
override fun logString() = "UVariable ($name, kind = ${kind.name})\n" +
(initializer?.let { it.logString().withMargin } ?: "<no initializer>")
}
@@ -0,0 +1,29 @@
/*
* Copyright 2000-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
interface UArrayAccessExpression : UExpression {
val receiver: UExpression
val indices: List<UExpression>
override fun traverse(handler: UastHandler) {
receiver.handleTraverse(handler)
indices.handleTraverseList(handler)
}
override fun logString() = log("UArrayAccessExpression", receiver, indices)
override fun renderString() = receiver.renderString() + indices.joinToString(prefix = "[", postfix = "]") { it.renderString() }
}
@@ -0,0 +1,31 @@
/*
* Copyright 2000-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
interface UAssignmentExpression : UExpression {
val reference: UExpression
val operator: String
val value: UExpression
override fun traverse(handler: UastHandler) {
reference.handleTraverse(handler)
value.handleTraverse(handler)
}
override fun logString() = "UAssignmentExpression ($operator)\n" + reference.logString().withMargin + "\n" + value.logString().withMargin
override fun renderString() = reference.renderString() + ' ' + operator + ' ' + value.renderString()
}
@@ -0,0 +1,32 @@
/*
* Copyright 2000-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
interface UBinaryExpression : UExpression {
val leftOperand: UExpression
val operator: UastBinaryOperator
val rightOperand: UExpression
override fun traverse(handler: UastHandler) {
leftOperand.handleTraverse(handler)
rightOperand.handleTraverse(handler)
}
override fun logString() =
"UBinaryExpression (${operator.text})\n" + leftOperand.logString().withMargin + "\n" + rightOperand.logString().withMargin
override fun renderString() = leftOperand.renderString() + ' ' + operator.text + ' ' + rightOperand.renderString()
}
@@ -0,0 +1,30 @@
/*
* Copyright 2000-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
interface UBinaryExpressionWithType : UExpression {
val operand: UExpression
val operationKind: UastBinaryExpressionWithTypeKind
val type: UType
override fun logString() = log("UBinaryExpressionWithType (${getExpressionType()?.name}, ${operationKind.name})", operand)
override fun renderString() = "(${operand.renderString()}) ${operationKind.name} ${getExpressionType()?.name}"
override fun traverse(handler: UastHandler) {
operand.handleTraverse(handler)
type.handleTraverse(handler)
}
}
@@ -0,0 +1,29 @@
/*
* Copyright 2000-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
interface UBlockExpression : UExpression {
val expressions: List<UExpression>
override fun traverse(handler: UastHandler) = expressions.handleTraverseList(handler)
override fun logString() = log("UBlockExpression", expressions)
override fun renderString() = buildString {
appendln("{")
expressions.forEach { appendln(it.renderString().withMargin) }
appendln("}")
}
}
@@ -0,0 +1,52 @@
/*
* Copyright 2000-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
interface UCallExpression : UExpression, UResolvable {
val functionReference: USimpleReferenceExpression?
val classReference: USimpleReferenceExpression?
val functionName: String?
val functionNameElement: UElement?
fun functionNameMatches(name: String) = functionName == name
val valueArgumentCount: Int
val valueArguments: List<UExpression>
val typeArgumentCount: Int
val typeArguments: List<UType>
val kind: UastCallKind
override fun resolve(context: UastContext): UFunction?
override fun resolveOrEmpty(context: UastContext): UFunction = resolve(context) ?: UFunctionNotResolved
override fun traverse(handler: UastHandler) {
functionReference?.handleTraverse(handler)
classReference?.handleTraverse(handler)
functionNameElement?.handleTraverse(handler)
valueArguments.handleTraverseList(handler)
typeArguments.handleTraverseList(handler)
}
override fun logString() = log("UFunctionCallExpression ($kind, argCount = $valueArgumentCount)", functionReference, valueArguments)
override fun renderString(): String {
val ref = functionName ?: functionReference?.renderString() ?: classReference?.renderString() ?: "<noref>"
return ref + "(" + valueArguments.joinToString { it.renderString() } + ")"
}
}
@@ -0,0 +1,27 @@
/*
* Copyright 2000-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
interface UCallableReferenceExpression : UExpression {
val qualifierType: UType
override fun traverse(handler: UastHandler) {
qualifierType.handleTraverse(handler)
}
override fun logString() = "UCallableReferenceExpression"
override fun renderString() = "::" + qualifierType.name
}
@@ -0,0 +1,21 @@
/*
* Copyright 2000-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
interface UClassLiteralExpression : UExpression, NoTraverse {
override fun logString() = "UClassLiteralExpression"
override fun renderString() = getExpressionType()?.name ?: "::class"
}
@@ -0,0 +1,36 @@
/*
* Copyright 2000-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
interface UDeclarationsExpression : UExpression {
val declarations: List<UElement>
val variables: List<UVariable>
get() = declarations.filterIsInstance<UVariable>()
override fun evaluate() = null
override fun traverse(handler: UastHandler) = declarations.handleTraverseList(handler)
override fun renderString() = declarations.joinToString("\n") { it.renderString() }
override fun logString() = log("UDeclarationsExpression", declarations)
}
class SimpleUDeclarationsExpression(
override val parent: UElement,
override val declarations: List<UElement>
) : UDeclarationsExpression {
override fun evaluate() = null
}
@@ -0,0 +1,35 @@
/*
* Copyright 2000-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
interface UExpressionList : UExpression {
val expressions: List<UExpression>
override fun evaluate(): Any? = null
override fun traverse(handler: UastHandler) = expressions.forEach { it.handleTraverse(handler) }
override fun logString() = log("UExpressionList", expressions)
override fun renderString() = log("", expressions)
}
interface USpecialExpressionList : UExpressionList {
val kind: UastSpecialExpressionKind
fun firstOrNull(): UExpression? = expressions.firstOrNull()
override fun logString() = log("USpecialExpressionList (${kind.name})", expressions)
override fun renderString() = kind.name + " " + expressions.joinToString(" : ") { it.renderString() }
}
@@ -0,0 +1,39 @@
/*
* Copyright 2000-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
interface UForEachExpression : ULoopExpression {
val variableName: String?
val iteratedValue: UExpression
override fun traverse(handler: UastHandler) {
iteratedValue.handleTraverse(handler)
body.handleTraverse(handler)
}
override fun renderString() = buildString {
append("for (")
append(variableName ?: "<error name>")
append(" : ")
append(iteratedValue.renderString())
append(") ")
append(body.renderString())
}
override fun logString() = "UForEachExpression ($variableName)\n" +
iteratedValue.logString().withMargin + "\n" +
body.logString().withMargin
}
@@ -0,0 +1,29 @@
/*
* Copyright 2000-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
interface ULabeledExpression : UExpression {
val label: String
val expression: UExpression
override fun traverse(handler: UastHandler) {
expression.handleTraverse(handler)
}
override fun logString() = log("ULabeledExpression ($label)", expression)
override fun renderString() = "$label@ ${expression.renderString()}"
}
@@ -0,0 +1,36 @@
/*
* Copyright 2000-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
interface ULambdaExpression : UExpression {
val valueParameters: List<UVariable>
val body: UExpression
override fun traverse(handler: UastHandler) {
valueParameters.handleTraverseList(handler)
body.handleTraverse(handler)
}
override fun logString() = log("ULambdaExpression", valueParameters, body)
override fun renderString(): String {
val renderedValueParameters = if (valueParameters.isEmpty())
""
else
valueParameters.joinToString { it.renderString() } + " ->\n"
return "{ " + renderedValueParameters + body.renderString().withMargin + "\n}"
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2000-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
interface ULiteralExpression : UExpression {
val text: String
val value: Any?
val isNull: Boolean
val isString: Boolean
get() = evaluate() is String
val isBoolean: Boolean
get() = evaluate() is Boolean
override fun traverse(handler: UastHandler) {}
override fun logString() = "ULiteralExpression ($text)"
override fun renderString() = text
}
@@ -0,0 +1,20 @@
/*
* Copyright 2000-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
interface ULoopExpression : UExpression {
val body: UExpression
}
@@ -0,0 +1,32 @@
/*
* Copyright 2000-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
class UNamedExpression(
override val name: String,
override val parent: UElement
): UExpression, UNamed {
lateinit var expression: UExpression
override fun traverse(handler: UastHandler) {
expression.handleTraverse(handler)
}
override fun logString() = log("UNamedExpression ($name)", expression)
override fun renderString() = "$name: $expression"
override fun evaluate() = expression.evaluate()
}
@@ -0,0 +1,27 @@
/*
* Copyright 2000-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
interface UObjectLiteralExpression : UExpression {
val declaration: UClass
override fun traverse(handler: UastHandler) {
declaration.handleTraverse(handler)
}
override fun logString() = log("UObjectLiteralExpression", declaration)
override fun renderString() = "anonymous " + declaration.renderString()
}
@@ -0,0 +1,27 @@
/*
* Copyright 2000-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
interface UParenthesizedExpression : UExpression {
val expression: UExpression
override fun traverse(handler: UastHandler) {
expression.handleTraverse(handler)
}
override fun logString() = log("UParenthesizedExpression", expression)
override fun renderString() = '(' + expression.renderString() + ')'
}
@@ -0,0 +1,33 @@
/*
* Copyright 2000-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
interface UQualifiedExpression : UExpression, UResolvable {
val receiver: UExpression
val selector: UExpression
val accessType: UastQualifiedExpressionAccessType
fun selectorMatches(identifier: String) = (selector as? USimpleReferenceExpression)?.identifier == identifier
override fun renderString() = receiver.renderString() + accessType.name + selector.renderString()
override fun traverse(handler: UastHandler) {
receiver.handleTraverse(handler)
selector.handleTraverse(handler)
}
override fun logString() = log("UQualifiedExpression", receiver, selector)
}
@@ -0,0 +1,23 @@
/*
* Copyright 2000-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
interface USimpleReferenceExpression : UExpression, UResolvable, NoTraverse {
val identifier: String
override fun logString() = "USimpleReferenceExpression ($identifier)"
override fun renderString() = identifier
}
@@ -0,0 +1,22 @@
/*
* Copyright 2000-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
interface USuperExpression : UExpression {
override fun logString() = "USuperExpression"
override fun renderString() = "super"
override fun traverse(handler: UastHandler) {}
}
@@ -0,0 +1,22 @@
/*
* Copyright 2000-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
interface UThisExpression : UExpression {
override fun logString() = "UThisExpression"
override fun renderString() = "this"
override fun traverse(handler: UastHandler) {}
}
@@ -0,0 +1,39 @@
/*
* Copyright 2000-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
import org.jetbrains.uast.kinds.UastOperator
interface UUnaryExpression : UExpression {
val operand: UExpression
val operator: UastOperator
override fun traverse(handler: UastHandler) {
operand.handleTraverse(handler)
}
}
interface UPrefixExpression : UUnaryExpression {
override val operator: UastPrefixOperator
override fun logString() = log("UPrefixExpression (${operator.text})", operand)
override fun renderString() = operator.text + operand.renderString()
}
interface UPostfixExpression : UUnaryExpression {
override val operator: UastPostfixOperator
override fun logString() = log("UPostfixExpression (${operator.text})", operand)
override fun renderString() = operand.renderString() + operator.text
}
@@ -0,0 +1,48 @@
/*
* Copyright 2000-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.
*/
@file:JvmName("UastLiteralUtils")
package org.jetbrains.uast
fun UElement.isNullLiteral(): Boolean = this is ULiteralExpression && this.isNull
fun UElement.isStringLiteral(): Boolean = this is ULiteralExpression && this.isString
fun UElement.getValueIfStringLiteral(): String? =
if (isStringLiteral()) (this as ULiteralExpression).value as String else null
fun UElement.isNumberLiteral(): Boolean = this is ULiteralExpression && this.value is Number
fun UElement.isIntegralLiteral(): Boolean = this is ULiteralExpression && when (value) {
is Int -> true
is Long -> true
is Short -> true
is Char -> true
is Byte -> true
else -> false
}
fun UElement.isBooleanLiteral(): Boolean = this is ULiteralExpression && this.isBoolean
fun ULiteralExpression.getLongValue(): Long = value.let {
when (it) {
is Long -> it
is Int -> it.toLong()
is Short -> it.toLong()
is Char -> it.toLong()
is Byte -> it.toLong()
else -> 0
}
}
@@ -0,0 +1,18 @@
/*
* Copyright 2000-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
internal fun List<UElement>.logString() = joinToString("\n") { it.logString().withMargin }
@@ -0,0 +1,37 @@
/*
* Copyright 2000-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.
*/
@file:JvmName("UastBinaryExpressionWithTypeUtils")
package org.jetbrains.uast
open class UastBinaryExpressionWithTypeKind(val name: String) {
open class TypeCast(name: String) : UastBinaryExpressionWithTypeKind(name)
open class InstanceCheck(name: String) : UastBinaryExpressionWithTypeKind(name)
companion object {
@JvmField
val TYPE_CAST = TypeCast("as")
@JvmField
val INSTANCE_CHECK = InstanceCheck("is")
@JvmField
val UNKNOWN = UastBinaryExpressionWithTypeKind("<unknown>")
}
}
fun UElement.isTypeCast() = this is UBinaryExpressionWithType && this.operationKind is UastBinaryExpressionWithTypeKind.TypeCast
fun UElement.isInstanceCheck() = this is UBinaryExpressionWithType && this.operationKind is UastBinaryExpressionWithTypeKind.InstanceCheck
@@ -0,0 +1,124 @@
/*
* Copyright 2000-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
import org.jetbrains.uast.kinds.UastOperator
class UastBinaryOperator(override val text: String): UastOperator {
companion object {
@JvmField
val ASSIGN = UastBinaryOperator("=")
@JvmField
val PLUS = UastBinaryOperator("+")
@JvmField
val MINUS = UastBinaryOperator("-")
@JvmField
val MULT = UastBinaryOperator("*")
@JvmField
val DIV = UastBinaryOperator("/")
@JvmField
val MOD = UastBinaryOperator("%")
@JvmField
val LOGICAL_OR = UastBinaryOperator("||")
@JvmField
val LOGICAL_AND = UastBinaryOperator("&&")
@JvmField
val BITWISE_OR = UastBinaryOperator("|")
@JvmField
val BITWISE_AND = UastBinaryOperator("&")
@JvmField
val BITWISE_XOR = UastBinaryOperator("^")
@JvmField
val EQUALS = UastBinaryOperator("==")
@JvmField
val NOT_EQUALS = UastBinaryOperator("!=")
@JvmField
val IDENTITY_EQUALS = UastBinaryOperator("===")
@JvmField
val IDENTITY_NOT_EQUALS = UastBinaryOperator("!==")
@JvmField
val GREATER = UastBinaryOperator(">")
@JvmField
val GREATER_OR_EQUAL = UastBinaryOperator(">=")
@JvmField
val LESS = UastBinaryOperator("<")
@JvmField
val LESS_OR_EQUAL = UastBinaryOperator("<=")
@JvmField
val SHIFT_LEFT = UastBinaryOperator("<<")
@JvmField
val SHIFT_RIGHT = UastBinaryOperator(">>")
@JvmField
val BITWISE_SHIFT_RIGHT = UastBinaryOperator(">>>")
@JvmField
val UNKNOWN = UastBinaryOperator("<unknown>")
@JvmField
val PLUS_ASSIGN = UastBinaryOperator("+=")
@JvmField
val MINUS_ASSIGN = UastBinaryOperator("-=")
@JvmField
val MULTIPLY_ASSIGN = UastBinaryOperator("*=")
@JvmField
val DIVIDE_ASSIGN = UastBinaryOperator("/=")
@JvmField
val REMAINDER_ASSIGN = UastBinaryOperator("%=")
@JvmField
val AND_ASSIGN = UastBinaryOperator("&=")
@JvmField
val XOR_ASSIGN = UastBinaryOperator("^=")
@JvmField
val OR_ASSIGN = UastBinaryOperator("|=")
@JvmField
val SHIFT_LEFT_ASSIGN = UastBinaryOperator("<<=")
@JvmField
val SHIFT_RIGHT_ASSIGN = UastBinaryOperator(">>=")
@JvmField
val BITWISE_SHIFT_RIGHT_ASSIGN = UastBinaryOperator(">>>=")
}
}
@@ -0,0 +1,26 @@
/*
* Copyright 2000-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
class UastCallKind(val name: String) {
companion object {
@JvmField
val FUNCTION_CALL = UastCallKind("function_call")
@JvmField
val CONSTRUCTOR_CALL = UastCallKind("constructor_call")
}
}
@@ -0,0 +1,29 @@
/*
* Copyright 2000-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
class UastFunctionKind(val name: String) {
companion object {
@JvmField
val FUNCTION = UastFunctionKind("function")
@JvmField
val CONSTRUCTOR = UastFunctionKind("CONSTRUCTOR")
@JvmField
val INITIALIZER = UastFunctionKind("INITIALIZER")
}
}
@@ -0,0 +1,27 @@
/*
* Copyright 2000-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
class UastModifier(val name: String) {
companion object {
@JvmField
val ABSTRACT = UastModifier("abstract")
@JvmField
val INNER = UastModifier("inner")
@JvmField
val FINAL = UastModifier("final")
}
}
@@ -0,0 +1,20 @@
/*
* Copyright 2000-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
interface UastOperator {
val text: String
}
@@ -0,0 +1,31 @@
/*
* Copyright 2000-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
import org.jetbrains.uast.kinds.UastOperator
class UastPostfixOperator(override val text: String): UastOperator {
companion object {
@JvmField
val INC = UastPostfixOperator("++")
@JvmField
val DEC = UastPostfixOperator("--")
@JvmField
val UNKNOWN = UastPostfixOperator("<unknown>")
}
}
@@ -0,0 +1,43 @@
/*
* Copyright 2000-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
import org.jetbrains.uast.kinds.UastOperator
class UastPrefixOperator(override val text: String): UastOperator {
companion object {
@JvmField
val INC = UastPrefixOperator("++")
@JvmField
val DEC = UastPrefixOperator("--")
@JvmField
val UNARY_MINUS = UastPrefixOperator("-")
@JvmField
val UNARY_PLUS = UastPrefixOperator("+")
@JvmField
val LOGICAL_NOT = UastPrefixOperator("!")
@JvmField
val BITWISE_NOT = UastPrefixOperator("~")
@JvmField
val UNKNOWN = UastPrefixOperator("<unknown>")
}
}
@@ -0,0 +1,23 @@
/*
* Copyright 2000-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
class UastQualifiedExpressionAccessType(val name: String) {
companion object {
@JvmField
val SIMPLE = UastQualifiedExpressionAccessType(".")
}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2000-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
class UastSpecialExpressionKind(val name: String) {
companion object {
@JvmField
val RETURN = UastSpecialExpressionKind("return")
@JvmField
val THROW = UastSpecialExpressionKind("throw")
@JvmField
val BREAK = UastSpecialExpressionKind("break")
@JvmField
val CONTINUE = UastSpecialExpressionKind("continue")
}
}
@@ -0,0 +1,29 @@
/*
* Copyright 2000-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
class UastVariableKind(val name: String) {
companion object {
@JvmField
val LOCAL_VARIABLE = UastVariableKind("local")
@JvmField
val MEMBER = UastVariableKind("member")
@JvmField
val VALUE_PARAMETER = UastVariableKind("parameter")
}
}
@@ -0,0 +1,31 @@
/*
* Copyright 2000-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
class UastVisibility(val name: String) {
companion object {
@JvmField
val PUBLIC = UastVisibility("public")
@JvmField
val PRIVATE = UastVisibility("private")
@JvmField
val PROTECTED = UastVisibility("protected")
@JvmField
val LOCAL = UastVisibility("local")
}
fun isPublic() = this == PUBLIC
}
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlin-runtime" level="project" />
</component>
</module>