<commit_before>/*******************************************************************************
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *******************************************************************************/
package org.jetbrains.kotlin.ui.search

import org.eclipse.jdt.ui.search.IMatchPresentation
import org.eclipse.jface.viewers.ILabelProvider
import org.eclipse.search.ui.text.Match
import org.eclipse.jface.viewers.LabelProvider
import org.jetbrains.kotlin.psi.JetReferenceExpression
import org.eclipse.swt.graphics.Image
import com.intellij.psi.util.PsiTreeUtil
import org.eclipse.jdt.ui.JavaUI
import org.eclipse.jdt.ui.ISharedImages
import org.jetbrains.kotlin.eclipse.ui.utils.EditorUtil
import org.jetbrains.kotlin.eclipse.ui.utils.getTextDocumentOffset
import org.eclipse.search.internal.ui.text.EditorOpener
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.ui.PlatformUI
import org.jetbrains.kotlin.core.builder.KotlinPsiManager
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider
import org.eclipse.jface.viewers.StyledString
import org.eclipse.jface.viewers.ITreeContentProvider
import org.eclipse.jface.viewers.Viewer
import org.eclipse.jdt.ui.JavaElementLabels
import org.eclipse.jdt.internal.corext.util.Strings
import org.jetbrains.kotlin.psi.JetElement
import org.jetbrains.kotlin.psi.JetNamedDeclaration

public class KotlinReferenceMatchPresentation : IMatchPresentation {
    private val editorOpener = EditorOpener()
    
    override fun createLabelProvider(): ILabelProvider = KotlinReferenceLabelProvider()
    
    override fun showMatch(match: Match, currentOffset: Int, currentLength: Int, activate: Boolean) {
        if (match !is KotlinElementMatch) return 
        
        val element = match.jetElement
        val eclipseFile = KotlinPsiManager.getEclispeFile(element.getContainingJetFile())
        if (eclipseFile != null) {
            val document = EditorUtil.getDocument(eclipseFile)
            editorOpener.openAndSelect(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
                    eclipseFile,
                    element.getTextDocumentOffset(document),
                    element.getTextLength(),
                    activate)
        }
    }
}

public class KotlinReferenceLabelProvider : LabelProvider() {
    override fun getText(element: Any): String {
        if (element !is KotlinAdaptableElement){
        	throw IllegalArgumentException("KotlinReferenceLabelProvider asked for non-reference expression: $element")
        }
        
        val jetElement = element.jetElement
        return getContainingDeclaration(jetElement)?.let { it.getFqName()?.asString() } ?: ""
    }
    
    override fun getImage(element: Any): Image {
        return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PUBLIC)
    }
    
    private fun getContainingDeclaration(jetElement: JetElement): JetNamedDeclaration? {
        return PsiTreeUtil.getNonStrictParentOfType(jetElement, javaClass<JetNamedDeclaration>())
    }
}<commit_msg>Use name for local classes to represent search result<commit_after>/*******************************************************************************
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *******************************************************************************/
package org.jetbrains.kotlin.ui.search

import org.eclipse.jdt.ui.search.IMatchPresentation
import org.eclipse.jface.viewers.ILabelProvider
import org.eclipse.search.ui.text.Match
import org.eclipse.jface.viewers.LabelProvider
import org.jetbrains.kotlin.psi.JetReferenceExpression
import org.eclipse.swt.graphics.Image
import com.intellij.psi.util.PsiTreeUtil
import org.eclipse.jdt.ui.JavaUI
import org.eclipse.jdt.ui.ISharedImages
import org.jetbrains.kotlin.eclipse.ui.utils.EditorUtil
import org.jetbrains.kotlin.eclipse.ui.utils.getTextDocumentOffset
import org.eclipse.search.internal.ui.text.EditorOpener
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.ui.PlatformUI
import org.jetbrains.kotlin.core.builder.KotlinPsiManager
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider
import org.eclipse.jface.viewers.StyledString
import org.eclipse.jface.viewers.ITreeContentProvider
import org.eclipse.jface.viewers.Viewer
import org.eclipse.jdt.ui.JavaElementLabels
import org.eclipse.jdt.internal.corext.util.Strings
import org.jetbrains.kotlin.psi.JetElement
import org.jetbrains.kotlin.psi.JetNamedDeclaration
import org.jetbrains.kotlin.psi.JetClass
import org.jetbrains.kotlin.ui.editors.completion.KotlinCompletionUtils
import org.jetbrains.kotlin.psi.JetNamedFunction
import org.jetbrains.kotlin.psi.JetClassOrObject
import org.jetbrains.kotlin.psi.JetProperty

public class KotlinReferenceMatchPresentation : IMatchPresentation {
    private val editorOpener = EditorOpener()
    
    override fun createLabelProvider(): ILabelProvider = KotlinReferenceLabelProvider()
    
    override fun showMatch(match: Match, currentOffset: Int, currentLength: Int, activate: Boolean) {
        if (match !is KotlinElementMatch) return 
        
        val element = match.jetElement
        val eclipseFile = KotlinPsiManager.getEclispeFile(element.getContainingJetFile())
        if (eclipseFile != null) {
            val document = EditorUtil.getDocument(eclipseFile)
            editorOpener.openAndSelect(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
                    eclipseFile,
                    element.getTextDocumentOffset(document),
                    element.getTextLength(),
                    activate)
        }
    }
}

public class KotlinReferenceLabelProvider : LabelProvider() {
    override fun getText(element: Any): String {
        if (element !is KotlinAdaptableElement){
        	throw IllegalArgumentException("KotlinReferenceLabelProvider asked for non-reference expression: $element")
        }
        
        val jetElement = element.jetElement
        val declaration = PsiTreeUtil.getNonStrictParentOfType(jetElement, 
                javaClass<JetNamedFunction>(),
                javaClass<JetProperty>(),
                javaClass<JetClassOrObject>()) as? JetNamedDeclaration
        return declaration?.let { it.getFqName()?.asString() ?: it.getNameAsSafeName().asString() } ?: ""
    }
    
    override fun getImage(element: Any): Image {
        return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PUBLIC)
    }
    
    private fun getContainingDeclaration(jetElement: JetElement): JetNamedDeclaration? {
        return PsiTreeUtil.getNonStrictParentOfType(jetElement, javaClass<JetNamedDeclaration>())
    }
}
{'fraction_non_alphanumeric': 0.12034092354662257, 'fraction_numerical': 0.0030530466861722425, 'mean_word_length': 4.052699228791774, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '21845', 'n_tokens_mistral': 2173, 'n_tokens_neox': 2057, 'n_words': 463}