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

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

Introduction

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

Prototype

public int size() 

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 w  w . java2s.  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.NameLookup.java

License:Open Source License

public NameLookup(IPackageFragmentRoot[] packageFragmentRoots, HashtableOfArrayToObject packageFragments,
        ICompilationUnit[] workingCopies, Map rootToResolvedEntries, JavaModelManager manager) {
    this.manager = manager;
    long start = -1;
    if (VERBOSE) {
        Util.verbose(" BUILDING NameLoopkup"); //$NON-NLS-1$
        Util.verbose(" -> pkg roots size: " + (packageFragmentRoots == null ? 0 : packageFragmentRoots.length)); //$NON-NLS-1$
        Util.verbose(" -> pkgs size: " + (packageFragments == null ? 0 : packageFragments.size())); //$NON-NLS-1$
        Util.verbose(" -> working copy size: " + (workingCopies == null ? 0 : workingCopies.length)); //$NON-NLS-1$
        start = System.currentTimeMillis();
    }//from  ww w. j a v  a 2  s  .c  o  m
    this.packageFragmentRoots = packageFragmentRoots;
    if (workingCopies == null) {
        this.packageFragments = packageFragments;
    } else {
        // clone tables as we're adding packages from working copies
        try {
            this.packageFragments = (HashtableOfArrayToObject) packageFragments.clone();
        } catch (CloneNotSupportedException e1) {
            // ignore (implementation of HashtableOfArrayToObject supports cloning)
        }
        this.typesInWorkingCopies = new HashMap();
        HashtableOfObjectToInt rootPositions = new HashtableOfObjectToInt();
        for (int i = 0, length = packageFragmentRoots.length; i < length; i++) {
            rootPositions.put(packageFragmentRoots[i], i);
        }
        for (int i = 0, length = workingCopies.length; i < length; i++) {
            ICompilationUnit workingCopy = workingCopies[i];
            PackageFragment pkg = (PackageFragment) workingCopy.getParent();
            IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
            int rootPosition = rootPositions.get(root);
            if (rootPosition == -1)
                continue; // working copy is not visible from this project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=169970)
            HashMap typeMap = (HashMap) this.typesInWorkingCopies.get(pkg);
            if (typeMap == null) {
                typeMap = new HashMap();
                this.typesInWorkingCopies.put(pkg, typeMap);
            }
            try {
                IType[] types = workingCopy.getTypes();
                int typeLength = types.length;
                if (typeLength == 0) {
                    String typeName = Util.getNameWithoutJavaLikeExtension(workingCopy.getElementName());
                    typeMap.put(typeName, NO_TYPES);
                } else {
                    for (int j = 0; j < typeLength; j++) {
                        IType type = types[j];
                        String typeName = type.getElementName();
                        Object existing = typeMap.get(typeName);
                        if (existing == null) {
                            typeMap.put(typeName, type);
                        } else if (existing instanceof IType) {
                            typeMap.put(typeName, new IType[] { (IType) existing, type });
                        } else {
                            IType[] existingTypes = (IType[]) existing;
                            int existingTypeLength = existingTypes.length;
                            System.arraycopy(existingTypes, 0,
                                    existingTypes = new IType[existingTypeLength + 1], 0, existingTypeLength);
                            existingTypes[existingTypeLength] = type;
                            typeMap.put(typeName, existingTypes);
                        }
                    }
                }
            } catch (JavaModelException e) {
                // working copy doesn't exist -> ignore
            }

            // add root of package fragment to cache
            String[] pkgName = pkg.names;
            Object existing = this.packageFragments.get(pkgName);
            if (existing == null || existing == JavaProjectElementInfo.NO_ROOTS) {
                this.packageFragments.put(pkgName, root);
                // ensure super packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
                // are also in the map
                JavaProjectElementInfo.addSuperPackageNames(pkgName, this.packageFragments);
            } else {
                if (existing instanceof PackageFragmentRoot) {
                    int exisitingPosition = rootPositions.get(existing);
                    if (rootPosition != exisitingPosition) { // if not equal
                        this.packageFragments.put(pkgName,
                                exisitingPosition < rootPosition
                                        ? new IPackageFragmentRoot[] { (PackageFragmentRoot) existing, root }
                                        : new IPackageFragmentRoot[] { root, (PackageFragmentRoot) existing });
                    }
                } else {
                    // insert root in the existing list
                    IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) existing;
                    int rootLength = roots.length;
                    int insertionIndex = 0;
                    for (int j = 0; j < rootLength; j++) {
                        int existingPosition = rootPositions.get(roots[j]);
                        if (rootPosition > existingPosition) {
                            // root is after this index
                            insertionIndex = j;
                        } else if (rootPosition == existingPosition) {
                            // root already in the existing list
                            insertionIndex = -1;
                            break;
                        } else if (rootPosition < existingPosition) {
                            // root is before this index (thus it is at the insertion index)
                            break;
                        }
                    }
                    if (insertionIndex != -1) {
                        IPackageFragmentRoot[] newRoots = new IPackageFragmentRoot[rootLength + 1];
                        System.arraycopy(roots, 0, newRoots, 0, insertionIndex);
                        newRoots[insertionIndex] = root;
                        System.arraycopy(roots, insertionIndex, newRoots, insertionIndex + 1,
                                rootLength - insertionIndex);
                        this.packageFragments.put(pkgName, newRoots);
                    }
                }
            }
        }
    }

    this.rootToResolvedEntries = rootToResolvedEntries;
    if (VERBOSE) {
        Util.verbose(" -> spent: " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
    }
}