Update platform versions for 181, 182, as32, as33 plugins
This commit is contained in:
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.KtNodeTypes.*
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
|
||||
import org.jetbrains.kotlin.idea.formatter.NodeIndentStrategy.Companion.strategy
|
||||
import org.jetbrains.kotlin.idea.util.requireNode
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens
|
||||
import org.jetbrains.kotlin.kdoc.parser.KDocElementTypes
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
@@ -156,7 +157,7 @@ abstract class KotlinCommonBlock(
|
||||
private fun List<ASTBlock>.splitAtIndex(index: Int, indent: Indent?, wrap: Wrap?): List<ASTBlock> {
|
||||
val operationBlock = this[index]
|
||||
val operationSyntheticBlock = SyntheticKotlinBlock(
|
||||
operationBlock.node,
|
||||
operationBlock.requireNode(),
|
||||
subList(index, size),
|
||||
null, indent, wrap, spacingBuilder
|
||||
) { createSyntheticSpacingNodeBlock(it) }
|
||||
@@ -177,7 +178,7 @@ abstract class KotlinCommonBlock(
|
||||
}
|
||||
|
||||
private fun isCallBlock(astBlock: ASTBlock): Boolean {
|
||||
val node = astBlock.node
|
||||
val node = astBlock.requireNode()
|
||||
return node.elementType in QUALIFIED_EXPRESSIONS && node.lastChildNode?.elementType == KtNodeTypes.CALL_EXPRESSION
|
||||
}
|
||||
|
||||
@@ -266,7 +267,7 @@ abstract class KotlinCommonBlock(
|
||||
|
||||
if (type == IF) {
|
||||
val elseBlock = mySubBlocks?.getOrNull(newChildIndex)
|
||||
if (elseBlock != null && elseBlock.node.elementType == KtTokens.ELSE_KEYWORD) {
|
||||
if (elseBlock != null && elseBlock.requireNode().elementType == KtTokens.ELSE_KEYWORD) {
|
||||
return ChildAttributes.DELEGATE_TO_NEXT_CHILD
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.psi.codeStyle.CommonCodeStyleSettings
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.idea.util.requireNode
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import java.util.*
|
||||
|
||||
@@ -57,12 +58,12 @@ class KotlinSpacingBuilder(val commonCodeStyleSettings: CommonCodeStyleSettings,
|
||||
val rightSet: TokenSet? = null
|
||||
) : (ASTBlock, ASTBlock, ASTBlock) -> Boolean {
|
||||
override fun invoke(p: ASTBlock, l: ASTBlock, r: ASTBlock): Boolean =
|
||||
(parent == null || p.node!!.elementType == parent) &&
|
||||
(left == null || l.node!!.elementType == left) &&
|
||||
(right == null || r.node!!.elementType == right) &&
|
||||
(parentSet == null || parentSet.contains(p.node!!.elementType)) &&
|
||||
(leftSet == null || leftSet.contains(l.node!!.elementType)) &&
|
||||
(rightSet == null || rightSet.contains(r.node!!.elementType))
|
||||
(parent == null || p.requireNode().elementType == parent) &&
|
||||
(left == null || l.requireNode().elementType == left) &&
|
||||
(right == null || r.requireNode().elementType == right) &&
|
||||
(parentSet == null || parentSet.contains(p.requireNode().elementType)) &&
|
||||
(leftSet == null || leftSet.contains(l.requireNode().elementType)) &&
|
||||
(rightSet == null || rightSet.contains(r.requireNode().elementType))
|
||||
}
|
||||
|
||||
private data class Rule(val conditions: List<Condition>,
|
||||
@@ -139,8 +140,8 @@ class KotlinSpacingBuilder(val commonCodeStyleSettings: CommonCodeStyleSettings,
|
||||
|
||||
if (spacing != null) {
|
||||
// TODO: it's a severe hack but I don't know how to implement it in other way
|
||||
if (child1.node.elementType == KtTokens.EOL_COMMENT && spacing.toString().contains("minLineFeeds=0")) {
|
||||
val isBeforeBlock = child2.node.elementType == KtNodeTypes.BLOCK || child2.node.firstChildNode?.elementType == KtNodeTypes.BLOCK
|
||||
if (child1.requireNode().elementType == KtTokens.EOL_COMMENT && spacing.toString().contains("minLineFeeds=0")) {
|
||||
val isBeforeBlock = child2.requireNode().elementType == KtNodeTypes.BLOCK || child2.requireNode().firstChildNode?.elementType == KtNodeTypes.BLOCK
|
||||
val keepBlankLines = if (isBeforeBlock) 0 else commonCodeStyleSettings.KEEP_BLANK_LINES_IN_CODE
|
||||
return createSpacing(0, minLineFeeds = 1, keepLineBreaks = true, keepBlankLines = keepBlankLines)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.psi.tree.TokenSet
|
||||
import com.intellij.util.text.TextRangeUtil
|
||||
import org.jetbrains.kotlin.KtNodeTypes.*
|
||||
import org.jetbrains.kotlin.idea.formatter.KotlinSpacingBuilder.CustomSpacingBuilder
|
||||
import org.jetbrains.kotlin.idea.util.requireNode
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -69,7 +70,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
|
||||
// Several line comments happened to be generated in one line
|
||||
inPosition(parent = null, left = EOL_COMMENT, right = EOL_COMMENT).customRule { _, _, right ->
|
||||
val nodeBeforeRight = right.node.treePrev
|
||||
val nodeBeforeRight = right.requireNode().treePrev
|
||||
if (nodeBeforeRight is PsiWhiteSpace && !nodeBeforeRight.textContains('\n')) {
|
||||
createSpacing(0, minLineFeeds = 1)
|
||||
}
|
||||
@@ -97,24 +98,24 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
emptyLines = 0, numberOfLineFeedsOtherwise = 0, numSpacesOtherwise = 1)
|
||||
|
||||
inPosition(parent = CLASS_BODY, left = SEMICOLON).customRule { parent, _, right ->
|
||||
val klass = parent.node.treeParent.psi as? KtClass ?: return@customRule null
|
||||
if (klass.isEnum() && right.node.elementType in DECLARATIONS) {
|
||||
val klass = parent.requireNode().treeParent.psi as? KtClass ?: return@customRule null
|
||||
if (klass.isEnum() && right.requireNode().elementType in DECLARATIONS) {
|
||||
createSpacing(0, minLineFeeds = 2, keepBlankLines = settings.KEEP_BLANK_LINES_IN_DECLARATIONS)
|
||||
}
|
||||
else null
|
||||
}
|
||||
|
||||
inPosition(parent = CLASS_BODY, left = LBRACE).customRule { parent, left, right ->
|
||||
if (right.node.elementType == RBRACE) {
|
||||
if (right.requireNode().elementType == RBRACE) {
|
||||
return@customRule createSpacing(0)
|
||||
}
|
||||
val classBody = parent.node.psi as KtClassBody
|
||||
val classBody = parent.requireNode().psi as KtClassBody
|
||||
val parentPsi = classBody.parent as? KtClassOrObject ?: return@customRule null
|
||||
if (kotlinCommonSettings.BLANK_LINES_AFTER_CLASS_HEADER == 0 || parentPsi.isObjectLiteral()) {
|
||||
null
|
||||
}
|
||||
else {
|
||||
val minLineFeeds = if (right.node.elementType == FUN || right.node.elementType == PROPERTY)
|
||||
val minLineFeeds = if (right.requireNode().elementType == FUN || right.requireNode().elementType == PROPERTY)
|
||||
1
|
||||
else
|
||||
0
|
||||
@@ -122,7 +123,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
builderUtil.createLineFeedDependentSpacing(
|
||||
1, 1, minLineFeeds,
|
||||
settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_IN_DECLARATIONS,
|
||||
TextRange(parentPsi.textRange.startOffset, left.node.psi.textRange.startOffset),
|
||||
TextRange(parentPsi.textRange.startOffset, left.requireNode().psi.textRange.startOffset),
|
||||
DependentSpacingRule(DependentSpacingRule.Trigger.HAS_LINE_FEEDS)
|
||||
.registerData(DependentSpacingRule.Anchor.MIN_LINE_FEEDS, kotlinCommonSettings.BLANK_LINES_AFTER_CLASS_HEADER + 1)
|
||||
)
|
||||
@@ -131,7 +132,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
|
||||
val parameterWithDocCommentRule = {
|
||||
_: ASTBlock, _: ASTBlock, right: ASTBlock ->
|
||||
if (right.node.firstChildNode.elementType == KtTokens.DOC_COMMENT) {
|
||||
if (right.requireNode().firstChildNode.elementType == KtTokens.DOC_COMMENT) {
|
||||
createSpacing(0, minLineFeeds = 1, keepLineBreaks = true, keepBlankLines = settings.KEEP_BLANK_LINES_IN_DECLARATIONS)
|
||||
}
|
||||
else {
|
||||
@@ -141,16 +142,16 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
inPosition(parent = VALUE_PARAMETER_LIST, right = VALUE_PARAMETER).customRule(parameterWithDocCommentRule)
|
||||
|
||||
inPosition(parent = PROPERTY, right = PROPERTY_ACCESSOR).customRule { parent, _, _ ->
|
||||
val startNode = parent.node.psi.firstChild
|
||||
val startNode = parent.requireNode().psi.firstChild
|
||||
.siblings()
|
||||
.dropWhile { it is PsiComment || it is PsiWhiteSpace }.firstOrNull() ?: parent.node.psi
|
||||
.dropWhile { it is PsiComment || it is PsiWhiteSpace }.firstOrNull() ?: parent.requireNode().psi
|
||||
Spacing.createDependentLFSpacing(1, 1,
|
||||
TextRange(startNode.textRange.startOffset, parent.textRange.endOffset),
|
||||
false, 0)
|
||||
}
|
||||
|
||||
inPosition(parent = VALUE_ARGUMENT_LIST, left = LPAR).customRule { parent, _, _ ->
|
||||
if (kotlinCommonSettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE && needWrapArgumentList(parent.node.psi)) {
|
||||
if (kotlinCommonSettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE && needWrapArgumentList(parent.requireNode().psi)) {
|
||||
Spacing.createDependentLFSpacing(0, 0,
|
||||
excludeLambdasAndObjects(parent),
|
||||
commonCodeStyleSettings.KEEP_LINE_BREAKS,
|
||||
@@ -167,7 +168,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
excludeLambdasAndObjects(parent),
|
||||
commonCodeStyleSettings.KEEP_LINE_BREAKS,
|
||||
commonCodeStyleSettings.KEEP_BLANK_LINES_IN_CODE)
|
||||
} else if (left.node.elementType == KtTokens.COMMA) {
|
||||
} else if (left.requireNode().elementType == KtTokens.COMMA) {
|
||||
// incomplete call being edited
|
||||
createSpacing(1)
|
||||
} else {
|
||||
@@ -285,7 +286,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
// class A private() - one space before modifier
|
||||
custom {
|
||||
inPosition(right = PRIMARY_CONSTRUCTOR).customRule { _, _, r ->
|
||||
val spacesCount = if (r.node.findLeafElementAt(0)?.elementType != LPAR) 1 else 0
|
||||
val spacesCount = if (r.requireNode().findLeafElementAt(0)?.elementType != LPAR) 1 else 0
|
||||
createSpacing(spacesCount, minLineFeeds = 0, keepLineBreaks = true, keepBlankLines = 0)
|
||||
}
|
||||
}
|
||||
@@ -374,7 +375,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
inPosition(parent = parent, right = keyword).customRule {
|
||||
_, _, right ->
|
||||
|
||||
val previousLeaf = builderUtil.getPreviousNonWhitespaceLeaf(right.node)
|
||||
val previousLeaf = builderUtil.getPreviousNonWhitespaceLeaf(right.requireNode())
|
||||
val leftBlock = if (
|
||||
previousLeaf != null &&
|
||||
previousLeaf.elementType == RBRACE &&
|
||||
@@ -419,12 +420,12 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
|
||||
val leftBraceRuleIfBlockIsWrapped = {
|
||||
_: ASTBlock, _: ASTBlock, right: ASTBlock ->
|
||||
spacingForLeftBrace(right.node!!.firstChildNode)
|
||||
spacingForLeftBrace(right.requireNode().firstChildNode)
|
||||
}
|
||||
|
||||
// Add space after a semicolon if there is another child at the same line
|
||||
inPosition(left = SEMICOLON).customRule { _, left, _ ->
|
||||
val nodeAfterLeft = left.node.treeNext
|
||||
val nodeAfterLeft = left.requireNode().treeNext
|
||||
if (nodeAfterLeft is PsiWhiteSpace && !nodeAfterLeft.textContains('\n')) {
|
||||
createSpacing(1)
|
||||
}
|
||||
@@ -452,8 +453,8 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
inPosition(right = CLASS_BODY).customRule(leftBraceRule(blockType = CLASS_BODY))
|
||||
|
||||
inPosition(left = WHEN_ENTRY, right = WHEN_ENTRY).customRule { _, left, right ->
|
||||
val leftEntry = left.node.psi as KtWhenEntry
|
||||
val rightEntry = right.node.psi as KtWhenEntry
|
||||
val leftEntry = left.requireNode().psi as KtWhenEntry
|
||||
val rightEntry = right.requireNode().psi as KtWhenEntry
|
||||
val blankLines = if (leftEntry.expression is KtBlockExpression || rightEntry.expression is KtBlockExpression)
|
||||
settings.kotlinCustomSettings.BLANK_LINES_AROUND_BLOCK_WHEN_BRANCHES
|
||||
else
|
||||
@@ -465,7 +466,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
inPosition(parent = WHEN_ENTRY, right = BLOCK).customRule(leftBraceRule())
|
||||
inPosition(parent = WHEN, right = LBRACE).customRule {
|
||||
parent, _, _ ->
|
||||
spacingForLeftBrace(block = parent.node, blockType = WHEN)
|
||||
spacingForLeftBrace(block = parent.requireNode(), blockType = WHEN)
|
||||
}
|
||||
|
||||
val spacesInSimpleFunction = if (kotlinCustomSettings.INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD) 1 else 0
|
||||
@@ -491,7 +492,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
inPosition(parent = FUNCTION_LITERAL,
|
||||
left = LBRACE)
|
||||
.customRule { _, _, right ->
|
||||
val rightNode = right.node!!
|
||||
val rightNode = right.requireNode()
|
||||
val rightType = rightNode.elementType
|
||||
if (rightType == VALUE_PARAMETER_LIST) {
|
||||
createSpacing(spacesInSimpleFunction, keepLineBreaks = false)
|
||||
@@ -506,9 +507,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
}
|
||||
|
||||
inPosition(parent = BLOCK, right = RBRACE).customRule { block, left, _ ->
|
||||
val psiElement = block.node.treeParent.psi
|
||||
val psiElement = block.requireNode().treeParent.psi
|
||||
|
||||
val empty = left.node.elementType == LBRACE
|
||||
val empty = left.requireNode().elementType == LBRACE
|
||||
|
||||
when (psiElement) {
|
||||
is KtFunction -> {
|
||||
@@ -525,7 +526,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
}
|
||||
|
||||
inPosition(parent = BLOCK, left = LBRACE).customRule { parent, _, _ ->
|
||||
val psiElement = parent.node.treeParent.psi
|
||||
val psiElement = parent.requireNode().treeParent.psi
|
||||
val funNode = psiElement as? KtFunction ?: return@customRule null
|
||||
|
||||
if (funNode.name != null) return@customRule null
|
||||
@@ -537,7 +538,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
}
|
||||
|
||||
inPosition(parentSet = EXTEND_COLON_ELEMENTS, left = PRIMARY_CONSTRUCTOR, right = COLON).customRule { parent, left, _ ->
|
||||
val primaryConstructor = left.node.psi as KtPrimaryConstructor
|
||||
val primaryConstructor = left.requireNode().psi as KtPrimaryConstructor
|
||||
val rightParenthesis = primaryConstructor.valueParameterList?.rightParenthesis
|
||||
val prevSibling = rightParenthesis?.prevSibling
|
||||
val spaces = if (kotlinCustomSettings.SPACE_BEFORE_EXTEND_COLON) 1 else 0
|
||||
@@ -572,7 +573,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
|
||||
private fun excludeLambdasAndObjects(parent: ASTBlock): List<TextRange> {
|
||||
val rangesToExclude = mutableListOf<TextRange>()
|
||||
parent.node.psi.accept(object : KtTreeVisitorVoid() {
|
||||
parent.requireNode().psi.accept(object : KtTreeVisitorVoid() {
|
||||
override fun visitLambdaExpression(lambdaExpression: KtLambdaExpression) {
|
||||
super.visitLambdaExpression(lambdaExpression)
|
||||
rangesToExclude.add(lambdaExpression.textRange)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.util
|
||||
|
||||
import com.intellij.formatting.ASTBlock
|
||||
|
||||
/*
|
||||
* ASTBlock is nullable since 182, this extension was introduced to minimize changes between bunches
|
||||
*/
|
||||
fun ASTBlock.requireNode() = node ?: error("ASTBlock.getNode() returned null")
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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.android
|
||||
|
||||
import com.android.SdkConstants
|
||||
import com.android.SdkConstants.ANDROID_PKG
|
||||
import com.android.SdkConstants.R_CLASS
|
||||
import com.android.resources.ResourceType
|
||||
import com.android.tools.idea.AndroidPsiUtils
|
||||
import com.android.tools.idea.AndroidPsiUtils.ResourceReferenceType.*
|
||||
import com.android.tools.idea.res.AndroidInternalRClassFinder
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.android.dom.AndroidAttributeValue
|
||||
import org.jetbrains.android.dom.manifest.Manifest
|
||||
import org.jetbrains.android.facet.AndroidFacet
|
||||
import org.jetbrains.android.util.AndroidResourceUtil
|
||||
import org.jetbrains.android.util.AndroidResourceUtil.isManifestJavaFile
|
||||
import org.jetbrains.android.util.AndroidResourceUtil.isRJavaFile
|
||||
import org.jetbrains.android.util.AndroidUtils
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceFile
|
||||
|
||||
internal fun KtClass.findComponentDeclarationInManifest(manifest: Manifest): AndroidAttributeValue<PsiClass>? {
|
||||
val application = manifest.application ?: return null
|
||||
val type = (unsafeResolveToDescriptor(BodyResolveMode.PARTIAL) as? ClassDescriptor)?.defaultType ?: return null
|
||||
|
||||
return when {
|
||||
type.isSubclassOf(AndroidUtils.ACTIVITY_BASE_CLASS_NAME) ->
|
||||
application.activities?.find { it.activityClass.value?.qualifiedName == fqName?.asString() }?.activityClass
|
||||
type.isSubclassOf(AndroidUtils.SERVICE_CLASS_NAME) ->
|
||||
application.services?.find { it.serviceClass.value?.qualifiedName == fqName?.asString() }?.serviceClass
|
||||
type.isSubclassOf(AndroidUtils.RECEIVER_CLASS_NAME) ->
|
||||
application.receivers?.find { it.receiverClass.value?.qualifiedName == fqName?.asString() }?.receiverClass
|
||||
type.isSubclassOf(AndroidUtils.PROVIDER_CLASS_NAME) ->
|
||||
application.providers?.find { it.providerClass.value?.qualifiedName == fqName?.asString() }?.providerClass
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
internal fun PsiElement.getAndroidFacetForFile(): AndroidFacet? {
|
||||
val file = containingFile ?: return null
|
||||
return AndroidFacet.getInstance(file)
|
||||
}
|
||||
|
||||
internal fun JavaPropertyDescriptor.getAndroidResourceType(): ResourceType? {
|
||||
if (getResourceReferenceType() == NONE) {
|
||||
return null
|
||||
}
|
||||
|
||||
val containingClass = containingDeclaration as? JavaClassDescriptor ?: return null
|
||||
return ResourceType.getEnum(containingClass.name.asString())
|
||||
}
|
||||
|
||||
internal fun JavaPropertyDescriptor.getResourceReferenceType(): AndroidPsiUtils.ResourceReferenceType {
|
||||
val containingClass = containingDeclaration as? JavaClassDescriptor ?: return NONE
|
||||
val rClass = containingClass.containingDeclaration as? JavaClassDescriptor ?: return NONE
|
||||
|
||||
if (R_CLASS == rClass.name.asString()) {
|
||||
return if ((rClass.containingDeclaration as? PackageFragmentDescriptor)?.fqName?.asString() == ANDROID_PKG) {
|
||||
FRAMEWORK
|
||||
}
|
||||
else {
|
||||
APP
|
||||
}
|
||||
}
|
||||
|
||||
return NONE
|
||||
}
|
||||
|
||||
internal fun getReferredResourceOrManifestField(facet: AndroidFacet, expression: KtSimpleNameExpression, localOnly: Boolean)
|
||||
= getReferredResourceOrManifestField(facet, expression, null, localOnly)
|
||||
|
||||
internal fun getReferredResourceOrManifestField(facet: AndroidFacet, expression: KtSimpleNameExpression,
|
||||
className: String?, localOnly: Boolean): AndroidResourceUtil.MyReferredResourceFieldInfo? {
|
||||
val resFieldName = expression.getReferencedName()
|
||||
val resClassReference = expression.getPreviousInQualifiedChain() as? KtSimpleNameExpression ?: return null
|
||||
val resClassName = resClassReference.getReferencedName()
|
||||
|
||||
if (resClassName.isEmpty() || className != null && className != resClassName) {
|
||||
return null
|
||||
}
|
||||
|
||||
val rClassReference = resClassReference.getPreviousInQualifiedChain() as? KtSimpleNameExpression ?: return null
|
||||
val rClassDescriptor = rClassReference.analyze(BodyResolveMode.PARTIAL)
|
||||
.get(BindingContext.REFERENCE_TARGET, rClassReference) as? ClassDescriptor ?: return null
|
||||
|
||||
val rClassShortName = rClassDescriptor.name.asString()
|
||||
val fromManifest = AndroidUtils.MANIFEST_CLASS_NAME == rClassShortName
|
||||
|
||||
if (!fromManifest && AndroidUtils.R_CLASS_NAME != rClassShortName) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (!localOnly) {
|
||||
val qName = rClassDescriptor.fqNameSafe.asString()
|
||||
|
||||
if (SdkConstants.CLASS_R == qName || AndroidInternalRClassFinder.INTERNAL_R_CLASS_QNAME == qName) {
|
||||
return AndroidResourceUtil.MyReferredResourceFieldInfo(resClassName, resFieldName, facet.module, true, false)
|
||||
}
|
||||
}
|
||||
|
||||
val containingFile = (rClassDescriptor.source.containingFile as? PsiSourceFile)?.psiFile ?: return null
|
||||
if (if (fromManifest) !isManifestJavaFile(facet, containingFile) else !isRJavaFile(facet, containingFile)) {
|
||||
return null
|
||||
}
|
||||
|
||||
return AndroidResourceUtil.MyReferredResourceFieldInfo(resClassName, resFieldName, facet.module, false, false)
|
||||
}
|
||||
|
||||
private fun KtExpression.getPreviousInQualifiedChain(): KtExpression? {
|
||||
val receiverExpression = getQualifiedExpressionForSelector()?.receiverExpression
|
||||
return (receiverExpression as? KtQualifiedExpression)?.selectorExpression ?: receiverExpression
|
||||
}
|
||||
+2
-2
@@ -24,7 +24,7 @@ import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.PsiClass
|
||||
import org.jetbrains.android.util.AndroidUtils
|
||||
import com.android.SdkConstants
|
||||
import org.jetbrains.android.augment.AndroidPsiElementFinder
|
||||
import com.android.tools.idea.res.AndroidInternalRClassFinder
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
||||
@@ -80,7 +80,7 @@ private fun getReferredInfo(
|
||||
}
|
||||
val qName = resolvedClass.qualifiedName
|
||||
|
||||
if (SdkConstants.CLASS_R == qName || AndroidPsiElementFinder.INTERNAL_R_CLASS_QNAME == qName) {
|
||||
if (SdkConstants.CLASS_R == qName || AndroidInternalRClassFinder.INTERNAL_R_CLASS_QNAME == qName) {
|
||||
return AndroidResourceUtil.MyReferredResourceFieldInfo(resClassName, resFieldName, facet.module, true, false)
|
||||
}
|
||||
val containingFile = resolvedClass.containingFile ?: return null
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
extra["versions.intellijSdk"] = "181.4892.42"
|
||||
extra["versions.intellijSdk"] = "181.5540.7"
|
||||
extra["versions.androidBuildTools"] = "r23.0.1"
|
||||
extra["versions.idea.NodeJS"] = "181.3494.12"
|
||||
//extra["versions.androidStudioRelease"] = "3.1.0.5"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
extra["versions.intellijSdk"] = "182.3458.5"
|
||||
extra["versions.intellijSdk"] = "182.3684.101"
|
||||
extra["versions.androidBuildTools"] = "r23.0.1"
|
||||
extra["versions.idea.NodeJS"] = "181.3494.12"
|
||||
//extra["versions.androidStudioRelease"] = "3.1.0.5"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
extra["versions.intellijSdk"] = "181.4668.68"
|
||||
extra["versions.intellijSdk"] = "181.5281.24"
|
||||
extra["versions.androidBuildTools"] = "r23.0.1"
|
||||
extra["versions.idea.NodeJS"] = "181.2784.17"
|
||||
extra["versions.androidStudioRelease"] = "3.2.0.13"
|
||||
extra["versions.androidStudioBuild"] = "181.4763614"
|
||||
extra["versions.androidStudioRelease"] = "3.2.0.22"
|
||||
extra["versions.androidStudioBuild"] = "181.4913314"
|
||||
|
||||
val gradleJars = listOf(
|
||||
"gradle-api",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
extra["versions.intellijSdk"] = "181.4892.42"
|
||||
extra["versions.intellijSdk"] = "181.5281.24"
|
||||
extra["versions.androidBuildTools"] = "r23.0.1"
|
||||
extra["versions.idea.NodeJS"] = "181.2784.17"
|
||||
extra["versions.androidStudioRelease"] = "3.3.0.0"
|
||||
extra["versions.androidStudioBuild"] = "181.4861037"
|
||||
extra["versions.androidStudioRelease"] = "3.3.0.2"
|
||||
extra["versions.androidStudioBuild"] = "181.4884283"
|
||||
|
||||
val gradleJars = listOf(
|
||||
"gradle-api",
|
||||
|
||||
Reference in New Issue
Block a user