1 | /******************************************************************************* |
2 | * Copyright (c) 2007, 2008 IBM Corporation and others. |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 |
5 | * which accompanies this distribution, and is available at |
6 | * http://www.eclipse.org/legal/epl-v10.html |
7 | * |
8 | * Contributors: |
9 | * IBM Corporation - initial API and implementation |
10 | *******************************************************************************/ |
11 | package org.eclipse.pde.api.tools.internal.comparator; |
12 | |
13 | import java.util.ArrayList; |
14 | import java.util.Iterator; |
15 | import java.util.List; |
16 | |
17 | import org.eclipse.pde.api.tools.internal.util.Util; |
18 | |
19 | /** |
20 | * Represents a type parameter inside a generic signature |
21 | */ |
22 | class TypeParameterDescriptor { |
23 | private static final String JAVA_LANG_OBJECT = "java.lang.Object"; //$NON-NLS-1$ |
24 | String classBound; |
25 | List interfaceBounds; |
26 | String name; |
27 | |
28 | public TypeParameterDescriptor(String name) { |
29 | this.name = name; |
30 | } |
31 | |
32 | public void addInterfaceBound(String bound) { |
33 | if (this.interfaceBounds == null) { |
34 | this.interfaceBounds = new ArrayList(); |
35 | } |
36 | this.interfaceBounds.add(bound); |
37 | } |
38 | |
39 | public void setClassBound(String bound) { |
40 | if (JAVA_LANG_OBJECT.equals(bound)) { |
41 | // we consider Object as an implicit bound |
42 | // <E> is implicitly <E extends Object> |
43 | return; |
44 | } |
45 | this.classBound = bound; |
46 | } |
47 | |
48 | public String toString() { |
49 | StringBuffer buffer = new StringBuffer(); |
50 | buffer.append("type parameter ").append(this.name).append(" : ").append(Util.LINE_DELIMITER); //$NON-NLS-1$ //$NON-NLS-2$ |
51 | if (this.classBound != null) { |
52 | buffer.append("class bound : ").append(this.classBound).append(Util.LINE_DELIMITER); //$NON-NLS-1$ |
53 | } |
54 | if (this.interfaceBounds != null) { |
55 | buffer.append("interface bounds : "); //$NON-NLS-1$ |
56 | int i = 0; |
57 | for (Iterator iterator = this.interfaceBounds.iterator(); iterator.hasNext(); ) { |
58 | if (i > 0) buffer.append(','); |
59 | i++; |
60 | buffer.append(iterator.next()); |
61 | } |
62 | buffer.append(Util.LINE_DELIMITER); |
63 | } |
64 | return String.valueOf(buffer); |
65 | } |
66 | } |