How to determine absolute file path of a Java source file in Eclipse plugin? - eclipse

In my custom Eclipse plugin, I have the fully qualified class name of a Java class as a String, and want to know its actual file path. In fact, I want to know the name of the source folder it resides in.
The class could be from any of the Java projects in the Workspace. The source folder names are arbitrary.
I use Eclipse 3.6.
Thanks!

You will have to use the search engine API. See org.eclipse.jdt.core.search.SearchEngine.
You can see that there are various static functions you can call, each with their own options. You will need to create an appropriate org.eclipse.jdt.core.search.SearchPattern and then pass it to the search engine along with a scope (the workspace) and a requestor (something that gathers all of the results).
Typically, you will get a bunch of stuff back, like ITypes, which are the public API for accessing types in the Java model. You can call IType.getResource().getLocation() to get the filesystem location of any type. The getResource method may return null, so you need to check for that.

You will need to use the JDT API stuff to get to the IResource of the Java class. From there you can use the Resource API to get the containing folders and whatever else you need.

Related

Get file path from IHyperlink

Assuming I have an IHyperlink object, which I get from my Console (actually it is JavaStackTraceHyperlink).
Is there an option to get the file path it uses?
No there is no official API to get the file path.
JavaStackTraceHyperlink does not have the file path and ends up searching the workspace when it needs to find the class.
Both JavaStackTraceHyperlink and the search methods it uses are internal classes and are therefore not part of the API.

Where do I put my resources in Scala?

While studying using Scala with JavaFX I have met the following code in a ProScalaFX example:
val resource = getClass.getResource("AdoptionForm.fxml")
if (resource == null) {
throw new IOException("Cannot load resource: AdoptionForm.fxml")
}
...
val root: jfxs.Parent = jfxf.FXMLLoader.load(resource)
Where do I put the actual "AdoptionForm.fxml" content in this case? Unfortunately I am neither familiar with using resources in Java.
I use SBT as the building system and Idea as an IDE.
There is a related question which suggests a way (putting the resource files in "src/main/resources" or "src/main/resources/packagename"), but it also says it doesn't work actually (needless to say I have tried).
src/main/resources is the correct location for placing resources in a default SBT configuration.
However, one has to be aware of the difference between getClass.getResource and ClassLoader.getResource. Using getClass.getResource("AdoptionForm.fxml") requires the file to be located in a path which corresponds to the package of the class.
For instance: If the class is located in com.domain.utils then the resource must be located at src/main/resources/com/domain/utils/AdoptionForm.fxml.
In order to switch from package-relative locations to absolute locations one can either use ClassLoader.getResource or just prepend the resource string with a /.
Example: getClass.getResource("/AdoptionForm.fxml") loads the resource from src/main/resources/AdoptionForm.fxml

Eclipse is not showing method parameters properly

In my eclipse, when i check for method help with ctrl+space i see the method parameters are showing like strings, int as arguments. Not showing like, string name/int id .
getAttribute(String arg0)
How can i make the eclipse to show the method as getAttribute(String name)
This is really difficult to me identify which param i should pass fro a method.
Any idea, where should i set the settings?
This problem happens when eclipse can't find the source or attached Javadoc, since java argument names are usually not present in the .class files (it would only be present in debug, and not for the interfaces).
You can check if a source or a documentation is attached using the helper F3.
You can increase the timeout eclipse uses for fetching a parameter name from attached Javadoc in the settings.
You can also attach the corresponding documentation jar or source jar as a dependency in order to allow eclipse to look-up the corresponding source.

GWT: Get constants in server side

I'm trying to get the constants (ConstantsWithLookup) stored in the client side in my server side, but it can't figure out how to do it. I have my constants interface and my constants properties in the same folder.
I've tried tips of other similar threads with no success.
I tried Hermes, gwt-i18n-server, gwt-dmesg, GTWI18N, using a ResourceBundle, trying to get source file properties.
For the first two, it seems that the main reason is the outdated support for the newest GWT version. As for the ResourceBundle, it cannot find the properties file because at deployment, there isn't a properties file, just a Constants.class.
I'm trying to avoid changing my properties file to another location (like /WEB-INF/constants).
I'm using Hermes with GWT 2.5.0.rc1, and it works fine. Usage:
put hermes-1.2.0.jar into war/WEB-INF/lib
Then on the server side write something like
MyConstantsWithLookup my = Hermes.get(MyConstantsWithLookup.class, "de");
String string = my.getString(key);
A properties file MyConstantsWithLookup.properties must exist in the same package as MyConstantsWithLookup.java, even if that properties file is empty (which might be the case if you're using #DefaultStringValue etc.)
Also add MyConstantsWithLookup_de.properties etc.
Make sure, that these properties files are copied next to your classes when compiling. Javac doesn't do that, so it must be done in an additional build step (Eclipse usually does this automatically, but it won't happen by itself when you build e.g. with Ant)
Many build setups will skip the java and properties files from the "client" package when compiling the server side. In that case, put your constants files in the "shared" package (if you have one).

IBM Eclipse WSDL Editor: How do I include an external wsdl/schema?

I am trying to create Web Services from the Top-Down approach. I downloaded Eclipse and am using the WSDL gui editor in it to build my WSDL files.
I am splitting up my Services based on "modules". The Types I am adding to the WSDLs all need to reference common stuff, such as PersonEntity, AddressEntity, States enumeration (simple type), Countries enumeration (simple type), and AbstractEntity. Since those items are all common I created a seperate WSDL file (named Commons.wsdl) that contains the type information for those types.
I want to "import" that WSDL into my other WSDL files to use:
For example, I have an entity named RegistrationEntity which inherits from AbstractEntity and contains a PersonEntity as well as an AddressEntity. I'm not sure how to do this... I saw that the WSDL spec has "import" and "include" and am not sure which one to use. Also, how do I actually import (or include) the Commons.wsdl file so that I can use the Types defined within it?
Thanks!
Oh, and I'm not sure if I'm supposed to stick this stuff in a seperate WSDL but another type of file such as an xsd or something. I really wanna follow best practices so if that's the proper way to do it then I'd rather do that.
I found out that the problem I had was I was creating a WSDL file for my commons and using an inline scheme for that, rather than creating an XSD file to be imported by my other WSDLs.
So instead I just created an Commons.XSD as my "Common Schema".