Beispiel #1
0
  /**
   * 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;
  }
Beispiel #2
0
 public List<IType> getSubtypesInProject(IJavaProject project) throws JavaModelException {
   // System.out.println("TypeCache.getSubtypesOf: " + type.getFullyQualifiedName() + " (hits=" +
   // SubTypeHierarchyCache.getCacheHits() + ",misses=" + SubTypeHierarchyCache.getCacheMisses()
   // + ")");
   ITypeHierarchy typeHierarchy =
       SubTypeHierarchyCache.getTypeHierarchyInProject(_type, project);
   List<IType> types = new LinkedList<IType>();
   IType[] subtypes = typeHierarchy.getAllSubtypes(_type);
   for (int subtypeNum = subtypes.length - 1; subtypeNum >= 0; subtypeNum--) {
     types.add(subtypes[subtypeNum]);
   }
   types.add(_type);
   return types;
 }
 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$
 }
  // -------
  private static IMethod[] classesDeclareMethodName(
      ITypeHierarchy hier, List<IType> classes, IMethod method, String newName)
      throws CoreException {
    Set<IMethod> result = new HashSet<>();
    IType type = method.getDeclaringType();
    List<IType> subtypes = Arrays.asList(hier.getAllSubtypes(type));

    int parameterCount = method.getParameterTypes().length;
    boolean isMethodPrivate = JdtFlags.isPrivate(method);

    for (Iterator<IType> iter = classes.iterator(); iter.hasNext(); ) {
      IType clazz = iter.next();
      IMethod[] methods = clazz.getMethods();
      boolean isSubclass = subtypes.contains(clazz);
      for (int j = 0; j < methods.length; j++) {
        IMethod foundMethod =
            Checks.findMethod(newName, parameterCount, false, new IMethod[] {methods[j]});
        if (foundMethod == null) continue;
        if (isSubclass || type.equals(clazz)) result.add(foundMethod);
        else if ((!isMethodPrivate) && (!JdtFlags.isPrivate(methods[j]))) result.add(foundMethod);
      }
    }
    return result.toArray(new IMethod[result.size()]);
  }