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.prefs
are 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 Formatter
and load the Eclipse formatter settings into your IDE manually.you have to do a few more steps:
- Install
Eclipse Code Formatter
and useorg.eclipse.jdt.core.prefs
andorg.eclipse.jdt.ui.prefs
insrc/core-common/.settings
to configureEclipse Java Formatter config file
andImport order
.
- Go to Preference => Code Style => Java, set
Scheme
to 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 theStringUtils
oforg.apache.commons.lang3.StringUtils
andio.kyligence.kap.guava20.shaded.common.base.Strings
. -
Using the
guava
in the package ofio.kyligence.kap.guava20.shaded.
. -
Don't use
log4j
directly, please useslf4j
. Lombok uses the annotation of@Slf4j
and Factory classorg.slf4j.LoggerFactory
. -
Add a new test or modified a test.
-
Please use the
junit5
instead ofjunit4
. For example, Using the annotation oforg.junit.jupiter.api.Test
instead oforg.junit.Test
. -
A test case that extends from
NLocalFileMetadataTestCase
needs to change with annotation@MetadataInfo
and remove theextend
.
Example: org.apache.kylin.junit.MetadataExtension, org.apache.kylin.metadata.epoch.EpochManagerTest
-