for example if I want to view the class Integer in eclipse, how do I get to it?
I know that there is a method to do it from the code itself for example if I write Integer d = 3; there is a bind i can use and view the class Integer, I just can't find it. Anyone knows what I am talking about ?
Simply place the cursor within "Integer" and press F3. Alternatively, you can Navigate->Open Type in the menu bar (or usually press Ctrl/Cmd+Shift+T) and that will display a "type search" window. There you just start typing the name of the class you want to jump to. You can even enter strings such as NPE there ... which would be looking for any class with those uppercase letters (often referred to as "camel case"), like NullPointerException for example.
That will "jump into" any known class in what's considered the current Java Build Path.
If source code is available, you can thus look into Integer.java.
If source code is missing, you will look at something like, but not exactly, de-assembled byte code.
The latter can happen if your project / workspace setup is missing the source files for libraries. In such cases, you have to go into your project setup and manually add source code. (most libraries come with extra zip files containing the Java sources; and those zip files can be added to the library definition in Eclipse). Since Eclipse it will show you whatever copy is on the current selection's Java Build Path, if you're developing with Java, having that be a JDK will allow its sources to appear automatically. It's best to have the Installed JREs preference page only point to JDKs if you can.
Related
I'm developing a simple javacard applet using the jcdk 3.0.5u3 with Eclipse Oxygen3. If I use a simple API from GlobalPlatform like the GPSystem.getCardContentState() results in error.
I've tried to add the globalplatform.jar file from GP API v1.1 and v1.6 to the Reference Libraries part of the package explorer. I also imported the "org.globalplatform.*" into the code.
import org.globalplatform.*;
if(GPSystem.getCardContentState() == GPSystem.APPLICATION_SELECTABLE){
//Do something
}
The converter returns "export file global platform.exp of package org.globalplatform not found"
Java Card doesn't just require a compile stage, it also performs the linking that is usually performed as dynamic linking in the JVM of a normal Java application. Basically it orders the methods and such, and then calls the right serial ID. You don't want your Applet to contain the string names of your fields after all: it would explode the memory requirements, and dynamically looking for classes and fields is not a good idea either within such a restricted platform.
So if you call external libraries then you need to configure:
the .jar file containing the .class files for the normal compiler;
the .exp file which contains the an export of the mapping of the normal names and the ID of the classes and fields specific for the converted classes of the called library;
If it is not already present on the card, you may also need the version specific .cap file for uploading. However, the GP functionality is should already be present on the card.
The ID's are only unique for a specific .cap file / preloaded byte code. This is why you always need the right .exp file for the code that is loaded. If another field is added, the ordering is different and the wrong fields would be linked, if the linker executes at all. So having the right .exp file is a requirement for correct conversion to .cap for your application / library.
For the JCDK I think you just need to configure the right -exportpath, as the GP should be included with the JCDK.
We're creating a new project in IntelliJ and must have something wrong because when we right click on a directory, select New and then get the context menu, Java based options are not shown. Currently get things like File, some HTML options, XML options.
We have assumed so far it's something we haven't configured correctly in the Project/Module configuration. The new module we are talking about is part of a multi module project. We created it using a Maven web archetype.
Any help configuring the project nature?
Edit: The answer is basic: 'That moment when you realise somethings not working because you haven't been clicking 'Apply'... :) We had a good laugh at ourselves when we discovered this'
The directory or one of the parent directories must be marked as Source Root (In this case, it appears in blue).
If this is not the case, right click your root source directory -> Mark As -> Source Root.
This can also happen if your package name is invalid.
For example, if your "package" is com.my-company (which is not a valid Java package name due to the dash), IntelliJ will prevent you from creating a Java Class in that package.
you need to mark your directory as source root (right click on the parent directory)
and then compile the plugin (it is important )
as result you will be able to add classes and more
If you open your module settings (F4) you can nominate which paths contain 'source'. Intellij will then mark these directories in blue and allow you to add classes etc.
In a similar fashion you can highlight test directories for unit tests.
Project Structure->Modules->{Your Module}->Sources->{Click the folder named java in src/main}->click the blue button which img is a blue folder,then you should see the right box contains new item(Source Folders).All be done;
I will share another interesting point. If you try to create a package with the reserved keyword then it will be treated as a normal directory and not a package. I was having this issue where I was creating a package named import and it was converting that to a directory.
Another possible solution is that the project name is not acceptable. For example, creating a project with spaces in the name does not block the project creation but the proper sources are not marked and when those are marked manually, I still was unable to create classes. Recreating the project with hyphens (-) instead of spaces corrected the problem for me.
Make sure you are not creating a package name which is same as predefined keywords in java like enum, int, long etc.
In my case I was trying to create a class under "enum" package. As soon as I changed package name to "enums" I was able to create class in it.
Had this issue too. Invalidating Caches/Restart did the trick for me. Please upvote so the the IntelliJ folks take this more seriously. This gives the IDE a terrible UI/UX experience.
https://youtrack.jetbrains.com/issue/IDEA-203100
There is another case where 'Java Class' don't show, maybe some reserved words exist in the package name, for example:
com.liuyong.package.case
com.liuyong.import.package
It's the same reason as #kuporific 's answer: the package name is invalid.
If you just created your project, let IntelliJ finish indexing your project.
You need to mark your java directory as Source Root ,
Right Click on Java directory
Select Mark Directory as option and click on the sub menu option Source Root
Most of the people already gave the answer but this one is just for making someone's life easier.
TL;DR
You must add the test folder as source.
Right click on java directory under test
Mark it as Tests
Add src/test/java in Test Source Folders
Thats it, IntelliJ will consider them as test source.
Maybe I'm misunderstanding something, but..
I want to be able to see that eclipse is getting Foo.class from a .jar (somewhere in the classpath) when it builds project B.
If I use the 'open type' (Ctrl + Shift + T) it seems that that just shows me all the places that Foo.class exists in my WORKSPACE?
Many thanks..
EDIT: I'm trying to find which jar is introducing a class into my code. It's not my jar. I don't have the source. I can't therefore open it and click it. I want a window that I can type in a type name, like 'Foo.class', and it tells me where that class is being brought in in my classpath. That must be quite simple? Ideally it would also tell me which occurrences later in the classpath were being hidden because it found the first one first. Does that make sense or am I talking nonsense?
EDIT: Guess I'm not making it clear. I don't have a piece of code that uses Foo. It's that somewhere in some included open source library something calls something calls Foo. So I can't highlight or right click anything. I guess I could write a piece of code that has it in? Seems a bit clunky..
Came here looking for the same, so though the question is two years old:
In eclipse Mars, if you press shift+control+T / ⇧+⌘+T on mac to bring up the "Open Type" dialog, the package as well as the name and path of the jar file is shown in the bottom of the window for a selected class.
Alternate Solution : particularly if you want to know the jar files which have needed class , you can search using WINRAR.
Use Find in WinRAR
i) Open WinRAR
ii) Open lib folder ( which contains all jar files ) in WinRAR
iii) Click on Find , type any classname (ex : ClassWriter.class )
iv) Click on OK
you will see all the classes which are named as ClassWriter.class in all jar files in lib folder.
Since there seems to be no good solution or plugin for this, I often create a dummy class in the root of my project:
public class Find {
public static void main(String[] args) {
System.out.println(
SomeClass.class.getProtectionDomain().getCodeSource().getLocation());
}
}
Then I just delete the class. A plugin would be nice :)
Look for .classpath file in your project.
OR
Where ever class Foo is used, go to that statement, while Ctrl key is pressed, left click the class name. Eclipse will take you to the location of Foo class. This will the Foo class eclipse is referring while building your code.
Right click on the class name, then select "Open declaration" (or just press F3), if you don't have a source attached, you can do it at that point. In the package explorer you have the functionality "Link with Editor" (a button with a couple of arrows going back and forward), that redirects you to the jar of the class. If you don't have the source, you still can use the "Link with Editor" functionality to see the propietary jar
I am creating an eclipse plugin, and I need Class object of selected file, not IType. Is it possible, and how is the best way to do it?
Edit: when I think about it, the best way is to add it like run as (like junit, profiler, or other plugins are doing). I suppose they must have access to Class (if X is class in question), because they are running it's functions. So how to create plugin that has "run as " action, and get live object?
In an eclipse plugin, you will, for instance, get the selected file through an IAction.
(it represents the non-UI side of a command which can be triggered by the end user. Actions are typically associated with buttons, menu items, and items in tool bars.)
From there:
IResource selectedResource = ResourceUtils.getSelectedResource();
IResource The workspace analog of file system files and directories. There are exactly four types of resource: files, folders, projects and the workspace root.
From its type, you can cast it into an IFile, which gives you acces to its full path (getFullPath())
Eclipse uses an abstract representation of the object being selected, be it a file (IResource) or be it a Java Type (IJavaType). As it is not required for a source file to be compiled (e.g. disabling auto build), there does not necessarily be a .class file or a Class object for the code being edited. Hence, there is no correct way to get a "Class" object from the a selection in the user interface.
However, as yesterday mentions, you could rely on the fact that the Eclipse builder mechanism will always compile the source files immediately and thus a .class file exists. To reach to this .class file at runtime, you would need to create a dynamic class loader for the project or start a runtime VM. I tried that and it does work, but it is a very unstable approach and can lead to various hard to trace failures.
The classname of an IType "curIType" can be retrieved through
curIType.getFullyQualifiedName()
That's the simple part. But then you have the problem, that this class does not have to be in the classloader of your plugin (if it's a class of one of the userprojects, it's seldom part of your classloader). So calling Class.forName(classname) won't do any good.
I had a similar case and did (in a first attempt) solve it by creating an own thread with an own classloader, which included all libraries of the current classloader and all libraries of the type's project. That's neither a short code nor a simple one and I've already refactored it. It's much simpler to get all information out of the IType and not using the classes anywhere in the plugincode.
Is anyone familiar with a tool that generates code stubs with meaningful names from class and javadoc?
The real question should've been "I have classes without debug information and a matching javadoc, but my IntelliJ IDEA 8.0.1 (please, no IDE wars) doesn't take into account the javadoc and shows me "void setLocation(Object object, String str1, int i1, int i2);" instead of "void setLocation(Object component, String name, int x, int y);" - which makes a HUGE difference, both to auto-completion and ease of use". If this can be answered, I'd be satisfied as well.
I suggest to file a bug against IDEA along these lines: If a class has no debug information but has JavaDocs, IDEA should use the JavaDoc to determine the names of the parameters.
Btw. Eclipse has the same problem. :)
Go to Project Structure (in 8.x that's Ctrl+Alt+Shift+S) -> Modules -> (select the module you're coding) -> Dependencies. Select the dependency (either JAR file or directory) that contains the third party component. Click on the "Edit..." button, a new window will pop up. If you have a JAR file or a folder on your computer with the javadocs, select "Attach JavaDoc..." and point IDEA to the location. You can also point it to an online API using "Specify JavaDoc URL..." - just give it the root of the javadoc-generated output. Select OK and close all the other dialog windows.
Go back to the editor, and highlight a method in the third party component. If you press Ctrl+Q, you should see a javadoc popup with full parameter descriptions.