How to maintain different file headers per project in IntelliJ? - intellij-idea

IntelliJ allows you to configure the "File and Code Templates" in Settings.
This is a global setting, however I want different templates depending on which project I am working on (for example there will be different #author tags if its commercial / open source work, and version information varies by project).
Eclipse manages this on a per-workspace basis; how can I achieve the same thing in IntelliJ IDEA?

Unfortunately per project templates are not supported in IntelliJ IDEA. I recommend you comment-on/vote-for/track the feature request Make file templates per-project. (See UPDATE about this feature request below)
A few workarounds you can try...
Create a File Template for each project. Then when you create a new class, use the project's template rather than the standard "Java class" template. It will clutter up your template list a bit, and you have to remember to change from the default template when creating a new class (remember than inline search is available in the new class dialog when setting the type). But it is workable.
The copyright settings are done on a per project basis. Sometimes a need for a specific header can be met using the copyright utility (even if it is not an actual copyright statement). The options are pretty good for determining where it gets placed. The one shortcoming will be that while you can configure it to be a comment just before the class declaration, you can only configure to be a block comment or inline comment, not a javadoc comment.
Finally, a last option would be to write a live template for each project with the header information. Then after you create a class use the proper one to place the header information.
Hopefully those things will help while we wait for the feature to get implemented.
UPDATE
The above mentioned feature request to allow for file templates to be saved on a per project basis has been implemented in IDEA v14.1. It is currently (Feb 2015) available as an EAP (i.e. beta). It is scheduled for release at the end of Q1 2015.

Related

<Gameplay Class>.h vs <Gameplay Class>.generated.h

In unreal engine, what is the difference between the two?
I could not find it in the API, just this: https://docs.unrealengine.com/5.0/en-US/gameplay-classes-in-unreal-engine/
I suspect that it adds .generated if you create the class from the Unreal editor, but I do not understand if it is any different with or without it.
Ah, so the .generated header is required inside the actual header file of the class (specifically as the last header).
https://forums.unrealengine.com/t/creating-classes-in-visual-studio/282386/4
Unreal has a code generation tool called "Unreal Header Tool" or UHT for short. During the build process of the project, it runs right before the actual compiler to generate code for the reflection, based on the UPROPERTY(), UFUNCTION(), etc. calls that you have in your code.
All that information is stored in two files: <Class>.generated.h and <Class>.generated.cpp
The header needs to be included last in the header to ensure that all references in a file are potentially valid in the generated code. Everything within the generated header file can be accessed via the UClass reflection system.
You can find the generated files in the "Intermediate/Build" directory of your project.
You can find the implementation of the UHT in the project on GitHub and a little more info about it in the docs.

how to config Intellij Idea live template's applicable context?

I want to create a live templates group for my custom file type, but when i pick a applicable context, there are a list of kind of file type or language but my custom file type.
Is the list predefined and can not extend?
The available context types depend on the enabled plugins. It says so (and not much more) here in the Jetbrains help page: https://www.jetbrains.com/help/idea/2016.3/live-templates-2.html
If your custom file already has a plugin, maybe all you have to do is add it. For example adding the plugin Perl adds Perl5 to the list.
Otherwise you need to look into how to create an extension. More on that here: http://www.jetbrains.org/display/IJOS/Writing+Plug-ins
Good luck!

Restrict Intellij IDEA backward analysis

I'm trying to analyze one Maven module of a Java project in Intellij IDEA using the Analyze->Inspect Code menu item. I have restricted the scope of the analysis to that project. When it runs the analysis, it gets to a phase called "Perform Backward Analysis" where it is looking at files outside of the module I ran the analysis on. Specifically, it is running the analysis on a large number of XML and HTML files that are used as part of the help documentation of the project and are not related to the code.
At the rate it is going, it is probably not going to finish the analysis this decade, so how do I either get Intellij to really only look at the files in the current directory, or turn off backward analysis, or exclude the XML/HTML files from the backward analysis so that it eventually finished?
When you go to Analyze->Inspect Code, the dialog gives you the option to limit to the "Current file" or the module that is active in the editor when you invoked it. You can also define a custom scope such as just java files or files in a particular package.. Click on the button with the ellipsis. In the dialog, click the help button for the syntax for defining scopes.
You can create a custom scope to do this. If you have a look at the custom scope dialog you'll find an option to exclude selected paths, or you can simply type a pattern, such as !*..*.xml.

Modifying the eclipse code and creating feature patch

I am building an eclipse rcp application. For the Drag and Drop functionality of resources I need extraset of validations. Eclipse doesn't suggest to subclass the ResourceDropAdapterAssistant. So I modified the code for ResourceDropAdapterAssistant which is in the package org.eclipse.ui.navigator.resources.
Now what is the best way to put this feature back to my eclipse? I have gone through this link. http://eclipsesource.com/blogs/2012/07/30/patching-your-own-eclipse-ide/
It has helped me to create a feature patch. But I am clear when I create the feature patch should I include only the modified class or all classes and packages under the plug-in?
Regards,
Priyank Thakkar
It should to only copy the .class files for the modified java files. However, I have created several feature patches and just find it easier and less error prone to include all .class files. So, that is what I would recommend doing.
Remember though that by default, a feature patch applies to exactly one version of the released feature. However, you can modify the created p2 metadata to expand the range. See these excellent blog posts for more information:
http://aniefer.blogspot.com/2009/06/patching-features-with-p2.html
http://aniefer.blogspot.com/2009/06/patching-features-part-2.html

How to keep the header comments up to date in Xcode

Xcode has a habit of putting all kinds of (redundant) information at the top of each code file it creates, containing copyright notices, class names, project names and client names. Like it or not, once you create a new class "A", then refactor it to be called "B", the information is wrong already. The comments will keep saying that this is "A.h" or "A.m". In addition, if you reuse classes from one project in a next, it will also state the wrong project name.
//
// A.h
// ProjectName
//
// Created by Author on 19-06-11.
// Copyright 2011 CompanyName. All rights reserved.
//
There must be a reason there aren't many people complaining about this. What is your trick to keep the header comments up to date? Is there a tool that auto-corrects it all? Is there a hidden setting?
Cheers,
EP.
There may be a way to update your comments but it will be tricky.
As far a customizing the template, this is not as bad. it is just a text file located in
/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Cocoa Touch/
Don't edit the files here, they will get overwritten when you update, or reinstall xcode.
Place your custom templates here, in your home directory.
~/Library/Developer/Xcode/Templates/File Templates/
High Order Bit explains further.
Short Answer: Use SCM Commit Hooks (git example, svn example, cvs example)
Reason: Well, you can be rest assured that XCode will not do it. What XCode can do is attach itself to version control system. Its fairly simple to do using commit hooks that most SCMs support. They fire up before/after the commit/push so that source code is updated. You can even send automated emails when commiting etc.
Since GIT is the most popular one in my opinion these days, see this article.
I use custom templates (see #TMB's comment for a link explaining creating your own) that eliminate the project name and copyright info. File name changes rarely enough that that hasn't bothered me yet. If it became a problem, I would just eliminate it from my templates. If I did it again, I would eliminate the file line from the start: There are better and more reliable ways to figure out what file you're in than going to the top of the file.