Clover coverage report - Convert - proto0
Coverage timestamp: Mo Nov 22 2004 13:19:16 CET
file stats: LOC: 105   Methods: 9
NCLOC: 70   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ParameterizableType.java 90% 82,9% 77,8% 83,3%
coverage coverage
 1    /*
 2    * Copyright 2004 Ronald Blaschke.
 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    package org.rblasch.convert.type;
 17   
 18    import java.util.ArrayList;
 19    import java.util.Arrays;
 20    import java.util.Collections;
 21    import java.util.Iterator;
 22    import java.util.List;
 23    import java.util.StringTokenizer;
 24   
 25    /**
 26    * @author Ronald Blaschke
 27    */
 28    public class ParameterizableType extends AbstractType {
 29  4 static ParameterizableType valueOf(final String s) throws UnknownTypeException {
 30  4 if (s.endsWith("[]")) {
 31    // special array syntax, eg int[], java.lang.Integer[]
 32  2 final String componentName = s.substring(0, s.length() - 2);
 33  2 final Type componentType = Types.findTypeByName(componentName);
 34   
 35  2 return new ParameterizableType(Types.findTypeByName("array"), componentType);
 36    } else {
 37  2 final int ltPos = s.indexOf('<');
 38  2 final int gtPos = s.lastIndexOf('>');
 39   
 40  2 if (ltPos == -1 || gtPos == -1) {
 41  0 throw new UnknownTypeException(s + " is not a parameterizable type");
 42    }
 43   
 44  2 final String parameters = s.substring(ltPos + 1, gtPos);
 45   
 46  2 final Type mainType = Types.findTypeByName(s.substring(0, ltPos));
 47  2 final List/*<Type>*/ parameterTypes = new ArrayList();
 48  2 for (final StringTokenizer tokenizer = new StringTokenizer(parameters, ","); tokenizer.hasMoreElements();) {
 49  2 final String token = tokenizer.nextToken();
 50  2 parameterTypes.add(Types.findTypeByName(token.trim()));
 51    }
 52   
 53  2 return new ParameterizableType(mainType, parameterTypes);
 54    }
 55    }
 56   
 57    private final Type t;
 58    private final List/*<Type>*/ parameters;
 59   
 60  2 ParameterizableType(final Type t, final Type p1) {
 61  2 this(t, Collections.singletonList(p1));
 62    }
 63   
 64  0 ParameterizableType(final Type t, final Type p1, final Type p2) {
 65  0 this(t, Arrays.asList(new Type[]{p1, p2}));
 66    }
 67   
 68  145 ParameterizableType(final Type t, final List/*<Type>*/ parameters) {
 69  145 this.t = t;
 70  145 this.parameters = new ArrayList(parameters);
 71    }
 72   
 73  8897 public Type getType() {
 74  8897 return t;
 75    }
 76   
 77  2857 public List/*<Type>*/ getParameters() {
 78  2857 return parameters;
 79    }
 80   
 81  730 public Type getParameter(final int i) {
 82  730 return (Type) parameters.get(i);
 83    }
 84   
 85  0 public List/*<Type>*/ toList() {
 86  0 final List/*<Type>*/ list = new ArrayList(1 + parameters.size());
 87  0 list.add(t);
 88  0 list.addAll(parameters);
 89  0 return list;
 90    }
 91   
 92  1427671 public String getName() {
 93  1427671 final StringBuffer buffy = new StringBuffer();
 94  1427671 buffy.append(t.getName());
 95  1427671 buffy.append('<');
 96  1427671 for (final Iterator i = parameters.iterator(); i.hasNext();) {
 97  1427672 buffy.append(((Type) i.next()).getName());
 98  1427672 if (i.hasNext()) {
 99  1 buffy.append(",");
 100    }
 101    }
 102  1427671 buffy.append('>');
 103  1427671 return buffy.toString();
 104    }
 105    }