Reformat
This commit is contained in:
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
*
|
* that can be found in the license/LICENSE.txt file.
|
||||||
* Licensed 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
@@ -37,16 +26,17 @@ import java.awt.BorderLayout
|
|||||||
import java.util.regex.PatternSyntaxException
|
import java.util.regex.PatternSyntaxException
|
||||||
import javax.swing.JPanel
|
import javax.swing.JPanel
|
||||||
|
|
||||||
abstract class NamingConventionInspection(private val entityName: String,
|
abstract class NamingConventionInspection(
|
||||||
defaultNamePattern: String) : AbstractKotlinInspection() {
|
private val entityName: String,
|
||||||
|
defaultNamePattern: String
|
||||||
|
) : AbstractKotlinInspection() {
|
||||||
protected var nameRegex: Regex? = defaultNamePattern.toRegex()
|
protected var nameRegex: Regex? = defaultNamePattern.toRegex()
|
||||||
var namePattern: String = defaultNamePattern
|
var namePattern: String = defaultNamePattern
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
nameRegex = try {
|
nameRegex = try {
|
||||||
value.toRegex()
|
value.toRegex()
|
||||||
}
|
} catch (e: PatternSyntaxException) {
|
||||||
catch(e: PatternSyntaxException) {
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,9 +45,11 @@ abstract class NamingConventionInspection(private val entityName: String,
|
|||||||
val name = element.name
|
val name = element.name
|
||||||
val nameIdentifier = element.nameIdentifier
|
val nameIdentifier = element.nameIdentifier
|
||||||
if (name != null && nameIdentifier != null && nameRegex?.matches(name) == false) {
|
if (name != null && nameIdentifier != null && nameRegex?.matches(name) == false) {
|
||||||
holder.registerProblem(element.nameIdentifier!!,
|
holder.registerProblem(
|
||||||
"$entityName name <code>#ref</code> doesn't match regex '$namePattern' #loc",
|
element.nameIdentifier!!,
|
||||||
RenameIdentifierFix())
|
"$entityName name <code>#ref</code> doesn't match regex '$namePattern' #loc",
|
||||||
|
RenameIdentifierFix()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,10 +93,11 @@ class FunctionNameInspection : NamingConventionInspection("Function", "[a-z][A-Z
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class PropertyNameInspectionBase protected constructor(private val kind: PropertyKind,
|
abstract class PropertyNameInspectionBase protected constructor(
|
||||||
entityName: String,
|
private val kind: PropertyKind,
|
||||||
defaultNamePattern: String)
|
entityName: String,
|
||||||
: NamingConventionInspection(entityName, defaultNamePattern) {
|
defaultNamePattern: String
|
||||||
|
) : NamingConventionInspection(entityName, defaultNamePattern) {
|
||||||
|
|
||||||
protected enum class PropertyKind { NORMAL, PRIVATE, OBJECT, CONST, LOCAL }
|
protected enum class PropertyKind { NORMAL, PRIVATE, OBJECT, CONST, LOCAL }
|
||||||
|
|
||||||
@@ -147,9 +140,11 @@ class PackageNameInspection : NamingConventionInspection("Package", "[a-z][A-Za-
|
|||||||
override fun visitPackageDirective(directive: KtPackageDirective) {
|
override fun visitPackageDirective(directive: KtPackageDirective) {
|
||||||
val qualifiedName = directive.qualifiedName
|
val qualifiedName = directive.qualifiedName
|
||||||
if (qualifiedName.isNotEmpty() && nameRegex?.matches(qualifiedName) == false) {
|
if (qualifiedName.isNotEmpty() && nameRegex?.matches(qualifiedName) == false) {
|
||||||
holder.registerProblem(directive.packageNameExpression!!,
|
holder.registerProblem(
|
||||||
"Package name <code>#ref</code> doesn't match regex '$namePattern' #loc",
|
directive.packageNameExpression!!,
|
||||||
RenamePackageFix())
|
"Package name <code>#ref</code> doesn't match regex '$namePattern' #loc",
|
||||||
|
RenamePackageFix()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user