diff --git a/plugins/lint/lint-api/src/com/android/tools/klint/client/api/LintDriver.java b/plugins/lint/lint-api/src/com/android/tools/klint/client/api/LintDriver.java index 6ee62e11931..a1fc93aaa7b 100644 --- a/plugins/lint/lint-api/src/com/android/tools/klint/client/api/LintDriver.java +++ b/plugins/lint/lint-api/src/com/android/tools/klint/client/api/LintDriver.java @@ -1504,8 +1504,8 @@ public class LintDriver { continue; } - String path = file.getPath(); - if (!path.endsWith(DOT_JAVA) && !UastConverterUtils.isFileSupported(plugins, path)) { + String filename = file.getName(); + if (!filename.endsWith(DOT_JAVA) && !UastConverterUtils.isFileSupported(plugins, filename)) { continue; } diff --git a/plugins/lint/lint-api/src/com/android/tools/klint/client/api/LintLanguageExtension.java b/plugins/lint/lint-api/src/com/android/tools/klint/client/api/LintLanguageExtension.java index be8f888751b..ecaa04efe7d 100644 --- a/plugins/lint/lint-api/src/com/android/tools/klint/client/api/LintLanguageExtension.java +++ b/plugins/lint/lint-api/src/com/android/tools/klint/client/api/LintLanguageExtension.java @@ -29,10 +29,10 @@ public abstract class LintLanguageExtension implements UastLanguagePlugin { public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.android.tools.klint.client.api.lintLanguageExtension"); - public static boolean isFileSupported(@Nullable Project project, String path) { + public static boolean isFileSupported(@Nullable Project project, String name) { LintLanguageExtension[] extensions = getExtensions(project); for (LintLanguageExtension ext : extensions) { - if (ext.getConverter().isFileSupported(path)) { + if (ext.getConverter().isFileSupported(name)) { return true; } } diff --git a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/AppCompatCallDetector.java b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/AppCompatCallDetector.java index 99754d2224d..c6bd5cbe2e4 100644 --- a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/AppCompatCallDetector.java +++ b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/AppCompatCallDetector.java @@ -96,24 +96,23 @@ public class AppCompatCallDetector extends Detector implements UastScanner { @Override public void visitFunctionCall(UastAndroidContext context, UCallExpression node) { if (mDependsOnAppCompat && isAppBarActivityCall(context, node)) { - String name = node.getFunctionName(); String replace = null; - if (GET_ACTION_BAR.equals(name)) { + if (node.functionNameMatches(GET_ACTION_BAR)) { replace = "getSupportActionBar"; - } else if (START_ACTION_MODE.equals(name)) { + } else if (node.functionNameMatches(START_ACTION_MODE)) { replace = "startSupportActionMode"; - } else if (SET_PROGRESS_BAR_VIS.equals(name)) { + } else if (node.functionNameMatches(SET_PROGRESS_BAR_VIS)) { replace = "setSupportProgressBarVisibility"; - } else if (SET_PROGRESS_BAR_IN_VIS.equals(name)) { + } else if (node.functionNameMatches(SET_PROGRESS_BAR_IN_VIS)) { replace = "setSupportProgressBarIndeterminateVisibility"; - } else if (SET_PROGRESS_BAR_INDETERMINATE.equals(name)) { + } else if (node.functionNameMatches(SET_PROGRESS_BAR_INDETERMINATE)) { replace = "setSupportProgressBarIndeterminate"; - } else if (REQUEST_WINDOW_FEATURE.equals(name)) { + } else if (node.functionNameMatches(REQUEST_WINDOW_FEATURE)) { replace = "supportRequestWindowFeature"; } if (replace != null) { - String message = String.format(ERROR_MESSAGE_FORMAT, replace, name); + String message = String.format(ERROR_MESSAGE_FORMAT, replace, node.getFunctionName()); context.report(ISSUE, node, UastAndroidUtils.getLocation(node), message); } } diff --git a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/CipherGetInstanceDetector.java b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/CipherGetInstanceDetector.java index 39a44036002..06a49cd44e2 100644 --- a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/CipherGetInstanceDetector.java +++ b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/CipherGetInstanceDetector.java @@ -83,7 +83,7 @@ public class CipherGetInstanceDetector extends Detector implements UastScanner { UExpression expression = argumentList.get(0); if (expression instanceof ULiteralExpression) { ULiteralExpression argument = (ULiteralExpression)expression; - String parameter = argument.getText(); + String parameter = argument.asString(); checkParameter(context, node, argument, parameter, false); } else if (expression instanceof UResolvable) { UDeclaration declaration = ((UResolvable)expression).resolve(context); diff --git a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/CleanupDetector.java b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/CleanupDetector.java index b1adeea5c4e..ccec93db878 100644 --- a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/CleanupDetector.java +++ b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/CleanupDetector.java @@ -157,11 +157,10 @@ public class CleanupDetector extends Detector implements UastScanner { @Override public void visitFunctionCall(UastAndroidContext context, UCallExpression node) { - String name = node.getFunctionName(); - if (BEGIN_TRANSACTION.equals(name)) { + if (node.functionNameMatches(BEGIN_TRANSACTION)) { checkTransactionCommits(context, node); } else { - checkResourceRecycled(context, node, name); + checkResourceRecycled(context, node, node.getFunctionName()); } } @@ -246,8 +245,7 @@ public class CleanupDetector extends Detector implements UastScanner { FinishVisitor visitor = new FinishVisitor(context, boundVariable) { @Override protected boolean isCleanupCall(@NonNull UCallExpression call) { - String methodName = call.getFunctionName(); - if (!recycleName.equals(methodName)) { + if (!call.functionNameMatches(recycleName)) { return false; } UDeclaration resolved = call.resolve(mContext); @@ -385,8 +383,7 @@ public class CleanupDetector extends Detector implements UastScanner { private static boolean isTransactionCommitMethodCall(@NonNull UastAndroidContext context, @NonNull UCallExpression call) { - String methodName = call.getFunctionName(); - return (COMMIT.equals(methodName) || COMMIT_ALLOWING_LOSS.equals(methodName)) && + return (call.functionNameMatches(COMMIT) || call.functionNameMatches(COMMIT_ALLOWING_LOSS)) && isMethodOnFragmentClass(context, call, FRAGMENT_TRANSACTION_CLS, FRAGMENT_TRANSACTION_V4_CLS); @@ -394,8 +391,7 @@ public class CleanupDetector extends Detector implements UastScanner { private static boolean isShowFragmentMethodCall(@NonNull UastAndroidContext context, @NonNull UCallExpression call) { - String methodName = call.getFunctionName(); - return SHOW.equals(methodName) + return call.functionNameMatches(SHOW) && isMethodOnFragmentClass(context, call, DIALOG_FRAGMENT, DIALOG_V4_FRAGMENT); } @@ -439,9 +435,8 @@ public class CleanupDetector extends Detector implements UastScanner { private static boolean isBeginTransaction(@NonNull UastAndroidContext context, @NonNull UCallExpression node) { - String methodName = node.getFunctionName(); - assert BEGIN_TRANSACTION.equals(methodName) : methodName; - if (BEGIN_TRANSACTION.equals(methodName)) { + assert node.functionNameMatches(BEGIN_TRANSACTION) : node.renderString(); + if (node.functionNameMatches(BEGIN_TRANSACTION)) { UFunction method = node.resolve(context); if (method != null) { UClass containingClass = UastUtils.getContainingClassOrEmpty(method); diff --git a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/SupportAnnotationDetector.java b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/SupportAnnotationDetector.java index 68c1bc18e32..1d83b8f73bb 100644 --- a/plugins/lint/lint-checks/src/com/android/tools/klint/checks/SupportAnnotationDetector.java +++ b/plugins/lint/lint-checks/src/com/android/tools/klint/checks/SupportAnnotationDetector.java @@ -46,6 +46,7 @@ import com.android.utils.XmlUtils; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import kotlin.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.uast.*; import org.jetbrains.uast.check.UastAndroidContext; @@ -1103,9 +1104,9 @@ public class SupportAnnotationDetector extends Detector implements UastScanner { private static void checkTypeDefConstant(@NonNull UastAndroidContext context, @NonNull UAnnotation annotation, @NonNull UElement argument, @Nullable UElement errorNode, boolean flag, Object value) { - List valueArguments = annotation.getValues(); - for (Object o : valueArguments) { - if (o.equals(value)) { + List> valueArguments = annotation.getValues(); + for (Pair o : valueArguments) { + if (o.getSecond().equals(value)) { return; } } @@ -1115,12 +1116,12 @@ public class SupportAnnotationDetector extends Detector implements UastScanner { private static void reportTypeDef(@NonNull UastAndroidContext context, @NonNull UAnnotation annotation, @NonNull UElement argument, @Nullable UElement errorNode) { - List allowed = annotation.getValues(); + List> allowed = annotation.getValues(); reportTypeDef(context, argument, errorNode, false, allowed); } private static void reportTypeDef(@NonNull UastAndroidContext context, @NonNull UElement node, - @Nullable UElement errorNode, boolean flag, @NonNull List allowedValues) { + @Nullable UElement errorNode, boolean flag, @NonNull List> allowedValues) { String values = listAllowedValues(allowedValues); String message; if (flag) { @@ -1134,9 +1135,10 @@ public class SupportAnnotationDetector extends Detector implements UastScanner { context.report(TYPE_DEF, errorNode, context.getLocation(errorNode), message); } - private static String listAllowedValues(@NonNull List allowedValues) { + private static String listAllowedValues(@NonNull List> allowedValues) { StringBuilder sb = new StringBuilder(); - for (Object allowedValue : allowedValues) { + for (Pair namedValue : allowedValues) { + Object allowedValue = namedValue.getSecond(); String s; if (allowedValue instanceof Integer) { s = allowedValue.toString(); diff --git a/plugins/lint/lint-idea/src/org/jetbrains/android/inspections/klint/AndroidLintExternalAnnotator.java b/plugins/lint/lint-idea/src/org/jetbrains/android/inspections/klint/AndroidLintExternalAnnotator.java index 4478953f0d9..6f2ff8ed248 100644 --- a/plugins/lint/lint-idea/src/org/jetbrains/android/inspections/klint/AndroidLintExternalAnnotator.java +++ b/plugins/lint/lint-idea/src/org/jetbrains/android/inspections/klint/AndroidLintExternalAnnotator.java @@ -145,7 +145,7 @@ public class AndroidLintExternalAnnotator extends ExternalAnnotator, path: String): Boolean { - return converters.any { it.converter.isFileSupported(path) } + fun isFileSupported(converters: List, name: String): Boolean { + return converters.any { it.converter.isFileSupported(name) } } } \ No newline at end of file diff --git a/plugins/uast-common/src/org/jetbrains/uast/UastVisitor.kt b/plugins/uast-common/src/org/jetbrains/uast/UastVisitor.kt index 5b7e7b06017..366c99e14c9 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/UastVisitor.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/UastVisitor.kt @@ -34,7 +34,6 @@ abstract class UastVisitor { open fun visitQualifiedExpression(node: UQualifiedExpression): Boolean = false open fun visitSimpleReferenceExpression(node: USimpleReferenceExpression): Boolean = false open fun visitCallExpression(node: UCallExpression): Boolean = false - open fun visitAssignmentExpression(node: UAssignmentExpression): Boolean = false open fun visitBinaryExpression(node: UBinaryExpression): Boolean = false open fun visitBinaryExpressionWithType(node: UBinaryExpressionWithType): Boolean = false open fun visitParenthesizedExpression(node: UParenthesizedExpression): Boolean = false @@ -80,7 +79,6 @@ abstract class UastVisitor { is UQualifiedExpression -> visitQualifiedExpression(node) is USimpleReferenceExpression -> visitSimpleReferenceExpression(node) is UCallExpression -> visitCallExpression(node) - is UAssignmentExpression -> visitAssignmentExpression(node) is UBinaryExpression -> visitBinaryExpression(node) is UBinaryExpressionWithType -> visitBinaryExpressionWithType(node) is UParenthesizedExpression -> visitParenthesizedExpression(node) diff --git a/plugins/uast-common/src/org/jetbrains/uast/baseElements/UAnnotation.kt b/plugins/uast-common/src/org/jetbrains/uast/baseElements/UAnnotation.kt index 4efb24d131b..0763b24df25 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/baseElements/UAnnotation.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/baseElements/UAnnotation.kt @@ -20,7 +20,8 @@ interface UAnnotation : UElement, UNamed, UFqNamed, LeafUElement { val valueArguments: List fun getValue(name: String) = valueArguments.firstOrNull { it.name == name }?.expression?.evaluate() - fun getValues() = valueArguments.map { it.expression.evaluate() } + + fun getValues() = valueArguments.map { Pair(it.name, it.expression.evaluate()) } override fun logString() = log("UAnnotation ($name)") override fun renderString() = if (valueArguments.isEmpty()) "@$name" else "@$name(" + diff --git a/plugins/uast-common/src/org/jetbrains/uast/baseElements/UElement.kt b/plugins/uast-common/src/org/jetbrains/uast/baseElements/UElement.kt index 69d133e921f..02809eacee2 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/baseElements/UElement.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/baseElements/UElement.kt @@ -17,6 +17,10 @@ package org.jetbrains.uast interface UElement { val parent: UElement? + + open val isValid: Boolean + get() = true + fun logString(): String fun renderString(): String = logString() fun traverse(callback: UastCallback) diff --git a/plugins/uast-common/src/org/jetbrains/uast/baseElements/UExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/baseElements/UExpression.kt index 962087e2c23..d95c6d125e8 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/baseElements/UExpression.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/baseElements/UExpression.kt @@ -16,15 +16,11 @@ package org.jetbrains.uast interface UExpression : UElement { - fun evaluate(): Any? + open fun evaluate(): Any? = null fun evaluateString(): String? = evaluate() as? String fun getExpressionType(): UType? = null } -interface NoEvaluate : UExpression { - override fun evaluate() = null -} - interface NoAnnotations : UAnnotated { override val annotations: List get() = emptyList() @@ -34,6 +30,6 @@ interface NoModifiers : UModifierOwner { override fun hasModifier(modifier: UastModifier) = false } -class EmptyExpression(override val parent: UElement) : UExpression, LeafUElement, NoEvaluate { +class EmptyExpression(override val parent: UElement) : UExpression, LeafUElement { override fun logString() = "EmptyExpression" } \ No newline at end of file diff --git a/plugins/uast-common/src/org/jetbrains/uast/expressions/UForEachExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/controlStructures/UForEachExpression.kt similarity index 81% rename from plugins/uast-common/src/org/jetbrains/uast/expressions/UForEachExpression.kt rename to plugins/uast-common/src/org/jetbrains/uast/controlStructures/UForEachExpression.kt index f355c9bc69c..a1494130920 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/expressions/UForEachExpression.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/controlStructures/UForEachExpression.kt @@ -16,24 +16,23 @@ package org.jetbrains.uast interface UForEachExpression : ULoopExpression { - val variableName: String? + val variable: UVariable val iteratedValue: UExpression override fun traverse(callback: UastCallback) { + variable.handleTraverse(callback) iteratedValue.handleTraverse(callback) body.handleTraverse(callback) } override fun renderString() = buildString { append("for (") - append(variableName ?: "") + append(variable.name) append(" : ") append(iteratedValue.renderString()) append(") ") append(body.renderString()) } - override fun logString() = "UForEachExpression ($variableName)\n" + - iteratedValue.logString().withMargin + "\n" + - body.logString().withMargin + override fun logString() = log("UForEachExpression", variable, iteratedValue, body) } diff --git a/plugins/uast-common/src/org/jetbrains/uast/expressions/ULoopExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/controlStructures/ULoopExpression.kt similarity index 100% rename from plugins/uast-common/src/org/jetbrains/uast/expressions/ULoopExpression.kt rename to plugins/uast-common/src/org/jetbrains/uast/controlStructures/ULoopExpression.kt diff --git a/plugins/uast-common/src/org/jetbrains/uast/controlStructures/USwitchExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/controlStructures/USwitchExpression.kt index 67b603a285d..57ce6b56b47 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/controlStructures/USwitchExpression.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/controlStructures/USwitchExpression.kt @@ -51,4 +51,4 @@ interface UDefaultSwitchClauseExpression : USwitchClauseExpression { override fun renderString() = "else -> " } -class SimpleUDefaultSwitchClauseExpression(override val parent: UElement) : UDefaultSwitchClauseExpression, NoEvaluate \ No newline at end of file +class SimpleUDefaultSwitchClauseExpression(override val parent: UElement) : UDefaultSwitchClauseExpression \ No newline at end of file diff --git a/plugins/uast-common/src/org/jetbrains/uast/controlStructures/UTryExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/controlStructures/UTryExpression.kt index 981f49b1ac6..11ba98bb1da 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/controlStructures/UTryExpression.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/controlStructures/UTryExpression.kt @@ -22,6 +22,7 @@ interface UTryExpression : UExpression { val finallyClause: UExpression? override fun traverse(callback: UastCallback) { + resources?.handleTraverseList(callback) tryClause.handleTraverse(callback) catchClauses.handleTraverseList(callback) finallyClause?.handleTraverse(callback) @@ -47,6 +48,8 @@ interface UCatchClause : UElement { override fun traverse(callback: UastCallback) { body.handleTraverse(callback) + parameters.handleTraverseList(callback) + types.handleTraverseList(callback) } override fun logString() = log("UCatchClause", body) diff --git a/plugins/uast-common/src/org/jetbrains/uast/declarations/UClass.kt b/plugins/uast-common/src/org/jetbrains/uast/declarations/UClass.kt index 1834201d752..e49cc896e43 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/declarations/UClass.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/declarations/UClass.kt @@ -47,7 +47,7 @@ interface UClass : UDeclaration, UFqNamed, UModifierOwner, UAnnotated { val constructors: List get() = declarations.filter { it is UFunction && it.kind == UastFunctionKind.CONSTRUCTOR } as List - fun isSubclassOf(name: String) : Boolean + fun isSubclassOf(fqName: String) : Boolean fun getSuperClass(context: UastContext): UClass? @@ -81,7 +81,7 @@ object UClassNotResolved : UClass { override val visibility = UastVisibility.PRIVATE override val superTypes = emptyList() override val declarations = emptyList() - override fun isSubclassOf(name: String) = false + override fun isSubclassOf(fqName: String) = false override val companions = emptyList() override val defaultType = UastErrorType override val nameElement = null diff --git a/plugins/uast-common/src/org/jetbrains/uast/declarations/UImportStatement.kt b/plugins/uast-common/src/org/jetbrains/uast/declarations/UImportStatement.kt index e6e5633b441..ba4cdcc13d4 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/declarations/UImportStatement.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/declarations/UImportStatement.kt @@ -22,6 +22,9 @@ interface UImportStatement : UElement { val isStarImport: Boolean val kind: UastImportKind + /* Returns null if isStarImport = true */ + fun resolve(context: UastContext): UDeclaration? + override fun traverse(callback: UastCallback) {} override fun logString() = "UImport ($fqNameToImport)" override fun renderString() = "import ${fqNameToImport ?: ""}" diff --git a/plugins/uast-common/src/org/jetbrains/uast/declarations/UType.kt b/plugins/uast-common/src/org/jetbrains/uast/declarations/UType.kt index dcab4ff5e5b..dc0334b8c0c 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/declarations/UType.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/declarations/UType.kt @@ -35,6 +35,10 @@ interface UType : UElement, UNamed, UFqNamed, UAnnotated, UResolvable, LeafUElem override fun resolve(context: UastContext): UClass? override fun resolveOrEmpty(context: UastContext) = resolve(context) ?: UClassNotResolved + + override fun traverse(callback: UastCallback) { + annotations.handleTraverseList(callback) + } } interface UTypeReference : UDeclaration, UResolvable, LeafUElement { diff --git a/plugins/uast-common/src/org/jetbrains/uast/declarations/UVariable.kt b/plugins/uast-common/src/org/jetbrains/uast/declarations/UVariable.kt index 460bf2e3b2c..fc46cfc2bff 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/declarations/UVariable.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/declarations/UVariable.kt @@ -19,6 +19,13 @@ interface UVariable : UDeclaration, UModifierOwner, UAnnotated { val initializer: UExpression? val kind: UastVariableKind val type: UType + val visibility: UastVisibility + + open val getters: List? + get() = null + + open val setters: List? + get() = null override fun traverse(callback: UastCallback) { nameElement?.handleTraverse(callback) @@ -37,3 +44,16 @@ interface UVariable : UDeclaration, UModifierOwner, UAnnotated { override fun logString() = "UVariable ($name, kind = ${kind.name})\n" + (initializer?.let { it.logString().withMargin } ?: "") } + +object UVariableNotResolved : UVariable { + override val initializer = null + override val kind = UastVariableKind.MEMBER + override val type = UastErrorType + override val nameElement = null + override val parent = null + override val name = "" + override val visibility = UastVisibility.LOCAL + + override fun hasModifier(modifier: UastModifier) = false + override val annotations = emptyList() +} \ No newline at end of file diff --git a/plugins/uast-common/src/org/jetbrains/uast/expressions/UAssignmentExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/expressions/UAssignmentExpression.kt deleted file mode 100644 index b06c9f56d06..00000000000 --- a/plugins/uast-common/src/org/jetbrains/uast/expressions/UAssignmentExpression.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.uast - -interface UAssignmentExpression : UExpression { - val reference: UExpression - val operator: String - val value: UExpression - - override fun traverse(callback: UastCallback) { - reference.handleTraverse(callback) - value.handleTraverse(callback) - } - - override fun logString() = "UAssignmentExpression ($operator)\n" + reference.logString().withMargin + "\n" + value.logString().withMargin - - override fun renderString() = reference.renderString() + ' ' + operator + ' ' + value.renderString() -} \ No newline at end of file diff --git a/plugins/uast-common/src/org/jetbrains/uast/expressions/ULabeledExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/expressions/ULabeledExpression.kt index cb4100e3a10..d729537c0f5 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/expressions/ULabeledExpression.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/expressions/ULabeledExpression.kt @@ -23,6 +23,8 @@ interface ULabeledExpression : UExpression { expression.handleTraverse(callback) } + override fun evaluate() = expression.evaluate() + override fun logString() = log("ULabeledExpression ($label)", expression) override fun renderString() = "$label@ ${expression.renderString()}" diff --git a/plugins/uast-common/src/org/jetbrains/uast/expressions/ULiteralExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/expressions/ULiteralExpression.kt index 715590389ec..6692c31867c 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/expressions/ULiteralExpression.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/expressions/ULiteralExpression.kt @@ -16,8 +16,6 @@ package org.jetbrains.uast interface ULiteralExpression : UExpression { - val text: String - val value: Any? val isNull: Boolean @@ -28,7 +26,9 @@ interface ULiteralExpression : UExpression { val isBoolean: Boolean get() = evaluate() is Boolean + fun asString() = value?.toString() ?: "" + override fun traverse(callback: UastCallback) {} - override fun logString() = "ULiteralExpression ($text)" - override fun renderString() = text + override fun logString() = "ULiteralExpression (${asString()})" + override fun renderString() = asString() } diff --git a/plugins/uast-common/src/org/jetbrains/uast/expressions/UParenthesizedExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/expressions/UParenthesizedExpression.kt index 4239396c480..1615c6472db 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/expressions/UParenthesizedExpression.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/expressions/UParenthesizedExpression.kt @@ -22,6 +22,8 @@ interface UParenthesizedExpression : UExpression { expression.handleTraverse(callback) } + override fun evaluate() = expression.evaluate() + override fun logString() = log("UParenthesizedExpression", expression) override fun renderString() = '(' + expression.renderString() + ')' } \ No newline at end of file diff --git a/plugins/uast-common/src/org/jetbrains/uast/expressions/USuperExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/expressions/USuperExpression.kt index 8995bc65bd1..e0e5949aca7 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/expressions/USuperExpression.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/expressions/USuperExpression.kt @@ -15,8 +15,7 @@ */ package org.jetbrains.uast -interface USuperExpression : UExpression { +interface USuperExpression : UExpression, LeafUElement { override fun logString() = "USuperExpression" override fun renderString() = "super" - override fun traverse(callback: UastCallback) {} } \ No newline at end of file diff --git a/plugins/uast-common/src/org/jetbrains/uast/expressions/UThisExpression.kt b/plugins/uast-common/src/org/jetbrains/uast/expressions/UThisExpression.kt index 9a26dcd025c..8c9dfe2d132 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/expressions/UThisExpression.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/expressions/UThisExpression.kt @@ -15,8 +15,7 @@ */ package org.jetbrains.uast -interface UThisExpression : UExpression { +interface UThisExpression : UExpression, LeafUElement { override fun logString() = "UThisExpression" override fun renderString() = "this" - override fun traverse(callback: UastCallback) {} } \ No newline at end of file diff --git a/plugins/uast-common/src/org/jetbrains/uast/kinds/UastFunctionKind.kt b/plugins/uast-common/src/org/jetbrains/uast/kinds/UastFunctionKind.kt index 15463a0e618..a5584de91bb 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/kinds/UastFunctionKind.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/kinds/UastFunctionKind.kt @@ -17,13 +17,20 @@ package org.jetbrains.uast open class UastFunctionKind(val text: String) { class UastInitializerKind(val name: String) : UastFunctionKind("INITIALIZER ($name)") + class UastVariableAccessor(val name: String) : UastFunctionKind(name) companion object { @JvmField val FUNCTION = UastFunctionKind("function") @JvmField - val CONSTRUCTOR = UastFunctionKind("CONSTRUCTOR") + val CONSTRUCTOR = UastFunctionKind("constructor") + + @JvmField + val GETTER = UastVariableAccessor("getter") + + @JvmField + val SETTER = UastVariableAccessor("setter") } override fun toString(): String{ diff --git a/plugins/uast-common/src/org/jetbrains/uast/kinds/UastImportKind.kt b/plugins/uast-common/src/org/jetbrains/uast/kinds/UastImportKind.kt index 790801a4360..7385b34df14 100644 --- a/plugins/uast-common/src/org/jetbrains/uast/kinds/UastImportKind.kt +++ b/plugins/uast-common/src/org/jetbrains/uast/kinds/UastImportKind.kt @@ -24,6 +24,9 @@ class UastImportKind(val text: String) { @JvmField val MEMBER = UastImportKind("member") + + @JvmField + val UNKNOWN = UastImportKind("unknown") } override fun toString(): String{ diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt b/plugins/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt index 4dcf58aa0b9..c6c8af85642 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt @@ -25,8 +25,8 @@ object JavaUastLanguagePlugin : UastLanguagePlugin { } internal object JavaConverter : UastConverter { - override fun isFileSupported(path: String): Boolean { - return path.endsWith(".java", ignoreCase = true) + override fun isFileSupported(name: String): Boolean { + return name.endsWith(".java", ignoreCase = true) } fun convert(file: PsiJavaFile): UFile = JavaUFile(file) @@ -125,10 +125,10 @@ internal object JavaConverter : UastConverter { parent: UElement, i: Int ): UExpression { - return if (i == 1) JavaCombinedUBinaryExpression(expression, parent).apply { + return if (i == 1) JavaSeparatedPolyadicUBinaryExpression(expression, parent).apply { leftOperand = convert(expression.operands[0], this) rightOperand = convert(expression.operands[1], this) - } else JavaCombinedUBinaryExpression(expression, parent).apply { + } else JavaSeparatedPolyadicUBinaryExpression(expression, parent).apply { leftOperand = convertPolyadicExpression(expression, parent, i - 1) rightOperand = convert(expression.operands[i], this) } 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 index 6b21e4b9315..39085ad7013 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUDoWhileExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUDoWhileExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiDoWhileStatement -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UDoWhileExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.psi.PsiElementBacked @@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUDoWhileExpression( override val psi: PsiDoWhileStatement, override val parent: UElement -) : JavaAbstractUElement(), UDoWhileExpression, PsiElementBacked, NoEvaluate { +) : JavaAbstractUElement(), UDoWhileExpression, PsiElementBacked { override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) } override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) } } \ 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 index 01c434b175e..9065b1533e0 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUForEachExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUForEachExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiForeachStatement -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.UForEachExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -24,9 +23,8 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUForEachExpression( override val psi: PsiForeachStatement, override val parent: UElement -) : JavaAbstractUElement(), UForEachExpression, PsiElementBacked, NoEvaluate { - override val variableName: String? - get() = psi.iterationParameter.name +) : JavaAbstractUElement(), UForEachExpression, PsiElementBacked { + override val variable by lz { JavaConverter.convert(psi.iterationParameter, this) } override val iteratedValue by lz { JavaConverter.convertOrEmpty(psi.iteratedValue, this) } override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) } 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 index c4cd37df320..1a629fcdad8 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUForExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUForExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiForStatement -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.UForExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUForExpression( override val psi: PsiForStatement, override val parent: UElement -) : JavaAbstractUElement(), UForExpression, PsiElementBacked, NoEvaluate { +) : JavaAbstractUElement(), UForExpression, PsiElementBacked { override val declaration by lz { psi.initialization?.let { JavaConverter.convert(it, this) } } override val condition by lz { psi.condition?.let { JavaConverter.convert(it, this) } } override val update by lz { psi.update?.let { JavaConverter.convert(it, this) } } 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 index 75950e28f9c..374bc6744fa 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUIfExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUIfExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiIfStatement -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.UIfExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUIfExpression( override val psi: PsiIfStatement, override val parent: UElement -) : JavaAbstractUElement(), UIfExpression, PsiElementBacked, NoEvaluate { +) : JavaAbstractUElement(), UIfExpression, PsiElementBacked { override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) } override val thenBranch by lz { JavaConverter.convertOrEmpty(psi.thenBranch, this) } override val elseBranch by lz { JavaConverter.convertOrEmpty(psi.elseBranch, this) } 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 index 930cc0bba08..7c3a6792905 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUSwitchExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUSwitchExpression.kt @@ -17,7 +17,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiSwitchLabelStatement import com.intellij.psi.PsiSwitchStatement -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.UExpressionSwitchClauseExpression import org.jetbrains.uast.USwitchExpression @@ -26,7 +25,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUSwitchExpression( override val psi: PsiSwitchStatement, override val parent: UElement -) : JavaAbstractUElement(), USwitchExpression, PsiElementBacked, NoEvaluate { +) : JavaAbstractUElement(), USwitchExpression, PsiElementBacked { override val expression by lz { JavaConverter.convertOrEmpty(psi.expression, this) } override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) } } @@ -34,6 +33,6 @@ class JavaUSwitchExpression( class JavaUExpressionSwitchClauseExpression( override val psi: PsiSwitchLabelStatement, override val parent: UElement -) : JavaAbstractUElement(), UExpressionSwitchClauseExpression, PsiElementBacked, NoEvaluate { +) : JavaAbstractUElement(), UExpressionSwitchClauseExpression, PsiElementBacked { override val caseValue by lz { JavaConverter.convertOrEmpty(psi.caseValue, this) } } \ 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 index 327f2cca15f..6d8047f8009 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUTernaryIfExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUTernaryIfExpression.kt @@ -23,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUTernaryIfExpression( override val psi: PsiConditionalExpression, override val parent: UElement -) : JavaAbstractUElement(), UIfExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { +) : JavaAbstractUElement(), UIfExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement { override val condition by lz { JavaConverter.convert(psi.condition, this) } override val thenBranch by lz { JavaConverter.convertOrEmpty(psi.thenExpression, this) } override val elseBranch by lz { JavaConverter.convertOrEmpty(psi.elseExpression, this) } 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 index ddf358fc34c..52a09b48d16 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUTryExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUTryExpression.kt @@ -23,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUTryExpression( override val psi: PsiTryStatement, override val parent: UElement -) : JavaAbstractUElement(), UTryExpression, PsiElementBacked, NoEvaluate { +) : JavaAbstractUElement(), UTryExpression, PsiElementBacked { override val tryClause by lz { JavaConverter.convertOrEmpty(psi.tryBlock, this) } override val catchClauses by lz { psi.catchSections.map { JavaUCatchClause(it, this) } } override val finallyClause by lz { psi.finallyBlock?.let { JavaConverter.convert(it, this) } } @@ -40,5 +40,5 @@ class JavaUCatchClause( ) : JavaAbstractUElement(), UCatchClause, PsiElementBacked { override val body by lz { JavaConverter.convertOrEmpty(psi.catchBlock, this) } override val parameters by lz { psi.parameter?.let { listOf(JavaConverter.convert(it, this)) } ?: emptyList() } - override val types by lz { listOf(JavaConverter.convert(psi.catchType, this)) } + override val types by lz { psi.preciseCatchTypes.map { JavaConverter.convert(it, this) } } } \ 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 index cb7f4b02987..823f983fc9b 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUWhileExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/controlStructures/JavaUWhileExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiWhileStatement -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.UWhileExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUWhileExpression( override val psi: PsiWhileStatement, override val parent: UElement -) : JavaAbstractUElement(), UWhileExpression, PsiElementBacked, NoEvaluate { +) : JavaAbstractUElement(), UWhileExpression, PsiElementBacked { override val condition by lz { JavaConverter.convertOrEmpty(psi.condition, this) } override val body by lz { JavaConverter.convertOrEmpty(psi.body, this) } } \ 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 index 633066b2fff..4fb404684b2 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUClass.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUClass.kt @@ -92,14 +92,14 @@ class JavaUClass( declarations } - override fun isSubclassOf(name: String): Boolean { + override fun isSubclassOf(fqName: String): Boolean { tailrec fun isSubClassOf(clazz: PsiClass?, name: String): Boolean = when { clazz == null -> false clazz.qualifiedName == name -> true else -> isSubClassOf(clazz.superClass, name) } - return isSubClassOf(psi, name) + return isSubClassOf(psi, fqName) } private companion object { @@ -169,13 +169,7 @@ private class JavaUAnonymousClassConstructor( override val valueParameters by lz { val args = newExpression.argumentList ?: return@lz emptyList() - val variables = ArrayList(args.expressions.size) - - for (i in 0..(args.expressions.size - 1)) { - variables += JavaUAnonymousClassConstructorParameter(args, i, this) - } - - variables + args.expressions.mapIndexed { i, psiExpression -> JavaUAnonymousClassConstructorParameter(args, i, this) } } override val typeParameters by lz { psi.typeParameters.map { JavaConverter.convert(it, this) } } @@ -216,4 +210,7 @@ private class JavaUAnonymousClassConstructorParameter( override val name: String get() = "p$index" + + override val visibility: UastVisibility + get() = UastVisibility.LOCAL } \ 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 index 8442897c753..4093ccdba4f 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUFile.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUFile.kt @@ -21,7 +21,7 @@ import org.jetbrains.uast.UImportStatement import org.jetbrains.uast.psi.PsiElementBacked class JavaUFile(override val psi: PsiJavaFile): JavaAbstractUElement(), UFile, PsiElementBacked { - override val packageFqName by lz { psi.packageName.let { if (it.isNotBlank()) it else null } } + override val packageFqName by lz { psi.packageName } override val importStatements: List by lz { val importList = psi.importList ?: return@lz emptyList() 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 index e9d2286cc37..2780f7f418e 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUImportStatement.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUImportStatement.kt @@ -16,8 +16,10 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiImportStatement +import org.jetbrains.uast.UDeclaration import org.jetbrains.uast.UElement import org.jetbrains.uast.UImportStatement +import org.jetbrains.uast.UastContext import org.jetbrains.uast.kinds.UastImportKind import org.jetbrains.uast.psi.PsiElementBacked @@ -32,5 +34,11 @@ class JavaUImportStatement( get() = UastImportKind.CLASS override val isStarImport: Boolean - get() = false + get() = psi.isOnDemand + + override fun resolve(context: UastContext): UDeclaration? { + if (psi.isOnDemand) return null + val resolvedElement = psi.resolve() ?: return null + return context.convert(resolvedElement) as? UDeclaration + } } \ 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 index 2b536cb7275..e697f6c7f91 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUStaticImportStatement.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUStaticImportStatement.kt @@ -16,8 +16,10 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiImportStaticStatement +import org.jetbrains.uast.UDeclaration import org.jetbrains.uast.UElement import org.jetbrains.uast.UImportStatement +import org.jetbrains.uast.UastContext import org.jetbrains.uast.kinds.UastImportKind import org.jetbrains.uast.psi.PsiElementBacked @@ -32,5 +34,11 @@ class JavaUStaticImportStatement( get() = UastImportKind.MEMBER override val isStarImport: Boolean - get() = true + get() = psi.isOnDemand + + override fun resolve(context: UastContext): UDeclaration? { + if (psi.isOnDemand) return null + val resolvedElement = psi.resolve() ?: return null + return context.convert(resolvedElement) as? UDeclaration + } } \ 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 index 0aeaaa0b825..6ade3016d25 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUVariable.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaUVariable.kt @@ -17,10 +17,7 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiField import com.intellij.psi.PsiVariable -import org.jetbrains.uast.UElement -import org.jetbrains.uast.UVariable -import org.jetbrains.uast.UastModifier -import org.jetbrains.uast.UastVariableKind +import org.jetbrains.uast.* import org.jetbrains.uast.psi.PsiElementBacked class JavaUVariable( @@ -40,6 +37,9 @@ class JavaUVariable( else -> UastVariableKind.LOCAL_VARIABLE } + override val visibility: UastVisibility + get() = psi.getVisibility() + override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier) override val annotations by lz { psi.modifierList.getAnnotations(this) } } \ 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 index fcc739e87e2..873135f0e24 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaValueParameterUVariable.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/declarations/JavaValueParameterUVariable.kt @@ -22,7 +22,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaValueParameterUVariable( override val psi: PsiParameter, override val parent: UElement -) : JavaAbstractUElement(), UVariable, PsiElementBacked, NoModifiers { +) : JavaAbstractUElement(), UVariable, PsiElementBacked { override val name: String get() = psi.name.orAnonymous() @@ -35,5 +35,9 @@ class JavaValueParameterUVariable( override val kind: UastVariableKind get() = UastVariableKind.VALUE_PARAMETER + override val visibility: UastVisibility + get() = UastVisibility.LOCAL + + override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier) override val annotations by lz { psi.modifierList.getAnnotations(this) } } \ No newline at end of file diff --git a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaDumbUElement.kt b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaDumbUElement.kt index 59d3053f1cb..be17243358b 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaDumbUElement.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaDumbUElement.kt @@ -24,6 +24,6 @@ class JavaDumbUElement( override val psi: PsiElement?, override val parent: UElement ) : JavaAbstractUElement(), UElement, PsiElementBacked, LeafUElement { - override fun logString() = "JavaPsiElementStub" + override fun logString() = "JavaDumbUElement" override fun renderString() = "" } \ 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/JavaSeparatedPolyadicUBinaryExpression.kt similarity index 92% rename from plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaCombinedUBinaryExpression.kt rename to plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaSeparatedPolyadicUBinaryExpression.kt index bf04e8e1286..80113a86694 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaCombinedUBinaryExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaSeparatedPolyadicUBinaryExpression.kt @@ -21,10 +21,10 @@ import org.jetbrains.uast.UElement import org.jetbrains.uast.UExpression import org.jetbrains.uast.psi.PsiElementBacked -class JavaCombinedUBinaryExpression( +class JavaSeparatedPolyadicUBinaryExpression( override val psi: PsiPolyadicExpression, override val parent: UElement -) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { +) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement { override lateinit var leftOperand: UExpression override lateinit var rightOperand: UExpression 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 index 968a24f5dbd..cba01512838 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUArrayAccessExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUArrayAccessExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiArrayAccessExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UArrayAccessExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.psi.PsiElementBacked @@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUArrayAccessExpression( override val psi: PsiArrayAccessExpression, override val parent: UElement -) : JavaAbstractUElement(), UArrayAccessExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), UArrayAccessExpression, PsiElementBacked, JavaUElementWithType { override val receiver by lz { JavaConverter.convert(psi.arrayExpression, this) } override val indices by lz { singletonListOrEmpty(JavaConverter.convertOrNull(psi.indexExpression, this)) } } \ 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 index 706b3c25beb..48fe06ed8a9 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUAssignmentExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUAssignmentExpression.kt @@ -16,18 +16,19 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiAssignmentExpression -import org.jetbrains.uast.UAssignmentExpression +import org.jetbrains.uast.UBinaryExpression import org.jetbrains.uast.UElement +import org.jetbrains.uast.UastBinaryOperator import org.jetbrains.uast.psi.PsiElementBacked class JavaUAssignmentExpression( override val psi: PsiAssignmentExpression, override val parent: UElement -) : JavaAbstractUElement(), UAssignmentExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { - override val reference by lz { JavaConverter.convert(psi.lExpression, this) } +) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement { + override val leftOperand by lz { JavaConverter.convert(psi.lExpression, this) } - override val operator: String - get() = psi.operationSign.text + override val operator: UastBinaryOperator + get() = UastBinaryOperator.ASSIGN - override val value by lz { JavaConverter.convertOrEmpty(psi.rExpression, this) } + override val rightOperand by lz { JavaConverter.convertOrEmpty(psi.rExpression, this) } } \ 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 index a03fdfeb87f..ad55e37d521 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUBinaryExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUBinaryExpression.kt @@ -23,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUBinaryExpression( override val psi: PsiBinaryExpression, override val parent: UElement -) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { +) : JavaAbstractUElement(), UBinaryExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement { override val leftOperand by lz { JavaConverter.convert(psi.lOperand, this) } override val rightOperand by lz { JavaConverter.convertOrEmpty(psi.rOperand, this) } override val operator by lz { psi.operationTokenType.getOperatorType() } 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 index 9b6863cce7d..a32accab314 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUBlockExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUBlockExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiBlockStatement -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UBlockExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.psi.PsiElementBacked @@ -24,6 +23,6 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUBlockExpression( override val psi: PsiBlockStatement, override val parent: UElement -) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaUElementWithType { override val expressions by lz { psi.codeBlock.statements.map { JavaConverter.convert(it, this) } } } \ 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 index 72462566c7f..e8fd2acee7a 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCallableReferenceExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCallableReferenceExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiMethodReferenceExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UCallableReferenceExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.psi.PsiElementBacked @@ -24,6 +23,6 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUCallableReferenceExpression( override val psi: PsiMethodReferenceExpression, override val parent: UElement -) : JavaAbstractUElement(), UCallableReferenceExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), UCallableReferenceExpression, PsiElementBacked, JavaUElementWithType { override val qualifierType by lz { JavaConverter.convert(psi.qualifierType?.type, this) } } \ 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 index e3151dc3c9e..3fe91ae3387 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUClassLiteralExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUClassLiteralExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiClassObjectAccessExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UClassLiteralExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.UType @@ -25,6 +24,6 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUClassLiteralExpression( override val psi: PsiClassObjectAccessExpression, override val parent: UElement -) : JavaAbstractUElement(), UClassLiteralExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), UClassLiteralExpression, PsiElementBacked, JavaUElementWithType { override val type: UType by lz { JavaConverter.convert(psi.type, this) } } \ 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 index 3de954b65d0..99150ea3f12 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCodeBlockExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCodeBlockExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiCodeBlock -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UBlockExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.psi.PsiElementBacked @@ -24,6 +23,6 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUCodeBlockExpression( override val psi: PsiCodeBlock, override val parent: UElement -) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), UBlockExpression, PsiElementBacked, JavaUElementWithType { override val expressions by lz { psi.statements.map { JavaConverter.convert(it, this) } } } \ 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 index eff0a9c8ee9..3bec8517be1 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCompositeQualifiedExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUCompositeQualifiedExpression.kt @@ -21,7 +21,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUCompositeQualifiedExpression( override val parent: UElement -) : JavaAbstractUElement(), UQualifiedExpression, PsiElementBacked, NoEvaluate { +) : JavaAbstractUElement(), UQualifiedExpression, PsiElementBacked { override lateinit var receiver: UExpression internal set 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 index 0d9377abc44..9a4b6ba7fbd 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUInstanceCheckExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUInstanceCheckExpression.kt @@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUInstanceCheckExpression( override val psi: PsiInstanceOfExpression, override val parent: UElement -) : JavaAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { +) : JavaAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement { override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) } override val type by lz { JavaConverter.convert(psi.checkType?.type, this) } 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 index 46643328248..b5a147a6132 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULabeledExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULabeledExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiLabeledStatement -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.ULabeledExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -24,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaULabeledExpression( override val psi: PsiLabeledStatement, override val parent: UElement -) : JavaAbstractUElement(), ULabeledExpression, PsiElementBacked, NoEvaluate { +) : JavaAbstractUElement(), ULabeledExpression, PsiElementBacked { override val label by lz { psi.labelIdentifier.text } override val expression by lz { JavaConverter.convertOrEmpty(psi.statement, this) } } \ 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 index 09a6b4e9c94..03dd5fe50eb 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULambdaExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULambdaExpression.kt @@ -19,7 +19,6 @@ import com.intellij.psi.PsiCodeBlock import com.intellij.psi.PsiExpression import com.intellij.psi.PsiLambdaExpression import org.jetbrains.uast.EmptyExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.ULambdaExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -27,7 +26,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaULambdaExpression( override val psi: PsiLambdaExpression, override val parent: UElement -) : JavaAbstractUElement(), ULambdaExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), ULambdaExpression, PsiElementBacked, JavaUElementWithType { override val valueParameters by lz { psi.parameterList.parameters.map { JavaConverter.convert(it, this) } } override val body by lz { 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 index 96cacb4832c..22a118c9580 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULiteralExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaULiteralExpression.kt @@ -23,11 +23,11 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaULiteralExpression( override val psi: PsiLiteralExpression, override val parent: UElement -) : JavaAbstractUElement(), ULiteralExpression, PsiElementBacked, JavaTypeHelper { - override val text by lz { psi.text } +) : JavaAbstractUElement(), ULiteralExpression, PsiElementBacked, JavaUElementWithType { + override val asString by lz { psi.text } override fun evaluate() = psi.value override val value by lz { evaluate() } override val isNull: Boolean - get() = text == "null" + get() = asString() == "null" } \ 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 index 9fae0ff21c2..a9a22b9b85a 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUObjectLiteralExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUObjectLiteralExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiNewExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UClassNotResolved import org.jetbrains.uast.UElement import org.jetbrains.uast.UObjectLiteralExpression @@ -24,7 +23,7 @@ import org.jetbrains.uast.UObjectLiteralExpression class JavaUObjectLiteralExpression( override val psi: PsiNewExpression, override val parent: UElement -) : JavaAbstractUElement(), UObjectLiteralExpression, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), UObjectLiteralExpression, JavaUElementWithType { override val declaration by lz { psi.anonymousClass?.let { JavaUClass(it, this, psi) } ?: UClassNotResolved } 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 index 8a1a7d7ff08..4f5c9b81d69 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUParenthesizedExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUParenthesizedExpression.kt @@ -23,6 +23,6 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUParenthesizedExpression( override val psi: PsiParenthesizedExpression, override val parent: UElement -) : JavaAbstractUElement(), UParenthesizedExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { +) : JavaAbstractUElement(), UParenthesizedExpression, PsiElementBacked, JavaUElementWithType { override val expression by lz { JavaConverter.convertOrEmpty(psi.expression, this) } } \ 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 index 5d9d2046aa7..5f8a75ff541 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUPostfixExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUPostfixExpression.kt @@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUPostfixExpression( override val psi: PsiPostfixExpression, override val parent: UElement -) : JavaAbstractUElement(), UPostfixExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { +) : JavaAbstractUElement(), UPostfixExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement { override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) } override val operator = when (psi.operationSign.text) { 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 index 5b63aa93ad2..103688b478e 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUPrefixExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUPrefixExpression.kt @@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUPrefixExpression( override val psi: PsiPrefixExpression, override val parent: UElement -) : JavaAbstractUElement(), UPrefixExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { +) : JavaAbstractUElement(), UPrefixExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement { override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) } override val operator = when (psi.operationSign.text) { 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 index 6ae346f879a..9f3fdb4c6bc 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUQualifiedExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUQualifiedExpression.kt @@ -22,7 +22,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUQualifiedExpression( override val psi: PsiReferenceExpression, override val parent: UElement -) : JavaAbstractUElement(), UQualifiedExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), UQualifiedExpression, PsiElementBacked, JavaUElementWithType { override val receiver by lz { JavaConverter.convertOrEmpty(psi.qualifierExpression, this) } override val selector by lz { JavaConverter.convert(psi.referenceNameElement, this) as? UExpression ?: EmptyExpression(this) } 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 index 4b3d9abdace..424211698e9 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUSimpleReferenceExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUSimpleReferenceExpression.kt @@ -24,7 +24,7 @@ class JavaUSimpleReferenceExpression( override val psi: PsiElement, override val identifier: String, override val parent: UElement -) : JavaAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, JavaUElementWithType { override fun resolve(context: UastContext) = psi.reference?.resolve()?.let { context.convert(it) } as? UDeclaration } @@ -32,7 +32,7 @@ class JavaClassUSimpleReferenceExpression( override val identifier: String, val ref: PsiJavaReference, override val parent: UElement -) : JavaAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, NoEvaluate { +) : JavaAbstractUElement(), USimpleReferenceExpression, PsiElementBacked { override val psi: PsiElement? get() = ref.element 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 index e52671d0f70..31a7fc2c2da 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUSuperExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUSuperExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiSuperExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.USuperExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -24,4 +23,4 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUSuperExpression( override val psi: PsiSuperExpression, override val parent: UElement -) : JavaAbstractUElement(), USuperExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate \ No newline at end of file +) : JavaAbstractUElement(), USuperExpression, PsiElementBacked, JavaUElementWithType \ 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 index 97765aa16b4..20914fc4965 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUThisExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUThisExpression.kt @@ -16,7 +16,6 @@ package org.jetbrains.uast.java import com.intellij.psi.PsiThisExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.UThisExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -24,4 +23,4 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUThisExpression( override val psi: PsiThisExpression, override val parent: UElement -) : JavaAbstractUElement(), UThisExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate \ No newline at end of file +) : JavaAbstractUElement(), UThisExpression, PsiElementBacked, JavaUElementWithType \ 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 index 22ce4cb15e6..b27b955e3bb 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUTypeCastExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/JavaUTypeCastExpression.kt @@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUTypeCastExpression( override val psi: PsiTypeCastExpression, override val parent: UElement -) : JavaAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { +) : JavaAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement { override val operand by lz { JavaConverter.convertOrEmpty(psi.operand, this) } override val type by lz { JavaConverter.convert(psi.castType?.type, this) } 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 index 184d4f77f59..6a5438a51c0 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/UnknownJavaExpression.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/UnknownJavaExpression.kt @@ -22,6 +22,6 @@ import org.jetbrains.uast.psi.PsiElementBacked class UnknownJavaExpression( override val psi: PsiElement, override val parent: UElement -) : UExpression, PsiElementBacked, NoEvaluate, LeafUElement { +) : UExpression, PsiElementBacked, LeafUElement { override fun logString() = "[!] UnknownJavaExpression ($psi)" } \ 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 index dc1bbee4879..595183461c5 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/javaHelpers.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/javaHelpers.kt @@ -20,13 +20,13 @@ import com.intellij.psi.PsiExpression import org.jetbrains.uast.UExpression import org.jetbrains.uast.psi.PsiElementBacked -interface JavaEvaluateHelper : UExpression, PsiElementBacked { +interface JavaEvaluatableUElement : UExpression, PsiElementBacked { override fun evaluate(): Any? { val psi = this.psi ?: return null return JavaPsiFacade.getInstance(psi.project).constantEvaluationHelper.computeConstantExpression(psi) } } -interface JavaTypeHelper : UExpression, PsiElementBacked { +interface JavaUElementWithType : UExpression, PsiElementBacked { override fun getExpressionType() = (psi as? PsiExpression)?.type?.let { JavaConverter.convert(it, this) } } \ 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 index f701b4500df..e6aaa6df35f 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/expressions/javaUCallExpressions.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/expressions/javaUCallExpressions.kt @@ -25,7 +25,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class JavaUCallExpression( override val psi: PsiMethodCallExpression, override val parent: UElement -) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType { override val kind: UastCallKind get() = UastCallKind.FUNCTION_CALL @@ -54,7 +54,7 @@ class JavaUCallExpression( class JavaConstructorUCallExpression( override val psi: PsiNewExpression, override val parent: UElement -) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaTypeHelper, NoEvaluate { +) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType { override val kind by lz { when { psi.arrayInitializer != null -> JavaUastCallKinds.ARRAY_INITIALIZER @@ -118,7 +118,7 @@ class JavaConstructorUCallExpression( class JavaArrayInitializerUCallExpression( override val psi: PsiArrayInitializerExpression, override val parent: UElement -) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { +) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement { override val functionReference: USimpleReferenceExpression? get() = null @@ -150,7 +150,7 @@ class JavaArrayInitializerUCallExpression( class JavaAnnotationArrayInitializerUCallExpression( override val psi: PsiArrayInitializerMemberValue, override val parent: UElement -) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaTypeHelper, JavaEvaluateHelper { +) : JavaAbstractUElement(), UCallExpression, PsiElementBacked, JavaUElementWithType, JavaEvaluatableUElement { override val kind = JavaUastCallKinds.ARRAY_INITIALIZER override val functionReference: USimpleReferenceExpression? 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 index a1dc92ec5f4..c0c91e6573d 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/internal/javaInternalUastUtils.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/internal/javaInternalUastUtils.kt @@ -30,6 +30,9 @@ internal fun PsiModifierListOwner.hasModifier(modifier: UastModifier): Boolean { if (modifier == UastModifier.OVERRIDE && this is PsiAnnotationOwner) { return this.annotations.any { it.qualifiedName == "java.lang.Override" } } + if (modifier == UastModifier.VARARG && this is PsiParameter) { + return this.isVarArgs + } val javaModifier = MODIFIER_MAP[modifier] ?: return false return hasModifierProperty(javaModifier) } @@ -43,7 +46,7 @@ internal fun PsiModifierListOwner.getVisibility(): UastVisibility { if (hasModifierProperty(PsiModifier.PUBLIC)) return UastVisibility.PUBLIC if (hasModifierProperty(PsiModifier.PROTECTED)) return UastVisibility.PROTECTED if (hasModifierProperty(PsiModifier.PRIVATE)) return UastVisibility.PRIVATE - return JavaUastVisibilities.DEFAULT + return JavaUastVisibilities.PACKAGE_LOCAL } internal fun IElementType.getOperatorType() = when (this) { @@ -87,4 +90,6 @@ internal inline fun String?.orAnonymous(kind: String = ""): String { internal fun runReadAction(action: () -> T): T { return ApplicationManager.getApplication().runReadAction(action) -} \ No newline at end of file +} + +internal fun lz(initializer: () -> T) = lazy(LazyThreadSafetyMode.NONE, initializer) \ 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 deleted file mode 100644 index 2ac026a6b2b..00000000000 --- a/plugins/uast-java/src/org/jetbrains/uast/java/internal/lz.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.uast.java - -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty - -internal fun 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/JavaUastModifiers.kt b/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastModifiers.kt deleted file mode 100644 index 62b01c8c578..00000000000 --- a/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastModifiers.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.uast.java - -import org.jetbrains.uast.UastModifier - -object JavaUastModifiers { - @JvmField - val INITIALIZER = UastModifier("static") -} \ 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 index b570519d054..98fededdaff 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastVisibilities.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/java/kinds/JavaUastVisibilities.kt @@ -19,8 +19,5 @@ import org.jetbrains.uast.UastVisibility object JavaUastVisibilities { @JvmField - val DEFAULT = UastVisibility("default") - - @JvmField - val INSTANCE = UastVisibility("instance") + val PACKAGE_LOCAL = UastVisibility("package_local") } \ 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 index c4ded269c07..b40a0c0cb71 100644 --- a/plugins/uast-java/src/org/jetbrains/uast/psi/PsiElementBacked.kt +++ b/plugins/uast-java/src/org/jetbrains/uast/psi/PsiElementBacked.kt @@ -17,7 +17,11 @@ package org.jetbrains.uast.psi import com.intellij.psi.PsiElement +import org.jetbrains.uast.UElement -interface PsiElementBacked { +interface PsiElementBacked : UElement { val psi: PsiElement? + + override val isValid: Boolean + get() = psi?.isValid ?: true } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/KotlinUastLanguagePlugin.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/KotlinUastLanguagePlugin.kt index 4bbdb86ecb4..79eb1e479c8 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/KotlinUastLanguagePlugin.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/KotlinUastLanguagePlugin.kt @@ -35,7 +35,7 @@ object KotlinUastLanguagePlugin : UastLanguagePlugin { } internal object KotlinConverter : UastConverter { - override fun isFileSupported(path: String) = path.endsWith(".kt", false) || path.endsWith(".kts", false) + override fun isFileSupported(name: String) = name.endsWith(".kt", false) || name.endsWith(".kts", false) override fun convert(element: Any?, parent: UElement): UElement? { if (element !is KtElement) return null diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinDumbUElement.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinDumbUElement.kt index 1ab1406fd78..c33f3c77a2a 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinDumbUElement.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinDumbUElement.kt @@ -25,6 +25,6 @@ class KotlinDumbUElement( override val psi: PsiElement?, override val parent: UElement ) : KotlinAbstractUElement(), UElement, PsiElementBacked, LeafUElement { - override fun logString() = "KotlinPsiElementStub" + override fun logString() = "KotlinDumbUElement" override fun renderString() = "" } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUClass.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUClass.kt index 5e491ac9a0a..96c4def32b2 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUClass.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUClass.kt @@ -134,10 +134,10 @@ class KotlinUClass( override val visibility by lz { psi.getVisibility() } - override fun isSubclassOf(name: String): Boolean { + override fun isSubclassOf(fqName: String): Boolean { val descriptor = psi.resolveToDescriptorIfAny() as? ClassDescriptor ?: return false return descriptor.defaultType.supertypes().any { - it.constructor.declarationDescriptor?.fqNameSafe?.asString() == name + it.constructor.declarationDescriptor?.fqNameSafe?.asString() == fqName } } diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUFile.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUFile.kt index b2e1893b3f3..b6e0920fc9d 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUFile.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUFile.kt @@ -21,10 +21,8 @@ import org.jetbrains.uast.UFile import org.jetbrains.uast.psi.PsiElementBacked class KotlinUFile(override val psi: KtFile): KotlinAbstractUElement(), UFile, PsiElementBacked { - override val packageFqName by lz { - val packageName = psi.packageFqName.asString() - if (packageName.isNotBlank()) packageName else null - } + override val packageFqName: String? + get() = psi.packageFqName.asString() override val declarations by lz { psi.declarations.map { KotlinConverter.convert(it, this) }.filterNotNull() } override val importStatements by lz { psi.importDirectives.map { KotlinUImportStatement(it, this) } } diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUImportStatement.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUImportStatement.kt index 822c6748175..0ba93bd5dac 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUImportStatement.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUImportStatement.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.uast import org.jetbrains.kotlin.psi.KtImportDirective import org.jetbrains.uast.UElement import org.jetbrains.uast.UImportStatement +import org.jetbrains.uast.UastContext import org.jetbrains.uast.kinds.UastImportKind import org.jetbrains.uast.psi.PsiElementBacked @@ -30,8 +31,11 @@ class KotlinUImportStatement( //TODO support member imports override val kind: UastImportKind - get() = UastImportKind.CLASS + get() = UastImportKind.UNKNOWN override val isStarImport: Boolean get() = psi.isAllUnder + + //TODO support + override fun resolve(context: UastContext) = null } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUVariable.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUVariable.kt index 4585b73ea8b..0f85189bf2d 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUVariable.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/KotlinUVariable.kt @@ -42,6 +42,14 @@ open class KotlinUVariable( KotlinConverter.convert(type, psi.project, this) } + override val getters: List? by lz { + (psi as? KtProperty)?.accessors?.filter { it.isGetter }?.map { VariableAccessorFunction(it, this) } + } + + override val setters: List? by lz { + (psi as? KtProperty)?.accessors?.filter { it.isSetter }?.map { VariableAccessorFunction(it, this) } + } + override val kind: UastVariableKind get() = when (psi.parent) { is KtClassBody -> UastVariableKind.MEMBER @@ -49,8 +57,58 @@ open class KotlinUVariable( else -> UastVariableKind.LOCAL_VARIABLE } + override val visibility: UastVisibility + get() = psi.getVisibility() + override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier) override val annotations by lz { psi.getUastAnnotations(this) } + + private class VariableAccessorFunction( + override val psi: KtPropertyAccessor, + override val parent: UVariable + ) : KotlinAbstractUElement(), UFunction, PsiElementBacked { + override val kind: UastFunctionKind + get() = if (psi.isGetter) + UastFunctionKind.GETTER + else if (psi.isSetter) + UastFunctionKind.SETTER + else + UastFunctionKind.FUNCTION + + override val valueParameters by lz { psi.valueParameters.map { KotlinConverter.convert(it, this) } } + + override val valueParameterCount: Int + get() = psi.valueParameters.size + + override val typeParameters: List + get() = emptyList() + override val typeParameterCount: Int + get() = 0 + + override val returnType: UType? + get() = if (psi.isSetter) null else parent.type + + override val body by lz { KotlinConverter.convertOrEmpty(psi.bodyExpression, this) } + + override val visibility: UastVisibility + get() = psi.getVisibility() + + override fun getSuperFunctions(context: UastContext): List { + throw UnsupportedOperationException() + } + + override val nameElement: UElement? + get() = throw UnsupportedOperationException() + override val name: String + get() = throw UnsupportedOperationException() + + override fun hasModifier(modifier: UastModifier): Boolean { + throw UnsupportedOperationException() + } + + override val annotations: List + get() = throw UnsupportedOperationException() + } } class KotlinDestructuredUVariable( @@ -66,6 +124,9 @@ class KotlinDestructuredUVariable( val returnType = resolvedCall.resultingDescriptor.returnType ?: return@lz UastErrorType KotlinConverter.convert(returnType, entry.project, this) } + + override val visibility: UastVisibility + get() = UastVisibility.LOCAL } class KotlinDestructuringUVariable( @@ -81,6 +142,9 @@ class KotlinDestructuringUVariable( override val nameElement = null override fun hasModifier(modifier: UastModifier) = false override val annotations = emptyList() + + override val visibility: UastVisibility + get() = UastVisibility.LOCAL } class KotlinParameterUVariable( @@ -102,6 +166,9 @@ class KotlinParameterUVariable( KotlinConverter.convert(param.type, psi.project, this) } + override val visibility: UastVisibility + get() = UastVisibility.LOCAL + override fun hasModifier(modifier: UastModifier) = psi.hasModifier(modifier) override val annotations = psi.getUastAnnotations(this) } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/kotlinUFunctions.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/kotlinUFunctions.kt index 6963224ad23..d8483cb876b 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/kotlinUFunctions.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/declarations/kotlinUFunctions.kt @@ -211,6 +211,8 @@ open class KotlinObjectLiteralConstructorUFunction( get() = this@KotlinObjectLiteralConstructorUFunction override val name: String get() = param.name.asString() + override val visibility: UastVisibility + get() = UastVisibility.LOCAL override fun hasModifier(modifier: UastModifier) = when(modifier) { UastModifier.VARARG -> param.varargElementType != null diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinStringTemplateUBinaryExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinStringTemplateUBinaryExpression.kt index fd78268fd69..03d32bc2caa 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinStringTemplateUBinaryExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinStringTemplateUBinaryExpression.kt @@ -26,7 +26,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinStringTemplateUBinaryExpression( override val psi: KtStringTemplateExpression, override val parent: UElement -) : KotlinAbstractUElement(), UBinaryExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UBinaryExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override lateinit var leftOperand: UExpression internal set diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUArrayAccessExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUArrayAccessExpression.kt index cd8ea803868..4617013bcf3 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUArrayAccessExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUArrayAccessExpression.kt @@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUArrayAccessExpression( override val psi: KtArrayAccessExpression, override val parent: UElement -) : KotlinAbstractUElement(), UArrayAccessExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UArrayAccessExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val receiver by lz { KotlinConverter.convertOrEmpty(psi.arrayExpression, this) } override val indices by lz { psi.indexExpressions.map { KotlinConverter.convert(it, this) } } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBinaryExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBinaryExpression.kt index 6d9f1bd81d6..67ff90efd0d 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBinaryExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBinaryExpression.kt @@ -25,7 +25,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUBinaryExpression( override val psi: KtBinaryExpression, override val parent: UElement -) : KotlinAbstractUElement(), UBinaryExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UBinaryExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val leftOperand by lz { KotlinConverter.convertOrEmpty(psi.left, this) } override val rightOperand by lz { KotlinConverter.convertOrEmpty(psi.right, this) } @@ -63,7 +63,7 @@ class KotlinUBinaryExpression( class KotlinCustomUBinaryExpression( override val psi: PsiElement, override val parent: UElement -) : KotlinAbstractUElement(), UBinaryExpression, PsiElementBacked, NoEvaluate { +) : KotlinAbstractUElement(), UBinaryExpression, PsiElementBacked { lateinit override var leftOperand: UExpression internal set diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBinaryExpressionWithType.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBinaryExpressionWithType.kt index f4ca34118f5..f71fbaa7b6b 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBinaryExpressionWithType.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBinaryExpressionWithType.kt @@ -25,7 +25,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUBinaryExpressionWithType( override val psi: KtBinaryExpressionWithTypeRHS, override val parent: UElement -) : KotlinAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val operand by lz { KotlinConverter.convert(psi.left, this) } override val type by lz { KotlinConverter.convert(psi.right, this) } override val operationKind = when (psi.operationReference.getReferencedNameElementType()) { @@ -38,7 +38,7 @@ class KotlinUBinaryExpressionWithType( class KotlinCustomUBinaryExpressionWithType( override val psi: PsiElement, override val parent: UElement -) : KotlinAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, NoEvaluate { +) : KotlinAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked { lateinit override var operand: UExpression internal set diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBlockExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBlockExpression.kt index 6c894d2f225..b707151e468 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBlockExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUBlockExpression.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.uast import org.jetbrains.kotlin.psi.KtBlockExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UBlockExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.psi.PsiElementBacked @@ -25,6 +24,6 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUBlockExpression( override val psi: KtBlockExpression, override val parent: UElement -) : KotlinAbstractUElement(), UBlockExpression, PsiElementBacked, KotlinTypeHelper, NoEvaluate { +) : KotlinAbstractUElement(), UBlockExpression, PsiElementBacked, KotlinUElementWithType { override val expressions by lz { psi.statements.map { KotlinConverter.convertOrEmpty(it, this) } } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUClassLiteralExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUClassLiteralExpression.kt index 08e4e0a7e40..24afc60b4c8 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUClassLiteralExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUClassLiteralExpression.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.uast import org.jetbrains.kotlin.psi.KtClassLiteralExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UClassLiteralExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.psi.PsiElementBacked @@ -25,6 +24,6 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUClassLiteralExpression( override val psi: KtClassLiteralExpression, override val parent: UElement -) : KotlinAbstractUElement(), UClassLiteralExpression, PsiElementBacked, KotlinTypeHelper, NoEvaluate { +) : KotlinAbstractUElement(), UClassLiteralExpression, PsiElementBacked, KotlinUElementWithType { override val type by lz { KotlinConverter.convert(psi.typeReference, this) } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUDoWhileExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUDoWhileExpression.kt index 1f4a80ba411..ff2a17854f2 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUDoWhileExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUDoWhileExpression.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.uast import org.jetbrains.kotlin.psi.KtDoWhileExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UDoWhileExpression import org.jetbrains.uast.UElement import org.jetbrains.uast.psi.PsiElementBacked @@ -25,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUDoWhileExpression( override val psi: KtDoWhileExpression, override val parent: UElement -) : KotlinAbstractUElement(), UDoWhileExpression, PsiElementBacked, NoEvaluate { +) : KotlinAbstractUElement(), UDoWhileExpression, PsiElementBacked { override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) } override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUExpression.kt index b25502b7670..b25cb5219ee 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUExpression.kt @@ -25,7 +25,7 @@ import org.jetbrains.uast.UExpression import org.jetbrains.uast.UType import org.jetbrains.uast.psi.PsiElementBacked -interface KotlinTypeHelper : UExpression, PsiElementBacked { +interface KotlinUElementWithType : UExpression, PsiElementBacked { override fun getExpressionType(): UType? { val ktElement = psi as? KtExpression ?: return null val ktType = ktElement.analyze(BodyResolveMode.PARTIAL)[BindingContext.EXPECTED_EXPRESSION_TYPE, ktElement] ?: return null @@ -33,7 +33,7 @@ interface KotlinTypeHelper : UExpression, PsiElementBacked { } } -interface KotlinEvaluateHelper : UExpression, PsiElementBacked { +interface KotlinEvaluatableUElement : UExpression, PsiElementBacked { override fun evaluate(): Any? { val ktElement = psi as? KtExpression ?: return null val compileTimeConst = ktElement.analyze(BodyResolveMode.PARTIAL)[BindingContext.COMPILE_TIME_VALUE, ktElement] diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUForEachExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUForEachExpression.kt index 2796fd6db34..b33590c89fb 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUForEachExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUForEachExpression.kt @@ -17,16 +17,14 @@ package org.jetbrains.kotlin.uast import org.jetbrains.kotlin.psi.KtForExpression -import org.jetbrains.uast.NoEvaluate -import org.jetbrains.uast.UElement -import org.jetbrains.uast.UForEachExpression +import org.jetbrains.uast.* import org.jetbrains.uast.psi.PsiElementBacked class KotlinUForEachExpression( override val psi: KtForExpression, override val parent: UElement -) : KotlinAbstractUElement(), UForEachExpression, PsiElementBacked, NoEvaluate { - override val variableName by lz { psi.loopParameter?.name } +) : KotlinAbstractUElement(), UForEachExpression, PsiElementBacked { + override val variable by lz { psi.loopParameter?.let { KotlinConverter.convert(it, this) } ?: UVariableNotResolved } override val iteratedValue by lz { KotlinConverter.convertOrEmpty(psi.loopRange, this) } override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUFunctionCallExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUFunctionCallExpression.kt index 852fb4c56a7..55b5e8c6213 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUFunctionCallExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUFunctionCallExpression.kt @@ -30,7 +30,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUFunctionCallExpression( override val psi: KtCallExpression, override val parent: UElement -) : KotlinAbstractUElement(), UCallExpression, PsiElementBacked, KotlinTypeHelper, NoEvaluate { +) : KotlinAbstractUElement(), UCallExpression, PsiElementBacked, KotlinUElementWithType { override val functionName: String? get() = (psi.calleeExpression as? KtSimpleNameExpression)?.getReferencedName() @@ -84,7 +84,7 @@ class KotlinUComponentFunctionCallExpression( override val psi: PsiElement, val n: Int, override val parent: UElement -) : UCallExpression, PsiElementBacked, NoEvaluate { +) : UCallExpression, PsiElementBacked { override val valueArgumentCount = 0 override val valueArguments = emptyList() override val typeArgumentCount = 0 @@ -101,13 +101,13 @@ class KotlinUSuperConstructorCallExpression( override val psi: KtObjectDeclaration, override val parent: UElement, val resolvedCall: () -> ResolvedCall<*>? -) : UCallExpression, PsiElementBacked, NoEvaluate { +) : UCallExpression, PsiElementBacked { override val functionReference: USimpleReferenceExpression? get() = null override val classReference: USimpleReferenceExpression by lz { val referenceParent = this - object : USimpleReferenceExpression, PsiElementBacked, NoEvaluate { + object : USimpleReferenceExpression, PsiElementBacked { override val parent: UElement? get() = referenceParent diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUIfExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUIfExpression.kt index be388ed474d..483d4c130d9 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUIfExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUIfExpression.kt @@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUIfExpression( override val psi: KtIfExpression, override val parent: UElement -) : KotlinAbstractUElement(), UIfExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UIfExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) } override val thenBranch by lz { KotlinConverter.convertOrNull(psi.then, this) } override val elseBranch by lz { KotlinConverter.convertOrNull(psi.`else`, this) } diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinULambdaExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinULambdaExpression.kt index 0bc2c2f7bc7..5bfc2dccbd4 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinULambdaExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinULambdaExpression.kt @@ -23,7 +23,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinULambdaExpression( override val psi: KtLambdaExpression, override val parent: UElement -) : KotlinAbstractUElement(), ULambdaExpression, PsiElementBacked, KotlinTypeHelper, NoEvaluate { +) : KotlinAbstractUElement(), ULambdaExpression, PsiElementBacked, KotlinUElementWithType { override val body by lz { KotlinConverter.convertOrEmpty(psi.bodyExpression, this) } override val valueParameters by lz { psi.valueParameters.map { KotlinConverter.convert(it, this) } } override fun renderString(): String { diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinULiteralExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinULiteralExpression.kt index 676923387e2..2871d411fa5 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinULiteralExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinULiteralExpression.kt @@ -26,12 +26,11 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinULiteralExpression( override val psi: KtConstantExpression, override val parent: UElement -) : KotlinAbstractUElement(), ULiteralExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), ULiteralExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val isNull: Boolean get() = psi.isNullExpression() - override val text: String - get() = psi.text + override fun asString(): String = psi.text override val value by lz { evaluate() } } @@ -39,9 +38,9 @@ class KotlinULiteralExpression( class KotlinStringULiteralExpression( override val psi: PsiElement, override val parent: UElement -) : KotlinAbstractUElement(), ULiteralExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), ULiteralExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val isNull = false - override val text: String + override val asString: String get() = '"' + psi.text + '"' override val value: String diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUObjectLiteralExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUObjectLiteralExpression.kt index 4fe8c387758..c2120007917 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUObjectLiteralExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUObjectLiteralExpression.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.uast import org.jetbrains.kotlin.psi.KtObjectLiteralExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.UObjectLiteralExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -25,6 +24,6 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUObjectLiteralExpression( override val psi: KtObjectLiteralExpression, override val parent: UElement -) : UObjectLiteralExpression, PsiElementBacked, KotlinTypeHelper, NoEvaluate { +) : UObjectLiteralExpression, PsiElementBacked, KotlinUElementWithType { override val declaration by lz { KotlinUClass(psi.objectDeclaration, this, true) } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUParenthesizedExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUParenthesizedExpression.kt index d224a2f1568..142bc990010 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUParenthesizedExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUParenthesizedExpression.kt @@ -24,6 +24,6 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUParenthesizedExpression( override val psi: KtParenthesizedExpression, override val parent: UElement -) : KotlinAbstractUElement(), UParenthesizedExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UParenthesizedExpression, PsiElementBacked, KotlinUElementWithType { override val expression by lz { KotlinConverter.convertOrEmpty(psi.expression, this) } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUPostfixExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUPostfixExpression.kt index 768a9ba3a2f..774b08bf7ee 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUPostfixExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUPostfixExpression.kt @@ -26,7 +26,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUPostfixExpression( override val psi: KtPostfixExpression, override val parent: UElement -) : KotlinAbstractUElement(), UPostfixExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UPostfixExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val operand by lz { KotlinConverter.convertOrEmpty(psi.baseExpression, this) } override val operator = when (psi.operationToken) { diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUPrefixExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUPrefixExpression.kt index 597568e2e99..229c534ec6a 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUPrefixExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUPrefixExpression.kt @@ -26,7 +26,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUPrefixExpression( override val psi: KtPrefixExpression, override val parent: UElement -) : KotlinAbstractUElement(), UPrefixExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UPrefixExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val operand by lz { KotlinConverter.convertOrEmpty(psi.baseExpression, this) } override val operator = when (psi.operationToken) { diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUQualifiedExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUQualifiedExpression.kt index 2da8c6bc405..aa971b34da9 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUQualifiedExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUQualifiedExpression.kt @@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUQualifiedExpression( override val psi: KtDotQualifiedExpression, override val parent: UElement -) : KotlinAbstractUElement(), UQualifiedExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UQualifiedExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) } override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) } override val accessType = UastQualifiedExpressionAccessType.SIMPLE @@ -35,7 +35,7 @@ class KotlinUQualifiedExpression( class KotlinUComponentQualifiedExpression( override val psi: KtDestructuringDeclarationEntry, override val parent: UElement -) : KotlinAbstractUElement(), UQualifiedExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UQualifiedExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override lateinit var receiver: UExpression internal set diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSafeQualifiedExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSafeQualifiedExpression.kt index b93dce7304e..2f1e7e2a827 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSafeQualifiedExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSafeQualifiedExpression.kt @@ -25,7 +25,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUSafeQualifiedExpression( override val psi: KtSafeQualifiedExpression, override val parent: UElement -) : KotlinAbstractUElement(), UQualifiedExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UQualifiedExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val receiver by lz { KotlinConverter.convertOrEmpty(psi.receiverExpression, this) } override val selector by lz { KotlinConverter.convertOrEmpty(psi.selectorExpression, this) } override val accessType = KotlinQualifiedExpressionAccessTypes.SAFE diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSimpleReferenceExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSimpleReferenceExpression.kt index 7d3341f607c..3b6adbdb6a8 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSimpleReferenceExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSimpleReferenceExpression.kt @@ -33,7 +33,7 @@ open class KotlinUSimpleReferenceExpression( override val identifier: String, override val parent: UElement, private val descriptor: DeclarationDescriptor? = null -) : KotlinAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override fun resolve(context: UastContext): UDeclaration? { val resultingDescriptor = descriptor ?: run { val ktElement = psi as? KtElement ?: return null @@ -58,7 +58,7 @@ class KotlinClassViaConstructorUSimpleReferenceExpression( override val psi: KtCallExpression, override val identifier: String, override val parent: UElement -) : KotlinAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, KotlinTypeHelper, NoEvaluate { +) : KotlinAbstractUElement(), USimpleReferenceExpression, PsiElementBacked, KotlinUElementWithType { override fun resolve(context: UastContext): UDeclaration? { val resolvedCall = psi.getResolvedCall(psi.analyze(BodyResolveMode.PARTIAL)) val resultingDescriptor = resolvedCall?.resultingDescriptor as? ConstructorDescriptor ?: return null @@ -71,6 +71,6 @@ class KotlinClassViaConstructorUSimpleReferenceExpression( class KotlinStringUSimpleReferenceExpression( override val identifier: String, override val parent: UElement -) : KotlinAbstractUElement(), USimpleReferenceExpression, NoEvaluate { +) : KotlinAbstractUElement(), USimpleReferenceExpression { override fun resolve(context: UastContext) = null } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSpecialExpressionList.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSpecialExpressionList.kt index 4104bce4a4f..81565d9d0d6 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSpecialExpressionList.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSpecialExpressionList.kt @@ -32,7 +32,7 @@ open class KotlinUSpecialExpressionList( override val psi: PsiElement?, override val kind: UastSpecialExpressionKind, // original element override val parent: UElement -) : KotlinAbstractUElement(), USpecialExpressionList, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), USpecialExpressionList, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { class Empty(psi: PsiElement, expressionType: UastSpecialExpressionKind, parent: UElement) : KotlinUSpecialExpressionList(psi, expressionType, parent) { init { expressions = emptyList() } diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSuperExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSuperExpression.kt index b688e59eb56..c684c0ca107 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSuperExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSuperExpression.kt @@ -24,4 +24,4 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUSuperExpression( override val psi: KtSuperExpression, override val parent: UElement -) : KotlinAbstractUElement(), USuperExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper \ No newline at end of file +) : KotlinAbstractUElement(), USuperExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSwitchExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSwitchExpression.kt index 6b881f0b4a9..0eff37d5ef7 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSwitchExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUSwitchExpression.kt @@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUSwitchExpression( override val psi: KtWhenExpression, override val parent: UElement -) : KotlinAbstractUElement(), USwitchExpression, PsiElementBacked, KotlinTypeHelper, NoEvaluate { +) : KotlinAbstractUElement(), USwitchExpression, PsiElementBacked, KotlinUElementWithType { override val expression by lz { KotlinConverter.convertOrNull(psi.subjectExpression, this) } //TODO to entries @@ -47,7 +47,7 @@ class KotlinUSwitchExpression( class KotlinUSwitchEntry( override val psi: KtWhenEntry, override val parent: UExpression -) : KotlinAbstractUElement(), UExpression, PsiElementBacked, NoEvaluate { +) : KotlinAbstractUElement(), UExpression, PsiElementBacked { val conditions by lz { psi.conditions.map { when (it) { is KtWhenConditionInRange -> KotlinCustomUBinaryExpression(it, this).apply { diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUThisExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUThisExpression.kt index a5b6e31b310..377e0ea5168 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUThisExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUThisExpression.kt @@ -24,4 +24,4 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUThisExpression( override val psi: KtThisExpression, override val parent: UElement -) : KotlinAbstractUElement(), UThisExpression, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper \ No newline at end of file +) : KotlinAbstractUElement(), UThisExpression, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUTryExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUTryExpression.kt index b046d1c4cd3..051f87dd4df 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUTryExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUTryExpression.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.uast import org.jetbrains.kotlin.psi.KtTryExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.UTryExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -25,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUTryExpression( override val psi: KtTryExpression, override val parent: UElement -) : KotlinAbstractUElement(), UTryExpression, PsiElementBacked, KotlinTypeHelper, NoEvaluate { +) : KotlinAbstractUElement(), UTryExpression, PsiElementBacked, KotlinUElementWithType { override val tryClause by lz { KotlinConverter.convert(psi.tryBlock, this) } override val catchClauses by lz { psi.catchClauses.map { KotlinUCatchClause(it, this) } } override val finallyClause by lz { psi.finallyBlock?.finalExpression?.let { KotlinConverter.convert(it, this) } } diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUTypeCheckExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUTypeCheckExpression.kt index 298e9e074c8..19de370ded2 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUTypeCheckExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUTypeCheckExpression.kt @@ -24,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUTypeCheckExpression( override val psi: KtIsExpression, override val parent: UElement -) : KotlinAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, KotlinTypeHelper, KotlinEvaluateHelper { +) : KotlinAbstractUElement(), UBinaryExpressionWithType, PsiElementBacked, KotlinUElementWithType, KotlinEvaluatableUElement { override val operand by lz { KotlinConverter.convert(psi.leftHandSide, this) } override val type by lz { KotlinConverter.convert(psi.typeReference, this) } override val operationKind = KotlinBinaryExpressionWithTypeKinds.NEGATED_INSTANCE_CHECK diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUWhileExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUWhileExpression.kt index d03452cc13e..f0cca675e94 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUWhileExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/KotlinUWhileExpression.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.uast import org.jetbrains.kotlin.psi.KtWhileExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.UWhileExpression import org.jetbrains.uast.psi.PsiElementBacked @@ -25,7 +24,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class KotlinUWhileExpression( override val psi: KtWhileExpression, override val parent: UElement -) : KotlinAbstractUElement(), UWhileExpression, PsiElementBacked, NoEvaluate { +) : KotlinAbstractUElement(), UWhileExpression, PsiElementBacked { override val condition by lz { KotlinConverter.convertOrEmpty(psi.condition, this) } override val body by lz { KotlinConverter.convertOrEmpty(psi.body, this) } } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/UnknownKotlinExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/UnknownKotlinExpression.kt index b921a73724e..2a8850c8188 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/UnknownKotlinExpression.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/expressions/UnknownKotlinExpression.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.uast import org.jetbrains.kotlin.psi.KtExpression -import org.jetbrains.uast.NoEvaluate import org.jetbrains.uast.UElement import org.jetbrains.uast.UExpression import org.jetbrains.uast.UastCallback @@ -26,7 +25,7 @@ import org.jetbrains.uast.psi.PsiElementBacked class UnknownKotlinExpression( override val psi: KtExpression, override val parent: UElement -) : KotlinAbstractUElement(), UExpression, PsiElementBacked, NoEvaluate { +) : KotlinAbstractUElement(), UExpression, PsiElementBacked { override fun traverse(callback: UastCallback) {} override fun logString() = "[!] UnknownKotlinExpression ($psi)" } \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/internal/kotlinInternalUastUtils.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/internal/kotlinInternalUastUtils.kt index 561f73925c1..c0ac0dc73ed 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/internal/kotlinInternalUastUtils.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/internal/kotlinInternalUastUtils.kt @@ -97,4 +97,6 @@ internal fun DeclarationDescriptor.toSource(project: Project) = try { DescriptorToSourceUtilsIde.getAnyDeclaration(project, this) } catch (e: Exception) { null -} \ No newline at end of file +} + +internal fun lz(initializer: () -> T) = lazy(LazyThreadSafetyMode.NONE, initializer) \ No newline at end of file diff --git a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/internal/lz.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/internal/lz.kt deleted file mode 100644 index 64c4868380d..00000000000 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/internal/lz.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.kotlin.uast - -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-kotlin/src/org/jetbrains/kotlin/uast/lint/PropertyAsCallAndroidUastAdditionalChecker.kt b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/lint/PropertyAsCallAndroidUastAdditionalChecker.kt index 859d2bc7c05..4a75107e47c 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/lint/PropertyAsCallAndroidUastAdditionalChecker.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/kotlin/uast/lint/PropertyAsCallAndroidUastAdditionalChecker.kt @@ -47,7 +47,7 @@ class PropertyAsCallAndroidUastAdditionalChecker : AndroidUastAdditionalChecker else null - val callExpression: UCallExpression = object : UCallExpression, NoEvaluate, PsiElementBacked { + val callExpression: UCallExpression = object : UCallExpression, PsiElementBacked { override val parent = element.parent override val psi = ktElement