Setting a breakpoint for when a Java class is loaded in IntelliJ IDEA - intellij-idea

Is there a way to set a breakpoint for when a particular Java class is loaded in IntelliJ IDEA?

In 2016 version it works by setting the breakpoint to the class definition line (public class YourClass ...). You don't have to use explicit constructor, it stops when ... new YourClass(); is called.

Not that I know of. But if you are trying to determine from where a class is first being loaded, you could put a break point in the constructor (or static fields/block) of the class, and look at the stack trace. That should tell you where the first call to the class is being made.

Related

Shortcut in intelliJ to jump to corresponding method

On windows, I know that we can search for all the methods in the current class by using Ctrl+F12.
Suppose, that I am in the class Car.java
and there we have a method called accelerate();
The method is really long and now I did some modifications at the end of this method. How can I jump back to the place where the method accelerate() starts?
I used Ctrl+U but that just does not do anything at all.
Refer to this page from IntelliJ's manual: Method navigation
It's Alt+Up or Alt+Down

Intellisense - deduce right Class by its methods

I'm used to work with NetBeans and now I'm trying IntelliJ. So my question is: Does IntelliJ has a way to get right class by its methods?
For example, in NetBeans if I write:
glGenBu // Intellisense will kick in and will suggest me
to use GL15.glGenBuffers() method from GL15 class
This will automatically import the right library.
This is very handy because I'm working with LWJGL and it has a bad way to manage OpenGL methods ('GLXX' where XX is the version of OpenGL and all methods that appeared in that version are stored in that class) and I never remember the right class where my desired method is.
Thank you.
Pressing Ctrl+Space when you already see completion list will show more suggestions, with static methods from the entire project among them. See https://www.jetbrains.com/help/idea/auto-completing-code.html for more details.

Identify the superclass or interface on which a method is being called in the Java editor of IntelliJ 2018?

Is there a quick easy way to have IntelliJ identify the superclass or interface defining the method being called in a class?
For example, in the following example, the fireEvent method is being called on the implicit this but this method is not defined within this Java class being edited in IntelliJ 2018.3. Is there some way to ask IntelliJ which of the several interfaces being implemented as well as any parent in the superclass hierarchy defines this particular method?
…
private void doIt() {
…
fireEvent( event ) ;
}
What I am asking is for the opposite of this Question, Does IntelliJ have the equivalent of the Eclipse “method view”?. That Question asks “for a given class, what are its methods offered?”. I am asking “for a given method being invoked, from what inherited superclass or interface is that method defined?”.
I generally just context-click (Ctrl-click on PC, Command-click on macOS) to navigate to the source for a method. The .java file of the superclass or interface opens in the editor.
In order to avoid navigating away, you can also context-hover. Another option is showing the javadoc via context-q when the cursor is somewhere in the method name.

Xcode pluginDidLoad not getting called when adding objective-c file in swift plugin

I'm working on a plugin for Xcode. It is supposed to be written in Swift.
When I start with a fresh plugin project (I'm using this Xcode Plugin template which is also available via Alcatraz) the project compiles and runs fine.
The pluginDidLoad method is getting called right after Xcode starts. As soon as I add any Objective-C file (and a bridging header of course) the pluginDidLoad method is not getting called anymore.
The Objective-C file might be as simple as an empty class that is a subclass of NSObject.
Removing the target-memberbership (for the plugin-target) from the newly created Objective-C (.m) file the aforementioned mentioned method is getting called again.
Has anyone developed a Xcode plugin in Swift that also uses Objective-C files before and got this working?
Update
It seems that my original solution only works with Swift only projects because Xcode always takes the objective c class if you have one.
So here is another trick: Extend the NSObject class by the function class func pluginDidLoad(bundle: NSBundle) {} and initialize your plugin there. Then it doesn't matter on which class it is called. You might have to check that also all Swift classes subclass NSObject. I pushed it to my repository that you can have a look
Original Post
I think I could reproduce the problem now. To simplify the problem, let's say that we have only two swift classes PluginMain and PluginHelper.
As you said, sometimes the plugin isn't getting called for some mysterious reason. I was struggling with the problem again and I was wondering how Xcode knows which class is the main class. So I came up with the idea to put the following initializer in both classes PluginMain and PluginHelper
class func pluginDidLoad(bundle: NSBundle) {
let appName = NSBundle.mainBundle().infoDictionary?["CFBundleName"] as? NSString
if appName == "Xcode" {
//sharedPlugin = SwiftySafe(bundle: bundle)
//initialize your shared plugin
}
}
By putting a breakpoint or log message in pluginDidLoad in both classes, I notices that Xcode isn't ignoring the plugin, it is just loading the wrong class (e.g. PluginHelper instead of PluginMain).
The Solution
It turns out that Xcode uses the class that is compiled first as the main class and calls pluginDidLoad only on that. So you can change that by reordering the "Compiled Sources" under your target settings->Build Phases. Move your main class so that it is on top. In the following image you find an example from my project. SwiftySafe is my main class.
My example
You will find my project here https://github.com/creinders/SwiftySafe if you want to compare the settings.
The pluginDidLoad method is called on the principal class. When the principal class is a Swift class, you have to include the module name in the NSPrincipalClass Info.plist key.
So if your target name is MyPlugin and your principal class is MyClass, set NSPrincipalClass to MyPlugin.MyClass.
Also make sure that MyClass inherits from NSObject.
Sometimes you need to tell Xcode to reload bundle. Run this and restart Xcode
defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-7.3

Overriding a method in behavior -smalltalk-

I have an object A in Smalltalk and I want to override a method specifically the method compile in the behavior.
my aim is to customize compile method by adding asserts before compiling a code.
I know that compile is found in the A class (up until behavior) but how can I use it ?
I have tried a lot of ways non are working, the last of what I did is :
I defined a method :
compile:code
self class compile:code. "this is not working it tells me message not understood"
how can I do this ?
[Pharo] Try redefining the method #compile:classified:withStamp:notifying: on the class side of your class. In this new implementation combine the assertion code with the first parameter (which is the source code you are about to compile) and then delegate to super with the modified code.