Example usage for org.eclipse.jdt.core IJavaElement PACKAGE_FRAGMENT_ROOT

List of usage examples for org.eclipse.jdt.core IJavaElement PACKAGE_FRAGMENT_ROOT

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement PACKAGE_FRAGMENT_ROOT.

Prototype

int PACKAGE_FRAGMENT_ROOT

To view the source code for org.eclipse.jdt.core IJavaElement PACKAGE_FRAGMENT_ROOT.

Click Source Link

Document

Constant representing a package fragment root.

Usage

From source file:org.eclipse.ajdt.internal.ui.wizards.exports.SealPackagesFilter.java

License:Open Source License

/**
 * Returns the result of this filter, when applied to the
 * given inputs./*  w w w.  j  av  a  2s .c  om*/
 *
 * @param inputs the set of elements to 
 * @return Returns true if element should be included in filtered set
 */
public boolean select(Viewer viewer, Object parent, Object element) {
    if (element instanceof IJavaElement) {
        int type = ((IJavaElement) element).getElementType();
        if (type == IJavaElement.JAVA_MODEL || type == IJavaElement.JAVA_PROJECT
                || type == IJavaElement.PACKAGE_FRAGMENT_ROOT)
            return true;
        return (type == IJavaElement.PACKAGE_FRAGMENT && fAllowedPackages.contains(element));

    } else
        return false;
}

From source file:org.eclipse.ajdt.internal.ui.wizards.exports.StandardJavaElementContentProvider.java

License:Open Source License

/**
 * Note: This method is for internal use only. Clients should not call this method.
 *//* w  w w.  j a va2  s .  c o m*/
protected boolean isClassPathChange(IJavaElementDelta delta) {

    // need to test the flags only for package fragment roots
    if (delta.getElement().getElementType() != IJavaElement.PACKAGE_FRAGMENT_ROOT)
        return false;

    int flags = delta.getFlags();
    return (delta.getKind() == IJavaElementDelta.CHANGED
            && ((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0)
            || ((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0)
            || ((flags & IJavaElementDelta.F_REORDER) != 0));
}

From source file:org.eclipse.che.jdt.core.ToolFactory.java

License:Open Source License

/**
 * Create a classfile reader onto a classfile Java element.
 * Create a default classfile reader, able to expose the internal representation of a given classfile
 * according to the decoding flag used to initialize the reader.
 * Answer null if the file named fileName doesn't represent a valid .class file.
 * <p/>//www  .  ja  va  2s. c  o m
 * The decoding flags are described in IClassFileReader.
 *
 * @param classfile
 *         the classfile element to introspect
 * @param decodingFlag
 *         the flag used to decode the class file reader.
 * @return a default classfile reader
 * @see org.eclipse.jdt.core.util.IClassFileReader
 */
public static IClassFileReader createDefaultClassFileReader(IClassFile classfile, int decodingFlag) {

    IPackageFragmentRoot root = (IPackageFragmentRoot) classfile
            .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
    if (root != null) {
        try {
            if (root instanceof JarPackageFragmentRoot) {
                String archiveName = null;
                ZipFile jar = null;
                try {
                    jar = ((JarPackageFragmentRoot) root).getJar();
                    archiveName = jar.getName();
                } finally {
                    JavaModelManager.getJavaModelManager().closeZipFile(jar);
                }
                PackageFragment packageFragment = (PackageFragment) classfile.getParent();
                String classFileName = classfile.getElementName();
                String entryName = org.eclipse.jdt.internal.core.util.Util.concatWith(packageFragment.names,
                        classFileName, '/');
                return createDefaultClassFileReader(archiveName, entryName, decodingFlag);
            } else {
                InputStream in = null;
                try {
                    in = ((IFile) ((JavaElement) classfile).resource()).getContents();
                    return createDefaultClassFileReader(in, decodingFlag);
                } finally {
                    if (in != null)
                        try {
                            in.close();
                        } catch (IOException e) {
                            // ignore
                        }
                }
            }
        } catch (CoreException e) {
            // unable to read
        }
    }
    return null;
}

From source file:org.eclipse.che.jdt.internal.core.DeltaProcessor.java

License:Open Source License

private boolean createExternalArchiveDelta(HashSet refreshedElements, IProgressMonitor monitor) {

    HashMap externalArchivesStatus = new HashMap();
    boolean hasDelta = false;

    // find JARs to refresh
    HashSet archivePathsToRefresh = new HashSet();
    Iterator iterator = refreshedElements.iterator();
    while (iterator.hasNext()) {
        IJavaElement element = (IJavaElement) iterator.next();
        switch (element.getElementType()) {
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
            archivePathsToRefresh.add(element.getPath());
            break;
        case IJavaElement.JAVA_PROJECT:
            JavaProject javaProject = (JavaProject) element;
            if (!JavaProject.hasJavaNature(javaProject.getProject())) {
                // project is not accessible or has lost its Java nature
                break;
            }/*from  www  . j a  v a2 s .  c  o m*/
            IClasspathEntry[] classpath;
            try {
                classpath = javaProject.getResolvedClasspath();
                for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
                    if (classpath[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        archivePathsToRefresh.add(classpath[j].getPath());
                    }
                }
            } catch (JavaModelException e) {
                // project doesn't exist -> ignore
            }
            break;
        case IJavaElement.JAVA_MODEL:
            //               Iterator projectNames = this.state.getOldJavaProjecNames().iterator();
            //               while (projectNames.hasNext()) {
            //                  String projectName = (String) projectNames.next();
            //                  IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
            //                  if (!JavaProject.hasJavaNature(project)) {
            //                     // project is not accessible or has lost its Java nature
            //                     continue;
            //                  }
            //                  javaProject = (JavaProject) JavaCore.create(project);
            //                  try {
            //                     classpath = javaProject.getResolvedClasspath();
            //                     for (int k = 0, cpLength = classpath.length; k < cpLength; k++){
            //                        if (classpath[k].getEntryKind() == IClasspathEntry.CPE_LIBRARY){
            //                           archivePathsToRefresh.add(classpath[k].getPath());
            //                        }
            //                     }
            //                  } catch (JavaModelException e2) {
            //                     // project doesn't exist -> ignore
            //                     continue;
            //                  }
            //               }
            throw new UnsupportedOperationException();
            //               break;
        }
    }

    //      // perform refresh
    //      Iterator projectNames = this.state.getOldJavaProjecNames().iterator();
    //      IWorkspaceRoot wksRoot = ResourcesPlugin.getWorkspace().getRoot();
    //      while (projectNames.hasNext()) {
    //
    //         if (monitor != null && monitor.isCanceled()) break;
    //
    //         String projectName = (String) projectNames.next();
    //         IProject project = wksRoot.getProject(projectName);
    //         if (!JavaProject.hasJavaNature(project)) {
    //            // project is not accessible or has lost its Java nature
    //            continue;
    //         }
    //         JavaProject javaProject = (JavaProject) JavaCore.create(project);
    //         IClasspathEntry[] entries;
    //         try {
    //            entries = javaProject.getResolvedClasspath();
    //         } catch (JavaModelException e1) {
    //            // project does not exist -> ignore
    //            continue;
    //         }
    //         boolean deltaContainsModifiedJar = false;
    //         for (int j = 0; j < entries.length; j++){
    //            if (entries[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
    //               IPath entryPath = entries[j].getPath();
    //
    //               if (!archivePathsToRefresh.contains(entryPath)) continue; // not supposed to be refreshed
    //
    //               String status = (String)externalArchivesStatus.get(entryPath);
    //               if (status == null){
    //
    //                  // Clear the external file state for this path, since this method is responsible for updating it.
    //                  this.manager.clearExternalFileState(entryPath);
    //
    //                  // compute shared status
    //                  Object targetLibrary = JavaModel.getTarget(entryPath, true);
    //
    //                  if (targetLibrary == null){ // missing JAR
    //                     if (this.state.getExternalLibTimeStamps().remove(entryPath) != null /* file was known*/
    //                           && this.state.roots.get(entryPath) != null /* and it was on the classpath*/) {
    //                        externalArchivesStatus.put(entryPath, EXTERNAL_JAR_REMOVED);
    //                        // the jar was physically removed: remove the index
    //                        this.manager.indexManager.removeIndex(entryPath);
    //                     }
    //
    //                  } else if (targetLibrary instanceof File){ // external JAR
    //
    //                     File externalFile = (File)targetLibrary;
    //
    //                     // check timestamp to figure if JAR has changed in some way
    //                     Long oldTimestamp =(Long) this.state.getExternalLibTimeStamps().get(entryPath);
    //                     long newTimeStamp = getTimeStamp(externalFile);
    //                     if (oldTimestamp != null){
    //
    //                        if (newTimeStamp == 0){ // file doesn't exist
    //                           externalArchivesStatus.put(entryPath, EXTERNAL_JAR_REMOVED);
    //                           this.state.getExternalLibTimeStamps().remove(entryPath);
    //                           // remove the index
    //                           this.manager.indexManager.removeIndex(entryPath);
    //
    //                        } else if (oldTimestamp.longValue() != newTimeStamp){
    //                           externalArchivesStatus.put(entryPath, EXTERNAL_JAR_CHANGED);
    //                           this.state.getExternalLibTimeStamps().put(entryPath, new Long(newTimeStamp));
    //                           // first remove the index so that it is forced to be re-indexed
    //                           this.manager.indexManager.removeIndex(entryPath);
    //                           // then index the jar
    //                           this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j])
    // .getLibraryIndexLocation(), true);
    //                        } else {
    //                           URL indexLocation = ((ClasspathEntry)entries[j]).getLibraryIndexLocation();
    //                           if (indexLocation != null) { // force reindexing, this could be faster rather than maintaining the list
    //                              this.manager.indexManager.indexLibrary(entryPath, project.getProject(), indexLocation);
    //                           }
    //                           externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
    //                        }
    //                     } else {
    //                        if (newTimeStamp == 0){ // jar still doesn't exist
    //                           externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
    //                        } else {
    //                           externalArchivesStatus.put(entryPath, EXTERNAL_JAR_ADDED);
    //                           this.state.getExternalLibTimeStamps().put(entryPath, new Long(newTimeStamp));
    //                           // index the new jar
    //                           this.manager.indexManager.removeIndex(entryPath);
    //                           this.manager.indexManager.indexLibrary(entryPath, project.getProject(), ((ClasspathEntry)entries[j])
    // .getLibraryIndexLocation());
    //                        }
    //                     }
    //                  } else { // internal JAR
    //                     externalArchivesStatus.put(entryPath, INTERNAL_JAR_IGNORE);
    //                  }
    //               }
    //               // according to computed status, generate a delta
    //               status = (String)externalArchivesStatus.get(entryPath);
    //               if (status != null){
    //                  if (status == EXTERNAL_JAR_ADDED){
    //                     PackageFragmentRoot root = (PackageFragmentRoot) javaProject.getPackageFragmentRoot(entryPath.toString());
    //                     if (VERBOSE){
    //                        System.out.println("- External JAR ADDED, affecting root: "+root.getElementName()); //$NON-NLS-1$
    //                     }
    //                     elementAdded(root, null, null);
    //                     deltaContainsModifiedJar = true;
    //                     this.state.addClasspathValidation(javaProject); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185733
    //                     hasDelta = true;
    //                  } else if (status == EXTERNAL_JAR_CHANGED) {
    //                     PackageFragmentRoot root = (PackageFragmentRoot) javaProject.getPackageFragmentRoot(entryPath.toString());
    //                     if (VERBOSE){
    //                        System.out.println("- External JAR CHANGED, affecting root: "+root.getElementName()); //$NON-NLS-1$
    //                     }
    //                     contentChanged(root);
    //                     deltaContainsModifiedJar = true;
    //                     hasDelta = true;
    //                  } else if (status == EXTERNAL_JAR_REMOVED) {
    //                     PackageFragmentRoot root = (PackageFragmentRoot) javaProject.getPackageFragmentRoot(entryPath.toString());
    //                     if (VERBOSE){
    //                        System.out.println("- External JAR REMOVED, affecting root: "+root.getElementName()); //$NON-NLS-1$
    //                     }
    //                     elementRemoved(root, null, null);
    //                     deltaContainsModifiedJar = true;
    //                     this.state.addClasspathValidation(javaProject); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185733
    //                     hasDelta = true;
    //                  }
    //               }
    //            }
    //         }
    //
    //         if (deltaContainsModifiedJar) {
    //            javaProject.resetResolvedClasspath();
    //         }
    //      }
    //
    //      if (hasDelta){
    //         // flush jar type cache
    //         JavaModelManager.getJavaModelManager().resetJarTypeCache();
    //      }
    return hasDelta;
}

From source file:org.eclipse.che.jdt.internal.core.DeltaProcessor.java

License:Open Source License

private int elementType(File res, int kind, int parentType, RootInfo rootInfo) {
    Path path = new Path(res.getAbsolutePath());
    switch (parentType) {
    case IJavaElement.JAVA_MODEL:
        // case of a movedTo or movedFrom project (other cases are handled in processResourceDelta(...)
        return IJavaElement.JAVA_PROJECT;

    case NON_JAVA_RESOURCE:
    case IJavaElement.JAVA_PROJECT:
        if (rootInfo == null) {
            rootInfo = enclosingRootInfo(path, kind);
        }/*from  w w  w.j  av  a2 s  .  c  o  m*/
        if (rootInfo != null && rootInfo.isRootOfProject(path)) {
            return IJavaElement.PACKAGE_FRAGMENT_ROOT;
        }
        // not yet in a package fragment root or root of another project
        // or package fragment to be included (see below)
        // $FALL-THROUGH$

    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
    case IJavaElement.PACKAGE_FRAGMENT:
        if (rootInfo == null) {
            IPath rootPath = externalPath(res);
            rootInfo = enclosingRootInfo(rootPath, kind);
        }
        if (rootInfo == null) {
            return NON_JAVA_RESOURCE;
        }
        if (Util.isExcluded(path, rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) {
            return NON_JAVA_RESOURCE;
        }
        if (res.isDirectory()) {
            if (parentType == NON_JAVA_RESOURCE && !Util.isExcluded(new Path(res.getParent()),
                    rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) {
                // parent is a non-Java resource because it doesn't have a valid package name (see https://bugs.eclipse
                // .org/bugs/show_bug.cgi?id=130982)
                return NON_JAVA_RESOURCE;
            }
            String sourceLevel = rootInfo.project == null ? null
                    : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true);
            String complianceLevel = rootInfo.project == null ? null
                    : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
            if (Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel)) {
                return IJavaElement.PACKAGE_FRAGMENT;
            }
            return NON_JAVA_RESOURCE;
        }
        String fileName = res.getName();
        String sourceLevel = rootInfo.project == null ? null
                : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true);
        String complianceLevel = rootInfo.project == null ? null
                : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
        if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel)) {
            return IJavaElement.COMPILATION_UNIT;
        } else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) {
            return IJavaElement.CLASS_FILE;
        } else {
            IPath rootPath = externalPath(res);
            if ((rootInfo = rootInfo(rootPath, kind)) != null
                    && rootInfo.project.getProject().getFullPath().isPrefixOf(rootPath) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310)
                                                                                        */) {
                // case of proj=src=bin and resource is a jar file on the classpath
                return IJavaElement.PACKAGE_FRAGMENT_ROOT;
            } else {
                return NON_JAVA_RESOURCE;
            }
        }

    default:
        return NON_JAVA_RESOURCE;
    }
}

From source file:org.eclipse.che.jdt.internal.core.DeltaProcessor.java

License:Open Source License

private void traverseDelta(IResourceDelta delta, int elementType, RootInfo rootInfo, OutputsInfo outputsInfo) {

    File res = delta.getFile();//from   www .  java 2  s  .com

    // set stack of elements
    if (this.currentElement == null && rootInfo != null) {
        this.currentElement = rootInfo.project;
    }

    // process current delta
    boolean processChildren = true;
    if (res instanceof IProject) {
        // reset source element parser cache
        this.sourceElementParserCache = null;

        processChildren = updateCurrentDeltaAndIndex(delta,
                elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT ? IJavaElement.JAVA_PROJECT : // case of prj=src
                        elementType,
                rootInfo);
    } else if (rootInfo != null) {
        processChildren = updateCurrentDeltaAndIndex(delta, elementType, rootInfo);
    } else {
        // not yet inside a package fragment root
        processChildren = true;
    }

    // get the project's output locations and traverse mode
    //      if (outputsInfo == null) outputsInfo = outputsInfo(rootInfo, res);

    // process children if needed
    if (processChildren) {
        IResourceDelta[] children = (IResourceDelta[]) delta.getAffectedChildren();
        boolean oneChildOnClasspath = false;
        int length = children.length;
        IResourceDelta[] orphanChildren = null;
        Openable parent = null;
        boolean isValidParent = true;
        for (int i = 0; i < length; i++) {
            IResourceDelta child = children[i];
            File childRes = child.getFile();

            // check source attachment change
            checkSourceAttachmentChange(child, childRes);

            // find out whether the child is a package fragment root of the current project
            IPath childPath = externalPath(childRes);
            int childKind = child.getKind();
            RootInfo childRootInfo = rootInfo(childPath, childKind);
            RootInfo originalChildRootInfo = childRootInfo;
            if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) {
                // package fragment root of another project (dealt with later)
                childRootInfo = null;
            }

            // compute child type
            int childType = elementType(childRes, childKind, elementType,
                    rootInfo == null ? childRootInfo : rootInfo);

            // is childRes in the output folder and is it filtered out ?
            boolean isResFilteredFromOutput = isResFilteredFromOutput(rootInfo, outputsInfo, childRes,
                    childType);

            boolean isNestedRoot = rootInfo != null && childRootInfo != null;
            if (!isResFilteredFromOutput && !isNestedRoot) { // do not treat as non-java rsc if nested root

                traverseDelta(child, childType, rootInfo == null ? childRootInfo : rootInfo, outputsInfo); // traverse delta for child in the same project

                if (childType == NON_JAVA_RESOURCE) {
                    if (rootInfo != null) { // if inside a package fragment root
                        if (!isValidParent)
                            continue;
                        if (parent == null) {
                            // find the parent of the non-java resource to attach to
                            if (this.currentElement == null
                                    || !rootInfo.project.equals(this.currentElement.getJavaProject())) { // note if currentElement is the
                                // IJavaModel, getJavaProject() is null
                                // force the currentProject to be used
                                this.currentElement = rootInfo.project;
                            }
                            if (elementType == IJavaElement.JAVA_PROJECT
                                    || (elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT
                                            && res instanceof IProject)) {
                                // NB: attach non-java resource to project (not to its package fragment root)
                                parent = rootInfo.project;
                            } else {
                                parent = createElement(res, elementType, rootInfo);
                            }
                            if (parent == null) {
                                isValidParent = false;
                                continue;
                            }
                        }
                        // add child as non java resource
                        try {
                            nonJavaResourcesChanged(parent, child);
                        } catch (JavaModelException e) {
                            // ignore
                        }
                    } else {
                        // the non-java resource (or its parent folder) will be attached to the java project
                        if (orphanChildren == null)
                            orphanChildren = new IResourceDelta[length];
                        orphanChildren[i] = child;
                    }
                } else {
                    if (rootInfo == null && childRootInfo == null) {
                        // the non-java resource (or its parent folder) will be attached to the java project
                        if (orphanChildren == null)
                            orphanChildren = new IResourceDelta[length];
                        orphanChildren[i] = child;
                    }
                }
            } else {
                oneChildOnClasspath = true; // to avoid reporting child delta as non-java resource delta
            }

            // if child is a nested root
            // or if it is not a package fragment root of the current project
            // but it is a package fragment root of another project, traverse delta too
            if (isNestedRoot || (childRootInfo == null && originalChildRootInfo != null)) {
                traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, originalChildRootInfo, null); // binary output of childRootInfo.project cannot be this root
            }

            // if the child is a package fragment root of one or several other projects
            ArrayList rootList;
            if ((rootList = otherRootsInfo(childPath, childKind)) != null) {
                Iterator iterator = rootList.iterator();
                while (iterator.hasNext()) {
                    originalChildRootInfo = (RootInfo) iterator.next();
                    this.currentElement = null; // ensure that 2 roots refering to the same resource don't share the current element (see
                    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=210746 )
                    traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, originalChildRootInfo, null); // binary output of childRootInfo.project cannot be this root
                }
            }
        }
        if (orphanChildren != null && (oneChildOnClasspath // orphan children are siblings of a package fragment root
                || res instanceof IProject)) { // non-java resource directly under a project

            //            // attach orphan children
            //            IProject rscProject = res.getProject();
            //            JavaProject adoptiveProject = (JavaProject)JavaCore.create(rscProject);
            //            if (adoptiveProject != null
            //                  && JavaProject.hasJavaNature(rscProject)) { // delta iff Java project (18698)
            //               for (int i = 0; i < length; i++) {
            //                  if (orphanChildren[i] != null) {
            //                     try {
            //                        nonJavaResourcesChanged(adoptiveProject, orphanChildren[i]);
            //                     } catch (JavaModelException e) {
            //                        // ignore
            //                     }
            //                  }
            //               }
            //            }
        } // else resource delta will be added by parent
    } // else resource delta will be added by parent
}

From source file:org.eclipse.che.jdt.internal.core.JavaModelManager.java

License:Open Source License

public synchronized Object removeInfoAndChildren(JavaElement element) throws JavaModelException {
    Object info = this.cache.peekAtInfo(element);
    if (info != null) {
        boolean wasVerbose = false;
        try {/*from  w ww. jav a  2  s  .  co  m*/
            if (JavaModelCache.VERBOSE) {
                String elementType;
                switch (element.getElementType()) {
                case IJavaElement.JAVA_PROJECT:
                    elementType = "project"; //$NON-NLS-1$
                    break;
                case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                    elementType = "root"; //$NON-NLS-1$
                    break;
                case IJavaElement.PACKAGE_FRAGMENT:
                    elementType = "package"; //$NON-NLS-1$
                    break;
                case IJavaElement.CLASS_FILE:
                    elementType = "class file"; //$NON-NLS-1$
                    break;
                case IJavaElement.COMPILATION_UNIT:
                    elementType = "compilation unit"; //$NON-NLS-1$
                    break;
                default:
                    elementType = "element"; //$NON-NLS-1$
                }
                System.out.println(Thread.currentThread() + " CLOSING " + elementType + " "
                        + element.toStringWithAncestors()); //$NON-NLS-1$//$NON-NLS-2$
                wasVerbose = true;
                JavaModelCache.VERBOSE = false;
            }
            element.closing(info);
            if (element instanceof IParent) {
                closeChildren(info);
            }
            this.cache.removeInfo(element);
            if (wasVerbose) {
                System.out.println(this.cache.toStringFillingRation("-> ")); //$NON-NLS-1$
            }
        } finally {
            JavaModelCache.VERBOSE = wasVerbose;
        }
        return info;
    }
    return null;
}

From source file:org.eclipse.che.jdt.internal.core.Openable.java

License:Open Source License

/**
 * Find enclosing package fragment root if any
 */// www.j  a v  a  2  s.c  om
public PackageFragmentRoot getPackageFragmentRoot() {
    return (PackageFragmentRoot) getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
}

From source file:org.eclipse.che.jdt.internal.core.search.JavaSearchScope.java

License:Open Source License

/**
 * Add an element to the java search scope.
 *
 * @param element//from   w  ww .  j a v  a2s. c  o  m
 *         The element we want to add to current java search scope
 * @throws org.eclipse.jdt.core.JavaModelException
 *         May happen if some Java Model info are not available
 */
public void add(IJavaElement element) throws JavaModelException {
    IPath containerPath = null;
    String containerPathToString = null;
    PackageFragmentRoot root = null;
    int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
    switch (element.getElementType()) {
    case IJavaElement.JAVA_MODEL:
        // a workspace sope should be used
        break;
    case IJavaElement.JAVA_PROJECT:
        add((JavaProject) element, null, includeMask, new HashSet(2), new HashSet(2), null);
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        root = (PackageFragmentRoot) element;
        IPath rootPath = root.internalPath();
        containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
        containerPathToString = containerPath.getDevice() == null ? containerPath.toString()
                : containerPath.toOSString();
        File rootResource = root.resource();
        String projectPath = root.getJavaProject().getPath().toString();
        if (rootResource != null /*&& rootResource.isAccessible()*/) {
            String relativePath = Util.relativePath(new Path(rootResource.getAbsolutePath()),
                    containerPath.segmentCount());
            add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
        } else {
            add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$
        }
        break;
    case IJavaElement.PACKAGE_FRAGMENT:
        root = (PackageFragmentRoot) element.getParent();
        projectPath = root.getJavaProject().getPath().toString();
        if (root.isArchive()) {
            String relativePath = org.eclipse.jdt.internal.core.util.Util
                    .concatWith(((PackageFragment) element).names, '/');
            containerPath = root.getPath();
            containerPathToString = containerPath.getDevice() == null ? containerPath.toString()
                    : containerPath.toOSString();
            add(projectPath, relativePath, containerPathToString, true/*package*/, null);
        } else {
            File resource = ((JavaElement) element).resource();
            if (resource != null) {
                //                  if (resource.isAccessible()) {
                containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath()
                        : root.internalPath();
                //                  } else {
                //                     // for working copies, get resource container full path
                //                     containerPath = resource.getParent().getFullPath();
                //                  }
                containerPathToString = containerPath.getDevice() == null ? containerPath.toString()
                        : containerPath.toOSString();
                String relativePath = Util.relativePath(new Path(resource.getAbsolutePath()),
                        containerPath.segmentCount());
                add(projectPath, relativePath, containerPathToString, true/*package*/, null);
            }
        }
        break;
    default:
        // remember sub-cu (or sub-class file) java elements
        if (element instanceof IMember) {
            if (this.elements == null) {
                this.elements = new ArrayList();
            }
            this.elements.add(element);
        }
        root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
        projectPath = root.getJavaProject().getPath().toString();
        String relativePath;
        if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
            containerPath = root.getParent().getPath();
            relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segment*/);
        } else {
            containerPath = root.internalPath();
            relativePath = getPath(element, true/*relative path*/).toString();
        }
        containerPathToString = containerPath.getDevice() == null ? containerPath.toString()
                : containerPath.toOSString();
        add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
    }

    if (root != null)
        addEnclosingProjectOrJar(
                root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath());
}

From source file:org.eclipse.che.jdt.internal.core.search.JavaSearchScope.java

License:Open Source License

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 = org.eclipse.jdt.internal.core.util.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:/*from   w  w w . j av a  2s. c o  m*/
        return getPath(element.getParent(), relativeToRoot);
    }
}