Bug 426909 - Please add CompilationUnitToFileAdapter
Summary: Please add CompilationUnitToFileAdapter
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-29 10:59 EST by Paul Verest CLA
Modified: 2014-07-17 10:45 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Verest CLA 2014-01-29 10:59:39 EST
Currently to get IFile for selected resource requires adding adapter that makes extensions dependent on JDT. While actually it is missing functionality in JDT (as well as in JSDT).

Please provide such adapter with JDT.


	import org.eclipse.core.resources.IFile;
	import org.eclipse.core.runtime.IAdapterFactory;
	import org.eclipse.jdt.core.ICompilationUnit;
	
	
	/** The adapter factory class
	http://stackoverflow.com/questions/775709/eclipse-pde-navigator-view-treeselection-obtaining-the-file-type-and-name
	 */
	public class CompilationUnitToFileAdapter implements IAdapterFactory {
	    @Override
	    public Object getAdapter(Object adaptableObject, Class adapterType) {
	        if (adaptableObject instanceof ICompilationUnit)
	            // note: "adapting" it here just means returning the ref'd IFile
	            return (IFile) ((ICompilationUnit)adaptableObject).getResource();
	        return null;
	    }
	    @Override
	    public Class[] getAdapterList() {
	        return new Class[] {IFile.class};
	    }
	}

plugin.xml

    <!-- -->
	<extension point="org.eclipse.core.runtime.adapters">
	    <factory
	        adaptableType="org.eclipse.jdt.core.ICompilationUnit"
	        class="org.nodeclipse.enide.jdt.CompilationUnitToFileAdapter">
	        <adapter type="org.eclipse.core.resources.IFile" />
	    </factory>
	</extension>