Пример #1
0
 private static void populateClasses(
     final Shell shell, final IParent parent, final List<IType> types, final Filter filter) {
   try {
     for (final IJavaElement element : parent.getChildren()) {
       if (element instanceof IType) {
         final IType type = (IType) element;
         if (type.isClass()
             && type.isStructureKnown()
             && !type.isAnonymous()
             && !type.isLocal()
             && !Flags.isAbstract(type.getFlags())
             && Flags.isPublic(type.getFlags())
             && (filter == null || filter.accept(type))) {
           types.add(type);
         }
       } else if (element instanceof IParent
           && !element.getPath().toString().contains("/test/")
           && (!(element instanceof IPackageFragmentRoot)
               || !((IPackageFragmentRoot) element).isExternal())) {
         populateClasses(shell, (IParent) element, types, filter);
       }
     }
   } catch (final JavaModelException e) {
     Activator.error(e);
   }
 }
Пример #2
0
 private IPath getPath(IJavaElement element, boolean relativeToRoot) {
   switch (element.getElementType()) {
     case IJavaElement.JAVA_MODEL:
       return Path.EMPTY;
     case IJavaElement.JAVA_PROJECT:
       return element.getPath();
     case IJavaElement.PACKAGE_FRAGMENT_ROOT:
       if (relativeToRoot) return Path.EMPTY;
       return element.getPath();
     case IJavaElement.PACKAGE_FRAGMENT:
       String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
       return getPath(element.getParent(), relativeToRoot).append(new Path(relativePath));
     case IJavaElement.COMPILATION_UNIT:
     case IJavaElement.CLASS_FILE:
       return getPath(element.getParent(), relativeToRoot)
           .append(new Path(element.getElementName()));
     default:
       return getPath(element.getParent(), relativeToRoot);
   }
 }
Пример #3
0
  private static boolean canSeeFocus(
      IJavaElement focus, JavaProject javaProject, char[][][] focusQualifiedNames) {
    try {
      if (focus == null) return false;
      if (focus.equals(javaProject)) return true;

      if (focus instanceof JarPackageFragmentRoot) {
        // focus is part of a jar
        IPath focusPath = focus.getPath();
        IClasspathEntry[] entries = javaProject.getExpandedClasspath();
        for (int i = 0, length = entries.length; i < length; i++) {
          IClasspathEntry entry = entries[i];
          if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
              && entry.getPath().equals(focusPath)) return true;
        }
        return false;
      }
      // look for dependent projects
      IPath focusPath = ((JavaProject) focus).getProject().getFullPath();
      IClasspathEntry[] entries = javaProject.getExpandedClasspath();
      for (int i = 0, length = entries.length; i < length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT
            && entry.getPath().equals(focusPath)) {
          if (focusQualifiedNames
              != null) { // builder state is usable, hence use it to try to reduce project which can
                         // see the focus...
            State projectState =
                (State)
                    JavaModelManager.getJavaModelManager()
                        .getLastBuiltState(javaProject.getProject(), null);
            if (projectState != null) {
              Object[] values = projectState.getReferences().valueTable;
              int vLength = values.length;
              for (int j = 0; j < vLength; j++) {
                if (values[j] == null) continue;
                ReferenceCollection references = (ReferenceCollection) values[j];
                if (references.includes(focusQualifiedNames, null, null)) {
                  return true;
                }
              }
              return false;
            }
          }
          return true;
        }
      }
      return false;
    } catch (JavaModelException e) {
      return false;
    }
  }
Пример #4
0
  String getSourceLocation(IBinding methodBinding, ITypeBinding declaringClass) {
    if (methodBinding == null) {
      throw new IllegalStateException("Cannot find methodbinding, running without workspace?");
    }

    IJavaElement javaElement = methodBinding.getJavaElement();
    if (javaElement == null) {
      return null;
    }
    IPath path = javaElement.getPath();
    if ("jar".equals(path.getFileExtension())) {
      return path.lastSegment();
    } else if (declaringClass != null) {
      return declaringClass
          .getJavaElement()
          .getResource()
          .getProjectRelativePath()
          .toPortableString();
    } else {
      return javaElement.getPath().toPortableString();
    }
  }