01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16:
17: package com.google.gwt.checkstyle;
18:
19: import com.puppycrawl.tools.checkstyle.api.DetailAST;
20: import com.puppycrawl.tools.checkstyle.api.TokenTypes;
21: import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck;
22:
23: /**
24: * Override MemberNameCheck to correctly use match rather than find.
25: */
26: public class FieldCheck extends MemberNameCheck {
27: public FieldCheck() {
28: // Specifically stopping fields such as fMainWnd from being allowed.
29: setFormat("([a-eg-z]|(f[a-z0-9]))[a-zA-Z0-9]*");
30: }
31:
32: public void visitToken(DetailAST aAST) {
33: if (mustCheckName(aAST)) {
34: final DetailAST nameAST = aAST
35: .findFirstToken(TokenTypes.IDENT);
36: if (!getRegexp().matcher(nameAST.getText()).matches()) {
37: log(
38: nameAST.getLineNo(),
39: nameAST.getText()
40: + ": Field names must start with [a-z], may not start with f[A-Z], and should not contain '_''s.");
41: }
42: }
43: }
44: }
|