<commit_before>package com.redhat.ceylon.eclipse.imp.editorActionContributions;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.imp.editor.UniversalEditor;
import org.eclipse.imp.parser.ISourcePositionLocator;
import org.eclipse.jface.action.Action;
import org.eclipse.swt.widgets.Shell;

import com.redhat.ceylon.compiler.typechecker.model.Declaration;
import com.redhat.ceylon.compiler.typechecker.tree.Tree;
import com.redhat.ceylon.eclipse.imp.core.CeylonReferenceResolver;
import com.redhat.ceylon.eclipse.imp.editor.FilteredTypesSelectionDialog;
import com.redhat.ceylon.eclipse.imp.parser.CeylonParseController;
import com.redhat.ceylon.eclipse.imp.quickfix.QuickFixAssistant;
import com.redhat.ceylon.eclipse.ui.CeylonPlugin;
import com.redhat.ceylon.eclipse.ui.ICeylonResources;

class OpenDeclarationAction extends Action {
    private final UniversalEditor editor;
    
    OpenDeclarationAction(UniversalEditor editor) {
        this("Open Declaration...", editor);
    }
    
    OpenDeclarationAction(String text, UniversalEditor editor) {
        super(text);
        this.editor = editor;
        setImageDescriptor(CeylonPlugin.getInstance().getImageRegistry()
                .getDescriptor(ICeylonResources.CEYLON_OPEN_DECLARATION));
    }
    
    @Override
    public void run() {
        Shell shell = CeylonPlugin.getInstance().getWorkbench()
                .getActiveWorkbenchWindow().getShell();
        FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(shell, editor);
        dialog.setTitle("Open Declaration");
        dialog.open();
        Object[] types = dialog.getResult();
        if (types != null && types.length > 0) {
            CeylonParseController cpc = (CeylonParseController) editor.getParseController();
            Tree.Declaration node = CeylonReferenceResolver.getDeclarationNode(cpc, 
                    (Declaration) types[0]);
            ISourcePositionLocator locator = cpc.getSourcePositionLocator();
            IPath path = locator.getPath(node).removeFirstSegments(1);
            int targetOffset = locator.getStartOffset(node);
            IResource file = cpc.getProject().getRawProject().findMember(path);
            QuickFixAssistant.gotoChange(file, targetOffset, 0);
        }
    }
}<commit_msg>use selected text to init search pattern<commit_after>package com.redhat.ceylon.eclipse.imp.editorActionContributions;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.imp.editor.UniversalEditor;
import org.eclipse.imp.parser.ISourcePositionLocator;
import org.eclipse.jface.action.Action;
import org.eclipse.swt.widgets.Shell;

import com.redhat.ceylon.compiler.typechecker.model.Declaration;
import com.redhat.ceylon.compiler.typechecker.tree.Tree;
import com.redhat.ceylon.eclipse.imp.core.CeylonReferenceResolver;
import com.redhat.ceylon.eclipse.imp.editor.FilteredTypesSelectionDialog;
import com.redhat.ceylon.eclipse.imp.parser.CeylonParseController;
import com.redhat.ceylon.eclipse.imp.quickfix.QuickFixAssistant;
import com.redhat.ceylon.eclipse.ui.CeylonPlugin;
import com.redhat.ceylon.eclipse.ui.ICeylonResources;

class OpenDeclarationAction extends Action {
    private final UniversalEditor editor;
    
    OpenDeclarationAction(UniversalEditor editor) {
        this("Open Declaration...", editor);
    }
    
    OpenDeclarationAction(String text, UniversalEditor editor) {
        super(text);
        this.editor = editor;
        setImageDescriptor(CeylonPlugin.getInstance().getImageRegistry()
                .getDescriptor(ICeylonResources.CEYLON_OPEN_DECLARATION));
    }
    
    @Override
    public void run() {
        Shell shell = CeylonPlugin.getInstance().getWorkbench()
                .getActiveWorkbenchWindow().getShell();
        FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(shell, editor);
        dialog.setTitle("Open Declaration");
        dialog.setInitialPattern(editor.getSelectionText());
        dialog.open();
        Object[] types = dialog.getResult();
        if (types != null && types.length > 0) {
            CeylonParseController cpc = (CeylonParseController) editor.getParseController();
            Tree.Declaration node = CeylonReferenceResolver.getDeclarationNode(cpc, 
                    (Declaration) types[0]);
            ISourcePositionLocator locator = cpc.getSourcePositionLocator();
            IPath path = locator.getPath(node).removeFirstSegments(1);
            int targetOffset = locator.getStartOffset(node);
            IResource file = cpc.getProject().getRawProject().findMember(path);
            QuickFixAssistant.gotoChange(file, targetOffset, 0);
        }
    }
}
{'fraction_non_alphanumeric': 0.10083857442348008, 'fraction_numerical': 0.0016771488469601676, 'mean_word_length': 3.6958661417322833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6967340', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1293, 'n_words': 207}