Use uast-common and uast-java as an external dependency

This commit is contained in:
Yan Zhulanow
2016-12-30 18:23:24 +03:00
parent ff6ff108ad
commit 7152c9c789
135 changed files with 42 additions and 6806 deletions
+2 -4
View File
@@ -73,12 +73,9 @@
<element id="archive" name="android-lint.jar">
<element id="module-output" name="uast-kotlin" />
<element id="module-output" name="lint-idea" />
<element id="module-output" name="uast-java" />
<element id="module-output" name="uast-common" />
<element id="module-output" name="lint-checks" />
<element id="library" level="project" name="guava" />
<element id="module-output" name="lint-api" />
<element id="module-output" name="uast-android" />
<element id="module-output" name="uast-kotlin-idea" />
</element>
<element id="archive" name="allopen-ide-plugin.jar">
<element id="module-output" name="allopen-ide" />
@@ -103,6 +100,7 @@
<element id="archive" name="kotlin-gradle-tooling.jar">
<element id="module-output" name="kotlin-gradle-tooling" />
</element>
<element id="library" level="project" name="uast-java" />
</element>
<element id="directory" name="kotlinc">
<element id="dir-copy" path="$PROJECT_DIR$/dist/kotlinc" />
+13
View File
@@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="uast-java">
<CLASSES>
<root url="jar://$PROJECT_DIR$/dependencies/uast-common.jar!/" />
<root url="jar://$PROJECT_DIR$/dependencies/uast-java.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$PROJECT_DIR$/dependencies/uast-common-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/dependencies/uast-java-sources.jar!/" />
</SOURCES>
</library>
</component>
+1 -2
View File
@@ -94,9 +94,8 @@
<module fileurl="file://$PROJECT_DIR$/compiler/serialization/serialization.iml" filepath="$PROJECT_DIR$/compiler/serialization/serialization.iml" group="compiler" />
<module fileurl="file://$PROJECT_DIR$/compiler/tests-common/tests-common.iml" filepath="$PROJECT_DIR$/compiler/tests-common/tests-common.iml" group="compiler" />
<module fileurl="file://$PROJECT_DIR$/compiler/tests-ir-jvm/tests-ir-jvm.iml" filepath="$PROJECT_DIR$/compiler/tests-ir-jvm/tests-ir-jvm.iml" group="compiler/ir" />
<module fileurl="file://$PROJECT_DIR$/plugins/uast-common/uast-common.iml" filepath="$PROJECT_DIR$/plugins/uast-common/uast-common.iml" group="plugins/lint" />
<module fileurl="file://$PROJECT_DIR$/plugins/uast-java/uast-java.iml" filepath="$PROJECT_DIR$/plugins/uast-java/uast-java.iml" group="plugins/lint" />
<module fileurl="file://$PROJECT_DIR$/plugins/uast-kotlin/uast-kotlin.iml" filepath="$PROJECT_DIR$/plugins/uast-kotlin/uast-kotlin.iml" group="plugins/lint" />
<module fileurl="file://$PROJECT_DIR$/plugins/uast-kotlin-idea/uast-kotlin-idea.iml" filepath="$PROJECT_DIR$/plugins/uast-kotlin-idea/uast-kotlin-idea.iml" />
<module fileurl="file://$PROJECT_DIR$/compiler/util/util.iml" filepath="$PROJECT_DIR$/compiler/util/util.iml" />
<module fileurl="file://$PROJECT_DIR$/core/util.runtime/util.runtime.iml" filepath="$PROJECT_DIR$/core/util.runtime/util.runtime.iml" group="core" />
</modules>
+1 -2
View File
@@ -8,11 +8,10 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="guava" level="project" />
<orderEntry type="module" module-name="uast-common" exported="" />
<orderEntry type="module" module-name="uast-java" exported="" />
<orderEntry type="library" name="android-plugin" level="project" />
<orderEntry type="library" name="intellij-core" level="project" />
<orderEntry type="module" module-name="android-annotations" />
<orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="library" exported="" name="uast-java" level="project" />
</component>
</module>
@@ -1,73 +0,0 @@
package org.jetbrains.uast
import com.intellij.lang.Language
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiVariable
import org.jetbrains.uast.psi.PsiElementBacked
class UastContext(override val project: Project) : UastLanguagePlugin {
private companion object {
private val CONTEXT_LANGUAGE = object : Language("UastContextLanguage") {}
}
override val language: Language
get() = CONTEXT_LANGUAGE
override val priority: Int
get() = 0
val languagePlugins: Collection<UastLanguagePlugin>
get() = UastLanguagePlugin.getInstances(project)
fun findPlugin(element: PsiElement): UastLanguagePlugin? {
val language = element.language
return languagePlugins.firstOrNull { it.language == language }
}
override fun isFileSupported(fileName: String) = languagePlugins.any { it.isFileSupported(fileName) }
fun getMethod(method: PsiMethod): UMethod = convertWithParent<UMethod>(method)!!
fun getVariable(variable: PsiVariable): UVariable = convertWithParent<UVariable>(variable)!!
fun getClass(clazz: PsiClass): UClass = convertWithParent<UClass>(clazz)!!
override fun convertElement(element: PsiElement, parent: UElement?, requiredType: Class<out UElement>?): UElement? {
return findPlugin(element)?.convertElement(element, parent, requiredType)
}
override fun convertElementWithParent(element: PsiElement, requiredType: Class<out UElement>?): UElement? {
return findPlugin(element)?.convertElementWithParent(element, requiredType)
}
override fun getMethodCallExpression(
element: PsiElement,
containingClassFqName: String?,
methodName: String
): UastLanguagePlugin.ResolvedMethod? {
return findPlugin(element)?.getMethodCallExpression(element, containingClassFqName, methodName)
}
override fun getConstructorCallExpression(
element: PsiElement,
fqName: String
): UastLanguagePlugin.ResolvedConstructor? {
return findPlugin(element)?.getConstructorCallExpression(element, fqName)
}
override fun isExpressionValueUsed(element: UExpression): Boolean {
val language = element.getLanguage()
return (languagePlugins.firstOrNull { it.language == language })?.isExpressionValueUsed(element) ?: false
}
private tailrec fun UElement.getLanguage(): Language {
if (this is PsiElementBacked) {
psi?.language?.let { return it }
}
val containingElement = this.containingElement ?: throw IllegalStateException("At least UFile should have a language")
return containingElement.getLanguage()
}
}
@@ -1,98 +0,0 @@
package org.jetbrains.uast
import com.intellij.lang.Language
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.project.Project
import com.intellij.psi.*
interface UastLanguagePlugin {
companion object {
val extensionPointName = ExtensionPointName.create<UastLanguagePlugin>("org.jetbrains.uast.uastLanguagePlugin")
fun getInstances(project: Project): Collection<UastLanguagePlugin> {
val projectArea = Extensions.getArea(project)
if (!projectArea.hasExtensionPoint(extensionPointName.name)) return listOf()
return projectArea.getExtensionPoint(extensionPointName).extensions.toList()
}
}
data class ResolvedMethod(val call: UCallExpression, val method: PsiMethod)
data class ResolvedConstructor(val call: UCallExpression, val constructor: PsiMethod, val clazz: PsiClass)
val language: Language
val project: Project
/**
* Checks if the file with the given [fileName] is supported.
*
* @param fileName the source file name.
* @return true, if the file is supported by this converter, false otherwise.
*/
fun isFileSupported(fileName: String): Boolean
/**
* Returns the converter priority. Might be positive, negative or 0 (Java's is 0).
* UastConverter with the higher priority will be queried earlier.
*
* Priority is useful when a language N wraps its own elements (NElement) to, for example, Java's PsiElements,
* and Java resolves the reference to such wrapped PsiElements, not the original NElement.
* In this case N implementation can handle such wrappers in UastConverter earlier than Java's converter,
* so N language converter will have a higher priority.
*/
val priority: Int
fun convertElement(element: PsiElement, parent: UElement?, requiredType: Class<out UElement>? = null): UElement?
/**
* Convert [element] to the [UElement] with the given parent.
*/
fun convertElementWithParent(element: PsiElement, requiredType: Class<out UElement>?): UElement?
fun getMethodCallExpression(
element: PsiElement,
containingClassFqName: String?,
methodName: String
): ResolvedMethod?
fun getConstructorCallExpression(
element: PsiElement,
fqName: String
) : ResolvedConstructor?
fun getMethodBody(element: PsiMethod): UExpression? {
if (element is UMethod) return element.uastBody
return (convertElementWithParent(element, null) as? UMethod)?.uastBody
}
fun getInitializerBody(element: PsiClassInitializer): UExpression {
if (element is UClassInitializer) return element.uastBody
return (convertElementWithParent(element, null) as? UClassInitializer)?.uastBody ?: UastEmptyExpression
}
fun getInitializerBody(element: PsiVariable): UExpression? {
if (element is UVariable) return element.uastInitializer
return (convertElementWithParent(element, null) as? UVariable)?.uastInitializer
}
/**
* Returns true if the expression value is used.
* Do not rely on this property too much, its value can be approximate in some cases.
*/
fun isExpressionValueUsed(element: UExpression): Boolean
}
inline fun <reified T : UElement> UastLanguagePlugin.convertOpt(element: PsiElement?, parent: UElement?): T? {
if (element == null) return null
return convertElement(element, parent) as? T
}
inline fun <reified T : UElement> UastLanguagePlugin.convert(element: PsiElement, parent: UElement?): T {
return convertElement(element, parent, T::class.java) as T
}
inline fun <reified T : UElement> UastLanguagePlugin.convertWithParent(element: PsiElement?): T? {
if (element == null) return null
return convertElementWithParent(element, T::class.java) as? T
}
@@ -1,137 +0,0 @@
@file:JvmMultifileClass
@file:JvmName("UastUtils")
package org.jetbrains.uast
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiNamedElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.uast.expressions.UReferenceExpression
import org.jetbrains.uast.psi.PsiElementBacked
import java.io.File
inline fun <reified T : UElement> UElement.getParentOfType(strict: Boolean = true): T? = getParentOfType(T::class.java, strict)
@JvmOverloads
fun <T : UElement> UElement.getParentOfType(parentClass: Class<out UElement>, strict: Boolean = true): T? {
var element = (if (strict) containingElement else this) ?: return null
while (true) {
if (parentClass.isInstance(element)) {
@Suppress("UNCHECKED_CAST")
return element as T
}
element = element.containingElement ?: return null
}
}
fun <T : UElement> UElement.getParentOfType(
parentClass: Class<out UElement>,
strict: Boolean = true,
vararg terminators: Class<out UElement>
): T? {
var element = (if (strict) containingElement else this) ?: return null
while (true) {
if (parentClass.isInstance(element)) {
@Suppress("UNCHECKED_CAST")
return element as T
}
if (terminators.any { it.isInstance(element) }) {
return null
}
element = element.containingElement ?: return null
}
}
fun <T : UElement> UElement.getParentOfType(
strict: Boolean = true,
firstParentClass: Class<out T>,
vararg parentClasses: Class<out T>
): T? {
var element = (if (strict) containingElement else this) ?: return null
while (true) {
if (firstParentClass.isInstance(element)) {
@Suppress("UNCHECKED_CAST")
return element as T
}
if (parentClasses.any { it.isInstance(element) }) {
@Suppress("UNCHECKED_CAST")
return element as T
}
element = element.containingElement ?: return null
}
}
fun UElement.getContainingFile() = getParentOfType<UFile>(UFile::class.java)
fun UElement.getContainingUClass() = getParentOfType<UClass>(UClass::class.java)
fun UElement.getContainingUMethod() = getParentOfType<UMethod>(UMethod::class.java)
fun UElement.getContainingUVariable() = getParentOfType<UVariable>(UVariable::class.java)
fun UElement.getContainingMethod() = getContainingUMethod()?.psi
fun UElement.getContainingClass() = getContainingUClass()?.psi
fun UElement.getContainingVariable() = getContainingUVariable()?.psi
fun PsiElement?.getContainingClass() = this?.let { PsiTreeUtil.getParentOfType(it, PsiClass::class.java) }
fun UElement.isChildOf(probablyParent: UElement?, strict: Boolean = false): Boolean {
tailrec fun isChildOf(current: UElement?, probablyParent: UElement): Boolean {
return when (current) {
null -> false
probablyParent -> true
else -> isChildOf(current.containingElement, probablyParent)
}
}
if (probablyParent == null) return false
return isChildOf(if (strict) this else containingElement, probablyParent)
}
/**
* Resolves the receiver element if it implements [UResolvable].
*
* @return the resolved element, or null if the element was not resolved, or if the receiver element is not an [UResolvable].
*/
fun UElement.tryResolve(): PsiElement? = (this as? UResolvable)?.resolve()
fun UElement.tryResolveNamed(): PsiNamedElement? = (this as? UResolvable)?.resolve() as? PsiNamedElement
fun UElement.tryResolveUDeclaration(context: UastContext): UDeclaration? {
return (this as? UResolvable)?.resolve()?.let { context.convertElementWithParent(it, null) as? UDeclaration }
}
fun UReferenceExpression?.getQualifiedName() = (this?.resolve() as? PsiClass)?.qualifiedName
/**
* Returns the String expression value, or null if the value can't be calculated or if the calculated value is not a String.
*/
fun UExpression.evaluateString(): String? = evaluate() as? String
/**
* Get a physical [File] for this file, or null if there is no such file on disk.
*/
fun UFile.getIoFile(): File? = psi.virtualFile?.let { VfsUtilCore.virtualToIoFile(it) }
tailrec fun UElement.getUastContext(): UastContext {
if (this is PsiElementBacked) {
val psi = this.psi
if (psi != null) {
return ServiceManager.getService(psi.project, UastContext::class.java) ?: error("UastContext not found")
}
}
return (containingElement ?: error("PsiElement should exist at least for UFile")).getUastContext()
}
tailrec fun UElement.getLanguagePlugin(): UastLanguagePlugin {
if (this is PsiElementBacked) {
val psi = this.psi
if (psi != null) {
val uastContext = ServiceManager.getService(psi.project, UastContext::class.java) ?: error("UastContext not found")
return uastContext.findPlugin(psi) ?: error("Language plugin was not found for $this (${this.javaClass.name})")
}
}
return (containingElement ?: error("PsiElement should exist at least for UFile")).getLanguagePlugin()
}
@@ -1,13 +0,0 @@
package org.jetbrains.uast
import com.intellij.psi.PsiElement
import org.jetbrains.uast.psi.PsiElementBacked
class UComment(override val psi: PsiElement, override val containingElement: UElement) : UElement, PsiElementBacked {
val text: String
get() = asSourceString()
override fun asLogString() = "UComment"
override fun asRenderString(): String = asSourceString()
override fun asSourceString(): String = psi.text
}
@@ -1,91 +0,0 @@
/*
* 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.visitor.UastVisitor
/**
* The common interface for all Uast elements.
*/
interface UElement {
/**
* Returns the element parent.
*/
val containingElement: UElement?
/**
* Returns true if this element is valid, false otherwise.
*/
val isPsiValid: Boolean
get() = true
/**
* Returns the list of comments for this element.
*/
val comments: List<UComment>
get() = emptyList()
/**
* Returns the log string.
*
* Output example (should be something like this):
* UWhileExpression
* UBinaryExpression (>)
* USimpleReferenceExpression (i)
* ULiteralExpression (5)
* UBlockExpression
* UCallExpression (println)
* ULiteralExpression (ABC)
* UPostfixExpression (--)
* USimpleReferenceExpression(i)
*
* @return the expression tree for this element.
* @see [UIfExpression] for example.
*/
fun asLogString(): String
/**
* Returns the string in pseudo-code.
*
* Output example (should be something like this):
* while (i > 5) {
* println("Hello, world")
* i--
* }
*
* @return the rendered text.
* @see [UIfExpression] for example.
*/
fun asRenderString(): String = asLogString()
/**
* Returns the string as written in the source file.
* Use this String only for logging and diagnostic text messages.
*
* @return the original text.
*/
fun asSourceString(): String = asRenderString()
/**
* Passes the element to the specified visitor.
*
* @param visitor the visitor to pass the element to.
*/
fun accept(visitor: UastVisitor) {
visitor.visitElement(this)
visitor.afterVisitElement(this)
}
}
@@ -1,90 +0,0 @@
/*
* 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 com.intellij.psi.PsiType
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents an expression or statement (which is considered as an expression in Uast).
*/
interface UExpression : UElement, UAnnotated {
/**
* Returns the expression value or null if the value can't be calculated.
*/
fun evaluate(): Any? = null
/**
* Returns expression type, or null if type can not be inferred, or if this expression is a statement.
*/
fun getExpressionType(): PsiType? = null
override fun accept(visitor: UastVisitor) {
visitor.visitElement(this)
visitor.afterVisitElement(this)
}
}
/**
* Represents an annotated element.
*/
interface UAnnotated : UElement {
/**
* Returns the list of annotations applied to the current element.
*/
val annotations: List<UAnnotation>
/**
* Looks up for annotation element using the annotation qualified name.
*
* @param fqName the qualified name to search
* @return the first annotation element with the specified qualified name, or null if there is no annotation with such name.
*/
fun findAnnotation(fqName: String): UAnnotation? = annotations.firstOrNull { it.qualifiedName == fqName }
}
/**
* Represents a labeled element.
*/
interface ULabeled : UElement {
/**
* Returns the label name, or null if the label is empty.
*/
val label: String?
/**
* Returns the label identifier, or null if the label is empty.
*/
val labelIdentifier: UIdentifier?
}
/**
* In some cases (user typing, syntax error) elements, which are supposed to exist, are missing.
* The obvious example — the lack of the condition expression in [UIfExpression], e.g. `if () return`.
* [UIfExpression.condition] is required to return not-null values,
* and Uast implementation should return something instead of `null` in this case.
*
* Use [UastEmptyExpression] in this case.
*/
object UastEmptyExpression : UExpression {
override val containingElement: UElement?
get() = null
override val annotations: List<UAnnotation>
get() = emptyList()
override fun asLogString() = "EmptyExpression"
}
@@ -1,33 +0,0 @@
/*
* 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
import com.intellij.psi.PsiElement
import org.jetbrains.uast.psi.PsiElementBacked
class UIdentifier(
override val psi: PsiElement?,
override val containingElement: UElement?
) : UElement, PsiElementBacked {
/**
* Returns the identifier name.
*/
val name: String
get() = psi?.text ?: "<error>"
override fun asLogString() = "Identifier ($name)"
}
@@ -1,19 +0,0 @@
package org.jetbrains.uast
/**
* An interface for the [UElement] which has a name.
*/
interface UNamed {
/**
* Returns the element name.
*/
val name: String?
/**
* Checks if the element name is equal to the passed name.
*
* @param name the name to check against
* @return true if the element name is equal to [name], false otherwise.
*/
fun matchesName(name: String) = this.name == name
}
@@ -1,13 +0,0 @@
package org.jetbrains.uast
import com.intellij.psi.PsiElement
interface UResolvable {
/**
* Resolve the reference.
* Note that the reference is *always* resolved to an unwrapped [PsiElement], never to a [UElement].
*
* @return the resolved element, or null if the reference couldn't be resolved.
*/
fun resolve(): PsiElement?
}
@@ -1,16 +0,0 @@
package org.jetbrains.uast
import com.intellij.psi.PsiType
import com.intellij.psi.PsiTypeVisitor
object UastErrorType : PsiType(emptyArray()) {
override fun getInternalCanonicalText() = "<ErrorType>"
override fun equalsToText(text: String) = false
override fun getCanonicalText() = internalCanonicalText
override fun getPresentableText() = canonicalText
override fun isValid() = false
override fun getResolveScope() = null
override fun getSuperTypes() = emptyArray<PsiType>()
override fun <A : Any?> accept(visitor: PsiTypeVisitor<A>) = visitor.visitType(this)
}
@@ -1,62 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represent a
*
* `do {
* // body
* } while (expr)`
*
* loop expression.
*/
interface UDoWhileExpression : ULoopExpression {
/**
* Returns the loop post-condition.
*/
val condition: UExpression
/**
* Returns an identifier for the 'do' keyword.
*/
val doIdentifier: UIdentifier
/**
* Returns an identifier for the 'while' keyword.
*/
val whileIdentifier: UIdentifier
override fun accept(visitor: UastVisitor) {
if (visitor.visitDoWhileExpression(this)) return
annotations.acceptList(visitor)
condition.accept(visitor)
body.accept(visitor)
visitor.afterVisitDoWhileExpression(this)
}
override fun asRenderString() = buildString {
append("do ")
append(body.asRenderString())
appendln("while (${condition.asRenderString()})")
}
override fun asLogString() = log("UDoWhileExpression", condition, body)
}
@@ -1,65 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a
*
* `for (element : collectionOfElements) {
* // body
* }`
*
* loop expression.
*/
interface UForEachExpression : ULoopExpression {
/**
* Returns the loop variable.
*/
val variable: UParameter
/**
* Returns the iterated value (collection, sequence, iterable etc.)
*/
val iteratedValue: UExpression
/**
* Returns the identifier for the 'for' ('foreach') keyword.
*/
val forIdentifier: UIdentifier
override fun accept(visitor: UastVisitor) {
if (visitor.visitForEachExpression(this)) return
annotations.acceptList(visitor)
iteratedValue.accept(visitor)
body.accept(visitor)
visitor.afterVisitForEachExpression(this)
}
override fun asRenderString() = buildString {
append("for (")
append(variable.name)
append(" : ")
append(iteratedValue.asRenderString())
append(") ")
append(body.asRenderString())
}
override fun asLogString() = log("UForEachExpression", variable, iteratedValue, body)
}
@@ -1,74 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a
*
* `for (initDeclarations; loopCondition; update) {
* // body
* }`
*
* loop expression.
*/
interface UForExpression : ULoopExpression {
/**
* Returns the [UExpression] containing variable declarations, or null if the are no variables declared.
*/
val declaration: UExpression?
/**
* Returns the loop condition, or null if the condition is empty.
*/
val condition: UExpression?
/**
* Returns the loop update expression(s).
*/
val update: UExpression?
/**
* Returns the identifier for the 'for' keyword.
*/
val forIdentifier: UIdentifier
override fun accept(visitor: UastVisitor) {
if (visitor.visitForExpression(this)) return
annotations.acceptList(visitor)
declaration?.accept(visitor)
condition?.accept(visitor)
update?.accept(visitor)
body.accept(visitor)
visitor.afterVisitForExpression(this)
}
override fun asRenderString() = buildString {
append("for (")
declaration?.let { append(it.asRenderString()) }
append("; ")
condition?.let { append(it.asRenderString()) }
append("; ")
update?.let { append(it.asRenderString()) }
append(") ")
append(body.asRenderString())
}
override fun asLogString() = log("UForExpression", declaration, condition, update, body)
}
@@ -1,97 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents
*
* `if (condition) {
* // do if true
* } else {
* // do if false
* }`
*
* and
*
* `condition : trueExpression ? falseExpression`
*
* condition expressions.
*/
interface UIfExpression : UExpression {
/**
* Returns the condition expression.
*/
val condition: UExpression
/**
* Returns the expression which is executed if the condition is true, or null if the expression is empty.
*/
val thenExpression: UExpression?
/**
* Returns the expression which is executed if the condition is false, or null if the expression is empty.
*/
val elseExpression: UExpression?
/**
* Returns true if the expression is ternary (condition ? trueExpression : falseExpression).
*/
val isTernary: Boolean
/**
* Returns an identifier for the 'if' keyword.
*/
val ifIdentifier: UIdentifier
/**
* Returns an identifier for the 'else' keyword, or null if the conditional expression has not the 'else' part.
*/
val elseIdentifier: UIdentifier?
override fun accept(visitor: UastVisitor) {
if (visitor.visitIfExpression(this)) return
annotations.acceptList(visitor)
condition.accept(visitor)
thenExpression?.accept(visitor)
elseExpression?.accept(visitor)
visitor.afterVisitIfExpression(this)
}
override fun asLogString() = log("UIfExpression", condition, thenExpression, elseExpression)
override fun asRenderString() = buildString {
if (isTernary) {
append("(" + condition.asRenderString() + ")")
append(" ? ")
append("(" + (thenExpression?.asRenderString() ?: "<noexpr>") + ")")
append(" : ")
append("(" + (elseExpression?.asRenderString() ?: "<noexpr>") + ")")
} else {
append("if (${condition.asRenderString()}) ")
thenExpression?.let { append(it.asRenderString()) }
val elseBranch = elseExpression
if (elseBranch != null && elseBranch !is UastEmptyExpression) {
if (thenExpression !is UBlockExpression) append(" ")
append("else ")
append(elseBranch.asRenderString())
}
}
}
}
@@ -1,26 +0,0 @@
/*
* 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
/**
* Represents a loop expression.
*/
interface ULoopExpression : UExpression {
/**
* Returns the loop body [UExpression].
*/
val body: UExpression
}
@@ -1,113 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a
*
* ` switch (expression) {
* case value1 -> expr1
* case value2 -> expr2
* ...
* else -> exprElse
* }
*
* conditional expression.
*/
interface USwitchExpression : UExpression {
/**
Returns the expression on which the `switch` expression is performed.
*/
val expression: UExpression?
/**
Returns the switch body.
The body should contain [USwitchClauseExpression] expressions.
*/
val body: UExpression
/**
* Returns an identifier for the 'switch' ('case', 'when', ...) keyword.
*/
val switchIdentifier: UIdentifier
override fun accept(visitor: UastVisitor) {
if (visitor.visitSwitchExpression(this)) return
annotations.acceptList(visitor)
expression?.accept(visitor)
body.accept(visitor)
visitor.afterVisitSwitchExpression(this)
}
override fun asLogString() = log("USwitchExpression", expression, body)
override fun asRenderString() = buildString {
val expr = expression?.let { "(" + it.asRenderString() + ") " } ?: ""
appendln("switch $expr")
appendln(body.asRenderString())
}
}
/**
* Represents a [USwitchExpression] clause.
* [USwitchClauseExpression] does not contain the clause body,
* and the actual body expression should be the next element in the parent expression list.
*/
interface USwitchClauseExpression : UExpression {
/**
* Returns the list of values for this clause, or null if the are no values for this close
* (for example, for the `else` clause).
*/
val caseValues: List<UExpression>?
override fun accept(visitor: UastVisitor) {
if (visitor.visitSwitchClauseExpression(this)) return
annotations.acceptList(visitor)
caseValues?.acceptList(visitor)
visitor.afterVisitSwitchClauseExpression(this)
}
override fun asRenderString() = (caseValues?.joinToString { it.asRenderString() } ?: "else") + " -> "
override fun asLogString() = log("USwitchClauseExpression", caseValues)
}
/**
* Represents a [USwitchExpression] clause with the body.
* [USwitchClauseExpressionWithBody], comparing with [USwitchClauseExpression], contains the body expression.
*
* Implementing this interface *is the right way* to support `switch` clauses in your language.
*/
interface USwitchClauseExpressionWithBody : USwitchClauseExpression {
/**
* Returns the body expression for this clause.
*/
val body: UExpression
override fun accept(visitor: UastVisitor) {
if (visitor.visitSwitchClauseExpression(this)) return
annotations.acceptList(visitor)
caseValues?.acceptList(visitor)
body.accept(visitor)
visitor.afterVisitSwitchClauseExpression(this)
}
override fun asRenderString() = (caseValues?.joinToString { it.asRenderString() } ?: "else") + " -> " + body.asRenderString()
override fun asLogString() = log("USwitchClauseExpressionWithBody", caseValues, body)
}
@@ -1,133 +0,0 @@
/*
* 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 com.intellij.psi.PsiResourceListElement
import com.intellij.psi.PsiType
import org.jetbrains.uast.expressions.UTypeReferenceExpression
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents
*
* `try {
* // tryClause body
* } catch (e: Type1, Type2 ... TypeN) {
* // catchClause1 body
* } ... {
* finally {
* //finallyBody
* }`
*
* and
*
* `try (resource1, ..., resourceN) {
* // tryClause body
* }`
*
* expressions.
*/
interface UTryExpression : UExpression {
/**
* Returns `true` if the try expression is a try-with-resources expression.
*/
val isResources: Boolean
/**
* Returns the list of try resources, or null if this expression is not a `try-with-resources` expression.
*/
val resources: List<PsiResourceListElement>?
/**
* Returns the `try` clause expression.
*/
val tryClause: UExpression
/**
* Returns the `catch` clauses [UCatchClause] expression list.
*/
val catchClauses: List<UCatchClause>
/**
* Returns the `finally` clause expression, or null if the `finally` clause is absent.
*/
val finallyClause: UExpression?
/**
* Returns an identifier for the 'try' keyword.
*/
val tryIdentifier: UIdentifier
/**
* Returns an identifier for the 'finally' keyword, or null if the 'try' expression has not a 'finally' clause.
*/
val finallyIdentifier: UIdentifier?
override fun accept(visitor: UastVisitor) {
if (visitor.visitTryExpression(this)) return
annotations.acceptList(visitor)
tryClause.accept(visitor)
catchClauses.acceptList(visitor)
finallyClause?.accept(visitor)
visitor.afterVisitTryExpression(this)
}
override fun asRenderString() = buildString {
append("try ")
appendln(tryClause.asRenderString().trim('\n', '\r'))
catchClauses.forEach { appendln(it.asRenderString().trim('\n', '\r')) }
finallyClause?.let { append("finally ").append(it.asRenderString().trim('\n', '\r')) }
}
override fun asLogString() = log("UTryExpression", tryClause, catchClauses, finallyClause)
}
/**
* Represents the `catch` clause in [UTryExpression].
*/
interface UCatchClause : UElement {
/**
* Returns the `catch` clause body expression.
*/
val body: UExpression
/**
* Returns the exception parameter variables for this `catch` clause.
*/
val parameters: List<UParameter>
/**
* Returns the exception type references for this `catch` clause.
*/
val typeReferences: List<UTypeReferenceExpression>
/**
* Returns the expression types for this `catch` clause.
*/
val types: List<PsiType>
get() = typeReferences.map { it.type }
override fun accept(visitor: UastVisitor) {
if (visitor.visitCatchClause(this)) return
body.accept(visitor)
visitor.afterVisitCatchClause(this)
}
override fun asLogString() = log("UCatchClause", body)
override fun asRenderString() = "catch (e) " + body.asRenderString()
}
@@ -1,56 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a
*
* `while (condition) {
* // body
* }`
*
* expression.
*/
interface UWhileExpression : ULoopExpression {
/**
* Returns the loop condition.
*/
val condition: UExpression
/**
* Returns an identifier for the 'while' keyword.
*/
val whileIdentifier: UIdentifier
override fun accept(visitor: UastVisitor) {
if (visitor.visitWhileExpression(this)) return
annotations.acceptList(visitor)
condition.accept(visitor)
body.accept(visitor)
visitor.afterVisitWhileExpression(this)
}
override fun asRenderString() = buildString {
append("while (${condition.asRenderString()}) ")
append(body.asRenderString())
}
override fun asLogString() = log("UWhileExpression", condition, body)
}
@@ -1,38 +0,0 @@
package org.jetbrains.uast
import com.intellij.psi.PsiClass
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.psi.PsiElementBacked
import org.jetbrains.uast.visitor.UastVisitor
/**
* An annotation wrapper to be used in [UastVisitor].
*/
interface UAnnotation : UElement, PsiElementBacked, UResolvable {
/**
* Returns the annotation qualified name.
*/
val qualifiedName: String?
/**
* Returns the annotation class, or null if the class reference was not resolved.
*/
override fun resolve(): PsiClass?
/**
* Returns the annotation values.
*/
val attributeValues: List<UNamedExpression>
fun findAttributeValue(name: String?): UNamedExpression?
fun findDeclaredAttributeValue(name: String?): UNamedExpression?
override fun asLogString() = "UAnnotation"
override fun accept(visitor: UastVisitor) {
if (visitor.visitAnnotation(this)) return
attributeValues.acceptList(visitor)
visitor.afterVisitAnnotation(this)
}
}
@@ -1,45 +0,0 @@
package org.jetbrains.uast
import com.intellij.psi.PsiAnonymousClass
import com.intellij.psi.PsiClass
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* A class wrapper to be used in [UastVisitor].
*/
interface UClass : UDeclaration, PsiClass {
override val psi: PsiClass
/**
* Returns a [UClass] wrapper of the superclass of this class, or null if this class is [java.lang.Object].
*/
val uastSuperClass: UClass?
get() {
val superClass = superClass ?: return null
return getUastContext().convertWithParent(superClass)
}
/**
* Returns [UDeclaration] wrappers for the class declarations.
*/
val uastDeclarations: List<UDeclaration>
val uastFields: List<UVariable>
val uastInitializers: List<UClassInitializer>
val uastMethods: List<UMethod>
val uastNestedClasses: List<UClass>
override fun asLogString() = "UClass (name = $name)"
override fun accept(visitor: UastVisitor) {
if (visitor.visitClass(this)) return
annotations.acceptList(visitor)
uastDeclarations.acceptList(visitor)
visitor.afterVisitClass(this)
}
}
interface UAnonymousClass : UClass, PsiAnonymousClass {
override val psi: PsiAnonymousClass
}
@@ -1,29 +0,0 @@
package org.jetbrains.uast
import com.intellij.psi.PsiClassInitializer
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* A class initializer wrapper to be used in [UastVisitor].
*/
interface UClassInitializer : UDeclaration, PsiClassInitializer {
override val psi: PsiClassInitializer
/**
* Returns the body of this class initializer.
*/
val uastBody: UExpression
@Deprecated("Use uastBody instead.", ReplaceWith("uastBody"))
override fun getBody() = psi.body
override fun accept(visitor: UastVisitor) {
if (visitor.visitInitializer(this)) return
annotations.acceptList(visitor)
uastBody.accept(visitor)
visitor.afterVisitInitializer(this)
}
override fun asLogString() = "UMethod (name = ${psi.name}"
}
@@ -1,41 +0,0 @@
package org.jetbrains.uast
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiModifier
import com.intellij.psi.PsiModifierListOwner
import org.jetbrains.uast.psi.PsiElementBacked
/**
* A [PsiElement] declaration wrapper.
*/
interface UDeclaration : UElement, PsiElementBacked, PsiModifierListOwner, UAnnotated {
/**
* Returns the original declaration (which is *always* unwrapped, never a [UDeclaration]).
*/
override val psi: PsiModifierListOwner
override fun getOriginalElement(): PsiElement? = psi.originalElement
/**
* Returns the declaration name identifier, or null if the declaration is anonymous.
*/
val uastAnchor: UElement?
/**
* Returns `true` if this declaration has a [PsiModifier.STATIC] modifier.
*/
val isStatic: Boolean
get() = hasModifierProperty(PsiModifier.STATIC)
/**
* Returns `true` if this declaration has a [PsiModifier.FINAL] modifier.
*/
val isFinal: Boolean
get() = hasModifierProperty(PsiModifier.FINAL)
/**
* Returns a declaration visibility.
*/
val visibility: UastVisibility
get() = UastVisibility[this]
}
@@ -1,58 +0,0 @@
package org.jetbrains.uast
import com.intellij.psi.PsiFile
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a Uast file.
*/
interface UFile : UElement, UAnnotated {
/**
* Returns the original [PsiFile].
*/
val psi: PsiFile
/**
* Returns the Java package name of this file.
* Returns an empty [String] for the default package.
*/
val packageName: String
/**
* Returns the import statements for this file.
*/
val imports: List<UImportStatement>
/**
* Returns the list of top-level classes declared in this file.
*/
val classes: List<UClass>
/**
* Returns the plugin for a language used in this file.
*/
val languagePlugin: UastLanguagePlugin
/**
* Returns all comments in file.
*/
val allCommentsInFile: List<UComment>
override fun asLogString() = "UFile"
/**
* [UFile] is a top-level element of the Uast hierarchy, thus the [containingElement] always returns null for it.
*/
override val containingElement: UElement?
get() = null
override fun accept(visitor: UastVisitor) {
if (visitor.visitFile(this)) return
annotations.acceptList(visitor)
imports.acceptList(visitor)
classes.acceptList(visitor)
visitor.afterVisitFile(this)
}
}
@@ -1,26 +0,0 @@
package org.jetbrains.uast
import org.jetbrains.uast.psi.PsiElementBacked
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents an import statement.
*/
interface UImportStatement : UResolvable, UElement, PsiElementBacked {
/**
* Returns true if the statement is an import-on-demand (star-import) statement.
*/
val isOnDemand: Boolean
/**
* Returns the reference to the imported element.
*/
val importReference: UElement?
override fun asLogString() = "UImportStatement (onDemand = $isOnDemand)"
override fun accept(visitor: UastVisitor) {
if (visitor.visitImportStatement(this)) return
visitor.afterVisitImportStatement(this)
}
}
@@ -1,63 +0,0 @@
package org.jetbrains.uast
import com.intellij.psi.PsiAnnotationMethod
import com.intellij.psi.PsiMethod
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* A method visitor to be used in [UastVisitor].
*/
interface UMethod : UDeclaration, PsiMethod {
override val psi: PsiMethod
/**
* Returns the body expression (which can be also a [UBlockExpression]).
*/
val uastBody: UExpression?
/**
* Returns the method parameters.
*/
val uastParameters: List<UParameter>
/**
* Returns true, if the method overrides a method of a super class.
*/
val isOverride: Boolean
@Deprecated("Use uastBody instead.", ReplaceWith("uastBody"))
override fun getBody() = psi.body
override fun accept(visitor: UastVisitor) {
if (visitor.visitMethod(this)) return
annotations.acceptList(visitor)
uastParameters.acceptList(visitor)
uastBody?.accept(visitor)
visitor.afterVisitMethod(this)
}
override fun asLogString() = "UMethod (name = $name)"
}
interface UAnnotationMethod : UMethod, PsiAnnotationMethod {
override val psi: PsiAnnotationMethod
/**
* Returns the default value of this annotation method.
*/
val uastDefaultValue: UExpression?
override fun getDefaultValue() = psi.defaultValue
override fun accept(visitor: UastVisitor) {
if (visitor.visitMethod(this)) return
annotations.acceptList(visitor)
uastParameters.acceptList(visitor)
uastBody?.accept(visitor)
uastDefaultValue?.accept(visitor)
visitor.afterVisitMethod(this)
}
override fun asLogString() = "UAnnotationMethod (name = $name)"
}
@@ -1,70 +0,0 @@
package org.jetbrains.uast
import com.intellij.psi.*
import org.jetbrains.uast.expressions.UTypeReferenceExpression
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* A variable wrapper to be used in [UastVisitor].
*/
interface UVariable : UDeclaration, PsiVariable {
override val psi: PsiVariable
/**
* Returns the variable initializer or the parameter default value, or null if the variable has not an initializer.
*/
val uastInitializer: UExpression?
/**
* Returns variable type reference.
*/
val typeReference: UTypeReferenceExpression?
override fun accept(visitor: UastVisitor) {
if (visitor.visitVariable(this)) return
annotations.acceptList(visitor)
uastInitializer?.accept(visitor)
visitor.afterVisitVariable(this)
}
@Deprecated("Use uastInitializer instead.", ReplaceWith("uastInitializer"))
override fun getInitializer() = psi.initializer
override fun asLogString() = "UVariable (name = $name)"
override fun asRenderString() = buildString {
val modifiers = PsiModifier.MODIFIERS.filter { psi.hasModifierProperty(it) }.joinToString(" ")
if (modifiers.isNotEmpty()) append(modifiers).append(' ')
append("var ").append(psi.name).append(": ").append(psi.type.getCanonicalText(false))
}
}
interface UParameter : UVariable, PsiParameter {
override val psi: PsiParameter
}
interface UField : UVariable, PsiField {
override val psi: PsiField
}
interface ULocalVariable : UVariable, PsiLocalVariable {
override val psi: PsiLocalVariable
}
interface UEnumConstant : UField, UCallExpression, PsiEnumConstant {
override val psi: PsiEnumConstant
override fun asLogString() = "UEnumConstant (name = ${psi.name}"
override fun accept(visitor: UastVisitor) {
if (visitor.visitVariable(this)) return
annotations.acceptList(visitor)
methodIdentifier?.accept(visitor)
classReference?.accept(visitor)
valueArguments.acceptList(visitor)
visitor.afterVisitVariable(this)
}
override fun asRenderString() = name ?: "<ERROR>"
}
@@ -1,47 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents `receiver[index0, ..., indexN]` expression.
*/
interface UArrayAccessExpression : UExpression {
/**
* Returns the receiver expression.
*/
val receiver: UExpression
/**
* Returns the list of index expressions.
*/
val indices: List<UExpression>
override fun accept(visitor: UastVisitor) {
if (visitor.visitArrayAccessExpression(this)) return
annotations.acceptList(visitor)
receiver.accept(visitor)
indices.acceptList(visitor)
visitor.afterVisitArrayAccessExpression(this)
}
override fun asLogString() = log("UArrayAccessExpression", receiver, indices)
override fun asRenderString() = receiver.asRenderString() +
indices.joinToString(prefix = "[", postfix = "]") { it.asRenderString() }
}
@@ -1,67 +0,0 @@
/*
* 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 com.intellij.psi.PsiMethod
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a binary expression (value1 op value2), eg. `2 + "A"`.
*/
interface UBinaryExpression : UExpression {
/**
* Returns the left operand.
*/
val leftOperand: UExpression
/**
* Returns the right operand.
*/
val rightOperand: UExpression
/**
* Returns the binary operator.
*/
val operator: UastBinaryOperator
/**
* Returns the operator identifier.
*/
val operatorIdentifier: UIdentifier?
/**
* Resolve the operator method.
*
* @return the resolved method, or null if the method can't be resolved, or if the expression is not a method call.
*/
fun resolveOperator(): PsiMethod?
override fun accept(visitor: UastVisitor) {
if (visitor.visitBinaryExpression(this)) return
annotations.acceptList(visitor)
leftOperand.accept(visitor)
rightOperand.accept(visitor)
visitor.afterVisitBinaryExpression(this)
}
override fun asLogString() =
"UBinaryExpression (${operator.text})" + LINE_SEPARATOR +
leftOperand.asLogString().withMargin + LINE_SEPARATOR +
rightOperand.asLogString().withMargin
override fun asRenderString() = leftOperand.asRenderString() + ' ' + operator.text + ' ' + rightOperand.asRenderString()
}
@@ -1,60 +0,0 @@
/*
* 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 com.intellij.psi.PsiType
import org.jetbrains.uast.expressions.UTypeReferenceExpression
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a binary expression with type (value op type), e.g. ("A" instanceof String).
*/
interface UBinaryExpressionWithType : UExpression {
/**
* Returns the operand expression.
*/
val operand: UExpression
/**
* Returns the operation kind.
*/
val operationKind: UastBinaryExpressionWithTypeKind
/**
* Returns the type reference of this expression.
*/
val typeReference: UTypeReferenceExpression?
/**
* Returns the type.
*/
val type: PsiType
override fun asLogString() = log("UBinaryExpressionWithType " +
"(${getExpressionType()?.name}, ${operationKind.name})", operand)
override fun asRenderString() = "${operand.asRenderString()} ${operationKind.name} ${type.name}"
override fun accept(visitor: UastVisitor) {
if (visitor.visitBinaryExpressionWithType(this)) return
annotations.acceptList(visitor)
operand.accept(visitor)
visitor.afterVisitBinaryExpressionWithType(this)
}
}
@@ -1,45 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents the code block expression: `{ /* code */ }`.
*/
interface UBlockExpression : UExpression {
/**
* Returns the list of block expressions.
*/
val expressions: List<UExpression>
override fun accept(visitor: UastVisitor) {
if (visitor.visitBlockExpression(this)) return
annotations.acceptList(visitor)
expressions.acceptList(visitor)
visitor.afterVisitBlockExpression(this)
}
override fun asLogString() = log("UBlockExpression", expressions)
override fun asRenderString() = buildString {
appendln("{")
expressions.forEach { appendln(it.asRenderString().withMargin) }
appendln("}")
}
}
@@ -1,39 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a `break` expression.
*/
interface UBreakExpression : UExpression {
/**
* Returns the expression label, or null if the label is not specified.
*/
val label: String?
override fun accept(visitor: UastVisitor) {
if (visitor.visitBreakExpression(this)) return
annotations.acceptList(visitor)
visitor.afterVisitBreakExpression(this)
}
override fun asLogString() = "UBreakExpression (" + (label ?: "<no label>") + ")"
override fun asRenderString() = label?.let { "break@$it" } ?: "break"
}
@@ -1,113 +0,0 @@
/*
* 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 com.intellij.psi.PsiMethod
import com.intellij.psi.PsiType
import org.jetbrains.uast.expressions.UReferenceExpression
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a call expression (method/constructor call, array initializer).
*/
interface UCallExpression : UExpression, UResolvable {
/**
* Returns the call kind.
*/
val kind: UastCallKind
/**
* Returns the called method name, or null if the call is not a method call.
* This property should return the actual resolved function name.
*/
val methodName: String?
/**
* Returns the expression receiver.
* For example, for call `a.b.[c()]` the receiver is `a.b`.
*/
val receiver: UExpression?
/**
* Returns the receiver type, or null if the call has not a receiver.
*/
val receiverType: PsiType?
/**
* Returns the function reference expression if the call is a non-constructor method call, null otherwise.
*/
val methodIdentifier: UIdentifier?
/**
* Returns the class reference if the call is a constructor call, null otherwise.
*/
val classReference: UReferenceExpression?
/**
* Returns the value argument count.
*
* Retrieving the argument count could be faster than getting the [valueArguments.size],
* because there is no need to create actual [UExpression] instances.
*/
val valueArgumentCount: Int
/**
* Returns the list of value arguments.
*/
val valueArguments: List<UExpression>
/**
* Returns the type argument count.
*/
val typeArgumentCount: Int
/**
* Returns the type arguments for the call.
*/
val typeArguments: List<PsiType>
/**
* Returns the return type of the called function, or null if the call is not a function call.
*/
val returnType: PsiType?
/**
* Resolve the called method.
*
* @return the [PsiMethod], or null if the method was not resolved.
* Note that the [PsiMethod] is an unwrapped [PsiMethod], not a [UMethod].
*/
override fun resolve(): PsiMethod?
override fun accept(visitor: UastVisitor) {
if (visitor.visitCallExpression(this)) return
annotations.acceptList(visitor)
methodIdentifier?.accept(visitor)
classReference?.accept(visitor)
valueArguments.acceptList(visitor)
visitor.afterVisitCallExpression(this)
}
override fun asLogString() = log("UCallExpression ($kind, argCount = $valueArgumentCount)", methodIdentifier, valueArguments)
override fun asRenderString(): String {
val ref = classReference?.asRenderString() ?: methodName ?: methodIdentifier?.asRenderString() ?: "<noref>"
return ref + "(" + valueArguments.joinToString { it.asRenderString() } + ")"
}
}
@@ -1,62 +0,0 @@
/*
* 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 com.intellij.psi.PsiType
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a callable reference expression, e.g. `Clazz::methodName`.
*/
interface UCallableReferenceExpression : UExpression {
/**
* Returns the qualifier expression.
* Can be null if the [qualifierType] is known.
*/
val qualifierExpression: UExpression?
/**
* Returns the qualifier type.
* Can be null if the qualifier is an expression.
*/
val qualifierType: PsiType?
/**
* Returns the callable name.
*/
val callableName: String
override fun accept(visitor: UastVisitor) {
if (visitor.visitCallableReferenceExpression(this)) return
annotations.acceptList(visitor)
qualifierExpression?.accept(visitor)
visitor.afterVisitCallableReferenceExpression(this)
}
override fun asLogString() = "UCallableReferenceExpression"
override fun asRenderString() = buildString {
qualifierExpression?.let {
append(it.asRenderString())
} ?: qualifierType?.let {
append(it.name)
}
append("::")
append(callableName)
}
}
@@ -1,47 +0,0 @@
/*
* 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 com.intellij.psi.PsiType
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents the class literal expression, e.g. `Clazz.class`.
*/
interface UClassLiteralExpression : UExpression {
override fun asLogString() = "UClassLiteralExpression"
override fun asRenderString() = (type?.name) ?: "(${expression?.asRenderString() ?: "<no expression>"})" + "::class"
/**
* Returns a type of this class literal, or null if the type can't be determined in a compile-time.
*/
val type: PsiType?
/**
* Returns an expression for this class literal expression.
* Might be null if the [type] is specified.
*/
val expression: UExpression?
override fun accept(visitor: UastVisitor) {
if (visitor.visitClassLiteralExpression(this)) return
annotations.acceptList(visitor)
expression?.accept(visitor)
visitor.afterVisitClassLiteralExpression(this)
}
}
@@ -1,39 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a `continue` expression.
*/
interface UContinueExpression : UExpression {
/**
* Returns the expression label, or null if the label is not specified.
*/
val label: String?
override fun accept(visitor: UastVisitor) {
if (visitor.visitContinueExpression(this)) return
annotations.acceptList(visitor)
visitor.afterVisitContinueExpression(this)
}
override fun asLogString() = "UContinueExpression (" + (label ?: "<no label>") + ")"
override fun asRenderString() = label?.let { "continue@$it" } ?: "continue"
}
@@ -1,47 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a generic list of expressions.
*/
interface UExpressionList : UExpression {
/**
* Returns the list of expressions.
*/
val expressions: List<UExpression>
/**
* Returns the list kind.
*/
val kind: UastSpecialExpressionKind
override fun accept(visitor: UastVisitor) {
if (visitor.visitExpressionList(this)) return
annotations.acceptList(visitor)
expressions.acceptList(visitor)
visitor.afterVisitExpressionList(this)
}
fun firstOrNull(): UExpression? = expressions.firstOrNull()
override fun asLogString() = log("USpecialExpressionList (${kind.name})", expressions)
override fun asRenderString() = kind.name + " " + expressions.joinToString(" : ") { it.asRenderString() }
}
@@ -1,26 +0,0 @@
/*
* 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.expressions
import org.jetbrains.uast.UExpression
import org.jetbrains.uast.ULabeled
import org.jetbrains.uast.UResolvable
/**
* A common parent for "this" and "super" expressions.
*/
interface UInstanceExpression : UExpression, ULabeled, UResolvable
@@ -1,47 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents an expression with the label specified.
*/
interface ULabeledExpression : UExpression, ULabeled {
/**
* Returns the expression label.
*/
override val label: String
/**
* Returns the expression itself.
*/
val expression: UExpression
override fun accept(visitor: UastVisitor) {
if (visitor.visitLabeledExpression(this)) return
annotations.acceptList(visitor)
expression.accept(visitor)
visitor.afterVisitLabeledExpression(this)
}
override fun evaluate() = expression.evaluate()
override fun asLogString() = log("ULabeledExpression ($label)", expression)
override fun asRenderString() = "$label@ ${expression.asRenderString()}"
}
@@ -1,54 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents the lambda expression.
*/
interface ULambdaExpression : UExpression {
/**
* Returns the list of lambda value parameters.
*/
val valueParameters: List<UParameter>
/**
* Returns the lambda body expression.
*/
val body: UExpression
override fun accept(visitor: UastVisitor) {
if (visitor.visitLambdaExpression(this)) return
annotations.acceptList(visitor)
valueParameters.acceptList(visitor)
body.accept(visitor)
visitor.afterVisitLambdaExpression(this)
}
override fun asLogString() = log("ULambdaExpression", valueParameters, body)
override fun asRenderString(): String {
val renderedValueParameters = if (valueParameters.isEmpty())
""
else
valueParameters.joinToString { it.asRenderString() } + " ->" + LINE_SEPARATOR
return "{ " + renderedValueParameters + body.asRenderString().withMargin + LINE_SEPARATOR + "}"
}
}
@@ -1,69 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a literal expression.
*/
interface ULiteralExpression : UExpression {
/**
* Returns the literal expression value.
* This is basically a String, Number or null if the literal is a `null` literal.
*/
val value: Any?
/**
* Returns true if the literal is a `null`-literal, false otherwise.
*/
val isNull: Boolean
get() = value == null
/**
* Returns true if the literal is a [String] literal, false otherwise.
*/
val isString: Boolean
get() = evaluate() is String
/**
* Returns true if the literal is a [Boolean] literal, false otherwise.
*/
val isBoolean: Boolean
get() = evaluate() is Boolean
override fun accept(visitor: UastVisitor) {
if (visitor.visitLiteralExpression(this)) return
annotations.acceptList(visitor)
visitor.afterVisitLiteralExpression(this)
}
override fun asRenderString(): String {
val value = value
return when (value) {
null -> "null"
is Char -> "'$value'"
is String -> '"' + value.replace("\\", "\\\\")
.replace("\r", "\\r").replace("\n", "\\n")
.replace("\t", "\\t").replace("\b", "\\b")
.replace("\"", "\\\"") + '"'
else -> value.toString()
}
}
override fun asLogString() = "ULiteralExpression (${asRenderString()})"
}
@@ -1,50 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
class UNamedExpression(
override val name: String,
override val containingElement: UElement?
): UExpression, UNamed {
lateinit var expression: UExpression
override val annotations: List<UAnnotation>
get() = emptyList()
override fun accept(visitor: UastVisitor) {
if (visitor.visitElement(this)) return
annotations.acceptList(visitor)
expression.accept(visitor)
visitor.afterVisitElement(this)
}
override fun asLogString() = log("UNamedExpression ($name)", expression)
override fun asRenderString() = name + " = " + expression.asRenderString()
override fun evaluate() = expression.evaluate()
companion object {
inline fun create(name: String, parent: UElement?, innerExpr: UElement.() -> UExpression): UNamedExpression {
return UNamedExpression(name, parent).apply {
expression = innerExpr(this)
}
}
}
}
@@ -1,60 +0,0 @@
/*
* 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 com.intellij.psi.PsiType
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents an object literal expression, e.g. `new Runnable() {}` in Java.
*/
interface UObjectLiteralExpression : UCallExpression {
/**
* Returns the class declaration.
*/
val declaration: UClass
override val methodIdentifier: UIdentifier?
get() = null
override val kind: UastCallKind
get() = UastCallKind.CONSTRUCTOR_CALL
override val methodName: String?
get() = null
override val receiver: UExpression?
get() = null
override val receiverType: PsiType?
get() = null
override val returnType: PsiType?
get() = null
override fun accept(visitor: UastVisitor) {
if (visitor.visitObjectLiteralExpression(this)) return
annotations.acceptList(visitor)
declaration.accept(visitor)
visitor.afterVisitObjectLiteralExpression(this)
}
override fun asLogString() = log("UObjectLiteralExpression", declaration)
override fun asRenderString() = "anonymous " + declaration.text
}
@@ -1,42 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a parenthesized expression, e.g. `(23 + 3)`.
*/
interface UParenthesizedExpression : UExpression {
/**
* Returns an expression inside the parenthesis.
*/
val expression: UExpression
override fun accept(visitor: UastVisitor) {
if (visitor.visitParenthesizedExpression(this)) return
annotations.acceptList(visitor)
expression.accept(visitor)
visitor.afterVisitParenthesizedExpression(this)
}
override fun evaluate() = expression.evaluate()
override fun asLogString() = log("UParenthesizedExpression", expression)
override fun asRenderString() = '(' + expression.asRenderString() + ')'
}
@@ -1,53 +0,0 @@
/*
* 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.expressions.UReferenceExpression
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents the qualified expression (receiver.selector).
*/
interface UQualifiedReferenceExpression : UReferenceExpression {
/**
* Returns the expression receiver.
*/
val receiver: UExpression
/**
* Returns the expression selector.
*/
val selector: UExpression
/**
* Returns the access type (simple, safe access, etc.).
*/
val accessType: UastQualifiedExpressionAccessType
override fun asRenderString() = receiver.asRenderString() + accessType.name + selector.asRenderString()
override fun accept(visitor: UastVisitor) {
if (visitor.visitQualifiedReferenceExpression(this)) return
annotations.acceptList(visitor)
receiver.accept(visitor)
selector.accept(visitor)
visitor.afterVisitQualifiedReferenceExpression(this)
}
override fun asLogString() = log("UQualifiedExpression", receiver, selector)
}
@@ -1,29 +0,0 @@
/*
* 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.expressions
import org.jetbrains.uast.UExpression
import org.jetbrains.uast.UResolvable
interface UReferenceExpression : UExpression, UResolvable {
/**
* Returns the resolved name for this reference, or null if the reference can't be resolved.
*/
val resolvedName: String?
override fun asLogString() = "UReferenceExpression"
}
@@ -1,41 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a `return` expression.
*/
interface UReturnExpression : UExpression {
/**
* Returns the `return` value.
*/
val returnExpression: UExpression?
override fun accept(visitor: UastVisitor) {
if (visitor.visitReturnExpression(this)) return
annotations.acceptList(visitor)
returnExpression?.accept(visitor)
visitor.afterVisitReturnExpression(this)
}
override fun asRenderString() = returnExpression.let { if (it == null) "return" else "return " + it.asRenderString() }
override fun asLogString() = log("UReturnExpression", returnExpression)
}
@@ -1,39 +0,0 @@
/*
* 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.expressions.UReferenceExpression
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a simple reference expression (a non-qualified identifier).
*/
interface USimpleNameReferenceExpression : UReferenceExpression {
/**
* Returns the identifier name.
*/
val identifier: String
override fun accept(visitor: UastVisitor) {
if (visitor.visitSimpleNameReferenceExpression(this)) return
annotations.acceptList(visitor)
visitor.afterVisitSimpleNameReferenceExpression(this)
}
override fun asLogString() = "USimpleReferenceExpression ($identifier)"
override fun asRenderString() = identifier
}
@@ -1,35 +0,0 @@
/*
* 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.expressions.UInstanceExpression
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a `super` expression.
* Qualified `super` is not supported at the moment.
*/
interface USuperExpression : UInstanceExpression {
override fun asLogString() = "USuperExpression"
override fun asRenderString() = "super"
override fun accept(visitor: UastVisitor) {
if (visitor.visitSuperExpression(this)) return
annotations.acceptList(visitor)
visitor.afterVisitSuperExpression(this)
}
}
@@ -1,35 +0,0 @@
/*
* 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.expressions.UInstanceExpression
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a `this` expression.
* Qualified `this` is not supported at the moment.
*/
interface UThisExpression : UInstanceExpression {
override fun asLogString() = "UThisExpression"
override fun asRenderString() = "this"
override fun accept(visitor: UastVisitor) {
if (visitor.visitThisExpression(this)) return
annotations.acceptList(visitor)
visitor.afterVisitThisExpression(this)
}
}
@@ -1,41 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a `throw` expression.
*/
interface UThrowExpression : UExpression {
/**
* Returns ths thrown expression.
*/
val thrownExpression: UExpression
override fun accept(visitor: UastVisitor) {
if (visitor.visitThrowExpression(this)) return
annotations.acceptList(visitor)
thrownExpression.accept(visitor)
visitor.afterVisitThrowExpression(this)
}
override fun asRenderString() = "throw " + thrownExpression.asRenderString()
override fun asLogString() = log("UThrowExpression", thrownExpression)
}
@@ -1,29 +0,0 @@
package org.jetbrains.uast.expressions
import com.intellij.psi.PsiType
import com.intellij.psi.util.PsiTypesUtil
import org.jetbrains.uast.UExpression
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.name
import org.jetbrains.uast.visitor.UastVisitor
interface UTypeReferenceExpression : UExpression {
/**
* Returns the resolved type for this reference.
*/
val type: PsiType
/**
* Returns the qualified name of the class type, or null if the [type] is not a class type.
*/
fun getQualifiedName() = PsiTypesUtil.getPsiClass(type)?.qualifiedName
override fun accept(visitor: UastVisitor) {
if (visitor.visitTypeReferenceExpression(this)) return
annotations.acceptList(visitor)
visitor.afterVisitTypeReferenceExpression(this)
}
override fun asLogString() = "UTypeReferenceExpression (${type.name})"
override fun asRenderString() = type.name
}
@@ -1,80 +0,0 @@
/*
* 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 com.intellij.psi.PsiMethod
import org.jetbrains.uast.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
interface UUnaryExpression : UExpression {
/**
* Returns the expression operand.
*/
val operand: UExpression
/**
* Returns the expression operator.
*/
val operator: UastOperator
/**
* Returns the operator identifier.
*/
val operatorIdentifier: UIdentifier?
/**
* Resolve the operator method.
*
* @return the resolved method, or null if the method can't be resolved, or if the expression is not a method call.
*/
fun resolveOperator(): PsiMethod?
override fun accept(visitor: UastVisitor) {
if (visitor.visitUnaryExpression(this)) return
annotations.acceptList(visitor)
operand.accept(visitor)
visitor.afterVisitUnaryExpression(this)
}
}
interface UPrefixExpression : UUnaryExpression {
override val operator: UastPrefixOperator
override fun accept(visitor: UastVisitor) {
if (visitor.visitPrefixExpression(this)) return
annotations.acceptList(visitor)
operand.accept(visitor)
visitor.afterVisitPrefixExpression(this)
}
override fun asLogString() = log("UPrefixExpression (${operator.text})", operand)
override fun asRenderString() = operator.text + operand.asRenderString()
}
interface UPostfixExpression : UUnaryExpression {
override val operator: UastPostfixOperator
override fun accept(visitor: UastVisitor) {
if (visitor.visitPostfixExpression(this)) return
annotations.acceptList(visitor)
operand.accept(visitor)
visitor.afterVisitPostfixExpression(this)
}
override fun asLogString() = log("UPostfixExpression (${operator.text})", operand)
override fun asRenderString() = operand.asRenderString() + operator.text
}
@@ -1,41 +0,0 @@
/*
* 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.internal.acceptList
import org.jetbrains.uast.internal.log
import org.jetbrains.uast.visitor.UastVisitor
/**
* Represents a list of declarations.
* Example in Java: `int a = 4, b = 3`.
*/
interface UVariableDeclarationsExpression : UExpression {
/**
* Returns the list of variables inside this [UVariableDeclarationsExpression].
*/
val variables: List<UVariable>
override fun accept(visitor: UastVisitor) {
if (visitor.visitDeclarationsExpression(this)) return
annotations.acceptList(visitor)
variables.acceptList(visitor)
visitor.afterVisitDeclarationsExpression(this)
}
override fun asRenderString() = variables.joinToString(LINE_SEPARATOR) { it.asRenderString() }
override fun asLogString() = log("UDeclarationsExpression", variables)
}
@@ -1,98 +0,0 @@
/*
* 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
/**
* Checks if the [UElement] is a null literal.
*
* @return true if the receiver is a null literal, false otherwise.
*/
fun UElement.isNullLiteral(): Boolean = this is ULiteralExpression && this.isNull
/**
* Checks if the [UElement] is a boolean literal.
*
* @return true if the receiver is a boolean literal, false otherwise.
*/
fun UElement.isBooleanLiteral(): Boolean = this is ULiteralExpression && this.isBoolean
/**
* Checks if the [UElement] is a `true` boolean literal.
*
* @return true if the receiver is a `true` boolean literal, false otherwise.
*/
fun UElement.isTrueLiteral(): Boolean = this is ULiteralExpression && this.isBoolean && this.value == true
/**
* Checks if the [UElement] is a `false` boolean literal.
*
* @return true if the receiver is a `false` boolean literal, false otherwise.
*/
fun UElement.isFalseLiteral(): Boolean = this is ULiteralExpression && this.isBoolean && this.value == false
/**
* Checks if the [UElement] is a [String] literal.
*
* @return true if the receiver is a [String] literal, false otherwise.
*/
fun UElement.isStringLiteral(): Boolean = this is ULiteralExpression && this.isString
/**
* Returns the [String] literal value.
*
* @return literal text if the receiver is a valid [String] literal, null otherwise.
*/
fun UElement.getValueIfStringLiteral(): String? =
if (isStringLiteral()) (this as ULiteralExpression).value as String else null
/**
* Checks if the [UElement] is a [Number] literal (Integer, Long, Float, Double, etc.).
*
* @return true if the receiver is a [Number] literal, false otherwise.
*/
fun UElement.isNumberLiteral(): Boolean = this is ULiteralExpression && this.value is Number
/**
* Checks if the [UElement] is an integral literal (is an [Integer], [Long], [Short], [Char] or [Byte]).
*
* @return true if the receiver is an integral literal, false otherwise.
*/
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
}
/**
* Returns the integral value of the literal.
*
* @return long representation of the literal expression value,
* 0 if the receiver literal expression is not a integral one.
*/
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
}
}
@@ -1,41 +0,0 @@
package org.jetbrains.uast.internal
import com.intellij.psi.PsiElement
import org.jetbrains.uast.LINE_SEPARATOR
import org.jetbrains.uast.UElement
import org.jetbrains.uast.asLogString
import org.jetbrains.uast.visitor.UastVisitor
import org.jetbrains.uast.withMargin
/**
* Builds the log message for the [UElement.asLogString] function.
*
* @param firstLine the message line (the interface name, some optional information).
* @param nested nested UElements. Could be `List<UElement>`, [UElement] or `null`.
* @throws IllegalStateException if the [nested] argument is invalid.
* @return the rendered log string.
*/
fun UElement.log(firstLine: String, vararg nested: Any?): String {
return (if (firstLine.isBlank()) "" else firstLine + LINE_SEPARATOR) + nested.joinToString(LINE_SEPARATOR) {
when (it) {
null -> "<no element>".withMargin
is List<*> -> {
if (it.firstOrNull() is PsiElement) {
@Suppress("UNCHECKED_CAST")
(it as List<PsiElement>).joinToString(LINE_SEPARATOR) { it.text }
} else {
@Suppress("UNCHECKED_CAST")
(it as List<UElement>).asLogString()
}
}
is UElement -> it.asLogString().withMargin
else -> error("Invalid element type: $it")
}
}
}
fun List<UElement>.acceptList(visitor: UastVisitor) {
for (element in this) {
element.accept(visitor)
}
}
@@ -1,46 +0,0 @@
/*
* 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 com.intellij.psi.PsiType
internal val ERROR_NAME = "<error>"
internal val LINE_SEPARATOR = System.getProperty("line.separator") ?: "\n"
val String.withMargin: String
get() = lines().joinToString(LINE_SEPARATOR) { " " + it }
internal operator fun String.times(n: Int) = this.repeat(n)
internal fun List<UElement>.asLogString() = joinToString(LINE_SEPARATOR) { it.asLogString().withMargin }
internal fun StringBuilder.appendWithSpace(s: String) {
if (s.isNotEmpty()) {
append(s)
append(' ')
}
}
internal tailrec fun UExpression.unwrapParenthesis(): UExpression = when (this) {
is UParenthesizedExpression -> expression.unwrapParenthesis()
else -> this
}
internal fun <T> lz(f: () -> T) = lazy(LazyThreadSafetyMode.NONE, f)
internal val PsiType.name: String
get() = getCanonicalText(false)
@@ -1,37 +0,0 @@
/*
* 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
/**
* Kinds of [UBinaryExpressionWithType].
* Examples: type casts, instance checks.
*/
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>")
}
}
@@ -1,135 +0,0 @@
/*
* 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 of operators in [UBinaryExpression].
*/
open class UastBinaryOperator(override val text: String): UastOperator {
class LogicalOperator(text: String): UastBinaryOperator(text)
class ComparisonOperator(text: String): UastBinaryOperator(text)
class ArithmeticOperator(text: String): UastBinaryOperator(text)
class BitwiseOperator(text: String): UastBinaryOperator(text)
class AssignOperator(text: String): UastBinaryOperator(text)
companion object {
@JvmField
val ASSIGN = AssignOperator("=")
@JvmField
val PLUS = ArithmeticOperator("+")
@JvmField
val MINUS = ArithmeticOperator("-")
@JvmField
val MULTIPLY = ArithmeticOperator("*")
@JvmField
val DIV = ArithmeticOperator("/")
@JvmField
val MOD = ArithmeticOperator("%")
@JvmField
val LOGICAL_OR = LogicalOperator("||")
@JvmField
val LOGICAL_AND = LogicalOperator("&&")
@JvmField
val BITWISE_OR = BitwiseOperator("|")
@JvmField
val BITWISE_AND = BitwiseOperator("&")
@JvmField
val BITWISE_XOR = BitwiseOperator("^")
@JvmField
val EQUALS = ComparisonOperator("==")
@JvmField
val NOT_EQUALS = ComparisonOperator("!=")
@JvmField
val IDENTITY_EQUALS = ComparisonOperator("===")
@JvmField
val IDENTITY_NOT_EQUALS = ComparisonOperator("!==")
@JvmField
val GREATER = ComparisonOperator(">")
@JvmField
val GREATER_OR_EQUAL = ComparisonOperator(">=")
@JvmField
val LESS = ComparisonOperator("<")
@JvmField
val LESS_OR_EQUAL = ComparisonOperator("<=")
@JvmField
val SHIFT_LEFT = BitwiseOperator("<<")
@JvmField
val SHIFT_RIGHT = BitwiseOperator(">>")
@JvmField
val UNSIGNED_SHIFT_RIGHT = BitwiseOperator(">>>")
@JvmField
val OTHER = UastBinaryOperator("<other>")
@JvmField
val PLUS_ASSIGN = AssignOperator("+=")
@JvmField
val MINUS_ASSIGN = AssignOperator("-=")
@JvmField
val MULTIPLY_ASSIGN = AssignOperator("*=")
@JvmField
val DIVIDE_ASSIGN = AssignOperator("/=")
@JvmField
val REMAINDER_ASSIGN = AssignOperator("%=")
@JvmField
val AND_ASSIGN = AssignOperator("&=")
@JvmField
val XOR_ASSIGN = AssignOperator("^=")
@JvmField
val OR_ASSIGN = AssignOperator("|=")
@JvmField
val SHIFT_LEFT_ASSIGN = AssignOperator("<<=")
@JvmField
val SHIFT_RIGHT_ASSIGN = AssignOperator(">>=")
@JvmField
val UNSIGNED_SHIFT_RIGHT_ASSIGN = AssignOperator(">>>=")
}
override fun toString(): String{
return "UastBinaryOperator(text='$text')"
}
}
@@ -1,47 +0,0 @@
/*
* 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 of [UCallExpression].
*/
open class UastCallKind(val name: String) {
companion object {
@JvmField
val METHOD_CALL = UastCallKind("method_call")
@JvmField
val CONSTRUCTOR_CALL = UastCallKind("constructor_call")
@JvmField
val NEW_ARRAY_WITH_DIMENSIONS = UastCallKind("new_array_with_dimensions")
/**
* Initializer parts are available in call expression as value arguments.
* [NEW_ARRAY_WITH_INITIALIZER] is a top-level initializer. In case of multi-dimensional arrays, inner initializers
* have type of [NESTED_ARRAY_INITIALIZER].
*/
@JvmField
val NEW_ARRAY_WITH_INITIALIZER = UastCallKind("new_array_with_initializer")
@JvmField
val NESTED_ARRAY_INITIALIZER = UastCallKind("array_initializer")
}
override fun toString(): String{
return "UastCallKind(name='$name')"
}
}
@@ -1,43 +0,0 @@
/*
* 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 of [UClass].
*/
open class UastClassKind(val text: String) {
companion object {
@JvmField
val CLASS = UastClassKind("class")
@JvmField
val INTERFACE = UastClassKind("interface")
@JvmField
val ANNOTATION = UastClassKind("annotation")
@JvmField
val ENUM = UastClassKind("enum")
@JvmField
val OBJECT = UastClassKind("object")
}
override fun toString(): String{
return "UastClassKind(text='$text')"
}
}
@@ -1,28 +0,0 @@
/*
* 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
/**
* Uast operator base interface.
*
* @see [UastPrefixOperator], [UastPostfixOperator], [UastBinaryOperator]
*/
interface UastOperator {
/**
* Returns the operator text to render in [UElement.asRenderString].
*/
val text: String
}
@@ -1,36 +0,0 @@
/*
* 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
/**
* [UPostfixExpression] operators.
*/
open class UastPostfixOperator(override val text: String): UastOperator {
companion object {
@JvmField
val INC = UastPostfixOperator("++")
@JvmField
val DEC = UastPostfixOperator("--")
@JvmField
val UNKNOWN = UastPostfixOperator("<unknown>")
}
override fun toString(): String{
return "UastPostfixOperator(text='$text')"
}
}
@@ -1,48 +0,0 @@
/*
* 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
/**
* [UPrefixExpression] operators.
*/
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>")
}
override fun toString(): String{
return "UastPrefixOperator(text='$text')"
}
}
@@ -1,31 +0,0 @@
/*
* 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
/**
* Access types of [UQualifiedReferenceExpression].
* Additional type examples: Kotlin safe call (?.).
*/
open class UastQualifiedExpressionAccessType(val name: String) {
companion object {
@JvmField
val SIMPLE = UastQualifiedExpressionAccessType(".")
}
override fun toString(): String{
return "UastQualifiedExpressionAccessType(name='$name')"
}
}
@@ -1,25 +0,0 @@
/*
* 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 of [UExpressionList].
*/
open class UastSpecialExpressionKind(val name: String) {
override fun toString(): String{
return "UastSpecialExpressionKind(name='$name')"
}
}
@@ -1,40 +0,0 @@
/*
* 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 com.intellij.psi.PsiLocalVariable
import com.intellij.psi.PsiModifier
import com.intellij.psi.PsiModifierListOwner
enum class UastVisibility(val text: String) {
PUBLIC("public"),
PRIVATE("private"),
PROTECTED("protected"),
PACKAGE_LOCAL("packageLocal"),
LOCAL("local");
override fun toString() = text
companion object {
operator fun get(declaration: PsiModifierListOwner): UastVisibility {
if (declaration.hasModifierProperty(PsiModifier.PUBLIC)) return UastVisibility.PUBLIC
if (declaration.hasModifierProperty(PsiModifier.PROTECTED)) return UastVisibility.PROTECTED
if (declaration.hasModifierProperty(PsiModifier.PRIVATE)) return UastVisibility.PRIVATE
if (declaration is PsiLocalVariable) return UastVisibility.LOCAL
return UastVisibility.PACKAGE_LOCAL
}
}
}
@@ -1,27 +0,0 @@
/*
* 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.
*/
@file:JvmName("UastPsiUtils")
package org.jetbrains.uast.psi
import com.intellij.psi.PsiElement
import org.jetbrains.uast.UElement
interface PsiElementBacked : UElement {
val psi: PsiElement?
override val isPsiValid: Boolean
get() = psi?.isValid ?: true
}
@@ -1,6 +0,0 @@
package org.jetbrains.uast.psi
import com.intellij.openapi.util.Segment
import org.jetbrains.uast.UElement
interface UElementWithLocation : UElement, Segment
@@ -1,11 +0,0 @@
package org.jetbrains.uast.psi
import com.intellij.lang.Language
import com.intellij.psi.PsiElement
import com.intellij.psi.impl.light.LightParameter
import org.jetbrains.uast.UastErrorType
class UastPsiParameterNotResolved(
declarationScope: PsiElement,
language: Language
) : LightParameter("error", UastErrorType, declarationScope, language)
@@ -1,160 +0,0 @@
@file:JvmMultifileClass
@file:JvmName("UastUtils")
package org.jetbrains.uast
/**
* Get the topmost parent qualified expression for the call expression.
*
* Example 1:
* Code: variable.call(args)
* Call element: E = call(args)
* Qualified parent (return value): Q = [getQualifiedCallElement](E) = variable.call(args)
*
* Example 2:
* Code: call(args)
* Call element: E = call(args)
* Qualified parent (return value): Q = [getQualifiedCallElement](E) = call(args) (no qualifier)
*
* @return containing qualified expression if the call is a child of the qualified expression, call element otherwise.
*/
fun UExpression.getQualifiedParentOrThis(): UExpression {
fun findParent(current: UExpression?, previous: UExpression): UExpression? = when (current) {
is UQualifiedReferenceExpression -> {
if (current.selector == previous)
findParent(current.containingElement as? UExpression, current) ?: current
else
previous
}
is UParenthesizedExpression -> findParent(current.expression, previous) ?: previous
else -> null
}
return findParent(containingElement as? UExpression, this) ?: this
}
fun UExpression.asQualifiedPath(): List<String>? {
if (this is USimpleNameReferenceExpression) {
return listOf(this.identifier)
} else if (this !is UQualifiedReferenceExpression) {
return null
}
var error = false
val list = mutableListOf<String>()
fun addIdentifiers(expr: UQualifiedReferenceExpression) {
val receiver = expr.receiver.unwrapParenthesis()
val selector = expr.selector as? USimpleNameReferenceExpression ?: run { error = true; return }
when (receiver) {
is UQualifiedReferenceExpression -> addIdentifiers(receiver)
is USimpleNameReferenceExpression -> list += receiver.identifier
else -> {
error = true
return
}
}
list += selector.identifier
}
addIdentifiers(this)
return if (error) null else list
}
/**
* Return the list of qualified expressions.
*
* Example:
* Code: obj.call(param).anotherCall(param2).getter
* Qualified chain: [obj, call(param), anotherCall(param2), getter]
*
* @return list of qualified expressions, or the empty list if the received expression is not a qualified expression.
*/
fun UExpression?.getQualifiedChain(): List<UExpression> {
fun collect(expr: UQualifiedReferenceExpression, chains: MutableList<UExpression>) {
val receiver = expr.receiver.unwrapParenthesis()
if (receiver is UQualifiedReferenceExpression) {
collect(receiver, chains)
} else {
chains += receiver
}
val selector = expr.selector.unwrapParenthesis()
if (selector is UQualifiedReferenceExpression) {
collect(selector, chains)
} else {
chains += selector
}
}
if (this == null) return emptyList()
val qualifiedExpression = this as? UQualifiedReferenceExpression ?: return listOf(this)
val chains = mutableListOf<UExpression>()
collect(qualifiedExpression, chains)
return chains
}
/**
* Return the outermost qualified expression.
*
* @return the outermost qualified expression,
* this element if the parent expression is not a qualified expression,
* or null if the element is not a qualified expression.
*
* Example:
* Code: a.b.c(asd).g
* Call element: c(asd)
* Outermost qualified (return value): a.b.c(asd).g
*/
fun UExpression.getOutermostQualified(): UQualifiedReferenceExpression? {
tailrec fun getOutermostQualified(current: UElement?, previous: UExpression): UQualifiedReferenceExpression? = when (current) {
is UQualifiedReferenceExpression -> getOutermostQualified(current.containingElement, current)
is UParenthesizedExpression -> getOutermostQualified(current.containingElement, previous)
else -> if (previous is UQualifiedReferenceExpression) previous else null
}
return getOutermostQualified(this.containingElement, this)
}
/**
* Checks if the received expression is a qualified chain of identifiers, and the trailing part of such chain is [fqName].
*
* @param fqName the chain part to check against. Sequence of identifiers, separated by dot ('.'). Example: "com.example".
* @return true, if the received expression is a qualified chain of identifiers, and the trailing part of such chain is [fqName].
*/
fun UExpression.matchesQualified(fqName: String): Boolean {
val identifiers = this.asQualifiedPath() ?: return false
val passedIdentifiers = fqName.trim('.').split('.')
return identifiers == passedIdentifiers
}
/**
* Checks if the received expression is a qualified chain of identifiers, and the leading part of such chain is [fqName].
*
* @param fqName the chain part to check against. Sequence of identifiers, separated by dot ('.'). Example: "com.example".
* @return true, if the received expression is a qualified chain of identifiers, and the leading part of such chain is [fqName].
*/
fun UExpression.startsWithQualified(fqName: String): Boolean {
val identifiers = this.asQualifiedPath() ?: return false
val passedIdentifiers = fqName.trim('.').split('.')
if (identifiers.size < passedIdentifiers.size) return false
passedIdentifiers.forEachIndexed { i, passedIdentifier ->
if (passedIdentifier != identifiers[i]) return false
}
return true
}
/**
* Checks if the received expression is a qualified chain of identifiers, and the trailing part of such chain is [fqName].
*
* @param fqName the chain part to check against. Sequence of identifiers, separated by dot ('.'). Example: "com.example".
* @return true, if the received expression is a qualified chain of identifiers, and the trailing part of such chain is [fqName].
*/
fun UExpression.endsWithQualified(fqName: String): Boolean {
val identifiers = this.asQualifiedPath()?.asReversed() ?: return false
val passedIdentifiers = fqName.trim('.').split('.').asReversed()
if (identifiers.size < passedIdentifiers.size) return false
passedIdentifiers.forEachIndexed { i, passedIdentifier ->
if (passedIdentifier != identifiers[i]) return false
}
return true
}
@@ -1,41 +0,0 @@
/*
* 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("UastExpressionUtils")
package org.jetbrains.uast.util
import org.jetbrains.uast.*
fun UElement.isConstructorCall() = (this as? UCallExpression)?.kind == UastCallKind.CONSTRUCTOR_CALL
fun UElement.isMethodCall() = (this as? UCallExpression)?.kind == UastCallKind.METHOD_CALL
fun UElement.isNewArray() = isNewArrayWithDimensions() || isNewArrayWithInitializer()
fun UElement.isNewArrayWithDimensions() = (this as? UCallExpression)?.kind == UastCallKind.NEW_ARRAY_WITH_DIMENSIONS
fun UElement.isNewArrayWithInitializer() = (this as? UCallExpression)?.kind == UastCallKind.NEW_ARRAY_WITH_INITIALIZER
@Deprecated("Use isArrayInitializer()", ReplaceWith("isArrayInitializer()"))
fun UElement.isNestedArrayInitializer() = isArrayInitializer()
fun UElement.isArrayInitializer() = (this as? UCallExpression)?.kind == UastCallKind.NESTED_ARRAY_INITIALIZER
fun UElement.isTypeCast() = (this as? UBinaryExpressionWithType)?.operationKind is UastBinaryExpressionWithTypeKind.TypeCast
fun UElement.isInstanceCheck() = (this as? UBinaryExpressionWithType)?.operationKind is UastBinaryExpressionWithTypeKind.InstanceCheck
fun UElement.isAssignment() = (this as? UBinaryExpression)?.operator is UastBinaryOperator.AssignOperator
@@ -1,175 +0,0 @@
/*
* 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.*
import org.jetbrains.uast.expressions.UTypeReferenceExpression
class DelegatingUastVisitor(private val visitors: List<UastVisitor>): UastVisitor {
override fun visitElement(node: UElement): Boolean {
return visitors.all { it.visitElement(node) }
}
override fun visitVariable(node: UVariable): Boolean {
return visitors.all { it.visitVariable(node) }
}
override fun visitMethod(node: UMethod): Boolean {
return visitors.all { it.visitMethod(node) }
}
override fun visitLabeledExpression(node: ULabeledExpression): Boolean {
return visitors.all { it.visitLabeledExpression(node) }
}
override fun visitDeclarationsExpression(node: UVariableDeclarationsExpression): Boolean {
return visitors.all { it.visitDeclarationsExpression(node) }
}
override fun visitBlockExpression(node: UBlockExpression): Boolean {
return visitors.all { it.visitBlockExpression(node) }
}
override fun visitQualifiedReferenceExpression(node: UQualifiedReferenceExpression): Boolean {
return visitors.all { it.visitQualifiedReferenceExpression(node) }
}
override fun visitSimpleNameReferenceExpression(node: USimpleNameReferenceExpression): Boolean {
return visitors.all { it.visitSimpleNameReferenceExpression(node) }
}
override fun visitTypeReferenceExpression(node: UTypeReferenceExpression): Boolean {
return visitors.all { it.visitTypeReferenceExpression(node) }
}
override fun visitCallExpression(node: UCallExpression): Boolean {
return visitors.all { it.visitCallExpression(node) }
}
override fun visitBinaryExpression(node: UBinaryExpression): Boolean {
return visitors.all { it.visitBinaryExpression(node) }
}
override fun visitBinaryExpressionWithType(node: UBinaryExpressionWithType): Boolean {
return visitors.all { it.visitBinaryExpressionWithType(node) }
}
override fun visitParenthesizedExpression(node: UParenthesizedExpression): Boolean {
return visitors.all { it.visitParenthesizedExpression(node) }
}
override fun visitUnaryExpression(node: UUnaryExpression): Boolean {
return visitors.all { it.visitUnaryExpression(node) }
}
override fun visitPrefixExpression(node: UPrefixExpression): Boolean {
return visitors.all { it.visitPrefixExpression(node) }
}
override fun visitPostfixExpression(node: UPostfixExpression): Boolean {
return visitors.all { it.visitPostfixExpression(node) }
}
override fun visitExpressionList(node: UExpressionList): Boolean {
return visitors.all { it.visitExpressionList(node) }
}
override fun visitIfExpression(node: UIfExpression): Boolean {
return visitors.all { it.visitIfExpression(node) }
}
override fun visitSwitchExpression(node: USwitchExpression): Boolean {
return visitors.all { it.visitSwitchExpression(node) }
}
override fun visitSwitchClauseExpression(node: USwitchClauseExpression): Boolean {
return visitors.all { it.visitSwitchClauseExpression(node) }
}
override fun visitWhileExpression(node: UWhileExpression): Boolean {
return visitors.all { it.visitWhileExpression(node) }
}
override fun visitDoWhileExpression(node: UDoWhileExpression): Boolean {
return visitors.all { it.visitDoWhileExpression(node) }
}
override fun visitForExpression(node: UForExpression): Boolean {
return visitors.all { it.visitForExpression(node) }
}
override fun visitForEachExpression(node: UForEachExpression): Boolean {
return visitors.all { it.visitForEachExpression(node) }
}
override fun visitTryExpression(node: UTryExpression): Boolean {
return visitors.all { it.visitTryExpression(node) }
}
override fun visitCatchClause(node: UCatchClause): Boolean {
return visitors.all { it.visitCatchClause(node) }
}
override fun visitLiteralExpression(node: ULiteralExpression): Boolean {
return visitors.all { it.visitLiteralExpression(node) }
}
override fun visitThisExpression(node: UThisExpression): Boolean {
return visitors.all { it.visitThisExpression(node) }
}
override fun visitSuperExpression(node: USuperExpression): Boolean {
return visitors.all { it.visitSuperExpression(node) }
}
override fun visitReturnExpression(node: UReturnExpression): Boolean {
return visitors.all { it.visitReturnExpression(node) }
}
override fun visitBreakExpression(node: UBreakExpression): Boolean {
return visitors.all { it.visitBreakExpression(node) }
}
override fun visitContinueExpression(node: UContinueExpression): Boolean {
return visitors.all { it.visitContinueExpression(node) }
}
override fun visitThrowExpression(node: UThrowExpression): Boolean {
return visitors.all { it.visitThrowExpression(node) }
}
override fun visitArrayAccessExpression(node: UArrayAccessExpression): Boolean {
return visitors.all { it.visitArrayAccessExpression(node) }
}
override fun visitCallableReferenceExpression(node: UCallableReferenceExpression): Boolean {
return visitors.all { it.visitCallableReferenceExpression(node) }
}
override fun visitClassLiteralExpression(node: UClassLiteralExpression): Boolean {
return visitors.all { it.visitClassLiteralExpression(node) }
}
override fun visitLambdaExpression(node: ULambdaExpression): Boolean {
return visitors.all { it.visitLambdaExpression(node) }
}
override fun visitObjectLiteralExpression(node: UObjectLiteralExpression): Boolean {
return visitors.all { it.visitObjectLiteralExpression(node) }
}
}
@@ -1,124 +0,0 @@
/*
* 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.*
import org.jetbrains.uast.expressions.UTypeReferenceExpression
interface UastVisitor {
fun visitElement(node: UElement): Boolean
fun visitFile(node: UFile): Boolean = visitElement(node)
fun visitImportStatement(node: UImportStatement): Boolean = visitElement(node)
fun visitClass(node: UClass): Boolean = visitElement(node)
fun visitInitializer(node: UClassInitializer): Boolean = visitElement(node)
fun visitMethod(node: UMethod): Boolean = visitElement(node)
fun visitVariable(node: UVariable): Boolean = visitElement(node)
fun visitAnnotation(node: UAnnotation): Boolean = visitElement(node)
// Expressions
fun visitLabeledExpression(node: ULabeledExpression) = visitElement(node)
fun visitDeclarationsExpression(node: UVariableDeclarationsExpression) = visitElement(node)
fun visitBlockExpression(node: UBlockExpression) = visitElement(node)
fun visitQualifiedReferenceExpression(node: UQualifiedReferenceExpression) = visitElement(node)
fun visitSimpleNameReferenceExpression(node: USimpleNameReferenceExpression) = visitElement(node)
fun visitTypeReferenceExpression(node: UTypeReferenceExpression) = visitElement(node)
fun visitCallExpression(node: UCallExpression) = visitElement(node)
fun visitBinaryExpression(node: UBinaryExpression) = visitElement(node)
fun visitBinaryExpressionWithType(node: UBinaryExpressionWithType) = visitElement(node)
fun visitParenthesizedExpression(node: UParenthesizedExpression) = visitElement(node)
fun visitUnaryExpression(node: UUnaryExpression) = visitElement(node)
fun visitPrefixExpression(node: UPrefixExpression) = visitElement(node)
fun visitPostfixExpression(node: UPostfixExpression) = visitElement(node)
fun visitExpressionList(node: UExpressionList) = visitElement(node)
fun visitIfExpression(node: UIfExpression) = visitElement(node)
fun visitSwitchExpression(node: USwitchExpression) = visitElement(node)
fun visitSwitchClauseExpression(node: USwitchClauseExpression) = visitElement(node)
fun visitWhileExpression(node: UWhileExpression) = visitElement(node)
fun visitDoWhileExpression(node: UDoWhileExpression) = visitElement(node)
fun visitForExpression(node: UForExpression) = visitElement(node)
fun visitForEachExpression(node: UForEachExpression) = visitElement(node)
fun visitTryExpression(node: UTryExpression) = visitElement(node)
fun visitCatchClause(node: UCatchClause) = visitElement(node)
fun visitLiteralExpression(node: ULiteralExpression) = visitElement(node)
fun visitThisExpression(node: UThisExpression) = visitElement(node)
fun visitSuperExpression(node: USuperExpression) = visitElement(node)
fun visitReturnExpression(node: UReturnExpression) = visitElement(node)
fun visitBreakExpression(node: UBreakExpression) = visitElement(node)
fun visitContinueExpression(node: UContinueExpression) = visitElement(node)
fun visitThrowExpression(node: UThrowExpression) = visitElement(node)
fun visitArrayAccessExpression(node: UArrayAccessExpression) = visitElement(node)
fun visitCallableReferenceExpression(node: UCallableReferenceExpression) = visitElement(node)
fun visitClassLiteralExpression(node: UClassLiteralExpression) = visitElement(node)
fun visitLambdaExpression(node: ULambdaExpression) = visitElement(node)
fun visitObjectLiteralExpression(node: UObjectLiteralExpression) = visitElement(node)
// After
fun afterVisitElement(node: UElement) {}
fun afterVisitFile(node: UFile) { afterVisitElement(node) }
fun afterVisitImportStatement(node: UImportStatement) { afterVisitElement(node) }
fun afterVisitClass(node: UClass) { afterVisitElement(node) }
fun afterVisitInitializer(node: UClassInitializer) { afterVisitElement(node) }
fun afterVisitMethod(node: UMethod) { afterVisitElement(node) }
fun afterVisitVariable(node: UVariable) { afterVisitElement(node) }
fun afterVisitAnnotation(node: UAnnotation) { afterVisitElement(node) }
// Expressions
fun afterVisitLabeledExpression(node: ULabeledExpression) { afterVisitElement(node) }
fun afterVisitDeclarationsExpression(node: UVariableDeclarationsExpression) { afterVisitElement(node) }
fun afterVisitBlockExpression(node: UBlockExpression) { afterVisitElement(node) }
fun afterVisitQualifiedReferenceExpression(node: UQualifiedReferenceExpression) { afterVisitElement(node) }
fun afterVisitSimpleNameReferenceExpression(node: USimpleNameReferenceExpression) { afterVisitElement(node) }
fun afterVisitTypeReferenceExpression(node: UTypeReferenceExpression) { afterVisitElement(node) }
fun afterVisitCallExpression(node: UCallExpression) { afterVisitElement(node) }
fun afterVisitBinaryExpression(node: UBinaryExpression) { afterVisitElement(node) }
fun afterVisitBinaryExpressionWithType(node: UBinaryExpressionWithType) { afterVisitElement(node) }
fun afterVisitParenthesizedExpression(node: UParenthesizedExpression) { afterVisitElement(node) }
fun afterVisitUnaryExpression(node: UUnaryExpression) { afterVisitElement(node) }
fun afterVisitPrefixExpression(node: UPrefixExpression) { afterVisitElement(node) }
fun afterVisitPostfixExpression(node: UPostfixExpression) { afterVisitElement(node) }
fun afterVisitExpressionList(node: UExpressionList) { afterVisitElement(node) }
fun afterVisitIfExpression(node: UIfExpression) { afterVisitElement(node) }
fun afterVisitSwitchExpression(node: USwitchExpression) { afterVisitElement(node) }
fun afterVisitSwitchClauseExpression(node: USwitchClauseExpression) { afterVisitElement(node) }
fun afterVisitWhileExpression(node: UWhileExpression) { afterVisitElement(node) }
fun afterVisitDoWhileExpression(node: UDoWhileExpression) { afterVisitElement(node) }
fun afterVisitForExpression(node: UForExpression) { afterVisitElement(node) }
fun afterVisitForEachExpression(node: UForEachExpression) { afterVisitElement(node) }
fun afterVisitTryExpression(node: UTryExpression) { afterVisitElement(node) }
fun afterVisitCatchClause(node: UCatchClause) { afterVisitElement(node) }
fun afterVisitLiteralExpression(node: ULiteralExpression) { afterVisitElement(node) }
fun afterVisitThisExpression(node: UThisExpression) { afterVisitElement(node) }
fun afterVisitSuperExpression(node: USuperExpression) { afterVisitElement(node) }
fun afterVisitReturnExpression(node: UReturnExpression) { afterVisitElement(node) }
fun afterVisitBreakExpression(node: UBreakExpression) { afterVisitElement(node) }
fun afterVisitContinueExpression(node: UContinueExpression) { afterVisitElement(node) }
fun afterVisitThrowExpression(node: UThrowExpression) { afterVisitElement(node) }
fun afterVisitArrayAccessExpression(node: UArrayAccessExpression) { afterVisitElement(node) }
fun afterVisitCallableReferenceExpression(node: UCallableReferenceExpression) { afterVisitElement(node) }
fun afterVisitClassLiteralExpression(node: UClassLiteralExpression) { afterVisitElement(node) }
fun afterVisitLambdaExpression(node: ULambdaExpression) { afterVisitElement(node) }
fun afterVisitObjectLiteralExpression(node: UObjectLiteralExpression) { afterVisitElement(node) }
}
abstract class AbstractUastVisitor : UastVisitor {
override fun visitElement(node: UElement): Boolean = false
}
object EmptyUastVisitor : AbstractUastVisitor()
-13
View File
@@ -1,13 +0,0 @@
<?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" />
<orderEntry type="library" exported="" name="intellij-core" level="project" />
</component>
</module>
@@ -1,64 +0,0 @@
/*
* 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.java
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiExpression
import com.intellij.psi.PsiType
import org.jetbrains.uast.UAnnotation
import org.jetbrains.uast.UExpression
import org.jetbrains.uast.java.internal.JavaUElementWithComments
import org.jetbrains.uast.psi.PsiElementBacked
abstract class JavaAbstractUElement : JavaUElementWithComments {
private val psiElement: PsiElement?
get() = (this as? PsiElementBacked)?.psi
override fun equals(other: Any?): Boolean {
if (this !is PsiElementBacked || other !is PsiElementBacked) {
return this === other
}
if (other.javaClass != this.javaClass) return false
return this.psi == other.psi
}
override fun asSourceString(): String {
if (this is PsiElementBacked) {
return this.psi?.text ?: super<JavaUElementWithComments>.asSourceString()
}
return super<JavaUElementWithComments>.asSourceString()
}
override fun toString() = asRenderString()
}
abstract class JavaAbstractUExpression : JavaAbstractUElement(), UExpression {
override fun evaluate(): Any? {
val psi = (this as? PsiElementBacked)?.psi ?: return null
return JavaPsiFacade.getInstance(psi.project).constantEvaluationHelper.computeConstantExpression(psi)
}
override val annotations: List<UAnnotation>
get() = emptyList()
override fun getExpressionType(): PsiType? {
val expression = (this as? PsiElementBacked)?.psi as? PsiExpression ?: return null
return expression.type
}
}
@@ -1,289 +0,0 @@
/*
* 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.java
import com.intellij.lang.Language
import com.intellij.lang.java.JavaLanguage
import com.intellij.openapi.project.Project
import com.intellij.psi.*
import org.jetbrains.uast.*
import org.jetbrains.uast.java.expressions.JavaUSynchronizedExpression
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUastLanguagePlugin(override val project: Project) : UastLanguagePlugin {
override val priority = 0
override fun isFileSupported(fileName: String) = fileName.endsWith(".java", ignoreCase = true)
override val language: Language
get() = JavaLanguage.INSTANCE
override fun isExpressionValueUsed(element: UExpression): Boolean = when (element) {
is JavaUVariableDeclarationsExpression -> false
is UnknownJavaExpression -> (element.containingElement as? UExpression)?.let { isExpressionValueUsed(it) } ?: false
else -> {
val statement = (element as? PsiElementBacked)?.psi as? PsiStatement
statement != null && statement.parent !is PsiExpressionStatement
}
}
override fun getMethodCallExpression(
element: PsiElement,
containingClassFqName: String?,
methodName: String
): UastLanguagePlugin.ResolvedMethod? {
if (element !is PsiMethodCallExpression) return null
if (element.methodExpression.referenceName != methodName) return null
val uElement = convertElementWithParent(element, null)
val callExpression = when (uElement) {
is UCallExpression -> uElement
is UQualifiedReferenceExpression -> uElement.selector as UCallExpression
else -> error("Invalid element type: $uElement")
}
val method = callExpression.resolve() ?: return null
if (containingClassFqName != null) {
val containingClass = method.containingClass ?: return null
if (containingClass.qualifiedName != containingClassFqName) return null
}
return UastLanguagePlugin.ResolvedMethod(callExpression, method)
}
override fun getConstructorCallExpression(
element: PsiElement,
fqName: String
): UastLanguagePlugin.ResolvedConstructor? {
if (element !is PsiNewExpression) return null
val simpleName = fqName.substringAfterLast('.')
if (element.classReference?.referenceName != simpleName) return null
val callExpression = convertElementWithParent(element, null) as? UCallExpression ?: return null
val constructorMethod = element.resolveConstructor() ?: return null
val containingClass = constructorMethod.containingClass ?: return null
if (containingClass.qualifiedName != fqName) return null
return UastLanguagePlugin.ResolvedConstructor(callExpression, constructorMethod, containingClass)
}
override fun convertElement(element: PsiElement, parent: UElement?, requiredType: Class<out UElement>?): UElement? {
if (element !is PsiElement) return null
return convertDeclaration(element, parent, requiredType) ?: JavaConverter.convertPsiElement(element, parent, requiredType)
}
override fun convertElementWithParent(element: PsiElement, requiredType: Class<out UElement>?): UElement? {
if (element !is PsiElement) return null
if (element is PsiJavaFile) return JavaUFile(element, this)
JavaConverter.getCached<UElement>(element)?.let { return it }
val parent = JavaConverter.unwrapElements(element.parent) ?: return null
val parentUElement = convertElementWithParent(parent, null) ?: return null
return convertElement(element, parentUElement, requiredType)
}
private fun convertDeclaration(element: PsiElement, parent: UElement?, requiredType: Class<out UElement>?): UElement? {
if (element.isValid) element.getUserData(JAVA_CACHED_UELEMENT_KEY)?.let { ref ->
ref.get()?.let { return it }
}
return with (requiredType) { when (element) {
is PsiJavaFile -> el<UFile> { JavaUFile(element, this@JavaUastLanguagePlugin) }
is UDeclaration -> element
is PsiClass -> el<UClass> { JavaUClass.create(element, parent) }
is PsiMethod -> el<UMethod> { JavaUMethod.create(element, this@JavaUastLanguagePlugin, parent) }
is PsiClassInitializer -> el<UClassInitializer> { JavaUClassInitializer(element, parent) }
is PsiVariable -> el<UVariable> { JavaUVariable.create(element, parent) }
is PsiAnnotation -> el<UAnnotation> { JavaUAnnotation(element, parent) } //???
else -> null
}}
}
}
internal inline fun <reified T : UElement> Class<out UElement>?.el(f: () -> UElement?): UElement? {
return if (this == null || T::class.java == this) f() else null
}
internal inline fun <reified T : UElement> Class<out UElement>?.expr(f: () -> UExpression): UExpression {
return if (this == null || T::class.java == this) f() else UastEmptyExpression
}
internal object JavaConverter {
internal inline fun <reified T : UElement> getCached(element: PsiElement): T? {
return null
//todo
}
internal tailrec fun unwrapElements(element: PsiElement?): PsiElement? = when (element) {
is PsiExpressionStatement -> unwrapElements(element.parent)
is PsiParameterList -> unwrapElements(element.parent)
is PsiAnnotationParameterList -> unwrapElements(element.parent)
else -> element
}
internal fun convertPsiElement(el: PsiElement, parent: UElement?, requiredType: Class<out UElement>? = null): UElement? {
getCached<UElement>(el)?.let { return it }
return with (requiredType) { when (el) {
is PsiCodeBlock -> el<UBlockExpression> { convertBlock(el, parent) }
is PsiResourceExpression -> convertExpression(el.expression, parent, requiredType)
is PsiExpression -> convertExpression(el, parent, requiredType)
is PsiStatement -> convertStatement(el, parent, requiredType)
is PsiIdentifier -> el<USimpleNameReferenceExpression> { JavaUSimpleNameReferenceExpression(el, el.text, parent) }
is PsiNameValuePair -> el<UNamedExpression> { convertNameValue(el, parent) }
is PsiArrayInitializerMemberValue -> el<UCallExpression> { JavaAnnotationArrayInitializerUCallExpression(el, parent) }
else -> null
}}
}
internal fun convertBlock(block: PsiCodeBlock, parent: UElement?): UBlockExpression =
getCached(block) ?: JavaUCodeBlockExpression(block, parent)
internal fun convertNameValue(pair: PsiNameValuePair, parent: UElement?): UNamedExpression {
return UNamedExpression.create(pair.name.orAnonymous(), parent) {
val value = pair.value as? PsiElement
value?.let { convertPsiElement(it, this, null) as? UExpression } ?: UnknownJavaExpression(value ?: pair, this)
}
}
internal fun convertReference(expression: PsiReferenceExpression, parent: UElement?, requiredType: Class<out UElement>?): UExpression {
return with (requiredType) {
if (expression.isQualified) {
expr<UQualifiedReferenceExpression> { JavaUQualifiedReferenceExpression(expression, parent) }
} else {
val name = expression.referenceName ?: "<error name>"
expr<USimpleNameReferenceExpression> { JavaUSimpleNameReferenceExpression(expression, name, parent, expression) }
}
}
}
private fun convertPolyadicExpression(
expression: PsiPolyadicExpression,
parent: UElement?,
i: Int
): UBinaryExpression {
return if (i == 1) JavaSeparatedPolyadicUBinaryExpression(expression, parent).apply {
leftOperand = convertExpression(expression.operands[0], this)
rightOperand = convertExpression(expression.operands[1], this)
} else JavaSeparatedPolyadicUBinaryExpression(expression, parent).apply {
leftOperand = convertPolyadicExpression(expression, parent, i - 1)
rightOperand = convertExpression(expression.operands[i], this)
}
}
internal fun convertExpression(el: PsiExpression, parent: UElement?, requiredType: Class<out UElement>? = null): UExpression {
getCached<UExpression>(el)?.let { return it }
return with (requiredType) { when (el) {
is PsiPolyadicExpression -> expr<UBinaryExpression> { convertPolyadicExpression(el, parent, el.operands.size - 1) }
is PsiAssignmentExpression -> expr<UBinaryExpression> { JavaUAssignmentExpression(el, parent) }
is PsiConditionalExpression -> expr<UIfExpression> { JavaUTernaryIfExpression(el, parent) }
is PsiNewExpression -> {
if (el.anonymousClass != null)
expr<UObjectLiteralExpression> { JavaUObjectLiteralExpression(el, parent) }
else
expr<UCallExpression> { JavaConstructorUCallExpression(el, parent) }
}
is PsiMethodCallExpression -> {
if (el.methodExpression.qualifierExpression != null)
expr<UQualifiedReferenceExpression> {
JavaUCompositeQualifiedExpression(el, parent).apply {
receiver = convertExpression(el.methodExpression.qualifierExpression!!, this)
selector = JavaUCallExpression(el, this)
}
}
else
expr<UCallExpression> { JavaUCallExpression(el, parent) }
}
is PsiArrayInitializerExpression -> expr<UCallExpression> { JavaArrayInitializerUCallExpression(el, parent) }
is PsiBinaryExpression -> expr<UBinaryExpression> { JavaUBinaryExpression(el, parent) }
is PsiParenthesizedExpression -> expr<UParenthesizedExpression> { JavaUParenthesizedExpression(el, parent) }
is PsiPrefixExpression -> expr<UPrefixExpression> { JavaUPrefixExpression(el, parent) }
is PsiPostfixExpression -> expr<UPostfixExpression> { JavaUPostfixExpression(el, parent) }
is PsiLiteralExpression -> expr<ULiteralExpression> { JavaULiteralExpression(el, parent) }
is PsiReferenceExpression -> convertReference(el, parent, requiredType)
is PsiThisExpression -> expr<UThisExpression> { JavaUThisExpression(el, parent) }
is PsiSuperExpression -> expr<USuperExpression> { JavaUSuperExpression(el, parent) }
is PsiInstanceOfExpression -> expr<UBinaryExpressionWithType> { JavaUInstanceCheckExpression(el, parent) }
is PsiTypeCastExpression -> expr<UBinaryExpressionWithType> { JavaUTypeCastExpression(el, parent) }
is PsiClassObjectAccessExpression -> expr<UClassLiteralExpression> { JavaUClassLiteralExpression(el, parent) }
is PsiArrayAccessExpression -> expr<UArrayAccessExpression> { JavaUArrayAccessExpression(el, parent) }
is PsiLambdaExpression -> expr<ULambdaExpression> { JavaULambdaExpression(el, parent) }
is PsiMethodReferenceExpression -> expr<UCallableReferenceExpression> { JavaUCallableReferenceExpression(el, parent) }
else -> UnknownJavaExpression(el, parent)
}}
}
internal fun convertStatement(el: PsiStatement, parent: UElement?, requiredType: Class<out UElement>? = null): UExpression {
getCached<UExpression>(el)?.let { return it }
return with (requiredType) { when (el) {
is PsiDeclarationStatement -> expr<UVariableDeclarationsExpression> { convertDeclarations(el.declaredElements, parent!!) }
is PsiExpressionListStatement -> expr<UVariableDeclarationsExpression> { convertDeclarations(el.expressionList.expressions, parent!!) }
is PsiBlockStatement -> expr<UBlockExpression> { JavaUBlockExpression(el, parent) }
is PsiLabeledStatement -> expr<ULabeledExpression> { JavaULabeledExpression(el, parent) }
is PsiExpressionStatement -> convertExpression(el.expression, parent, requiredType)
is PsiIfStatement -> expr<UIfExpression> { JavaUIfExpression(el, parent) }
is PsiSwitchStatement -> expr<USwitchExpression> { JavaUSwitchExpression(el, parent) }
is PsiSwitchLabelStatement -> expr<USwitchClauseExpression> {
if (el.isDefaultCase)
DefaultUSwitchClauseExpression(parent)
else JavaUCaseSwitchClauseExpression(el, parent)
}
is PsiWhileStatement -> expr<UWhileExpression> { JavaUWhileExpression(el, parent) }
is PsiDoWhileStatement -> expr<UDoWhileExpression> { JavaUDoWhileExpression(el, parent) }
is PsiForStatement -> expr<UForExpression> { JavaUForExpression(el, parent) }
is PsiForeachStatement -> expr<UForEachExpression> { JavaUForEachExpression(el, parent) }
is PsiBreakStatement -> expr<UBreakExpression> { JavaUBreakExpression(el, parent) }
is PsiContinueStatement -> expr<UContinueExpression> { JavaUContinueExpression(el, parent) }
is PsiReturnStatement -> expr<UReturnExpression> { JavaUReturnExpression(el, parent) }
is PsiAssertStatement -> expr<UCallExpression> { JavaUAssertExpression(el, parent) }
is PsiThrowStatement -> expr<UThrowExpression> { JavaUThrowExpression(el, parent) }
is PsiSynchronizedStatement -> expr<UBlockExpression> { JavaUSynchronizedExpression(el, parent) }
is PsiTryStatement -> expr<UTryExpression> { JavaUTryExpression(el, parent) }
else -> UnknownJavaExpression(el, parent)
}}
}
private fun convertDeclarations(elements: Array<out PsiElement>, parent: UElement): UVariableDeclarationsExpression {
return JavaUVariableDeclarationsExpression(parent).apply {
val variables = mutableListOf<UVariable>()
for (element in elements) {
if (element !is PsiVariable) continue
variables += JavaUVariable.create(element, this)
}
this.variables = variables
}
}
internal fun convertOrEmpty(statement: PsiStatement?, parent: UElement?): UExpression {
return statement?.let { convertStatement(it, parent, null) } ?: UastEmptyExpression
}
internal fun convertOrEmpty(expression: PsiExpression?, parent: UElement?): UExpression {
return expression?.let { convertExpression(it, parent) } ?: UastEmptyExpression
}
internal fun convertOrNull(expression: PsiExpression?, parent: UElement?): UExpression? {
return if (expression != null) convertExpression(expression, parent) else null
}
internal fun convertOrEmpty(block: PsiCodeBlock?, parent: UElement?): UExpression {
return if (block != null) convertBlock(block, parent) else UastEmptyExpression
}
}
@@ -1,36 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiDoWhileStatement
import com.intellij.psi.impl.source.tree.ChildRole
import org.jetbrains.uast.UDoWhileExpression
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUDoWhileExpression(
override val psi: PsiDoWhileStatement,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UDoWhileExpression, PsiElementBacked {
override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) }
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
override val doIdentifier: UIdentifier
get() = UIdentifier(psi.getChildByRole(ChildRole.DO_KEYWORD), this)
override val whileIdentifier: UIdentifier
get() = UIdentifier(psi.getChildByRole(ChildRole.WHILE_KEYWORD), this)
}
@@ -1,38 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiForeachStatement
import com.intellij.psi.impl.source.tree.ChildRole
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UForEachExpression
import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.UParameter
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUForEachExpression(
override val psi: PsiForeachStatement,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UForEachExpression, PsiElementBacked {
override val variable: UParameter
get() = JavaUParameter(psi.iterationParameter, this)
override val iteratedValue by lz { JavaConverter.convertOrEmpty(psi.iteratedValue, this) }
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
override val forIdentifier: UIdentifier
get() = UIdentifier(psi.getChildByRole(ChildRole.FOR_KEYWORD), this)
}
@@ -1,36 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiForStatement
import com.intellij.psi.impl.source.tree.ChildRole
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UForExpression
import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUForExpression(
override val psi: PsiForStatement,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UForExpression, PsiElementBacked {
override val declaration by lz { psi.initialization?.let { JavaConverter.convertStatement(it, this) } }
override val condition by lz { psi.condition?.let { JavaConverter.convertExpression(it, this) } }
override val update by lz { psi.update?.let { JavaConverter.convertStatement(it, this) } }
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
override val forIdentifier: UIdentifier
get() = UIdentifier(psi.getChildByRole(ChildRole.FOR_KEYWORD), this)
}
@@ -1,41 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiIfStatement
import com.intellij.psi.impl.source.tree.ChildRole
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.UIfExpression
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUIfExpression(
override val psi: PsiIfStatement,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UIfExpression, PsiElementBacked {
override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) }
override val thenExpression by lz { JavaConverter.convertOrEmpty(psi.thenBranch, this) }
override val elseExpression by lz { JavaConverter.convertOrEmpty(psi.elseBranch, this) }
override val isTernary: Boolean
get() = false
override val ifIdentifier: UIdentifier
get() = UIdentifier(psi.getChildByRole(ChildRole.IF_KEYWORD), this)
override val elseIdentifier: UIdentifier?
get() = psi.getChildByRole(ChildRole.ELSE_KEYWORD)?.let { UIdentifier(it, this) }
}
@@ -1,54 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiSwitchLabelStatement
import com.intellij.psi.PsiSwitchStatement
import com.intellij.psi.impl.source.tree.ChildRole
import org.jetbrains.uast.*
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUSwitchExpression(
override val psi: PsiSwitchStatement,
override val containingElement: UElement?
) : JavaAbstractUExpression(), USwitchExpression, PsiElementBacked {
override val expression by lz { JavaConverter.convertOrEmpty(psi.expression, this) }
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
override val switchIdentifier: UIdentifier
get() = UIdentifier(psi.getChildByRole(ChildRole.SWITCH_KEYWORD), this)
}
class JavaUCaseSwitchClauseExpression(
override val psi: PsiSwitchLabelStatement,
override val containingElement: UElement?
) : JavaAbstractUExpression(), USwitchClauseExpression, PsiElementBacked {
override val caseValues by lz {
val value = psi.caseValue ?: return@lz null
listOf(JavaConverter.convertExpression(value, this))
}
}
class DefaultUSwitchClauseExpression(override val containingElement: UElement?) : USwitchClauseExpression {
override val caseValues: List<UExpression>?
get() = null
override val annotations: List<UAnnotation>
get() = emptyList()
override fun asLogString() = "DefaultUSwitchClauseExpression"
override fun asRenderString() = "else -> "
}
@@ -1,40 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiConditionalExpression
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.UIfExpression
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUTernaryIfExpression(
override val psi: PsiConditionalExpression,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UIfExpression, PsiElementBacked {
override val condition by lz { JavaConverter.convertExpression(psi.condition, this) }
override val thenExpression by lz { JavaConverter.convertOrEmpty(psi.thenExpression, this) }
override val elseExpression by lz { JavaConverter.convertOrEmpty(psi.elseExpression, this) }
override val isTernary: Boolean
get() = true
override val ifIdentifier: UIdentifier
get() = UIdentifier(null, this)
override val elseIdentifier: UIdentifier?
get() = UIdentifier(null, this)
}
@@ -1,64 +0,0 @@
/*
* 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.java
import com.intellij.psi.*
import com.intellij.psi.impl.source.tree.ChildRole
import org.jetbrains.uast.UCatchClause
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.UTryExpression
import org.jetbrains.uast.expressions.UTypeReferenceExpression
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUTryExpression(
override val psi: PsiTryStatement,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UTryExpression, PsiElementBacked {
override val tryClause by lz { JavaConverter.convertOrEmpty(psi.tryBlock, this) }
override val catchClauses by lz { psi.catchSections.map { JavaUCatchClause(it, this) } }
override val finallyClause by lz { psi.finallyBlock?.let { JavaConverter.convertBlock(it, this) } }
override val resources: List<PsiResourceListElement>?
get() = psi.resourceList?.toList() ?: emptyList<PsiResourceListElement>()
override val isResources: Boolean
get() = psi.resourceList != null
override val tryIdentifier: UIdentifier
get() = UIdentifier(psi.getChildByRole(ChildRole.TRY_KEYWORD), this)
override val finallyIdentifier: UIdentifier?
get() = psi.getChildByRole(ChildRole.FINALLY_KEYWORD)?.let { UIdentifier(it, this) }
}
class JavaUCatchClause(
override val psi: PsiCatchSection,
override val containingElement: UElement?
) : JavaAbstractUElement(), UCatchClause, PsiElementBacked {
override val body by lz { JavaConverter.convertOrEmpty(psi.catchBlock, this) }
override val parameters by lz {
(psi.parameter?.let { listOf(it) } ?: emptyList()).map { JavaUParameter(it, this) }
}
override val typeReferences by lz {
val typeElement = psi.parameter?.typeElement ?: return@lz emptyList<UTypeReferenceExpression>()
if (typeElement.type is PsiDisjunctionType) {
typeElement.children.filterIsInstance<PsiTypeElement>().map { JavaUTypeReferenceExpression(it, this) }
} else {
listOf(JavaUTypeReferenceExpression(typeElement, this))
}
}
}
@@ -1,34 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiWhileStatement
import com.intellij.psi.impl.source.tree.ChildRole
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.UWhileExpression
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUWhileExpression(
override val psi: PsiWhileStatement,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UWhileExpression, PsiElementBacked {
override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) }
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
override val whileIdentifier: UIdentifier
get() = UIdentifier(psi.getChildByRole(ChildRole.WHILE_KEYWORD), this)
}
@@ -1,52 +0,0 @@
package org.jetbrains.uast.java
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiClass
import org.jetbrains.uast.*
class JavaUAnnotation(
override val psi: PsiAnnotation,
override val containingElement: UElement?
) : UAnnotation {
override val qualifiedName: String?
get() = psi.qualifiedName
override val attributeValues: List<UNamedExpression> by lz {
val context = getUastContext()
val attributes = psi.parameterList.attributes
attributes.map { attribute ->
UNamedExpression(attribute.name ?: "", this).apply {
val value = attribute.value?.let { context.convertElement(it, this, null) } as? UExpression
expression = value ?: UastEmptyExpression
}
}
}
override fun resolve(): PsiClass? = psi.nameReferenceElement?.resolve() as? PsiClass
override fun findAttributeValue(name: String?): UNamedExpression? {
val context = getUastContext()
val attributeValue = psi.findAttributeValue(name) ?: return null
val value = context.convertElement(attributeValue, this, null)
return UNamedExpression(name ?: "", value)
}
override fun findDeclaredAttributeValue(name: String?): UNamedExpression? {
val context = getUastContext()
val attributeValue = psi.findDeclaredAttributeValue(name) ?: return null
val value = context.convertElement(attributeValue, this, null)
return UNamedExpression(name ?: "", value)
}
companion object {
@JvmStatic
fun wrap(annotation: PsiAnnotation): UAnnotation = JavaUAnnotation(annotation, null)
@JvmStatic
fun wrap(annotations: List<PsiAnnotation>): List<UAnnotation> = annotations.map { JavaUAnnotation(it, null) }
@JvmStatic
fun wrap(annotations: Array<PsiAnnotation>): List<UAnnotation> = annotations.map { JavaUAnnotation(it, null) }
}
}
@@ -1,87 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiAnonymousClass
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import org.jetbrains.uast.*
import org.jetbrains.uast.java.internal.JavaUElementWithComments
abstract class AbstractJavaUClass : UClass, JavaUElementWithComments {
override val uastDeclarations by lz {
mutableListOf<UDeclaration>().apply {
addAll(uastFields)
addAll(uastInitializers)
addAll(uastMethods)
addAll(uastNestedClasses)
}
}
override val uastAnchor: UElement?
get() = UIdentifier(psi.nameIdentifier, this)
override val annotations: List<UAnnotation>
get() = psi.annotations.map { JavaUAnnotation(it, this) }
override val uastFields: List<UVariable> by lz {
psi.fields.map { getLanguagePlugin().convert<UVariable>(it, this) }
}
override val uastInitializers: List<UClassInitializer> by lz {
psi.initializers.map { getLanguagePlugin().convert<UClassInitializer>(it, this) }
}
override val uastMethods: List<UMethod> by lz {
psi.methods.map { getLanguagePlugin().convert<UMethod>(it, this) }
}
override val uastNestedClasses: List<UClass> by lz {
psi.innerClasses.map { getLanguagePlugin().convert<UClass>(it, this) }
}
override fun equals(other: Any?) = this === other
override fun hashCode() = psi.hashCode()
}
class JavaUClass private constructor(psiClass: PsiClass, override val containingElement: UElement?) : AbstractJavaUClass(), PsiClass by psiClass {
override val psi = unwrap<UClass, PsiClass>(psiClass)
override fun getOriginalElement(): PsiElement? {
return super.getOriginalElement()
}
companion object {
fun create(psi: PsiClass, containingElement: UElement?): UClass {
return if (psi is PsiAnonymousClass)
JavaUAnonymousClass(psi, containingElement)
else
JavaUClass(psi, containingElement)
}
}
}
class JavaUAnonymousClass(
psi: PsiAnonymousClass,
override val containingElement: UElement?
) : AbstractJavaUClass(), UAnonymousClass, PsiAnonymousClass by psi {
override val psi: PsiAnonymousClass = unwrap<UAnonymousClass, PsiAnonymousClass>(psi)
override fun getOriginalElement(): PsiElement? {
return super<AbstractJavaUClass>.getOriginalElement()
}
}
@@ -1,50 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiClassInitializer
import com.intellij.psi.PsiCodeBlock
import com.intellij.psi.PsiElement
import org.jetbrains.uast.*
import org.jetbrains.uast.java.internal.JavaUElementWithComments
class JavaUClassInitializer(
psi: PsiClassInitializer,
override val containingElement: UElement?
) : UClassInitializer, JavaUElementWithComments, PsiClassInitializer by psi {
override val psi = unwrap<UClassInitializer, PsiClassInitializer>(psi)
override fun getBody(): PsiCodeBlock {
return super.getBody()
}
override fun getOriginalElement(): PsiElement? {
return super.getOriginalElement()
}
override val uastAnchor: UElement?
get() = null
override val uastBody by lz {
getLanguagePlugin().convertElement(psi.body, this, null) as? UExpression ?: UastEmptyExpression
}
override val annotations by lz { psi.annotations.map { JavaUAnnotation(it, this) } }
override fun equals(other: Any?) = this === other
override fun hashCode() = psi.hashCode()
}
@@ -1,36 +0,0 @@
package org.jetbrains.uast.java
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiJavaFile
import com.intellij.psi.PsiRecursiveElementWalkingVisitor
import org.jetbrains.uast.UAnnotation
import org.jetbrains.uast.UComment
import org.jetbrains.uast.UFile
import org.jetbrains.uast.UastLanguagePlugin
import java.util.*
class JavaUFile(override val psi: PsiJavaFile, override val languagePlugin: UastLanguagePlugin) : UFile {
override val packageName: String
get() = psi.packageName
override val imports by lz {
psi.importList?.allImportStatements?.map { JavaUImportStatement(it, this) } ?: listOf()
}
override val annotations: List<UAnnotation>
get() = emptyList()
override val classes by lz { psi.classes.map { JavaUClass.create(it, this) } }
override val allCommentsInFile by lz {
val comments = ArrayList<UComment>(0)
psi.accept(object : PsiRecursiveElementWalkingVisitor() {
override fun visitComment(comment: PsiComment) {
comments += UComment(comment, this@JavaUFile)
}
})
comments
}
override fun equals(other: Any?) = (other as? JavaUFile)?.psi == psi
}
@@ -1,15 +0,0 @@
package org.jetbrains.uast.java
import com.intellij.psi.PsiImportStatementBase
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UImportStatement
class JavaUImportStatement(
override val psi: PsiImportStatementBase,
override val containingElement: UElement?
) : UImportStatement {
override val isOnDemand: Boolean
get() = psi.isOnDemand
override val importReference by lz { psi.importReference?.let { JavaDumbUElement(it, this) } }
override fun resolve() = psi.resolve()
}
@@ -1,74 +0,0 @@
/*
* 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.java
import com.intellij.psi.*
import org.jetbrains.uast.*
import org.jetbrains.uast.java.internal.JavaUElementWithComments
open class JavaUMethod(
psi: PsiMethod,
override val containingElement: UElement?
) : UMethod, JavaUElementWithComments, PsiMethod by psi {
override val psi = unwrap<UMethod, PsiMethod>(psi)
override fun getBody(): PsiCodeBlock? {
return super.getBody()
}
override fun getOriginalElement(): PsiElement? {
return super.getOriginalElement()
}
override val uastBody by lz {
val body = psi.body ?: return@lz null
getLanguagePlugin().convertElement(body, this) as? UExpression
}
override val annotations by lz { psi.annotations.map { JavaUAnnotation(it, this) } }
override val uastParameters by lz {
psi.parameterList.parameters.map { JavaUParameter(it, this) }
}
override val isOverride: Boolean
get() = psi.modifierList.findAnnotation("java.lang.Override") != null
override val uastAnchor: UElement
get() = UIdentifier((psi.originalElement as? PsiNameIdentifierOwner)?.nameIdentifier ?: psi.nameIdentifier, this)
override fun equals(other: Any?) = this === other
override fun hashCode() = psi.hashCode()
companion object {
fun create(psi: PsiMethod, languagePlugin: UastLanguagePlugin, containingElement: UElement?) = when (psi) {
is PsiAnnotationMethod -> JavaUAnnotationMethod(psi, languagePlugin, containingElement)
else -> JavaUMethod(psi, containingElement)
}
}
}
class JavaUAnnotationMethod(
override val psi: PsiAnnotationMethod,
languagePlugin: UastLanguagePlugin,
containingElement: UElement?
) : JavaUMethod(psi, containingElement), UAnnotationMethod {
override val uastDefaultValue by lz {
val defaultValue = psi.defaultValue ?: return@lz null
languagePlugin.convertElement(defaultValue, this, null) as? UExpression
}
}
@@ -1,169 +0,0 @@
/*
* 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.java
import com.intellij.psi.*
import org.jetbrains.uast.*
import org.jetbrains.uast.expressions.UReferenceExpression
import org.jetbrains.uast.expressions.UTypeReferenceExpression
import org.jetbrains.uast.java.internal.JavaUElementWithComments
import org.jetbrains.uast.psi.PsiElementBacked
abstract class AbstractJavaUVariable : PsiVariable, UVariable, JavaUElementWithComments {
override val uastInitializer by lz {
val initializer = psi.initializer ?: return@lz null
getLanguagePlugin().convertElement(initializer, this) as? UExpression
}
override val annotations by lz { psi.annotations.map { JavaUAnnotation(it, this) } }
override val typeReference by lz { getLanguagePlugin().convertOpt<UTypeReferenceExpression>(psi.typeElement, this) }
override val uastAnchor: UElement
get() = UIdentifier(psi.nameIdentifier, this)
override fun equals(other: Any?) = this === other
override fun hashCode() = psi.hashCode()
}
open class JavaUVariable(
psi: PsiVariable,
override val containingElement: UElement?
) : AbstractJavaUVariable(), UVariable, PsiVariable by psi {
override val psi = unwrap<UVariable, PsiVariable>(psi)
override fun getInitializer(): PsiExpression? {
return super<AbstractJavaUVariable>.getInitializer()
}
override fun getOriginalElement(): PsiElement? {
return super<AbstractJavaUVariable>.getOriginalElement()
}
companion object {
fun create(psi: PsiVariable, containingElement: UElement?): UVariable {
return when (psi) {
is PsiEnumConstant -> JavaUEnumConstant(psi, containingElement)
is PsiLocalVariable -> JavaULocalVariable(psi, containingElement)
is PsiParameter -> JavaUParameter(psi, containingElement)
is PsiField -> JavaUField(psi, containingElement)
else -> JavaUVariable(psi, containingElement)
}
}
}
}
open class JavaUParameter(
psi: PsiParameter,
override val containingElement: UElement?
) : AbstractJavaUVariable(), UParameter, PsiParameter by psi {
override val psi = unwrap<UParameter, PsiParameter>(psi)
override fun getInitializer(): PsiExpression? {
return super<AbstractJavaUVariable>.getInitializer()
}
override fun getOriginalElement(): PsiElement? {
return super<AbstractJavaUVariable>.getOriginalElement()
}
}
open class JavaUField(
psi: PsiField,
override val containingElement: UElement?
) : AbstractJavaUVariable(), UField, PsiField by psi {
override val psi = unwrap<UField, PsiField>(psi)
override fun getInitializer(): PsiExpression? {
return super<AbstractJavaUVariable>.getInitializer()
}
override fun getOriginalElement(): PsiElement? {
return super<AbstractJavaUVariable>.getOriginalElement()
}
}
open class JavaULocalVariable(
psi: PsiLocalVariable,
override val containingElement: UElement?
) : AbstractJavaUVariable(), ULocalVariable, PsiLocalVariable by psi {
override val psi = unwrap<ULocalVariable, PsiLocalVariable>(psi)
override fun getInitializer(): PsiExpression? {
return super<AbstractJavaUVariable>.getInitializer()
}
override fun getOriginalElement(): PsiElement? {
return super<AbstractJavaUVariable>.getOriginalElement()
}
}
open class JavaUEnumConstant(
psi: PsiEnumConstant,
override val containingElement: UElement?
) : AbstractJavaUVariable(), UEnumConstant, PsiEnumConstant by psi {
override val psi = unwrap<UEnumConstant, PsiEnumConstant>(psi)
override fun getInitializer(): PsiExpression? {
return super<AbstractJavaUVariable>.getInitializer()
}
override fun getOriginalElement(): PsiElement? {
return super<AbstractJavaUVariable>.getOriginalElement()
}
override val kind: UastCallKind
get() = UastCallKind.CONSTRUCTOR_CALL
override val receiver: UExpression?
get() = null
override val receiverType: PsiType?
get() = null
override val methodIdentifier: UIdentifier?
get() = null
override val classReference: UReferenceExpression?
get() = JavaEnumConstantClassReference(psi, containingElement)
override val typeArgumentCount: Int
get() = 0
override val typeArguments: List<PsiType>
get() = emptyList()
override val valueArgumentCount: Int
get() = psi.argumentList?.expressions?.size ?: 0
override val valueArguments by lz {
psi.argumentList?.expressions?.map {
getLanguagePlugin().convertElement(it, this) as? UExpression ?: UastEmptyExpression
} ?: emptyList()
}
override val returnType: PsiType?
get() = psi.type
override fun resolve() = psi.resolveMethod()
override val methodName: String?
get() = null
private class JavaEnumConstantClassReference(
override val psi: PsiEnumConstant,
override val containingElement: UElement?
) : JavaAbstractUExpression(), USimpleNameReferenceExpression, PsiElementBacked {
override fun resolve() = psi.containingClass
override val resolvedName: String?
get() = psi.containingClass?.name
override val identifier: String
get() = psi.containingClass?.name ?: "<error>"
}
}
@@ -1,28 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiElement
import org.jetbrains.uast.UElement
import org.jetbrains.uast.psi.PsiElementBacked
class JavaDumbUElement(
override val psi: PsiElement?,
override val containingElement: UElement?
) : JavaAbstractUElement(), UElement, PsiElementBacked {
override fun asLogString() = "JavaDumbUElement"
override fun asRenderString() = "<stub@$psi>"
}
@@ -1,37 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiPolyadicExpression
import org.jetbrains.uast.UBinaryExpression
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UExpression
import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.psi.PsiElementBacked
class JavaSeparatedPolyadicUBinaryExpression(
override val psi: PsiPolyadicExpression,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UBinaryExpression, PsiElementBacked {
override lateinit var leftOperand: UExpression
override lateinit var rightOperand: UExpression
override val operator = psi.operationTokenType.getOperatorType()
override val operatorIdentifier: UIdentifier?
get() = null
override fun resolveOperator() = null
}
@@ -1,29 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiArrayAccessExpression
import org.jetbrains.uast.UArrayAccessExpression
import org.jetbrains.uast.UElement
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUArrayAccessExpression(
override val psi: PsiArrayAccessExpression,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UArrayAccessExpression, PsiElementBacked {
override val receiver by lz { JavaConverter.convertExpression(psi.arrayExpression, this) }
override val indices by lz { singletonListOrEmpty(JavaConverter.convertOrNull(psi.indexExpression, this)) }
}
@@ -1,69 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiAssertStatement
import com.intellij.psi.PsiType
import org.jetbrains.uast.*
import org.jetbrains.uast.expressions.UReferenceExpression
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUAssertExpression(
override val psi: PsiAssertStatement,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UCallExpression, PsiElementBacked {
val condition: UExpression by lz { JavaConverter.convertOrEmpty(psi.assertCondition, this) }
val message: UExpression? by lz { JavaConverter.convertOrNull(psi.assertDescription, this) }
override val methodIdentifier: UIdentifier?
get() = null
override val classReference: UReferenceExpression?
get() = null
override val methodName: String
get() = "assert"
override val receiver: UExpression?
get() = null
override val receiverType: PsiType?
get() = null
override val valueArgumentCount: Int
get() = if (message != null) 2 else 1
override val valueArguments by lz {
val message = this.message
if (message != null) listOf(condition, message) else listOf(condition)
}
override val typeArgumentCount: Int
get() = 0
override val typeArguments: List<PsiType>
get() = emptyList()
override val returnType: PsiType
get() = PsiType.VOID
override val kind: UastCallKind
get() = JavaUastCallKinds.ASSERT
override fun resolve() = null
}
@@ -1,36 +0,0 @@
/*
* 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.java
import com.intellij.psi.PsiAssignmentExpression
import org.jetbrains.uast.UBinaryExpression
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.psi.PsiElementBacked
class JavaUAssignmentExpression(
override val psi: PsiAssignmentExpression,
override val containingElement: UElement?
) : JavaAbstractUExpression(), UBinaryExpression, PsiElementBacked {
override val leftOperand by lz { JavaConverter.convertExpression(psi.lExpression, this) }
override val rightOperand by lz { JavaConverter.convertOrEmpty(psi.rExpression, this) }
override val operator by lz { psi.operationTokenType.getOperatorType() }
override fun resolveOperator() = null
override val operatorIdentifier: UIdentifier
get() = UIdentifier(psi.operationSign, this)
}

Some files were not shown because too many files have changed in this diff Show More