1 | /******************************************************************************* |
2 | * Copyright (c) 2007, 2009 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.provisional; |
12 | |
13 | |
14 | import java.util.LinkedList; |
15 | import java.util.List; |
16 | |
17 | import org.eclipse.core.runtime.CoreException; |
18 | import org.eclipse.pde.api.tools.internal.builder.TypeScope; |
19 | import org.eclipse.pde.api.tools.internal.descriptors.ComponentDescriptorImpl; |
20 | import org.eclipse.pde.api.tools.internal.descriptors.PackageDescriptorImpl; |
21 | import org.eclipse.pde.api.tools.internal.model.CompositeApiTypeContainer; |
22 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IComponentDescriptor; |
23 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IFieldDescriptor; |
24 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IMethodDescriptor; |
25 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IPackageDescriptor; |
26 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IReferenceTypeDescriptor; |
27 | import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; |
28 | import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer; |
29 | import org.eclipse.pde.api.tools.internal.util.Signatures; |
30 | |
31 | /** |
32 | * Factory to create API model objects. |
33 | * |
34 | * @since 1.0 |
35 | */ |
36 | public class Factory { |
37 | |
38 | /** |
39 | * Returns a component descriptor for the {@link IApiComponent} with the given id |
40 | * and an undefined version. |
41 | * The given id does not have to be the id of a component that actually exists: no |
42 | * resolution or lookup of any kind is done with the descriptor. |
43 | * |
44 | * @param componentid |
45 | * @return a new component descriptor |
46 | */ |
47 | public static IComponentDescriptor componentDescriptor(String componentid) { |
48 | return new ComponentDescriptorImpl(componentid, null); |
49 | } |
50 | |
51 | /** |
52 | * Returns a component descriptor for the {@link IApiComponent} with the given id and version. |
53 | * The given id does not have to be the id of a component that actually exists: no |
54 | * resolution or lookup of any kind is done with the descriptor. |
55 | * |
56 | * @param componentid |
57 | * @param version version descriptor or <code>null</code> if none |
58 | * @return a new component descriptor |
59 | */ |
60 | public static IComponentDescriptor componentDescriptor(String componentid, String version) { |
61 | return new ComponentDescriptorImpl(componentid, version); |
62 | } |
63 | |
64 | /** |
65 | * Returns a package descriptor for the package with the given name. |
66 | * An empty string indicates the default package. Package names are |
67 | * dot qualified. |
68 | * |
69 | * @param packageName package name |
70 | * @return an {@link IPackageDescriptor} for the package |
71 | */ |
72 | public static IPackageDescriptor packageDescriptor(String packageName) { |
73 | return new PackageDescriptorImpl(packageName); |
74 | } |
75 | |
76 | /** |
77 | * Utility method to create a type descriptor for a type with the |
78 | * given fully qualified name. Package names are dot qualified and |
79 | * type names are '$'-qualified. |
80 | * |
81 | * @param fullyQualifiedName |
82 | * @return an {@link ITypeDescriptor} for the type |
83 | */ |
84 | public static IReferenceTypeDescriptor typeDescriptor(String fullyQualifiedName) { |
85 | String packageName = Signatures.getPackageName(fullyQualifiedName); |
86 | String typeName = Signatures.getTypeName(fullyQualifiedName); |
87 | return packageDescriptor(packageName).getType(typeName); |
88 | } |
89 | |
90 | /** |
91 | * Utility method to create a type descriptor for a method contained within the given |
92 | * type |
93 | * |
94 | * @param typename the name of the enclosing type for the method |
95 | * @param name the name of the method |
96 | * @param signaturethe signature of the method |
97 | * @return an {@link IMethodDescriptor} for the method |
98 | */ |
99 | public static IMethodDescriptor methodDescriptor(String typename, String name, String signature) { |
100 | IReferenceTypeDescriptor type = typeDescriptor(typename); |
101 | return type.getMethod(name, signature); |
102 | } |
103 | |
104 | /** |
105 | * Utility method to create a type descriptor for a field contained within the given type |
106 | * |
107 | * @param typename the name of the enclosing type for the field |
108 | * @param name the name of the field |
109 | * @return an {@link IFieldDescriptor} for the field |
110 | */ |
111 | public static IFieldDescriptor fieldDescriptor(String typename , String name) { |
112 | IReferenceTypeDescriptor type = typeDescriptor(typename); |
113 | return type.getField(name); |
114 | } |
115 | |
116 | /** |
117 | * Returns a scope containing all elements in the given components. |
118 | * |
119 | * @param components API components |
120 | * @return search scope |
121 | * @throws CoreException if the baseline of the given components is disposed |
122 | */ |
123 | public static IApiTypeContainer newScope(IApiComponent[] components) throws CoreException { |
124 | List compList = new LinkedList(); |
125 | for (int i = 0; i < components.length; i++) { |
126 | compList.add(components[i]); |
127 | } |
128 | CompositeApiTypeContainer scope = new CompositeApiTypeContainer(components[0].getBaseline(), compList); |
129 | return scope; |
130 | } |
131 | |
132 | /** |
133 | * Returns a new scope containing the specified types in the given component. |
134 | * |
135 | * @param component API component |
136 | * @param types reference types |
137 | * @return search scope |
138 | */ |
139 | public static IApiTypeContainer newTypeScope(IApiComponent component, IReferenceTypeDescriptor[] types) { |
140 | return new TypeScope(component, types); |
141 | } |
142 | } |
143 | |