Light Classes: Generate light wrappers for name identifiers
diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt
index 53347a7..28597e2 100644
--- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt
+++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt
@@ -385,6 +385,10 @@
     override fun getElementType(): IStubElementType<out StubElement<*>, *>? = classOrObject.elementType
     override fun getStub(): KotlinClassOrObjectStub<out KtClassOrObject>? = classOrObject.stub
 
+    private val _lightIdentifier = KtLightIdentifier(this, classOrObject)
+
+    override fun getNameIdentifier() = _lightIdentifier
+
     companion object {
         private val JAVA_API_STUB = Key.create<CachedValue<WithFileStubAndExtraDiagnostics>>("JAVA_API_STUB")
 
diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightField.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightField.kt
index 6b5183d..45d2ca5 100644
--- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightField.kt
+++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightField.kt
@@ -25,6 +25,7 @@
 import org.jetbrains.kotlin.name.FqName
 import org.jetbrains.kotlin.psi.KtDeclaration
 import org.jetbrains.kotlin.psi.KtEnumEntry
+import org.jetbrains.kotlin.psi.KtNamedDeclaration
 
 interface KtLightField : PsiField, KtLightDeclaration<KtDeclaration, PsiField>
 
@@ -41,7 +42,9 @@
 
     override fun getName() = delegate.name
 
-    override fun getNameIdentifier() = delegate.nameIdentifier
+    private val _lightIdentifier = KtLightIdentifier(this, origin as? KtNamedDeclaration)
+
+    override fun getNameIdentifier() = _lightIdentifier
 
     override fun getDocComment() = delegate.docComment
 
diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightIdentifier.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightIdentifier.kt
new file mode 100644
index 0000000..a36820c
--- /dev/null
+++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightIdentifier.kt
@@ -0,0 +1,30 @@
+/*
+ * 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.asJava
+
+import com.intellij.openapi.util.TextRange
+import com.intellij.psi.PsiNameIdentifierOwner
+import com.intellij.psi.impl.light.LightIdentifier
+import org.jetbrains.kotlin.psi.KtNamedDeclaration
+
+class KtLightIdentifier(
+        private val lightOwner: PsiNameIdentifierOwner,
+        private val ktDeclaration: KtNamedDeclaration?
+) : LightIdentifier(lightOwner.manager, ktDeclaration?.nameIdentifier?.text ?: "") {
+    override fun getParent() = lightOwner
+    override fun getTextRange() = ktDeclaration?.nameIdentifier?.textRange ?: TextRange.EMPTY_RANGE
+}
\ No newline at end of file
diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightMethod.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightMethod.kt
index 9c02a69..83a1b49 100644
--- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightMethod.kt
+++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightMethod.kt
@@ -112,6 +112,10 @@
 
     override fun getModifierList() = _modifierList
 
+    private val _lightIdentifier = KtLightIdentifier(this, origin as? KtNamedDeclaration)
+
+    override fun getNameIdentifier() = _lightIdentifier
+
     override fun getParameterList() = paramsList.value
 
     override fun getTypeParameterList() = typeParamsList.value