1 /******************************************************************************* 2 * Copyright (c) 2008, 2013 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.pde.api.tools.internal.provisional.model; 15 16 import java.util.List; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.pde.api.tools.internal.provisional.builder.IReference; 21 22 /** 23 * Provides the structure of a type - for example, a class or interface along 24 * with its methods and fields. 25 * 26 * @see IApiMethod 27 * @see IApiField 28 * 29 * @since 1.1 30 * @noimplement This interface is not intended to be implemented by clients. 31 * @noextend This interface is not intended to be extended by clients. 32 */ 33 public interface IApiType extends IApiMember { 34 35 /** 36 * Returns the {@link IApiMethod} that encloses this type, iff this type is 37 * a local type (class defined in a method body). A call to this method will 38 * load the enclosing type to find the enclosing method. 39 * 40 * @return the {@link IApiMethod} that encloses this type or 41 * <code>null</code> 42 */ getEnclosingMethod()43 public IApiMethod getEnclosingMethod(); 44 45 /** 46 * Returns the field with the specified name in this type (for example, 47 * <code>"bar"</code>), or <code>null</code> if none. 48 * 49 * @param name the given name 50 * @return the field with the specified name in this type or 51 * <code>null</code> 52 */ getField(String name)53 public IApiField getField(String name); 54 55 /** 56 * Returns the fields declared by this type. 57 * 58 * @return the fields declared by this type 59 */ getFields()60 public IApiField[] getFields(); 61 62 /** 63 * Returns the method with the specified name and signature in this type. 64 * For example, <code>"foo", "(Ljava.lang.String;I)V"</code>, retrieves the 65 * method <code>foo(String, int)</code>. To retrieve a constructor, 66 * <code>"<init>"</code> must specified must be as method name. 67 * 68 * @param name method name 69 * @param parameterTypeSignatures parameter types 70 * @return the method with the specified name and parameter types in this 71 * type or <code>null</code> 72 */ getMethod(String name, String signature)73 public IApiMethod getMethod(String name, String signature); 74 75 /** 76 * Returns the methods and constructors declared by this type. 77 * 78 * @return the methods and constructors declared by this type 79 */ getMethods()80 public IApiMethod[] getMethods(); 81 82 /** 83 * Returns whether this type is an anonymous type. 84 * 85 * @return true if this type is an anonymous type, false otherwise 86 */ isAnonymous()87 public boolean isAnonymous(); 88 89 /** 90 * Returns whether this type is a local type. 91 * 92 * @return whether this type is a local type 93 */ isLocal()94 public boolean isLocal(); 95 96 /** 97 * Returns whether this type represents a class. 98 * <p> 99 * Note that a class can neither be an interface, an enumeration class, nor 100 * an annotation type. 101 * </p> 102 * 103 * @return true if this type represents a class, false otherwise 104 */ isClass()105 public boolean isClass(); 106 107 /** 108 * Returns whether this type represents an enumeration class. 109 * <p> 110 * Note that an enumeration class can neither be a class, an interface, nor 111 * an annotation type. 112 * </p> 113 * 114 * @return true if this type represents an enumeration class, false 115 * otherwise 116 */ isEnum()117 public boolean isEnum(); 118 119 /** 120 * Returns whether this type represents an interface. 121 * <p> 122 * Note that an interface can also be an annotation type, but it can neither 123 * be a class nor an enumeration class. 124 * </p> 125 * 126 * @return true if this type represents an interface, false otherwise 127 */ isInterface()128 public boolean isInterface(); 129 130 /** 131 * Returns whether this type represents an annotation type. 132 * <p> 133 * Note that an annotation type is also an interface, but it can neither be 134 * a class nor an enumeration class. 135 * </p> 136 * 137 * @return true if this type represents an annotation type, false otherwise 138 */ isAnnotation()139 public boolean isAnnotation(); 140 141 /** 142 * Returns whether this type is a member type. 143 * 144 * @return whether this type is a member type 145 */ isMemberType()146 public boolean isMemberType(); 147 148 /** 149 * Returns the fully qualified name of this type's superclass, or 150 * <code>null</code> if none. 151 * <p> 152 * For interfaces, the superclass name is always 153 * <code>"java.lang.Object"</code>. For anonymous types, the superclass name 154 * is the name appearing after the 'new' keyword'. If the superclass is a 155 * parameterized type, the string may include its type arguments enclosed in 156 * "<>". If the returned string is needed for anything other than 157 * display purposes, use {@link #getSuperclassTypeSignature()} which returns 158 * a structured type signature string containing more precise information. 159 * </p> 160 * 161 * @return the name of this type's superclass or <code>null</code> 162 */ getSuperclassName()163 public String getSuperclassName(); 164 165 /** 166 * Returns the superclass of this class or <code>null</code> if none. For 167 * interfaces, java.lang.Object is returned. 168 * 169 * @return superclass or <code>null</code> 170 * @throws CoreException if unable to retrieve the superclass 171 */ getSuperclass()172 public IApiType getSuperclass() throws CoreException; 173 174 /** 175 * Returns the names of interfaces that this type implements or extends or 176 * <code>null</code> if none. 177 * <p> 178 * For classes, this gives the interfaces that this class implements. For 179 * interfaces, this gives the interfaces that this interface extends. Null 180 * is returned if this type does not implement or extend any interfaces. 181 * </p> 182 * 183 * @return the names of interfaces that this type implements or extends, or 184 * <code>null</code> if none 185 */ getSuperInterfaceNames()186 public String[] getSuperInterfaceNames(); 187 188 /** 189 * Returns the resolved super interfaces that this type implements or 190 * extends, or an empty collection if none. 191 * 192 * @return resolved super interfaces 193 * @throws CoreException if unable to retrieve super interfaces 194 */ getSuperInterfaces()195 public IApiType[] getSuperInterfaces() throws CoreException; 196 197 /** 198 * Returns member types contained in this type. 199 * 200 * @return member types, possibly an empty array 201 * @exception CoreException if unable to retrieve member types 202 */ getMemberTypes()203 public IApiType[] getMemberTypes() throws CoreException; 204 205 /** 206 * Returns the member type with the given simple name or <code>null</code> 207 * if none. 208 * 209 * @param simpleName simple name 210 * @return member type or <code>null</code> 211 * @exception CoreException if unable to retrieve the type 212 */ getMemberType(String simpleName)213 public IApiType getMemberType(String simpleName) throws CoreException; 214 215 /** 216 * Returns the simple (unqualified) name for this type. 217 * 218 * @return unqualified name 219 */ getSimpleName()220 public String getSimpleName(); 221 222 /** 223 * Returns the {@link IApiTypeRoot} that this type is defined in 224 * 225 * @return the {@link IApiTypeRoot} this type is defined in 226 */ getTypeRoot()227 public IApiTypeRoot getTypeRoot(); 228 229 /** 230 * Extracts and returns all references made from this type of the specified 231 * kind. The list contains instances of {@link IReference}. 232 * 233 * @param referenceMask kinds of references to extract/search for as 234 * described by 235 * {@link org.eclipse.pde.api.tools.internal.provisional.search.ReferenceModifiers} 236 * @param monitor progress monitor or <code>null</code> 237 * @return extracted {@link IReference}s, possibly an empty collection 238 * @throws CoreException if this type does not exist or an exception occurs 239 * reading underlying storage 240 */ extractReferences(int referenceMask, IProgressMonitor monitor)241 public List<IReference> extractReferences(int referenceMask, IProgressMonitor monitor) throws CoreException; 242 } 243