Lint: Update Uast implementation (the new version is without declaration level)
This commit is contained in:
committed by
Yan Zhulanow
parent
6491d3fbac
commit
d5d491e6b2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -16,15 +16,42 @@
|
||||
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import org.jetbrains.uast.UElement
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.java.internal.JavaUElementWithComments
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
abstract class JavaAbstractUElement : UElement {
|
||||
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 fun getExpressionType(): PsiType? {
|
||||
val expression = (this as? PsiElementBacked)?.psi as? PsiExpression ?: return null
|
||||
return expression.type
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -16,215 +16,274 @@
|
||||
|
||||
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
|
||||
|
||||
object JavaUastLanguagePlugin : UastLanguagePlugin {
|
||||
override val converter: UastConverter = JavaConverter
|
||||
override val visitorExtensions: List<UastVisitorExtension>
|
||||
get() = emptyList()
|
||||
}
|
||||
class JavaUastLanguagePlugin(override val project: Project) : UastLanguagePlugin {
|
||||
override val priority = 0
|
||||
|
||||
internal object JavaConverter : UastConverter {
|
||||
override fun isFileSupported(name: String): Boolean {
|
||||
return name.endsWith(".java", ignoreCase = true)
|
||||
}
|
||||
override fun isFileSupported(fileName: String) = fileName.endsWith(".java", ignoreCase = true)
|
||||
|
||||
fun convert(file: PsiJavaFile): UFile = JavaUFile(file)
|
||||
override val language: Language
|
||||
get() = JavaLanguage.INSTANCE
|
||||
|
||||
override fun convert(element: Any?, parent: UElement): UElement? {
|
||||
if (element !is PsiElement) return null
|
||||
return convertPsiElement(element, parent)
|
||||
}
|
||||
|
||||
override fun convertWithParent(element: Any?): UElement? {
|
||||
if (element !is PsiElement) return null
|
||||
if (element is PsiJavaFile) return JavaUFile(element)
|
||||
|
||||
val parent = element.parent ?: return null
|
||||
val parentUElement = convertWithParent(parent) ?: return null
|
||||
return convertPsiElement(element, parentUElement)
|
||||
}
|
||||
|
||||
private fun convertPsiElement(element: PsiElement?, parent: UElement) = when (element) {
|
||||
is PsiJavaFile -> JavaUFile(element)
|
||||
is PsiClass -> JavaUClass(element, parent)
|
||||
is PsiCodeBlock -> convert(element, parent)
|
||||
is PsiMethod -> convert(element, parent)
|
||||
is PsiField -> convert(element, parent)
|
||||
is PsiVariable -> convert(element, parent)
|
||||
is PsiClassInitializer -> convert(element, parent)
|
||||
is PsiAnnotation -> convert(element, parent)
|
||||
is PsiResourceExpression -> convert(element.expression, parent)
|
||||
is PsiExpression -> convert(element, parent)
|
||||
is PsiStatement -> convert(element, parent)
|
||||
is PsiIdentifier -> JavaUSimpleReferenceExpression(element, element.text, parent)
|
||||
is PsiImportStatementBase -> convert(element, parent)
|
||||
is PsiParameter -> convert(element, parent)
|
||||
is PsiTypeParameter -> convert(element, parent)
|
||||
is PsiNameValuePair -> convert(element, parent)
|
||||
is PsiType -> convert(element, parent)
|
||||
is PsiArrayInitializerMemberValue -> JavaAnnotationArrayInitializerUCallExpression(element, parent)
|
||||
else -> null
|
||||
}
|
||||
|
||||
internal fun convert(importStatement: PsiImportStatementBase, parent: UElement): UImportStatement? = when (importStatement) {
|
||||
is PsiImportStatement -> JavaUImportStatement(importStatement, parent)
|
||||
is PsiImportStaticStatement -> JavaUStaticImportStatement(importStatement, parent)
|
||||
else -> null
|
||||
}
|
||||
|
||||
internal fun convert(type: PsiType?, parent: UElement) = JavaUType(type, parent)
|
||||
|
||||
internal fun convert(parameter: PsiParameter, parent: UElement) = JavaValueParameterUVariable(parameter, parent)
|
||||
|
||||
internal fun convert(block: PsiCodeBlock, parent: UElement) = JavaUCodeBlockExpression(block, parent)
|
||||
|
||||
internal fun convert(method: PsiMethod, parent: UElement) = JavaUFunction(method, parent)
|
||||
|
||||
internal fun convert(field: PsiField, parent: UElement) = JavaUVariable(field, parent)
|
||||
|
||||
internal fun convert(variable: PsiVariable, parent: UElement) = JavaUVariable(variable, parent)
|
||||
|
||||
internal fun convert(annotation: PsiAnnotation, parent: UElement) = JavaUAnnotation(annotation, parent)
|
||||
|
||||
internal fun convert(clazz: PsiClass, parent: UElement) = JavaUClass(clazz, parent)
|
||||
|
||||
internal fun convert(initializer: PsiClassInitializer, parent: UElement) = JavaClassInitializerUFunction(initializer, parent)
|
||||
|
||||
internal fun convert(parameter: PsiTypeParameter, parent: UElement) = JavaParameterUTypeReference(parameter, parent)
|
||||
|
||||
internal fun convert(pair: PsiNameValuePair, parent: UElement) = UNamedExpression(pair.name.orAnonymous(), parent).apply {
|
||||
val value = pair.value
|
||||
expression = convert(value, this) as? UExpression ?: UnknownJavaExpression(value ?: pair, this)
|
||||
}
|
||||
|
||||
internal fun convert(expression: PsiReferenceExpression, parent: UElement): UExpression {
|
||||
return if (expression.isQualified) {
|
||||
JavaUQualifiedExpression(expression, parent)
|
||||
} else {
|
||||
val name = expression.referenceName ?: "<error name>"
|
||||
val element = expression.referenceNameElement ?: expression
|
||||
JavaUSimpleReferenceExpression(element, name, parent)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
internal fun convert(expression: PsiQualifiedReferenceElement, parent: UElement): UExpression {
|
||||
val referenceName = expression.referenceName ?: "<error name>"
|
||||
val referenceNameElement = expression.element ?: expression
|
||||
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)
|
||||
}
|
||||
|
||||
return JavaUCompositeQualifiedExpression(parent).apply {
|
||||
receiver = expression.qualifier?.let { convert(it, this) } as? UExpression ?: EmptyUExpression(parent)
|
||||
selector = JavaUSimpleReferenceExpression(referenceNameElement, referenceName, this)
|
||||
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 UAnnotation -> el<UAnnotation> { SimpleUAnnotation(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
|
||||
): UExpression {
|
||||
expression: PsiPolyadicExpression,
|
||||
parent: UElement?,
|
||||
i: Int
|
||||
): UBinaryExpression {
|
||||
return if (i == 1) JavaSeparatedPolyadicUBinaryExpression(expression, parent).apply {
|
||||
leftOperand = convert(expression.operands[0], this)
|
||||
rightOperand = convert(expression.operands[1], this)
|
||||
leftOperand = convertExpression(expression.operands[0], this)
|
||||
rightOperand = convertExpression(expression.operands[1], this)
|
||||
} else JavaSeparatedPolyadicUBinaryExpression(expression, parent).apply {
|
||||
leftOperand = convertPolyadicExpression(expression, parent, i - 1)
|
||||
rightOperand = convert(expression.operands[i], this)
|
||||
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 }
|
||||
|
||||
internal fun convert(expression: PsiExpression, parent: UElement): UExpression = when (expression) {
|
||||
is PsiPolyadicExpression -> convertPolyadicExpression(expression, parent, expression.operands.size - 1)
|
||||
is PsiAssignmentExpression -> JavaUAssignmentExpression(expression, parent)
|
||||
is PsiConditionalExpression -> JavaUTernaryIfExpression(expression, parent)
|
||||
is PsiNewExpression -> {
|
||||
if (expression.anonymousClass != null) {
|
||||
JavaUObjectLiteralExpression(expression, parent)
|
||||
} else {
|
||||
JavaConstructorUCallExpression(expression, parent)
|
||||
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 -> {
|
||||
val qualifier = expression.methodExpression.qualifierExpression
|
||||
if (qualifier != null) {
|
||||
JavaUCompositeQualifiedExpression(parent).apply {
|
||||
receiver = convert(qualifier, this)
|
||||
selector = JavaUCallExpression(expression, this)
|
||||
}
|
||||
} else {
|
||||
JavaUCallExpression(expression, 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 -> JavaArrayInitializerUCallExpression(expression, parent)
|
||||
is PsiBinaryExpression -> JavaUBinaryExpression(expression, parent)
|
||||
is PsiParenthesizedExpression -> JavaUParenthesizedExpression(expression, parent)
|
||||
is PsiPrefixExpression -> JavaUPrefixExpression(expression, parent)
|
||||
is PsiPostfixExpression -> JavaUPostfixExpression(expression, parent)
|
||||
is PsiLiteralExpression -> JavaULiteralExpression(expression, parent)
|
||||
is PsiReferenceExpression -> convert(expression, parent)
|
||||
is PsiThisExpression -> JavaUThisExpression(expression, parent)
|
||||
is PsiSuperExpression -> JavaUSuperExpression(expression, parent)
|
||||
is PsiInstanceOfExpression -> JavaUInstanceCheckExpression(expression, parent)
|
||||
is PsiTypeCastExpression -> JavaUTypeCastExpression(expression, parent)
|
||||
is PsiClassObjectAccessExpression -> JavaUClassLiteralExpression(expression, parent)
|
||||
is PsiArrayAccessExpression -> JavaUArrayAccessExpression(expression, parent)
|
||||
is PsiLambdaExpression -> JavaULambdaExpression(expression, parent)
|
||||
is PsiMethodReferenceExpression -> JavaUCallableReferenceExpression(expression, 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 }
|
||||
|
||||
else -> UnknownJavaExpression(expression, parent)
|
||||
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)
|
||||
}}
|
||||
}
|
||||
|
||||
internal fun convert(statement: PsiStatement, parent: UElement): UExpression = when (statement) {
|
||||
is PsiDeclarationStatement -> convertDeclarations(statement.declaredElements, parent)
|
||||
is PsiExpressionListStatement -> convertDeclarations(statement.expressionList.expressions, parent)
|
||||
is PsiBlockStatement -> JavaUBlockExpression(statement, parent)
|
||||
is PsiLabeledStatement -> JavaULabeledExpression(statement, parent)
|
||||
is PsiExpressionStatement -> convert(statement.expression, parent)
|
||||
is PsiIfStatement -> JavaUIfExpression(statement, parent)
|
||||
is PsiSwitchStatement -> JavaUSwitchExpression(statement, parent)
|
||||
is PsiSwitchLabelStatement -> {
|
||||
if (statement.isDefaultCase)
|
||||
DefaultUSwitchClauseExpression(parent)
|
||||
else JavaUCaseSwitchClauseExpression(statement, parent)
|
||||
}
|
||||
is PsiWhileStatement -> JavaUWhileExpression(statement, parent)
|
||||
is PsiDoWhileStatement -> JavaUDoWhileExpression(statement, parent)
|
||||
is PsiForStatement -> JavaUForExpression(statement, parent)
|
||||
is PsiForeachStatement -> JavaUForEachExpression(statement, parent)
|
||||
is PsiBreakStatement -> JavaUBreakExpression(statement, parent)
|
||||
is PsiContinueStatement -> JavaUContinueExpression(statement, parent)
|
||||
is PsiReturnStatement -> JavaUReturnExpression(statement, parent)
|
||||
is PsiAssertStatement -> JavaUAssertExpression(statement, parent)
|
||||
is PsiThrowStatement -> JavaUThrowExpression(statement, parent)
|
||||
is PsiSynchronizedStatement -> JavaUSynchronizedExpression(statement, parent)
|
||||
is PsiTryStatement -> JavaUTryExpression(statement, parent)
|
||||
|
||||
else -> UnknownJavaExpression(statement, parent)
|
||||
}
|
||||
|
||||
internal fun convertOrEmpty(statement: PsiStatement?, parent: UElement): UExpression {
|
||||
return if (statement != null) convert(statement, parent) else EmptyUExpression(parent)
|
||||
}
|
||||
|
||||
internal fun convertOrEmpty(expression: PsiExpression?, parent: UElement): UExpression {
|
||||
return if (expression != null) convert(expression, parent) else EmptyUExpression(parent)
|
||||
}
|
||||
|
||||
internal fun convertOrNull(expression: PsiExpression?, parent: UElement): UExpression? {
|
||||
return if (expression != null) convert(expression, parent) else null
|
||||
}
|
||||
|
||||
internal fun convertOrEmpty(block: PsiCodeBlock?, parent: UElement): UExpression {
|
||||
return if (block != null) convert(block, parent) else EmptyUExpression(parent)
|
||||
}
|
||||
|
||||
private fun convertDeclarations(elements: Array<out PsiElement>, parent: UElement): SimpleUDeclarationsExpression {
|
||||
val uelements = arrayListOf<UElement>()
|
||||
return SimpleUDeclarationsExpression(parent, uelements).apply {
|
||||
private fun convertDeclarations(elements: Array<out PsiElement>, parent: UElement): UVariableDeclarationsExpression {
|
||||
return JavaUVariableDeclarationsExpression(parent).apply {
|
||||
val variables = mutableListOf<UVariable>()
|
||||
for (element in elements) {
|
||||
convert(element, this)?.let { uelements += it }
|
||||
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
|
||||
}
|
||||
}
|
||||
+9
-2
@@ -16,14 +16,21 @@
|
||||
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 parent: UElement
|
||||
) : JavaAbstractUElement(), UDoWhileExpression, PsiElementBacked {
|
||||
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)
|
||||
}
|
||||
+10
-3
@@ -16,16 +16,23 @@
|
||||
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 parent: UElement
|
||||
) : JavaAbstractUElement(), UForEachExpression, PsiElementBacked {
|
||||
override val variable by lz { JavaConverter.convert(psi.iterationParameter, this) }
|
||||
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)
|
||||
}
|
||||
+10
-5
@@ -16,16 +16,21 @@
|
||||
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 parent: UElement
|
||||
) : JavaAbstractUElement(), UForExpression, PsiElementBacked {
|
||||
override val declaration by lz { psi.initialization?.let { JavaConverter.convert(it, this) } }
|
||||
override val condition by lz { psi.condition?.let { JavaConverter.convert(it, this) } }
|
||||
override val update by lz { psi.update?.let { JavaConverter.convert(it, this) } }
|
||||
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)
|
||||
}
|
||||
+12
-4
@@ -16,18 +16,26 @@
|
||||
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 parent: UElement
|
||||
) : JavaAbstractUElement(), UIfExpression, PsiElementBacked {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UIfExpression, PsiElementBacked {
|
||||
override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val thenBranch by lz { JavaConverter.convertOrEmpty(psi.thenBranch, this) }
|
||||
override val elseBranch by lz { JavaConverter.convertOrEmpty(psi.elseBranch, 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) }
|
||||
}
|
||||
-33
@@ -1,33 +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.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
open class JavaUSpecialExpressionList(
|
||||
override val psi: PsiElement,
|
||||
override val kind: UastSpecialExpressionKind, // original element
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), USpecialExpressionList, PsiElementBacked {
|
||||
class Empty(psi: PsiElement, expressionType: UastSpecialExpressionKind, parent: UElement) :
|
||||
JavaUSpecialExpressionList(psi, expressionType, parent) {
|
||||
init { expressions = emptyList() }
|
||||
}
|
||||
|
||||
override lateinit var expressions: List<UExpression>
|
||||
}
|
||||
+12
-8
@@ -17,31 +17,35 @@ 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 parent: UElement
|
||||
) : JavaAbstractUElement(), USwitchExpression, PsiElementBacked {
|
||||
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 parent: UElement
|
||||
) : JavaAbstractUElement(), USwitchClauseExpression, PsiElementBacked {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), USwitchClauseExpression, PsiElementBacked {
|
||||
override val caseValues by lz {
|
||||
val value = psi.caseValue ?: return@lz null
|
||||
listOf(JavaConverter.convert(value, this))
|
||||
listOf(JavaConverter.convertExpression(value, this))
|
||||
}
|
||||
}
|
||||
|
||||
class DefaultUSwitchClauseExpression(override val parent: UElement) : USwitchClauseExpression {
|
||||
class DefaultUSwitchClauseExpression(override val containingElement: UElement?) : USwitchClauseExpression {
|
||||
override val caseValues: List<UExpression>?
|
||||
get() = null
|
||||
|
||||
override fun logString() = "DefaultUSwitchClauseExpression"
|
||||
override fun renderString() = "else -> "
|
||||
override fun asLogString() = "DefaultUSwitchClauseExpression"
|
||||
override fun asRenderString() = "else -> "
|
||||
}
|
||||
+12
-5
@@ -17,17 +17,24 @@ 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 parent: UElement
|
||||
) : JavaAbstractUElement(), UIfExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val condition by lz { JavaConverter.convert(psi.condition, this) }
|
||||
override val thenBranch by lz { JavaConverter.convertOrEmpty(psi.thenExpression, this) }
|
||||
override val elseBranch by lz { JavaConverter.convertOrEmpty(psi.elseExpression, this) }
|
||||
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)
|
||||
}
|
||||
+34
-14
@@ -15,30 +15,50 @@
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiCatchSection
|
||||
import com.intellij.psi.PsiTryStatement
|
||||
import org.jetbrains.uast.*
|
||||
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 parent: UElement
|
||||
) : JavaAbstractUElement(), UTryExpression, PsiElementBacked {
|
||||
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.convert(it, this) } }
|
||||
override val resources by lz {
|
||||
val vars = psi.resourceList ?: return@lz null
|
||||
val resources = vars.map { JavaConverter.convert(it, this) ?: UDeclarationNotResolved }
|
||||
if (resources.isEmpty()) null else resources
|
||||
}
|
||||
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 parent: UElement
|
||||
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(JavaConverter.convert(it, this)) } ?: emptyList() }
|
||||
override val types by lz { psi.preciseCatchTypes.map { JavaConverter.convert(it, 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))
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -16,14 +16,19 @@
|
||||
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 parent: UElement
|
||||
) : JavaAbstractUElement(), UWhileExpression, PsiElementBacked {
|
||||
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)
|
||||
}
|
||||
-63
@@ -1,63 +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.PsiClassInitializer
|
||||
import com.intellij.psi.PsiModifier
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaClassInitializerUFunction(
|
||||
override val psi: PsiClassInitializer,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UFunction, PsiElementBacked, NoAnnotations {
|
||||
override val kind: UastFunctionKind.UastInitializerKind
|
||||
get() {
|
||||
return if (psi.hasModifierProperty(PsiModifier.STATIC))
|
||||
JavaFunctionKinds.STATIC_INITIALIZER
|
||||
else
|
||||
JavaFunctionKinds.INSTANCE_INITIALIZER
|
||||
}
|
||||
|
||||
override val valueParameters: List<UVariable>
|
||||
get() = emptyList()
|
||||
|
||||
override val valueParameterCount: Int
|
||||
get() = 0
|
||||
|
||||
override val typeParameters: List<UTypeReference>
|
||||
get() = emptyList()
|
||||
|
||||
override val typeParameterCount: Int
|
||||
get() = 0
|
||||
|
||||
override val returnType: UType?
|
||||
get() = null
|
||||
|
||||
override val body by lz { JavaConverter.convert(psi.body, this) }
|
||||
|
||||
override val visibility: UastVisibility
|
||||
get() = UastVisibility.LOCAL
|
||||
|
||||
override val nameElement: UElement?
|
||||
get() = null
|
||||
|
||||
override val name: String
|
||||
get() = "<static>"
|
||||
|
||||
override fun getSuperFunctions(context: UastContext) = emptyList<UFunction>()
|
||||
override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier)
|
||||
}
|
||||
-35
@@ -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.java
|
||||
|
||||
import com.intellij.psi.PsiTypeParameter
|
||||
import org.jetbrains.uast.UClass
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UTypeReference
|
||||
import org.jetbrains.uast.UastContext
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaParameterUTypeReference(
|
||||
override val psi: PsiTypeParameter,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UTypeReference, PsiElementBacked {
|
||||
override val name: String
|
||||
get() = psi.name.orAnonymous()
|
||||
|
||||
override val nameElement by lz { psi.nameIdentifier?.let { JavaDumbUElement(it, this) } }
|
||||
|
||||
override fun resolve(context: UastContext) = psi.reference?.resolve()?.let { JavaConverter.convertWithParent(it) } as? UClass
|
||||
}
|
||||
@@ -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.java
|
||||
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
import org.jetbrains.uast.UAnnotation
|
||||
import org.jetbrains.uast.UClass
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UastContext
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUAnnotation(
|
||||
override val psi: PsiAnnotation,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UAnnotation, PsiElementBacked {
|
||||
override val name: String
|
||||
get() = psi.nameReferenceElement?.referenceName.orAnonymous()
|
||||
|
||||
override val fqName: String?
|
||||
get() = psi.qualifiedName
|
||||
|
||||
override val valueArguments by lz {
|
||||
psi.parameterList.attributes.map {
|
||||
JavaConverter.convert(it, this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolve(context: UastContext) = context.convert(psi.reference?.resolve()) as? UClass
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -13,199 +13,54 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.ide.util.JavaAnonymousClassesHelper
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.util.ClassUtil
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.util.PsiTypesUtil
|
||||
import com.intellij.psi.PsiAnonymousClass
|
||||
import com.intellij.psi.PsiClass
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kinds.UastVariableInitialierKind
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.java.internal.JavaUElementWithComments
|
||||
|
||||
class JavaUClass(
|
||||
override val psi: PsiClass,
|
||||
override val parent: UElement,
|
||||
val newExpression: PsiNewExpression? = null
|
||||
) : JavaAbstractUElement(), UClass, PsiElementBacked {
|
||||
override val name: String
|
||||
get() = psi.name.orAnonymous()
|
||||
|
||||
override val nameElement by lz {
|
||||
if (psi is PsiAnonymousClass && newExpression != null) {
|
||||
newExpression.classOrAnonymousClassReference?.referenceNameElement?.let { JavaDumbUElement(it, this) }
|
||||
} else {
|
||||
JavaConverter.convert(psi.nameIdentifier, this)
|
||||
abstract class AbstractJavaUClass : UClass, JavaUElementWithComments {
|
||||
override val uastDeclarations by lz {
|
||||
mutableListOf<UDeclaration>().apply {
|
||||
addAll(uastFields)
|
||||
addAll(uastInitializers)
|
||||
addAll(uastMethods)
|
||||
addAll(uastNestedClasses)
|
||||
}
|
||||
}
|
||||
|
||||
override val fqName: String?
|
||||
get() = psi.qualifiedName
|
||||
override val uastAnchor: UElement?
|
||||
get() = UIdentifier(psi.nameIdentifier, this)
|
||||
|
||||
override val kind by lz {
|
||||
when {
|
||||
psi.isEnum -> UastClassKind.ENUM
|
||||
psi.isAnnotationType -> UastClassKind.ANNOTATION
|
||||
psi.isInterface -> UastClassKind.INTERFACE
|
||||
psi is PsiAnonymousClass -> UastClassKind.OBJECT
|
||||
else -> UastClassKind.CLASS
|
||||
}
|
||||
}
|
||||
override val uastAnnotations by lz { psi.annotations.map { SimpleUAnnotation(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 val defaultType by lz { JavaConverter.convert(PsiTypesUtil.getClassType(psi), this) }
|
||||
override fun equals(other: Any?) = this === other
|
||||
override fun hashCode() = psi.hashCode()
|
||||
}
|
||||
|
||||
override val companions: List<UClass>
|
||||
get() = emptyList()
|
||||
class JavaUClass private constructor(psi: PsiClass, override val containingElement: UElement?) : AbstractJavaUClass(), PsiClass by psi {
|
||||
override val psi = unwrap<UClass, PsiClass>(psi)
|
||||
|
||||
override val isAnonymous: Boolean
|
||||
get() = psi is PsiAnonymousClass
|
||||
|
||||
override val internalName by lz { getInternalName(psi) }
|
||||
|
||||
override val superTypes by lz {
|
||||
psi.extendsListTypes.map { JavaConverter.convert(it, this) } + psi.implementsListTypes.map { JavaConverter.convert(it, this) }
|
||||
}
|
||||
|
||||
override fun getSuperClass(context: UastContext) = context.convert(psi.superClass) as? UClass
|
||||
|
||||
override val visibility: UastVisibility
|
||||
get() = psi.getVisibility()
|
||||
|
||||
override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier)
|
||||
override val annotations by lz { psi.modifierList.getAnnotations(this) }
|
||||
|
||||
override val declarations by lz {
|
||||
val declarations = arrayListOf<UDeclaration>()
|
||||
psi.fields.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
|
||||
if (psi is PsiAnonymousClass && newExpression != null) {
|
||||
declarations += JavaUAnonymousClassConstructor(psi, newExpression, this)
|
||||
}
|
||||
|
||||
psi.methods.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
psi.innerClasses.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
psi.initializers.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
declarations
|
||||
}
|
||||
|
||||
override fun isSubclassOf(fqName: String): Boolean {
|
||||
return psi.supers.any { base -> psi.isInheritor(base, false) }
|
||||
}
|
||||
|
||||
private companion object {
|
||||
/* Primarily copied from IntellijLintUtils and ClassContext classes from the Android IDEA plugin */
|
||||
private fun getInternalName(psiClass: PsiClass): String? {
|
||||
if (psiClass is PsiAnonymousClass) {
|
||||
val parent = PsiTreeUtil.getParentOfType(psiClass, PsiClass::class.java)
|
||||
if (parent != null) {
|
||||
val internalName = getInternalName(parent) ?: return null
|
||||
return internalName + JavaAnonymousClassesHelper.getName(psiClass)
|
||||
}
|
||||
}
|
||||
var sig = ClassUtil.getJVMClassName(psiClass)
|
||||
if (sig == null) {
|
||||
val qualifiedName = psiClass.qualifiedName
|
||||
if (qualifiedName != null) {
|
||||
return getInternalName(qualifiedName)
|
||||
}
|
||||
return null
|
||||
}
|
||||
else if (sig.indexOf('.') != -1) {
|
||||
// Workaround -- ClassUtil doesn't treat this correctly!
|
||||
// .replace('.', '/');
|
||||
sig = getInternalName(sig)
|
||||
}
|
||||
return sig
|
||||
}
|
||||
|
||||
private fun getInternalName(fqcn: String): String {
|
||||
if (fqcn.indexOf('.') == -1) {
|
||||
return fqcn
|
||||
}
|
||||
|
||||
// If class name contains $, it's not an ambiguous inner class name.
|
||||
if (fqcn.indexOf('$') != -1) {
|
||||
return fqcn.replace('.', '/')
|
||||
}
|
||||
// Let's assume that components that start with Caps are class names.
|
||||
val sb = StringBuilder(fqcn.length)
|
||||
var prev: String? = null
|
||||
for (part in fqcn.split('.')) {
|
||||
if (prev != null && !prev.isEmpty()) {
|
||||
if (Character.isUpperCase(prev[0])) {
|
||||
sb.append('$')
|
||||
}
|
||||
else {
|
||||
sb.append('/')
|
||||
}
|
||||
}
|
||||
sb.append(part)
|
||||
prev = part
|
||||
}
|
||||
|
||||
return sb.toString()
|
||||
companion object {
|
||||
fun create(psi: PsiClass, containingElement: UElement?): UClass {
|
||||
return if (psi is PsiAnonymousClass)
|
||||
JavaUAnonymousClass(psi, containingElement)
|
||||
else
|
||||
JavaUClass(psi, containingElement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class JavaUAnonymousClassConstructor(
|
||||
override val psi: PsiAnonymousClass,
|
||||
newExpression: PsiNewExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UFunction, PsiElementBacked, NoAnnotations, NoModifiers {
|
||||
override val kind = UastFunctionKind.CONSTRUCTOR
|
||||
|
||||
override val valueParameterCount by lz { newExpression.argumentList?.expressions?.size ?: 0 }
|
||||
|
||||
override val valueParameters by lz {
|
||||
val args = newExpression.argumentList ?: return@lz emptyList<UVariable>()
|
||||
args.expressions.mapIndexed { i, psiExpression -> JavaUAnonymousClassConstructorParameter(args, i, this) }
|
||||
}
|
||||
override val typeParameters by lz { psi.typeParameters.map { JavaConverter.convert(it, this) } }
|
||||
|
||||
override val typeParameterCount: Int
|
||||
get() = psi.typeParameters.size
|
||||
|
||||
override val returnType: UType?
|
||||
get() = null
|
||||
|
||||
override val body: UExpression?
|
||||
get() = null
|
||||
|
||||
override val visibility: UastVisibility
|
||||
get() = UastVisibility.LOCAL
|
||||
|
||||
override fun getSuperFunctions(context: UastContext) = emptyList<UFunction>()
|
||||
|
||||
override val nameElement: UElement?
|
||||
get() = null
|
||||
|
||||
override val name: String
|
||||
get() = "<init>"
|
||||
}
|
||||
|
||||
private class JavaUAnonymousClassConstructorParameter(
|
||||
val psi: PsiExpressionList,
|
||||
val index: Int,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UVariable, NoAnnotations, NoModifiers {
|
||||
override val initializer by lz { JavaConverter.convert(psi.expressions[index], this) }
|
||||
|
||||
override val initializerKind: UastVariableInitialierKind
|
||||
get() = UastVariableInitialierKind.EXPRESSION
|
||||
|
||||
override val kind: UastVariableKind
|
||||
get() = UastVariableKind.VALUE_PARAMETER
|
||||
|
||||
override val type by lz { JavaConverter.convert(psi.expressionTypes[index], this) }
|
||||
|
||||
override val nameElement: UElement?
|
||||
get() = null
|
||||
|
||||
override val name: String
|
||||
get() = "p$index"
|
||||
|
||||
override val visibility: UastVisibility
|
||||
get() = UastVisibility.LOCAL
|
||||
class JavaUAnonymousClass(
|
||||
psi: PsiAnonymousClass,
|
||||
override val containingElement: UElement?
|
||||
) : AbstractJavaUClass(), UAnonymousClass, PsiAnonymousClass by psi {
|
||||
override val psi: PsiAnonymousClass = unwrap<UAnonymousClass, PsiAnonymousClass>(psi)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 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 val uastAnchor: UElement?
|
||||
get() = null
|
||||
|
||||
override val uastBody by lz {
|
||||
getLanguagePlugin().convertElement(psi.body, this, null) as? UExpression ?: UastEmptyExpression
|
||||
}
|
||||
|
||||
override val uastAnnotations by lz { psi.annotations.map { SimpleUAnnotation(it, this) } }
|
||||
|
||||
override fun equals(other: Any?) = this === other
|
||||
override fun hashCode() = psi.hashCode()
|
||||
}
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiJavaFile
|
||||
import com.intellij.psi.PsiRecursiveElementWalkingVisitor
|
||||
import org.jetbrains.uast.UComment
|
||||
import org.jetbrains.uast.UFile
|
||||
import org.jetbrains.uast.UImportStatement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.UastLanguagePlugin
|
||||
import java.util.*
|
||||
|
||||
class JavaUFile(override val psi: PsiJavaFile): JavaAbstractUElement(), UFile, PsiElementBacked {
|
||||
override val packageFqName by lz { psi.packageName }
|
||||
|
||||
override val importStatements: List<UImportStatement> by lz {
|
||||
val importList = psi.importList ?: return@lz emptyList<UImportStatement>()
|
||||
importList.importStatements.map { JavaConverter.convert(it, this) }.filterNotNull()
|
||||
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 declarations by lz { psi.classes.map { JavaUClass(it, this) } }
|
||||
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,92 +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.PsiArrayType
|
||||
import com.intellij.psi.PsiClassType
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUFunction(
|
||||
override val psi: PsiMethod,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UFunction, PsiElementBacked {
|
||||
override val kind: UastFunctionKind
|
||||
get() = if (psi.isConstructor) UastFunctionKind.CONSTRUCTOR else UastFunctionKind.FUNCTION
|
||||
|
||||
override val name: String
|
||||
get() = if (psi.isConstructor) "<init>" else psi.name
|
||||
|
||||
override val nameElement by lz { JavaDumbUElement(psi.nameIdentifier, this) }
|
||||
|
||||
override val valueParameters by lz { psi.parameterList.parameters.map { JavaConverter.convert(it, this) } }
|
||||
|
||||
override val valueParameterCount: Int
|
||||
get() = psi.parameterList.parametersCount
|
||||
|
||||
override val typeParameters by lz { psi.typeParameters.map { JavaConverter.convert(it, this) } }
|
||||
|
||||
override val typeParameterCount: Int
|
||||
get() = psi.typeParameters.size
|
||||
|
||||
override val returnType by lz { psi.returnType?.let { JavaConverter.convert(it, this) } }
|
||||
|
||||
override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier)
|
||||
|
||||
val thrownExceptions: List<UType> by lz {
|
||||
psi.throwsList.referencedTypes.map { JavaConverter.convert(it, this) }
|
||||
}
|
||||
|
||||
override val annotations by lz { psi.modifierList.getAnnotations(this) }
|
||||
|
||||
override val visibility: UastVisibility
|
||||
get() = psi.getVisibility()
|
||||
|
||||
override val body by lz { psi.body?.let { JavaConverter.convert(it, this) } }
|
||||
|
||||
override val bytecodeDescriptor by lz { getDescriptor(psi) }
|
||||
|
||||
override fun getSuperFunctions(context: UastContext): List<UFunction> {
|
||||
return psi.findSuperMethods().map { context.convert(it) as? UFunction }.filterNotNull()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
fun getDescriptor(psi: PsiMethod): String? {
|
||||
val parameterTypes = psi.parameterList.parameters.map {
|
||||
renderType(it.type) ?: return null
|
||||
}
|
||||
val returnType = renderType(psi.returnType) ?: return null
|
||||
return parameterTypes.joinToString("", "(", ")") + returnType
|
||||
}
|
||||
|
||||
fun renderType(type: PsiType?): String? = when (type) {
|
||||
null -> null
|
||||
PsiType.CHAR -> "C"
|
||||
PsiType.DOUBLE -> "D"
|
||||
PsiType.FLOAT -> "F"
|
||||
PsiType.INT -> "I"
|
||||
PsiType.LONG -> "J"
|
||||
PsiType.SHORT -> "S"
|
||||
PsiType.BOOLEAN -> "Z"
|
||||
PsiType.VOID -> "V"
|
||||
is PsiArrayType -> renderType(type.componentType)?.let { "[$it" }
|
||||
is PsiClassType -> type.resolve()?.qualifiedName?.replace('.', '/')?.let { "L$it;" }
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,15 @@
|
||||
/*
|
||||
* 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.PsiImportStatement
|
||||
import org.jetbrains.uast.UDeclaration
|
||||
import com.intellij.psi.PsiImportStatementBase
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UImportStatement
|
||||
import org.jetbrains.uast.UastContext
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUImportStatement(
|
||||
override val psi: PsiImportStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UImportStatement, PsiElementBacked {
|
||||
override val fqNameToImport: String?
|
||||
get() = psi.qualifiedName
|
||||
|
||||
override val isStarImport: Boolean
|
||||
override val psi: PsiImportStatementBase,
|
||||
override val containingElement: UElement?
|
||||
) : UImportStatement {
|
||||
override val isOnDemand: Boolean
|
||||
get() = psi.isOnDemand
|
||||
|
||||
override fun resolve(context: UastContext): UDeclaration? {
|
||||
if (psi.isOnDemand) return null
|
||||
val resolvedElement = psi.resolve() ?: return null
|
||||
return context.convert(resolvedElement) as? UDeclaration
|
||||
}
|
||||
override val importReference by lz { psi.importReference?.let { JavaDumbUElement(it, this) } }
|
||||
override fun resolve() = psi.resolve()
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.PsiAnnotationMethod
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiNameIdentifierOwner
|
||||
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 val uastBody by lz {
|
||||
val body = psi.body ?: return@lz null
|
||||
getLanguagePlugin().convertElement(body, this) as? UExpression
|
||||
}
|
||||
|
||||
override val uastAnnotations by lz { psi.annotations.map { SimpleUAnnotation(it, this) } }
|
||||
|
||||
override val uastParameters by lz {
|
||||
psi.parameterList.parameters.map { JavaUParameter(it, this) }
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
-40
@@ -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.PsiImportStaticStatement
|
||||
import org.jetbrains.uast.UDeclaration
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UImportStatement
|
||||
import org.jetbrains.uast.UastContext
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUStaticImportStatement(
|
||||
override val psi: PsiImportStaticStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UImportStatement, PsiElementBacked {
|
||||
override val fqNameToImport: String?
|
||||
get() = psi.referenceName
|
||||
|
||||
override val isStarImport: Boolean
|
||||
get() = psi.isOnDemand
|
||||
|
||||
override fun resolve(context: UastContext): UDeclaration? {
|
||||
if (psi.isOnDemand) return null
|
||||
val resolvedElement = psi.resolve() ?: return null
|
||||
return context.convert(resolvedElement) as? UDeclaration
|
||||
}
|
||||
}
|
||||
@@ -1,82 +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.PsiClassType
|
||||
import com.intellij.psi.PsiPrimitiveType
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.UClass
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UType
|
||||
import org.jetbrains.uast.UastContext
|
||||
|
||||
class JavaUType(
|
||||
val psi: PsiType?,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UType {
|
||||
override val name: String
|
||||
get() = when (psi) {
|
||||
is PsiClassType -> psi.className?.substringAfterLast('.').orAnonymous("type")
|
||||
else -> psi?.canonicalText?.substringAfterLast('.')
|
||||
}.orAnonymous("type")
|
||||
|
||||
override val fqName: String?
|
||||
get() = when (psi) {
|
||||
is PsiClassType -> psi.resolve()?.qualifiedName
|
||||
else -> null
|
||||
}
|
||||
|
||||
override val isInt: Boolean
|
||||
get() = check("int", "java.lang.Integer")
|
||||
|
||||
override val isLong: Boolean
|
||||
get() = check("long", "java.lang.Long")
|
||||
|
||||
override val isShort: Boolean
|
||||
get() = check("short", "java.lang.Short")
|
||||
|
||||
override val isFloat: Boolean
|
||||
get() = check("float", "java.lang.Float")
|
||||
|
||||
override val isDouble: Boolean
|
||||
get() = check("double", "java.lang.Double")
|
||||
|
||||
override val isChar: Boolean
|
||||
get() = check("char", "java.lang.Character")
|
||||
|
||||
override val isBoolean: Boolean
|
||||
get() = check("boolean", "java.lang.Boolean")
|
||||
|
||||
override val isByte: Boolean
|
||||
get() = check("byte", "java.lang.Byte")
|
||||
|
||||
val isString: Boolean
|
||||
get() = (psi as? PsiClassType)?.resolve()?.qualifiedName == "java.lang.String"
|
||||
|
||||
val isPrimitive: Boolean
|
||||
get() = psi is PsiPrimitiveType
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
private inline fun check(unboxedType: String, boxedType: String): Boolean =
|
||||
name == unboxedType || (psi as? PsiClassType)?.resolve()?.qualifiedName == boxedType
|
||||
|
||||
override val annotations by lz { psi.getAnnotations(this) }
|
||||
|
||||
override fun resolve(context: UastContext) = when (psi) {
|
||||
is PsiClassType -> psi.resolve()?.let { context.convert(it) as? UClass }
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -13,41 +13,117 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiField
|
||||
import com.intellij.psi.PsiLocalVariable
|
||||
import com.intellij.psi.PsiVariable
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kinds.UastVariableInitialierKind
|
||||
import org.jetbrains.uast.kinds.UastVariableInitialierKind.Companion.NO_INITIALIZER
|
||||
import org.jetbrains.uast.kinds.UastVariableInitialierKind.Companion.EXPRESSION
|
||||
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
|
||||
|
||||
class JavaUVariable(
|
||||
override val psi: PsiVariable,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UVariable, PsiElementBacked {
|
||||
override val name: String
|
||||
get() = psi.name.orAnonymous()
|
||||
|
||||
override val nameElement by lz { JavaDumbUElement(psi.nameIdentifier, this) }
|
||||
override val type by lz { JavaConverter.convert(psi.type, this) }
|
||||
|
||||
override val initializer by lz { JavaConverter.convertOrEmpty(psi.initializer, this) }
|
||||
|
||||
override val initializerKind: UastVariableInitialierKind
|
||||
get() = if (psi.initializer != null) EXPRESSION else NO_INITIALIZER
|
||||
|
||||
override val kind = when (psi) {
|
||||
is PsiField -> UastVariableKind.MEMBER
|
||||
is PsiLocalVariable -> UastVariableKind.LOCAL_VARIABLE
|
||||
else -> UastVariableKind.LOCAL_VARIABLE
|
||||
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 visibility: UastVisibility
|
||||
get() = psi.getVisibility()
|
||||
override val uastAnnotations by lz { psi.annotations.map { SimpleUAnnotation(it, this) } }
|
||||
override val typeReference by lz { getLanguagePlugin().convertOpt<UTypeReferenceExpression>(psi.typeElement, this) }
|
||||
|
||||
override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier)
|
||||
override val annotations by lz { psi.modifierList.getAnnotations(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)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
open class JavaUField(
|
||||
psi: PsiField,
|
||||
override val containingElement: UElement?
|
||||
) : AbstractJavaUVariable(), UField, PsiField by psi {
|
||||
override val psi = unwrap<UField, PsiField>(psi)
|
||||
}
|
||||
|
||||
open class JavaULocalVariable(
|
||||
psi: PsiLocalVariable,
|
||||
override val containingElement: UElement?
|
||||
) : AbstractJavaUVariable(), ULocalVariable, PsiLocalVariable by psi {
|
||||
override val psi = unwrap<ULocalVariable, PsiLocalVariable>(psi)
|
||||
}
|
||||
|
||||
open class JavaUEnumConstant(
|
||||
psi: PsiEnumConstant,
|
||||
override val containingElement: UElement?
|
||||
) : AbstractJavaUVariable(), UEnumConstant, PsiEnumConstant by psi {
|
||||
override val psi = unwrap<UEnumConstant, PsiEnumConstant>(psi)
|
||||
|
||||
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>"
|
||||
}
|
||||
}
|
||||
-47
@@ -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.java
|
||||
|
||||
import com.intellij.psi.PsiParameter
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kinds.UastVariableInitialierKind
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaValueParameterUVariable(
|
||||
override val psi: PsiParameter,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UVariable, PsiElementBacked {
|
||||
override val name: String
|
||||
get() = psi.name.orAnonymous()
|
||||
|
||||
override val nameElement by lz { JavaDumbUElement(psi.nameIdentifier, this) }
|
||||
override val type by lz { JavaConverter.convert(psi.type, this) }
|
||||
|
||||
override val initializer: UExpression?
|
||||
get() = null
|
||||
|
||||
override val initializerKind: UastVariableInitialierKind
|
||||
get() = UastVariableInitialierKind.NO_INITIALIZER
|
||||
|
||||
override val kind: UastVariableKind
|
||||
get() = UastVariableKind.VALUE_PARAMETER
|
||||
|
||||
override val visibility: UastVisibility
|
||||
get() = UastVisibility.LOCAL
|
||||
|
||||
override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier)
|
||||
override val annotations by lz { psi.modifierList.getAnnotations(this) }
|
||||
}
|
||||
@@ -21,8 +21,8 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaDumbUElement(
|
||||
override val psi: PsiElement?,
|
||||
override val parent: UElement
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUElement(), UElement, PsiElementBacked {
|
||||
override fun logString() = "JavaDumbUElement"
|
||||
override fun renderString() = "<stub@$psi>"
|
||||
override fun asLogString() = "JavaDumbUElement"
|
||||
override fun asRenderString() = "<stub@$psi>"
|
||||
}
|
||||
+8
-3
@@ -19,14 +19,19 @@ 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 parent: UElement
|
||||
) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
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
|
||||
}
|
||||
+3
-3
@@ -22,8 +22,8 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUArrayAccessExpression(
|
||||
override val psi: PsiArrayAccessExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UArrayAccessExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val receiver by lz { JavaConverter.convert(psi.arrayExpression, this) }
|
||||
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)) }
|
||||
}
|
||||
+25
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -17,31 +17,34 @@
|
||||
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 parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked {
|
||||
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 receiverType: UType?
|
||||
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 functionReference: USimpleReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val classReference: USimpleReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val functionName: String?
|
||||
get() = "<assert>"
|
||||
|
||||
override val functionNameElement: UElement?
|
||||
get() = null
|
||||
|
||||
override val valueArgumentCount: Int
|
||||
get() = if (message != null) 2 else 1
|
||||
|
||||
@@ -52,11 +55,15 @@ class JavaUAssertExpression(
|
||||
|
||||
override val typeArgumentCount: Int
|
||||
get() = 0
|
||||
override val typeArguments: List<UType>
|
||||
|
||||
override val typeArguments: List<PsiType>
|
||||
get() = emptyList()
|
||||
|
||||
override val returnType: PsiType
|
||||
get() = PsiType.VOID
|
||||
|
||||
override val kind: UastCallKind
|
||||
get() = JavaUastCallKinds.ASSERT
|
||||
|
||||
override fun resolve(context: UastContext) = null
|
||||
override fun resolve() = null
|
||||
}
|
||||
+9
-3
@@ -18,13 +18,19 @@ 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 parent: UElement
|
||||
) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val leftOperand by lz { JavaConverter.convert(psi.lExpression, this) }
|
||||
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)
|
||||
}
|
||||
@@ -18,13 +18,19 @@ package org.jetbrains.uast.java
|
||||
import com.intellij.psi.PsiBinaryExpression
|
||||
import org.jetbrains.uast.UBinaryExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUBinaryExpression(
|
||||
override val psi: PsiBinaryExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val leftOperand by lz { JavaConverter.convert(psi.lOperand, this) }
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UBinaryExpression, PsiElementBacked {
|
||||
override val leftOperand by lz { JavaConverter.convertExpression(psi.lOperand, this) }
|
||||
override val rightOperand by lz { JavaConverter.convertOrEmpty(psi.rOperand, this) }
|
||||
override val operator by lz { psi.operationTokenType.getOperatorType() }
|
||||
|
||||
override val operatorIdentifier: UIdentifier
|
||||
get() = UIdentifier(psi.operationSign, this)
|
||||
|
||||
override fun resolveOperator() = null
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUBlockExpression(
|
||||
override val psi: PsiBlockStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val expressions by lz { psi.codeBlock.statements.map { JavaConverter.convert(it, this) } }
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UBlockExpression, PsiElementBacked {
|
||||
override val expressions by lz { psi.codeBlock.statements.map { JavaConverter.convertStatement(it, this) } }
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -23,8 +23,8 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUBreakExpression(
|
||||
override val psi: PsiBreakStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBreakExpression, PsiElementBacked {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UBreakExpression, PsiElementBacked {
|
||||
override val label: String?
|
||||
get() = psi.labelIdentifier?.text
|
||||
}
|
||||
+7
-7
@@ -16,20 +16,20 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiMethodReferenceExpression
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.UCallableReferenceExpression
|
||||
import org.jetbrains.uast.UDeclaration
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UastContext
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUCallableReferenceExpression(
|
||||
override val psi: PsiMethodReferenceExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallableReferenceExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UCallableReferenceExpression, PsiElementBacked {
|
||||
override val qualifierExpression by lz { JavaConverter.convertOrNull(psi.qualifierExpression, this) }
|
||||
override val qualifierType by lz { JavaConverter.convert(psi.qualifierType?.type, this) }
|
||||
|
||||
override val qualifierType: PsiType?
|
||||
get() = psi.qualifierType?.type
|
||||
|
||||
override val callableName: String
|
||||
get() = psi.referenceName.orAnonymous()
|
||||
|
||||
override fun resolve(context: UastContext) = context.convert(psi.resolve()) as? UDeclaration
|
||||
}
|
||||
+8
-4
@@ -16,14 +16,18 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiClassObjectAccessExpression
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.UClassLiteralExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UType
|
||||
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUClassLiteralExpression(
|
||||
override val psi: PsiClassObjectAccessExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UClassLiteralExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val type: UType by lz { JavaConverter.convert(psi.type, this) }
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UClassLiteralExpression, PsiElementBacked {
|
||||
override val type: PsiType
|
||||
get() = psi.type
|
||||
|
||||
override val expression by lz { JavaUTypeReferenceExpression(psi.operand, this) }
|
||||
}
|
||||
+3
-3
@@ -22,7 +22,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUCodeBlockExpression(
|
||||
override val psi: PsiCodeBlock,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val expressions by lz { psi.statements.map { JavaConverter.convert(it, this) } }
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UBlockExpression, PsiElementBacked {
|
||||
override val expressions by lz { psi.statements.map { JavaConverter.convertStatement(it, this) } }
|
||||
}
|
||||
+9
-14
@@ -16,30 +16,25 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiNamedElement
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUCompositeQualifiedExpression(
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UQualifiedExpression, PsiElementBacked {
|
||||
override val psi: PsiElement,
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UQualifiedReferenceExpression, PsiElementBacked {
|
||||
override lateinit var receiver: UExpression
|
||||
internal set
|
||||
|
||||
override lateinit var selector: UExpression
|
||||
internal set
|
||||
|
||||
override val resolvedName: String?
|
||||
get() = (resolve() as? PsiNamedElement)?.name
|
||||
|
||||
override fun resolve() = (selector as? UResolvable)?.resolve()
|
||||
|
||||
override val accessType: UastQualifiedExpressionAccessType
|
||||
get() = UastQualifiedExpressionAccessType.SIMPLE
|
||||
|
||||
override fun resolve(context: UastContext): UDeclaration? {
|
||||
val selector = selector
|
||||
return when (selector) {
|
||||
is UCallExpression -> selector.resolve(context)
|
||||
is USimpleReferenceExpression -> selector.resolve(context)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
override val psi: PsiElement
|
||||
get() = (selector as? PsiElementBacked)?.psi ?: (receiver as? PsiElementBacked)?.psi ?: error("No PSI element found")
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -23,8 +23,8 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUContinueExpression(
|
||||
override val psi: PsiContinueStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UContinueExpression, PsiElementBacked {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UContinueExpression, PsiElementBacked {
|
||||
override val label: String?
|
||||
get() = psi.labelIdentifier?.text
|
||||
}
|
||||
+7
-6
@@ -16,21 +16,22 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiInstanceOfExpression
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.UBinaryExpressionWithType
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UTypeReference
|
||||
import org.jetbrains.uast.UastBinaryExpressionWithTypeKind
|
||||
import org.jetbrains.uast.UastErrorType
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUInstanceCheckExpression(
|
||||
override val psi: PsiInstanceOfExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UBinaryExpressionWithType, PsiElementBacked {
|
||||
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||
override val type by lz { JavaConverter.convert(psi.checkType?.type, this) }
|
||||
override val typeReference by lz { psi.checkType?.let { JavaUTypeReferenceExpression(it, this) } }
|
||||
|
||||
override val typeReference: UTypeReference?
|
||||
get() = null
|
||||
override val type: PsiType
|
||||
get() = psi.checkType?.type ?: UastErrorType
|
||||
|
||||
override val operationKind: UastBinaryExpressionWithTypeKind.InstanceCheck
|
||||
get() = UastBinaryExpressionWithTypeKind.INSTANCE_CHECK
|
||||
|
||||
@@ -22,8 +22,9 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaULabeledExpression(
|
||||
override val psi: PsiLabeledStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), ULabeledExpression, PsiElementBacked {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), ULabeledExpression, PsiElementBacked {
|
||||
override val label by lz { psi.labelIdentifier.text }
|
||||
override val expression by lz { JavaConverter.convertOrEmpty(psi.statement, this) }
|
||||
override fun evaluate() = expression.evaluate()
|
||||
}
|
||||
@@ -18,23 +18,25 @@ package org.jetbrains.uast.java
|
||||
import com.intellij.psi.PsiCodeBlock
|
||||
import com.intellij.psi.PsiExpression
|
||||
import com.intellij.psi.PsiLambdaExpression
|
||||
import org.jetbrains.uast.EmptyUExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.ULambdaExpression
|
||||
import org.jetbrains.uast.UastEmptyExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaULambdaExpression(
|
||||
override val psi: PsiLambdaExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), ULambdaExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val valueParameters by lz { psi.parameterList.parameters.map { JavaConverter.convert(it, this) } }
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), ULambdaExpression, PsiElementBacked {
|
||||
override val valueParameters by lz {
|
||||
psi.parameterList.parameters.map { JavaUParameter(it, this) }
|
||||
}
|
||||
|
||||
override val body by lz {
|
||||
val b = psi.body
|
||||
when (b) {
|
||||
is PsiCodeBlock -> JavaConverter.convert(b, this)
|
||||
is PsiExpression -> JavaConverter.convert(b, this)
|
||||
else -> EmptyUExpression(this)
|
||||
is PsiCodeBlock -> JavaConverter.convertBlock(b, this)
|
||||
is PsiExpression -> JavaConverter.convertExpression(b, this)
|
||||
else -> UastEmptyExpression
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,8 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaULiteralExpression(
|
||||
override val psi: PsiLiteralExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), ULiteralExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), ULiteralExpression, PsiElementBacked {
|
||||
override fun evaluate() = psi.value
|
||||
override val value by lz { evaluate() }
|
||||
}
|
||||
+24
-5
@@ -16,15 +16,34 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiNewExpression
|
||||
import org.jetbrains.uast.UClassNotResolved
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UObjectLiteralExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUObjectLiteralExpression(
|
||||
override val psi: PsiNewExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UObjectLiteralExpression, JavaUElementWithType {
|
||||
override val declaration by lz {
|
||||
psi.anonymousClass?.let { JavaUClass(it, this, psi) } ?: UClassNotResolved
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UObjectLiteralExpression, PsiElementBacked {
|
||||
override val declaration by lz { JavaUClass.create(psi.anonymousClass!!, this) }
|
||||
|
||||
override val classReference by lz {
|
||||
psi.classReference?.let { ref ->
|
||||
JavaClassUSimpleNameReferenceExpression(ref.element?.text.orAnonymous(), ref, ref.element, this)
|
||||
}
|
||||
}
|
||||
|
||||
override val valueArgumentCount: Int
|
||||
get() = psi.argumentList?.expressions?.size ?: 0
|
||||
|
||||
override val valueArguments by lz {
|
||||
psi.argumentList?.expressions?.map { JavaConverter.convertExpression(it, this) } ?: emptyList()
|
||||
}
|
||||
|
||||
override val typeArgumentCount by lz { psi.classReference?.typeParameters?.size ?: 0 }
|
||||
|
||||
override val typeArguments: List<PsiType>
|
||||
get() = psi.classReference?.typeParameters?.toList() ?: emptyList()
|
||||
|
||||
override fun resolve() = psi.resolveMethod()
|
||||
}
|
||||
+3
-2
@@ -22,7 +22,8 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUParenthesizedExpression(
|
||||
override val psi: PsiParenthesizedExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UParenthesizedExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UParenthesizedExpression, PsiElementBacked {
|
||||
override val expression by lz { JavaConverter.convertOrEmpty(psi.expression, this) }
|
||||
override fun evaluate() = expression.evaluate()
|
||||
}
|
||||
@@ -18,16 +18,22 @@ package org.jetbrains.uast.java
|
||||
import com.intellij.psi.JavaTokenType
|
||||
import com.intellij.psi.PsiPostfixExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.UPostfixExpression
|
||||
import org.jetbrains.uast.UastPostfixOperator
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUPostfixExpression(
|
||||
override val psi: PsiPostfixExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UPostfixExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UPostfixExpression, PsiElementBacked {
|
||||
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||
|
||||
override val operatorIdentifier: UIdentifier?
|
||||
get() = UIdentifier(psi.operationSign, this)
|
||||
|
||||
override fun resolveOperator() = null
|
||||
|
||||
override val operator = when (psi.operationTokenType) {
|
||||
JavaTokenType.PLUSPLUS -> UastPostfixOperator.INC
|
||||
JavaTokenType.MINUSMINUS -> UastPostfixOperator.DEC
|
||||
|
||||
@@ -18,16 +18,22 @@ package org.jetbrains.uast.java
|
||||
import com.intellij.psi.JavaTokenType
|
||||
import com.intellij.psi.PsiPrefixExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.UPrefixExpression
|
||||
import org.jetbrains.uast.UastPrefixOperator
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUPrefixExpression(
|
||||
override val psi: PsiPrefixExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UPrefixExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UPrefixExpression, PsiElementBacked {
|
||||
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||
|
||||
override val operatorIdentifier: UIdentifier?
|
||||
get() = UIdentifier(psi.operationSign, this)
|
||||
|
||||
override fun resolveOperator() = null
|
||||
|
||||
override val operator = when (psi.operationTokenType) {
|
||||
JavaTokenType.PLUS -> UastPrefixOperator.UNARY_PLUS
|
||||
JavaTokenType.MINUS -> UastPrefixOperator.UNARY_MINUS
|
||||
|
||||
+14
-7
@@ -15,19 +15,26 @@
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiNamedElement
|
||||
import com.intellij.psi.PsiReferenceExpression
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UQualifiedReferenceExpression
|
||||
import org.jetbrains.uast.UastQualifiedExpressionAccessType
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUQualifiedExpression(
|
||||
class JavaUQualifiedReferenceExpression(
|
||||
override val psi: PsiReferenceExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UQualifiedExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UQualifiedReferenceExpression, PsiElementBacked {
|
||||
override val receiver by lz { JavaConverter.convertOrEmpty(psi.qualifierExpression, this) }
|
||||
override val selector by lz { JavaConverter.convert(psi.referenceNameElement, this) as? UExpression ?: EmptyUExpression(this) }
|
||||
|
||||
override val selector by lz {
|
||||
JavaUSimpleNameReferenceExpression(psi.referenceNameElement, psi.referenceName ?: "<error>", this, psi) }
|
||||
|
||||
override val accessType: UastQualifiedExpressionAccessType
|
||||
get() = UastQualifiedExpressionAccessType.SIMPLE
|
||||
|
||||
override fun resolve(context: UastContext) = psi.resolve()?.let { JavaConverter.convertWithParent(it) } as? UDeclaration
|
||||
override val resolvedName: String?
|
||||
get() = (psi.resolve() as? PsiNamedElement)?.name
|
||||
|
||||
override fun resolve() = psi.resolve()
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUReturnExpression(
|
||||
override val psi: PsiReturnStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UReturnExpression, PsiElementBacked {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UReturnExpression, PsiElementBacked {
|
||||
override val returnExpression by lz { JavaConverter.convertOrNull(psi.returnValue, this) }
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.USimpleNameReferenceExpression
|
||||
import org.jetbrains.uast.expressions.UTypeReferenceExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUSimpleNameReferenceExpression(
|
||||
override val psi: PsiElement?,
|
||||
override val identifier: String,
|
||||
override val containingElement: UElement?,
|
||||
val reference: PsiReference? = null
|
||||
) : JavaAbstractUExpression(), USimpleNameReferenceExpression, PsiElementBacked {
|
||||
override fun resolve() = (reference ?: psi as? PsiReference)?.resolve()
|
||||
override val resolvedName: String?
|
||||
get() = ((reference ?: psi as? PsiReference)?.resolve() as? PsiNamedElement)?.name
|
||||
}
|
||||
|
||||
class JavaUTypeReferenceExpression(
|
||||
override val psi: PsiTypeElement,
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UTypeReferenceExpression, PsiElementBacked {
|
||||
override val type: PsiType
|
||||
get() = psi.type
|
||||
}
|
||||
|
||||
class JavaClassUSimpleNameReferenceExpression(
|
||||
override val identifier: String,
|
||||
val ref: PsiJavaReference,
|
||||
override val psi: PsiElement?,
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), USimpleNameReferenceExpression, PsiElementBacked {
|
||||
override fun resolve() = ref.resolve()
|
||||
override val resolvedName: String?
|
||||
get() = (ref.resolve() as? PsiNamedElement)?.name
|
||||
}
|
||||
-40
@@ -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.PsiElement
|
||||
import com.intellij.psi.PsiJavaReference
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUSimpleReferenceExpression(
|
||||
override val psi: PsiElement,
|
||||
override val identifier: String,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override fun resolve(context: UastContext) = psi.reference?.resolve()?.let { context.convert(it) } as? UDeclaration
|
||||
}
|
||||
|
||||
class JavaClassUSimpleReferenceExpression(
|
||||
override val identifier: String,
|
||||
val ref: PsiJavaReference,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), USimpleReferenceExpression, PsiElementBacked {
|
||||
override val psi: PsiElement?
|
||||
get() = ref.element
|
||||
|
||||
override fun resolve(context: UastContext) = context.convert(ref.resolve()) as? UDeclaration
|
||||
}
|
||||
@@ -22,5 +22,5 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUSuperExpression(
|
||||
override val psi: PsiSuperExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), USuperExpression, PsiElementBacked, JavaUElementWithType
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), USuperExpression, PsiElementBacked
|
||||
+6
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -19,24 +19,22 @@ package org.jetbrains.uast.java.expressions
|
||||
import com.intellij.psi.PsiSynchronizedStatement
|
||||
import org.jetbrains.uast.UBlockExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.acceptList
|
||||
import org.jetbrains.uast.java.JavaAbstractUElement
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.java.JavaAbstractUExpression
|
||||
import org.jetbrains.uast.java.JavaConverter
|
||||
import org.jetbrains.uast.java.JavaUElementWithType
|
||||
import org.jetbrains.uast.java.lz
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
class JavaUSynchronizedExpression(
|
||||
override val psi: PsiSynchronizedStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val expressions by lz { psi.body?.statements?.map { JavaConverter.convert(it, this) } ?: listOf() }
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UBlockExpression, PsiElementBacked {
|
||||
override val expressions by lz { psi.body?.statements?.map { JavaConverter.convertStatement(it, this) } ?: listOf() }
|
||||
val lockExpression by lz { JavaConverter.convertOrEmpty(psi.lockExpression, this) }
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitBlockExpression(this)) return
|
||||
psi.lockExpression
|
||||
expressions.acceptList(visitor)
|
||||
lockExpression.accept(visitor)
|
||||
visitor.afterVisitBlockExpression(this)
|
||||
|
||||
@@ -22,5 +22,5 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUThisExpression(
|
||||
override val psi: PsiThisExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UThisExpression, PsiElementBacked, JavaUElementWithType
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UThisExpression, PsiElementBacked
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUThrowExpression(
|
||||
override val psi: PsiThrowStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UThrowExpression, PsiElementBacked {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UThrowExpression, PsiElementBacked {
|
||||
override val thrownExpression by lz { JavaConverter.convertOrEmpty(psi.exception, this) }
|
||||
}
|
||||
+10
-8
@@ -15,23 +15,25 @@
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.PsiTypeCastExpression
|
||||
import org.jetbrains.uast.UBinaryExpressionWithType
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UTypeReference
|
||||
import org.jetbrains.uast.UastBinaryExpressionWithTypeKind
|
||||
import org.jetbrains.uast.UastErrorType
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUTypeCastExpression(
|
||||
override val psi: PsiTypeCastExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UBinaryExpressionWithType, PsiElementBacked {
|
||||
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||
override val type by lz { JavaConverter.convert(psi.castType?.type, this) }
|
||||
|
||||
override val typeReference: UTypeReference?
|
||||
get() = null
|
||||
|
||||
|
||||
override val type: PsiType
|
||||
get() = psi.castType?.type ?: UastErrorType
|
||||
|
||||
override val typeReference by lz { psi.castType?.let { JavaUTypeReferenceExpression(it, this) } }
|
||||
|
||||
override val operationKind: UastBinaryExpressionWithTypeKind.TypeCast
|
||||
get() = UastBinaryExpressionWithTypeKind.TYPE_CAST
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UVariable
|
||||
import org.jetbrains.uast.UVariableDeclarationsExpression
|
||||
|
||||
class JavaUVariableDeclarationsExpression(
|
||||
override val containingElement: UElement?
|
||||
) : UVariableDeclarationsExpression {
|
||||
override lateinit var variables: List<UVariable>
|
||||
internal set
|
||||
|
||||
constructor(parent: UElement?, variables: List<UVariable>) : this(parent) {
|
||||
this.variables = variables
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,13 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class UnknownJavaExpression(
|
||||
override val psi: PsiElement,
|
||||
override val parent: UElement
|
||||
override val containingElement: UElement?
|
||||
) : UExpression, PsiElementBacked {
|
||||
override fun logString() = "[!] UnknownJavaExpression ($psi)"
|
||||
override fun asLogString() = "[!] UnknownJavaExpression ($psi)"
|
||||
}
|
||||
@@ -1,32 +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.PsiExpression
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
interface JavaEvaluatableUElement : UExpression, PsiElementBacked {
|
||||
override fun evaluate(): Any? {
|
||||
val psi = this.psi ?: return null
|
||||
return JavaPsiFacade.getInstance(psi.project).constantEvaluationHelper.computeConstantExpression(psi)
|
||||
}
|
||||
}
|
||||
|
||||
interface JavaUElementWithType : UExpression, PsiElementBacked {
|
||||
override fun getExpressionType() = (psi as? PsiExpression)?.type?.let { JavaConverter.convert(it, this) }
|
||||
}
|
||||
+119
-90
@@ -15,70 +15,96 @@
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiArrayInitializerExpression
|
||||
import com.intellij.psi.PsiArrayInitializerMemberValue
|
||||
import com.intellij.psi.PsiMethodCallExpression
|
||||
import com.intellij.psi.PsiNewExpression
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.util.PsiTypesUtil
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.expressions.UReferenceExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.psi.UElementWithLocation
|
||||
|
||||
class JavaUCallExpression(
|
||||
override val psi: PsiMethodCallExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val receiverType: UType?
|
||||
get() {
|
||||
val qualifiedExpression = parent as? UQualifiedExpression ?: return null
|
||||
if (qualifiedExpression.selector != this) return null
|
||||
return qualifiedExpression.receiver.getExpressionType()
|
||||
}
|
||||
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UCallExpression, PsiElementBacked, UElementWithLocation {
|
||||
override val kind: UastCallKind
|
||||
get() = UastCallKind.FUNCTION_CALL
|
||||
get() = UastCallKind.METHOD_CALL
|
||||
|
||||
override val functionReference by lz {
|
||||
JavaConverter.convert(psi.methodExpression.referenceNameElement, this) as? USimpleReferenceExpression
|
||||
override val methodIdentifier by lz {
|
||||
val methodExpression = psi.methodExpression
|
||||
val nameElement = methodExpression.referenceNameElement ?: return@lz null
|
||||
UIdentifier(nameElement, this)
|
||||
}
|
||||
|
||||
override val classReference: USimpleReferenceExpression?
|
||||
override val classReference: UReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val valueArgumentCount by lz { psi.argumentList.expressions.size }
|
||||
override val valueArguments by lz { psi.argumentList.expressions.map { JavaConverter.convert(it, this) } }
|
||||
override val valueArguments by lz { psi.argumentList.expressions.map { JavaConverter.convertExpression(it, this) } }
|
||||
|
||||
override val typeArgumentCount by lz { psi.typeArguments.size }
|
||||
override val typeArguments by lz { psi.typeArguments.map { JavaConverter.convert(it, this) } }
|
||||
|
||||
override val functionName: String
|
||||
get() = psi.methodExpression.referenceName ?: "<error name>"
|
||||
override val typeArguments: List<PsiType>
|
||||
get() = psi.typeArguments.toList()
|
||||
|
||||
override val functionNameElement: UElement?
|
||||
get() = functionReference
|
||||
override val returnType: PsiType?
|
||||
get() = psi.type
|
||||
|
||||
override fun resolve(context: UastContext) = psi.resolveMethod()?.let { context.convert(it) as? UFunction }
|
||||
override val methodName: String?
|
||||
get() = psi.methodExpression.referenceName
|
||||
|
||||
override fun resolve() = psi.resolveMethod()
|
||||
|
||||
override fun getStartOffset(): Int {
|
||||
return psi.methodExpression.referenceNameElement?.textOffset ?: psi.methodExpression.textOffset
|
||||
}
|
||||
|
||||
override fun getEndOffset() = psi.textRange.endOffset
|
||||
|
||||
override val receiver: UExpression?
|
||||
get() {
|
||||
return if (containingElement is UQualifiedReferenceExpression && containingElement.selector == this)
|
||||
containingElement.receiver
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
override val receiverType: PsiType?
|
||||
get() {
|
||||
val qualifierType = psi.methodExpression.qualifierExpression?.type
|
||||
if (qualifierType != null) {
|
||||
return qualifierType
|
||||
}
|
||||
|
||||
val method = resolve() ?: return null
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC)) return null
|
||||
return method.containingClass?.let { PsiTypesUtil.getClassType(it) }
|
||||
}
|
||||
}
|
||||
|
||||
class JavaConstructorUCallExpression(
|
||||
override val psi: PsiNewExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UCallExpression, PsiElementBacked {
|
||||
override val kind by lz {
|
||||
when {
|
||||
psi.arrayInitializer != null -> JavaUastCallKinds.NEW_ARRAY_WITH_INITIALIZER
|
||||
psi.arrayDimensions.isNotEmpty() -> JavaUastCallKinds.NEW_ARRAY_DIMENTIONS
|
||||
psi.arrayInitializer != null -> UastCallKind.NEW_ARRAY_WITH_INITIALIZER
|
||||
psi.arrayDimensions.isNotEmpty() -> UastCallKind.NEW_ARRAY_WITH_DIMENSIONS
|
||||
else -> UastCallKind.CONSTRUCTOR_CALL
|
||||
}
|
||||
}
|
||||
|
||||
override val receiverType: UType?
|
||||
override val receiver: UExpression?
|
||||
get() = null
|
||||
|
||||
override val functionReference: USimpleReferenceExpression?
|
||||
|
||||
override val receiverType: PsiType?
|
||||
get() = null
|
||||
|
||||
override val methodIdentifier: UIdentifier?
|
||||
get() = null
|
||||
|
||||
override val classReference by lz {
|
||||
psi.classReference?.let { ref ->
|
||||
JavaClassUSimpleReferenceExpression(ref.element?.text.orAnonymous(), ref, this)
|
||||
JavaClassUSimpleNameReferenceExpression(ref.element?.text.orAnonymous(), ref, ref.element, this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,102 +123,105 @@ class JavaConstructorUCallExpression(
|
||||
override val valueArguments by lz {
|
||||
val initializer = psi.arrayInitializer
|
||||
if (initializer != null) {
|
||||
initializer.initializers.map { JavaConverter.convert(it, this) }
|
||||
initializer.initializers.map { JavaConverter.convertExpression(it, this) }
|
||||
}
|
||||
else if (psi.arrayDimensions.isNotEmpty()) {
|
||||
psi.arrayDimensions.map { JavaConverter.convert(it, this) }
|
||||
psi.arrayDimensions.map { JavaConverter.convertExpression(it, this) }
|
||||
}
|
||||
else {
|
||||
psi.argumentList?.expressions?.map { JavaConverter.convert(it, this) } ?: emptyList()
|
||||
psi.argumentList?.expressions?.map { JavaConverter.convertExpression(it, this) } ?: emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
override val typeArgumentCount by lz { psi.typeArguments.size }
|
||||
override val typeArguments by lz { psi.typeArguments.map { JavaConverter.convert(it, this) } }
|
||||
override val typeArgumentCount by lz { psi.classReference?.typeParameters?.size ?: 0 }
|
||||
|
||||
override val functionName: String?
|
||||
get() {
|
||||
val initializer = psi.arrayInitializer
|
||||
return if (initializer != null)
|
||||
"<newArrayWithInitializer>"
|
||||
else if (psi.arrayDimensions.isNotEmpty())
|
||||
"<newArrayWithDimensions>"
|
||||
else null
|
||||
}
|
||||
override val typeArguments: List<PsiType>
|
||||
get() = psi.classReference?.typeParameters?.toList() ?: emptyList()
|
||||
|
||||
override val functionNameElement by lz { JavaDumbUElement(psi, this) }
|
||||
override val returnType: PsiType?
|
||||
get() = (psi.classReference?.resolve() as? PsiClass)?.let { PsiTypesUtil.getClassType(it) } ?: psi.type
|
||||
|
||||
override val methodName: String?
|
||||
get() = null
|
||||
|
||||
override fun resolve(context: UastContext) = psi.resolveConstructor()?.let { context.convert(it) } as? UFunction
|
||||
override fun resolve() = psi.resolveMethod()
|
||||
}
|
||||
|
||||
class JavaArrayInitializerUCallExpression(
|
||||
override val psi: PsiArrayInitializerExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val receiverType: UType?
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UCallExpression, PsiElementBacked {
|
||||
override val methodIdentifier: UIdentifier?
|
||||
get() = null
|
||||
|
||||
override val classReference: UReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val methodName: String?
|
||||
get() = null
|
||||
|
||||
override val functionReference: USimpleReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val classReference: USimpleReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val functionName: String
|
||||
get() = "<array>"
|
||||
|
||||
override val functionNameElement: UElement?
|
||||
get() = null
|
||||
|
||||
override val valueArgumentCount by lz { psi.initializers.size }
|
||||
override val valueArguments by lz { psi.initializers.map { JavaConverter.convert(it, this) } }
|
||||
override val valueArguments by lz { psi.initializers.map { JavaConverter.convertExpression(it, this) } }
|
||||
|
||||
override val typeArgumentCount: Int
|
||||
get() = 0
|
||||
|
||||
override val typeArguments: List<UType>
|
||||
override val typeArguments: List<PsiType>
|
||||
get() = emptyList()
|
||||
|
||||
override val kind: UastCallKind
|
||||
get() = UastCallKind.ARRAY_INITIALIZER
|
||||
override val returnType: PsiType?
|
||||
get() = psi.type
|
||||
|
||||
override fun resolve(context: UastContext) = null
|
||||
override val kind: UastCallKind
|
||||
get() = UastCallKind.NESTED_ARRAY_INITIALIZER
|
||||
|
||||
override fun resolve() = null
|
||||
|
||||
override val receiver: UExpression?
|
||||
get() = null
|
||||
|
||||
override val receiverType: PsiType?
|
||||
get() = null
|
||||
}
|
||||
|
||||
class JavaAnnotationArrayInitializerUCallExpression(
|
||||
override val psi: PsiArrayInitializerMemberValue,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val receiverType: UType?
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UCallExpression, PsiElementBacked {
|
||||
override val kind: UastCallKind
|
||||
get() = UastCallKind.NESTED_ARRAY_INITIALIZER
|
||||
|
||||
override val methodIdentifier: UIdentifier?
|
||||
get() = null
|
||||
|
||||
override val classReference: UReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val methodName: String?
|
||||
get() = null
|
||||
|
||||
override val kind: UastCallKind
|
||||
get() = UastCallKind.ARRAY_INITIALIZER
|
||||
|
||||
override val functionReference: USimpleReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val classReference: USimpleReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val functionName: String
|
||||
get() = "<annotationArray>"
|
||||
|
||||
override val functionNameElement: UElement?
|
||||
get() = null
|
||||
|
||||
override val valueArgumentCount by lz { psi.initializers.size }
|
||||
|
||||
override val valueArguments by lz {
|
||||
psi.initializers.map {
|
||||
JavaConverter.convert(it, this) as? UExpression ?: UnknownJavaExpression(it, this)
|
||||
JavaConverter.convertPsiElement(it, this) as? UExpression ?: UnknownJavaExpression(it, this)
|
||||
}
|
||||
}
|
||||
|
||||
override val typeArgumentCount: Int
|
||||
override val typeArgumentCount: Int
|
||||
get() = 0
|
||||
|
||||
override val typeArguments: List<UType>
|
||||
override val typeArguments: List<PsiType>
|
||||
get() = emptyList()
|
||||
|
||||
override fun resolve(context: UastContext) = null
|
||||
override val returnType: PsiType?
|
||||
get() = null
|
||||
|
||||
override fun resolve() = null
|
||||
|
||||
override val receiver: UExpression?
|
||||
get() = null
|
||||
|
||||
override val receiverType: PsiType?
|
||||
get() = null
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.jetbrains.uast.java.internal
|
||||
|
||||
import com.intellij.psi.PsiComment
|
||||
import org.jetbrains.uast.UComment
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
interface JavaUElementWithComments : UElement {
|
||||
override val comments: List<UComment>
|
||||
get() {
|
||||
val psi = (this as? PsiElementBacked)?.psi ?: return emptyList()
|
||||
return psi.children.filter { it is PsiComment }.map { UComment(it, this) }
|
||||
}
|
||||
}
|
||||
@@ -15,59 +15,31 @@
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.JavaTokenType
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiModifierListOwner
|
||||
import com.intellij.psi.impl.source.tree.CompositeElement
|
||||
import com.intellij.psi.impl.source.tree.java.PsiDoWhileStatementImpl
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.UDeclaration
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UastBinaryOperator
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
private val MODIFIER_MAP = mapOf(
|
||||
UastModifier.ABSTRACT to PsiModifier.ABSTRACT,
|
||||
UastModifier.FINAL to PsiModifier.FINAL,
|
||||
UastModifier.STATIC to PsiModifier.STATIC
|
||||
)
|
||||
|
||||
internal fun PsiModifierListOwner.hasModifier(modifier: UastModifier): Boolean {
|
||||
if (modifier == UastModifier.JVM_FIELD && this is PsiField) {
|
||||
return true
|
||||
}
|
||||
if (modifier == UastModifier.OVERRIDE && this is PsiAnnotationOwner) {
|
||||
return this.annotations.any { it.qualifiedName == "java.lang.Override" }
|
||||
}
|
||||
if (modifier == UastModifier.VARARG && this is PsiParameter) {
|
||||
return this.isVarArgs
|
||||
}
|
||||
if (modifier == UastModifier.IMMUTABLE && this is PsiVariable) {
|
||||
return this.hasModifierProperty(PsiModifier.FINAL)
|
||||
}
|
||||
if (modifier == UastModifier.FINAL && this is PsiVariable) {
|
||||
return false
|
||||
}
|
||||
val javaModifier = MODIFIER_MAP[modifier] ?: return false
|
||||
return hasModifierProperty(javaModifier)
|
||||
}
|
||||
|
||||
internal fun PsiAnnotationOwner?.getAnnotations(owner: UElement): List<UAnnotation> {
|
||||
if (this == null) return emptyList()
|
||||
return annotations.map { JavaConverter.convert(it, owner) }
|
||||
}
|
||||
|
||||
internal fun PsiModifierListOwner.getVisibility(): UastVisibility {
|
||||
if (hasModifierProperty(PsiModifier.PUBLIC)) return UastVisibility.PUBLIC
|
||||
if (hasModifierProperty(PsiModifier.PROTECTED)) return UastVisibility.PROTECTED
|
||||
if (hasModifierProperty(PsiModifier.PRIVATE)) return UastVisibility.PRIVATE
|
||||
if (this is PsiLocalVariable) return UastVisibility.LOCAL
|
||||
return JavaUastVisibilities.PACKAGE_LOCAL
|
||||
}
|
||||
internal val JAVA_CACHED_UELEMENT_KEY = Key.create<WeakReference<UElement>>("cached-java-uelement")
|
||||
|
||||
internal fun IElementType.getOperatorType() = when (this) {
|
||||
JavaTokenType.EQ -> UastBinaryOperator.ASSIGN
|
||||
JavaTokenType.PLUS -> UastBinaryOperator.PLUS
|
||||
JavaTokenType.MINUS -> UastBinaryOperator.MINUS
|
||||
JavaTokenType.ASTERISK -> UastBinaryOperator.MULT
|
||||
JavaTokenType.ASTERISK -> UastBinaryOperator.MULTIPLY
|
||||
JavaTokenType.DIV -> UastBinaryOperator.DIV
|
||||
JavaTokenType.PERC -> UastBinaryOperator.MOD
|
||||
JavaTokenType.OR -> UastBinaryOperator.BITWISE_OR
|
||||
JavaTokenType.AND -> UastBinaryOperator.BITWISE_AND
|
||||
JavaTokenType.XOR -> UastBinaryOperator.BITWISE_XOR
|
||||
JavaTokenType.EQEQ -> UastBinaryOperator.IDENTITY_EQUALS
|
||||
JavaTokenType.NE -> UastBinaryOperator.IDENTITY_NOT_EQUALS
|
||||
JavaTokenType.GT -> UastBinaryOperator.GREATER
|
||||
@@ -88,7 +60,7 @@ internal fun IElementType.getOperatorType() = when (this) {
|
||||
JavaTokenType.LTLTEQ -> UastBinaryOperator.SHIFT_LEFT_ASSIGN
|
||||
JavaTokenType.GTGTEQ -> UastBinaryOperator.SHIFT_RIGHT_ASSIGN
|
||||
JavaTokenType.GTGTGTEQ -> UastBinaryOperator.UNSIGNED_SHIFT_RIGHT_ASSIGN
|
||||
else -> UastBinaryOperator.UNKNOWN
|
||||
else -> UastBinaryOperator.OTHER
|
||||
}
|
||||
|
||||
internal fun <T> singletonListOrEmpty(element: T?) = if (element != null) listOf(element) else emptyList<T>()
|
||||
@@ -98,8 +70,15 @@ internal inline fun String?.orAnonymous(kind: String = ""): String {
|
||||
return this ?: "<anonymous" + (if (kind.isNotBlank()) " $kind" else "") + ">"
|
||||
}
|
||||
|
||||
internal fun <T> runReadAction(action: () -> T): T {
|
||||
return ApplicationManager.getApplication().runReadAction<T>(action)
|
||||
internal fun <T> lz(initializer: () -> T) = lazy(LazyThreadSafetyMode.NONE, initializer)
|
||||
|
||||
val PsiModifierListOwner.annotations: Array<PsiAnnotation>
|
||||
get() = modifierList?.annotations ?: emptyArray()
|
||||
|
||||
internal inline fun <reified T : UDeclaration, reified P : PsiElement> unwrap(element: P): P {
|
||||
val unwrapped = if (element is T) element.psi else element
|
||||
assert(unwrapped !is UElement)
|
||||
return unwrapped as P
|
||||
}
|
||||
|
||||
internal fun <T> lz(initializer: () -> T) = lazy(LazyThreadSafetyMode.NONE, initializer)
|
||||
internal fun PsiElement.getChildByRole(role: Int) = (this as? CompositeElement)?.findChildByRoleAsPsiElement(role)
|
||||
@@ -1,24 +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 org.jetbrains.uast.UastFunctionKind
|
||||
|
||||
object JavaFunctionKinds {
|
||||
val INSTANCE_INITIALIZER = UastFunctionKind.UastInitializerKind("<instance>")
|
||||
val STATIC_INITIALIZER = UastFunctionKind.UastInitializerKind("<static>")
|
||||
}
|
||||
@@ -18,12 +18,6 @@ package org.jetbrains.uast.java
|
||||
import org.jetbrains.uast.UastCallKind
|
||||
|
||||
object JavaUastCallKinds {
|
||||
@JvmField
|
||||
val NEW_ARRAY_WITH_INITIALIZER = UastCallKind("new_array_with_initializer")
|
||||
|
||||
@JvmField
|
||||
val NEW_ARRAY_DIMENTIONS = UastCallKind("new_array_dimensions")
|
||||
|
||||
@JvmField
|
||||
val ASSERT = UastCallKind("assert")
|
||||
}
|
||||
@@ -1,23 +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 org.jetbrains.uast.UastVisibility
|
||||
|
||||
object JavaUastVisibilities {
|
||||
@JvmField
|
||||
val PACKAGE_LOCAL = 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 isValid: Boolean
|
||||
get() = psi?.isValid ?: true
|
||||
}
|
||||
@@ -19,26 +19,25 @@ import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase
|
||||
import com.intellij.testFramework.LightPlatformTestCase
|
||||
import org.jetbrains.uast.java.JavaConverter
|
||||
import java.io.File
|
||||
|
||||
open class AbstractStructureTest : LightCodeInsightTestCase() {
|
||||
fun test(name: String) {
|
||||
val testDir = testDataPath
|
||||
val javaFile = File(testDir, "$name.java")
|
||||
val logFile = File(File(testDir, "log"), "$name.txt")
|
||||
val renderFile = File(File(testDir, "render"), "$name.txt")
|
||||
|
||||
val psiClass = createClass(javaFile.readText())
|
||||
val uElement = JavaConverter.convertWithParent(psiClass) ?: error("UFile was not created")
|
||||
val uFile = uElement.getContainingFile() ?: error("No containing file")
|
||||
try {
|
||||
assertEqualsFile(uFile.logString(), logFile)
|
||||
} catch (e: NoTestFileException) {
|
||||
assertEqualsFile(uFile.renderString(), renderFile)
|
||||
throw e
|
||||
}
|
||||
assertEqualsFile(uFile.renderString(), renderFile)
|
||||
// val testDir = testDataPath
|
||||
// val javaFile = File(testDir, "$name.java")
|
||||
// val logFile = File(File(testDir, "log"), "$name.txt")
|
||||
// val renderFile = File(File(testDir, "render"), "$name.txt")
|
||||
//
|
||||
// val psiClass = createClass(javaFile.readText())
|
||||
// val uElement = JavaConverter.convertWithParent(psiClass) ?: error("UFile was not created")
|
||||
// val uFile = uElement.getContainingFile() ?: error("No containing file")
|
||||
// try {
|
||||
// assertEqualsFile(uFile.logString(), logFile)
|
||||
// } catch (e: NoTestFileException) {
|
||||
// assertEqualsFile(uFile.renderString(), renderFile)
|
||||
// throw e
|
||||
// }
|
||||
// assertEqualsFile(uFile.renderString(), renderFile)
|
||||
}
|
||||
|
||||
private fun createClass(text: String): PsiClass {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
||||
<orderEntry type="module" module-name="uast-common" />
|
||||
<orderEntry type="library" name="intellij-core" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="idea-full" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
Reference in New Issue
Block a user