• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 import com.google.common.base.CharMatcher;
18 import com.google.errorprone.refaster.annotation.AfterTemplate;
19 import com.google.errorprone.refaster.annotation.BeforeTemplate;
20 
21 /**
22  * Refaster refactorings to rewrite uses of CharMatcher static constants to the static factory
23  * methods.
24  */
25 public class CharMatcherRewrite {
26   class Whitespace {
27     @BeforeTemplate
before()28     CharMatcher before() {
29       return CharMatcher.WHITESPACE;
30     }
31 
32     @AfterTemplate
after()33     CharMatcher after() {
34       return CharMatcher.whitespace();
35     }
36   }
37 
38   class BreakingWhitespace {
39     @BeforeTemplate
before()40     CharMatcher before() {
41       return CharMatcher.BREAKING_WHITESPACE;
42     }
43 
44     @AfterTemplate
after()45     CharMatcher after() {
46       return CharMatcher.breakingWhitespace();
47     }
48   }
49 
50   class Ascii {
51     @BeforeTemplate
before()52     CharMatcher before() {
53       return CharMatcher.ASCII;
54     }
55 
56     @AfterTemplate
after()57     CharMatcher after() {
58       return CharMatcher.ascii();
59     }
60   }
61 
62   class Digit {
63     @BeforeTemplate
before()64     CharMatcher before() {
65       return CharMatcher.DIGIT;
66     }
67 
68     @AfterTemplate
after()69     CharMatcher after() {
70       return CharMatcher.digit();
71     }
72   }
73 
74   class JavaDigit {
75     @BeforeTemplate
before()76     CharMatcher before() {
77       return CharMatcher.JAVA_DIGIT;
78     }
79 
80     @AfterTemplate
after()81     CharMatcher after() {
82       return CharMatcher.javaDigit();
83     }
84   }
85 
86   class JavaLetterOrDigit {
87     @BeforeTemplate
before()88     CharMatcher before() {
89       return CharMatcher.JAVA_LETTER_OR_DIGIT;
90     }
91 
92     @AfterTemplate
after()93     CharMatcher after() {
94       return CharMatcher.javaLetterOrDigit();
95     }
96   }
97 
98   class JavaUpperCase {
99     @BeforeTemplate
before()100     CharMatcher before() {
101       return CharMatcher.JAVA_UPPER_CASE;
102     }
103 
104     @AfterTemplate
after()105     CharMatcher after() {
106       return CharMatcher.javaUpperCase();
107     }
108   }
109 
110   class JavaLowerCase {
111     @BeforeTemplate
before()112     CharMatcher before() {
113       return CharMatcher.JAVA_LOWER_CASE;
114     }
115 
116     @AfterTemplate
after()117     CharMatcher after() {
118       return CharMatcher.javaLowerCase();
119     }
120   }
121 
122   class JavaIsoControl {
123     @BeforeTemplate
before()124     CharMatcher before() {
125       return CharMatcher.JAVA_ISO_CONTROL;
126     }
127 
128     @AfterTemplate
after()129     CharMatcher after() {
130       return CharMatcher.javaIsoControl();
131     }
132   }
133 
134   class Invisible {
135     @BeforeTemplate
before()136     CharMatcher before() {
137       return CharMatcher.INVISIBLE;
138     }
139 
140     @AfterTemplate
after()141     CharMatcher after() {
142       return CharMatcher.invisible();
143     }
144   }
145 
146   class SingleWidth {
147     @BeforeTemplate
before()148     CharMatcher before() {
149       return CharMatcher.SINGLE_WIDTH;
150     }
151 
152     @AfterTemplate
after()153     CharMatcher after() {
154       return CharMatcher.singleWidth();
155     }
156   }
157 
158   class Any {
159     @BeforeTemplate
before()160     CharMatcher before() {
161       return CharMatcher.ANY;
162     }
163 
164     @AfterTemplate
after()165     CharMatcher after() {
166       return CharMatcher.any();
167     }
168   }
169 
170   class None {
171     @BeforeTemplate
before()172     CharMatcher before() {
173       return CharMatcher.NONE;
174     }
175 
176     @AfterTemplate
after()177     CharMatcher after() {
178       return CharMatcher.none();
179     }
180   }
181 }
182