score:1
Accepted answer
the input to an editor does not have to support adapting to ifile
. the input will usually implement one or more of ifileeditorinput
, ipatheditorinput
, iurieditorinput
and ilocationprovider
.
this code will find the ifile
or ipath
if possible:
/**
* get a file from the editor input if possible.
*
* @param input the editor input
* @return the file or <code>null</code>
*/
public static ifile getfilefromeditorinput(final ieditorinput input)
{
if (input == null)
return null;
if (input instanceof ifileeditorinput)
return ((ifileeditorinput)input).getfile();
final ipath path = getpathfromeditorinput(input);
if (path == null)
return null;
return resourcesplugin.getworkspace().getroot().getfile(path);
}
/**
* get the file path from the editor input.
*
* @param input the editor input
* @return the path or <code>null</code>
*/
public static ipath getpathfromeditorinput(final ieditorinput input)
{
if (input instanceof ilocationprovider)
return ((ilocationprovider)input).getpath(input);
if (input instanceof iurieditorinput)
{
final uri uri = ((iurieditorinput)input).geturi();
if (uri != null)
{
final ipath path = uriutil.topath(uri);
if (path != null)
return path;
}
}
if (input instanceof ifileeditorinput)
{
final ifile file = ((ifileeditorinput)input).getfile();
if (file != null)
return file.getlocation();
}
return null;
}
Source: stackoverflow.com
Related Query
- Canonical get active file code throwing FileNotFound exception
- Eclipse Plugin Get Code from Current Open File
- FileNotFound - When trying to get asset file
- How to get IFile handler to an active file in Eclipse editor
- Eclipse throwing Exception on code completition
- Java code working fine in Eclipse but jar file throwing error
- How to get source code from .class file( class file version is 1.2)
- Plugin develop and Xtext: extends ViewPart and doesn't know how to get the AST of the active file
- Using a linked file in Assets directory - FileNotFound Exception
- wrote code for binding in jndi and its throwing null pointer exception I am not sure whats wrong with the configuration
- maven in eclipse giving filenotfound exception for data.csv file
- I cannot get the write to file part of the code to work
- How to get php to run in same file with html code in eclipse?
- PHP: include file with dirname(__FILE__) but still get php code assist in Eclipse
- How to solve unreachable code eclipse... if get exception the " hai " statement will not execute
- FileNotFound exception error even thought the file exists in eclipse
- "please check gdb is codesigned - see taskgated(8)" - How to get gdb installed with homebrew code signed?
- Class file name must end with .class exception in Java Search
- I get "Source not found" when debugging my Java code in Eclipse
- How do you open an external Vim editor containing the active Eclipse editor file
- Why do I get message: "Unhandled event loop exception Java heap space" in Eclipse when using javascript autocomplete?
- How can I get Eclipse to index code inside #ifdef .... #endif
- Change unhandled exception auto-generated catch code in Eclipse?
- How to add Eclipse Code Formatter file in Android Studio
- Debugging jar file with source code attached in eclipse
- Code coverage in Java with EclEmma not scanning expecting exception methods
- Eclipse - break on user code when unhandled exception is raised on Android App
- How to get Eclipse Console to hyperlink text to source code files?
- Get the absolute path of the currently edited file in Eclipse
- Is it possible to get the deleted file from Eclipse workspace?
More Query from same tag
- Set Context Path in Dynamic WebProject
- Android: Editor does not contain a main type
- Jadclipse plugin installation issues
- how to find the class causing memory leak?
- Android - Image button (XML) isn't working?
- How to make eclipse read bundle properties in UTF-8?
- m2eclipse eclipse europa 3.3.2 installation error
- Does NetBeans have anything like Eclipse's Shift-F2 to bring up PHP Manual page for keyword?
- need to read the json arrays inside the object using java
- Getting 'mismatching null constraints' error when implementing Map.entrySet (Java8, Eclipse)
- How to attach libraries to JAR file?
- How to debug PHP application using Eclipse PDT (xdebug and zend debugger)
- installing android sdk 23
- Why Can't I see my android device in DDMS Perspective Mode in Eclipse?
- building android lite version - full and lite versions get mixed on emulator
- Is it possible to limit the memory in Tomcat for a single WAR app?
- trouble installing object aid in eclipse
- Eclipse Google -App -Engine "Will NOT Enhance"
- How to remove charcter console limit from Eclipse?
- How to store multiple movie titles in an array in java using a for loop
- Could not create servlet in web application project (google app engine) by using eclipse
- Cannot connect to IBM Bluemix from eclipse
- Eclipse weblogic domain creation failed. Input line too long
- How to determine memory corruption in web app deployed to T/C 6?
- Quickly browse throw types implementing or declaring a method
- Accessing in-memory HSQLDB in Eclipse
- upgrade servlet 4.0.1 to servlet 5.0
- opening and running Files in android eclipse
- Eclipse Mars 1.0 Build Path Missing From Properties Menu
- Eclipse Error on styles value