Example usage for org.eclipse.jdt.internal.core ClassFile existsUsingJarTypeCache

List of usage examples for org.eclipse.jdt.internal.core ClassFile existsUsingJarTypeCache

Introduction

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

Prototype

public boolean existsUsingJarTypeCache() 

Source Link

Usage

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

License:Open Source License

/**
 * Performs type search in a binary package.
 *///from  w  w  w  . ja v  a2  s. c  om
protected void seekTypesInBinaryPackage(String name, IPackageFragment pkg, boolean partialMatch,
        int acceptFlags, IJavaElementRequestor requestor) {
    long start = -1;
    if (VERBOSE)
        start = System.currentTimeMillis();
    try {
        if (!partialMatch) {
            // exact match
            if (requestor.isCanceled())
                return;
            ClassFile classFile = new ClassFile((PackageFragment) pkg, manager, name);
            if (classFile.existsUsingJarTypeCache()) {
                IType type = classFile.getType();
                if (acceptType(type, acceptFlags, false/*not a source type*/)) {
                    requestor.acceptType(type);
                }
            }
        } else {
            IJavaElement[] classFiles = null;
            try {
                classFiles = pkg.getChildren();
            } catch (JavaModelException npe) {
                return; // the package is not present
            }
            int length = classFiles.length;
            String unqualifiedName = name;
            int index = name.lastIndexOf('$');
            if (index != -1) {
                //the type name of the inner type
                unqualifiedName = Util.localTypeName(name, index, name.length());
                // unqualifiedName is empty if the name ends with a '$' sign.
                // See http://dev.eclipse.org/bugs/show_bug.cgi?id=14642
            }
            int matchLength = name.length();
            for (int i = 0; i < length; i++) {
                if (requestor.isCanceled())
                    return;
                IJavaElement classFile = classFiles[i];
                // MatchName will never have the extension ".class" and the elementName always will.
                String elementName = classFile.getElementName();
                if (elementName.regionMatches(true /*ignore case*/, 0, name, 0, matchLength)) {
                    IType type = ((ClassFile) classFile).getType();
                    String typeName = type.getElementName();
                    if (typeName.length() > 0 && !Character.isDigit(typeName.charAt(0))) { //not an anonymous type
                        if (nameMatches(unqualifiedName, type, true/*partial match*/)
                                && acceptType(type, acceptFlags, false/*not a source type*/))
                            requestor.acceptType(type);
                    }
                }
            }
        }
    } finally {
        if (VERBOSE)
            this.timeSpentInSeekTypesInBinaryPackage += System.currentTimeMillis() - start;
    }
}

From source file:org.codehaus.groovy.eclipse.core.builder.GroovyNameLookup.java

License:Apache License

/**
 * Copied from parent class/*  w  w w  . ja va  2s .  c  o  m*/
 * Changes marked with // GROOVY begin and // GROOVY end
 */
@Override
protected void seekTypesInBinaryPackage(String name, IPackageFragment pkg, boolean partialMatch,
        int acceptFlags, IJavaElementRequestor requestor) {
    long start = -1;
    if (VERBOSE)
        start = System.currentTimeMillis();
    try {
        // GROOVY begin
        // ensure ends with .class
        if (!name.endsWith(".class")) {
            name += ".class";
        }
        // GROOVY end
        if (!partialMatch) {
            // exact match
            if (requestor.isCanceled())
                return;
            ClassFile classFile = (ClassFile) pkg.getClassFile(name);
            if (classFile.existsUsingJarTypeCache()) {
                IType type = classFile.getType();
                if (acceptType(type, acceptFlags, false/*not a source type*/)) {
                    requestor.acceptType(type);
                }
            }

            // GROOVY begin
            // class file may still exist as an inner type
            IJavaElement[] classFiles = null;
            try {
                classFiles = pkg.getChildren();
            } catch (JavaModelException npe) {
                return; // the package is not present
            }
            for (IJavaElement elt : classFiles) {
                classFile = (ClassFile) elt;
                if (classFile.getElementName().endsWith("$" + name)) {
                    IType type = classFile.getType();
                    if (acceptType(type, acceptFlags, false/*not a source type*/)) {
                        requestor.acceptType(type);
                    }
                }
            }
            // GROOVY end

        } else {
            IJavaElement[] classFiles = null;
            try {
                classFiles = pkg.getChildren();
            } catch (JavaModelException npe) {
                return; // the package is not present
            }
            int length = classFiles.length;
            String unqualifiedName = name;
            int index = name.lastIndexOf('$');
            if (index != -1) {
                //the type name of the inner type
                unqualifiedName = Util.localTypeName(name, index, name.length());
                // unqualifiedName is empty if the name ends with a '$' sign.
                // See http://dev.eclipse.org/bugs/show_bug.cgi?id=14642
            }
            int matchLength = name.length();
            for (int i = 0; i < length; i++) {
                if (requestor.isCanceled())
                    return;
                IJavaElement classFile = classFiles[i];
                // MatchName will never have the extension ".class" and the elementName always will.
                String elementName = classFile.getElementName();
                if (elementName.regionMatches(true /*ignore case*/, 0, name, 0, matchLength)) {
                    IType type = ((ClassFile) classFile).getType();
                    String typeName = type.getElementName();
                    if (typeName.length() > 0 && !Character.isDigit(typeName.charAt(0))) { //not an anonymous type
                        if (nameMatches(unqualifiedName, type, true/*partial match*/)
                                && acceptType(type, acceptFlags, false/*not a source type*/))
                            requestor.acceptType(type);
                    }
                }
            }
        }
    } finally {
        if (VERBOSE)
            this.timeSpentInSeekTypesInBinaryPackage += System.currentTimeMillis() - start;
    }
}