| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library services.src.refactoring.naming_conventions; | 5 library services.src.refactoring.naming_conventions; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/services/correction/status.dart'; | 7 import 'package:analysis_server/src/services/correction/status.dart'; |
| 8 import 'package:analysis_server/src/services/correction/strings.dart'; | 8 import 'package:analysis_server/src/services/correction/strings.dart'; |
| 9 | 9 |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * Returns the [RefactoringStatus] with severity: | 12 * Returns the [RefactoringStatus] with severity: |
| 13 * OK if the name is valid; | 13 * OK if the name is valid; |
| 14 * WARNING if the name is discouraged; | 14 * WARNING if the name is discouraged; |
| 15 * FATAL if the name is illegal. | 15 * FATAL if the name is illegal. |
| 16 */ | 16 */ |
| 17 RefactoringStatus validateClassName(String name) { | 17 RefactoringStatus validateClassName(String name) { |
| 18 return _validateUpperCamelCase(name, "Class"); | 18 return _validateUpperCamelCase(name, "Class"); |
| 19 } | 19 } |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Returns the [RefactoringStatus] with severity: | 22 * Returns the [RefactoringStatus] with severity: |
| 23 * OK if the name is valid; | 23 * OK if the name is valid; |
| 24 * WARNING if the name is discouraged; | 24 * WARNING if the name is discouraged; |
| 25 * FATAL if the name is illegal. | 25 * FATAL if the name is illegal. |
| 26 */ | 26 */ |
| 27 RefactoringStatus validateConstantName(String name) { | |
| 28 // null | |
| 29 if (name == null) { | |
| 30 return new RefactoringStatus.fatal("Constant name must not be null."); | |
| 31 } | |
| 32 // is not identifier | |
| 33 RefactoringStatus status = | |
| 34 _validateIdentifier(name, "Constant name", 'an uppercase letter or undersc
ore'); | |
| 35 if (!status.isOK) { | |
| 36 return status; | |
| 37 } | |
| 38 // is private, OK | |
| 39 int startIndex = 0; | |
| 40 if (name.codeUnitAt(0) == CHAR_UNDERSCORE) { | |
| 41 startIndex++; | |
| 42 } | |
| 43 // does not start with lower case | |
| 44 for (int i = startIndex; i < name.length; i++) { | |
| 45 int c = name.codeUnitAt(i); | |
| 46 if (!isUpperCase(c) && !isDigit(c) && c != CHAR_UNDERSCORE) { | |
| 47 return new RefactoringStatus.warning( | |
| 48 "Constant name should be all uppercase with underscores."); | |
| 49 } | |
| 50 } | |
| 51 // OK | |
| 52 return new RefactoringStatus(); | |
| 53 } | |
| 54 | |
| 55 /** | |
| 56 * Returns the [RefactoringStatus] with severity: | |
| 57 * OK if the name is valid; | |
| 58 * WARNING if the name is discouraged; | |
| 59 * FATAL if the name is illegal. | |
| 60 */ | |
| 61 RefactoringStatus validateConstructorName(String name) { | 27 RefactoringStatus validateConstructorName(String name) { |
| 62 if (name != null && name.isEmpty) { | 28 if (name != null && name.isEmpty) { |
| 63 return new RefactoringStatus(); | 29 return new RefactoringStatus(); |
| 64 } | 30 } |
| 65 return _validateLowerCamelCase(name, "Constructor"); | 31 return _validateLowerCamelCase(name, "Constructor"); |
| 66 } | 32 } |
| 67 | 33 |
| 68 /** | 34 /** |
| 69 * Returns the [RefactoringStatus] with severity: | 35 * Returns the [RefactoringStatus] with severity: |
| 70 * OK if the name is valid; | 36 * OK if the name is valid; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 247 } |
| 282 // does not start with upper case | 248 // does not start with upper case |
| 283 if (!isUpperCase(identifier.codeUnitAt(0))) { | 249 if (!isUpperCase(identifier.codeUnitAt(0))) { |
| 284 // By convention, class names usually start with an uppercase letter | 250 // By convention, class names usually start with an uppercase letter |
| 285 String message = "$desc should start with an uppercase letter."; | 251 String message = "$desc should start with an uppercase letter."; |
| 286 return new RefactoringStatus.warning(message); | 252 return new RefactoringStatus.warning(message); |
| 287 } | 253 } |
| 288 // OK | 254 // OK |
| 289 return new RefactoringStatus(); | 255 return new RefactoringStatus(); |
| 290 } | 256 } |
| OLD | NEW |