diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/JavaConverter.kt b/plugins/uast-java/src/org/jetbrains/uast/java/JavaConverter.kt new file mode 100644 index 00000000000..fb8c8319037 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/JavaConverter.kt @@ -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 ?: "" + val element = expression.referenceNameElement ?: expression + JavaUSimpleReferenceExpression(element, name, parent) + } + } + + internal fun convert(expression: PsiQualifiedReferenceElement, parent: UElement): UExpression { + val referenceName = expression.referenceName ?: "" + 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, parent: UElement): SimpleUDeclarationsExpression { + val uelements = arrayListOf() + return SimpleUDeclarationsExpression(parent, uelements).apply { + for (element in elements) { + convert(element, this)?.let { uelements += it } + } + } + } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUDoWhileExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUDoWhileExpression.kt new file mode 100644 index 00000000000..9c542dac970 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUDoWhileExpression.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUForEachExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUForEachExpression.kt new file mode 100644 index 00000000000..9369fb62307 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUForEachExpression.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUForExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUForExpression.kt new file mode 100644 index 00000000000..f8c25d295be --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUForExpression.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUIfExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUIfExpression.kt new file mode 100644 index 00000000000..2f198a8ce6a --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUIfExpression.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUSpecialExpressionList.kt b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUSpecialExpressionList.kt new file mode 100644 index 00000000000..7b65d0e8f12 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUSpecialExpressionList.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUSwitchExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUSwitchExpression.kt new file mode 100644 index 00000000000..5d646acffb5 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUSwitchExpression.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUTernaryIfExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUTernaryIfExpression.kt new file mode 100644 index 00000000000..fe444353d90 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUTernaryIfExpression.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUTryExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUTryExpression.kt new file mode 100644 index 00000000000..6bce93015f3 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUTryExpression.kt @@ -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)) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUWhileExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUWhileExpression.kt new file mode 100644 index 00000000000..947e7a0d195 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUWhileExpression.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaClassInitializerUFunction.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaClassInitializerUFunction.kt new file mode 100644 index 00000000000..8eedcf5aa5a --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaClassInitializerUFunction.kt @@ -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() + override val valueParameterCount = 0 + override val typeParameters = emptyList() + 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 = "" + + override fun getSuperFunctions(context: UastContext) = emptyList() +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaParameterUTypeReference.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaParameterUTypeReference.kt new file mode 100644 index 00000000000..62fefa58539 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaParameterUTypeReference.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUAnnotation.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUAnnotation.kt new file mode 100644 index 00000000000..f6422a82c8e --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUAnnotation.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUClass.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUClass.kt new file mode 100644 index 00000000000..390372da593 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUClass.kt @@ -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() + 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() + val variables = ArrayList(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() + + override val nameElement = null + override val name = "" +} + +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" +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUFile.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUFile.kt new file mode 100644 index 00000000000..076cb2191ee --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUFile.kt @@ -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 by lz { + val importList = psi.importList ?: return@lz emptyList() + importList.importStatements.map { JavaConverter.convert(it, this) }.filterNotNull() + } + + override val declarations by lz { psi.classes.map { JavaUClass(it, this) } } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUFunction.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUFunction.kt new file mode 100644 index 00000000000..a28d17dd90c --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUFunction.kt @@ -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) "" 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 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 { + return psi.findSuperMethods().map { context.convert(it) as? UFunction }.filterNotNull() + } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUImportStatement.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUImportStatement.kt new file mode 100644 index 00000000000..15e52810b93 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUImportStatement.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUStaticImportStatement.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUStaticImportStatement.kt new file mode 100644 index 00000000000..6d1cb7bc5f1 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUStaticImportStatement.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUType.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUType.kt new file mode 100644 index 00000000000..6360e19e483 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUType.kt @@ -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 + } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUVariable.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUVariable.kt new file mode 100644 index 00000000000..8bb3e2758cf --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUVariable.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaValueParameterUVariable.kt b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaValueParameterUVariable.kt new file mode 100644 index 00000000000..dcb22db558b --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaValueParameterUVariable.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaCombinedUBinaryExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaCombinedUBinaryExpression.kt new file mode 100644 index 00000000000..4795658f3a7 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaCombinedUBinaryExpression.kt @@ -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() +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaPsiElementStub.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaPsiElementStub.kt new file mode 100644 index 00000000000..795e22bd779 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaPsiElementStub.kt @@ -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() = "" +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUArrayAccessExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUArrayAccessExpression.kt new file mode 100644 index 00000000000..147e1669e1b --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUArrayAccessExpression.kt @@ -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)) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUAssignmentExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUAssignmentExpression.kt new file mode 100644 index 00000000000..8eda60aa964 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUAssignmentExpression.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUBinaryExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUBinaryExpression.kt new file mode 100644 index 00000000000..71c7187859a --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUBinaryExpression.kt @@ -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() } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUBlockExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUBlockExpression.kt new file mode 100644 index 00000000000..275f7bccc6a --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUBlockExpression.kt @@ -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) } } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCallableReferenceExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCallableReferenceExpression.kt new file mode 100644 index 00000000000..bd6aa2dfb31 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCallableReferenceExpression.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUClassLiteralExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUClassLiteralExpression.kt new file mode 100644 index 00000000000..ca60d815043 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUClassLiteralExpression.kt @@ -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 \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCodeBlockExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCodeBlockExpression.kt new file mode 100644 index 00000000000..4f4bea20b7d --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCodeBlockExpression.kt @@ -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) } } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCompositeQualifiedExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCompositeQualifiedExpression.kt new file mode 100644 index 00000000000..5152a0f1218 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCompositeQualifiedExpression.kt @@ -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") +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUInstanceCheckExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUInstanceCheckExpression.kt new file mode 100644 index 00000000000..172fb029333 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUInstanceCheckExpression.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULabeledExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULabeledExpression.kt new file mode 100644 index 00000000000..758482e3041 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULabeledExpression.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULambdaExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULambdaExpression.kt new file mode 100644 index 00000000000..477df9b9f17 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULambdaExpression.kt @@ -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) + } + } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULiteralExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULiteralExpression.kt new file mode 100644 index 00000000000..c68783f5832 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULiteralExpression.kt @@ -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" +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUObjectLiteralExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUObjectLiteralExpression.kt new file mode 100644 index 00000000000..8d71f6bedc6 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUObjectLiteralExpression.kt @@ -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 + } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUParenthesizedExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUParenthesizedExpression.kt new file mode 100644 index 00000000000..5c9eb4a3f85 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUParenthesizedExpression.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUPostfixExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUPostfixExpression.kt new file mode 100644 index 00000000000..070bc41b90a --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUPostfixExpression.kt @@ -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 + } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUPrefixExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUPrefixExpression.kt new file mode 100644 index 00000000000..e1592ebe542 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUPrefixExpression.kt @@ -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 + } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUQualifiedExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUQualifiedExpression.kt new file mode 100644 index 00000000000..99303d88473 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUQualifiedExpression.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUSimpleReferenceExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUSimpleReferenceExpression.kt new file mode 100644 index 00000000000..10ebcbf76b0 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUSimpleReferenceExpression.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUSuperExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUSuperExpression.kt new file mode 100644 index 00000000000..5b83f0a3aca --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUSuperExpression.kt @@ -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 \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUThisExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUThisExpression.kt new file mode 100644 index 00000000000..763f5968b2f --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUThisExpression.kt @@ -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 \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUTypeCastExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUTypeCastExpression.kt new file mode 100644 index 00000000000..347ce99ec8e --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUTypeCastExpression.kt @@ -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 +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/UnknownJavaExpression.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/UnknownJavaExpression.kt new file mode 100644 index 00000000000..58ac668a369 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/UnknownJavaExpression.kt @@ -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)" +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/javaHelpers.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/javaHelpers.kt new file mode 100644 index 00000000000..dc1bbee4879 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/javaHelpers.kt @@ -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) } +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/javaUCallExpressions.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/javaUCallExpressions.kt new file mode 100644 index 00000000000..f63867414bd --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/javaUCallExpressions.kt @@ -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 ?: "" + + 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) + "" + else if (psi.arrayDimensions.isNotEmpty()) + "" + 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 = "" + 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() + + 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 = "" + 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() + + override fun resolve(context: UastContext) = null +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/internal/javaInternalUastUtils.kt b/plugins/uast-java/src/org/jetbrains/uast/java/internal/javaInternalUastUtils.kt new file mode 100644 index 00000000000..d578f1f012d --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/internal/javaInternalUastUtils.kt @@ -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 { + 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 singletonListOrEmpty(element: T?) = if (element != null) listOf(element) else emptyList() + +@Suppress("NOTHING_TO_INLINE") +internal inline fun String?.orAnonymous(kind: String = ""): String { + return this ?: "" +} + +internal fun runReadAction(action: () -> T): T { + return ApplicationManager.getApplication().runReadAction(action) +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/internal/lz.kt b/plugins/uast-java/src/org/jetbrains/uast/java/internal/lz.kt new file mode 100644 index 00000000000..2ac026a6b2b --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/internal/lz.kt @@ -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 lz(initializer: () -> T): ReadOnlyProperty = UnsafeLazyInsideReadAction(initializer, false) + +private class UnsafeLazyInsideReadAction(initializer: () -> T, private val readAction: Boolean) : ReadOnlyProperty { + 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 \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaSpecialExpressionKinds.kt b/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaSpecialExpressionKinds.kt new file mode 100644 index 00000000000..78eede2ba8b --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaSpecialExpressionKinds.kt @@ -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") +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastCallKinds.kt b/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastCallKinds.kt new file mode 100644 index 00000000000..0df6bd91778 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastCallKinds.kt @@ -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") +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastModifiers.kt b/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastModifiers.kt new file mode 100644 index 00000000000..62b01c8c578 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastModifiers.kt @@ -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") +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastVisibilities.kt b/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastVisibilities.kt new file mode 100644 index 00000000000..b570519d054 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastVisibilities.kt @@ -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") +} \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/psi/PsiElementBacked.kt b/plugins/uast-java/src/org/jetbrains/uast/psi/PsiElementBacked.kt new file mode 100644 index 00000000000..5f355f160e6 --- /dev/null +++ b/plugins/uast-java/src/org/jetbrains/uast/psi/PsiElementBacked.kt @@ -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? +} \ No newline at end of file diff --git a/plugins/uast-java/test/org/jetbrains/uast/AbstractStructureTest.kt b/plugins/uast-java/test/org/jetbrains/uast/AbstractStructureTest.kt new file mode 100644 index 00000000000..28971cd2a2a --- /dev/null +++ b/plugins/uast-java/test/org/jetbrains/uast/AbstractStructureTest.kt @@ -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") +} \ No newline at end of file diff --git a/plugins/uast-java/test/org/jetbrains/uast/StructureTest.kt b/plugins/uast-java/test/org/jetbrains/uast/StructureTest.kt new file mode 100644 index 00000000000..97f1333396d --- /dev/null +++ b/plugins/uast-java/test/org/jetbrains/uast/StructureTest.kt @@ -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") +} \ No newline at end of file diff --git a/plugins/uast-java/testData/ControlStructures.java b/plugins/uast-java/testData/ControlStructures.java new file mode 100644 index 00000000000..3c18b0665ce --- /dev/null +++ b/plugins/uast-java/testData/ControlStructures.java @@ -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); + } +} diff --git a/plugins/uast-java/testData/Lambda.java b/plugins/uast-java/testData/Lambda.java new file mode 100644 index 00000000000..9d4a9f0fba7 --- /dev/null +++ b/plugins/uast-java/testData/Lambda.java @@ -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); +} \ No newline at end of file diff --git a/plugins/uast-java/testData/NestedClasses.java b/plugins/uast-java/testData/NestedClasses.java new file mode 100644 index 00000000000..211405f502b --- /dev/null +++ b/plugins/uast-java/testData/NestedClasses.java @@ -0,0 +1,13 @@ +class NestedClasses { + public static class Nested { + void func1() { + + } + } + + public class Inner { + void func2() { + + } + } +} \ No newline at end of file diff --git a/plugins/uast-java/testData/Simple.java b/plugins/uast-java/testData/Simple.java new file mode 100644 index 00000000000..e56e521dae8 --- /dev/null +++ b/plugins/uast-java/testData/Simple.java @@ -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; + } +} \ No newline at end of file diff --git a/plugins/uast-java/testData/SpecialExpressions.java b/plugins/uast-java/testData/SpecialExpressions.java new file mode 100644 index 00000000000..157e8374047 --- /dev/null +++ b/plugins/uast-java/testData/SpecialExpressions.java @@ -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; + } +} \ No newline at end of file diff --git a/plugins/uast-java/testData/log/ControlStructures.txt b/plugins/uast-java/testData/log/ControlStructures.txt new file mode 100644 index 00000000000..2c64a7de5f7 --- /dev/null +++ b/plugins/uast-java/testData/log/ControlStructures.txt @@ -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) \ No newline at end of file diff --git a/plugins/uast-java/testData/log/Lambda.txt b/plugins/uast-java/testData/log/Lambda.txt new file mode 100644 index 00000000000..b67dae3402b --- /dev/null +++ b/plugins/uast-java/testData/log/Lambda.txt @@ -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) + + 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 \ No newline at end of file diff --git a/plugins/uast-java/testData/log/NestedClasses.txt b/plugins/uast-java/testData/log/NestedClasses.txt new file mode 100644 index 00000000000..d7582c99731 --- /dev/null +++ b/plugins/uast-java/testData/log/NestedClasses.txt @@ -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 + \ No newline at end of file diff --git a/plugins/uast-java/testData/log/Simple.txt b/plugins/uast-java/testData/log/Simple.txt new file mode 100644 index 00000000000..8e277c53c9e --- /dev/null +++ b/plugins/uast-java/testData/log/Simple.txt @@ -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) \ No newline at end of file diff --git a/plugins/uast-java/testData/log/SpecialExpressions.txt b/plugins/uast-java/testData/log/SpecialExpressions.txt new file mode 100644 index 00000000000..2ce98d7fa93 --- /dev/null +++ b/plugins/uast-java/testData/log/SpecialExpressions.txt @@ -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) + + 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) \ No newline at end of file diff --git a/plugins/uast-java/testData/render/ControlStructures.txt b/plugins/uast-java/testData/render/ControlStructures.txt new file mode 100644 index 00000000000..daf9a294e75 --- /dev/null +++ b/plugins/uast-java/testData/render/ControlStructures.txt @@ -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) + + } + + } +} diff --git a/plugins/uast-java/testData/render/Lambda.txt b/plugins/uast-java/testData/render/Lambda.txt new file mode 100644 index 00000000000..87eeb5d3e65 --- /dev/null +++ b/plugins/uast-java/testData/render/Lambda.txt @@ -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 + } +} \ No newline at end of file diff --git a/plugins/uast-java/testData/render/NestedClasses.txt b/plugins/uast-java/testData/render/NestedClasses.txt new file mode 100644 index 00000000000..155a1de6d15 --- /dev/null +++ b/plugins/uast-java/testData/render/NestedClasses.txt @@ -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 { + } + + } + } +} diff --git a/plugins/uast-java/testData/render/Simple.txt b/plugins/uast-java/testData/render/Simple.txt new file mode 100644 index 00000000000..5727e7fdbaf --- /dev/null +++ b/plugins/uast-java/testData/render/Simple.txt @@ -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 + } + + } +} diff --git a/plugins/uast-java/testData/render/SpecialExpressions.txt b/plugins/uast-java/testData/render/SpecialExpressions.txt new file mode 100644 index 00000000000..2120337706a --- /dev/null +++ b/plugins/uast-java/testData/render/SpecialExpressions.txt @@ -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 ("Err") + } + + try { + Thread.sleep(1000) + } + + catch (e) { + } + + finally { + a = 3 + } + + { + a = 5 + } + + return true + } + + } +} diff --git a/plugins/uast-java/uast-java.iml b/plugins/uast-java/uast-java.iml new file mode 100644 index 00000000000..168b983caf1 --- /dev/null +++ b/plugins/uast-java/uast-java.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file