Compile IntelliJ IDEA Community and use the changes in Android Studio?

Hi,

Today I reported what I thought it was a problem on my end but it was actually a bug in the code. Since this may take some time to get fixed and pushed into Android Studio (what I'm actually using) I thought there could be an easy for me to temporarily fix this on my current Android Studio installation.

My first thoughts for this are:

  1. Clone IntelliJ IDEA Community from the GitHub repository.
  2. Make my changes.
  3. Compile the final binary files.
  4. Integrate in Android Studio.


I'm not sure if it's this easy and if it doesn't break anything in Android Studio. I'm thinking that the integration part will be just to copy some .jar file from the compiled binaries into Android Studio, but like I said, not sure if it's this easy...

Any pointers anyone?

For reference, I'm talking about this issue: http://youtrack.jetbrains.com/issue/IDEA-108385

5 comments

Patching a single .class file inside the jar will probably work, but copying an entire jar will most likely lead to a broken installation. The actual story of synchronizing changes between IntelliJ IDEA and Android Studio is a bit complicated at the moment, and right now there is no good way to fetch a revision of the IntelliJ IDEA codebase corresponding to a particular build of Android Studio.

(Given that IntelliJ IDEA Community Edition has the same set of features, why don't you simply use that?)

0

I'd rather use Google's version instead. They might do something specific for android and it may take time to synch that with the Community version, since you just said "synchronizing changes between IntelliJ IDEA and Android Studio is a bit complicated at the moment". That's what I eventually did and it worked fine. I changed a single file and replaced that .class file inside the .jar file. My change worked, I was able to, somewhat, fix the problem in the linked issue but it's not yet perfect...

Regarding fixing the issue at hand, maybe someone can help me:

On this file, I changed the following:

public void visitXmlAttribute(XmlAttribute attribute) {
    final String name = attribute.isNamespaceDeclaration() ? "" : attribute.getName();
    final XmlElementArrangementEntry entry = createNewEntry(
      attribute.getTextRange(), XML_ATTRIBUTE, name, true);
    processEntry(entry, null);
  }

Into:

public void visitXmlAttribute(XmlAttribute attribute) {
    final XmlElementArrangementEntry entry = createNewEntry(
      attribute.getTextRange(), XML_ATTRIBUTE, attribute.getName(), true);
    processEntry(entry, null);
  }

But the thing is, Android XML style dictates that the line:

xmlns:android="http://schemas.android.com/apk/res/android" 

To be always in the same line as the tag name, like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list_view_item" />

But with my code change and with the rearrangement rules, it becomes like this:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list_view_item" />

Which is not right.

If the rearrangement rules are completely disabled (0 rules) and I have this:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list_view_item" />

And then format/rearrange the code, it will become this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list_view_item" />

Which is correct. But it won't have my custom rules applied (which there's a bunch, see this image).

Can anyone help me fix this issue?

0

This is weird, I haven't done anything and everything seems to be working as I wanted... Everything is properly rearranged matching my rules, with my fix an xmlns:android even gets placed on the same line as the tag. I've attached a few files for anyone that wants to test this...

You may also notice the idea.fix.jar file I've attached. This file is the one that contains the .java/.class file modified by my and it only contains that file in the proper folder structure. I found this by accident but placing 'idea.fix.jar' on "lib" folder of Android Studio (next to idea.jar) makes it work. Which means I don't need to replace the whole idea.jar file swapping just one .class file inside it.

Why does this work? I'm glad it works, it makes the whole thing simpler but... Does it make sense that it should work? Just wondering...



Attachment(s):
idea.fix.jar
Custom.xml
xml_arrangement.png
0

Hi Ricardo,

I assume that it works simply because idea.fix.jar is located before idea.jar, that's why when ide classloader is asked to find XmlArrangementVisitor class, it looks into idea.fix.jar first.

Denis

0

That was my first thaught, I just wanted to confirm it.

Thanks :)

0

Please sign in to leave a comment.