Decouple idea-analysis from Android
Introduce API for extending syntax highlighting; use it in android component
This commit is contained in:
@@ -33,7 +33,6 @@
|
||||
<orderEntry type="module" module-name="descriptors" />
|
||||
<orderEntry type="library" exported="" name="idea-full" level="project" />
|
||||
<orderEntry type="library" name="uast-java" level="project" />
|
||||
<orderEntry type="module" module-name="android-extensions-compiler" />
|
||||
<orderEntry type="module" module-name="frontend.script" />
|
||||
</component>
|
||||
</module>
|
||||
+2
@@ -73,6 +73,8 @@ internal class FunctionsHighlightingVisitor(holder: AnnotationHolder, bindingCon
|
||||
private fun highlightCall(callee: PsiElement, resolvedCall: ResolvedCall<out CallableDescriptor>) {
|
||||
val calleeDescriptor = resolvedCall.resultingDescriptor
|
||||
|
||||
if (applyHighlighterExtensions(callee, calleeDescriptor)) return
|
||||
|
||||
if (calleeDescriptor.isDynamic()) {
|
||||
highlightName(callee, DYNAMIC_FUNCTION_CALL)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.idea.highlighter
|
||||
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
|
||||
abstract class HighlighterExtension {
|
||||
abstract fun highlightReference(elementToHighlight: PsiElement, descriptor: DeclarationDescriptor): TextAttributesKey?
|
||||
|
||||
companion object {
|
||||
val EP_NAME = ExtensionPointName.create<HighlighterExtension>("org.jetbrains.kotlin.highlighterExtension")
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,10 @@ package org.jetbrains.kotlin.idea.highlighter
|
||||
import com.intellij.lang.annotation.Annotation
|
||||
import com.intellij.lang.annotation.AnnotationHolder
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtVisitorVoid
|
||||
|
||||
abstract class HighlightingVisitor protected constructor(
|
||||
@@ -44,4 +46,16 @@ abstract class HighlightingVisitor protected constructor(
|
||||
createInfoAnnotation(textRange, message).textAttributes = attributesKey
|
||||
}
|
||||
}
|
||||
|
||||
protected fun applyHighlighterExtensions(element: PsiElement, descriptor: DeclarationDescriptor): Boolean {
|
||||
if (!NameHighlighter.namesHighlightingEnabled) return false
|
||||
for (extension in Extensions.getExtensions(HighlighterExtension.EP_NAME)) {
|
||||
val key = extension.highlightReference(element, descriptor)
|
||||
if (key != null) {
|
||||
highlightName(element, key)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.highlighter
|
||||
|
||||
import com.intellij.lang.annotation.AnnotationHolder
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.android.synthetic.res.AndroidSyntheticProperty
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
|
||||
import org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingColors.*
|
||||
@@ -73,13 +72,12 @@ internal class PropertiesHighlightingVisitor(holder: AnnotationHolder, bindingCo
|
||||
elementToHighlight: PsiElement,
|
||||
descriptor: PropertyDescriptor) {
|
||||
|
||||
if (applyHighlighterExtensions(elementToHighlight, descriptor)) return
|
||||
|
||||
val attributesKey = when {
|
||||
descriptor.isDynamic() ->
|
||||
DYNAMIC_PROPERTY_CALL
|
||||
|
||||
descriptor is AndroidSyntheticProperty ->
|
||||
ANDROID_EXTENSIONS_PROPERTY_CALL
|
||||
|
||||
descriptor.extensionReceiverParameter != null ->
|
||||
EXTENSION_PROPERTY
|
||||
|
||||
|
||||
+1
@@ -86,6 +86,7 @@ internal class TypeKindHighlightingVisitor(holder: AnnotationHolder, bindingCont
|
||||
val identifier = classOrObject.nameIdentifier
|
||||
val classDescriptor = bindingContext.get(BindingContext.CLASS, classOrObject)
|
||||
if (identifier != null && classDescriptor != null) {
|
||||
if (applyHighlighterExtensions(identifier, classDescriptor)) return
|
||||
highlightName(identifier, textAttributesKeyForClass(classDescriptor))
|
||||
}
|
||||
super.visitClassOrObject(classOrObject)
|
||||
|
||||
@@ -26,5 +26,6 @@
|
||||
<orderEntry type="module" module-name="light-classes" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="dx-android" level="project" />
|
||||
<orderEntry type="module" module-name="idea-gradle" />
|
||||
<orderEntry type="module" module-name="android-extensions-compiler" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.intellij.openapi.editor.colors.TextAttributesKey
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.android.synthetic.res.AndroidSyntheticProperty
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.highlighter.HighlighterExtension
|
||||
import org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingColors
|
||||
|
||||
class AndroidHighlighterExtension : HighlighterExtension() {
|
||||
override fun highlightReference(elementToHighlight: PsiElement, descriptor: DeclarationDescriptor): TextAttributesKey? =
|
||||
if (descriptor is AndroidSyntheticProperty)
|
||||
KotlinHighlightingColors.ANDROID_EXTENSIONS_PROPERTY_CALL
|
||||
else
|
||||
null
|
||||
}
|
||||
@@ -90,6 +90,8 @@
|
||||
<classBuilderFactoryInterceptorExtension implementation="org.jetbrains.kotlin.android.synthetic.codegen.ParcelableClinitClassBuilderInterceptorExtension"/>
|
||||
|
||||
<androidDexer implementation="org.jetbrains.kotlin.android.debugger.AndroidDexerImpl"/>
|
||||
|
||||
<highlighterExtension implementation="org.jetbrains.kotlin.android.AndroidHighlighterExtension"/>
|
||||
</extensions>
|
||||
|
||||
<project-components>
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
|
||||
<extensionPoint name="idePlatformSupport"
|
||||
interface="org.jetbrains.kotlin.caches.resolve.IdePlatformSupport"/>
|
||||
|
||||
<extensionPoint name="highlighterExtension"
|
||||
interface="org.jetbrains.kotlin.idea.highlighter.HighlighterExtension"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="org.jetbrains.kotlin">
|
||||
|
||||
Reference in New Issue
Block a user