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

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

Introduction

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

Prototype

public HashtableOfArrayToObject(int size) 

Source Link

Usage

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

License:Open Source License

private IType createTypeFromJar(String resourcePath, int separatorIndex) throws JavaModelException {
    // path to a class file inside a jar
    // Optimization: cache package fragment root handle and package handles
    if (this.lastPkgFragmentRootPath == null || this.lastPkgFragmentRootPath.length() > resourcePath.length()
            || !resourcePath.startsWith(this.lastPkgFragmentRootPath)) {
        String jarPath = resourcePath.substring(0, separatorIndex);
        IPackageFragmentRoot root = ((AbstractJavaSearchScope) this.scope).packageFragmentRoot(resourcePath,
                separatorIndex, jarPath);
        if (root == null)
            return null;
        this.lastPkgFragmentRootPath = jarPath;
        this.lastPkgFragmentRoot = root;
        this.packageHandles = new HashtableOfArrayToObject(5);
    }/*  w  ww .ja  v a2  s .  c om*/
    // create handle
    String classFilePath = resourcePath.substring(separatorIndex + 1);
    String[] simpleNames = new Path(classFilePath).segments();
    String[] pkgName;
    int length = simpleNames.length - 1;
    if (length > 0) {
        pkgName = new String[length];
        System.arraycopy(simpleNames, 0, pkgName, 0, length);
    } else {
        pkgName = CharOperation.NO_STRINGS;
    }
    IPackageFragment pkgFragment = (IPackageFragment) this.packageHandles.get(pkgName);
    if (pkgFragment == null) {
        pkgFragment = ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName);
        // filter org.apache.commons.lang.enum package for projects above 1.5 
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=317264
        if (length == 5 && pkgName[4].equals("enum")) { //$NON-NLS-1$
            IJavaProject proj = (IJavaProject) pkgFragment.getAncestor(IJavaElement.JAVA_PROJECT);
            if (!proj.equals(this.lastProject)) {
                String complianceStr = proj.getOption(CompilerOptions.OPTION_Source, true);
                this.complianceValue = CompilerOptions.versionToJdkLevel(complianceStr);
                this.lastProject = proj;
            }
            if (this.complianceValue >= ClassFileConstants.JDK1_5)
                return null;
        }
        this.packageHandles.put(pkgName, pkgFragment);
    }
    return pkgFragment.getClassFile(simpleNames[length]).getType();
}

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

License:Open Source License

private IType createTypeFromPath(String resourcePath, String simpleTypeName, char[][] enclosingTypeNames)
        throws JavaModelException {
    // path to a file in a directory
    // Optimization: cache package fragment root handle and package handles
    int rootPathLength = -1;
    if (this.lastPkgFragmentRootPath == null || !(resourcePath.startsWith(this.lastPkgFragmentRootPath)
            && (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
            && resourcePath.charAt(rootPathLength) == '/')) {
        PackageFragmentRoot root = (PackageFragmentRoot) ((AbstractJavaSearchScope) this.scope)
                .packageFragmentRoot(resourcePath, -1/*not a jar*/, null/*no jar path*/);
        if (root == null)
            return null;
        this.lastPkgFragmentRoot = root;
        this.lastPkgFragmentRootPath = root.internalPath().toString();
        this.packageHandles = new HashtableOfArrayToObject(5);
    }//from www .j  a v a2 s  .  co m
    // create handle
    resourcePath = resourcePath.substring(this.lastPkgFragmentRootPath.length() + 1);
    String[] simpleNames = new Path(resourcePath).segments();
    String[] pkgName;
    int length = simpleNames.length - 1;
    if (length > 0) {
        pkgName = new String[length];
        System.arraycopy(simpleNames, 0, pkgName, 0, length);
    } else {
        pkgName = CharOperation.NO_STRINGS;
    }
    IPackageFragment pkgFragment = (IPackageFragment) this.packageHandles.get(pkgName);
    if (pkgFragment == null) {
        pkgFragment = ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName);
        this.packageHandles.put(pkgName, pkgFragment);
    }
    String simpleName = simpleNames[length];
    if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(simpleName)) {
        ICompilationUnit unit = pkgFragment.getCompilationUnit(simpleName);
        int etnLength = enclosingTypeNames == null ? 0 : enclosingTypeNames.length;
        IType type = (etnLength == 0) ? unit.getType(simpleTypeName)
                : unit.getType(new String(enclosingTypeNames[0]));
        if (etnLength > 0) {
            for (int i = 1; i < etnLength; i++) {
                type = type.getType(new String(enclosingTypeNames[i]));
            }
            type = type.getType(simpleTypeName);
        }
        return type;
    } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(simpleName)) {
        IClassFile classFile = pkgFragment.getClassFile(simpleName);
        return classFile.getType();
    }
    return null;
}

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

License:Open Source License

/**
 * Creates an Openable handle from the given resource path.
 * The resource path can be a path to a file in the workbench (e.g. /Proj/com/ibm/jdt/core/HandleFactory.java)
 * or a path to a file in a jar file - it then contains the path to the jar file and the path to the file in the jar
 * (e.g. c:/jdk1.2.2/jre/lib/rt.jar|java/lang/Object.class or /Proj/rt.jar|java/lang/Object.class)
 * NOTE: This assumes that the resource path is the toString() of an IPath,
 *       in other words, it uses the IPath.SEPARATOR for file path
 *            and it uses '/' for entries in a zip file.
 * If not null, uses the given scope as a hint for getting Java project handles.
 */// w  w  w  . ja va 2s . c  om
public Openable createOpenable(String resourcePath, IJavaSearchScope scope) {
    int separatorIndex;
    if ((separatorIndex = resourcePath.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR)) > -1) {
        // path to a class file inside a jar
        // Optimization: cache package fragment root handle and package handles
        int rootPathLength;
        if (this.lastPkgFragmentRootPath == null
                || (rootPathLength = this.lastPkgFragmentRootPath.length()) != resourcePath.length()
                || !resourcePath.regionMatches(0, this.lastPkgFragmentRootPath, 0, rootPathLength)) {
            String jarPath = resourcePath.substring(0, separatorIndex);
            PackageFragmentRoot root = getJarPkgFragmentRoot(resourcePath, separatorIndex, jarPath, scope);
            if (root == null)
                return null; // match is outside classpath
            this.lastPkgFragmentRootPath = jarPath;
            this.lastPkgFragmentRoot = root;
            this.packageHandles = new HashtableOfArrayToObject(5);
        }
        // create handle
        String classFilePath = resourcePath.substring(separatorIndex + 1);
        String[] simpleNames = new Path(classFilePath).segments();
        String[] pkgName;
        int length = simpleNames.length - 1;
        if (length > 0) {
            pkgName = new String[length];
            System.arraycopy(simpleNames, 0, pkgName, 0, length);
        } else {
            pkgName = CharOperation.NO_STRINGS;
        }
        IPackageFragment pkgFragment = (IPackageFragment) this.packageHandles.get(pkgName);
        if (pkgFragment == null) {
            pkgFragment = this.lastPkgFragmentRoot.getPackageFragment(pkgName);
            this.packageHandles.put(pkgName, pkgFragment);
        }
        IClassFile classFile = pkgFragment.getClassFile(simpleNames[length]);
        return (Openable) classFile;
    } else {
        // path to a file in a directory
        // Optimization: cache package fragment root handle and package handles
        int rootPathLength = -1;
        if (this.lastPkgFragmentRootPath == null || !(resourcePath.startsWith(this.lastPkgFragmentRootPath)
                && !org.eclipse.jdt.internal.compiler.util.Util.isExcluded(resourcePath.toCharArray(),
                        this.lastPkgFragmentRoot.fullInclusionPatternChars(),
                        this.lastPkgFragmentRoot.fullExclusionPatternChars(), false)
                && (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
                && resourcePath.charAt(rootPathLength) == '/')) {
            PackageFragmentRoot root = getPkgFragmentRoot(resourcePath);
            if (root == null)
                return null; // match is outside classpath
            this.lastPkgFragmentRoot = root;
            this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.internalPath().toString();
            this.packageHandles = new HashtableOfArrayToObject(5);
        }
        // create handle
        resourcePath = resourcePath.substring(this.lastPkgFragmentRootPath.length() + 1);
        String[] simpleNames = new Path(resourcePath).segments();
        String[] pkgName;
        int length = simpleNames.length - 1;
        if (length > 0) {
            pkgName = new String[length];
            System.arraycopy(simpleNames, 0, pkgName, 0, length);
        } else {
            pkgName = CharOperation.NO_STRINGS;
        }
        IPackageFragment pkgFragment = (IPackageFragment) this.packageHandles.get(pkgName);
        if (pkgFragment == null) {
            pkgFragment = this.lastPkgFragmentRoot.getPackageFragment(pkgName);
            this.packageHandles.put(pkgName, pkgFragment);
        }
        String simpleName = simpleNames[length];
        if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(simpleName)) {
            ICompilationUnit unit = pkgFragment.getCompilationUnit(simpleName);
            return (Openable) unit;
        } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(simpleName)) {
            IClassFile classFile = pkgFragment.getClassFile(simpleName);
            return (Openable) classFile;
        }
        return null;
    }
}