Code review changes
This commit is contained in:
@@ -25,8 +25,8 @@ object JavaUastLanguagePlugin : UastLanguagePlugin {
|
||||
}
|
||||
|
||||
internal object JavaConverter : UastConverter {
|
||||
override fun isFileSupported(path: String): Boolean {
|
||||
return path.endsWith(".java", ignoreCase = true)
|
||||
override fun isFileSupported(name: String): Boolean {
|
||||
return name.endsWith(".java", ignoreCase = true)
|
||||
}
|
||||
|
||||
fun convert(file: PsiJavaFile): UFile = JavaUFile(file)
|
||||
@@ -125,10 +125,10 @@ internal object JavaConverter : UastConverter {
|
||||
parent: UElement,
|
||||
i: Int
|
||||
): UExpression {
|
||||
return if (i == 1) JavaCombinedUBinaryExpression(expression, parent).apply {
|
||||
return if (i == 1) JavaSeparatedPolyadicUBinaryExpression(expression, parent).apply {
|
||||
leftOperand = convert(expression.operands[0], this)
|
||||
rightOperand = convert(expression.operands[1], this)
|
||||
} else JavaCombinedUBinaryExpression(expression, parent).apply {
|
||||
} else JavaSeparatedPolyadicUBinaryExpression(expression, parent).apply {
|
||||
leftOperand = convertPolyadicExpression(expression, parent, i - 1)
|
||||
rightOperand = convert(expression.operands[i], this)
|
||||
}
|
||||
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiDoWhileStatement
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UDoWhileExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUDoWhileExpression(
|
||||
override val psi: PsiDoWhileStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UDoWhileExpression, PsiElementBacked, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UDoWhileExpression, PsiElementBacked {
|
||||
override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||
}
|
||||
+2
-4
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiForeachStatement
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UForEachExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,9 +23,8 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUForEachExpression(
|
||||
override val psi: PsiForeachStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UForEachExpression, PsiElementBacked, NoEvaluate {
|
||||
override val variableName: String?
|
||||
get() = psi.iterationParameter.name
|
||||
) : JavaAbstractUElement(), UForEachExpression, PsiElementBacked {
|
||||
override val variable by lz { JavaConverter.convert(psi.iterationParameter, this) }
|
||||
|
||||
override val iteratedValue by lz { JavaConverter.convertOrEmpty(psi.iteratedValue, this) }
|
||||
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiForStatement
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UForExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUForExpression(
|
||||
override val psi: PsiForStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UForExpression, PsiElementBacked, NoEvaluate {
|
||||
) : 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) } }
|
||||
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiIfStatement
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UIfExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUIfExpression(
|
||||
override val psi: PsiIfStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UIfExpression, PsiElementBacked, NoEvaluate {
|
||||
) : JavaAbstractUElement(), 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) }
|
||||
|
||||
+2
-3
@@ -17,7 +17,6 @@ package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiSwitchLabelStatement
|
||||
import com.intellij.psi.PsiSwitchStatement
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpressionSwitchClauseExpression
|
||||
import org.jetbrains.uast.USwitchExpression
|
||||
@@ -26,7 +25,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUSwitchExpression(
|
||||
override val psi: PsiSwitchStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), USwitchExpression, PsiElementBacked, NoEvaluate {
|
||||
) : JavaAbstractUElement(), USwitchExpression, PsiElementBacked {
|
||||
override val expression by lz { JavaConverter.convertOrEmpty(psi.expression, this) }
|
||||
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||
}
|
||||
@@ -34,6 +33,6 @@ class JavaUSwitchExpression(
|
||||
class JavaUExpressionSwitchClauseExpression(
|
||||
override val psi: PsiSwitchLabelStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UExpressionSwitchClauseExpression, PsiElementBacked, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UExpressionSwitchClauseExpression, PsiElementBacked {
|
||||
override val caseValue by lz { JavaConverter.convertOrEmpty(psi.caseValue, this) }
|
||||
}
|
||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUTernaryIfExpression(
|
||||
override val psi: PsiConditionalExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UIfExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
) : 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) }
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUTryExpression(
|
||||
override val psi: PsiTryStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UTryExpression, PsiElementBacked, NoEvaluate {
|
||||
) : JavaAbstractUElement(), 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) } }
|
||||
@@ -40,5 +40,5 @@ class JavaUCatchClause(
|
||||
) : 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 { listOf(JavaConverter.convert(psi.catchType, this)) }
|
||||
override val types by lz { psi.preciseCatchTypes.map { JavaConverter.convert(it, this) } }
|
||||
}
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiWhileStatement
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UWhileExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUWhileExpression(
|
||||
override val psi: PsiWhileStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UWhileExpression, PsiElementBacked, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UWhileExpression, PsiElementBacked {
|
||||
override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) }
|
||||
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||
}
|
||||
@@ -92,14 +92,14 @@ class JavaUClass(
|
||||
declarations
|
||||
}
|
||||
|
||||
override fun isSubclassOf(name: String): Boolean {
|
||||
override fun isSubclassOf(fqName: String): Boolean {
|
||||
tailrec fun isSubClassOf(clazz: PsiClass?, name: String): Boolean = when {
|
||||
clazz == null -> false
|
||||
clazz.qualifiedName == name -> true
|
||||
else -> isSubClassOf(clazz.superClass, name)
|
||||
}
|
||||
|
||||
return isSubClassOf(psi, name)
|
||||
return isSubClassOf(psi, fqName)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
@@ -169,13 +169,7 @@ private class JavaUAnonymousClassConstructor(
|
||||
|
||||
override val valueParameters by lz {
|
||||
val args = newExpression.argumentList ?: return@lz emptyList<UVariable>()
|
||||
val variables = ArrayList<UVariable>(args.expressions.size)
|
||||
|
||||
for (i in 0..(args.expressions.size - 1)) {
|
||||
variables += JavaUAnonymousClassConstructorParameter(args, i, this)
|
||||
}
|
||||
|
||||
variables
|
||||
args.expressions.mapIndexed { i, psiExpression -> JavaUAnonymousClassConstructorParameter(args, i, this) }
|
||||
}
|
||||
override val typeParameters by lz { psi.typeParameters.map { JavaConverter.convert(it, this) } }
|
||||
|
||||
@@ -216,4 +210,7 @@ private class JavaUAnonymousClassConstructorParameter(
|
||||
|
||||
override val name: String
|
||||
get() = "p$index"
|
||||
|
||||
override val visibility: UastVisibility
|
||||
get() = UastVisibility.LOCAL
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.uast.UImportStatement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUFile(override val psi: PsiJavaFile): JavaAbstractUElement(), UFile, PsiElementBacked {
|
||||
override val packageFqName by lz { psi.packageName.let { if (it.isNotBlank()) it else null } }
|
||||
override val packageFqName by lz { psi.packageName }
|
||||
|
||||
override val importStatements: List<UImportStatement> by lz {
|
||||
val importList = psi.importList ?: return@lz emptyList<UImportStatement>()
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiImportStatement
|
||||
import org.jetbrains.uast.UDeclaration
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UImportStatement
|
||||
import org.jetbrains.uast.UastContext
|
||||
import org.jetbrains.uast.kinds.UastImportKind
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
@@ -32,5 +34,11 @@ class JavaUImportStatement(
|
||||
get() = UastImportKind.CLASS
|
||||
|
||||
override val isStarImport: Boolean
|
||||
get() = false
|
||||
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
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -16,8 +16,10 @@
|
||||
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.kinds.UastImportKind
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
@@ -32,5 +34,11 @@ class JavaUStaticImportStatement(
|
||||
get() = UastImportKind.MEMBER
|
||||
|
||||
override val isStarImport: Boolean
|
||||
get() = true
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,7 @@ package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiField
|
||||
import com.intellij.psi.PsiVariable
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UVariable
|
||||
import org.jetbrains.uast.UastModifier
|
||||
import org.jetbrains.uast.UastVariableKind
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUVariable(
|
||||
@@ -40,6 +37,9 @@ class JavaUVariable(
|
||||
else -> UastVariableKind.LOCAL_VARIABLE
|
||||
}
|
||||
|
||||
override val visibility: UastVisibility
|
||||
get() = psi.getVisibility()
|
||||
|
||||
override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier)
|
||||
override val annotations by lz { psi.modifierList.getAnnotations(this) }
|
||||
}
|
||||
+5
-1
@@ -22,7 +22,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaValueParameterUVariable(
|
||||
override val psi: PsiParameter,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UVariable, PsiElementBacked, NoModifiers {
|
||||
) : JavaAbstractUElement(), UVariable, PsiElementBacked {
|
||||
override val name: String
|
||||
get() = psi.name.orAnonymous()
|
||||
|
||||
@@ -35,5 +35,9 @@ class JavaValueParameterUVariable(
|
||||
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) }
|
||||
}
|
||||
@@ -24,6 +24,6 @@ class JavaDumbUElement(
|
||||
override val psi: PsiElement?,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UElement, PsiElementBacked, LeafUElement {
|
||||
override fun logString() = "JavaPsiElementStub"
|
||||
override fun logString() = "JavaDumbUElement"
|
||||
override fun renderString() = "<stub@$psi>"
|
||||
}
|
||||
+2
-2
@@ -21,10 +21,10 @@ import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaCombinedUBinaryExpression(
|
||||
class JavaSeparatedPolyadicUBinaryExpression(
|
||||
override val psi: PsiPolyadicExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override lateinit var leftOperand: UExpression
|
||||
override lateinit var rightOperand: UExpression
|
||||
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiArrayAccessExpression
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UArrayAccessExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUArrayAccessExpression(
|
||||
override val psi: PsiArrayAccessExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UArrayAccessExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UArrayAccessExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val receiver by lz { JavaConverter.convert(psi.arrayExpression, this) }
|
||||
override val indices by lz { singletonListOrEmpty(JavaConverter.convertOrNull(psi.indexExpression, this)) }
|
||||
}
|
||||
+7
-6
@@ -16,18 +16,19 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiAssignmentExpression
|
||||
import org.jetbrains.uast.UAssignmentExpression
|
||||
import org.jetbrains.uast.UBinaryExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UastBinaryOperator
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUAssignmentExpression(
|
||||
override val psi: PsiAssignmentExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UAssignmentExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
override val reference by lz { JavaConverter.convert(psi.lExpression, this) }
|
||||
) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val leftOperand by lz { JavaConverter.convert(psi.lExpression, this) }
|
||||
|
||||
override val operator: String
|
||||
get() = psi.operationSign.text
|
||||
override val operator: UastBinaryOperator
|
||||
get() = UastBinaryOperator.ASSIGN
|
||||
|
||||
override val value by lz { JavaConverter.convertOrEmpty(psi.rExpression, this) }
|
||||
override val rightOperand by lz { JavaConverter.convertOrEmpty(psi.rExpression, this) }
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUBinaryExpression(
|
||||
override val psi: PsiBinaryExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val leftOperand by lz { JavaConverter.convert(psi.lOperand, this) }
|
||||
override val rightOperand by lz { JavaConverter.convertOrEmpty(psi.rOperand, this) }
|
||||
override val operator by lz { psi.operationTokenType.getOperatorType() }
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiBlockStatement
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UBlockExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,6 +23,6 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUBlockExpression(
|
||||
override val psi: PsiBlockStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val expressions by lz { psi.codeBlock.statements.map { JavaConverter.convert(it, this) } }
|
||||
}
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiMethodReferenceExpression
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UCallableReferenceExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,6 +23,6 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUCallableReferenceExpression(
|
||||
override val psi: PsiMethodReferenceExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallableReferenceExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UCallableReferenceExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val qualifierType by lz { JavaConverter.convert(psi.qualifierType?.type, this) }
|
||||
}
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiClassObjectAccessExpression
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UClassLiteralExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UType
|
||||
@@ -25,6 +24,6 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUClassLiteralExpression(
|
||||
override val psi: PsiClassObjectAccessExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UClassLiteralExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UClassLiteralExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val type: UType by lz { JavaConverter.convert(psi.type, this) }
|
||||
}
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiCodeBlock
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UBlockExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,6 +23,6 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUCodeBlockExpression(
|
||||
override val psi: PsiCodeBlock,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val expressions by lz { psi.statements.map { JavaConverter.convert(it, this) } }
|
||||
}
|
||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUCompositeQualifiedExpression(
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UQualifiedExpression, PsiElementBacked, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UQualifiedExpression, PsiElementBacked {
|
||||
override lateinit var receiver: UExpression
|
||||
internal set
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUInstanceCheckExpression(
|
||||
override val psi: PsiInstanceOfExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
) : JavaAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||
override val type by lz { JavaConverter.convert(psi.checkType?.type, this) }
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiLabeledStatement
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.ULabeledExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaULabeledExpression(
|
||||
override val psi: PsiLabeledStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), ULabeledExpression, PsiElementBacked, NoEvaluate {
|
||||
) : JavaAbstractUElement(), ULabeledExpression, PsiElementBacked {
|
||||
override val label by lz { psi.labelIdentifier.text }
|
||||
override val expression by lz { JavaConverter.convertOrEmpty(psi.statement, this) }
|
||||
}
|
||||
@@ -19,7 +19,6 @@ import com.intellij.psi.PsiCodeBlock
|
||||
import com.intellij.psi.PsiExpression
|
||||
import com.intellij.psi.PsiLambdaExpression
|
||||
import org.jetbrains.uast.EmptyExpression
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.ULambdaExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -27,7 +26,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaULambdaExpression(
|
||||
override val psi: PsiLambdaExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), ULambdaExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), ULambdaExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val valueParameters by lz { psi.parameterList.parameters.map { JavaConverter.convert(it, this) } }
|
||||
|
||||
override val body by lz {
|
||||
|
||||
@@ -23,11 +23,11 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaULiteralExpression(
|
||||
override val psi: PsiLiteralExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), ULiteralExpression, PsiElementBacked, JavaTypeHelper {
|
||||
override val text by lz { psi.text }
|
||||
) : JavaAbstractUElement(), ULiteralExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val asString by lz { psi.text }
|
||||
override fun evaluate() = psi.value
|
||||
override val value by lz { evaluate() }
|
||||
|
||||
override val isNull: Boolean
|
||||
get() = text == "null"
|
||||
get() = asString() == "null"
|
||||
}
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiNewExpression
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UClassNotResolved
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UObjectLiteralExpression
|
||||
@@ -24,7 +23,7 @@ import org.jetbrains.uast.UObjectLiteralExpression
|
||||
class JavaUObjectLiteralExpression(
|
||||
override val psi: PsiNewExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UObjectLiteralExpression, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UObjectLiteralExpression, JavaUElementWithType {
|
||||
override val declaration by lz {
|
||||
psi.anonymousClass?.let { JavaUClass(it, this, psi) } ?: UClassNotResolved
|
||||
}
|
||||
|
||||
+1
-1
@@ -23,6 +23,6 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUParenthesizedExpression(
|
||||
override val psi: PsiParenthesizedExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UParenthesizedExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
) : JavaAbstractUElement(), UParenthesizedExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val expression by lz { JavaConverter.convertOrEmpty(psi.expression, this) }
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUPostfixExpression(
|
||||
override val psi: PsiPostfixExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UPostfixExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
) : JavaAbstractUElement(), UPostfixExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||
|
||||
override val operator = when (psi.operationSign.text) {
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUPrefixExpression(
|
||||
override val psi: PsiPrefixExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UPrefixExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
) : JavaAbstractUElement(), UPrefixExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||
|
||||
override val operator = when (psi.operationSign.text) {
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUQualifiedExpression(
|
||||
override val psi: PsiReferenceExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UQualifiedExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UQualifiedExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val receiver by lz { JavaConverter.convertOrEmpty(psi.qualifierExpression, this) }
|
||||
override val selector by lz { JavaConverter.convert(psi.referenceNameElement, this) as? UExpression ?: EmptyExpression(this) }
|
||||
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ class JavaUSimpleReferenceExpression(
|
||||
override val psi: PsiElement,
|
||||
override val identifier: String,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override fun resolve(context: UastContext) = psi.reference?.resolve()?.let { context.convert(it) } as? UDeclaration
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class JavaClassUSimpleReferenceExpression(
|
||||
override val identifier: String,
|
||||
val ref: PsiJavaReference,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, NoEvaluate {
|
||||
) : JavaAbstractUElement(), USimpleReferenceExpression, PsiElementBacked {
|
||||
override val psi: PsiElement?
|
||||
get() = ref.element
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiSuperExpression
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.USuperExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,4 +23,4 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUSuperExpression(
|
||||
override val psi: PsiSuperExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), USuperExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate
|
||||
) : JavaAbstractUElement(), USuperExpression, PsiElementBacked, JavaUElementWithType
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiThisExpression
|
||||
import org.jetbrains.uast.NoEvaluate
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UThisExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -24,4 +23,4 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUThisExpression(
|
||||
override val psi: PsiThisExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UThisExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate
|
||||
) : JavaAbstractUElement(), UThisExpression, PsiElementBacked, JavaUElementWithType
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUTypeCastExpression(
|
||||
override val psi: PsiTypeCastExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
) : JavaAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||
override val type by lz { JavaConverter.convert(psi.castType?.type, this) }
|
||||
|
||||
|
||||
@@ -22,6 +22,6 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class UnknownJavaExpression(
|
||||
override val psi: PsiElement,
|
||||
override val parent: UElement
|
||||
) : UExpression, PsiElementBacked, NoEvaluate, LeafUElement {
|
||||
) : UExpression, PsiElementBacked, LeafUElement {
|
||||
override fun logString() = "[!] UnknownJavaExpression ($psi)"
|
||||
}
|
||||
@@ -20,13 +20,13 @@ import com.intellij.psi.PsiExpression
|
||||
import org.jetbrains.uast.UExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
interface JavaEvaluateHelper : UExpression, PsiElementBacked {
|
||||
interface JavaEvaluatableUElement : UExpression, PsiElementBacked {
|
||||
override fun evaluate(): Any? {
|
||||
val psi = this.psi ?: return null
|
||||
return JavaPsiFacade.getInstance(psi.project).constantEvaluationHelper.computeConstantExpression(psi)
|
||||
}
|
||||
}
|
||||
|
||||
interface JavaTypeHelper : UExpression, PsiElementBacked {
|
||||
interface JavaUElementWithType : UExpression, PsiElementBacked {
|
||||
override fun getExpressionType() = (psi as? PsiExpression)?.type?.let { JavaConverter.convert(it, this) }
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
class JavaUCallExpression(
|
||||
override val psi: PsiMethodCallExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val kind: UastCallKind
|
||||
get() = UastCallKind.FUNCTION_CALL
|
||||
|
||||
@@ -54,7 +54,7 @@ class JavaUCallExpression(
|
||||
class JavaConstructorUCallExpression(
|
||||
override val psi: PsiNewExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val kind by lz {
|
||||
when {
|
||||
psi.arrayInitializer != null -> JavaUastCallKinds.ARRAY_INITIALIZER
|
||||
@@ -118,7 +118,7 @@ class JavaConstructorUCallExpression(
|
||||
class JavaArrayInitializerUCallExpression(
|
||||
override val psi: PsiArrayInitializerExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val functionReference: USimpleReferenceExpression?
|
||||
get() = null
|
||||
|
||||
@@ -150,7 +150,7 @@ class JavaArrayInitializerUCallExpression(
|
||||
class JavaAnnotationArrayInitializerUCallExpression(
|
||||
override val psi: PsiArrayInitializerMemberValue,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val kind = JavaUastCallKinds.ARRAY_INITIALIZER
|
||||
|
||||
override val functionReference: USimpleReferenceExpression?
|
||||
|
||||
@@ -30,6 +30,9 @@ internal fun PsiModifierListOwner.hasModifier(modifier: UastModifier): Boolean {
|
||||
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
|
||||
}
|
||||
val javaModifier = MODIFIER_MAP[modifier] ?: return false
|
||||
return hasModifierProperty(javaModifier)
|
||||
}
|
||||
@@ -43,7 +46,7 @@ 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
|
||||
return JavaUastVisibilities.DEFAULT
|
||||
return JavaUastVisibilities.PACKAGE_LOCAL
|
||||
}
|
||||
|
||||
internal fun IElementType.getOperatorType() = when (this) {
|
||||
@@ -87,4 +90,6 @@ internal inline fun String?.orAnonymous(kind: String = ""): String {
|
||||
|
||||
internal fun <T> runReadAction(action: () -> T): T {
|
||||
return ApplicationManager.getApplication().runReadAction<T>(action)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun <T> lz(initializer: () -> T) = lazy(LazyThreadSafetyMode.NONE, initializer)
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
internal fun <T> lz(initializer: () -> T): ReadOnlyProperty<Any, T> = UnsafeLazyInsideReadAction(initializer, false)
|
||||
|
||||
private class UnsafeLazyInsideReadAction<out T>(initializer: () -> T, private val readAction: Boolean) : ReadOnlyProperty<Any, T> {
|
||||
private var initializer: (() -> T)? = initializer
|
||||
private var _value: Any? = UNINITIALIZED_VALUE
|
||||
|
||||
override fun getValue(thisRef: Any, property: KProperty<*>): T {
|
||||
if (_value === UNINITIALIZED_VALUE) {
|
||||
if (readAction) {
|
||||
_value = runReadAction { initializer!!() }
|
||||
}
|
||||
else {
|
||||
_value = initializer!!()
|
||||
}
|
||||
initializer = null
|
||||
}
|
||||
return _value as T
|
||||
}
|
||||
}
|
||||
|
||||
private object UNINITIALIZED_VALUE
|
||||
@@ -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.UastModifier
|
||||
|
||||
object JavaUastModifiers {
|
||||
@JvmField
|
||||
val INITIALIZER = UastModifier("static")
|
||||
}
|
||||
@@ -19,8 +19,5 @@ import org.jetbrains.uast.UastVisibility
|
||||
|
||||
object JavaUastVisibilities {
|
||||
@JvmField
|
||||
val DEFAULT = UastVisibility("default")
|
||||
|
||||
@JvmField
|
||||
val INSTANCE = UastVisibility("instance")
|
||||
val PACKAGE_LOCAL = UastVisibility("package_local")
|
||||
}
|
||||
@@ -17,7 +17,11 @@
|
||||
package org.jetbrains.uast.psi
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.uast.UElement
|
||||
|
||||
interface PsiElementBacked {
|
||||
interface PsiElementBacked : UElement {
|
||||
val psi: PsiElement?
|
||||
|
||||
override val isValid: Boolean
|
||||
get() = psi?.isValid ?: true
|
||||
}
|
||||
Reference in New Issue
Block a user