Java Uast: Initial implementation
This commit is contained in:
@@ -0,0 +1,236 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
|
||||||
|
object JavaConverter : UastConverter {
|
||||||
|
override fun isFileSupported(path: String): Boolean {
|
||||||
|
return path.endsWith(".java", ignoreCase = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun convert(file: PsiJavaFile): UFile = JavaUFile(file)
|
||||||
|
|
||||||
|
override fun convert(element: Any?, parent: UElement): UElement? {
|
||||||
|
if (element !is PsiElement) return null
|
||||||
|
return convertPsiElement(element, parent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun convertWithParent(element: Any?): UElement? {
|
||||||
|
if (element !is PsiElement) return null
|
||||||
|
if (element is PsiJavaFile) return JavaUFile(element)
|
||||||
|
|
||||||
|
val parent = element.parent ?: return null
|
||||||
|
val parentUElement = convertWithParent(parent) ?: return null
|
||||||
|
return convertPsiElement(element, parentUElement)
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
is PsiCodeBlock -> convert(element, parent)
|
||||||
|
is PsiMethod -> convert(element, parent)
|
||||||
|
is PsiField -> convert(element, parent)
|
||||||
|
is PsiVariable -> convert(element, parent)
|
||||||
|
is PsiClassInitializer -> convert(element, parent)
|
||||||
|
is PsiAnnotation -> convert(element, parent)
|
||||||
|
is PsiExpression -> convert(element, parent)
|
||||||
|
is PsiStatement -> convert(element, parent)
|
||||||
|
is PsiIdentifier -> JavaUSimpleReferenceExpression(element, element.text, parent)
|
||||||
|
is PsiImportStatementBase -> convert(element, parent)
|
||||||
|
is PsiParameter -> convert(element, parent)
|
||||||
|
is PsiTypeParameter -> convert(element, parent)
|
||||||
|
is PsiNameValuePair -> convert(element, parent)
|
||||||
|
is PsiType -> convert(element, parent)
|
||||||
|
is PsiArrayInitializerMemberValue -> JavaAnnotationArrayInitializerUCallExpression(element, parent)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun convert(importStatement: PsiImportStatementBase, parent: UElement): UImportStatement? = when (importStatement) {
|
||||||
|
is PsiImportStatement -> JavaUImportStatement(importStatement, parent)
|
||||||
|
is PsiImportStaticStatement -> JavaUStaticImportStatement(importStatement, parent)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun convert(type: PsiType?, parent: UElement) = JavaUType(type, parent)
|
||||||
|
|
||||||
|
internal fun convert(parameter: PsiParameter, parent: UElement) = JavaValueParameterUVariable(parameter, parent)
|
||||||
|
|
||||||
|
internal fun convert(block: PsiCodeBlock, parent: UElement) = JavaUCodeBlockExpression(block, parent)
|
||||||
|
|
||||||
|
internal fun convert(method: PsiMethod, parent: UElement) = JavaUFunction(method, parent)
|
||||||
|
|
||||||
|
internal fun convert(field: PsiField, parent: UElement) = JavaUVariable(field, parent)
|
||||||
|
|
||||||
|
internal fun convert(variable: PsiVariable, parent: UElement) = JavaUVariable(variable, parent)
|
||||||
|
|
||||||
|
internal fun convert(annotation: PsiAnnotation, parent: UElement) = JavaUAnnotation(annotation, parent)
|
||||||
|
|
||||||
|
internal fun convert(clazz: PsiClass, parent: UElement) = JavaUClass(clazz, parent)
|
||||||
|
|
||||||
|
internal fun convert(initializer: PsiClassInitializer, parent: UElement) = JavaClassInitializerUFunction(initializer, parent)
|
||||||
|
|
||||||
|
internal fun convert(parameter: PsiTypeParameter, parent: UElement) = JavaParameterUTypeReference(parameter, parent)
|
||||||
|
|
||||||
|
internal fun convert(pair: PsiNameValuePair, parent: UElement) = UNamedExpression(pair.name.orAnonymous(), parent).apply {
|
||||||
|
val value = pair.value
|
||||||
|
expression = convert(value, this) as? UExpression ?: UnknownJavaExpression(value ?: pair, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun convert(expression: PsiReferenceExpression, parent: UElement): UExpression {
|
||||||
|
return if (expression.isQualified) {
|
||||||
|
JavaUQualifiedExpression(expression, parent)
|
||||||
|
} else {
|
||||||
|
val name = expression.referenceName ?: "<error name>"
|
||||||
|
val element = expression.referenceNameElement ?: expression
|
||||||
|
JavaUSimpleReferenceExpression(element, name, parent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun convert(expression: PsiQualifiedReferenceElement, parent: UElement): UExpression {
|
||||||
|
val referenceName = expression.referenceName ?: "<error name>"
|
||||||
|
val referenceNameElement = expression.element ?: expression
|
||||||
|
|
||||||
|
return JavaUCompositeQualifiedExpression(parent).apply {
|
||||||
|
receiver = expression.qualifier?.let { convert(it, this) } as? UExpression ?: EmptyExpression(parent)
|
||||||
|
selector = JavaUSimpleReferenceExpression(referenceNameElement, referenceName, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun convertPolyadicExpression(
|
||||||
|
expression: PsiPolyadicExpression,
|
||||||
|
parent: UElement,
|
||||||
|
i: Int
|
||||||
|
): UExpression {
|
||||||
|
return if (i == 1) JavaCombinedUBinaryExpression(expression, parent).apply {
|
||||||
|
leftOperand = convert(expression.operands[0], this)
|
||||||
|
rightOperand = convert(expression.operands[1], this)
|
||||||
|
} else JavaCombinedUBinaryExpression(expression, parent).apply {
|
||||||
|
leftOperand = convertPolyadicExpression(expression, parent, i - 1)
|
||||||
|
rightOperand = convert(expression.operands[i], this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun convert(expression: PsiExpression, parent: UElement): UExpression = when (expression) {
|
||||||
|
is PsiPolyadicExpression -> convertPolyadicExpression(expression, parent, expression.operands.size - 1)
|
||||||
|
is PsiAssignmentExpression -> JavaUAssignmentExpression(expression, parent)
|
||||||
|
is PsiConditionalExpression -> JavaUTernaryIfExpression(expression, parent)
|
||||||
|
is PsiNewExpression -> {
|
||||||
|
if (expression.anonymousClass != null) {
|
||||||
|
JavaUObjectLiteralExpression(expression, parent)
|
||||||
|
} else {
|
||||||
|
JavaConstructorUCallExpression(expression, parent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is PsiMethodCallExpression -> {
|
||||||
|
val qualifier = expression.methodExpression.qualifierExpression
|
||||||
|
if (qualifier != null) {
|
||||||
|
JavaUCompositeQualifiedExpression(parent).apply {
|
||||||
|
receiver = convert(qualifier, this)
|
||||||
|
selector = JavaUCallExpression(expression, this)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
JavaUCallExpression(expression, parent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is PsiArrayInitializerExpression -> JavaArrayInitializerUCallExpression(expression, parent)
|
||||||
|
is PsiBinaryExpression -> JavaUBinaryExpression(expression, parent)
|
||||||
|
is PsiParenthesizedExpression -> JavaUParenthesizedExpression(expression, parent)
|
||||||
|
is PsiPrefixExpression -> JavaUPrefixExpression(expression, parent)
|
||||||
|
is PsiPostfixExpression -> JavaUPostfixExpression(expression, parent)
|
||||||
|
is PsiLiteralExpression -> JavaULiteralExpression(expression, parent)
|
||||||
|
is PsiReferenceExpression -> convert(expression, parent)
|
||||||
|
is PsiThisExpression -> JavaUThisExpression(expression, parent)
|
||||||
|
is PsiSuperExpression -> JavaUSuperExpression(expression, parent)
|
||||||
|
is PsiInstanceOfExpression -> JavaUInstanceCheckExpression(expression, parent)
|
||||||
|
is PsiTypeCastExpression -> JavaUTypeCastExpression(expression, parent)
|
||||||
|
is PsiClassObjectAccessExpression -> JavaUClassLiteralExpression(expression, parent)
|
||||||
|
is PsiArrayAccessExpression -> JavaUArrayAccessExpression(expression, parent)
|
||||||
|
is PsiLambdaExpression -> JavaULambdaExpression(expression, parent)
|
||||||
|
is PsiMethodReferenceExpression -> JavaUCallableReferenceExpression(expression, parent)
|
||||||
|
|
||||||
|
else -> UnknownJavaExpression(expression, parent)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun convert(statement: PsiStatement, parent: UElement): UExpression = when (statement) {
|
||||||
|
is PsiDeclarationStatement -> convertDeclarations(statement.declaredElements, parent)
|
||||||
|
is PsiExpressionListStatement -> convertDeclarations(statement.expressionList.expressions, parent)
|
||||||
|
is PsiBlockStatement -> JavaUBlockExpression(statement, parent)
|
||||||
|
is PsiLabeledStatement -> JavaULabeledExpression(statement, parent)
|
||||||
|
is PsiExpressionStatement -> convert(statement.expression, parent)
|
||||||
|
is PsiIfStatement -> JavaUIfExpression(statement, parent)
|
||||||
|
is PsiSwitchStatement -> JavaUSwitchExpression(statement, parent)
|
||||||
|
is PsiSwitchLabelStatement -> {
|
||||||
|
if (statement.isDefaultCase)
|
||||||
|
SimpleUDefaultSwitchClauseExpression(parent)
|
||||||
|
else JavaUExpressionSwitchClauseExpression(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 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun convertOrEmpty(expression: PsiExpression?, parent: UElement): UExpression {
|
||||||
|
return if (expression != null) convert(expression, parent) else EmptyExpression(parent)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun convertOrNull(expression: PsiExpression?, parent: UElement): UExpression? {
|
||||||
|
return if (expression != null) convert(expression, parent) else null
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun convertOrEmpty(block: PsiCodeBlock?, parent: UElement): UExpression {
|
||||||
|
return if (block != null) convert(block, parent) else EmptyExpression(parent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun convertDeclarations(elements: Array<out PsiElement>, parent: UElement): SimpleUDeclarationsExpression {
|
||||||
|
val uelements = arrayListOf<UElement>()
|
||||||
|
return SimpleUDeclarationsExpression(parent, uelements).apply {
|
||||||
|
for (element in elements) {
|
||||||
|
convert(element, this)?.let { uelements += it }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiDoWhileStatement
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UDoWhileExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUDoWhileExpression(
|
||||||
|
override val psi: PsiDoWhileStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UDoWhileExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) }
|
||||||
|
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiForeachStatement
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UForEachExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUForEachExpression(
|
||||||
|
override val psi: PsiForeachStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UForEachExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override val variableName: String?
|
||||||
|
get() = psi.iterationParameter.name
|
||||||
|
|
||||||
|
override val iteratedValue by lz { JavaConverter.convertOrEmpty(psi.iteratedValue, this) }
|
||||||
|
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiForStatement
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UForExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUForExpression(
|
||||||
|
override val psi: PsiForStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UForExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override val declaration by lz { psi.initialization?.let { JavaConverter.convert(it, this) } }
|
||||||
|
override val condition by lz { psi.condition?.let { JavaConverter.convert(it, this) } }
|
||||||
|
override val update by lz { psi.update?.let { JavaConverter.convert(it, this) } }
|
||||||
|
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiIfStatement
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UIfExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUIfExpression(
|
||||||
|
override val psi: PsiIfStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UIfExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) }
|
||||||
|
override val thenBranch by lz { JavaConverter.convertOrEmpty(psi.thenBranch, this) }
|
||||||
|
override val elseBranch by lz { JavaConverter.convertOrEmpty(psi.elseBranch, this) }
|
||||||
|
override val isTernary = false
|
||||||
|
}
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
open class JavaUSpecialExpressionList(
|
||||||
|
override val psi: PsiElement,
|
||||||
|
override val kind: UastSpecialExpressionKind, // original element
|
||||||
|
override val parent: UElement
|
||||||
|
) : USpecialExpressionList, PsiElementBacked {
|
||||||
|
class Empty(psi: PsiElement, expressionType: UastSpecialExpressionKind, parent: UElement) :
|
||||||
|
JavaUSpecialExpressionList(psi, expressionType, parent) {
|
||||||
|
init { expressions = emptyList() }
|
||||||
|
}
|
||||||
|
|
||||||
|
override lateinit var expressions: List<UExpression>
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiSwitchLabelStatement
|
||||||
|
import com.intellij.psi.PsiSwitchStatement
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UExpressionSwitchClauseExpression
|
||||||
|
import org.jetbrains.uast.USwitchExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUSwitchExpression(
|
||||||
|
override val psi: PsiSwitchStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : USwitchExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override val expression by lz { JavaConverter.convertOrEmpty(psi.expression, this) }
|
||||||
|
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||||
|
}
|
||||||
|
|
||||||
|
class JavaUExpressionSwitchClauseExpression(
|
||||||
|
override val psi: PsiSwitchLabelStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UExpressionSwitchClauseExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override val caseValue by lz { JavaConverter.convertOrEmpty(psi.caseValue, this) }
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiConditionalExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UIfExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUTernaryIfExpression(
|
||||||
|
override val psi: PsiConditionalExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UIfExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
override val condition by lz { JavaConverter.convert(psi.condition, this) }
|
||||||
|
override val thenBranch by lz { JavaConverter.convertOrEmpty(psi.thenExpression, this) }
|
||||||
|
override val elseBranch by lz { JavaConverter.convertOrEmpty(psi.elseExpression, this) }
|
||||||
|
override val isTernary = true
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiCatchSection
|
||||||
|
import com.intellij.psi.PsiTryStatement
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UCatchClause
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UTryExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUTryExpression(
|
||||||
|
override val psi: PsiTryStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UTryExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
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) } }
|
||||||
|
}
|
||||||
|
|
||||||
|
class JavaUCatchClause(
|
||||||
|
override val psi: PsiCatchSection,
|
||||||
|
override val parent: UElement
|
||||||
|
) : 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)) }
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiWhileStatement
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UWhileExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUWhileExpression(
|
||||||
|
override val psi: PsiWhileStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UWhileExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) }
|
||||||
|
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiClassInitializer
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaClassInitializerUFunction(
|
||||||
|
override val psi: PsiClassInitializer,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UFunction, PsiElementBacked, NoAnnotations, NoModifiers {
|
||||||
|
override val kind = UastFunctionKind.INITIALIZER
|
||||||
|
override val valueParameters = emptyList<UVariable>()
|
||||||
|
override val valueParameterCount = 0
|
||||||
|
override val typeParameters = emptyList<UTypeReference>()
|
||||||
|
override val typeParameterCount = 0
|
||||||
|
override val returnType = null
|
||||||
|
override val body by lz { JavaConverter.convert(psi.body, this) }
|
||||||
|
|
||||||
|
override val visibility = UastVisibility.LOCAL
|
||||||
|
override val nameElement = null
|
||||||
|
override val name = "<static>"
|
||||||
|
|
||||||
|
override fun getSuperFunctions(context: UastContext) = emptyList<UFunction>()
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiTypeParameter
|
||||||
|
import org.jetbrains.uast.UClass
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UTypeReference
|
||||||
|
import org.jetbrains.uast.UastContext
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaParameterUTypeReference(
|
||||||
|
override val psi: PsiTypeParameter,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UTypeReference, PsiElementBacked {
|
||||||
|
override val name: String
|
||||||
|
get() = psi.name.orAnonymous()
|
||||||
|
|
||||||
|
override val nameElement by lz { psi.nameIdentifier?.let { JavaPsiElementStub(it, this) } }
|
||||||
|
|
||||||
|
override fun resolve(context: UastContext) = psi.reference?.resolve()?.let { JavaConverter.convertWithParent(it) } as? UClass
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiAnnotation
|
||||||
|
import org.jetbrains.uast.UAnnotation
|
||||||
|
import org.jetbrains.uast.UClass
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UastContext
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUAnnotation(
|
||||||
|
override val psi: PsiAnnotation,
|
||||||
|
override val parent: UElement?
|
||||||
|
) : UAnnotation, PsiElementBacked {
|
||||||
|
override val name: String
|
||||||
|
get() = psi.nameReferenceElement?.referenceName.orAnonymous()
|
||||||
|
|
||||||
|
override val fqName: String?
|
||||||
|
get() = psi.qualifiedName
|
||||||
|
|
||||||
|
override val valueArguments by lz {
|
||||||
|
psi.parameterList.attributes.map {
|
||||||
|
JavaConverter.convert(it, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun resolve(context: UastContext) = context.convert(psi.reference?.resolve()) as? UClass
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class JavaUClass(
|
||||||
|
override val psi: PsiClass,
|
||||||
|
override val parent: UElement?,
|
||||||
|
val newExpression: PsiNewExpression? = null
|
||||||
|
) : UClass, PsiElementBacked {
|
||||||
|
override val name: String
|
||||||
|
get() = psi.name.orAnonymous()
|
||||||
|
|
||||||
|
override val nameElement by lz {
|
||||||
|
if (psi is PsiAnonymousClass && newExpression != null) {
|
||||||
|
newExpression.classOrAnonymousClassReference?.referenceNameElement?.let { JavaPsiElementStub(it, this) }
|
||||||
|
} else {
|
||||||
|
JavaConverter.convert(psi.nameIdentifier, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val fqName: String?
|
||||||
|
get() = psi.qualifiedName
|
||||||
|
|
||||||
|
override val isEnum: Boolean
|
||||||
|
get() = psi.isEnum
|
||||||
|
|
||||||
|
override val isInterface: Boolean
|
||||||
|
get() = psi.isInterface
|
||||||
|
|
||||||
|
override val isAnnotation: Boolean
|
||||||
|
get() = psi.isAnnotationType
|
||||||
|
|
||||||
|
override val isObject = psi is PsiAnonymousClass
|
||||||
|
override val isAnonymous = psi is PsiAnonymousClass
|
||||||
|
|
||||||
|
override val internalName = null
|
||||||
|
|
||||||
|
override val superTypes by lz {
|
||||||
|
psi.extendsListTypes.map { JavaConverter.convert(it, this) } + psi.implementsListTypes.map { JavaConverter.convert(it, this) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSuperClass(context: UastContext) = context.convert(psi.superClass) as? UClass
|
||||||
|
|
||||||
|
override val visibility: UastVisibility
|
||||||
|
get() = psi.getVisibility()
|
||||||
|
|
||||||
|
override fun hasModifier(modifier: UastModifier) = when (modifier) {
|
||||||
|
UastModifier.INNER -> !psi.hasModifierProperty(PsiModifier.STATIC) && !isTopLevel()
|
||||||
|
else -> psi.hasModifier(modifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val annotations by lz { psi.modifierList.getAnnotations(this) }
|
||||||
|
|
||||||
|
override val declarations by lz {
|
||||||
|
val declarations = arrayListOf<UDeclaration>()
|
||||||
|
psi.fields.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||||
|
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.innerClasses.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||||
|
psi.initializers.mapTo(declarations) { JavaConverter.convert(it, this) }
|
||||||
|
declarations
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSubclassOf(name: 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class JavaUAnonymousClassConstructor(
|
||||||
|
override val psi: PsiAnonymousClass,
|
||||||
|
val newExpression: PsiNewExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UFunction, PsiElementBacked, NoAnnotations, NoModifiers {
|
||||||
|
override val kind = UastFunctionKind.CONSTRUCTOR
|
||||||
|
|
||||||
|
override val valueParameterCount by lz { newExpression.argumentList?.expressions?.size ?: 0 }
|
||||||
|
|
||||||
|
override val valueParameters by lz {
|
||||||
|
val args = newExpression.argumentList ?: return@lz emptyList<UVariable>()
|
||||||
|
val variables = ArrayList<UVariable>(args.expressions.size)
|
||||||
|
|
||||||
|
for (i in 0..(args.expressions.size - 1)) {
|
||||||
|
variables += JavaUAnonymousClassConstructorParameter(args, i, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
variables
|
||||||
|
}
|
||||||
|
override val typeParameters by lz { psi.typeParameters.map { JavaConverter.convert(it, this) } }
|
||||||
|
|
||||||
|
override val typeParameterCount: Int
|
||||||
|
get() = psi.typeParameters.size
|
||||||
|
|
||||||
|
override val returnType = null
|
||||||
|
override val body = EmptyExpression(this)
|
||||||
|
override val visibility = UastVisibility.LOCAL
|
||||||
|
|
||||||
|
override fun getSuperFunctions(context: UastContext) = emptyList<UFunction>()
|
||||||
|
|
||||||
|
override val nameElement = null
|
||||||
|
override val name = "<init>"
|
||||||
|
}
|
||||||
|
|
||||||
|
private class JavaUAnonymousClassConstructorParameter(
|
||||||
|
val psi: PsiExpressionList,
|
||||||
|
val index: Int,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UVariable, NoAnnotations, NoModifiers {
|
||||||
|
override val initializer by lz { JavaConverter.convert(psi.expressions[index], this) }
|
||||||
|
override val kind = UastVariableKind.VALUE_PARAMETER
|
||||||
|
override val type by lz { JavaConverter.convert(psi.expressionTypes[index], this) }
|
||||||
|
override val nameElement = null
|
||||||
|
override val name = "p$index"
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiJavaFile
|
||||||
|
import org.jetbrains.uast.UFile
|
||||||
|
import org.jetbrains.uast.UImportStatement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUFile(override val psi: PsiJavaFile): UFile, PsiElementBacked {
|
||||||
|
override val packageFqName by lz { psi.packageName.let { if (it.isNotBlank()) it else null } }
|
||||||
|
|
||||||
|
override val importStatements: List<UImportStatement> by lz {
|
||||||
|
val importList = psi.importList ?: return@lz emptyList<UImportStatement>()
|
||||||
|
importList.importStatements.map { JavaConverter.convert(it, this) }.filterNotNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
override val declarations by lz { psi.classes.map { JavaUClass(it, this) } }
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiMethod
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUFunction(
|
||||||
|
override val psi: PsiMethod,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UFunction, PsiElementBacked {
|
||||||
|
override val kind: UastFunctionKind
|
||||||
|
get() = if (psi.isConstructor) UastFunctionKind.CONSTRUCTOR else UastFunctionKind.FUNCTION
|
||||||
|
|
||||||
|
override val name: String
|
||||||
|
get() = if (psi.isConstructor) "<init>" else psi.name
|
||||||
|
|
||||||
|
override val nameElement by lz { JavaConverter.convert(psi.nameIdentifier, this) }
|
||||||
|
|
||||||
|
override val valueParameters by lz { psi.parameterList.parameters.map { JavaConverter.convert(it, this) } }
|
||||||
|
|
||||||
|
override val valueParameterCount: Int
|
||||||
|
get() = psi.parameterList.parametersCount
|
||||||
|
|
||||||
|
override val typeParameters by lz { psi.typeParameters.map { JavaConverter.convert(it, this) } }
|
||||||
|
|
||||||
|
override val typeParameterCount: Int
|
||||||
|
get() = psi.typeParameters.size
|
||||||
|
|
||||||
|
override val returnType by lz { psi.returnType?.let { JavaConverter.convert(it, this) } }
|
||||||
|
|
||||||
|
override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier)
|
||||||
|
|
||||||
|
val thrownExceptions: List<UType> by lz {
|
||||||
|
psi.throwsList.referencedTypes.map { JavaConverter.convert(it, this) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override val annotations by lz { psi.modifierList.getAnnotations(this) }
|
||||||
|
|
||||||
|
override val visibility: UastVisibility
|
||||||
|
get() = psi.getVisibility()
|
||||||
|
|
||||||
|
override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) }
|
||||||
|
|
||||||
|
override fun getSuperFunctions(context: UastContext): List<UFunction> {
|
||||||
|
return psi.findSuperMethods().map { context.convert(it) as? UFunction }.filterNotNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiImportStatement
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UImportStatement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUImportStatement(
|
||||||
|
override val psi: PsiImportStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UImportStatement, PsiElementBacked {
|
||||||
|
override val nameToImport: String?
|
||||||
|
get() = psi.qualifiedName
|
||||||
|
|
||||||
|
override val isStarImport = false
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiImportStaticStatement
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UImportStatement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUStaticImportStatement(
|
||||||
|
override val psi: PsiImportStaticStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UImportStatement, PsiElementBacked {
|
||||||
|
override val nameToImport: String?
|
||||||
|
get() = psi.referenceName
|
||||||
|
|
||||||
|
override val isStarImport = true
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiClassType
|
||||||
|
import com.intellij.psi.PsiType
|
||||||
|
import org.jetbrains.uast.UClass
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UType
|
||||||
|
import org.jetbrains.uast.UastContext
|
||||||
|
|
||||||
|
class JavaUType(
|
||||||
|
val psi: PsiType?,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UType {
|
||||||
|
override val name: String
|
||||||
|
get() = when (psi) {
|
||||||
|
is PsiClassType -> psi.className.substringAfterLast('.')
|
||||||
|
else -> psi?.canonicalText?.substringAfterLast('.')
|
||||||
|
}.orAnonymous("type")
|
||||||
|
|
||||||
|
override val fqName: String?
|
||||||
|
get() = when (psi) {
|
||||||
|
is PsiClassType -> psi.resolve()?.qualifiedName
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
override val isInt: Boolean
|
||||||
|
get() = name == "int"
|
||||||
|
|
||||||
|
override val isBoolean: Boolean
|
||||||
|
get() = name == "boolean"
|
||||||
|
|
||||||
|
override val annotations by lz { psi.getAnnotations(this) }
|
||||||
|
|
||||||
|
override fun resolve(context: UastContext) = when (psi) {
|
||||||
|
is PsiClassType -> psi.resolve()?.let { context.convert(it) as? UClass }
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.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.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUVariable(
|
||||||
|
override val psi: PsiVariable,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UVariable, PsiElementBacked {
|
||||||
|
override val name: String
|
||||||
|
get() = psi.name.orAnonymous()
|
||||||
|
|
||||||
|
override val nameElement by lz { JavaConverter.convert(psi.nameIdentifier, this) }
|
||||||
|
override val type by lz { JavaConverter.convert(psi.type, this) }
|
||||||
|
|
||||||
|
override val initializer by lz { JavaConverter.convertOrEmpty(psi.initializer, this) }
|
||||||
|
|
||||||
|
override val kind = when (psi) {
|
||||||
|
is PsiField -> UastVariableKind.MEMBER
|
||||||
|
else -> UastVariableKind.LOCAL_VARIABLE
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier)
|
||||||
|
override val annotations by lz { psi.modifierList.getAnnotations(this) }
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiParameter
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaValueParameterUVariable(
|
||||||
|
override val psi: PsiParameter,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UVariable, PsiElementBacked, NoModifiers {
|
||||||
|
override val name: String
|
||||||
|
get() = psi.name.orAnonymous()
|
||||||
|
|
||||||
|
override val nameElement by lz { JavaConverter.convert(psi.nameIdentifier, this) }
|
||||||
|
override val type by lz { JavaConverter.convert(psi.type, this) }
|
||||||
|
override val initializer = null
|
||||||
|
override val kind = UastVariableKind.VALUE_PARAMETER
|
||||||
|
|
||||||
|
override val annotations by lz { psi.modifierList.getAnnotations(this) }
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiPolyadicExpression
|
||||||
|
import org.jetbrains.uast.UBinaryExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaCombinedUBinaryExpression(
|
||||||
|
override val psi: PsiPolyadicExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UBinaryExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
override lateinit var leftOperand: UExpression
|
||||||
|
override lateinit var rightOperand: UExpression
|
||||||
|
|
||||||
|
override val operator = psi.operationTokenType.getOperatorType()
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.uast.NoTraverse
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaPsiElementStub(
|
||||||
|
override val psi: PsiElement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UElement, PsiElementBacked, NoTraverse {
|
||||||
|
override fun logString() = "JavaPsiElementStub"
|
||||||
|
override fun renderString() = "<stub@$psi>"
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiArrayAccessExpression
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UArrayAccessExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUArrayAccessExpression(
|
||||||
|
override val psi: PsiArrayAccessExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UArrayAccessExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||||
|
override val receiver by lz { JavaConverter.convert(psi.arrayExpression, this) }
|
||||||
|
override val indices by lz { singletonListOrEmpty(JavaConverter.convertOrNull(psi.indexExpression, this)) }
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiAssignmentExpression
|
||||||
|
import org.jetbrains.uast.UAssignmentExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUAssignmentExpression(
|
||||||
|
override val psi: PsiAssignmentExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UAssignmentExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
override val reference by lz { JavaConverter.convert(psi.lExpression, this) }
|
||||||
|
override val operator = psi.operationSign.text
|
||||||
|
override val value by lz { JavaConverter.convertOrEmpty(psi.rExpression, this) }
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiBinaryExpression
|
||||||
|
import org.jetbrains.uast.UBinaryExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUBinaryExpression(
|
||||||
|
override val psi: PsiBinaryExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UBinaryExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
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() }
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiBlockStatement
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UBlockExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUBlockExpression(
|
||||||
|
override val psi: PsiBlockStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UBlockExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||||
|
override val expressions by lz { psi.codeBlock.statements.map { JavaConverter.convert(it, this) } }
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiMethodReferenceExpression
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UCallableReferenceExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUCallableReferenceExpression(
|
||||||
|
override val psi: PsiMethodReferenceExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UCallableReferenceExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||||
|
override val qualifierType by lz { JavaConverter.convert(psi.qualifierType?.type, this) }
|
||||||
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiClassObjectAccessExpression
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UClassLiteralExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUClassLiteralExpression(
|
||||||
|
override val psi: PsiClassObjectAccessExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UClassLiteralExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiCodeBlock
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UBlockExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUCodeBlockExpression(
|
||||||
|
override val psi: PsiCodeBlock,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UBlockExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||||
|
override val expressions by lz { psi.statements.map { JavaConverter.convert(it, this) } }
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUCompositeQualifiedExpression(
|
||||||
|
override val parent: UElement
|
||||||
|
) : UQualifiedExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override lateinit var receiver: UExpression
|
||||||
|
internal set
|
||||||
|
|
||||||
|
override lateinit var selector: UExpression
|
||||||
|
internal set
|
||||||
|
|
||||||
|
override val accessType = UastQualifiedExpressionAccessType.SIMPLE
|
||||||
|
|
||||||
|
override fun resolve(context: UastContext): UDeclaration? {
|
||||||
|
val selector = selector
|
||||||
|
return when (selector) {
|
||||||
|
is UCallExpression -> selector.resolve(context)
|
||||||
|
is USimpleReferenceExpression -> selector.resolve(context)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val psi: PsiElement
|
||||||
|
get() = (selector as? PsiElementBacked)?.psi ?: (receiver as? PsiElementBacked)?.psi ?: error("No PSI element found")
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiInstanceOfExpression
|
||||||
|
import org.jetbrains.uast.UBinaryExpressionWithType
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UastBinaryExpressionWithTypeKind
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUInstanceCheckExpression(
|
||||||
|
override val psi: PsiInstanceOfExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UBinaryExpressionWithType, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||||
|
override val type by lz { JavaConverter.convert(psi.checkType?.type, this) }
|
||||||
|
override val operationKind = UastBinaryExpressionWithTypeKind.INSTANCE_CHECK
|
||||||
|
override fun evaluate() = null
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiLabeledStatement
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.ULabeledExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaULabeledExpression(
|
||||||
|
override val psi: PsiLabeledStatement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : ULabeledExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override val label by lz { psi.labelIdentifier.text }
|
||||||
|
override val expression by lz { JavaConverter.convertOrEmpty(psi.statement, this) }
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.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
|
||||||
|
|
||||||
|
class JavaULambdaExpression(
|
||||||
|
override val psi: PsiLambdaExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : ULambdaExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||||
|
override val valueParameters by lz { psi.parameterList.parameters.map { JavaConverter.convert(it, this) } }
|
||||||
|
|
||||||
|
override val body by lz {
|
||||||
|
val b = psi.body
|
||||||
|
when (b) {
|
||||||
|
is PsiCodeBlock -> JavaConverter.convert(b, this)
|
||||||
|
is PsiExpression -> JavaConverter.convert(b, this)
|
||||||
|
else -> EmptyExpression(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiLiteralExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.ULiteralExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaULiteralExpression(
|
||||||
|
override val psi: PsiLiteralExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : ULiteralExpression, PsiElementBacked, JavaTypeHelper {
|
||||||
|
override val text by lz { psi.text }
|
||||||
|
override fun evaluate() = psi.value
|
||||||
|
override val value by lz { evaluate() }
|
||||||
|
override val isNull = text == "null"
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiNewExpression
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UClassNotResolved
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UObjectLiteralExpression
|
||||||
|
|
||||||
|
class JavaUObjectLiteralExpression(
|
||||||
|
override val psi: PsiNewExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UObjectLiteralExpression, JavaTypeHelper, NoEvaluate {
|
||||||
|
override val declaration by lz {
|
||||||
|
psi.anonymousClass?.let { JavaUClass(it, this, psi) } ?: UClassNotResolved
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiParenthesizedExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UParenthesizedExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUParenthesizedExpression(
|
||||||
|
override val psi: PsiParenthesizedExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UParenthesizedExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
override val expression by lz { JavaConverter.convertOrEmpty(psi.expression, this) }
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiPostfixExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UPostfixExpression
|
||||||
|
import org.jetbrains.uast.UastPostfixOperator
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUPostfixExpression(
|
||||||
|
override val psi: PsiPostfixExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UPostfixExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||||
|
|
||||||
|
override val operator = when (psi.operationSign.text) {
|
||||||
|
"++" -> UastPostfixOperator.INC
|
||||||
|
"--" -> UastPostfixOperator.DEC
|
||||||
|
else -> UastPostfixOperator.UNKNOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiPrefixExpression
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UPrefixExpression
|
||||||
|
import org.jetbrains.uast.UastPrefixOperator
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUPrefixExpression(
|
||||||
|
override val psi: PsiPrefixExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UPrefixExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
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
|
||||||
|
else -> UastPrefixOperator.UNKNOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiReferenceExpression
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUQualifiedExpression(
|
||||||
|
override val psi: PsiReferenceExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UQualifiedExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||||
|
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 accessType = UastQualifiedExpressionAccessType.SIMPLE
|
||||||
|
|
||||||
|
override fun resolve(context: UastContext) = psi.resolve()?.let { JavaConverter.convertWithParent(it) } as? UDeclaration
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiJavaReference
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUSimpleReferenceExpression(
|
||||||
|
override val psi: PsiElement,
|
||||||
|
override val identifier: String,
|
||||||
|
override val parent: UElement
|
||||||
|
) : USimpleReferenceExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||||
|
override fun resolve(context: UastContext) = psi.reference?.resolve()?.let { context.convert(it) } as? UDeclaration
|
||||||
|
}
|
||||||
|
|
||||||
|
class JavaClassUSimpleReferenceExpression(
|
||||||
|
override val identifier: String,
|
||||||
|
val ref: PsiJavaReference,
|
||||||
|
override val parent: UElement
|
||||||
|
) : USimpleReferenceExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override val psi: PsiElement?
|
||||||
|
get() = ref.element
|
||||||
|
|
||||||
|
override fun resolve(context: UastContext) = context.convert(ref.resolve()) as? UDeclaration
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiSuperExpression
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.USuperExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUSuperExpression(
|
||||||
|
override val psi: PsiSuperExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : USuperExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiThisExpression
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UThisExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUThisExpression(
|
||||||
|
override val psi: PsiThisExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UThisExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiTypeCastExpression
|
||||||
|
import org.jetbrains.uast.UBinaryExpressionWithType
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UastBinaryExpressionWithTypeKind
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUTypeCastExpression(
|
||||||
|
override val psi: PsiTypeCastExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UBinaryExpressionWithType, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) }
|
||||||
|
override val type by lz { JavaConverter.convert(psi.castType?.type, this) }
|
||||||
|
override val operationKind = UastBinaryExpressionWithTypeKind.TYPE_CAST
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.uast.NoEvaluate
|
||||||
|
import org.jetbrains.uast.UElement
|
||||||
|
import org.jetbrains.uast.UExpression
|
||||||
|
import org.jetbrains.uast.UastHandler
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class UnknownJavaExpression(
|
||||||
|
override val psi: PsiElement,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UExpression, PsiElementBacked, NoEvaluate {
|
||||||
|
override fun traverse(handler: UastHandler) {}
|
||||||
|
override fun logString() = "[!] UnknownJavaExpression ($psi)"
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.JavaPsiFacade
|
||||||
|
import com.intellij.psi.PsiExpression
|
||||||
|
import org.jetbrains.uast.UExpression
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
interface JavaEvaluateHelper : UExpression, PsiElementBacked {
|
||||||
|
override fun evaluate(): Any? {
|
||||||
|
val psi = this.psi ?: return null
|
||||||
|
return JavaPsiFacade.getInstance(psi.project).constantEvaluationHelper.computeConstantExpression(psi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JavaTypeHelper : UExpression, PsiElementBacked {
|
||||||
|
override fun getExpressionType() = (psi as? PsiExpression)?.type?.let { JavaConverter.convert(it, this) }
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiArrayInitializerExpression
|
||||||
|
import com.intellij.psi.PsiArrayInitializerMemberValue
|
||||||
|
import com.intellij.psi.PsiMethodCallExpression
|
||||||
|
import com.intellij.psi.PsiNewExpression
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
import org.jetbrains.uast.psi.PsiElementBacked
|
||||||
|
|
||||||
|
class JavaUCallExpression(
|
||||||
|
override val psi: PsiMethodCallExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UCallExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||||
|
override val kind = UastCallKind.FUNCTION_CALL
|
||||||
|
|
||||||
|
override val functionReference by lz {
|
||||||
|
JavaConverter.convert(psi.methodExpression.referenceNameElement, this) as? USimpleReferenceExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
override val classReference = null
|
||||||
|
|
||||||
|
override val valueArgumentCount by lz { psi.argumentList.expressions.size }
|
||||||
|
override val valueArguments by lz { psi.argumentList.expressions.map { JavaConverter.convert(it, this) } }
|
||||||
|
|
||||||
|
override val typeArgumentCount by lz { psi.typeArguments.size }
|
||||||
|
override val typeArguments by lz { psi.typeArguments.map { JavaConverter.convert(it, this) } }
|
||||||
|
|
||||||
|
override val functionName: String
|
||||||
|
get() = psi.methodExpression.referenceName ?: "<error name>"
|
||||||
|
|
||||||
|
override val functionNameElement: UElement?
|
||||||
|
get() = functionReference
|
||||||
|
|
||||||
|
override fun resolve(context: UastContext) = psi.resolveMethod()?.let { context.convert(it) as? UFunction }
|
||||||
|
}
|
||||||
|
|
||||||
|
class JavaConstructorUCallExpression(
|
||||||
|
override val psi: PsiNewExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UCallExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate {
|
||||||
|
override val kind by lz {
|
||||||
|
when {
|
||||||
|
psi.arrayInitializer != null -> JavaUastCallKinds.ARRAY_INITIALIZER
|
||||||
|
psi.arrayDimensions.isNotEmpty() -> JavaUastCallKinds.ARRAY_DIMENSIONS
|
||||||
|
else -> UastCallKind.CONSTRUCTOR_CALL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val functionReference = null
|
||||||
|
|
||||||
|
override val classReference by lz {
|
||||||
|
psi.classReference?.let { ref ->
|
||||||
|
JavaClassUSimpleReferenceExpression(ref.element?.text.orAnonymous(), ref, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val valueArgumentCount: Int
|
||||||
|
get() {
|
||||||
|
val initializer = psi.arrayInitializer
|
||||||
|
return if (initializer != null) {
|
||||||
|
initializer.initializers.size
|
||||||
|
} else if (psi.arrayDimensions.isNotEmpty()) {
|
||||||
|
psi.arrayDimensions.size
|
||||||
|
} else {
|
||||||
|
psi.argumentList?.expressions?.size ?: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val valueArguments by lz {
|
||||||
|
val initializer = psi.arrayInitializer
|
||||||
|
if (initializer != null) {
|
||||||
|
initializer.initializers.map { JavaConverter.convert(it, this) }
|
||||||
|
}
|
||||||
|
else if (psi.arrayDimensions.isNotEmpty()) {
|
||||||
|
psi.arrayDimensions.map { JavaConverter.convert(it, this) }
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
psi.argumentList?.expressions?.map { JavaConverter.convert(it, this) } ?: emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val typeArgumentCount by lz { psi.typeArguments.size }
|
||||||
|
override val typeArguments by lz { psi.typeArguments.map { JavaConverter.convert(it, this) } }
|
||||||
|
|
||||||
|
override val functionName: String?
|
||||||
|
get() {
|
||||||
|
val initializer = psi.arrayInitializer
|
||||||
|
return if (initializer != null)
|
||||||
|
"<newArray>"
|
||||||
|
else if (psi.arrayDimensions.isNotEmpty())
|
||||||
|
"<newArrayWithDimensions>"
|
||||||
|
else null
|
||||||
|
}
|
||||||
|
|
||||||
|
override val functionNameElement by lz { JavaPsiElementStub(psi, this) }
|
||||||
|
|
||||||
|
override fun resolve(context: UastContext) = psi.resolveConstructor()?.let { context.convert(it) } as? UFunction
|
||||||
|
}
|
||||||
|
|
||||||
|
class JavaArrayInitializerUCallExpression(
|
||||||
|
override val psi: PsiArrayInitializerExpression,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UCallExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
override val functionReference = null
|
||||||
|
override val classReference = null
|
||||||
|
override val functionName = "<array>"
|
||||||
|
override val functionNameElement = null
|
||||||
|
|
||||||
|
override val valueArgumentCount by lz { psi.initializers.size }
|
||||||
|
override val valueArguments by lz { psi.initializers.map { JavaConverter.convert(it, this) } }
|
||||||
|
|
||||||
|
override val typeArgumentCount = 0
|
||||||
|
override val typeArguments = emptyList<UType>()
|
||||||
|
|
||||||
|
override val kind = JavaUastCallKinds.ARRAY_INITIALIZER
|
||||||
|
|
||||||
|
override fun resolve(context: UastContext) = null
|
||||||
|
override fun evaluate() = null
|
||||||
|
}
|
||||||
|
|
||||||
|
class JavaAnnotationArrayInitializerUCallExpression(
|
||||||
|
override val psi: PsiArrayInitializerMemberValue,
|
||||||
|
override val parent: UElement
|
||||||
|
) : UCallExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper {
|
||||||
|
override val kind = JavaUastCallKinds.ARRAY_INITIALIZER
|
||||||
|
|
||||||
|
override val functionReference = null
|
||||||
|
override val classReference = null
|
||||||
|
override val functionName = "<annotationArray>"
|
||||||
|
override val functionNameElement = null
|
||||||
|
|
||||||
|
override val valueArgumentCount by lz { psi.initializers.size }
|
||||||
|
override val valueArguments by lz {
|
||||||
|
psi.initializers.map {
|
||||||
|
JavaConverter.convert(it, this) as? UExpression ?: UnknownJavaExpression(it, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val typeArgumentCount = 0
|
||||||
|
override val typeArguments = emptyList<UType>()
|
||||||
|
|
||||||
|
override fun resolve(context: UastContext) = null
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import com.intellij.psi.tree.IElementType
|
||||||
|
import org.jetbrains.uast.*
|
||||||
|
|
||||||
|
private val MODIFIER_MAP = mapOf(
|
||||||
|
UastModifier.ABSTRACT to PsiModifier.ABSTRACT,
|
||||||
|
UastModifier.FINAL to PsiModifier.FINAL
|
||||||
|
)
|
||||||
|
|
||||||
|
internal fun PsiModifierListOwner.hasModifier(modifier: UastModifier): Boolean {
|
||||||
|
val javaModifier = MODIFIER_MAP[modifier] ?: return false
|
||||||
|
return hasModifierProperty(javaModifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun PsiAnnotationOwner?.getAnnotations(owner: UElement): List<UAnnotation> {
|
||||||
|
if (this == null) return emptyList()
|
||||||
|
return annotations.map { JavaConverter.convert(it, owner) }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun PsiModifierListOwner.getVisibility(): UastVisibility {
|
||||||
|
if (hasModifierProperty(PsiModifier.PUBLIC)) return UastVisibility.PUBLIC
|
||||||
|
if (hasModifierProperty(PsiModifier.PROTECTED)) return UastVisibility.PROTECTED
|
||||||
|
if (hasModifierProperty(PsiModifier.PRIVATE)) return UastVisibility.PRIVATE
|
||||||
|
return JavaUastVisibilities.DEFAULT
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun IElementType.getOperatorType() = when (this) {
|
||||||
|
JavaTokenType.PLUS -> UastBinaryOperator.PLUS
|
||||||
|
JavaTokenType.MINUS -> UastBinaryOperator.MINUS
|
||||||
|
JavaTokenType.ASTERISK -> UastBinaryOperator.MULT
|
||||||
|
JavaTokenType.DIV -> UastBinaryOperator.DIV
|
||||||
|
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
|
||||||
|
JavaTokenType.GE -> UastBinaryOperator.GREATER_OR_EQUAL
|
||||||
|
JavaTokenType.LT -> UastBinaryOperator.LESS
|
||||||
|
JavaTokenType.LE -> UastBinaryOperator.LESS_OR_EQUAL
|
||||||
|
JavaTokenType.LTLT -> UastBinaryOperator.SHIFT_LEFT
|
||||||
|
JavaTokenType.GTGT -> UastBinaryOperator.SHIFT_RIGHT
|
||||||
|
JavaTokenType.GTGTGT -> UastBinaryOperator.BITWISE_SHIFT_RIGHT
|
||||||
|
else -> UastBinaryOperator.UNKNOWN
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun <T> singletonListOrEmpty(element: T?) = if (element != null) listOf(element) else emptyList<T>()
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
internal inline fun String?.orAnonymous(kind: String = ""): String {
|
||||||
|
return this ?: "<anonymous" + (if (kind.isNotBlank()) " $kind" else "") + ">"
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun <T> runReadAction(action: () -> T): T {
|
||||||
|
return ApplicationManager.getApplication().runReadAction<T>(action)
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* 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.UastSpecialExpressionKind
|
||||||
|
|
||||||
|
object JavaSpecialExpressionKinds {
|
||||||
|
@JvmField
|
||||||
|
val ASSERT = UastSpecialExpressionKind("assert")
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val SYNCHRONIZED = UastSpecialExpressionKind("synchronized")
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* 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.UastCallKind
|
||||||
|
|
||||||
|
object JavaUastCallKinds {
|
||||||
|
@JvmField
|
||||||
|
val ARRAY_INITIALIZER = UastCallKind("array_initializer")
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val ARRAY_DIMENSIONS = UastCallKind("array_dimensions")
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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")
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast.java
|
||||||
|
|
||||||
|
import org.jetbrains.uast.UastVisibility
|
||||||
|
|
||||||
|
object JavaUastVisibilities {
|
||||||
|
@JvmField
|
||||||
|
val DEFAULT = UastVisibility("default")
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val INSTANCE = UastVisibility("instance")
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
@file:JvmName("UastPsiUtils")
|
||||||
|
package org.jetbrains.uast.psi
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
|
||||||
|
interface PsiElementBacked {
|
||||||
|
val psi: com.intellij.psi.PsiElement?
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jetbrains.uast
|
||||||
|
|
||||||
|
import com.intellij.psi.JavaPsiFacade
|
||||||
|
import com.intellij.psi.PsiClass
|
||||||
|
import com.intellij.testFramework.LightCodeInsightTestCase
|
||||||
|
import com.intellij.testFramework.LightPlatformTestCase
|
||||||
|
import org.jetbrains.uast.java.JavaConverter
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
open class AbstractStructureTest : LightCodeInsightTestCase() {
|
||||||
|
fun test(name: String) {
|
||||||
|
val testDir = File("testData")
|
||||||
|
val javaFile = File(testDir, "$name.java")
|
||||||
|
val logFile = File(File(testDir, "log"), "$name.txt")
|
||||||
|
val renderFile = File(File(testDir, "render"), "$name.txt")
|
||||||
|
|
||||||
|
val psiClass = createClass(javaFile.readText())
|
||||||
|
val uElement = JavaConverter.convertWithParent(psiClass) ?: error("UFile was not created")
|
||||||
|
val uFile = uElement.getContainingFile() ?: error("No containing file")
|
||||||
|
try {
|
||||||
|
assertEqualsFile(uFile.logString(), logFile)
|
||||||
|
} catch (e: NoTestFileException) {
|
||||||
|
assertEqualsFile(uFile.renderString(), renderFile)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
assertEqualsFile(uFile.renderString(), renderFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createClass(text: String): PsiClass {
|
||||||
|
val factory = JavaPsiFacade.getInstance(LightPlatformTestCase.ourProject).elementFactory
|
||||||
|
val classA = factory.createClassFromText(text, null).innerClasses[0]
|
||||||
|
return classA
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertEqualsFile(text: String, file: File) {
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.parentFile.mkdirs()
|
||||||
|
file.writeText(text)
|
||||||
|
throw NoTestFileException(file)
|
||||||
|
} else {
|
||||||
|
val lineSeparator = System.getProperty("line.separator") ?: "\n";
|
||||||
|
val expected = file.readLines().map { it.trimEnd() }.joinToString(lineSeparator).trim()
|
||||||
|
val actual = text.lines().map { it.trimEnd() }.joinToString(lineSeparator).trim()
|
||||||
|
assertEquals(expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NoTestFileException(file: File) : RuntimeException("Test file was generated: $file")
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
class StructureTest : AbstractStructureTest() {
|
||||||
|
fun testSimple() = test("Simple")
|
||||||
|
fun testControlStructures() = test("ControlStructures")
|
||||||
|
fun testNestedClasses() = test("NestedClasses")
|
||||||
|
fun testSpecialExpressions() = test("SpecialExpressions")
|
||||||
|
fun testLambda() = test("Lambda")
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
class ControlStructures {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String mode = args.length == 1 ? "singleArg" : "multiArgs";
|
||||||
|
|
||||||
|
for (String arg : args) {
|
||||||
|
System.out.println(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < args.length; ++i) {
|
||||||
|
System.out.println(i + ": " + args[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (i < args.length) {
|
||||||
|
System.out.println("Index " + i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
do {
|
||||||
|
System.out.println(i);
|
||||||
|
i += 1;
|
||||||
|
} while (i < args.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
class Lambda {
|
||||||
|
void example() {
|
||||||
|
doJob(arg -> arg + arg, "Mary");
|
||||||
|
}
|
||||||
|
|
||||||
|
void doJob(Job job, String arg) {
|
||||||
|
System.out.println(job.doJob(arg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Job {
|
||||||
|
String doJob(String arg);
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
class NestedClasses {
|
||||||
|
public static class Nested {
|
||||||
|
void func1() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Inner {
|
||||||
|
void func2() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
class Simple {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public Simple(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
class SpecialExpressions {
|
||||||
|
boolean test() {
|
||||||
|
assert 5 > 3;
|
||||||
|
assert 5 > 3 : "Message";
|
||||||
|
|
||||||
|
synchronized (this) {
|
||||||
|
System.out.println("A");
|
||||||
|
}
|
||||||
|
|
||||||
|
int a = 5, b = 7, c;
|
||||||
|
|
||||||
|
while (a > 0) {
|
||||||
|
if (a == 3) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (a % 5 == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
a--;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.test();
|
||||||
|
super.hashCode();
|
||||||
|
|
||||||
|
String x;
|
||||||
|
switch (a) {
|
||||||
|
case 1: {
|
||||||
|
x = "1";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3: x = "3";
|
||||||
|
case 4: x = "4";
|
||||||
|
default: x = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (System.getProperty("abc", "").equals("1")) {
|
||||||
|
throw new AssertionError("Err");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
a = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
a = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
UFile (package = null)
|
||||||
|
UClass (_Dummy_, enum = false, interface = false, object = false)
|
||||||
|
UClass (ControlStructures, enum = false, interface = false, object = false)
|
||||||
|
UFunction (main, kind = function, paramCount = 1)
|
||||||
|
UBlockExpression
|
||||||
|
UIfExpression
|
||||||
|
UBinaryExpression (===)
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (args)
|
||||||
|
USimpleReferenceExpression (length)
|
||||||
|
ULiteralExpression (0)
|
||||||
|
UBlockExpression
|
||||||
|
USpecialExpressionList (return)
|
||||||
|
|
||||||
|
EmptyExpression
|
||||||
|
UDeclarationsExpression
|
||||||
|
UVariable (mode, kind = local)
|
||||||
|
UIfExpression
|
||||||
|
UBinaryExpression (===)
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (args)
|
||||||
|
USimpleReferenceExpression (length)
|
||||||
|
ULiteralExpression (1)
|
||||||
|
ULiteralExpression ("singleArg")
|
||||||
|
ULiteralExpression ("multiArgs")
|
||||||
|
UForEachExpression (arg)
|
||||||
|
USimpleReferenceExpression (args)
|
||||||
|
UBlockExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (System)
|
||||||
|
USimpleReferenceExpression (out)
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||||
|
USimpleReferenceExpression (println)
|
||||||
|
USimpleReferenceExpression (arg)
|
||||||
|
UForExpression
|
||||||
|
UDeclarationsExpression
|
||||||
|
UVariable (i, kind = local)
|
||||||
|
ULiteralExpression (0)
|
||||||
|
UBinaryExpression (<)
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (args)
|
||||||
|
USimpleReferenceExpression (length)
|
||||||
|
UPrefixExpression (++)
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
UBlockExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (System)
|
||||||
|
USimpleReferenceExpression (out)
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||||
|
USimpleReferenceExpression (println)
|
||||||
|
UBinaryExpression (+)
|
||||||
|
UBinaryExpression (+)
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
ULiteralExpression (": ")
|
||||||
|
UArrayAccessExpression
|
||||||
|
USimpleReferenceExpression (args)
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
UDeclarationsExpression
|
||||||
|
UVariable (i, kind = local)
|
||||||
|
ULiteralExpression (0)
|
||||||
|
UWhileExpression
|
||||||
|
UBinaryExpression (<)
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (args)
|
||||||
|
USimpleReferenceExpression (length)
|
||||||
|
UBlockExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (System)
|
||||||
|
USimpleReferenceExpression (out)
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||||
|
USimpleReferenceExpression (println)
|
||||||
|
UBinaryExpression (+)
|
||||||
|
ULiteralExpression ("Index ")
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
UPostfixExpression (++)
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
UAssignmentExpression (=)
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
ULiteralExpression (0)
|
||||||
|
UDoWhileExpression
|
||||||
|
UBinaryExpression (<)
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (args)
|
||||||
|
USimpleReferenceExpression (length)
|
||||||
|
UBlockExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (System)
|
||||||
|
USimpleReferenceExpression (out)
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||||
|
USimpleReferenceExpression (println)
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
UAssignmentExpression (+=)
|
||||||
|
USimpleReferenceExpression (i)
|
||||||
|
ULiteralExpression (1)
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
UFile (package = null)
|
||||||
|
UClass (_Dummy_, enum = false, interface = false, object = false)
|
||||||
|
UClass (Lambda, enum = false, interface = false, object = false)
|
||||||
|
UFunction (example, kind = function, paramCount = 0)
|
||||||
|
UBlockExpression
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 2)
|
||||||
|
USimpleReferenceExpression (doJob)
|
||||||
|
ULambdaExpression
|
||||||
|
UVariable (arg, kind = parameter)
|
||||||
|
<no initializer>
|
||||||
|
UBinaryExpression (+)
|
||||||
|
USimpleReferenceExpression (arg)
|
||||||
|
USimpleReferenceExpression (arg)
|
||||||
|
ULiteralExpression ("Mary")
|
||||||
|
UFunction (doJob, kind = function, paramCount = 2)
|
||||||
|
UBlockExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (System)
|
||||||
|
USimpleReferenceExpression (out)
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||||
|
USimpleReferenceExpression (println)
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (job)
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||||
|
USimpleReferenceExpression (doJob)
|
||||||
|
USimpleReferenceExpression (arg)
|
||||||
|
UClass (Job, enum = false, interface = true, object = false)
|
||||||
|
UFunction (doJob, kind = function, paramCount = 1)
|
||||||
|
EmptyExpression
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
UFile (package = null)
|
||||||
|
UClass (_Dummy_, enum = false, interface = false, object = false)
|
||||||
|
UClass (NestedClasses, enum = false, interface = false, object = false)
|
||||||
|
UClass (Nested, enum = false, interface = false, object = false)
|
||||||
|
UFunction (func1, kind = function, paramCount = 0)
|
||||||
|
UBlockExpression
|
||||||
|
|
||||||
|
UClass (Inner, enum = false, interface = false, object = false)
|
||||||
|
UFunction (func2, kind = function, paramCount = 0)
|
||||||
|
UBlockExpression
|
||||||
|
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
UFile (package = null)
|
||||||
|
UClass (_Dummy_, enum = false, interface = false, object = false)
|
||||||
|
UClass (Simple, enum = false, interface = false, object = false)
|
||||||
|
UVariable (name, kind = member)
|
||||||
|
EmptyExpression
|
||||||
|
UFunction (Simple, kind = function, paramCount = 1)
|
||||||
|
UBlockExpression
|
||||||
|
UAssignmentExpression (=)
|
||||||
|
UQualifiedExpression
|
||||||
|
UThisExpression
|
||||||
|
USimpleReferenceExpression (name)
|
||||||
|
USimpleReferenceExpression (name)
|
||||||
|
UFunction (getName, kind = function, paramCount = 0)
|
||||||
|
UBlockExpression
|
||||||
|
USpecialExpressionList (return)
|
||||||
|
USimpleReferenceExpression (name)
|
||||||
|
UFunction (setName, kind = function, paramCount = 1)
|
||||||
|
UBlockExpression
|
||||||
|
UAssignmentExpression (=)
|
||||||
|
UQualifiedExpression
|
||||||
|
UThisExpression
|
||||||
|
USimpleReferenceExpression (name)
|
||||||
|
USimpleReferenceExpression (name)
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
UFile (package = null)
|
||||||
|
UClass (_Dummy_, enum = false, interface = false, object = false)
|
||||||
|
UClass (SpecialExpressions, enum = false, interface = false, object = false)
|
||||||
|
UFunction (test, kind = function, paramCount = 0)
|
||||||
|
UBlockExpression
|
||||||
|
USpecialExpressionList (assert)
|
||||||
|
UBinaryExpression (>)
|
||||||
|
ULiteralExpression (5)
|
||||||
|
ULiteralExpression (3)
|
||||||
|
EmptyExpression
|
||||||
|
USpecialExpressionList (assert)
|
||||||
|
UBinaryExpression (>)
|
||||||
|
ULiteralExpression (5)
|
||||||
|
ULiteralExpression (3)
|
||||||
|
ULiteralExpression ("Message")
|
||||||
|
USpecialExpressionList (synchronized)
|
||||||
|
UThisExpression
|
||||||
|
UBlockExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (System)
|
||||||
|
USimpleReferenceExpression (out)
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||||
|
USimpleReferenceExpression (println)
|
||||||
|
ULiteralExpression ("A")
|
||||||
|
UDeclarationsExpression
|
||||||
|
UVariable (a, kind = local)
|
||||||
|
ULiteralExpression (5)
|
||||||
|
UVariable (b, kind = local)
|
||||||
|
ULiteralExpression (7)
|
||||||
|
UVariable (c, kind = local)
|
||||||
|
EmptyExpression
|
||||||
|
UWhileExpression
|
||||||
|
UBinaryExpression (>)
|
||||||
|
USimpleReferenceExpression (a)
|
||||||
|
ULiteralExpression (0)
|
||||||
|
UBlockExpression
|
||||||
|
UIfExpression
|
||||||
|
UBinaryExpression (===)
|
||||||
|
USimpleReferenceExpression (a)
|
||||||
|
ULiteralExpression (3)
|
||||||
|
UBlockExpression
|
||||||
|
USpecialExpressionList (break)
|
||||||
|
|
||||||
|
EmptyExpression
|
||||||
|
UIfExpression
|
||||||
|
UBinaryExpression (===)
|
||||||
|
UBinaryExpression (%)
|
||||||
|
USimpleReferenceExpression (a)
|
||||||
|
ULiteralExpression (5)
|
||||||
|
ULiteralExpression (0)
|
||||||
|
UBlockExpression
|
||||||
|
USpecialExpressionList (continue)
|
||||||
|
|
||||||
|
EmptyExpression
|
||||||
|
UPostfixExpression (--)
|
||||||
|
USimpleReferenceExpression (a)
|
||||||
|
UQualifiedExpression
|
||||||
|
UThisExpression
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 0)
|
||||||
|
USimpleReferenceExpression (test)
|
||||||
|
|
||||||
|
UQualifiedExpression
|
||||||
|
USuperExpression
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 0)
|
||||||
|
USimpleReferenceExpression (hashCode)
|
||||||
|
|
||||||
|
UDeclarationsExpression
|
||||||
|
UVariable (x, kind = local)
|
||||||
|
EmptyExpression
|
||||||
|
USwitchExpression
|
||||||
|
USimpleReferenceExpression (a)
|
||||||
|
UBlockExpression
|
||||||
|
UExpressionSwitchClauseExpression
|
||||||
|
ULiteralExpression (1)
|
||||||
|
UBlockExpression
|
||||||
|
UAssignmentExpression (=)
|
||||||
|
USimpleReferenceExpression (x)
|
||||||
|
ULiteralExpression ("1")
|
||||||
|
USpecialExpressionList (break)
|
||||||
|
|
||||||
|
UExpressionSwitchClauseExpression
|
||||||
|
ULiteralExpression (3)
|
||||||
|
UAssignmentExpression (=)
|
||||||
|
USimpleReferenceExpression (x)
|
||||||
|
ULiteralExpression ("3")
|
||||||
|
UExpressionSwitchClauseExpression
|
||||||
|
ULiteralExpression (4)
|
||||||
|
UAssignmentExpression (=)
|
||||||
|
USimpleReferenceExpression (x)
|
||||||
|
ULiteralExpression ("4")
|
||||||
|
UDefaultSwitchClause
|
||||||
|
UAssignmentExpression (=)
|
||||||
|
USimpleReferenceExpression (x)
|
||||||
|
ULiteralExpression ("")
|
||||||
|
UIfExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (System)
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 2)
|
||||||
|
USimpleReferenceExpression (getProperty)
|
||||||
|
ULiteralExpression ("abc")
|
||||||
|
ULiteralExpression ("")
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||||
|
USimpleReferenceExpression (equals)
|
||||||
|
ULiteralExpression ("1")
|
||||||
|
UBlockExpression
|
||||||
|
USpecialExpressionList (throw)
|
||||||
|
UFunctionCallExpression (CONSTRUCTOR_CALL, argCount = 1)
|
||||||
|
<no element>
|
||||||
|
ULiteralExpression ("Err")
|
||||||
|
EmptyExpression
|
||||||
|
UTryExpression
|
||||||
|
UBlockExpression
|
||||||
|
UQualifiedExpression
|
||||||
|
USimpleReferenceExpression (Thread)
|
||||||
|
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||||
|
USimpleReferenceExpression (sleep)
|
||||||
|
ULiteralExpression (1000) UCatchClause
|
||||||
|
UBlockExpression
|
||||||
|
UBlockExpression
|
||||||
|
UAssignmentExpression (=)
|
||||||
|
USimpleReferenceExpression (a)
|
||||||
|
ULiteralExpression (3)
|
||||||
|
UBlockExpression
|
||||||
|
UAssignmentExpression (=)
|
||||||
|
USimpleReferenceExpression (a)
|
||||||
|
ULiteralExpression (5)
|
||||||
|
USpecialExpressionList (return)
|
||||||
|
ULiteralExpression (true)
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
default class _Dummy_ {
|
||||||
|
default inner class ControlStructures {
|
||||||
|
public fun main(args: java.lang.String[]): void {
|
||||||
|
if (args.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var mode: String = (args.length === 1) ? ("singleArg") : ("multiArgs")
|
||||||
|
for (arg : args) {
|
||||||
|
System.out.println(arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i: int = 0; i < args.length; ++i) {
|
||||||
|
System.out.println(i + ": " + args[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
var i: int = 0
|
||||||
|
while (i < args.length) {
|
||||||
|
System.out.println("Index " + i)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
do {
|
||||||
|
System.out.println(i)
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
while (i < args.length)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
default class _Dummy_ {
|
||||||
|
default inner class Lambda {
|
||||||
|
default fun example(): void {
|
||||||
|
doJob({ arg: String ->
|
||||||
|
arg + arg
|
||||||
|
}, "Mary")
|
||||||
|
}
|
||||||
|
|
||||||
|
default fun doJob(job: Job, arg: String): void {
|
||||||
|
System.out.println(job.doJob(arg))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
default abstract interface Job {
|
||||||
|
public fun doJob(arg: String): String = EmptyExpression
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
default class _Dummy_ {
|
||||||
|
default inner class NestedClasses {
|
||||||
|
public class Nested {
|
||||||
|
default fun func1(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public inner class Inner {
|
||||||
|
default fun func2(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
default class _Dummy_ {
|
||||||
|
default inner class Simple {
|
||||||
|
var name: String
|
||||||
|
|
||||||
|
public fun Simple(name: String) {
|
||||||
|
this.name = name
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun getName(): String {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun setName(name: String): void {
|
||||||
|
this.name = name
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
default class _Dummy_ {
|
||||||
|
default inner class SpecialExpressions {
|
||||||
|
default fun test(): boolean {
|
||||||
|
assert 5 > 3 : EmptyExpression
|
||||||
|
assert 5 > 3 : "Message"
|
||||||
|
synchronized this : {
|
||||||
|
System.out.println("A")
|
||||||
|
}
|
||||||
|
|
||||||
|
var a: int = 5
|
||||||
|
var b: int = 7
|
||||||
|
var c: int
|
||||||
|
while (a > 0) {
|
||||||
|
if (a === 3) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a % 5 === 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
a--
|
||||||
|
}
|
||||||
|
|
||||||
|
this.test()
|
||||||
|
super.hashCode()
|
||||||
|
var x: String
|
||||||
|
switch (a)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
x = "1"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
x = "3"
|
||||||
|
case 4:
|
||||||
|
x = "4"
|
||||||
|
else:
|
||||||
|
x = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (System.getProperty("abc", "").equals("1")) {
|
||||||
|
throw <noref>("Err")
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
finally {
|
||||||
|
a = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
a = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
||||||
|
<orderEntry type="module" module-name="uast-common" />
|
||||||
|
<orderEntry type="library" name="intellij-core" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="idea-full" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
Reference in New Issue
Block a user