Other code review changes
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.java.expressions.JavaUSynchronizedExpression
|
||||
|
||||
object JavaUastLanguagePlugin : UastLanguagePlugin {
|
||||
override val converter: UastConverter = JavaConverter
|
||||
@@ -45,8 +46,6 @@ internal object JavaConverter : UastConverter {
|
||||
return convertPsiElement(element, parentUElement)
|
||||
}
|
||||
|
||||
fun convertAnnotation(annotation: PsiAnnotation) = convertWithParent(annotation) as UAnnotation
|
||||
|
||||
private fun convertPsiElement(element: PsiElement?, parent: UElement) = when (element) {
|
||||
is PsiJavaFile -> JavaUFile(element)
|
||||
is PsiClass -> JavaUClass(element, parent)
|
||||
@@ -115,7 +114,7 @@ internal object JavaConverter : UastConverter {
|
||||
val referenceNameElement = expression.element ?: expression
|
||||
|
||||
return JavaUCompositeQualifiedExpression(parent).apply {
|
||||
receiver = expression.qualifier?.let { convert(it, this) } as? UExpression ?: EmptyExpression(parent)
|
||||
receiver = expression.qualifier?.let { convert(it, this) } as? UExpression ?: EmptyUExpression(parent)
|
||||
selector = JavaUSimpleReferenceExpression(referenceNameElement, referenceName, this)
|
||||
}
|
||||
}
|
||||
@@ -185,42 +184,30 @@ internal object JavaConverter : UastConverter {
|
||||
is PsiSwitchStatement -> JavaUSwitchExpression(statement, parent)
|
||||
is PsiSwitchLabelStatement -> {
|
||||
if (statement.isDefaultCase)
|
||||
SimpleUDefaultSwitchClauseExpression(parent)
|
||||
else JavaUExpressionSwitchClauseExpression(statement, parent)
|
||||
DefaultUSwitchClauseExpression(parent)
|
||||
else JavaUCaseSwitchClauseExpression(statement, parent)
|
||||
}
|
||||
is PsiWhileStatement -> JavaUWhileExpression(statement, parent)
|
||||
is PsiDoWhileStatement -> JavaUDoWhileExpression(statement, parent)
|
||||
is PsiForStatement -> JavaUForExpression(statement, parent)
|
||||
is PsiForeachStatement -> JavaUForEachExpression(statement, parent)
|
||||
is PsiBreakStatement -> JavaUSpecialExpressionList.Empty(statement, UastSpecialExpressionKind.BREAK, parent)
|
||||
is PsiContinueStatement -> JavaUSpecialExpressionList.Empty(statement, UastSpecialExpressionKind.CONTINUE, parent)
|
||||
is PsiReturnStatement -> JavaUSpecialExpressionList(statement, UastSpecialExpressionKind.RETURN, parent).apply {
|
||||
expressions = singletonListOrEmpty(convertOrNull(statement.returnValue, this))
|
||||
}
|
||||
is PsiAssertStatement -> JavaUSpecialExpressionList(statement, JavaSpecialExpressionKinds.ASSERT, parent).apply {
|
||||
expressions = listOf(
|
||||
convertOrEmpty(statement.assertCondition, this),
|
||||
convertOrEmpty(statement.assertDescription, this))
|
||||
}
|
||||
is PsiThrowStatement -> JavaUSpecialExpressionList(statement, UastSpecialExpressionKind.THROW, parent).apply {
|
||||
expressions = singletonListOrEmpty(convertOrNull(statement.exception, this))
|
||||
}
|
||||
is PsiSynchronizedStatement -> JavaUSpecialExpressionList(statement, JavaSpecialExpressionKinds.SYNCHRONIZED, parent).apply {
|
||||
expressions = listOf(
|
||||
convertOrEmpty(statement.lockExpression, this),
|
||||
convertOrEmpty(statement.body, this))
|
||||
}
|
||||
is PsiBreakStatement -> JavaUBreakExpression(statement, parent)
|
||||
is PsiContinueStatement -> JavaUContinueExpression(statement, parent)
|
||||
is PsiReturnStatement -> JavaUReturnExpression(statement, parent)
|
||||
is PsiAssertStatement -> JavaUAssertExpression(statement, parent)
|
||||
is PsiThrowStatement -> JavaUThrowExpression(statement, parent)
|
||||
is PsiSynchronizedStatement -> JavaUSynchronizedExpression(statement, parent)
|
||||
is PsiTryStatement -> JavaUTryExpression(statement, parent)
|
||||
|
||||
else -> UnknownJavaExpression(statement, parent)
|
||||
}
|
||||
|
||||
internal fun convertOrEmpty(statement: PsiStatement?, parent: UElement): UExpression {
|
||||
return if (statement != null) convert(statement, parent) else EmptyExpression(parent)
|
||||
return if (statement != null) convert(statement, parent) else EmptyUExpression(parent)
|
||||
}
|
||||
|
||||
internal fun convertOrEmpty(expression: PsiExpression?, parent: UElement): UExpression {
|
||||
return if (expression != null) convert(expression, parent) else EmptyExpression(parent)
|
||||
return if (expression != null) convert(expression, parent) else EmptyUExpression(parent)
|
||||
}
|
||||
|
||||
internal fun convertOrNull(expression: PsiExpression?, parent: UElement): UExpression? {
|
||||
@@ -228,7 +215,7 @@ internal object JavaConverter : UastConverter {
|
||||
}
|
||||
|
||||
internal fun convertOrEmpty(block: PsiCodeBlock?, parent: UElement): UExpression {
|
||||
return if (block != null) convert(block, parent) else EmptyExpression(parent)
|
||||
return if (block != null) convert(block, parent) else EmptyUExpression(parent)
|
||||
}
|
||||
|
||||
private fun convertDeclarations(elements: Array<out PsiElement>, parent: UElement): SimpleUDeclarationsExpression {
|
||||
|
||||
+15
-6
@@ -17,9 +17,7 @@ package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiSwitchLabelStatement
|
||||
import com.intellij.psi.PsiSwitchStatement
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UExpressionSwitchClauseExpression
|
||||
import org.jetbrains.uast.USwitchExpression
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUSwitchExpression(
|
||||
@@ -30,9 +28,20 @@ class JavaUSwitchExpression(
|
||||
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||
}
|
||||
|
||||
class JavaUExpressionSwitchClauseExpression(
|
||||
class JavaUCaseSwitchClauseExpression(
|
||||
override val psi: PsiSwitchLabelStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UExpressionSwitchClauseExpression, PsiElementBacked {
|
||||
override val caseValue by lz { JavaConverter.convertOrEmpty(psi.caseValue, this) }
|
||||
) : JavaAbstractUElement(), USwitchClauseExpression, PsiElementBacked {
|
||||
override val caseValues by lz {
|
||||
val value = psi.caseValue ?: return@lz null
|
||||
listOf(JavaConverter.convert(value, this))
|
||||
}
|
||||
}
|
||||
|
||||
class DefaultUSwitchClauseExpression(override val parent: UElement) : USwitchClauseExpression {
|
||||
override val caseValues: List<UExpression>?
|
||||
get() = null
|
||||
|
||||
override fun logString() = "DefaultUSwitchClauseExpression"
|
||||
override fun renderString() = "else -> "
|
||||
}
|
||||
+9
-2
@@ -16,15 +16,21 @@
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiClassInitializer
|
||||
import com.intellij.psi.PsiModifier
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaClassInitializerUFunction(
|
||||
override val psi: PsiClassInitializer,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UFunction, PsiElementBacked, NoAnnotations, NoModifiers {
|
||||
) : JavaAbstractUElement(), UFunction, PsiElementBacked, NoAnnotations {
|
||||
override val kind: UastFunctionKind.UastInitializerKind
|
||||
get() = JavaFunctionKinds.STATIC_INITIALIZER
|
||||
get() {
|
||||
return if (psi.hasModifierProperty(PsiModifier.STATIC))
|
||||
JavaFunctionKinds.STATIC_INITIALIZER
|
||||
else
|
||||
JavaFunctionKinds.INSTANCE_INITIALIZER
|
||||
}
|
||||
|
||||
override val valueParameters: List<UVariable>
|
||||
get() = emptyList()
|
||||
@@ -53,4 +59,5 @@ class JavaClassInitializerUFunction(
|
||||
get() = "<static>"
|
||||
|
||||
override fun getSuperFunctions(context: UastContext) = emptyList<UFunction>()
|
||||
override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier)
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUAnnotation(
|
||||
override val psi: PsiAnnotation,
|
||||
override val parent: UElement?
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UAnnotation, PsiElementBacked {
|
||||
override val name: String
|
||||
get() = psi.nameReferenceElement?.referenceName.orAnonymous()
|
||||
|
||||
@@ -21,13 +21,11 @@ import com.intellij.psi.util.ClassUtil
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.util.PsiTypesUtil
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.kinds.UastClassKind
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import java.util.*
|
||||
|
||||
class JavaUClass(
|
||||
override val psi: PsiClass,
|
||||
override val parent: UElement?,
|
||||
override val parent: UElement,
|
||||
val newExpression: PsiNewExpression? = null
|
||||
) : JavaAbstractUElement(), UClass, PsiElementBacked {
|
||||
override val name: String
|
||||
@@ -79,27 +77,19 @@ class JavaUClass(
|
||||
override val declarations by lz {
|
||||
val declarations = arrayListOf<UDeclaration>()
|
||||
psi.fields.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
psi.constructors.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
|
||||
if (psi is PsiAnonymousClass && newExpression != null) {
|
||||
declarations += JavaUAnonymousClassConstructor(psi, newExpression, this)
|
||||
}
|
||||
|
||||
psi.methods.filter { !it.isConstructor }.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
psi.interfaces.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
psi.methods.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
psi.innerClasses.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
psi.initializers.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||
declarations
|
||||
}
|
||||
|
||||
override fun isSubclassOf(fqName: String): Boolean {
|
||||
tailrec fun isSubClassOf(clazz: PsiClass?, name: String): Boolean = when {
|
||||
clazz == null -> false
|
||||
clazz.qualifiedName == name -> true
|
||||
else -> isSubClassOf(clazz.superClass, name)
|
||||
}
|
||||
|
||||
return isSubClassOf(psi, fqName)
|
||||
return psi.supers.any { base -> psi.isInheritor(base, false) }
|
||||
}
|
||||
|
||||
private companion object {
|
||||
@@ -179,7 +169,8 @@ private class JavaUAnonymousClassConstructor(
|
||||
override val returnType: UType?
|
||||
get() = null
|
||||
|
||||
override val body = EmptyExpression(this)
|
||||
override val body: UExpression?
|
||||
get() = null
|
||||
|
||||
override val visibility: UastVisibility
|
||||
get() = UastVisibility.LOCAL
|
||||
|
||||
@@ -57,7 +57,7 @@ class JavaUFunction(
|
||||
override val visibility: UastVisibility
|
||||
get() = psi.getVisibility()
|
||||
|
||||
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||
override val body by lz { psi.body?.let { JavaConverter.convert(it, this) } }
|
||||
|
||||
override val bytecodeDescriptor by lz { getDescriptor(psi) }
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ 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
|
||||
|
||||
class JavaUImportStatement(
|
||||
@@ -30,9 +29,6 @@ class JavaUImportStatement(
|
||||
override val fqNameToImport: String?
|
||||
get() = psi.qualifiedName
|
||||
|
||||
override val kind: UastImportKind
|
||||
get() = UastImportKind.CLASS
|
||||
|
||||
override val isStarImport: Boolean
|
||||
get() = psi.isOnDemand
|
||||
|
||||
|
||||
-4
@@ -20,7 +20,6 @@ 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
|
||||
|
||||
class JavaUStaticImportStatement(
|
||||
@@ -30,9 +29,6 @@ class JavaUStaticImportStatement(
|
||||
override val fqNameToImport: String?
|
||||
get() = psi.referenceName
|
||||
|
||||
override val kind: UastImportKind
|
||||
get() = UastImportKind.MEMBER
|
||||
|
||||
override val isStarImport: Boolean
|
||||
get() = psi.isOnDemand
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ class JavaUType(
|
||||
override val isLong: Boolean
|
||||
get() = check("long", "java.lang.Long")
|
||||
|
||||
override val isShort: Boolean
|
||||
get() = check("short", "java.lang.Short")
|
||||
|
||||
override val isFloat: Boolean
|
||||
get() = check("float", "java.lang.Float")
|
||||
|
||||
@@ -59,6 +62,7 @@ class JavaUType(
|
||||
override val isByte: Boolean
|
||||
get() = check("byte", "java.lang.Byte")
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
private inline fun check(unboxedType: String, boxedType: String): Boolean =
|
||||
name == unboxedType || (psi as? PsiClassType)?.resolve()?.qualifiedName == boxedType
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiAssertStatement
|
||||
import org.jetbrains.uast.*
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUAssertExpression(
|
||||
override val psi: PsiAssertStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked {
|
||||
val condition: UExpression by lz { JavaConverter.convertOrEmpty(psi.assertCondition, this) }
|
||||
val message: UExpression? by lz { JavaConverter.convertOrNull(psi.assertDescription, this) }
|
||||
|
||||
override val functionReference: USimpleReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val classReference: USimpleReferenceExpression?
|
||||
get() = null
|
||||
|
||||
override val functionName: String?
|
||||
get() = "<assert>"
|
||||
|
||||
override val functionNameElement: UElement?
|
||||
get() = null
|
||||
|
||||
override val valueArgumentCount: Int
|
||||
get() = if (message != null) 2 else 1
|
||||
|
||||
override val valueArguments by lz {
|
||||
val message = this.message
|
||||
if (message != null) listOf(condition, message) else listOf(condition)
|
||||
}
|
||||
|
||||
override val typeArgumentCount: Int
|
||||
get() = 0
|
||||
override val typeArguments: List<UType>
|
||||
get() = emptyList()
|
||||
|
||||
override val kind: UastCallKind
|
||||
get() = JavaUastCallKinds.ASSERT
|
||||
|
||||
override fun resolve(context: UastContext) = null
|
||||
}
|
||||
+1
-5
@@ -18,7 +18,6 @@ package org.jetbrains.uast.java
|
||||
import com.intellij.psi.PsiAssignmentExpression
|
||||
import org.jetbrains.uast.UBinaryExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UastBinaryOperator
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUAssignmentExpression(
|
||||
@@ -26,9 +25,6 @@ class JavaUAssignmentExpression(
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val leftOperand by lz { JavaConverter.convert(psi.lExpression, this) }
|
||||
|
||||
override val operator: UastBinaryOperator
|
||||
get() = UastBinaryOperator.ASSIGN
|
||||
|
||||
override val rightOperand by lz { JavaConverter.convertOrEmpty(psi.rExpression, this) }
|
||||
override val operator by lz { psi.operationTokenType.getOperatorType() }
|
||||
}
|
||||
+12
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,14 +13,18 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import org.jetbrains.uast.UastSpecialExpressionKind
|
||||
import com.intellij.psi.PsiBreakStatement
|
||||
import org.jetbrains.uast.UBreakExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
object JavaSpecialExpressionKinds {
|
||||
@JvmField
|
||||
val ASSERT = UastSpecialExpressionKind("assert")
|
||||
|
||||
@JvmField
|
||||
val SYNCHRONIZED = UastSpecialExpressionKind("synchronized")
|
||||
class JavaUBreakExpression(
|
||||
override val psi: PsiBreakStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBreakExpression, PsiElementBacked {
|
||||
override val label: String?
|
||||
get() = psi.labelIdentifier?.text
|
||||
}
|
||||
+7
@@ -17,12 +17,19 @@ package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiMethodReferenceExpression
|
||||
import org.jetbrains.uast.UCallableReferenceExpression
|
||||
import org.jetbrains.uast.UDeclaration
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UastContext
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUCallableReferenceExpression(
|
||||
override val psi: PsiMethodReferenceExpression,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallableReferenceExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val qualifierExpression by lz { JavaConverter.convertOrNull(psi.qualifierExpression, this) }
|
||||
override val qualifierType by lz { JavaConverter.convert(psi.qualifierType?.type, this) }
|
||||
override val callableName: String
|
||||
get() = psi.referenceName.orAnonymous()
|
||||
|
||||
override fun resolve(context: UastContext) = context.convert(psi.resolve()) as? UDeclaration
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiContinueStatement
|
||||
import org.jetbrains.uast.UContinueExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUContinueExpression(
|
||||
override val psi: PsiContinueStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UContinueExpression, PsiElementBacked {
|
||||
override val label: String?
|
||||
get() = psi.labelIdentifier?.text
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.uast.java
|
||||
import com.intellij.psi.PsiCodeBlock
|
||||
import com.intellij.psi.PsiExpression
|
||||
import com.intellij.psi.PsiLambdaExpression
|
||||
import org.jetbrains.uast.EmptyExpression
|
||||
import org.jetbrains.uast.EmptyUExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.ULambdaExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
@@ -34,7 +34,7 @@ class JavaULambdaExpression(
|
||||
when (b) {
|
||||
is PsiCodeBlock -> JavaConverter.convert(b, this)
|
||||
is PsiExpression -> JavaConverter.convert(b, this)
|
||||
else -> EmptyExpression(this)
|
||||
else -> EmptyUExpression(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiKeyword
|
||||
import com.intellij.psi.PsiLiteralExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.ULiteralExpression
|
||||
@@ -29,5 +30,5 @@ class JavaULiteralExpression(
|
||||
override val value by lz { evaluate() }
|
||||
|
||||
override val isNull: Boolean
|
||||
get() = asString() == "null"
|
||||
get() = asString() == PsiKeyword.NULL
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.JavaTokenType
|
||||
import com.intellij.psi.PsiPostfixExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UPostfixExpression
|
||||
@@ -27,9 +28,9 @@ class JavaUPostfixExpression(
|
||||
) : JavaAbstractUElement(), UPostfixExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||
|
||||
override val operator = when (psi.operationSign.text) {
|
||||
"++" -> UastPostfixOperator.INC
|
||||
"--" -> UastPostfixOperator.DEC
|
||||
override val operator = when (psi.operationSign) {
|
||||
JavaTokenType.PLUSPLUS -> UastPostfixOperator.INC
|
||||
JavaTokenType.MINUSMINUS -> UastPostfixOperator.DEC
|
||||
else -> UastPostfixOperator.UNKNOWN
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.JavaTokenType
|
||||
import com.intellij.psi.PsiPrefixExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UPrefixExpression
|
||||
@@ -27,13 +28,13 @@ class JavaUPrefixExpression(
|
||||
) : JavaAbstractUElement(), UPrefixExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||
|
||||
override val operator = when (psi.operationSign.text) {
|
||||
"+" -> UastPrefixOperator.UNARY_PLUS
|
||||
"-" -> UastPrefixOperator.UNARY_MINUS
|
||||
"++" -> UastPrefixOperator.INC
|
||||
"--" -> UastPrefixOperator.DEC
|
||||
"!" -> UastPrefixOperator.LOGICAL_NOT
|
||||
"~" -> UastPrefixOperator.BITWISE_NOT
|
||||
override val operator = when (psi.operationSign) {
|
||||
JavaTokenType.PLUS -> UastPrefixOperator.UNARY_PLUS
|
||||
JavaTokenType.MINUS -> UastPrefixOperator.UNARY_MINUS
|
||||
JavaTokenType.PLUSPLUS -> UastPrefixOperator.INC
|
||||
JavaTokenType.MINUSMINUS-> UastPrefixOperator.DEC
|
||||
JavaTokenType.EXCL -> UastPrefixOperator.LOGICAL_NOT
|
||||
JavaTokenType.TILDE -> UastPrefixOperator.BITWISE_NOT
|
||||
else -> UastPrefixOperator.UNKNOWN
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -24,7 +24,7 @@ class JavaUQualifiedExpression(
|
||||
override val parent: UElement
|
||||
) : 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) }
|
||||
override val selector by lz { JavaConverter.convert(psi.referenceNameElement, this) as? UExpression ?: EmptyUExpression(this) }
|
||||
|
||||
override val accessType: UastQualifiedExpressionAccessType
|
||||
get() = UastQualifiedExpressionAccessType.SIMPLE
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiReturnStatement
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UReturnExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUReturnExpression(
|
||||
override val psi: PsiReturnStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UReturnExpression, PsiElementBacked {
|
||||
override val returnExpression by lz { JavaConverter.convertOrNull(psi.returnValue, this) }
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.uast.java.expressions
|
||||
|
||||
import com.intellij.psi.PsiSynchronizedStatement
|
||||
import org.jetbrains.uast.UBlockExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.acceptList
|
||||
import org.jetbrains.uast.java.JavaAbstractUElement
|
||||
import org.jetbrains.uast.java.JavaConverter
|
||||
import org.jetbrains.uast.java.JavaUElementWithType
|
||||
import org.jetbrains.uast.java.lz
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
import org.jetbrains.uast.visitor.UastVisitor
|
||||
|
||||
class JavaUSynchronizedExpression(
|
||||
override val psi: PsiSynchronizedStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val expressions by lz { psi.body?.statements?.map { JavaConverter.convert(it, this) } ?: listOf() }
|
||||
val lockExpression by lz { JavaConverter.convertOrEmpty(psi.lockExpression, this) }
|
||||
|
||||
override fun accept(visitor: UastVisitor) {
|
||||
if (visitor.visitBlockExpression(this)) return
|
||||
psi.lockExpression
|
||||
expressions.acceptList(visitor)
|
||||
lockExpression.accept(visitor)
|
||||
visitor.afterVisitBlockExpression(this)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.uast.java
|
||||
|
||||
import com.intellij.psi.PsiThrowStatement
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.UThrowExpression
|
||||
import org.jetbrains.uast.psi.PsiElementBacked
|
||||
|
||||
class JavaUThrowExpression(
|
||||
override val psi: PsiThrowStatement,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UThrowExpression, PsiElementBacked {
|
||||
override val thrownExpression by lz { JavaConverter.convertOrEmpty(psi.exception, this) }
|
||||
}
|
||||
@@ -57,8 +57,8 @@ class JavaConstructorUCallExpression(
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType {
|
||||
override val kind by lz {
|
||||
when {
|
||||
psi.arrayInitializer != null -> JavaUastCallKinds.ARRAY_INITIALIZER
|
||||
psi.arrayDimensions.isNotEmpty() -> JavaUastCallKinds.ARRAY_DIMENSIONS
|
||||
psi.arrayInitializer != null -> JavaUastCallKinds.NEW_ARRAY_WITH_INITIALIZER
|
||||
psi.arrayDimensions.isNotEmpty() -> JavaUastCallKinds.NEW_ARRAY_DIMENTIONS
|
||||
else -> UastCallKind.CONSTRUCTOR_CALL
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ class JavaConstructorUCallExpression(
|
||||
get() {
|
||||
val initializer = psi.arrayInitializer
|
||||
return if (initializer != null)
|
||||
"<newArray>"
|
||||
"<newArrayWithInitializer>"
|
||||
else if (psi.arrayDimensions.isNotEmpty())
|
||||
"<newArrayWithDimensions>"
|
||||
else null
|
||||
@@ -141,7 +141,7 @@ class JavaArrayInitializerUCallExpression(
|
||||
get() = emptyList()
|
||||
|
||||
override val kind: UastCallKind
|
||||
get() = JavaUastCallKinds.ARRAY_INITIALIZER
|
||||
get() = UastCallKind.ARRAY_INITIALIZER
|
||||
|
||||
override fun resolve(context: UastContext) = null
|
||||
}
|
||||
@@ -150,7 +150,8 @@ class JavaAnnotationArrayInitializerUCallExpression(
|
||||
override val psi: PsiArrayInitializerMemberValue,
|
||||
override val parent: UElement
|
||||
) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement {
|
||||
override val kind = JavaUastCallKinds.ARRAY_INITIALIZER
|
||||
override val kind: UastCallKind
|
||||
get() = UastCallKind.ARRAY_INITIALIZER
|
||||
|
||||
override val functionReference: USimpleReferenceExpression?
|
||||
get() = null
|
||||
|
||||
@@ -33,6 +33,12 @@ internal fun PsiModifierListOwner.hasModifier(modifier: UastModifier): Boolean {
|
||||
if (modifier == UastModifier.VARARG && this is PsiParameter) {
|
||||
return this.isVarArgs
|
||||
}
|
||||
if (modifier == UastModifier.IMMUTABLE && this is PsiVariable) {
|
||||
return this.hasModifierProperty(PsiModifier.FINAL)
|
||||
}
|
||||
if (modifier == UastModifier.FINAL && this is PsiVariable) {
|
||||
return false;
|
||||
}
|
||||
val javaModifier = MODIFIER_MAP[modifier] ?: return false
|
||||
return hasModifierProperty(javaModifier)
|
||||
}
|
||||
@@ -58,7 +64,6 @@ internal fun IElementType.getOperatorType() = when (this) {
|
||||
JavaTokenType.PERC -> UastBinaryOperator.MOD
|
||||
JavaTokenType.OR -> UastBinaryOperator.BITWISE_OR
|
||||
JavaTokenType.AND -> UastBinaryOperator.BITWISE_AND
|
||||
JavaTokenType.TILDE -> UastBinaryOperator.BITWISE_XOR
|
||||
JavaTokenType.EQEQ -> UastBinaryOperator.IDENTITY_EQUALS
|
||||
JavaTokenType.NE -> UastBinaryOperator.IDENTITY_NOT_EQUALS
|
||||
JavaTokenType.GT -> UastBinaryOperator.GREATER
|
||||
@@ -72,6 +77,7 @@ internal fun IElementType.getOperatorType() = when (this) {
|
||||
JavaTokenType.MINUSEQ -> UastBinaryOperator.MINUS_ASSIGN
|
||||
JavaTokenType.ASTERISKEQ -> UastBinaryOperator.MULTIPLY_ASSIGN
|
||||
JavaTokenType.DIVEQ -> UastBinaryOperator.DIVIDE_ASSIGN
|
||||
JavaTokenType.PERCEQ -> UastBinaryOperator.REMAINDER_ASSIGN
|
||||
JavaTokenType.ANDEQ -> UastBinaryOperator.AND_ASSIGN
|
||||
JavaTokenType.XOREQ -> UastBinaryOperator.XOR_ASSIGN
|
||||
JavaTokenType.OREQ -> UastBinaryOperator.OR_ASSIGN
|
||||
|
||||
@@ -19,5 +19,6 @@ package org.jetbrains.uast.java
|
||||
import org.jetbrains.uast.UastFunctionKind
|
||||
|
||||
object JavaFunctionKinds {
|
||||
val INSTANCE_INITIALIZER = UastFunctionKind.UastInitializerKind("<instance>")
|
||||
val STATIC_INITIALIZER = UastFunctionKind.UastInitializerKind("<static>")
|
||||
}
|
||||
@@ -19,8 +19,11 @@ import org.jetbrains.uast.UastCallKind
|
||||
|
||||
object JavaUastCallKinds {
|
||||
@JvmField
|
||||
val ARRAY_INITIALIZER = UastCallKind("array_initializer")
|
||||
val NEW_ARRAY_WITH_INITIALIZER = UastCallKind("new_array_with_initializer")
|
||||
|
||||
@JvmField
|
||||
val ARRAY_DIMENSIONS = UastCallKind("array_dimensions")
|
||||
val NEW_ARRAY_DIMENTIONS = UastCallKind("new_array_dimensions")
|
||||
|
||||
@JvmField
|
||||
val ASSERT = UastCallKind("assert")
|
||||
}
|
||||
Reference in New Issue
Block a user