IntelliJ IDEA, Open API - list methods requiring be implemented - scala

I am developing an IntelliJ IDEA plugin which has to generate some project-specific classes in the Java/Scala project. I have a superclass and a few traits to extend. How can I list methods, which I need to implement in a class being created?
I mean the same list that will appear in the 'Implement methods' dialog.

In the source code for the IDEA community version, take a look at the com.intellij.codeInsight.daemon.impl.quickfix.ImplementMethodsFix class for an example of doing this. The chooseMethodsToImplement method ultimately calls com.intellij.codeInsight.generation.OverrideImplementUtil
.showOverrideImplementChooser(...) to get the methods. Also take a look at the com.intellij.codeInsight.generation.OverrideImplementExploreUtil class.

Related

How to properly implement repository in flutter/dart

Being new to flutter and dart, I am looking for ways to structure my projects. I have found that the Repository pattern made its way to dart (I have a strong Java background), but I have found that there's not the necessary tools yet to properly implement a repository.
How I would normally approach this is to first create the simple straightforward methods. I ended up with the following dart code:
abstract class CategoryRepository {
Future<List<Category>> getCategories();
Future<Category?> getCategoryById(String id);
}
All is good. But now imagine I have a PostRepository, and I only want to return posts of a specific category? I am missing a standardized way in flutter how to add conditions to my repository select methods. I cannot believe nobody has written something for this purpose before so I am doubting whether I am on the right track here. Maybe my Java background is throwing me off.
In Java (specifically Spring JPA) I am used to specifications, predicates and criteria as documented here.
In .NET you can implement select methods of a repository pattern with the Expression class which allows you to use LINQ to add select criteria as documented here.
For Flutter or Dart, what would be the equivalent? Or am I on the wrong track?
I have found the flutter_repository package, but it is deprecated (without a reason). Looking at the documentation it indeed had Specifications which are used to add conditions. This would be exactly what I expect/need, but again it's deprecated.
This is where I cannot find the information publicly anymore and am questioning "how to properly implement repository in flutter/dart", hence the reason for posting this.

How to get the implementations of dart abstract classes in dart-lang github repo?

Since dart is an open source language I was trying to get the implementations of dart abstract classes? for example I would like to see how dart team implemented String abstract class to see "trim()" method implementation, there is similar question here maybe but couldn't help me.
Navigating the Dart SDK repository require some experience before it gets easier. One reason is that it contains different implementation of some methods depending on the target platform (native vs JavaScript). Also, sometimes the native implementation is being done in C++ depending on if that makes more sense.
In your case, I have found the following two implementation of String.trim(). The first is used for native (Dart VM and AOT):
https://github.com/dart-lang/sdk/blob/1278bd5adb6a857580f137e47bc521976222f7b9/sdk/lib/_internal/vm/lib/string_patch.dart#L485
And the second is used when the target is JavaScript (sometimes, we can proxy methods directly to native JavaScript methods but in this case, the trim() in JS does have a different behavior from the String.trim() in Dart. This is documented above the method in the link):
https://github.com/dart-lang/sdk/blob/1278bd5adb6a857580f137e47bc521976222f7b9/sdk/lib/_internal/js_runtime/lib/js_string.dart#L263
Note about the annotations used in the first link
The internal Dart source code can often look a bit alien compared to the normal Dart code. E.g.:
#pragma("vm:recognized", "asm-intrinsic")
#pragma("vm:external-name", "String_charAt")
external String operator [](int index);
The #pragma is used tell the Dart compiler some additional information. It can e.g. be to enforce inlining of certain methods. Or as here, tell the compiler it should call a C++ method bound to an entry called String_charAt. If we make a search in the GitHub repo. we can find that method here:
https://github.com/dart-lang/sdk/blob/e995cb5f7cd67d39c1ee4bdbe95c8241db36725f/runtime/lib/string.cc#L443-L449

How to distinguish wizards in Eclipse RCP?

We have an Eclipse IDE application on 3.x that uses various newWizards to allow the user to create different files. Although these files differ slightly contentwise, the structure of the wizards is quite similar.
Thus, a sound object-oriented approach would be to instantiate different wizards from the same class and initialize them with different data.
Problem:
To decide what wizard needs which data we need a way to distinguish the different already instantiated wizards (e.g during the call to the init method of the wizard).
Is there any way to do so? It would e.g. help if somebody knows a way to get the wizard's id defined in the extension point from within the instantiated wizard.
If your wizard implements IExecutableExtension, it will be passed the configuration element that represents the extension for which it is created.
You can also use extension factories in that you specify a type that implements IExecutableExtensionFactory.
The interface allows you to control how the instances provided to extension-points (wizards in your case) are created.
Extension example:
<extension point="org.eclipse.ui.wizards">
<newWizard
name="..."
class="com.example.WizardFactory">
</newWizard>
Note that the extension factory may also implement IExecutableExtension to gain access to extension attributes before creating the extension's executable class.

Using only part of a class from a different target

I just created a new target for the Lite version of my app. The Lite app only uses part of a base class that I have in the main app, ie it won't need to use an option that requires it to import 4 or 5 files.
My question is, from a design perspective, what is the best way to handle this so that my Lite version can only use the part of the class that it needs? Obviously, one solution is I just import those 4 unnecessary files into Lite build phase, and just use the whole class (even the parts it doesn't need). This seems inefficient though. I know I can do an ifndef to block those files from being imported if the Lite version is running, but how do I block out the code in the class from also not being picked up by the compiler?
Would a better way just be to have my Lite version create a subclass of the Base class that only uses the options it needs? But then I believe, would I still need to import those unnecessary files?
Just a bit confused about this, first time I've ever created another target that utilizes code from the main target. Any help appreciate thanks.
Put the common/lite functionality in a super class. Heavy functionality in the sub-class.
As another answer points out, you can handle this by putting the lite functionality in a subclass and the full functionality in a superclass.
Another option is to use a single class, and add the full functionality in an Objective-C category. Essentially, you can define methods in the category to supplement – or replace – methods in the base implementation.
Unlike a subclass, however, methods defined in a category can't invoke super to get the base class's functionality. super still refers to the base class's superclass, whether that's NSObject, UIDocument, or what have you – not the implementation without the category.
The advantage is that you only have one class name, so the code which instantiates your class (or classes) doesn't need to use something like #ifdef to switch classes and #includes depending on whether you're building the lite or full version.

I want to know list of methods of predefined classes in objective-c

I want to know list of methods of predefined classes in objective-c using any tool like "javap" in java.
In java, javap tool is used for getting list of all existing methods of class using command prompt.
Is it possible in objective-c? any tools are available?
Please help me.
Thank U.
you can use the objc runtime function class_copyMethodList, then enumerate the results for the info you are interested in.