Automatically grouping imports in intelliJ IDEA - java

I want to group imports by packages in intelliJ.
Right now it sorts the imports properly, and gives me this.
import com.google.common.Something
import com.google.common.SomethingElse
import org.apache.commons.Something
import org.apache.commons.SomethingElse
I want it to be
import com.google.common.Something
import com.google.common.SomethingElse
import org.apache.commons.Something
import org.apache.commons.SomethingElse
How can I make intelliJ automatically do this, without having to set the package names individually in Editor->Cody Style->Java->Imports->Import Layout.

Related

Android Studio - Reformat code "Optimize imports" order not working properly

When i'm organizing my imports in Android studio (Cmd+Opt+L). I don't understand how Android Studio define the order.
What I notice is that, imports start with common name like android.*, java.*, com.*, which are grouped alone, separated with a blank line, then all other imports are grouped bellow alphabetically.
In my project, shared with other people, androidx.* classes are also grouped alone, right after android.* classes. But in my case, these libraries aren't sorted alone but put at the end, mixed with all other imports.
Ex:
import android.app.Application;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import com.google.android.exoplayer2.C;
import java.util.ArrayList;
import java.util.Date;
import javax.inject.Inject;
// import other classes
Becomes for me after Reformat code :
import android.app.Application;
import android.text.TextUtils;
import com.google.android.exoplayer2.C;
import java.util.ArrayList;
import java.util.Date;
import javax.inject.Inject;
// import other classes + ANDROIDX CLASSES
This is problem, as every time me or a colleague works on a class and use the auto reformat option, git consider it legitimately as change. And sometimes, conflict occurs.
Any idea on how to fix this import order.
Finally found a solution.
The import layout can be modified in settings > Editor > Code Style > Java. Then in the Imports tab, at the bottom there's a section for the import Layout !
Si I added a new package bellow android.* and a blank line.

Replacement for missing liquibase classes moving from liquibase 2.0.3 to 3.3.0

I have a project using liquibase-core 2.0.3. When I updated to liquibase-core 3.3.0 I'm getting a lot of compiler class not found errors for the classes below.
Any help on info on where/what they have been replaced with is much appreciated?
import liquibase.change.core.AnonymousChange;
import liquibase.database.core.MaxDBDatabase;
import liquibase.database.typeconversion.TypeConverter;
import liquibase.database.typeconversion.core.CacheTypeConverter;
import liquibase.database.typeconversion.core.DB2TypeConverter;
import liquibase.database.typeconversion.core.DefaultTypeConverter;
import liquibase.database.typeconversion.core.DerbyTypeConverter;
import liquibase.database.typeconversion.core.FirebirdTypeConverter;
import liquibase.database.typeconversion.core.H2TypeConverter;
import liquibase.database.typeconversion.core.HsqlTypeConverter;
import liquibase.database.typeconversion.core.InformixTypeConverter;
import liquibase.database.typeconversion.core.MSSQLTypeConverter;
import liquibase.database.typeconversion.core.MaxDBTypeConverter;
import liquibase.database.typeconversion.core.MySQLTypeConverter;
import liquibase.database.typeconversion.core.OracleTypeConverter;
import liquibase.database.typeconversion.core.Postgres83TypeConverter;
import liquibase.database.typeconversion.core.PostgresTypeConverter;
import liquibase.database.typeconversion.core.SQLiteTypeConverter;
import liquibase.database.typeconversion.core.SybaseASATypeConverter;
import liquibase.database.typeconversion.core.SybaseTypeConverter;
import liquibase.snapshot.jvm.DB2DatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.DerbyDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.H2DatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.HsqlDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.InformixDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.MSSQLDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.MySQLDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.OracleDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.PostgresDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.SQLiteDatabaseSnapshotGenerator;
import liquibase.snapshot.jvm.StandardJdbcDatabaseSnapshotGenerator;
MaxDBDatabase was pulled into a separate extension https://github.com/liquibase/liquibase-maxdb so you will need to include that jar as well.
The TypeConverter code mainly moved to the classes in liquibase.datatype.
The database-specific SnapshotGenerator classes were replaced with a more general-purpose SnapshotGeneratorFactory and object-specific subclasses vs. database-specific subclasses.
I see you cross-posted to the liquibase forum at http://forum.liquibase.org/topic/replacement-for-missing-liquibase-classes-moving-from-liquibase-2-0-3-to-3-3-0#49382000001219004 If you have specific usage questions, that is probably the best place to follow up since it is more discussion-oriented than stackoverflow.

LWJGL/opengl in eclipse

I cannot seem to import the opengl properly.
I am following this simple tutorial:
https://www.youtube.com/watch?v=ZKJC2cloIqc
As far as I understand, I have the correct jar and native files.
// I can import these
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
//I cannot however import this:
import org.lwjgl.LWJGLEXCEPTION;
//and gl methods such as this are not recognized:
glClear(GL_COLOR_BUFFER_BIT);
I am using eclipse, I also have netbeans and am debating getting the intelij IDE being used in this tutorial if it will make this work.
You didn't Import GL11 to use gl methods (or other versions for certain methods )
You can use a static import so you don't have to put GL11 in front of every method or anything else

Importing everything from an empty package

I have a package named utilities which has several sub-packages. The utilities package has no classes by itself but the sub-packages do.
I can import all the classes from the sub-packages one by one by doing this:
import utilities.consoleredirect.MessageConsole;
import utilities.generalutils.Helper;
import utilities.generalutils.Pair;
import utilities.generalutils.PropertiesUtils;
import utilities.sqlhandling.Connector;
import utilities.sqlhandling.SQLDatabase;
import utilities.sqlhandling.User;
import utilities.tweetshandling.TwitterTools;
import utilities.tweetshandling.WordCounting;
But if I try to do import utilities.*; I get the error that the package does not exist (in my IDE - NetBeans) but if I try to create the package then I get the error that the file already exists. The folder structure is correct, this is it for easier visualization:
So why can't I just do import utilities.*; and I have to manually import every class?
You can't use a wildcard in an import statement to import other packages, it's just for classes.
So you could do:
import utilities.consoleredirect.*;
import utilities.generalutils.*;
import utilities.sqlhandling.*;
import utilities.tweetshandling.*;
If you're using a sensible IDE, you won't need to think about this very much. Just try and use a class by name and the import statement will be added automagically.

How to rename entire java package name in Eclipse so that its all occurences gets renamed?

I want to rename entire package and it's all ocurences includeing package name and imports, change in eclipse.
For example com.google.gdata.client and its classes to com.xyz.google.gdata.client and its all occurences.
Actually, I want to customize gdata-core.1.47.jar source code as per my requirement. First thing I need to do is to change the package structure as per my requirements. But when I followed the above mentioned steps, some more imports were automatically added
For example before refctor,
For class com.google.api.gbase.client has following import
import com.google.gdata.util.common.xml.XmlWriter;
import com.google.gdata.data.Extension;
import com.google.gdata.data.ExtensionProfile;
import com.google.gdata.data.AttributeHelper;
import com.google.gdata.data.ExtensionDescription;
import com.google.gdata.util.ParseException;
import com.google.gdata.util.XmlParser;
But after after rename it to com.google.gdata.client to com.xyz.google.gdata.client it add some more imports like below,
import com.google.api.gbase.client.AddValueHandler;
import com.google.api.gbase.client.AttributeHistogram;
import com.google.api.gbase.client.GoogleBaseAttributeId;
import com.google.api.gbase.client.GoogleBaseAttributeType;
import com.google.api.gbase.client.GoogleBaseEntry;
import com.google.api.gbase.client.UniqueValue;
import com.google.gdata.util.XmlWriter;
import com.xyz.google.gdata.data.AttributeHelper;
import com.xyz.google.gdata.data.Extension;
import com.xyz.google.gdata.data.ExtensionDescription;
import com.xyz.google.gdata.data.ExtensionProfile;
import com.xyz.google.gdata.util.ParseException;
import com.xyz.google.gdata.util.XmlParser;
In the Project Explorer, right click the package name and choose Refactor->Rename.

Categories

Resources