Example usage for org.eclipse.jdt.internal.core.util HashtableOfArrayToObject put

List of usage examples for org.eclipse.jdt.internal.core.util HashtableOfArrayToObject put

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.util HashtableOfArrayToObject put.

Prototype

public Object put(Object[] key, Object value) 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.JarPackageFragmentRoot.java

License:Open Source License

/**
 * Compute the package fragment children of this package fragment root.
 * These are all of the directory zip entries, and any directories implied
 * by the path of class files contained in the jar of this package fragment root.
 *///  w ww .j a  v a  2s  . c  om
protected boolean computeChildren(OpenableElementInfo info, File underlyingResource) throws JavaModelException {
    HashtableOfArrayToObject rawPackageInfo = new HashtableOfArrayToObject();
    IJavaElement[] children;
    ZipFile jar = null;
    try {
        //            Object file = JavaModel.getTarget(getPath(), true);
        //            long level = Util.getJdkLevel(file);
        String compliance = CompilerOptions.VERSION_1_8;
        jar = getJar();

        // always create the default package
        rawPackageInfo.put(CharOperation.NO_STRINGS, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });

        for (Enumeration e = jar.entries(); e.hasMoreElements();) {
            ZipEntry member = (ZipEntry) e.nextElement();
            initRawPackageInfo(rawPackageInfo, member.getName(), member.isDirectory(), compliance);
        }

        // loop through all of referenced packages, creating package fragments if necessary
        // and cache the entry names in the rawPackageInfo table
        children = new IJavaElement[rawPackageInfo.size()];
        int index = 0;
        for (int i = 0, length = rawPackageInfo.keyTable.length; i < length; i++) {
            String[] pkgName = (String[]) rawPackageInfo.keyTable[i];
            if (pkgName == null)
                continue;
            children[index++] = getPackageFragment(pkgName);
        }
    } catch (CoreException e) {
        if (e.getCause() instanceof ZipException) {
            // not a ZIP archive, leave the children empty
            Util.log(IStatus.ERROR, "Invalid ZIP archive: " + toStringWithAncestors()); //$NON-NLS-1$
            children = NO_ELEMENTS;
        } else if (e instanceof JavaModelException) {
            throw (JavaModelException) e;
        } else {
            throw new JavaModelException(e);
        }
    } finally {
        manager.closeZipFile(jar);
    }

    info.setChildren(children);
    ((JarPackageFragmentRootInfo) info).rawPackageInfo = rawPackageInfo;
    return true;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.JarPackageFragmentRoot.java

License:Open Source License

private void initRawPackageInfo(HashtableOfArrayToObject rawPackageInfo, String entryName, boolean isDirectory,
        String compliance) {//from ww w  . j a v  a 2 s  .c  o  m
    int lastSeparator = isDirectory ? entryName.length() - 1 : entryName.lastIndexOf('/');
    String[] pkgName = Util.splitOn('/', entryName, 0, lastSeparator);
    String[] existing = null;
    int length = pkgName.length;
    int existingLength = length;
    while (existingLength >= 0) {
        existing = (String[]) rawPackageInfo.getKey(pkgName, existingLength);
        if (existing != null)
            break;
        existingLength--;
    }
    //        JavaModelManager manager = JavaModelManager.getJavaModelManager();
    for (int i = existingLength; i < length; i++) {
        // sourceLevel must be null because we know nothing about it based on a jar file
        if (Util.isValidFolderNameForPackage(pkgName[i], null, compliance)) {
            System.arraycopy(existing, 0, existing = new String[i + 1], 0, i);
            existing[i] = manager.intern(pkgName[i]);
            rawPackageInfo.put(existing, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
        } else {
            // non-Java resource folder
            if (!isDirectory) {
                ArrayList[] children = (ArrayList[]) rawPackageInfo.get(existing);
                if (children[1/*NON_JAVA*/] == EMPTY_LIST)
                    children[1/*NON_JAVA*/] = new ArrayList();
                children[1/*NON_JAVA*/].add(entryName);
            }
            return;
        }
    }
    if (isDirectory)
        return;

    // add classfile info amongst children
    ArrayList[] children = (ArrayList[]) rawPackageInfo.get(pkgName);
    if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) {
        if (children[0/*JAVA*/] == EMPTY_LIST)
            children[0/*JAVA*/] = new ArrayList();
        String nameWithoutExtension = entryName.substring(lastSeparator + 1, entryName.length() - 6);
        children[0/*JAVA*/].add(nameWithoutExtension);
    } else {
        if (children[1/*NON_JAVA*/] == EMPTY_LIST)
            children[1/*NON_JAVA*/] = new ArrayList();
        children[1/*NON_JAVA*/].add(entryName);
    }

}

From source file:com.codenvy.ide.ext.java.server.internal.core.JavaProjectElementInfo.java

License:Open Source License

static void addSuperPackageNames(String[] pkgName, HashtableOfArrayToObject packageFragments) {
    for (int i = pkgName.length - 1; i > 0; i--) {
        if (packageFragments.getKey(pkgName, i) == null) {
            System.arraycopy(pkgName, 0, pkgName = new String[i], 0, i);
            packageFragments.put(pkgName, NO_ROOTS);
        }/*  w  ww .jav a 2  s  .c  om*/
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.JavaProjectElementInfo.java

License:Open Source License

NameLookup newNameLookup(JavaProject project, ICompilationUnit[] workingCopies) {
    ProjectCache cache = getProjectCache(project);
    HashtableOfArrayToObject allPkgFragmentsCache = cache.allPkgFragmentsCache;
    if (allPkgFragmentsCache == null) {
        //         HashMap rootInfos = project.manager.deltaState.roots;
        IPackageFragmentRoot[] allRoots = cache.allPkgFragmentRootsCache;
        int length = allRoots.length;
        allPkgFragmentsCache = new HashtableOfArrayToObject();
        for (int i = 0; i < length; i++) {
            IPackageFragmentRoot root = allRoots[i];
            DeltaProcessor.RootInfo rootInfo = null;//(DeltaProcessor.RootInfo) rootInfos.get(root.getPath());
            JavaProject rootProject = project;//rootInfo == null ? project : rootInfo.project;
            HashSetOfArray fragmentsCache;
            if (rootProject.equals(project)) {
                // retrieve package fragments cache from this project
                fragmentsCache = (HashSetOfArray) cache.pkgFragmentsCaches.get(root);
            } else {
                // retrieve package fragments  cache from the root's project
                ProjectCache rootProjectCache;
                try {
                    rootProjectCache = rootProject.getProjectCache();
                } catch (JavaModelException e) {
                    // project doesn't exit
                    continue;
                }/*from w  w w.ja  v a2 s . c  o  m*/
                fragmentsCache = (HashSetOfArray) rootProjectCache.pkgFragmentsCaches.get(root);
            }
            if (fragmentsCache == null) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183833
                fragmentsCache = new HashSetOfArray();
                initializePackageNames(root, fragmentsCache);
            }
            Object[][] set = fragmentsCache.set;
            for (int j = 0, length2 = set.length; j < length2; j++) {
                String[] pkgName = (String[]) set[j];
                if (pkgName == null)
                    continue;
                Object existing = allPkgFragmentsCache.get(pkgName);
                if (existing == null || existing == NO_ROOTS) {
                    allPkgFragmentsCache.put(pkgName, root);
                    // ensure super packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
                    // are also in the map
                    addSuperPackageNames(pkgName, allPkgFragmentsCache);
                } else {
                    if (existing instanceof PackageFragmentRoot) {
                        allPkgFragmentsCache.put(pkgName,
                                new IPackageFragmentRoot[] { (PackageFragmentRoot) existing, root });
                    } else {
                        IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) existing;
                        int rootLength = roots.length;
                        System.arraycopy(roots, 0, roots = new IPackageFragmentRoot[rootLength + 1], 0,
                                rootLength);
                        roots[rootLength] = root;
                        allPkgFragmentsCache.put(pkgName, roots);
                    }
                }
            }
        }
        cache.allPkgFragmentsCache = allPkgFragmentsCache;
    }
    return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, workingCopies,
            cache.rootToResolvedEntries, project.getJavaModelManager());
}