How to properly import Java code style settings with IntelliJ? - java

I tried to import Google's Java code style with IntelliJ.
The style file contains the following configuration:
<code_scheme name="GoogleStyle">
<option name="JAVA_INDENT_OPTIONS">
<value>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="8" />
...
</value>
</option>
...
</code_scheme>
But after the import my settings still show
Tab size 4 (instead of 8)
Indent 4 (instead of 2)
Continuation indent 8 (instead of 4)
When I export that style scheme then in the output file the values are the same as in the original file:
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="8" />
Steps I took to import the style:
Navigate to Settings -> Editor -> Code Style -> Java
Click Manage button next to Scheme dropdown -> Import... -> IntelliJ IDEA code style XML
From the Scheme dropdown select the new option (called "GoogleStyle")
Apply
I'm using IntelliJ IDEA Community 2016.2.2
The expected result is that when I import the style then created style scheme has indent size (etc) the same as specified in the code scheme file.
How can I do that?

EDITED
The file from Google uses an old (I suppose) key for filetype (java instead of Java). I have made the following changes and it works.
<ADDITIONAL_INDENT_OPTIONS fileType="JAVA">
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="8" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
<option name="USE_RELATIVE_INDENTS" value="false" />
</ADDITIONAL_INDENT_OPTIONS>
I have made a fork of the GitHub repository with the file corrected (https://github.com/nhenneaux/styleguide/blob/gh-pages/intellij-java-google-style.xml).
The easiest way is to import the style file into ~/.IntelliJIdea2016.2/config/codestyles. Then you have to restart Intellij and go in the style settings to select GoogleStyle.

It seems that the format used in the configuration file differes from what IntelliJ (at least the version I'm using) expects.
I changed my code setting, exported them and looked for differences.
The ident setting were in the output file like so:
<code_scheme name="MyTestStyle">
...
<codeStyleSettings language="JAVA">
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="4" />
<option name="TAB_SIZE" value="8" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
Importing this file worked as expected.

Related

Intellij idea compile

when I try to run my code, it says
D:\collinear\.idea\workspace.xml
Failed to load project configuration: cannot parse file D:\collinear\.idea\workspace.xml: Unexpected end tag: expected </todo-panel>
at [row,col {unknown-source}]: [82,11]
Could any one help with this?
The original file code is
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="de3c797f-950b-4f17-a955-daf1b2a2e70a" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ProjectId" id="2CSYuDBFUzu27f0DeiBxNrUgEMo" />
<component name="ProjectViewState">
<option name="abbreviatePackageNames" value="true" />
<option name="autoscrollFromSource" value="true" />
<option name="autoscrollToSource" value="true" />
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="false" />
<option name="showModules" value="false" />
<option name="sortByType" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true"
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="project-level" UseSingleDictionary="true" transferred="true" />
</project>
This is the code
Computer vision involves analyzing patterns in visual images and reconstructing the real-world objects that produced them. The process is often broken up into two phases: feature detection and pattern recognition. Feature detection involves selecting important features of the image; pattern recognition involves discovering patterns in the features. We will investigate a particularly clean pattern recognition problem involving points and line segments. This kind of pattern recognition arises in many other applications such as statistical data analysis.

How to validate invalid Cucumber/Gherkin .feature file in build?

If I create step in Cucumber .feature file that is not implemented I get snippet in logs.
But if I make error in .feature file like starting new line with "Andd" or with anything but keywords (given, when..) then I get error in IntelliJ "Unexpected element" which is underlined and that's great.
But despite that when I build project I get "success build".
Also when I go further and run Cucumber tests I get
"0 Scenarios, 0 Steps found." and no explanation why.
Is there any build parameter that can be added to mark such build unsuccessful?
Is there any way to point to such errors?
Edit: when running from cmd 'mvn test..' I get nice stack trace.
Problem is only when running in Intellij > Run/Debug Configuration.
Sample .run.xml that I am using:
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Feature: testFeed" type="CucumberJavaRunConfigurationType" factoryName="Cucumber java" nameIsGenerated="true">
<option name="CUCUMBER_CORE_VERSION" value="5" />
<option name="FILE_PATH" value="$PROJECT_DIR$/src/test/resources/features/testFeed.feature" />
<option name="GLUE" value="com.testing.stepdefiniton" />
<option name="MAIN_CLASS_NAME" value="io.cucumber.core.cli.Main" />
<module name="testing" />
<option name="PROGRAM_PARAMETERS" value=" --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm5SMFormatter" />
<shortenClasspath name="NONE" />
<option name="SUGGESTED_NAME" value="Feature: testFeed" />
<option name="VM_PARAMETERS" value="-Dspring.profiles.active=local -Dcucumber.filter.tags="#test"" />
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="io.cucumber.core.cli.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
There are two parts to this question
You usage of IntelliJ (I can't help you with this)
Your usage of Cucumber (maybe I can help here)
Cucumber is telling you that it can't find any scenarios or any steps. Its not going to contribute until you can fix that. You need to either try running Cucumber from the command line, or configure IntelliJ correctly so it can find the features and steps when running cucumber.

How to make VS Code organize Java imports like IntelliJ

I'm using VS Code for Java development and working with other developers who use IntelliJ. I'd like to use the Organize Imports command (Shift+Alt+O) to clean up my imports, but I don't want to fight over import order with every commit. So I'd like to configure VS Code to organize the imports in the same order as IntelliJ's default. Does anybody have a configuration that would do this?
If this is not possible, is there a workspace configuration I can apply to both VS Code and IntelliJ so that the two IDEs will agree, even if they aren't agreeing on IntelliJ's default?
We were able to get it the almost identical with the following config tweaks.
VS Code:
{
"java.completion.importOrder": [
"",
"javax",
"java",
"#"
]
}
IntelliJ
The only difference from the IntelliJ default is a new line between import javax... and import java....
It's possible to get VS Code and IntelliJ to agree on a standard format, as long as that standard format:
Puts static imports at the top*
Separates all specific sections with empty lines
Puts everything not in its own specific section in a catch-all section at the end*
Never uses wildcard imports
Not actually true; static imports can be positioned in VS Code with '#', and everything else can be position in VS Code with ''.
IntelliJ's default settings don't work for this, but it is flexible enough to be reconfigured. Here are the files to add to a project to make just that project set up consistent rules for both IDEs (make sure they are not excluded in .gitignore).
Rule: The following groups separated by empty lines: Static imports, java.*, javax.*, everything else.
.vscode/settings.json:
{
"java.completion.importOrder": ["java", "javax"],
}
.idea/codeStyles/codeStyleConfig.xml:
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
.idea/codeStyles/Project.xml
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JavaCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</code_scheme>
</component>

Source control intellij code style settings

We have a project being managed by more than 20 developers and most of them use intellij.
I was wondering if we can source an xml file somehow so that every developer doesn't have to import code style settings manually.
How to properly import Java code style settings with IntelliJ?
This thread suggests that we have to manually import the xml file and only then we will see those settings will come into effect. Is there a setting that can import the code styles automatically?
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="15" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
</value>
</option>
<codeStyleSettings language="JAVA">
<option name="KEEP_LINE_BREAKS" value="false" />
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
</codeStyleSettings>
</value>
</option>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</component>
</project>
The above settings in .idea/codestyleSettings.xml did the trick.

Intellij -Project structure settings (spring facet config) - where are they stored?

Have a project that I am migrating over from netbeans to intellij.
Intellij recognises the spring config files and gives the warning "please configure/setup spring facet for modules". This requires manually adding these under project structure settings.
I don't want the other team members to all have to do this manually, so I wish to check these settings into git, but according to that, there are no changed files in the project directory (I have standard ignores added to .gitignore). I have also tried searches of file contents for the config file names etc and that turns up nothing too.
So my question is where are the settings stored? In a file that is typically on the ignored list or in a location external to the project directory?
Essentially all the IDEA related configuration for the project is under .idea folder, for example, all the project workspace iteams you can find in the .idea/worksapce.xml, include the spring features you mentioned.
But this is not a good idea to keep those things in your VCs, the .idea folder is ignore default as in the configuration items will store you local env related like the full path to your local gradle, e.g.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:/DevTools/gradle-2.14.1" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="useAutoImport" value="true" />
<option name="myModules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
Here are some files under the .idea folder for my proejct
Update:
For the spring facets, it's under the module .iml file, like
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration>
<fileset id="fileset" name="Spring Application Context" removed="false">
<file>file://$MODULE_DIR$/src/main/resources/META-INF/spring/integration-beans.xml</file>
</fileset>
</configuration>
</facet>
</component>

Categories