Coding and Naming Convention
Coding convention is very important for teamwork. Not only it keeps code neat and tidy, but it also saves a lot of work too. Different coding convention (and auto formatter) will cause unnecessary code changes that require more effort at code review and code merge.
Setup IDE code formatter
For Java code, we use Eclipse's default formatter setting, with one change that allows long lines.
-
For Eclipse developers, no manual setting is required. Code formatter configurations
src/core-common/.settings/org.eclipse.jdt.core.prefsare on the git repo. Your IDE should be auto-configured when the projects are imported. -
For IntelliJ IDEA developers, you need to install
Eclipse Code Formatterand load the Eclipse formatter settings into your IDE manually.you have to do a few more steps:
- Install
Eclipse Code Formatterand useorg.eclipse.jdt.core.prefsandorg.eclipse.jdt.ui.prefsinsrc/core-common/.settingsto configureEclipse Java Formatter config fileandImport order.

- Go to Preference => Code Style => Java, set
Schemeto Default, and set both Class count to use import with*and Names count to use static import with*to 99.

- Disable IntelliJ IDEA’s
Optimize imports on the fly

- Format the code before committing the code.
- Install
Setup IDE license header template
Each source file should include the following Apache License header
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
The checkstyle plugin will check the header rule when packaging also. The license file locates under dev-support/checkstyle-apache-header.txt. To make it easy for developers, please add the header as Copyright Profile and set it as default for the Kylin project.

Code Rules(Important)
-
For JavaScript, XML, and other code, please use space for indent. And as a general rule, keep your code format consistent with existing lines. No other enforcement at the moment.
-
Using
StringUtils, just use theStringUtilsoforg.apache.commons.lang3.StringUtilsandio.kyligence.kap.guava20.shaded.common.base.Strings. -
Using the
guavain the package ofio.kyligence.kap.guava20.shaded.. -
Don't use
log4jdirectly, please useslf4j. Lombok uses the annotation of@Slf4jand Factory classorg.slf4j.LoggerFactory. -
Add a new test or modified a test.
-
Please use the
junit5instead ofjunit4. For example, Using the annotation oforg.junit.jupiter.api.Testinstead oforg.junit.Test. -
A test case that extends from
NLocalFileMetadataTestCaseneeds to change with annotation@MetadataInfoand remove theextend.
Example: org.apache.kylin.junit.MetadataExtension, org.apache.kylin.metadata.epoch.EpochManagerTest
-