I have for example class LivePagedListProvider that that is in the android.arch.paging package.
Is there any direct way to determine which library in gradle file this class belongs to?
You can do this in Android Studio, by using the Navigate... Class menu option (or pressing CTRL-N on Windows).
Press CTRL-N, and when the search box opens up, start typing the name of the class you want to find.
As the matches are shown in the list below, to the right of each match will be shown which gradle dependency this class belongs to.
If you choose to open the class, then in the top left of your screen you will also see the name of the library.
This is useful because it lets you navigate around that JAR file, by clicking the various parts of the package name, but does not give you the full gradle dependency which is shown in the search box above.
A faster way I prefer is to use Search Everywhere box. Double tap shift key and in dialog that opens you can type your class name and its gradle dependency will be shown next to class name in suggestion drop-down.
Not sure you can say its the easy way, but it works for me.
For Mac, cmd+ Click (control + Left Click for Windows ) on that Class(not object) will take you to the declaration, where the Class actually exists.From that Class' package name, you can confidently tell which gradle project implementation that belong to, as both of them will be same.
Related
So this article i am following has this guy nesting packages like this. How can I achieve the same result?
I tried to nest a package like this but I was unable to make it like the image.
As #Sanjeevan is using Eclipse, here is a way to nest packages in Eclipse;
Right click the root folder of your desired "nested" package branch,
Select New > Folder,
Type a name for the package and click finish (in this example, the name of the first folder is parent),
Right click the parent folder.
Select New > Folder,
Type a name for the package and click finish (in this example, the name of the second folder is child),
You will see a folder named parent.child. This is your nested "package". When you create a new class under this folder, either package parent.child; will be added automatically to the top of your classes, or you must add them manually.
The solution was to type the sub packages with a '.'
So if we have a main package say 'com.main' and we wanted to make sure we wanted to create a sub package for that
we should write it as 'com.main.sub'
and to make sure we have it visually follow that, you can read this.
https://stackoverflow.com/a/25378808/20406462
The layout of the packages on disk is standardized, it's not something you can change, and it's the same whether you're using javac, IDEA, Eclipse, or anything else. They are always nested. What you're looking for is how to change they way they're shown to you.
Change the Package Presentation setting in the View to Hierarchical.
I have an eclipse project with a Class named User in my project. This User type in present inside a jar and is then included in build path of my project.
Now I have an extended Version of my User type say ExtendedUser which extend User type. I want to replace all Occurrence of User type with ExtendedUser.
However, when I try refactoring it with Rename (Alt+Shft+R), eclipse gives me Operation not available on current selection. It seems to work on other types which don't reside in a jar.
How can I achieve the above refactoring ?
I could do the search (Ctrl+H) and replace then, but would have to do some manual changes as the import statements would need to be changed too (and import packages are different for User and ExtendedUser).
If you do not want to use your class User anymore. Just make your changes in this class instead of extending the class. If you rename the class all occurencies are changes.
Otherwise you can search with Search > File in the whole project for User an replace the needed points with ExtendedUser.
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.
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