Example usage for org.eclipse.jdt.internal.core NameLookup findType

List of usage examples for org.eclipse.jdt.internal.core NameLookup findType

Introduction

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

Prototype

public Answer findType(String name, boolean partialMatch, int acceptFlags, boolean considerSecondaryTypes,
                boolean waitForIndexes, boolean checkRestrictions, IProgressMonitor monitor) 

Source Link

Usage

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

License:Open Source License

IType findType(String fullyQualifiedName, NameLookup lookup, boolean considerSecondaryTypes,
        IProgressMonitor progressMonitor) throws JavaModelException {
    NameLookup.Answer answer = lookup.findType(fullyQualifiedName, false,
            org.eclipse.jdt.internal.core.NameLookup.ACCEPT_ALL, considerSecondaryTypes,
            true, /* wait for indexes (only if consider secondary types)*/
            false/*don't check restrictions*/, progressMonitor);
    if (answer == null) {
        // try to find enclosing type
        int lastDot = fullyQualifiedName.lastIndexOf('.');
        if (lastDot == -1)
            return null;
        IType type = findType(fullyQualifiedName.substring(0, lastDot), lookup, considerSecondaryTypes,
                progressMonitor);/*from  w  ww. j a v a2 s.c om*/
        if (type != null) {
            type = type.getType(fullyQualifiedName.substring(lastDot + 1));
            if (!type.exists()) {
                return null;
            }
        }
        return type;
    }
    return answer.type;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * @see IJavaProject#findElement(IPath, WorkingCopyOwner)
 *//*from www  .ja v a2 s  .  c  o  m*/
public IJavaElement findElement(IPath path, WorkingCopyOwner owner) throws JavaModelException {

    if (path == null || path.isAbsolute()) {
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, path));
    }
    try {

        String extension = path.getFileExtension();
        if (extension == null) {
            String packageName = path.toString().replace(IPath.SEPARATOR, '.');
            return findPackageFragment(packageName);
        } else if (Util.isJavaLikeFileName(path.lastSegment()) || extension.equalsIgnoreCase(EXTENSION_class)) {
            IPath packagePath = path.removeLastSegments(1);
            String packageName = packagePath.toString().replace(IPath.SEPARATOR, '.');
            String typeName = path.lastSegment();
            typeName = typeName.substring(0, typeName.length() - extension.length() - 1);
            String qualifiedName = null;
            if (packageName.length() > 0) {
                qualifiedName = packageName + "." + typeName; //$NON-NLS-1$
            } else {
                qualifiedName = typeName;
            }

            // lookup type
            NameLookup lookup = newNameLookup(owner);
            NameLookup.Answer answer = lookup.findType(qualifiedName, false, NameLookup.ACCEPT_ALL,
                    true/* consider secondary types */, false/* do NOT wait for indexes */,
                    false/*don't check restrictions*/, null);

            if (answer != null) {
                return answer.type.getParent();
            } else {
                return null;
            }
        } else {
            // unsupported extension
            return null;
        }
    } catch (JavaModelException e) {
        if (e.getStatus().getCode() == IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST) {
            return null;
        } else {
            throw e;
        }
    }
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

IType findType(String fullyQualifiedName, NameLookup lookup, boolean considerSecondaryTypes,
        IProgressMonitor progressMonitor) throws JavaModelException {
    NameLookup.Answer answer = lookup.findType(fullyQualifiedName, false, NameLookup.ACCEPT_ALL,
            considerSecondaryTypes, true, /* wait for indexes (only if consider secondary types)*/
            false/*don't check restrictions*/, progressMonitor);
    if (answer == null) {
        // try to find enclosing type
        int lastDot = fullyQualifiedName.lastIndexOf('.');
        if (lastDot == -1)
            return null;
        IType type = findType(fullyQualifiedName.substring(0, lastDot), lookup, considerSecondaryTypes,
                progressMonitor);/*from www  .j av a 2  s .  c  o  m*/
        if (type != null) {
            type = type.getType(fullyQualifiedName.substring(lastDot + 1));
            if (!type.exists()) {
                return null;
            }
        }
        return type;
    }
    return answer.type;
}