/** * Returns all activities found in the given project (including those in libraries, except for * android.jar itself) * * @param project the project * @return a list of activity classes as fully qualified class names */ @SuppressWarnings("restriction") // BinaryType @NonNull public static List<String> getProjectActivities(IProject project) { final List<String> activities = new ArrayList<String>(); try { final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { IType[] activityTypes = new IType[0]; IType activityType = javaProject.findType(SdkConstants.CLASS_ACTIVITY); if (activityType != null) { ITypeHierarchy hierarchy = activityType.newTypeHierarchy(javaProject, new NullProgressMonitor()); activityTypes = hierarchy.getAllSubtypes(activityType); for (IType type : activityTypes) { if (type instanceof BinaryType && (type.getClassFile() == null || type.getClassFile().getResource() == null)) { continue; } activities.add(type.getFullyQualifiedName()); } } } } catch (CoreException e) { AdtPlugin.log(e, null); } return activities; }
/* * 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"); } }
private void checkOverridden(RefactoringStatus status, IProgressMonitor pm) throws JavaModelException { pm.beginTask("", 9); // $NON-NLS-1$ pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden); MethodDeclaration decl = fSourceProvider.getDeclaration(); IMethod method = (IMethod) decl.resolveBinding().getJavaElement(); if (method == null || Flags.isPrivate(method.getFlags())) { pm.worked(8); return; } IType type = method.getDeclaringType(); ITypeHierarchy hierarchy = type.newTypeHierarchy(new SubProgressMonitor(pm, 6)); checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1)); checkSuperClasses( status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1)); checkSuperInterfaces( status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1)); pm.setTaskName(""); // $NON-NLS-1$ }
protected ITypeHierarchy createTypeHierarchy(final IType type) throws JavaModelException { final ITypeHierarchy res = type.newTypeHierarchy(null); typeHierarchies.put(type, res); return res; }