/* * @see TypeHierarchyContentProvider.getTypesInHierarchy */ @Override protected final void getTypesInHierarchy(IType type, List<IType> res) { ITypeHierarchy hierarchy = getHierarchy(); if (hierarchy != null) { IType[] types = hierarchy.getSubtypes(type); if (isObject(type)) { for (int i = 0; i < types.length; i++) { IType curr = types[i]; if (!isAnonymousFromInterface( curr)) { // no anonymous classes on 'Object' -> will be children of interface res.add(curr); } } } else { boolean isHierarchyOnType = (hierarchy.getType() != null); boolean isClass = !Flags.isInterface(hierarchy.getCachedFlags(type)); if (isClass || isHierarchyOnType) { for (int i = 0; i < types.length; i++) { res.add(types[i]); } } else { for (int i = 0; i < types.length; i++) { IType curr = types[i]; // no classes implementing interfaces, only if anonymous if (Flags.isInterface(hierarchy.getCachedFlags(curr)) || isAnonymous(curr)) { res.add(curr); } } } } } }
/* * Ensure that the hierarchy using a working copy owner doesn't have primary working copy owner type * that are hidden by a type of the working copy owner * (regression test for bug 133372 [hierarchy] Type hierarchy returns type twice if executed on working copy layer) */ public void testHierarchy() throws CoreException { try { createFile("/P/Y.java", "public class Y extends X {\n" + "}"); WorkingCopyOwner owner = new TestWorkingCopyOwner(); this.workingCopy = getCompilationUnit("/P/Y.java").getWorkingCopy(owner, null /*no progress*/); IType focus = getCompilationUnit("/P/X.java").getType("X"); ITypeHierarchy hierarchy = focus.newTypeHierarchy(owner, null /*no progress*/); IType[] subtypes = hierarchy.getSubtypes(focus); assertTypesEqual("Unexpected types", "Y\n", subtypes); } finally { deleteFile("/P/Y.java"); } }
/** * @param progressMonitor * @param uriMappings * @param resource * @param methodsStack * @throws CoreException */ private void resolveResourcesUriMappings( final Resource resource, final String uriTemplateFragment, final Map<ResolvedUriMapping, Stack<ResourceMethod>> uriMappings, final Stack<ResourceMethod> methodsStack, final IProgressMonitor progressMonitor) throws CoreException { // resource resourceMethods and subresources resourceMethods are treated the same way for (ResourceMethod resourceMethod : resource.getAllMethods()) { String uriPathTemplate = resolveURIPathTemplate(uriTemplateFragment, resource, resourceMethod); MediaTypeCapabilities mediaTypeCapabilities = resolveMediaTypeCapabilities(resource, resourceMethod); UriMapping resourceUriMapping = resourceMethod.getUriMapping(); ResolvedUriMapping uriMapping = new ResolvedUriMapping( resourceUriMapping.getHTTPMethod(), uriPathTemplate, resourceUriMapping.getQueryParams(), mediaTypeCapabilities); @SuppressWarnings("unchecked") Stack<ResourceMethod> stack = (Stack<ResourceMethod>) methodsStack.clone(); stack.add(resourceMethod); uriMappings.put(uriMapping, stack); } // TODO : verify support chain of subresource locators // TODO : stack resourceMethods and detect+prevent cycles for (ResourceMethod resourceMethod : resource.getSubresourceLocators()) { String uriPathTemplate = resolveURIPathTemplate(uriTemplateFragment, resource, resourceMethod); IType returnType = resourceMethod.getReturnType(); if (returnType == null) { continue; } ITypeHierarchy subresourceTypeHierarchy = JdtUtils.resolveTypeHierarchy(returnType, false, progressMonitor); for (IType subresourceType : subresourceTypeHierarchy.getSubtypes(returnType)) { Resource subresource = getByType(subresourceType); if (subresource != null && !subresource.isRootResource()) { @SuppressWarnings("unchecked") Stack<ResourceMethod> stack = (Stack<ResourceMethod>) methodsStack.clone(); stack.add(resourceMethod); resolveResourcesUriMappings( subresource, uriPathTemplate, uriMappings, stack, progressMonitor); } } } }