Uast: Migrate to UAnnotation
This commit is contained in:
committed by
Yan Zhulanow
parent
fee54d9b86
commit
6ff29f473b
@@ -65,10 +65,12 @@ fun <T : UElement> UElement.getParentOfType(
|
||||
|
||||
fun UElement.getContainingFile() = getParentOfType<UFile>(UFile::class.java)
|
||||
|
||||
fun UElement.getContainingUClass() = getParentOfType<UClass>(UClass::class.java)
|
||||
fun UElement.getContainingUMethod() = getParentOfType<UMethod>(UMethod::class.java)
|
||||
fun UElement.getContainingUVariable() = getParentOfType<UVariable>(UVariable::class.java)
|
||||
|
||||
fun UElement.getContainingMethod() = getContainingUMethod()?.psi
|
||||
fun UElement.getContainingClass() = getContainingUClass()?.psi
|
||||
fun UElement.getContainingVariable() = getContainingUVariable()?.psi
|
||||
|
||||
fun PsiElement?.getContainingClass() = this?.let { PsiTreeUtil.getParentOfType(it, PsiClass::class.java) }
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
* Represents an expression or statement (which is considered as an expression in Uast).
|
||||
*/
|
||||
interface UExpression : UElement {
|
||||
interface UExpression : UElement, UAnnotated {
|
||||
/**
|
||||
* Returns the expression value or null if the value can't be calculated.
|
||||
*/
|
||||
@@ -46,7 +45,7 @@ interface UAnnotated : UElement {
|
||||
/**
|
||||
* Returns the list of annotations applied to the current element.
|
||||
*/
|
||||
val annotations: List<PsiAnnotation>
|
||||
val annotations: List<UAnnotation>
|
||||
|
||||
/**
|
||||
* Looks up for annotation element using the annotation qualified name.
|
||||
@@ -54,7 +53,22 @@ interface UAnnotated : UElement {
|
||||
* @param fqName the qualified name to search
|
||||
* @return the first annotation element with the specified qualified name, or null if there is no annotation with such name.
|
||||
*/
|
||||
fun findAnnotation(fqName: String): PsiAnnotation? = annotations.firstOrNull { it.qualifiedName == fqName }
|
||||
fun findAnnotation(fqName: String): UAnnotation? = annotations.firstOrNull { it.qualifiedName == fqName }
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a labeled element.
|
||||
*/
|
||||
interface ULabeled : UElement {
|
||||
/**
|
||||
* Returns the label name, or null if the label is empty.
|
||||
*/
|
||||
val label: String?
|
||||
|
||||
/**
|
||||
* Returns the label identifier, or null if the label is empty.
|
||||
*/
|
||||
val labelIdentifier: UIdentifier?
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,5 +83,8 @@ object UastEmptyExpression : UExpression {
|
||||
override val containingElement: UElement?
|
||||
get() = null
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override fun asLogString() = "EmptyExpression"
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -45,6 +46,7 @@ interface UDoWhileExpression : ULoopExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitDoWhileExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
condition.accept(visitor)
|
||||
body.accept(visitor)
|
||||
visitor.afterVisitDoWhileExpression(this)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -45,6 +46,7 @@ interface UForEachExpression : ULoopExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitForEachExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
iteratedValue.accept(visitor)
|
||||
body.accept(visitor)
|
||||
visitor.afterVisitForEachExpression(this)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -50,6 +51,7 @@ interface UForExpression : ULoopExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitForExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
declaration?.accept(visitor)
|
||||
condition?.accept(visitor)
|
||||
update?.accept(visitor)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -66,6 +67,7 @@ interface UIfExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitIfExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
condition.accept(visitor)
|
||||
thenExpression?.accept(visitor)
|
||||
elseExpression?.accept(visitor)
|
||||
|
||||
@@ -50,6 +50,7 @@ interface USwitchExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitSwitchExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
expression?.accept(visitor)
|
||||
body.accept(visitor)
|
||||
visitor.afterVisitSwitchExpression(this)
|
||||
@@ -78,6 +79,7 @@ interface USwitchClauseExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitSwitchClauseExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
caseValues?.acceptList(visitor)
|
||||
visitor.afterVisitSwitchClauseExpression(this)
|
||||
}
|
||||
@@ -100,6 +102,7 @@ interface USwitchClauseExpressionWithBody : USwitchClauseExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitSwitchClauseExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
caseValues?.acceptList(visitor)
|
||||
body.accept(visitor)
|
||||
visitor.afterVisitSwitchClauseExpression(this)
|
||||
|
||||
@@ -80,6 +80,7 @@ interface UTryExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitTryExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
tryClause.accept(visitor)
|
||||
catchClauses.acceptList(visitor)
|
||||
finallyClause?.accept(visitor)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -40,6 +41,7 @@ interface UWhileExpression : ULoopExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitWhileExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
condition.accept(visitor)
|
||||
body.accept(visitor)
|
||||
visitor.afterVisitWhileExpression(this)
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package org.jetbrains.uast
|
||||
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
|
||||
class SimpleUAnnotation(
|
||||
psi: PsiAnnotation,
|
||||
override val containingElement: UElement?
|
||||
) : UAnnotation, PsiAnnotation by psi {
|
||||
override val psi: PsiAnnotation = unwrap(psi)
|
||||
|
||||
private companion object {
|
||||
fun unwrap(psi: PsiAnnotation): PsiAnnotation {
|
||||
val unwrapped = if (psi is UAnnotation) psi.psi else psi
|
||||
assert(unwrapped !is UElement)
|
||||
return unwrapped
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,38 @@
|
||||
package org.jetbrains.uast
|
||||
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
import com.intellij.psi.PsiClass
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
* An annotation wrapper to be used in [UastVisitor].
|
||||
*/
|
||||
interface UAnnotation : UElement, PsiAnnotation, PsiElementBacked {
|
||||
interface UAnnotation : UElement, PsiElementBacked, UResolvable {
|
||||
/**
|
||||
* Returns the original annotation (which is *always* unwrapped [PsiAnnotation], never a [UAnnotation]).
|
||||
* Returns the annotation qualified name.
|
||||
*/
|
||||
override val psi: PsiAnnotation
|
||||
|
||||
override fun getOriginalElement() = psi.originalElement
|
||||
val qualifiedName: String?
|
||||
|
||||
/**
|
||||
* Returns the annotation class, or null if the class reference was not resolved.
|
||||
*/
|
||||
override fun resolve(): PsiClass?
|
||||
|
||||
/**
|
||||
* Returns the annotation values.
|
||||
*/
|
||||
val attributeValues: List<UNamedExpression>
|
||||
|
||||
fun findAttributeValue(name: String?): UNamedExpression?
|
||||
|
||||
fun findDeclaredAttributeValue(name: String?): UNamedExpression?
|
||||
|
||||
override fun asLogString() = "UAnnotation"
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitAnnotation(this)) return
|
||||
attributeValues.acceptList(visitor)
|
||||
visitor.afterVisitAnnotation(this)
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ interface UClass : UDeclaration, PsiClass {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitClass(this)) return
|
||||
uastAnnotations.acceptList(visitor)
|
||||
annotations.acceptList(visitor)
|
||||
uastDeclarations.acceptList(visitor)
|
||||
visitor.afterVisitClass(this)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ interface UClassInitializer : UDeclaration, PsiClassInitializer {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitInitializer(this)) return
|
||||
uastAnnotations.acceptList(visitor)
|
||||
annotations.acceptList(visitor)
|
||||
uastBody.accept(visitor)
|
||||
visitor.afterVisitInitializer(this)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
/**
|
||||
* A [PsiElement] declaration wrapper.
|
||||
*/
|
||||
interface UDeclaration : UElement, PsiElementBacked, PsiModifierListOwner {
|
||||
interface UDeclaration : UElement, PsiElementBacked, PsiModifierListOwner, UAnnotated {
|
||||
/**
|
||||
* Returns the original declaration (which is *always* unwrapped, never a [UDeclaration]).
|
||||
*/
|
||||
@@ -21,8 +21,6 @@ interface UDeclaration : UElement, PsiElementBacked, PsiModifierListOwner {
|
||||
*/
|
||||
val uastAnchor: UElement?
|
||||
|
||||
val uastAnnotations: List<UAnnotation>
|
||||
|
||||
/**
|
||||
* Returns `true` if this declaration has a [PsiModifier.STATIC] modifier.
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.jetbrains.uast.visitor.UastVisitor
|
||||
/**
|
||||
* Represents a Uast file.
|
||||
*/
|
||||
interface UFile : UElement {
|
||||
interface UFile : UElement, UAnnotated {
|
||||
/**
|
||||
* Returns the original [PsiFile].
|
||||
*/
|
||||
@@ -49,6 +49,7 @@ interface UFile : UElement {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitFile(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
imports.acceptList(visitor)
|
||||
classes.acceptList(visitor)
|
||||
visitor.afterVisitFile(this)
|
||||
|
||||
@@ -21,12 +21,17 @@ interface UMethod : UDeclaration, PsiMethod {
|
||||
*/
|
||||
val uastParameters: List<UParameter>
|
||||
|
||||
/**
|
||||
* Returns true, if the method overrides a method of a super class.
|
||||
*/
|
||||
val isOverride: Boolean
|
||||
|
||||
@Deprecated("Use uastBody instead.", ReplaceWith("uastBody"))
|
||||
override fun getBody() = psi.body
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitMethod(this)) return
|
||||
uastAnnotations.acceptList(visitor)
|
||||
annotations.acceptList(visitor)
|
||||
uastParameters.acceptList(visitor)
|
||||
uastBody?.accept(visitor)
|
||||
visitor.afterVisitMethod(this)
|
||||
@@ -47,7 +52,7 @@ interface UAnnotationMethod : UMethod, PsiAnnotationMethod {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitMethod(this)) return
|
||||
uastAnnotations.acceptList(visitor)
|
||||
annotations.acceptList(visitor)
|
||||
uastParameters.acceptList(visitor)
|
||||
uastBody?.accept(visitor)
|
||||
uastDefaultValue?.accept(visitor)
|
||||
|
||||
@@ -23,7 +23,7 @@ interface UVariable : UDeclaration, PsiVariable {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitVariable(this)) return
|
||||
uastAnnotations.acceptList(visitor)
|
||||
annotations.acceptList(visitor)
|
||||
uastInitializer?.accept(visitor)
|
||||
visitor.afterVisitVariable(this)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ interface UEnumConstant : UField, UCallExpression, PsiEnumConstant {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitVariable(this)) return
|
||||
uastAnnotations.acceptList(visitor)
|
||||
annotations.acceptList(visitor)
|
||||
methodIdentifier?.accept(visitor)
|
||||
classReference?.accept(visitor)
|
||||
valueArguments.acceptList(visitor)
|
||||
|
||||
@@ -35,6 +35,7 @@ interface UArrayAccessExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitArrayAccessExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
receiver.accept(visitor)
|
||||
indices.acceptList(visitor)
|
||||
visitor.afterVisitArrayAccessExpression(this)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.uast
|
||||
|
||||
import com.intellij.psi.PsiMethod
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
@@ -51,6 +52,7 @@ interface UBinaryExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitBinaryExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
leftOperand.accept(visitor)
|
||||
rightOperand.accept(visitor)
|
||||
visitor.afterVisitBinaryExpression(this)
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.uast
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.expressions.UTypeReferenceExpression
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -52,6 +53,7 @@ interface UBinaryExpressionWithType : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitBinaryExpressionWithType(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
operand.accept(visitor)
|
||||
visitor.afterVisitBinaryExpressionWithType(this)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ interface UBlockExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitBlockExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
expressions.acceptList(visitor)
|
||||
visitor.afterVisitBlockExpression(this)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,8 @@ interface UBreakExpression : UExpression {
|
||||
val label: String?
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
visitor.visitBreakExpression(this)
|
||||
if (visitor.visitBreakExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
visitor.afterVisitBreakExpression(this)
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ interface UCallExpression : UExpression, UResolvable {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitCallExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
methodIdentifier?.accept(visitor)
|
||||
classReference?.accept(visitor)
|
||||
valueArguments.acceptList(visitor)
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.uast
|
||||
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
@@ -42,6 +43,7 @@ interface UCallableReferenceExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitCallableReferenceExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
qualifierExpression?.accept(visitor)
|
||||
visitor.afterVisitCallableReferenceExpression(this)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.uast
|
||||
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
@@ -38,7 +39,8 @@ interface UClassLiteralExpression : UExpression {
|
||||
val expression: UExpression?
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
visitor.visitClassLiteralExpression(this)
|
||||
if (visitor.visitClassLiteralExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
expression?.accept(visitor)
|
||||
visitor.afterVisitClassLiteralExpression(this)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,8 @@ interface UContinueExpression : UExpression {
|
||||
val label: String?
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
visitor.visitContinueExpression(this)
|
||||
if (visitor.visitContinueExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
visitor.afterVisitContinueExpression(this)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,14 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
* Represents a generic list of expressions.
|
||||
*/
|
||||
interface USpecialExpressionList : UExpression {
|
||||
interface UExpressionList : UExpression {
|
||||
/**
|
||||
* Returns the list of expressions.
|
||||
*/
|
||||
@@ -32,13 +34,14 @@ interface USpecialExpressionList : UExpression {
|
||||
val kind: UastSpecialExpressionKind
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitSpecialExpressionList(this)) return
|
||||
if (visitor.visitExpressionList(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
expressions.acceptList(visitor)
|
||||
visitor.afterVisitSpecialExpressionList(this)
|
||||
visitor.afterVisitExpressionList(this)
|
||||
}
|
||||
|
||||
fun firstOrNull(): UExpression? = expressions.firstOrNull()
|
||||
|
||||
override fun logString() = log("USpecialExpressionList (${kind.name})", expressions)
|
||||
override fun renderString() = kind.name + " " + expressions.joinToString(" : ") { it.renderString() }
|
||||
override fun asLogString() = log("USpecialExpressionList (${kind.name})", expressions)
|
||||
override fun asRenderString() = kind.name + " " + expressions.joinToString(" : ") { it.asRenderString() }
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.uast.expressions
|
||||
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.ULabeled
|
||||
import org.jetbrains.uast.UResolvable
|
||||
|
||||
/**
|
||||
* A common parent for "this" and "super" expressions.
|
||||
*/
|
||||
interface UInstanceExpression : UExpression, ULabeled, UResolvable
|
||||
@@ -15,17 +15,18 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
* Represents an expression with the label specified.
|
||||
*/
|
||||
interface ULabeledExpression : UExpression {
|
||||
interface ULabeledExpression : UExpression, ULabeled {
|
||||
/**
|
||||
* Returns the expression label.
|
||||
*/
|
||||
val label: String
|
||||
override val label: String
|
||||
|
||||
/**
|
||||
* Returns the expression itself.
|
||||
@@ -34,6 +35,7 @@ interface ULabeledExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitLabeledExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
expression.accept(visitor)
|
||||
visitor.afterVisitLabeledExpression(this)
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ interface ULambdaExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitLambdaExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
valueParameters.acceptList(visitor)
|
||||
body.accept(visitor)
|
||||
visitor.afterVisitLambdaExpression(this)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
@@ -46,7 +47,8 @@ interface ULiteralExpression : UExpression {
|
||||
get() = evaluate() is Boolean
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
visitor.visitLiteralExpression(this)
|
||||
if (visitor.visitLiteralExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
visitor.afterVisitLiteralExpression(this)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -24,8 +25,12 @@ class UNamedExpression(
|
||||
): UExpression, UNamed {
|
||||
lateinit var expression: UExpression
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitElement(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
expression.accept(visitor)
|
||||
visitor.afterVisitElement(this)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.uast
|
||||
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -49,6 +50,7 @@ interface UObjectLiteralExpression : UCallExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitObjectLiteralExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
declaration.accept(visitor)
|
||||
visitor.afterVisitObjectLiteralExpression(this)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -29,6 +30,7 @@ interface UParenthesizedExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitParenthesizedExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
expression.accept(visitor)
|
||||
visitor.afterVisitParenthesizedExpression(this)
|
||||
}
|
||||
|
||||
+2
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.expressions.UReferenceExpression
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -42,6 +43,7 @@ interface UQualifiedReferenceExpression : UReferenceExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitQualifiedReferenceExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
receiver.accept(visitor)
|
||||
selector.accept(visitor)
|
||||
visitor.afterVisitQualifiedReferenceExpression(this)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -30,6 +31,7 @@ interface UReturnExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitReturnExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
returnExpression?.accept(visitor)
|
||||
visitor.afterVisitReturnExpression(this)
|
||||
}
|
||||
|
||||
+3
-1
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.expressions.UReferenceExpression
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,8 @@ interface USimpleNameReferenceExpression : UReferenceExpression {
|
||||
val identifier: String
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
visitor.visitSimpleNameReferenceExpression(this)
|
||||
if (visitor.visitSimpleNameReferenceExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
visitor.afterVisitSimpleNameReferenceExpression(this)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,18 +15,21 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.expressions.UInstanceExpression
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
* Represents a `super` expression.
|
||||
* Qualified `super` is not supported at the moment.
|
||||
*/
|
||||
interface USuperExpression : UExpression {
|
||||
interface USuperExpression : UInstanceExpression {
|
||||
override fun asLogString() = "USuperExpression"
|
||||
override fun asRenderString() = "super"
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
visitor.visitSuperExpression(this)
|
||||
if (visitor.visitSuperExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
visitor.afterVisitSuperExpression(this)
|
||||
}
|
||||
}
|
||||
@@ -15,18 +15,21 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.expressions.UInstanceExpression
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
/**
|
||||
* Represents a `this` expression.
|
||||
* Qualified `this` is not supported at the moment.
|
||||
*/
|
||||
interface UThisExpression : UExpression {
|
||||
interface UThisExpression : UInstanceExpression {
|
||||
override fun asLogString() = "UThisExpression"
|
||||
override fun asRenderString() = "this"
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
visitor.visitThisExpression(this)
|
||||
if (visitor.visitThisExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
visitor.afterVisitThisExpression(this)
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.uast
|
||||
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -30,6 +31,7 @@ interface UThrowExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitThrowExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
thrownExpression.accept(visitor)
|
||||
visitor.afterVisitThrowExpression(this)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.uast.expressions
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.util.PsiTypesUtil
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.name
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -18,7 +19,8 @@ interface UTypeReferenceExpression : UExpression {
|
||||
fun getQualifiedName() = PsiTypesUtil.getPsiClass(type)?.qualifiedName
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
visitor.visitTypeReferenceExpression(this)
|
||||
if (visitor.visitTypeReferenceExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
visitor.afterVisitTypeReferenceExpression(this)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.uast
|
||||
|
||||
import com.intellij.psi.PsiMethod
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
@@ -44,6 +45,7 @@ interface UUnaryExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitUnaryExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
operand.accept(visitor)
|
||||
visitor.afterVisitUnaryExpression(this)
|
||||
}
|
||||
@@ -54,6 +56,7 @@ interface UPrefixExpression : UUnaryExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitPrefixExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
operand.accept(visitor)
|
||||
visitor.afterVisitPrefixExpression(this)
|
||||
}
|
||||
@@ -67,6 +70,7 @@ interface UPostfixExpression : UUnaryExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitPostfixExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
operand.accept(visitor)
|
||||
visitor.afterVisitPostfixExpression(this)
|
||||
}
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ interface UVariableDeclarationsExpression : UExpression {
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitDeclarationsExpression(this)) return
|
||||
annotations.acceptList(visitor)
|
||||
variables.acceptList(visitor)
|
||||
visitor.afterVisitDeclarationsExpression(this)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,10 @@ fun UElement.isNewArrayWithDimensions() = (this as? UCallExpression)?.kind == Ua
|
||||
|
||||
fun UElement.isNewArrayWithInitializer() = (this as? UCallExpression)?.kind == UastCallKind.NEW_ARRAY_WITH_INITIALIZER
|
||||
|
||||
fun UElement.isNestedArrayInitializer() = (this as? UCallExpression)?.kind == UastCallKind.NESTED_ARRAY_INITIALIZER
|
||||
@Deprecated("Use isArrayInitializer()", ReplaceWith("isArrayInitializer()"))
|
||||
fun UElement.isNestedArrayInitializer() = isArrayInitializer()
|
||||
|
||||
fun UElement.isArrayInitializer() = (this as? UCallExpression)?.kind == UastCallKind.NESTED_ARRAY_INITIALIZER
|
||||
|
||||
fun UElement.isTypeCast() = (this as? UBinaryExpressionWithType)?.operationKind is UastBinaryExpressionWithTypeKind.TypeCast
|
||||
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiExpression
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.uast.UAnnotation
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.java.internal.JavaUElementWithComments
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -49,7 +53,10 @@ abstract class JavaAbstractUExpression : JavaAbstractUElement(), UExpression {
|
||||
val psi = (this as? PsiElementBacked)?.psi ?: return null
|
||||
return JavaPsiFacade.getInstance(psi.project).constantEvaluationHelper.computeConstantExpression(psi)
|
||||
}
|
||||
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override fun getExpressionType(): PsiType? {
|
||||
val expression = (this as? PsiElementBacked)?.psi as? PsiExpression ?: return null
|
||||
return expression.type
|
||||
|
||||
@@ -109,7 +109,7 @@ class JavaUastLanguagePlugin(override val project: Project) : UastLanguagePlugin
|
||||
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) } //???
|
||||
is PsiAnnotation -> el<UAnnotation> { JavaUAnnotation(element, parent) } //???
|
||||
else -> null
|
||||
}}
|
||||
}
|
||||
|
||||
+3
@@ -46,6 +46,9 @@ class DefaultUSwitchClauseExpression(override val containingElement: UElement?)
|
||||
override val caseValues: List<UExpression>?
|
||||
get() = null
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override fun asLogString() = "DefaultUSwitchClauseExpression"
|
||||
override fun asRenderString() = "else -> "
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
import com.intellij.psi.PsiClass
|
||||
import org.jetbrains.uast.*
|
||||
|
||||
class JavaUAnnotation(
|
||||
override val psi: PsiAnnotation,
|
||||
override val containingElement: UElement?
|
||||
) : UAnnotation {
|
||||
override val qualifiedName: String?
|
||||
get() = psi.qualifiedName
|
||||
|
||||
override val attributeValues: List<UNamedExpression> by lz {
|
||||
val context = getUastContext()
|
||||
val attributes = psi.parameterList.attributes
|
||||
|
||||
attributes.map { attribute ->
|
||||
UNamedExpression(attribute.name ?: "", this).apply {
|
||||
val value = attribute.value?.let { context.convertElement(it, this, null) } as? UExpression
|
||||
expression = value ?: UastEmptyExpression
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolve(): PsiClass? = psi.nameReferenceElement?.resolve() as? PsiClass
|
||||
|
||||
override fun findAttributeValue(name: String?): UNamedExpression? {
|
||||
val context = getUastContext()
|
||||
val attributeValue = psi.findAttributeValue(name) ?: return null
|
||||
val value = context.convertElement(attributeValue, this, null)
|
||||
return UNamedExpression(name ?: "", value)
|
||||
}
|
||||
|
||||
override fun findDeclaredAttributeValue(name: String?): UNamedExpression? {
|
||||
val context = getUastContext()
|
||||
val attributeValue = psi.findDeclaredAttributeValue(name) ?: return null
|
||||
val value = context.convertElement(attributeValue, this, null)
|
||||
return UNamedExpression(name ?: "", value)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun wrap(annotation: PsiAnnotation): UAnnotation = JavaUAnnotation(annotation, null)
|
||||
|
||||
@JvmStatic
|
||||
fun wrap(annotations: List<PsiAnnotation>): List<UAnnotation> = annotations.map { JavaUAnnotation(it, null) }
|
||||
|
||||
@JvmStatic
|
||||
fun wrap(annotations: Array<PsiAnnotation>): List<UAnnotation> = annotations.map { JavaUAnnotation(it, null) }
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,24 @@ abstract class AbstractJavaUClass : UClass, JavaUElementWithComments {
|
||||
override val uastAnchor: UElement?
|
||||
get() = UIdentifier(psi.nameIdentifier, this)
|
||||
|
||||
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 annotations: List<UAnnotation>
|
||||
get() = psi.annotations.map { JavaUAnnotation(it, this) }
|
||||
|
||||
override val uastFields: List<UVariable> by lz {
|
||||
psi.fields.map { getLanguagePlugin().convert<UVariable>(it, this) }
|
||||
}
|
||||
|
||||
override val uastInitializers: List<UClassInitializer> by lz {
|
||||
psi.initializers.map { getLanguagePlugin().convert<UClassInitializer>(it, this) }
|
||||
}
|
||||
|
||||
override val uastMethods: List<UMethod> by lz {
|
||||
psi.methods.map { getLanguagePlugin().convert<UMethod>(it, this) }
|
||||
}
|
||||
|
||||
override val uastNestedClasses: List<UClass> by lz {
|
||||
psi.innerClasses.map { getLanguagePlugin().convert<UClass>(it, this) }
|
||||
}
|
||||
|
||||
override fun equals(other: Any?) = this === other
|
||||
override fun hashCode() = psi.hashCode()
|
||||
|
||||
@@ -33,7 +33,7 @@ class JavaUClassInitializer(
|
||||
getLanguagePlugin().convertElement(psi.body, this, null) as? UExpression ?: UastEmptyExpression
|
||||
}
|
||||
|
||||
override val uastAnnotations by lz { psi.annotations.map { SimpleUAnnotation(it, this) } }
|
||||
override val annotations by lz { psi.annotations.map { JavaUAnnotation(it, this) } }
|
||||
|
||||
override fun equals(other: Any?) = this === other
|
||||
override fun hashCode() = psi.hashCode()
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.uast.java
|
||||
import com.intellij.psi.PsiComment
|
||||
import com.intellij.psi.PsiJavaFile
|
||||
import com.intellij.psi.PsiRecursiveElementWalkingVisitor
|
||||
import org.jetbrains.uast.UAnnotation
|
||||
import org.jetbrains.uast.UComment
|
||||
import org.jetbrains.uast.UFile
|
||||
import org.jetbrains.uast.UastLanguagePlugin
|
||||
@@ -16,6 +17,9 @@ class JavaUFile(override val psi: PsiJavaFile, override val languagePlugin: Uast
|
||||
psi.importList?.allImportStatements?.map { JavaUImportStatement(it, this) } ?: listOf()
|
||||
}
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override val classes by lz { psi.classes.map { JavaUClass.create(it, this) } }
|
||||
|
||||
override val allCommentsInFile by lz {
|
||||
|
||||
@@ -33,12 +33,15 @@ open class JavaUMethod(
|
||||
getLanguagePlugin().convertElement(body, this) as? UExpression
|
||||
}
|
||||
|
||||
override val uastAnnotations by lz { psi.annotations.map { SimpleUAnnotation(it, this) } }
|
||||
override val annotations by lz { psi.annotations.map { JavaUAnnotation(it, this) } }
|
||||
|
||||
override val uastParameters by lz {
|
||||
psi.parameterList.parameters.map { JavaUParameter(it, this) }
|
||||
}
|
||||
|
||||
override val isOverride: Boolean
|
||||
get() = psi.modifierList.findAnnotation("java.lang.Override") != null
|
||||
|
||||
override val uastAnchor: UElement
|
||||
get() = UIdentifier((psi.originalElement as? PsiNameIdentifierOwner)?.nameIdentifier ?: psi.nameIdentifier, this)
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ abstract class AbstractJavaUVariable : PsiVariable, UVariable, JavaUElementWithC
|
||||
getLanguagePlugin().convertElement(initializer, this) as? UExpression
|
||||
}
|
||||
|
||||
override val uastAnnotations by lz { psi.annotations.map { SimpleUAnnotation(it, this) } }
|
||||
override val annotations by lz { psi.annotations.map { JavaUAnnotation(it, this) } }
|
||||
override val typeReference by lz { getLanguagePlugin().convertOpt<UTypeReferenceExpression>(psi.typeElement, this) }
|
||||
|
||||
override val uastAnchor: UElement
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiLabeledStatement
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.ULabeledExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
@@ -24,7 +25,13 @@ class JavaULabeledExpression(
|
||||
override val psi: PsiLabeledStatement,
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), ULabeledExpression, PsiElementBacked {
|
||||
override val label by lz { psi.labelIdentifier.text }
|
||||
override val label: String
|
||||
get() = psi.labelIdentifier.text
|
||||
|
||||
override val labelIdentifier: UIdentifier?
|
||||
get() = UIdentifier(psi.labelIdentifier, this)
|
||||
|
||||
override val expression by lz { JavaConverter.convertOrEmpty(psi.statement, this) }
|
||||
|
||||
override fun evaluate() = expression.evaluate()
|
||||
}
|
||||
@@ -17,10 +17,19 @@ package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiSuperExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.USuperExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUSuperExpression(
|
||||
override val psi: PsiSuperExpression,
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), USuperExpression, PsiElementBacked
|
||||
) : JavaAbstractUExpression(), USuperExpression, PsiElementBacked {
|
||||
override val label: String?
|
||||
get() = psi.qualifier?.qualifiedName
|
||||
|
||||
override val labelIdentifier: UIdentifier?
|
||||
get() = psi.qualifier?.let { UIdentifier(it, this) }
|
||||
|
||||
override fun resolve() = psi.qualifier?.resolve()
|
||||
}
|
||||
@@ -17,10 +17,19 @@ package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiThisExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.UThisExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUThisExpression(
|
||||
override val psi: PsiThisExpression,
|
||||
override val containingElement: UElement?
|
||||
) : JavaAbstractUExpression(), UThisExpression, PsiElementBacked
|
||||
) : JavaAbstractUExpression(), UThisExpression, PsiElementBacked {
|
||||
override val label: String?
|
||||
get() = psi.qualifier?.qualifiedName
|
||||
|
||||
override val labelIdentifier: UIdentifier?
|
||||
get() = psi.qualifier?.let { UIdentifier(it, this) }
|
||||
|
||||
override fun resolve() = psi.qualifier?.resolve()
|
||||
}
|
||||
+4
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import org.jetbrains.uast.UAnnotation
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UVariable
|
||||
import org.jetbrains.uast.UVariableDeclarationsExpression
|
||||
@@ -13,4 +14,7 @@ class JavaUVariableDeclarationsExpression(
|
||||
constructor(parent: UElement?, variables: List<UVariable>) : this(parent) {
|
||||
this.variables = variables
|
||||
}
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.uast.UAnnotation
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -25,4 +26,7 @@ class UnknownJavaExpression(
|
||||
override val containingElement: UElement?
|
||||
) : UExpression, PsiElementBacked {
|
||||
override fun asLogString() = "[!] UnknownJavaExpression ($psi)"
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
}
|
||||
@@ -21,7 +21,6 @@ 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.UDeclaration
|
||||
import org.jetbrains.uast.UElement
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.psi.KtAnnotatedExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.uast.UAnnotation
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -32,4 +33,11 @@ abstract class KotlinAbstractUElement : UElement {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class KotlinAbstractUExpression : KotlinAbstractUElement(), UExpression
|
||||
abstract class KotlinAbstractUExpression : KotlinAbstractUElement(), UExpression {
|
||||
override val annotations: List<UAnnotation>
|
||||
get() {
|
||||
val psi = (this as? PsiElementBacked)?.psi as? KtExpression ?: return emptyList()
|
||||
val annotatedExpression = psi.parent as? KtAnnotatedExpression ?: return emptyList()
|
||||
return annotatedExpression.annotationEntries.map { KotlinUAnnotation(it, this) }
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,9 @@ package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiVariable
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||
import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.psi.PsiClass
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.uast.*
|
||||
|
||||
class KotlinUAnnotation(
|
||||
override val psi: KtAnnotationEntry,
|
||||
override val containingElement: UElement?
|
||||
) : UAnnotation {
|
||||
private val resolvedAnnotation by lz { psi.analyze()[BindingContext.ANNOTATION, psi] }
|
||||
|
||||
override val qualifiedName: String?
|
||||
get() = resolvedAnnotation?.type?.constructor?.declarationDescriptor?.fqNameSafe?.asString()
|
||||
|
||||
override val attributeValues by lz {
|
||||
val context = getUastContext()
|
||||
psi.valueArguments.map { arg ->
|
||||
val name = arg.getArgumentName()?.asName?.asString() ?: ""
|
||||
UNamedExpression(name, this).apply {
|
||||
val value = arg.getArgumentExpression()?.let { context.convertElement(it, this) } as? UExpression
|
||||
expression = value ?: UastEmptyExpression
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolve(): PsiClass? {
|
||||
val descriptor = resolvedAnnotation?.type?.constructor?.declarationDescriptor ?: return null
|
||||
return descriptor.toSource()?.getMaybeLightElement(this) as? PsiClass
|
||||
}
|
||||
|
||||
//TODO
|
||||
override fun findAttributeValue(name: String?) = findDeclaredAttributeValue(name)
|
||||
|
||||
override fun findDeclaredAttributeValue(name: String?): UNamedExpression? {
|
||||
return attributeValues.firstOrNull { it.matchesName(name ?: "value") }
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,9 @@ class KotlinUClass private constructor(
|
||||
override val containingElement: UElement?
|
||||
get() = containingMethod
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override val expressions by lz {
|
||||
initializers.map {
|
||||
getLanguagePlugin().convertOpt<UExpression>(it.body, this) ?: UastEmptyExpression
|
||||
|
||||
@@ -26,6 +26,9 @@ class KotlinUFile(override val psi: KtFile, override val languagePlugin: UastLan
|
||||
override val packageName: String
|
||||
get() = psi.packageFqName.asString()
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = psi.annotationEntries.map { KotlinUAnnotation(it, this) }
|
||||
|
||||
override val allCommentsInFile by lz {
|
||||
val comments = ArrayList<UComment>(0)
|
||||
psi.accept(object : PsiRecursiveElementWalkingVisitor() {
|
||||
|
||||
-1
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtImportDirective
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.jetbrains.uast.kotlin.declarations
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightElement
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethodImpl
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFunction
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.uast.*
|
||||
@@ -37,7 +39,10 @@ open class KotlinUMethod(
|
||||
val bodyExpression = (kotlinOrigin as? KtFunction)?.bodyExpression ?: return@lz null
|
||||
getLanguagePlugin().convertElement(bodyExpression, this) as? UExpression
|
||||
}
|
||||
|
||||
|
||||
override val isOverride: Boolean
|
||||
get() = (kotlinOrigin as? KtCallableDeclaration)?.hasModifier(KtTokens.OVERRIDE_KEYWORD) ?: false
|
||||
|
||||
companion object {
|
||||
fun create(psi: KtLightMethod, containingElement: UElement?) = when (psi) {
|
||||
is KtLightMethodImpl.KtLightAnnotationMethod -> KotlinUAnnotationMethod(psi, containingElement)
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.uast.expressions.UReferenceExpression
|
||||
import org.jetbrains.uast.expressions.UTypeReferenceExpression
|
||||
import org.jetbrains.uast.java.AbstractJavaUVariable
|
||||
import org.jetbrains.uast.java.JavaAbstractUExpression
|
||||
import org.jetbrains.uast.java.JavaUAnnotation
|
||||
import org.jetbrains.uast.java.annotations
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiParameter
|
||||
import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
|
||||
@@ -49,7 +50,7 @@ class KotlinUVariable(
|
||||
) : AbstractKotlinUVariable(), UVariable, PsiVariable by psi {
|
||||
override val psi = unwrap<UVariable, PsiVariable>(psi)
|
||||
|
||||
override val uastAnnotations by lz { psi.annotations.map { SimpleUAnnotation(it, this) } }
|
||||
override val annotations by lz { psi.annotations.map { JavaUAnnotation(it, this) } }
|
||||
override val typeReference by lz { getLanguagePlugin().convertOpt<UTypeReferenceExpression>(psi.typeElement, this) }
|
||||
|
||||
companion object {
|
||||
|
||||
+4
@@ -18,6 +18,7 @@ package org.jetbrains.uast.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtLabeledExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.ULabeledExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
@@ -28,5 +29,8 @@ class KotlinULabeledExpression(
|
||||
override val label: String
|
||||
get() = psi.getLabelName().orAnonymous("label")
|
||||
|
||||
override val labelIdentifier: UIdentifier?
|
||||
get() = psi.getTargetLabel()?.let { UIdentifier(it, this) }
|
||||
|
||||
override val expression by lz { KotlinConverter.convertOrEmpty(psi.baseExpression, this) }
|
||||
}
|
||||
+3
@@ -63,6 +63,9 @@ class KotlinUObjectLiteralExpression(
|
||||
) : KotlinAbstractUElement(), USimpleNameReferenceExpression, PsiElementBacked {
|
||||
override fun resolve() = (psi.resolveCallToDeclaration(this) as? PsiMethod)?.containingClass
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override val resolvedName: String?
|
||||
get() = identifier
|
||||
|
||||
|
||||
+3
@@ -109,6 +109,9 @@ open class KotlinUSimpleReferenceExpression(
|
||||
null
|
||||
}
|
||||
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
|
||||
override val receiverType by lz {
|
||||
val type = (resolvedCall.dispatchReceiver ?: resolvedCall.extensionReceiver)?.type ?: return@lz null
|
||||
type.toPsiType(this, psi, boxed = true)
|
||||
|
||||
+11
-1
@@ -17,11 +17,21 @@
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtSuperExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.USuperExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUSuperExpression(
|
||||
override val psi: KtSuperExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), USuperExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement
|
||||
) : KotlinAbstractUExpression(), USuperExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
|
||||
override val labelIdentifier: UIdentifier?
|
||||
get() = psi.getTargetLabel()?.let { UIdentifier(it, this) }
|
||||
|
||||
override fun resolve() = psi.analyze()[BindingContext.LABEL_TARGET, psi.getTargetLabel()]
|
||||
}
|
||||
+2
@@ -95,6 +95,8 @@ class KotlinUSwitchEntry(
|
||||
get() = null
|
||||
override val containingElement: UElement?
|
||||
get() = this@KotlinUSwitchEntry
|
||||
override val annotations: List<UAnnotation>
|
||||
get() = emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-1
@@ -17,11 +17,21 @@
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtThisExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIdentifier
|
||||
import org.jetbrains.uast.UThisExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class KotlinUThisExpression(
|
||||
override val psi: KtThisExpression,
|
||||
override val containingElement: UElement?
|
||||
) : KotlinAbstractUExpression(), UThisExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement
|
||||
) : KotlinAbstractUExpression(), UThisExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement {
|
||||
override val label: String?
|
||||
get() = psi.getLabelName()
|
||||
|
||||
override val labelIdentifier: UIdentifier?
|
||||
get() = psi.getTargetLabel()?.let { UIdentifier(it, this) }
|
||||
|
||||
override fun resolve() = psi.analyze()[BindingContext.LABEL_TARGET, psi.getTargetLabel()]
|
||||
}
|
||||
Reference in New Issue
Block a user