Eclipse source code reading: gototypeaction

Source: Internet
Author: User

Go to type is a sub-menu function under the navigate menu of Eclipse, as shown below:

Most of the content is the same as {eclipse source code reading: Go to resource click open link.

Paste the core code of the analysis directly here, and add Chinese comments to the key part.

/*************************************** **************************************** * Copyright (c) 2000,200 8 IBM Corporation and Others. * All Rights Reserved. this program and the accompanying materials * are made available under the terms of the eclipse Public License V1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html ** contributors: * IBM Corporation-initial API and implementation ********************************** **************************************** * ***/package Org. eclipse. jdt. internal. UI. packageview; import Org. eclipse. SWT. widgets. shell; import Org. eclipse. jface. action. action; import Org. eclipse. jface. dialogs. idialogconstants; import Org. eclipse. jface. dialogs. messagedialog; import Org. eclipse. jface. dialogs. progressmonitordialo G; import Org. eclipse. jface. viewers. istructuredselection; import Org. eclipse. jface. viewers. structuredselection; import Org. eclipse. UI. platformui; import Org. eclipse. UI. dialogs. selectiondialog; import Org. eclipse. jdt. core. icompilationunit; import Org. eclipse. jdt. core. ijavaelement; import Org. eclipse. jdt. core. itype; import Org. eclipse. jdt. core. javamodelexception; import Org. eclipse. jdt. core. search. searchengi Ne; import Org. eclipse. jdt. internal. corext. util. messages; import Org. eclipse. jdt. UI. ijavaelementsearchconstants; import Org. eclipse. jdt. UI. javaelementlabels; import Org. eclipse. jdt. UI. javaui; import Org. eclipse. jdt. internal. UI. ijavahelpcontextids; import Org. eclipse. jdt. internal. UI. javaplugin; import Org. eclipse. jdt. internal. UI. util. exceptionhandler; Class gototypeaction extends action {private packageexp Lorerpart fpackageexplorer; gototypeaction (packagepolicerpart) {super (); settext (packagesmessages. gototype_action_label); setdescription (packagesmessages. gototype_action_description); fpackageexplorer = part; platformui. getworkbench (). gethelpsystem (). sethelp (this, ijavahelpcontextids. goto_type_action);} public void run () {shell = javaplugin. getactiveworkbenchshell (); selectiondialog dialog = NUL L; // in essence, the filteredtypesselectiondialog dialog box is constructed. For more information, see my other summary () Try {dialog = javaui. createtypedialog (shell, new progressmonitordialog (Shell), searchengine. createworkspaceconds (), ijavaelementsearchconstants. consider_all_types, false);} catch (javamodelexception e) {String title = getdialogtitle (); string message = packagesmessages. gototype_error_message; exceptionhandler. handle (E, title, message); return;} Dialog. Settitle (getdialogtitle (); dialog. setmessage (packagesmessages. gototype_dialog_message); If (dialog. open () = idialogconstants. cancel_id) {return;} object [] types = dipes. getresult (); If (types! = NULL & types. length> 0) {gototype (itype) types [0]); // only select the first element} private void gototype (itype type) {// type. getancestor obtains the icompilationunit Cu = (icompilationunit) Type of the ancestor of the specified type (INT value is defined in ijavaelement. getancestor (ijavaelement. compilation_unit); ijavaelement element = NULL; If (Cu! = NULL) {element = Cu. getprimary ();} else {element = type. getancestor (ijavaelement. class_file);} If (element! = NULL) {packagepolicerpart view = packagepolicerpart. openinactiveperspective (); If (view! = NULL) {// In the tree structure of package explorer, locate view. selectreveal (New structuredselection (element); If (! Element. equals (getselectedelement (View) {messagedialog. openinformation (fpackageexplorer. getsite (). getshell (), getdialogtitle (), messages. format (packagesmessages. packageexplorer_element_not_present, javaelementlabels. getelementlabel (element, javaelementlabels. all_default) ;}}} private object getselectedelement (packagecyclerpart view) {return (istructuredselection) view. getsite (). getselectionprovider (). getselection ()). getfirstelement ();} private string getdialogtitle () {return packagesmessages. gototype_dialog_title ;}}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.