Skip to content

Commit 4a2dd1f

Browse files
committed
refs: #13 of() etc should be used before the ct.
static valueOf(), of() might hvae the ability to cache known values. So they should be preferred to the String representation. Signed-off-by: Mark Struberg <[email protected]>
1 parent 7f2ec8d commit 4a2dd1f

File tree

7 files changed

+145
-2
lines changed

7 files changed

+145
-2
lines changed

api/src/main/java/javax/config/spi/Converter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@
6161
* <p>If no explicit Converter and no built-in Converter could be found for a certain type,
6262
* the {@code Config} provides an <em>Implicit Converter</em>, if</p>
6363
* <ul>
64-
* <li>The target type {@code T} has a Constructor with a String parameter, or</li>
65-
* <li>The target type {@code T} has a Constructor with a CharSequence parameter, or</li>
64+
* <li>the target type {@code T} has a {@code static T of(String)} method, or</li>
65+
* <li>the target type {@code T} has a {@code static T of(CharSequence)} method, or</li>
6666
* <li>the target type {@code T} has a {@code static T valueOf(String)} method, or</li>
6767
* <li>the target type {@code T} has a {@code static T valueOf(CharSequence)} method, or</li>
6868
* <li>the target type {@code T} has a {@code static T parse(String)} method, or</li>
6969
* <li>the target type {@code T} has a {@code static T parse(CharSequence)} method, or</li>
70+
* <li>The target type {@code T} has a Constructor with a String parameter, or</li>
71+
* <li>The target type {@code T} has a Constructor with a CharSequence parameter, or</li>
7072
* </ul>
7173
*
7274
* <p>The lookup will be done in the order of the above list.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* You may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.eclipse.configjsr.converters.implicit;
20+
21+
/**
22+
* Part of the implicit Converter test.
23+
*
24+
* Sample class which has a valueOf(String) method
25+
*
26+
* @author <a href="mailto:[email protected]">Mark Struberg</a>
27+
*/
28+
public class ConvTestTypeWCharSequenceOf {
29+
private String val;
30+
31+
public ConvTestTypeWCharSequenceOf() {
32+
}
33+
34+
/**
35+
* this ct should actually not be used by our test
36+
*/
37+
public ConvTestTypeWCharSequenceOf(CharSequence val) {
38+
this.val = "wrong" + val;
39+
}
40+
41+
public static ConvTestTypeWCharSequenceOf of(CharSequence val) {
42+
ConvTestTypeWCharSequenceOf o = new ConvTestTypeWCharSequenceOf();
43+
o.val = val.toString();
44+
return o;
45+
}
46+
47+
public String getVal() {
48+
return val;
49+
}
50+
}

tck/src/main/java/org/eclipse/configjsr/converters/implicit/ConvTestTypeWCharSequenceParse.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
public class ConvTestTypeWCharSequenceParse {
2929
private String val;
3030

31+
public ConvTestTypeWCharSequenceParse() {
32+
}
33+
34+
/**
35+
* this ct should actually not be used by our test
36+
*/
37+
public ConvTestTypeWCharSequenceParse(CharSequence val) {
38+
this.val = "wrong" + val;
39+
}
40+
3141
public static ConvTestTypeWCharSequenceParse parse(CharSequence val) {
3242
ConvTestTypeWCharSequenceParse o = new ConvTestTypeWCharSequenceParse();
3343
o.val = val.toString();

tck/src/main/java/org/eclipse/configjsr/converters/implicit/ConvTestTypeWCharSequenceValueOf.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
public class ConvTestTypeWCharSequenceValueOf {
2929
private String val;
3030

31+
public ConvTestTypeWCharSequenceValueOf() {
32+
}
33+
34+
/**
35+
* this ct should actually not be used by our test
36+
*/
37+
public ConvTestTypeWCharSequenceValueOf(CharSequence val) {
38+
this.val = "wrong" + val;
39+
}
40+
3141
public static ConvTestTypeWCharSequenceValueOf valueOf(CharSequence val) {
3242
ConvTestTypeWCharSequenceValueOf o = new ConvTestTypeWCharSequenceValueOf();
3343
o.val = val.toString();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2016-2018 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* You may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.eclipse.configjsr.converters.implicit;
20+
21+
/**
22+
* Part of the implicit Converter test.
23+
*
24+
* Sample class which has a valueOf(String) method
25+
*
26+
* @author <a href="mailto:[email protected]">Mark Struberg</a>
27+
*/
28+
public class ConvTestTypeWStringOf {
29+
private String val;
30+
31+
public ConvTestTypeWStringOf() {
32+
}
33+
34+
/**
35+
* this ct should actually not be used by our test
36+
*/
37+
public ConvTestTypeWStringOf(String val) {
38+
this.val = "wrong" + val;
39+
}
40+
41+
public static ConvTestTypeWStringOf of(String val) {
42+
ConvTestTypeWStringOf o = new ConvTestTypeWStringOf();
43+
o.val = val;
44+
return o;
45+
}
46+
47+
public String getVal() {
48+
return val;
49+
}
50+
}

tck/src/main/java/org/eclipse/configjsr/converters/implicit/ConvTestTypeWStringParse.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828
public class ConvTestTypeWStringParse {
2929
private String val;
3030

31+
32+
public ConvTestTypeWStringParse() {
33+
}
34+
35+
/**
36+
* this ct should actually not be used by our test
37+
*/
38+
public ConvTestTypeWStringParse(String val) {
39+
this.val = "wrong" + val;
40+
}
41+
3142
public static ConvTestTypeWStringParse parse(String val) {
3243
ConvTestTypeWStringParse o = new ConvTestTypeWStringParse();
3344
o.val = val;

tck/src/main/java/org/eclipse/configjsr/converters/implicit/ConvTestTypeWStringValueOf.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
public class ConvTestTypeWStringValueOf {
2929
private String val;
3030

31+
public ConvTestTypeWStringValueOf() {
32+
}
33+
34+
/**
35+
* this ct should actually not be used by our test
36+
*/
37+
public ConvTestTypeWStringValueOf(String val) {
38+
this.val = "wrong" + val;
39+
}
40+
3141
public static ConvTestTypeWStringValueOf valueOf(String val) {
3242
ConvTestTypeWStringValueOf o = new ConvTestTypeWStringValueOf();
3343
o.val = val;

0 commit comments

Comments
 (0)